예제 #1
0
        public void IN_OnNetworkMessage(Message packet)
        {
            switch (packet.type)
            {
            case Message.Type.Approved:
                OnApproved(packet);
                break;

            case Message.Type.EAC:
                EACServer.OnMessageReceived(packet);
                SendPacket(BaseServer, packet);
                break;

            case Message.Type.DisconnectReason:
                SendPacket(BaseServer, packet);
                if (BaseServer != null && BaseServer.connections.Count > 0)
                {
                    packet.read.Position = 1L;
                    string reasone = packet.read.String();
                    BaseServer?.Kick(BaseServer.connections[0], reasone);
                    ConsoleSystem.LogWarning("[VirtualServer]: От игрового сервера получена причина дисконнекта: " + reasone);
                }
                break;

            case Message.Type.Entities:
                packet.read.UInt32();
                using (Entity entity = Entity.Deserialize(packet.read))
                {
                    if (EntityManager.OnEntity(entity) == false)
                    {
                        if (BaseServer.write.Start())
                        {
                            BaseServer.write.PacketID(Message.Type.Entities);
                            BaseServer.write.UInt32(TakeEntityNUM);
                            entity.WriteToStream(BaseServer.write);
                            BaseServer.write.Send(new SendInfo(BaseServer.connections[0]));
                        }
                    }
                }
                break;

            case Message.Type.EntityDestroy:
                EntityManager.OnEntityDestroy(packet);
                SendPacket(BaseServer, packet);
                break;

            case Message.Type.EntityPosition:
                EntityManager.OnEntityPosition(packet);
                SendPacket(BaseServer, packet);
                break;

            default:
                if (NetworkManager.Instance.IN_NetworkMessage(packet) == false)
                {
                    SendPacket(BaseServer, packet);
                }
                break;
            }
        }
예제 #2
0
        public void OUT_OnNetworkMessage(Message packet)
        {
            switch (packet.type)
            {
            case Message.Type.Ready:
                packet.connection.decryptIncoming = true;
                SendPacket(BaseClient, packet);
                BaseClient.Connection.encryptOutgoing = true;
                return;

            case Message.Type.GiveUserInformation:
                ConnectionInformation = UserInformation.ParsePacket(packet);

                if (Settings.UseCustomToken)
                {
                    ConnectionInformation.SteamToken = Settings.CustomToken;
                    if (BaseClient.write.Start())
                    {
                        BaseClient.write.PacketID(Message.Type.GiveUserInformation);
                        ConnectionInformation.Write(BaseClient);
                        BaseClient.Send();
                    }
                }
                else
                {
                    SendPacket(BaseClient, packet);
                }
                break;

            case Message.Type.EAC:
                EACServer.OnMessageReceived(packet);
                SendPacket(BaseClient, packet);
                break;

            default:
                if (NetworkManager.Instance.Out_NetworkMessage(packet) == false)
                {
                    SendPacket(BaseClient, packet);
                }
                break;
            }
        }
