// Hall mode - Watcher Mode public AoDisplay(string sv, int room, ushort uid, string name, bool record, bool msglog) { InitializeComponent(); Init(); mzi = null; mvisi = null; VW.Cyvi vi = new VW.Cyvi(this); visiThread = new Thread(delegate() { int port = Base.NetworkCode.HALL_PORT + room; vi.Init(); mvisi = new XIVisi(uid, name, 0, vi, sv, room, record, msglog, true, this); mvisi.RunAsync(); }); visiThread.Start(); yhTV = new OI.AoTV(this); tvDict = new Dictionary<string, OI.Television>(); }
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; } } }
// Constructor 3#: Used for Replay mode public XIVisi(string fileName, AoDisplay ad) { VI = new VW.Cyvi(ad); VI.Init(); VI.SetInGame(true); VW.Eywi eywi = new VW.Eywi(fileName); WI = eywi; this.ad = ad; Log = new ClLog(); Log.Start(Uid, false, false, 0); CommonConstruct(); this.auid = eywi.Uid; isReplay = true; }
// Constructor 2#: Used for Direct Connection private XIVisi(string server, int port, string name, int avatar, int hopeTeam, bool record, bool watcher, bool msglog, AoDisplay ad) { this.server = server; this.port = port; this.name = name; this.avatar = avatar; this.hopeTeam = hopeTeam; VI = new VW.Cyvi(ad); VI.Init(); VI.SetInGame(true); VW.Bywi bywi = new VW.Bywi(server, port, name, avatar, hopeTeam, 0, this); WI = bywi; this.ad = ad; Log = new ClLog(); Log.Start(Uid, record, msglog, 0); CommonConstruct(); if (!bywi.StartConnectDirect(watcher, VI)) { VI.Cout(Uid, "咦,您是不是掉线或者连错人了:-("); auid = 0; return; } VI.Cout(Uid, watcher ? "您开始旁观~" : "游戏开始咯~"); this.auid = bywi.Uid; if (watcher) Uid = bywi.Uid; bywi.Log = Log; VI.Log = Log; WI.Send("C2ST," + Uid, Uid, 0); isReplay = false; }