Beispiel #1
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            GameFlags    = (GameFlags)unpacker.GetInt();
            ScoreLimit   = unpacker.GetInt();
            TimeLimit    = unpacker.GetInt();
            MatchNum     = unpacker.GetInt();
            MatchCurrent = unpacker.GetInt();

            if (GameFlags < 0)
            {
                failedOn = nameof(GameFlags);
            }
            if (ScoreLimit < 0)
            {
                failedOn = nameof(ScoreLimit);
            }
            if (TimeLimit < 0)
            {
                failedOn = nameof(TimeLimit);
            }
            if (MatchNum < 0)
            {
                failedOn = nameof(MatchNum);
            }
            if (MatchCurrent < 0)
            {
                failedOn = nameof(MatchCurrent);
            }

            return(unpacker.Error);
        }
 public override bool UnPackError(UnPacker unpacker, ref string failedOn)
 {
     Yes   = unpacker.GetInt();
     No    = unpacker.GetInt();
     Pass  = unpacker.GetInt();
     Total = unpacker.GetInt();
     return(unpacker.Error);
 }
Beispiel #3
0
 public override bool UnPackError(UnPacker unpacker, ref string failedOn)
 {
     KickVote       = unpacker.GetBool();
     KickMin        = unpacker.GetInt();
     SpectatorsVote = unpacker.GetBool();
     TeamLock       = unpacker.GetBool();
     TeamBalance    = unpacker.GetBool();
     PlayerSlots    = unpacker.GetInt();
     return(unpacker.Error);
 }
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            Name    = unpacker.GetString(Sanitize);
            Clan    = unpacker.GetString(Sanitize);
            Country = unpacker.GetInt();
            unpacker.GetString(SkinPartNames, Sanitize);
            unpacker.GetBool(UseCustomColors);
            unpacker.GetInt(SkinPartColors);

            return(unpacker.Error);
        }
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            SpectatorMode = (SpectatorMode)unpacker.GetInt();
            SpectatorId   = unpacker.GetInt();

            if (SpectatorMode < 0 || SpectatorMode >= SpectatorMode.NumModes)
            {
                failedOn = nameof(SpectatorMode);
            }

            return(unpacker.Error);
        }
Beispiel #6
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            ChatMode = (ChatMode)unpacker.GetInt();
            TargetId = unpacker.GetInt();
            Message  = unpacker.GetString(Sanitize);

            if (ChatMode < 0 || ChatMode >= ChatMode.NumModes)
            {
                failedOn = nameof(ChatMode);
            }

            return(unpacker.Error);
        }
Beispiel #7
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            Name     = unpacker.GetString(Sanitize);
            ClientId = unpacker.GetInt();
            Team     = (Team)unpacker.GetInt();

            if (Team < Team.Spectators || Team > Team.Blue)
            {
                failedOn = nameof(Team);
            }

            return(unpacker.Error);
        }
Beispiel #8
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            ClientId = unpacker.GetInt();
            Team = (Team) unpacker.GetInt();
            Silent = unpacker.GetBool();
            CooldownTick = unpacker.GetInt();

            if (Team < Team.Spectators || Team > Team.Blue)
                failedOn = nameof(Team);
            if (CooldownTick < 0)
                failedOn = nameof(CooldownTick);

            return unpacker.Error;
        }
Beispiel #9
0
        protected override void NetMsgInfo(Chunk packet, UnPacker unPacker, int clientId)
        {
            if (!packet.Flags.HasFlag(SendFlags.Vital))
            {
                return;
            }

            if (Clients[clientId].State != ServerClientState.Auth)
            {
                return;
            }

            var version = unPacker.GetString(SanitizeType.SanitizeCC);

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

            var password = unPacker.GetString(SanitizeType.SanitizeCC);

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

            Clients[clientId].Version = unPacker.GetInt();
            Clients[clientId].State   = ServerClientState.Connecting;
            SendMap(clientId);
        }
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            ClientID = unpacker.GetInt();
            Reason   = unpacker.GetString(Sanitize);
            Silent   = unpacker.GetBool();

            return(unpacker.Error);
        }
