示例#1
0
        private void HandleMessage(int code, ReplyStream stream)
        {
            switch (code)
            {
            case 'A':
                HandleChallenge(stream);
                break;

            case 'D':
                _playersHandler.Process(stream);
                break;

            case 'E':
                HandleRules(stream);
                break;

            case 'I':
                HandleInformation(stream);
                break;

            default:
                HandleError(new Exception("Unexpected message: " + code));
                break;
            }
        }
示例#2
0
        private void ParseData(byte[] buffer)
        {
            ReplyStream stream = new ReplyStream(new MemoryStream(buffer));

            if (stream.ReadInt() == -1)
            {
                HandleMessage(stream.ReadByte(), stream);
            }
        }
示例#3
0
 private void HandleChallenge(ReplyStream stream)
 {
     byte[] buff = new byte[9];
     for (int i = 0; i < 4; i++)
     {
         buff[i] = 0xFF;
     }
     buff[4] = 0x55;
     for (int i = 5; i < 9; i++)
     {
         buff[i] = stream.ReadByte();
     }
     _socket.Send(buff, buff.Length);
 }
示例#4
0
        private void HandleInformation(ReplyStream stream)
        {
            stream.ReadByte();
            string name            = stream.ReadString();
            string map             = stream.ReadString();
            string gameDirectory   = stream.ReadString();
            string gameDescription = stream.ReadString();
            short  applicationId   = stream.ReadShort();
            int    playersCount    = stream.ReadUnsignedByte();
            int    maximumPlayers  = stream.ReadUnsignedByte();
            int    botCount        = stream.ReadByte();
            String type            = "";

            switch ((int)stream.ReadByte())
            {
            case 'd': type = "Dedicated"; break;

            case 'l': type = "Listen"; break;

            case 'p': type = "TV"; break;
            }

            String os = "";

            switch ((int)stream.ReadByte())
            {
            case 'l': os = "Linux"; break;

            case 'w': os = "Windows"; break;
            }
            bool   passwordRequired = stream.ReadByte() == 1;
            bool   vacSecure        = stream.ReadByte() == 1;
            String version          = stream.ReadString();

            String overall = name + " " + playersCount + "/" + maximumPlayers + " " + map;

            NameValueCollection list = new NameValueCollection(5)
            {
                ["name"]           = name,
                ["map"]            = map,
                ["playersCount"]   = playersCount.ToString(),
                ["maximumPlayers"] = maximumPlayers.ToString(),
                ["type"]           = type,
                ["os"]             = os
            };

            _handler.HandleServerInfo(list);
        }
示例#5
0
        private void HandlePlayers(ReplyStream stream)
        {
            int           playerCount = stream.ReadUnsignedByte();
            List <Player> players     = new List <Player>(playerCount);

            for (int x = 0; x < playerCount; x++)
            {
                Player player = new Player(stream.ReadUnsignedByte());
                String name   = stream.ReadString();
                if (name.Length > 0)
                {
                    player.Name = name;
                }
                player.Kills            = stream.ReadInt();
                player.SecondsConnected = stream.ReadFloat();
                players.Add(player);
            }

            _handler.HandlePlayers(players);
        }
示例#6
0
 private void HandleRules(ReplyStream stream)
 {
 }