示例#1
0
        protected override void NetMsgInfo(NetworkChunk packet, Unpacker unpacker, int clientId)
        {
            if (Clients[clientId].State != ServerClientState.AUTH)
            {
                return;
            }

            var version = unpacker.GetString(SanitizeType.SANITIZE_CC);

            if (string.IsNullOrEmpty(version) || !version.StartsWith(GameContext.NetVersion))
            {
                NetworkServer.Drop(clientId, $"Wrong version. Server is running '{GameContext.NetVersion}' and client '{version}'");
                return;
            }

            var password = unpacker.GetString(SanitizeType.SANITIZE_CC);

            if (!string.IsNullOrEmpty(Config["Password"]) && password != Config["Password"])
            {
                NetworkServer.Drop(clientId, "Wrong password");
                return;
            }

            if (clientId >= NetworkServer.ServerConfig.MaxClients - Config["SvReservedSlots"] &&
                !string.IsNullOrEmpty(Config["SvReservedSlotsPass"]) &&
                password != Config["SvReservedSlotsPass"])
            {
                NetworkServer.Drop(clientId, "This server is full");
                return;
            }

            Clients[clientId].State = ServerClientState.CONNECTING;
            SendMap(clientId);
        }
示例#2
0
 public override void Kick(int clientId, string reason)
 {
     NetworkServer.Drop(clientId, reason);
 }
示例#3
0
        public override void Run()
        {
            if (IsRunning)
            {
                return;
            }

            Debug.Log("server", "starting...");

            if (!LoadMap(Config["SvMap"]))
            {
                Debug.Error("server", $"failed to load map. mapname='{Config["SvMap"]}'");
                return;
            }

            if (!StartNetworkServer())
            {
                return;
            }

            Clients = new BaseServerClient[NetworkServer.ServerConfig.MaxClients];
            IdMap   = new int[Clients.Length * VANILLA_MAX_CLIENTS];

            for (var i = 0; i < Clients.Length; i++)
            {
                Clients[i] = Kernel.Get <BaseServerClient>();
            }

            NetworkServer.SetCallbacks(NewClientCallback, DelClientCallback);
            Console.Print(OutputLevel.STANDARD, "server", $"server name is '{Config["SvName"]}'");
            GameContext.OnInit();

            StartTime = Time.Get();
            IsRunning = true;

            _lastSent    = new int[NetworkServer.ServerConfig.MaxClients];
            _lastAsk     = new int[NetworkServer.ServerConfig.MaxClients];
            _lastAskTick = new int[NetworkServer.ServerConfig.MaxClients];

            while (IsRunning)
            {
                var now   = Time.Get();
                var ticks = 0;

                while (now > TickStartTime(Tick + 1))
                {
                    Tick++;
                    ticks++;

                    for (var clientId = 0; clientId < Clients.Length; clientId++)
                    {
                        if (Clients[clientId].State != ServerClientState.IN_GAME)
                        {
                            continue;
                        }

                        for (var inputIndex = 0; inputIndex < Clients[clientId].Inputs.Length; inputIndex++)
                        {
                            if (Clients[clientId].Inputs[inputIndex].Tick == Tick)
                            {
                                GameContext.OnClientPredictedInput(clientId,
                                                                   Clients[clientId].Inputs[inputIndex].PlayerInput);
                                break;
                            }
                        }
                    }

                    GameContext.OnTick();
                }

                if (ticks != 0)
                {
                    if (Tick % 2 == 0 || Config["SvHighBandwidth"])
                    {
                        DoSnapshot();
                    }
                    // UpdateClientRconCommands()
                }

                Register.RegisterUpdate(NetworkServer.NetType());
                PumpNetwork();

                Thread.Sleep(5);
            }

            for (var i = 0; i < Clients.Length; i++)
            {
                if (Clients[i].State != ServerClientState.EMPTY)
                {
                    NetworkServer.Drop(i, "Server shutdown");
                }
            }

            GameContext.OnShutdown();
        }