Beispiel #11
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            ClientId = unpacker.GetInt();
            Emoticon = (Emoticon)unpacker.GetInt();

            if (ClientId < 0)
            {
                failedOn = nameof(ClientId);
            }

            if (Emoticon < 0 || Emoticon >= Emoticon.NumEmoticons)
            {
                failedOn = nameof(Emoticon);
            }

            return(unpacker.Error);
        }
Beispiel #12
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            ClientID    = unpacker.GetInt();
            VoteType    = (Vote)unpacker.GetInt();
            Timeout     = unpacker.GetInt();
            Description = unpacker.GetString(Sanitize);
            Reason      = unpacker.GetString(Sanitize);

            if (VoteType < 0 || VoteType >= Vote.NumTypes)
            {
                failedOn = nameof(VoteType);
            }
            if (Timeout < 0 || Timeout > 60)
            {
                failedOn = nameof(Timeout);
            }

            return(unpacker.Error);
        }
Beispiel #13
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            Team = (Team)unpacker.GetInt();

            if (Team < Team.Spectators || Team > Team.Blue)
            {
                failedOn = nameof(Team);
            }

            return(unpacker.Error);
        }
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            Weapon = (Weapon)unpacker.GetInt();

            if (Weapon < 0 || Weapon >= Weapon.NumWeapons)
            {
                failedOn = nameof(Weapon);
            }

            return(unpacker.Error);
        }
Beispiel #15
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            Vote = unpacker.GetInt();

            if (Vote < -1 || Vote > 1)
            {
                failedOn = nameof(Vote);
            }

            return(unpacker.Error);
        }
Beispiel #16
0
        protected override void PumpNetwork()
        {
            NetworkServer.Update();

            Chunk packet        = null;
            uint  responseToken = 0;

            while (NetworkServer.Receive(ref packet, ref responseToken))
            {
                if (packet.Flags.HasFlag(SendFlags.Connless))
                {
                    if (Register.RegisterProcessPacket(packet, responseToken))
                    {
                        continue;
                    }

                    if (packet.DataSize >= MasterServerPackets.GetInfo.Length &&
                        packet.Data.ArrayCompare(MasterServerPackets.GetInfo, MasterServerPackets.GetInfo.Length))
                    {
                        var unpacker = new UnPacker();
                        unpacker.Reset(packet.Data, packet.DataSize, MasterServerPackets.GetInfo.Length);
                        var serverBrowserToken = unpacker.GetInt();

                        if (unpacker.Error)
                        {
                            continue;
                        }

                        var packer = new Packer();
                        GenerateServerInfo(packer, serverBrowserToken);

                        var response = new Chunk()
                        {
                            ClientId = -1,
                            EndPoint = packet.EndPoint,
                            Flags    = SendFlags.Connless,
                            Data     = packer.Data(),
                            DataSize = packer.Size(),
                        };

                        NetworkServer.Send(response, responseToken);
                    }
                }
                else
                {
                    ProcessClientPacket(packet);
                }
            }

            // TODO Econ.Update();
            NetworkBan.Update();
        }
Beispiel #17
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            Killer      = unpacker.GetInt();
            Victim      = unpacker.GetInt();
            Weapon      = unpacker.GetInt();
            ModeSpecial = unpacker.GetInt();

            if (Killer < 0)
            {
                failedOn = nameof(Killer);
            }
            if (Victim < 0)
            {
                failedOn = nameof(Victim);
            }
            if (Weapon < -3 || Weapon >= (int)Enums.Weapon.NumWeapons)
            {
                failedOn = nameof(Weapon);
            }

            return(unpacker.Error);
        }
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            ClientID = unpacker.GetInt();
            Local    = unpacker.GetBool();
            Team     = (Team)unpacker.GetInt();
            Name     = unpacker.GetString(Sanitize);
            Clan     = unpacker.GetString(Sanitize);
            Country  = unpacker.GetInt();

            unpacker.GetString(SkinPartNames, Sanitize);
            unpacker.GetBool(UseCustomColors);
            unpacker.GetInt(SkinPartColors);

            Silent = unpacker.GetBool();


            if (Team < Team.Spectators || Team > Team.Blue)
            {
                failedOn = nameof(Team);
            }

            return(unpacker.Error);
        }
