示例#1
0
文件: ZI.cs 项目: palome06/psd48
 public bool StartWatchHall()
 {
     TcpClient client = new TcpClient(server, port);
     NetworkStream tcpStream = client.GetStream();
     Base.VW.WHelper.SentByteLine(tcpStream, "C0QI," + name);
     while (true)
     {
         string line = Base.VW.WHelper.ReadByteLine(tcpStream);
         if (line.StartsWith("C0QJ,"))
         {
             string[] splits = line.Split(',');
             uid = ushort.Parse(splits[1]);
             List<int> crooms = new List<int>();
             for (int i = 2; i < splits.Length; ++i)
                 crooms.Add(int.Parse(splits[i]));
             if (crooms.Count > 0)
             {
                 do
                 {
                     Console.WriteLine("=>请选择您将旁观的房间(" + string.Join(",", crooms) + ")");
                     string inputHouse = Console.ReadLine().Trim();
                     int house = int.Parse(inputHouse);
                     if (crooms.Contains(house))
                     {
                         Base.VW.WHelper.SentByteLine(tcpStream, "C0QS," + house);
                         break;
                     }
                 } while (true);
             }
             else
             {
                 Console.WriteLine("<=== 当前没有正在游戏的房间。");
                 client.Close();
                 return false;
             }
         }
         else if (line.StartsWith("C1SQ,"))
         {
             room = ushort.Parse(line.Substring("C1SQ,".Length));
             if (room != 0)
             {
                 Console.WriteLine("Start XIClient For Watcher");
                 VW.Ayvi ayvi = new VW.Ayvi();
                 VI = ayvi; VI.Init();
                 XIClient xic = new XIClient(uid, name, teamCode,
                     VI, server, room, record, msglog, true);
                 //client.Close();
                 xic.RunAsync();
                 return true;
             }
             else
             {
                 Console.WriteLine("<=== 申请旁观失败。");
                 client.Close();
                 return false;
             }
         }
     }
 }
示例#2
0
文件: ZI.cs 项目: palome06/psd48
        public void ResumeHall()
        {
            VW.Ayvi ayvi = new VW.Ayvi();
            VI = ayvi;
            VI.Init(); VI.SetInGame(false);

            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;
                    Console.WriteLine("Re-connection Rejected.");
                }
                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...
                    Console.WriteLine("Restart XIClient");
                    VI.SetInGame(true);
                    XIClient.CreateInResumeHall(centerUid, subUid, name, VI,
                        server, roomNumber, passcode, record, msglog).RunAsync();
                    done = true;
                }
            }
        }