예제 #3
0
    public void OnNetworkMessage(Message packet)
    {
        Message.Type type = (Message.Type)packet.type;
        if (type != 4)
        {
            switch (type - 9)
            {
            case 0:
                if (!((Network.Connection)packet.connection).get_isAuthenticated())
                {
                    break;
                }
                if (((Network.Connection)packet.connection).GetPacketsPerSecond((Message.Type)packet.type) > (ulong)ConVar.Server.maxrpcspersecond)
                {
                    ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Paket Flooding: RPC Message");
                    break;
                }
                using (TimeWarning.New("OnRPCMessage", 20L))
                {
                    try
                    {
                        this.OnRPCMessage(packet);
                    }
                    catch (Exception ex)
                    {
                        this.Log(ex);
                        ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Invalid Packet: RPC Message");
                    }
                }
                ((Network.Connection)packet.connection).AddPacketsPerSecond((Message.Type)packet.type);
                break;

            case 1:
            case 2:
            case 4:
label_84:
                this.ProcessUnhandledPacket(packet);
                break;

            case 3:
                if (!((Network.Connection)packet.connection).get_isAuthenticated())
                {
                    break;
                }
                if (((Network.Connection)packet.connection).GetPacketsPerSecond((Message.Type)packet.type) > (ulong)ConVar.Server.maxcommandspersecond)
                {
                    ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Packet Flooding: Client Command");
                    break;
                }
                using (TimeWarning.New("OnClientCommand", 20L))
                {
                    try
                    {
                        ConsoleNetwork.OnClientCommand(packet);
                    }
                    catch (Exception ex)
                    {
                        this.Log(ex);
                        ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Invalid Packet: Client Command");
                    }
                }
                ((Network.Connection)packet.connection).AddPacketsPerSecond((Message.Type)packet.type);
                break;

            case 5:
                if (!((Network.Connection)packet.connection).get_isAuthenticated())
                {
                    break;
                }
                if (((Network.Connection)packet.connection).GetPacketsPerSecond((Message.Type)packet.type) > 1UL)
                {
                    ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Packet Flooding: Disconnect Reason");
                    break;
                }
                using (TimeWarning.New("ReadDisconnectReason", 20L))
                {
                    try
                    {
                        this.ReadDisconnectReason(packet);
                    }
                    catch (Exception ex)
                    {
                        this.Log(ex);
                        ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Invalid Packet: Disconnect Reason");
                    }
                }
                ((Network.Connection)packet.connection).AddPacketsPerSecond((Message.Type)packet.type);
                break;

            case 6:
                if (!((Network.Connection)packet.connection).get_isAuthenticated())
                {
                    break;
                }
                if (((Network.Connection)packet.connection).GetPacketsPerSecond((Message.Type)packet.type) > (ulong)ConVar.Server.maxtickspersecond)
                {
                    ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Packet Flooding: Player Tick");
                    break;
                }
                using (TimeWarning.New("OnPlayerTick", 20L))
                {
                    try
                    {
                        this.OnPlayerTick(packet);
                    }
                    catch (Exception ex)
                    {
                        this.Log(ex);
                        ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Invalid Packet: Player Tick");
                    }
                }
                ((Network.Connection)packet.connection).AddPacketsPerSecond((Message.Type)packet.type);
                break;

            default:
                switch (type - 18)
                {
                case 0:
                    if (((Network.Connection)packet.connection).GetPacketsPerSecond((Message.Type)packet.type) > 1UL)
                    {
                        ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Packet Flooding: User Information");
                        return;
                    }
                    using (TimeWarning.New("GiveUserInformation", 20L))
                    {
                        try
                        {
                            this.OnGiveUserInformation(packet);
                        }
                        catch (Exception ex)
                        {
                            this.Log(ex);
                            ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Invalid Packet: User Information");
                        }
                    }
                    ((Network.Connection)packet.connection).AddPacketsPerSecond((Message.Type)packet.type);
                    return;

                case 3:
                    if (!((Network.Connection)packet.connection).get_isAuthenticated())
                    {
                        return;
                    }
                    if (((Network.Connection)packet.connection).GetPacketsPerSecond((Message.Type)packet.type) > 100UL)
                    {
                        ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Packet Flooding: Disconnect Reason");
                        return;
                    }
                    using (TimeWarning.New("OnPlayerVoice", 20L))
                    {
                        try
                        {
                            this.OnPlayerVoice(packet);
                        }
                        catch (Exception ex)
                        {
                            this.Log(ex);
                            ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Invalid Packet: Player Voice");
                        }
                    }
                    ((Network.Connection)packet.connection).AddPacketsPerSecond((Message.Type)packet.type);
                    return;

                case 4:
                    using (TimeWarning.New("OnEACMessage", 20L))
                    {
                        try
                        {
                            EACServer.OnMessageReceived(packet);
                            return;
                        }
                        catch (Exception ex)
                        {
                            this.Log(ex);
                            ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Invalid Packet: EAC");
                            return;
                        }
                    }

                default:
                    goto label_84;
                }
            }
        }
        else
        {
            if (!((Network.Connection)packet.connection).get_isAuthenticated())
            {
                return;
            }
            if (((Network.Connection)packet.connection).GetPacketsPerSecond((Message.Type)packet.type) > 1UL)
            {
                ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Packet Flooding: Client Ready");
            }
            else
            {
                using (TimeWarning.New("ClientReady", 20L))
                {
                    try
                    {
                        this.ClientReady(packet);
                    }
                    catch (Exception ex)
                    {
                        this.Log(ex);
                        ((Network.Server)Network.Net.sv).Kick((Network.Connection)packet.connection, "Invalid Packet: Client Ready");
                    }
                }
                ((Network.Connection)packet.connection).AddPacketsPerSecond((Message.Type)packet.type);
            }
        }
    }