Beispiel #19
0
        protected override void NetMsgInput(Chunk packet, UnPacker unPacker, int clientId)
        {
            Clients[clientId].LastAckedSnapshot = unPacker.GetInt();

            var intendedTick = unPacker.GetInt();
            var size         = unPacker.GetInt();
            var now          = Time.Get();

            if (unPacker.Error)
            {
                return;
            }

            if (Clients[clientId].LastAckedSnapshot > 0)
            {
                Clients[clientId].SnapshotRate = SnapshotRate.Full;
            }

            if (intendedTick > Clients[clientId].LastInputTick)
            {
                var timeLeft = ((TickStartTime(intendedTick) - now) * 1000) / Time.Freq();
                var msg      = new MsgPacker((int)NetworkMessages.ServerInputTiming, true);
                msg.AddInt(intendedTick);
                msg.AddInt((int)timeLeft);
                SendMsg(msg, MsgFlags.None, clientId);
            }

            Clients[clientId].LastInputTick = intendedTick;

            if (intendedTick <= Tick)
            {
                intendedTick = Tick + 1;
            }

            var input = Clients[clientId].Inputs[Clients[clientId].CurrentInput];

            input.Tick = intendedTick;

            for (var i = 0; i < size / sizeof(int) && i < BaseServerClient.MaxInputSize; i++)
            {
                input.Data[i] = unPacker.GetInt();
            }

            var pingCorrection = Math.Clamp(unPacker.GetInt(), 0, 50);

            if (Clients[clientId].SnapshotStorage.Get(Clients[clientId].LastAckedSnapshot,
                                                      out var tagTime, out _))
            {
                Clients[clientId].Latency = (int)(((now - tagTime) * 1000) / Time.Freq());
                Clients[clientId].Latency = Math.Max(0, Clients[clientId].Latency - pingCorrection);
            }

            Array.Copy(input.Data, 0, Clients[clientId].LatestInput.Data, 0, BaseServerClient.MaxInputSize);

            Clients[clientId].CurrentInput++;
            Clients[clientId].CurrentInput &= BaseServerClient.MaxInputs;

            if (Clients[clientId].State == ServerClientState.InGame)
            {
                GameContext.OnClientDirectInput(clientId, Clients[clientId].LatestInput.Data);
            }
        }
Beispiel #20
0
        protected override void ProcessClientPacket(Chunk packet)
        {
            var clientId = packet.ClientId;
            var unpacker = new UnPacker();

            unpacker.Reset(packet.Data, packet.DataSize);

            var msg    = unpacker.GetInt();
            var system = (msg & 1) != 0;

            msg >>= 1;

            if (unpacker.Error)
            {
                return;
            }

            if (system)
            {
                var networkMsg = (NetworkMessages)msg;
                switch (networkMsg)
                {
                case NetworkMessages.ClientInfo:
                    NetMsgInfo(packet, unpacker, clientId);
                    break;

                case NetworkMessages.ClientRequestMapData:
                    NetMsgRequestMapData(packet, unpacker, clientId);
                    break;

                case NetworkMessages.ClientReady:
                    NetMsgReady(packet, unpacker, clientId);
                    break;

                case NetworkMessages.ClientEnterGame:
                    NetMsgEnterGame(packet, unpacker, clientId);
                    break;

                case NetworkMessages.ClientInput:
                    NetMsgInput(packet, unpacker, clientId);
                    break;

                case NetworkMessages.ClientRconCommand:
                    NetMsgRconCmd(packet, unpacker, clientId);
                    break;

                case NetworkMessages.ClientRconAuth:
                    NetMsgRconAuth(packet, unpacker, clientId);
                    break;

                case NetworkMessages.Ping:
                    NetMsgPing(packet, unpacker, clientId);
                    break;

                default:
                    Console.Print(OutputLevel.Debug, "server", $"strange message clientId={clientId} msg={msg} data_size={packet.DataSize}");
                    break;
                }
            }
            else if (packet.Flags.HasFlag(SendFlags.Vital) &&
                     Clients[clientId].State >= ServerClientState.Ready)
            {
                GameContext.OnMessage((GameMessage)msg, unpacker, clientId);
            }
        }