Exemple #1
0
        public override void Init(int clientId, Team startTeam)
        {
            base.Init(clientId, startTeam);

            Team           = startTeam;
            ActLatency     = new int[Server.MaxClients];
            Latency        = new Latency();
            TeeInfo        = new TeeInfo();
            LatestActivity = new Activity();
            IsReady        = false;
            LastSetTeam    = Server.Tick;
            LastChangeInfo = -1;
            SpectatorId    = -1;
            Spawning       = false;

            var idMap = BaseServer.GetIdMap(clientId);

            for (var i = 1; i < BaseServer.VANILLA_MAX_CLIENTS; i++)
            {
                Server.IdMap[idMap + i] = -1;
            }
            Server.IdMap[idMap] = clientId;
        }
Exemple #2
0
        protected virtual void UpdatePlayerMaps()
        {
            if (Server.Tick % Config["SvMapUpdateRate"] != 0)
            {
                return;
            }

            for (var i = 0; i < PlayersDistances.Count; i++)
            {
                PlayersDistances[i].First  = 0;
                PlayersDistances[i].Second = 0;
            }

            for (var i = 0; i < PlayersDistances.Count; i++)
            {
                if (!Server.ClientInGame(i))
                {
                    continue;
                }

                var idMap = BaseServer.GetIdMap(i);
                // compute distances
                for (var j = 0; j < PlayersDistances.Count; j++)
                {
                    PlayersDistances[j].Second = j;
                    if (!Server.ClientInGame(j) || GameContext.Players[j] == null)
                    {
                        PlayersDistances[j].First = (float)1e10;
                        continue;
                    }

                    var character = GameContext.Players[j].GetCharacter();
                    if (character == null)
                    {
                        PlayersDistances[j].First = (float)1e9;
                        continue;
                    }

                    // copypasted chunk from character.cpp Snap() follows
                    if (GameContext.Players[i].GetCharacter() != null &&
                        GameContext.Players[i].Team != Team.SPECTATORS &&
                        GameContext.Players[i].ClientVersion == ClientVersion.VANILLA)
                    {
                        PlayersDistances[j].First = (float)1e8;
                    }
                    else
                    {
                        PlayersDistances[j].First = 0;
                    }

                    PlayersDistances[j].First += Math.Distance(
                        GameContext.Players[i].ViewPos,
                        GameContext.Players[j].GetCharacter().Position
                        );
                }

                // always send the player himself
                PlayersDistances[i].First = 0;

                // compute reverse map
                var rMap = new int[PlayersDistances.Count];
                for (var j = 0; j < PlayersDistances.Count; j++)
                {
                    rMap[j] = -1;
                }

                for (var j = 0; j < BaseServer.VANILLA_MAX_CLIENTS; j++)
                {
                    if (Server.IdMap[idMap + j] == -1)
                    {
                        continue;
                    }
                    if (PlayersDistances[Server.IdMap[idMap + j]].First > 1e9)
                    {
                        Server.IdMap[idMap + j] = -1;
                    }
                    else
                    {
                        rMap[Server.IdMap[idMap + j]] = j;
                    }
                }

                PlayersDistances.Sort(DistancesComparer);

                var mapc   = 0;
                var demand = 0;

                for (var j = 0; j < BaseServer.VANILLA_MAX_CLIENTS - 1; j++)
                {
                    var k = PlayersDistances[j].Second;
                    if (rMap[k] != -1 || PlayersDistances[j].First > 5e9)
                    {
                        continue;
                    }

                    while (mapc < BaseServer.VANILLA_MAX_CLIENTS &&
                           Server.IdMap[idMap + mapc] != -1)
                    {
                        mapc++;
                    }

                    if (mapc < BaseServer.VANILLA_MAX_CLIENTS - 1)
                    {
                        Server.IdMap[idMap + mapc] = k;
                    }
                    else
                    {
                        demand++;
                    }
                }
                for (var j = PlayersDistances.Count - 1; j > BaseServer.VANILLA_MAX_CLIENTS - 2; j--)
                {
                    var k = PlayersDistances[j].Second;
                    if (rMap[k] != -1 && demand-- > 0)
                    {
                        Server.IdMap[idMap + rMap[k]] = -1;
                    }
                }
                Server.IdMap[idMap + BaseServer.VANILLA_MAX_CLIENTS - 1] = -1; // player with empty name to say chat msgs
            }
        }