Exemple #1
0
 public Djvi(int playerCount, Log log)
 {
     ayvis = new Ayvi[playerCount];
     for (int i = 0; i < ayvis.Length; ++i)
         ayvis[i] = new Ayvi();
     Log = log;
     ctoken = new CancellationTokenSource();
 }
Exemple #2
0
 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;
             }
         }
     }
 }
Exemple #3
0
        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();
        }
Exemple #4
0
        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;
                }
            }
        }
Exemple #5
0
        // Constructor 3#: Used for Direct Connection
        private XIClient(string server, int port, string name,
            int avatar, int hopeTeam, bool record, bool msglog, bool watcher)
        {
            joined = false;
            this.server = server; this.port = port;
            this.name = name; this.avatar = avatar;
            this.hopeTeam = hopeTeam;

            VW.Ayvi ayvi = new VW.Ayvi();
            VI = ayvi;
            VI.Init(); ayvi.SetInGame(true);
            VW.Bywi bywi = new VW.Bywi(server, port, name, avatar, hopeTeam, 0);
            WI = bywi;

            Log = new ClLog(); Log.Start(Uid, record, msglog, 0);
            if (!bywi.StartConnectDirect(watcher, VI))
            {
                VI.Cout(Uid, "咦,您是不是掉线或者连错人了:-(");
                auid = 0; return;
            }
            VI.Cout(Uid, watcher ? "您开始旁观~" : "游戏开始咯~");
            this.auid = bywi.Uid;
            bywi.Log = Log; ayvi.Log = Log;
            WI.Send("C2ST," + Uid, Uid, 0);
            CommonConstruct();
        }