示例#3
0
文件: ZI.cs 项目: palome06/psd48
        public void StartHall()
        {
            VW.Ayvi ayvi = new VW.Ayvi();
            VI = ayvi;
            VI.Init(); VI.SetInGame(false);

            TcpClient client = new TcpClient(server, port);
            NetworkStream tcpStream = client.GetStream();
            int version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Revision;
            string trainerjoin = (this.trainer != null && trainer.Length > 0) ? ("," + string.Join(",", trainer)) : "";
            Base.VW.WHelper.SentByteLine(tcpStream, "C0CO," + name + "," + avatar + ","
                + teamCode + "," + selCode + "," + levelCode + "," + version + trainerjoin);

            Thread msgThread = new Thread(delegate()
            {
                try
                {
                    //string readLine = Console.ReadLine();
                    string readLine = VI.RequestTalk(uid);
                    while (readLine != null)
                    {
                        lock (tcpStream)
                            Base.VW.WHelper.SentByteLine(tcpStream, "C0TK," + uid + "," + readLine);
                        readLine = VI.RequestTalk(uid);
                        //readLine = Console.ReadLine();
                    }
                }
                catch (System.IO.IOException) { }
            });
            bool done = false;
            while (!done)
            {
                string line = Base.VW.WHelper.ReadByteLine(tcpStream);
                if (line.StartsWith("G0XV,"))
                {
                    string expectVersion = line.Substring("C0XV,".Length);
                    VI.Cout(uid, "Version Missmatch. Expect " + expectVersion + ", please get updated.", uid);

                }
                else if (line.StartsWith("C0CN,"))
                {
                    uid = ushort.Parse(line.Substring("C1CO,".Length));
                    VI.Cout(uid, "Allocated with uid {0}", uid);
                }
                else if (line.StartsWith("C1RM,"))
                {
                    string[] splits = line.Split(',');
                    room = int.Parse(splits[1]);
                    for (int i = 2; i < splits.Length; i += 3)
                        roomMates.Add(new IchiPlayer()
                        {
                            Uid = ushort.Parse(splits[i]),
                            Name = splits[i + 1],
                            Avatar = int.Parse(splits[i + 2])
                        });
                    if (roomMates.Count > 0)
                        VI.Cout(uid, "您进入{0}#房间,其它成员为:{1}", room,
                            string.Join(",", roomMates.Select(p => "[" + p.Uid + "]" + p.Name)));
                    else
                        VI.Cout(uid, "您进入{0}#房间并成为房主。", 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);
                    VI.Cout(uid, "新成员{0}加入房间{1}#。", "[" + ip.Uid + "]" + ip.Name, room);
                }
                else if (line.StartsWith("C1LV,"))
                {
                    ushort ut = ushort.Parse(line.Substring("C1LV,".Length));
                    foreach (IchiPlayer ip in roomMates)
                    {
                        if (ip.Uid == ut)
                        {
                            roomMates.Remove(ip);
                            VI.Cout(uid, "{0}离开房间。", "[" + ip.Uid + "]" + ip.Name);
                            break;
                        }
                    }
                }
                else if (line.StartsWith("C1SA,"))
                {
                    Base.VW.WHelper.SentByteLine(tcpStream, "C1ST," + uid);
                    Console.WriteLine("Start XIClient");
                    //VI.Init();
                    VI.SetInGame(true);
                    XIClient xic = new XIClient(uid, name, teamCode, VI, server, room, record, msglog, false);
                    xic.RunAsync();
                    //client.Close();
                    done = true;
                }
                else if (line.StartsWith("C1TK,")) // Talk case
                {
                    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();
        }
示例#4
0
文件: Aywi.cs 项目: palome06/psd48
        // Hall path of construct Aywi, successors is the list player to join, null when indirect
        public IDictionary<ushort, Player> Connect(Base.VW.IVI vi, bool selTeam, List<ushort> valids)
        {
            n1 = new Dictionary<ushort, Neayer>();
            neayers = new Dictionary<ushort, Neayer>();
            netchers = new Dictionary<ushort, Netcher>();
            this.vi = vi;

            while (n1.Count < playerCapacity)
            {
                Socket socket = listener.AcceptSocket();
                try { ConnectDo(socket, valids, n1); } // no leave allowed.
                catch (SocketException) { }
                //Thread.Sleep(50);
            }
            IDictionary<ushort, ushort> cgmap = Rearrange(selTeam, n1);
            IDictionary<ushort, Player> newGarden = new Dictionary<ushort, Player>();
            neayers = new Dictionary<ushort, Neayer>();
            foreach (var pair in n1)
            {
                Neayer ny = pair.Value;
                ushort ut = cgmap[pair.Key];
                Player player = new Player(ny.Name, ny.Avatar, ut)
                {
                    Team = (ut % 2 == 0) ? 2 : 1,
                    IsAlive = true,
                    AUid = pair.Key
                };
                ny.Uid = ut;
                newGarden.Add(ut, player);
                neayers.Add(ut, ny);
            }
            foreach (var pair in neayers)
            {
                StartListenTask(() => KeepOnListenRecv(pair.Value));
                Base.VW.WHelper.SentByteLine(new NetworkStream(pair.Value.Tunnel), "C2SA,0");
            }
            foreach (var pair in netchers.ToList())
            {
                StartListenTask(() => KeepOnListenRecv(pair.Value));
                Base.VW.WHelper.SentByteLine(new NetworkStream(pair.Value.Tunnel), "C2SA,0");
            }
            StartListenTask(() => KeepOnListenSend());
            return newGarden;
        }