예제 #4
0
    public void OnNetworkMessage(Message packet)
    {
        Message.Type type = packet.type;
        if (type == Message.Type.Ready)
        {
            if (!packet.connection.isAuthenticated)
            {
                return;
            }
            if (packet.connection.GetPacketsPerSecond(packet.type) > (long)1)
            {
                Network.Net.sv.Kick(packet.connection, "Packet Flooding: Client Ready");
                return;
            }
            using (TimeWarning timeWarning = TimeWarning.New("ClientReady", (long)20))
            {
                try
                {
                    this.ClientReady(packet);
                }
                catch (Exception exception)
                {
                    this.Log(exception);
                    Network.Net.sv.Kick(packet.connection, "Invalid Packet: Client Ready");
                }
            }
            packet.connection.AddPacketsPerSecond(packet.type);
            return;
        }
        switch (type)
        {
        case Message.Type.RPCMessage:
        {
            if (!packet.connection.isAuthenticated)
            {
                return;
            }
            if (packet.connection.GetPacketsPerSecond(packet.type) > (long)ConVar.Server.maxrpcspersecond)
            {
                Network.Net.sv.Kick(packet.connection, "Paket Flooding: RPC Message");
                return;
            }
            using (timeWarning = TimeWarning.New("OnRPCMessage", (long)20))
            {
                try
                {
                    this.OnRPCMessage(packet);
                }
                catch (Exception exception1)
                {
                    this.Log(exception1);
                    Network.Net.sv.Kick(packet.connection, "Invalid Packet: RPC Message");
                }
            }
            packet.connection.AddPacketsPerSecond(packet.type);
            return;
        }

        case Message.Type.EntityPosition:
        case Message.Type.ConsoleMessage:
        case Message.Type.Effect:
        {
            this.ProcessUnhandledPacket(packet);
            return;
        }

        case Message.Type.ConsoleCommand:
        {
            if (!packet.connection.isAuthenticated)
            {
                return;
            }
            if (packet.connection.GetPacketsPerSecond(packet.type) > (long)ConVar.Server.maxcommandspersecond)
            {
                Network.Net.sv.Kick(packet.connection, "Packet Flooding: Client Command");
                return;
            }
            using (timeWarning = TimeWarning.New("OnClientCommand", (long)20))
            {
                try
                {
                    ConsoleNetwork.OnClientCommand(packet);
                }
                catch (Exception exception2)
                {
                    this.Log(exception2);
                    Network.Net.sv.Kick(packet.connection, "Invalid Packet: Client Command");
                }
            }
            packet.connection.AddPacketsPerSecond(packet.type);
            return;
        }

        case Message.Type.DisconnectReason:
        {
            if (!packet.connection.isAuthenticated)
            {
                return;
            }
            if (packet.connection.GetPacketsPerSecond(packet.type) > (long)1)
            {
                Network.Net.sv.Kick(packet.connection, "Packet Flooding: Disconnect Reason");
                return;
            }
            using (timeWarning = TimeWarning.New("ReadDisconnectReason", (long)20))
            {
                try
                {
                    this.ReadDisconnectReason(packet);
                }
                catch (Exception exception3)
                {
                    this.Log(exception3);
                    Network.Net.sv.Kick(packet.connection, "Invalid Packet: Disconnect Reason");
                }
            }
            packet.connection.AddPacketsPerSecond(packet.type);
            return;
        }

        case Message.Type.Tick:
        {
            if (!packet.connection.isAuthenticated)
            {
                return;
            }
            if (packet.connection.GetPacketsPerSecond(packet.type) > (long)ConVar.Server.maxtickspersecond)
            {
                Network.Net.sv.Kick(packet.connection, "Packet Flooding: Player Tick");
                return;
            }
            using (timeWarning = TimeWarning.New("OnPlayerTick", (long)20))
            {
                try
                {
                    this.OnPlayerTick(packet);
                }
                catch (Exception exception4)
                {
                    this.Log(exception4);
                    Network.Net.sv.Kick(packet.connection, "Invalid Packet: Player Tick");
                }
            }
            packet.connection.AddPacketsPerSecond(packet.type);
            return;
        }

        default:
        {
            switch (type)
            {
            case Message.Type.GiveUserInformation:
            {
                if (packet.connection.GetPacketsPerSecond(packet.type) > (long)1)
                {
                    Network.Net.sv.Kick(packet.connection, "Packet Flooding: User Information");
                    return;
                }
                using (timeWarning = TimeWarning.New("GiveUserInformation", (long)20))
                {
                    try
                    {
                        this.OnGiveUserInformation(packet);
                    }
                    catch (Exception exception5)
                    {
                        this.Log(exception5);
                        Network.Net.sv.Kick(packet.connection, "Invalid Packet: User Information");
                    }
                }
                packet.connection.AddPacketsPerSecond(packet.type);
                return;
            }

            case Message.Type.GroupEnter:
            case Message.Type.GroupLeave:
            {
                this.ProcessUnhandledPacket(packet);
                return;
            }

            case Message.Type.VoiceData:
            {
                if (!packet.connection.isAuthenticated)
                {
                    return;
                }
                if (packet.connection.GetPacketsPerSecond(packet.type) > (long)100)
                {
                    Network.Net.sv.Kick(packet.connection, "Packet Flooding: Disconnect Reason");
                    return;
                }
                using (timeWarning = TimeWarning.New("OnPlayerVoice", (long)20))
                {
                    try
                    {
                        this.OnPlayerVoice(packet);
                    }
                    catch (Exception exception6)
                    {
                        this.Log(exception6);
                        Network.Net.sv.Kick(packet.connection, "Invalid Packet: Player Voice");
                    }
                }
                packet.connection.AddPacketsPerSecond(packet.type);
                return;
            }

            case Message.Type.EAC:
            {
                using (timeWarning = TimeWarning.New("OnEACMessage", (long)20))
                {
                    try
                    {
                        EACServer.OnMessageReceived(packet);
                    }
                    catch (Exception exception7)
                    {
                        this.Log(exception7);
                        Network.Net.sv.Kick(packet.connection, "Invalid Packet: EAC");
                    }
                }
                return;
            }

            default:
            {
                this.ProcessUnhandledPacket(packet);
                return;
            }
            }
            break;
        }
        }
    }