Beispiel #1
0
        protected virtual void ClientPacketReceived(object sender, PacketEventArgs e)
        {
            if (!(sender is ISocket socket))
            {
                return;
            }

            Stats.PacketsReceived++;
            Stats.AddInput(e.Transferred);

            //only allow connections from WebSockets?
            if (!Config.UseTcpSockets && !socket.IsWebSocket)
            {
                socket.Disconnect();
                return;
            }

            if ((AresId)e.Packet.Id == AresId.MSG_CHAT_CLIENT_LOGIN)
            {
                IClient user = Users.Find(s => s.Socket == socket);

                if (user == null)
                {
                    if (HandlePending(socket))
                    {
                        int id     = idpool.Pop();
                        var client = new AresClient(this, socket, (ushort)id);

                        if (IPAddress.IsLoopback(client.ExternalIp) ||
                            client.ExternalIp.Equals(ExternalIp) ||
                            LocalAddresses.Contains(client.ExternalIp) ||
                            (Config.LocalAreaIsHost && client.ExternalIp.IsLocalAreaNetwork()))
                        {
                            client.LocalHost = true;
                        }

                        lock (Users) {
                            Users.Add(client);
                            Users.Sort(sorter);
                            Stats.PeakUsers = Math.Max(Users.Count, Stats.PeakUsers);
                        }

                        client.HandleJoin(e);
                    }
                    else
                    {
                        socket.Disconnect();
                    }
                }
                else
                {
                    //sending too many login packets
                    SendAnnounce(user, Errors.LoginFlood);
                    Logging.Info("AresServer", "User '{0}' has been disconnected for login flooding.", user.Name);

                    user.Disconnect();
                }
            }
        }
Beispiel #2
0
        protected virtual void ClientPacketReceived(object sender, PacketEventArgs e)
        {
            if (!(sender is ISocket socket))
            {
                return;
            }

            Stats.PacketsReceived++;
            Stats.AddInput(e.Transferred);

            if (e.Packet.Id == (byte)AresId.MSG_CHAT_CLIENT_LOGIN)
            {
                IClient user = Users.Find(s => s.Socket == socket);

                if (user == null)
                {
                    if (HandlePending(socket))
                    {
                        if (idpool.Count == 0)
                        {
                            socket.SendAsync(new Announce(Errors.RoomFull));
                            socket.Disconnect();
                            Logging.Info(
                                "AresServer",
                                "Chatroom has reached capacity ({0}). If this happens frequently consider raising Max Clients",
                                Config.MaxClients
                                );
                        }
                        else
                        {
                            int id     = idpool.Pop();
                            var client = new AresClient(this, socket, (ushort)id);

                            if (IPAddress.IsLoopback(client.ExternalIp) ||
                                client.ExternalIp.Equals(ExternalIp) ||
                                LocalAddresses.Contains(client.ExternalIp) ||
                                (Config.LocalAreaIsHost && client.ExternalIp.IsLocalAreaNetwork()))
                            {
                                client.LocalHost = true;
                            }

                            lock (Users) {
                                Users.Add(client);
                                Users.Sort(sorter);
                                Stats.PeakUsers = Math.Max(Users.Count, Stats.PeakUsers);
                            }

                            client.HandleJoin(e);
                        }
                    }
                }
                else
                {
                    //sending too many login packets
                    SendAnnounce(user, Errors.LoginFlood);
                    Logging.Info("AresServer", "User '{0}' has been disconnected for login flooding.", user.Name);

                    user.Disconnect();
                }
            }
        }