Пример #1
0
        protected override void GenerateServerInfo(Packer packer, int token)
        {
            var playersCount = 0;
            var clientsCount = 0;

            for (var i = 0; i < MaxClients; i++)
            {
                if (Clients[i].State == ServerClientState.Empty)
                {
                    continue;
                }

                if (GameContext.IsClientPlayer(i))
                {
                    playersCount++;
                }
                clientsCount++;
            }

            if (token != -1)
            {
                packer.Reset();
                packer.AddRaw(MasterServerPackets.Info);
                packer.AddInt(token);
            }

            packer.AddString(GameContext.GameVersion, 32);
            packer.AddString(Config["SvName"], 64);
            packer.AddString(Config["SvHostname"], 128);
            packer.AddString(CurrentMap.MapName, 32);
            packer.AddString(GameContext.GameController.GameType, 16);

            var flag = string.IsNullOrEmpty(Config["Password"]) ? 0 : ServerInfoFlagPassword;

            packer.AddInt(flag);
            packer.AddInt(Config["SvSkillLevel"]);
            packer.AddInt(playersCount);
            packer.AddInt(Config["SvPlayerSlots"]);
            packer.AddInt(clientsCount);
            packer.AddInt(MaxClients);

            if (token != -1)
            {
                for (var i = 0; i < MaxClients; i++)
                {
                    if (Clients[i].State != ServerClientState.Empty)
                    {
                        packer.AddString(ClientName(i), BaseServerClient.MaxNameLength);
                        packer.AddString(ClientClan(i), BaseServerClient.MaxClanLength);
                        packer.AddInt(ClientCountry(i));
                        packer.AddInt(GameContext.GameController.Score(i));
                        packer.AddInt(GameContext.IsClientPlayer(i) ? 0 : 1); // flag spectator=1, bot=2 (player=0)
                    }
                }
            }
        }