public void StartHall() { VW.Cyvi cyvi = new VW.Cyvi(AD); VI = cyvi; VI.Init(); VI.SetInGame(false); TcpClient client = null; try { client = new TcpClient(server, port); } catch (SocketException) { cyvi.ReportNoServer(server); return; } NetworkStream tcpStream = client.GetStream(); string trainerjoin = (this.trainer != null && trainer.Length > 0) ? ("," + string.Join(",", trainer)) : ""; int version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Revision; Base.VW.WHelper.SentByteLine(tcpStream, "C0CO," + name + "," + avatar + "," + teamCode + "," + selCode + "," + levelCode + "," + version + trainerjoin); Thread msgThread = new Thread(delegate() { try { string readLine = VI.RequestTalk(uid); while (readLine != null) { lock (tcpStream) Base.VW.WHelper.SentByteLine(tcpStream, "C0TK," + uid + "," + readLine); readLine = VI.RequestTalk(uid); } } catch (System.IO.IOException) { } }); bool done = false; while (!done) { string line = Base.VW.WHelper.ReadByteLine(tcpStream); if (line.StartsWith("C0XV,")) { cyvi.ReportWrongVersion(line.Substring("C0XV,".Length)); return; } if (line.StartsWith("C0CN,")) { uid = ushort.Parse(line.Substring("C1CO,".Length)); cyvi.SetNick(1, name, avatar); } else if (line.StartsWith("C1RM,")) { string[] splits = line.Split(','); room = int.Parse(splits[1]); int pos = 2; for (int i = 2; i < splits.Length; i += 3) { IchiPlayer ip = new IchiPlayer() { Uid = ushort.Parse(splits[i]), Name = splits[i + 1], Avatar = int.Parse(splits[i + 2]) }; roomMates.Add(ip); if (ip.Uid != uid) cyvi.SetNick(pos++, ip.Name, ip.Avatar); } cyvi.SetRoom(room); msgThread.Start(); } else if (line.StartsWith("C1NW,")) { string[] splits = line.Split(','); IchiPlayer ip = new IchiPlayer() { Uid = ushort.Parse(splits[1]), Name = splits[2], Avatar = int.Parse(splits[3]) }; roomMates.Add(ip); if (ip.Uid != uid) cyvi.SetNick(roomMates.Count, ip.Name, ip.Avatar); } else if (line.StartsWith("C1LV,")) { ushort ut = ushort.Parse(line.Substring("C1LV,".Length)); for (int idx = 0; idx < roomMates.Count; ++idx) { IchiPlayer ip = roomMates[idx]; if (ip.Uid == ut) { roomMates.RemoveAt(idx); break; } } int pos = 2; foreach (IchiPlayer ip in roomMates) { if (ip.Uid != uid) cyvi.SetNick(pos++, ip.Name, ip.Avatar); } while (pos <= 6) cyvi.SetNick(pos++, "", 0); } else if (line.StartsWith("C1SA,")) { Base.VW.WHelper.SentByteLine(tcpStream, "C1ST," + uid); VI.SetInGame(true); XV = new XIVisi(uid, name, teamCode, VI, server, room, record, msglog, false, AD); XV.RunAsync(); //client.Close(); done = true; } else if (line.StartsWith("C1TK,")) { int idx = line.IndexOf(',', "C1TK,".Length); string nick = Algo.Substring(line, "C1TK,".Length, idx); string content = Algo.Substring(line, idx + 1, -1); VI.Chat(content, nick); } } if (msgThread != null && msgThread.IsAlive) msgThread.Abort(); }
public void ResumeHall() { VW.Cyvi cyvi = new VW.Cyvi(AD); VI = cyvi; VI.Init(); VI.SetInGame(true); TcpClient client = new TcpClient(server, port); NetworkStream tcpStream = client.GetStream(); Base.VW.WHelper.SentByteLine(tcpStream, "C4CO," + name + "," + room); bool done = false; while (!done) { string line = Base.VW.WHelper.ReadByteLine(tcpStream); if (line.StartsWith("C4RM,0")) { done = true; System.Windows.MessageBox.Show("重连被拒绝."); } else if (line.StartsWith("C4RM,")) // Reconnection case { string[] parts = line.Split(','); ushort centerUid = ushort.Parse(parts[1]); // AUid ushort subUid = ushort.Parse(parts[2]); // Uid int roomNumber = int.Parse(parts[3]); string nick = parts[4]; string passcode = parts[5]; // start new connection... VI.SetInGame(true); cyvi.SetRoom(roomNumber); XV = XIVisi.CreateInResumeHall(centerUid, subUid, name, VI, server, roomNumber, passcode, record, msglog, AD); XV.RunAsync(); done = true; } } }