public void Print(object text)
 {
     if (this.ProtoConnected)
     {
         this.QueuePacket(WebOutbound.NoSuchTo(this, text.ToString()));
     }
 }
        private static void Text(ib0tClient client, String args, ulong time)
        {
            String text = args;

            if (text.StartsWith("#login") || text.StartsWith("#register"))
            {
                Command(client, text.Substring(1));
                return;
            }

            if (text.StartsWith("#") && client.SocketConnected)
            {
                Command(client, text.Substring(1));
            }

            if (client.SocketConnected)
            {
                if (!client.Captcha)
                {
                    if (String.IsNullOrEmpty(client.CaptchaWord) || (client.CaptchaWord.Length > 0 && client.CaptchaWord.ToUpper() != Helpers.StripColors(text).Trim().ToUpper()))
                    {
                        if (client.CaptchaWord.Length > 0 && client.CaptchaWord.ToUpper() != Helpers.StripColors(text).Trim().ToUpper())
                        {
                            Events.CaptchaReply(client, text);

                            if (!client.SocketConnected)
                            {
                                return;
                            }
                        }

                        CaptchaItem cap = Captcha.Create();
                        client.CaptchaWord = cap.Word;
                        Events.CaptchaSending(client);
                        client.QueuePacket(WebOutbound.NoSuchTo(client, String.Empty));

                        foreach (String str in cap.Lines)
                        {
                            client.QueuePacket(WebOutbound.NoSuchTo(client, str));
                        }

                        client.QueuePacket(WebOutbound.NoSuchTo(client, String.Empty));
                        return;
                    }
                    else
                    {
                        client.Captcha = true;
                        Events.CaptchaReply(client, text);
                        CaptchaManager.AddCaptcha(client);

                        if (client.Quarantined)
                        {
                            client.Unquarantine();
                        }

                        return;
                    }
                }
                else
                {
                    Events.TextReceived(client, text);
                }
            }
            else
            {
                return;
            }

            if (client.SocketConnected)
            {
                text = Events.TextSending(client, text);

                if (!String.IsNullOrEmpty(text) && client.SocketConnected && !client.Muzzled)
                {
                    if (client.Idled)
                    {
                        uint seconds_away = (uint)((Time.Now - client.IdleStart) / 1000);
                        IdleManager.Remove(client);
                        Events.Unidled(client, seconds_away);
                    }

                    if (client.SocketConnected)
                    {
                        byte[] js_style = null;

                        UserPool.AUsers.ForEachWhere(x =>
                        {
                            if (x.SupportsHTML)
                            {
                                if (String.IsNullOrEmpty(client.CustomName) || x.BlockCustomNames)
                                {
                                    if (x.SupportsHTML)
                                    {
                                        if (js_style != null)
                                        {
                                            x.SendPacket(js_style);
                                        }
                                    }

                                    x.SendPacket(TCPOutbound.Public(x, client.Name, text));
                                }
                                else
                                {
                                    if (x.SupportsHTML)
                                    {
                                        if (js_style != null)
                                        {
                                            x.SendPacket(js_style);
                                        }
                                    }

                                    x.SendPacket(TCPOutbound.NoSuch(x, client.CustomName + text));
                                }
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(client.CustomName) || x.BlockCustomNames)
                                {
                                    x.SendPacket(TCPOutbound.Public(x, client.Name, text));
                                }
                                else
                                {
                                    x.SendPacket(TCPOutbound.NoSuch(x, client.CustomName + text));
                                }
                            }
                        }, x => x.LoggedIn && x.Vroom == client.Vroom && !x.IgnoreList.Contains(client.Name) && !x.Quarantined);

                        UserPool.WUsers.ForEachWhere(x => x.QueuePacket(String.IsNullOrEmpty(client.CustomName) ?
                                                                        ib0t.WebOutbound.PublicTo(x, client.Name, text) : ib0t.WebOutbound.NoSuchTo(x, client.CustomName + text)),
                                                     x => x.LoggedIn && x.Vroom == client.Vroom && !x.IgnoreList.Contains(client.Name) && !x.Quarantined);

                        if (ServerCore.Linker.Busy && ServerCore.Linker.LoginPhase == LinkLeaf.LinkLogin.Ready)
                        {
                            ServerCore.Linker.SendPacket(LinkLeaf.LeafOutbound.LeafPublicText(ServerCore.Linker, client.Name, text));
                        }

                        Events.TextSent(client, text);
                    }
                }
            }
        }
        private static void Login(ib0tClient client, String args, ulong time)
        {
            String[] arg_items = GetArgItems(args);

            client.Extended = int.Parse(arg_items[0]) >= 2000;

            byte[] g = new byte[16];

            for (int i = 0; i < g.Length; i++)
            {
                g[i] = byte.Parse(arg_items[1].Substring((i * 2), 2), NumberStyles.HexNumber);
            }

            using (MD5 md5 = MD5.Create())
                client.Guid = new Guid(md5.ComputeHash(g));

            client.OrgName = arg_items[2].Trim();
            Helpers.FormatUsername(client);
            client.Name         = client.OrgName;
            client.FastPing     = false;
            client.FileCount    = 0;
            client.DataPort     = 0;
            client.NodeIP       = IPAddress.Parse("0.0.0.0");
            client.NodePort     = 0;
            client.Version      = arg_items[4] + " [" + arg_items[3] + "]";
            client._pmsg        = arg_items[4];
            client.CustomClient = true;
            client.LocalIP      = client.ExternalIP;
            client.Browsable    = false;
            client.Age          = 0;
            client.Sex          = 0;
            client.Country      = 0;
            client.Region       = String.Empty;
            IPAddress p_check = new IPAddress(client.ExternalIP.GetAddressBytes());

            ObSalt.GetSalt(client);
            client.Captcha = !Settings.Get <bool>("captcha");

            if (!client.Captcha)
            {
                client.Captcha = CaptchaManager.HasCaptcha(client);
            }

            if ((UserPool.AUsers.FindAll(x => x.ExternalIP.Equals(client.ExternalIP)).Count +
                 UserPool.WUsers.FindAll(x => x.ExternalIP.Equals(client.ExternalIP)).Count) > 3)
            {
                Events.Rejected(client, RejectedMsg.TooManyClients);
                throw new Exception("too many clients from this ip");
            }

            if (UserHistory.IsJoinFlooding(client, time))
            {
                Events.Rejected(client, RejectedMsg.TooSoon);
                throw new Exception("joined too quickly");
            }

            IClient hijack = UserPool.AUsers.Find(x => (x.Name == client.Name ||
                                                        x.OrgName == client.OrgName) && x.ID != client.ID && x.LoggedIn);

            if (hijack == null)
            {
                hijack = UserPool.WUsers.Find(x => (x.Name == client.Name ||
                                                    x.OrgName == client.OrgName) && x.ID != client.ID && x.LoggedIn);
            }

            if (hijack != null)
            {
                if (hijack.ExternalIP.Equals(client.ExternalIP))
                {
                    if (!hijack.WebClient)
                    {
                        ((AresClient)hijack).Disconnect(true);
                    }
                    else
                    {
                        ((ib0t.ib0tClient)hijack).Disconnect();
                    }

                    client.Name = client.OrgName;
                }
                else
                {
                    Events.Rejected(client, RejectedMsg.NameInUse);
                    throw new Exception("name in use");
                }
            }

            UserHistory.AddUser(client, time);

            if (BanSystem.IsBanned(client))
            {
                if (!Helpers.IsLocalHost(client))
                {
                    if (hijack != null && hijack is AresClient)
                    {
                        ((AresClient)hijack).SendDepart();
                    }

                    Events.Rejected(client, RejectedMsg.Banned);
                    throw new Exception("banned user");
                }
            }

            if (Proxies.Check(p_check, client.DNS))
            {
                if (!Helpers.IsLocalHost(client))
                {
                    if (Events.ProxyDetected(client))
                    {
                        if (hijack != null && hijack is AresClient)
                        {
                            ((AresClient)hijack).SendDepart();
                        }

                        Events.Rejected(client, RejectedMsg.Proxy);
                        throw new Exception("proxy detected");
                    }
                }
            }

            client.Quarantined = !client.Captcha && Settings.Get <int>("captcha_mode") == 1;

            if (!Events.Joining(client))
            {
                if (!Helpers.IsLocalHost(client))
                {
                    if (hijack != null && hijack is AresClient)
                    {
                        ((AresClient)hijack).SendDepart();
                    }

                    Events.Rejected(client, RejectedMsg.UserDefined);
                    throw new Exception("user defined rejection");
                }
            }

            if (Helpers.IsLocalHost(client))
            {
                client.Captcha     = true;
                client.Quarantined = false;
                client.Registered  = true;
                client.Owner       = true;
            }

            if (!client.Quarantined)
            {
                if (hijack == null || !(hijack is AresClient))
                {
                    LinkLeaf.LinkUser other = null;

                    if (ServerCore.Linker.Busy)
                    {
                        foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves)
                        {
                            other = leaf.Users.Find(x => x.Vroom == client.Vroom && x.Name == client.Name && x.Link.Visible);

                            if (other != null)
                            {
                                other.LinkCredentials.Visible = false;
                                break;
                            }
                        }
                    }

                    UserPool.AUsers.ForEachWhere(x => x.SendPacket(other == null ? TCPOutbound.Join(x, client) : TCPOutbound.UpdateUserStatus(x, client)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                    UserPool.WUsers.ForEachWhere(x => x.QueuePacket(other == null ? ib0t.WebOutbound.JoinTo(x, client.Name, client.Level) : ib0t.WebOutbound.UpdateTo(x, client.Name, client.Level)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);
                }

                client.LoggedIn = true;
                client.QueuePacket(WebOutbound.AckTo(client, client.Name));
                client.QueuePacket(WebOutbound.TopicFirstTo(client, Settings.Get <String>("topic")));
                client.QueuePacket(WebOutbound.UserlistItemTo(client, Settings.Get <String>("bot"), ILevel.Host));

                UserPool.AUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.UserlistItemTo(client, x.Name, x.Level)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                UserPool.WUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.UserlistItemTo(client, x.Name, x.Level)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                if (ServerCore.Linker.Busy)
                {
                    foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves)
                    {
                        leaf.Users.ForEachWhere(x => client.QueuePacket(WebOutbound.UserlistItemTo(client, x.Name, x.Level)),
                                                x => x.Vroom == client.Vroom && x.Link.Visible);
                    }
                }

                client.QueuePacket(WebOutbound.UserlistEndTo(client));
                client.QueuePacket(WebOutbound.UrlTo(client, Settings.Get <String>("link", "url"), Settings.Get <String>("text", "url")));

                UserPool.AUsers.ForEachWhere(x => x.SendPacket(TCPOutbound.Avatar(x, client)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                UserPool.WUsers.ForEachWhere(x => x.QueuePacket(WebOutbound.AvatarTo(x, client.Name, client.Avatar)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && x.Extended);

                UserPool.AUsers.ForEachWhere(x => x.SendPacket(TCPOutbound.PersonalMessage(x, client)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                UserPool.WUsers.ForEachWhere(x => x.QueuePacket(WebOutbound.PersMsgTo(x, client.Name, client.PersonalMessage)),
                                             x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && x.Extended);

                if (client.Extended)
                {
                    client.QueuePacket(WebOutbound.PerMsgBotTo(client));

                    if (Avatars.GotServerAvatar)
                    {
                        client.QueuePacket(Avatars.Server(client));
                    }

                    UserPool.AUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.AvatarTo(client, x.Name, x.Avatar)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && x.Avatar.Length > 0 && !x.Quarantined);

                    UserPool.WUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.AvatarTo(client, x.Name, x.Avatar)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                    if (ServerCore.Linker.Busy)
                    {
                        foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves)
                        {
                            leaf.Users.ForEachWhere(x => client.QueuePacket(WebOutbound.AvatarTo(client, x.Name, x.Avatar)),
                                                    x => x.Vroom == client.Vroom && x.Link.Visible && x.Avatar.Length > 0);
                        }
                    }

                    UserPool.AUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.PersMsgTo(client, x.Name, x.PersonalMessage)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && x.PersonalMessage.Length > 0 && !x.Quarantined);

                    UserPool.WUsers.ForEachWhere(x => client.QueuePacket(WebOutbound.PersMsgTo(client, x.Name, x.PersonalMessage)),
                                                 x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined);

                    UserPool.AUsers.ForEachWhere(x =>
                    {
                        AresFont f = (AresFont)x.Font;
                        client.QueuePacket(WebOutbound.FontTo(client, x.Name, f.oldN, f.oldT));
                    }, x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && x.Font.Enabled);

                    if (ServerCore.Linker.Busy)
                    {
                        foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves)
                        {
                            leaf.Users.ForEachWhere(x => client.QueuePacket(WebOutbound.PersMsgTo(client, x.Name, x.PersonalMessage)),
                                                    x => x.Vroom == client.Vroom && x.Link.Visible && x.PersonalMessage.Length > 0);
                        }
                    }
                }

                FloodControl.Remove(client);

                if (client.SocketConnected)
                {
                    IdleManager.Set(client);
                }

                if (ServerCore.Linker.Busy && ServerCore.Linker.LoginPhase == LinkLeaf.LinkLogin.Ready)
                {
                    ServerCore.Linker.SendPacket(LinkLeaf.LeafOutbound.LeafJoin(ServerCore.Linker, client));
                }

                Events.Joined(client);

                if (client.Owner)
                {
                    client.Level = ILevel.Host;
                }
            }
            else
            {
                if (hijack != null && hijack is AresClient)
                {
                    ((AresClient)hijack).SendDepart();
                }

                client.LoggedIn = true;
                client.QueuePacket(WebOutbound.AckTo(client, client.Name));
                client.QueuePacket(WebOutbound.TopicFirstTo(client, Settings.Get <String>("topic")));
                client.QueuePacket(WebOutbound.UserlistEndTo(client));
                client.QueuePacket(WebOutbound.PerMsgBotTo(client));
                client.QueuePacket(Avatars.Server(client));

                CaptchaItem cap = Captcha.Create();
                client.CaptchaWord = cap.Word;
                Events.CaptchaSending(client);
                client.QueuePacket(WebOutbound.NoSuchTo(client, String.Empty));

                foreach (String str in cap.Lines)
                {
                    client.QueuePacket(WebOutbound.NoSuchTo(client, str));
                }

                client.QueuePacket(WebOutbound.NoSuchTo(client, String.Empty));
            }
        }