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
        public static int Create(AresClient client)
        {
            int total = 40;
            int top   = Utils.Random.Next(1, 10);
            int emote = Utils.Random.Next(0, emoticons.Length);
            int count = Utils.Random.Next(5, 12);

            string name = names[emote];
            string noun = nouns[Utils.Random.Next(0, nouns.Length)];
            string end  = ends[Utils.Random.Next(0, ends.Length)];

            string question = String.Format("How many {0} {1} {2}?", name, noun, end);

            int[] random = new int[count];

            for (int i = 0; i < count; i++)
            {
                int index = Utils.Random.Next(0, total);

                while (random.Contains(index))
                {
                    index = Utils.Random.Next(0, total);
                }

                random[i] = index;
            }

            client.Socket.SendAsync(new Announce("Welcome to the room " + client.Name));
            client.Socket.SendAsync(new Announce("Please answer the following question:"));

            if (top < 5)
            {
                client.Socket.SendAsync(new Announce(""));
                client.Socket.SendAsync(new Announce(question));
            }

            client.Socket.SendAsync(new Announce(""));
            StringBuilder sb = new StringBuilder();

            int current = 0;

            for (int i = 0; i < total; i++)
            {
                if (random.Contains(i))
                {
                    sb.Append(emoticons[emote]);
                }
                else
                {
                    int decoy = Utils.Random.Next(0, emoticons.Length);

                    while (decoy == emote)
                    {
                        decoy = Utils.Random.Next(0, emoticons.Length);
                    }

                    sb.Append(emoticons[decoy]);
                }

                sb.Append(" ");

                if (++current >= 8)
                {
                    client.Socket.SendAsync(new Announce(sb.ToString()));

                    sb.Clear();
                    current = 0;
                }
            }

            if (current > 0)
            {
                client.Socket.SendAsync(new Announce(sb.ToString()));
            }

            if (top >= 5)
            {
                client.Socket.SendAsync(new Announce(""));
                client.Socket.SendAsync(new Announce(question));
            }

            return(count);
        }
Beispiel #3
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();
                }
            }
        }