Пример #1
0
        public void Close()
        {
            Settings.RUNNING = false;
            this.Running     = false;
            this.terminate   = true;

            try
            {
                this.tcp.Stop();
            }
            catch
            {
            }

            try
            {
                this.udp.Stop();
            }
            catch
            {
            }

            UserPool.Destroy();
            core.LinkHub.LeafPool.Destroy();
            UdpChannelList.Stop();

            if (Linker != null)
            {
                Linker.KillSocket();
            }
        }
Пример #2
0
        private void CheckTCPListener(ulong time)
        {
            if (this.tcp.Active)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (!this.tcp.Pending())
                    {
                        break;
                    }

                    Socket sock = this.tcp.AcceptSocket();

                    if (!this.udp.IsTcpChecker(sock))
                    {
                        UserPool.CreateAresClient(sock, time);
                    }
                }
            }
        }
Пример #3
0
        private void ServiceAresSockets(ulong time)
        {
            foreach (AresClient client in UserPool.AUsers)
            {
                if (!String.IsNullOrEmpty(client.DNS))
                {
                    if (client.IsHTML)
                    {
                        if (Settings.Get <bool>("enabled", "web"))
                        {
                            UserPool.CreateIb0tClient(client, time);
                        }
                        else
                        {
                            client.Disconnect();
                        }
                        break;
                    }

                    if (client.IsWebWorker)
                    {
                        UserPool.CreateWW(client);
                        client.Disconnect();
                        break;
                    }

                    TCPPacket packet = null;

                    while ((packet = client.NextReceivedPacket) != null && client.SocketConnected)
                    {
                        if (packet.Msg == TCPMsg.MSG_CHAT_CLIENTCOMPRESSED)
                        {
                            client.InsertUnzippedData(Zip.Decompress(packet.Packet.ToArray()));
                        }
                        else
                        {
                            try
                            {
                                TCPProcessor.Eval(client, packet, time);

                                if (client.IsLeaf)
                                {
                                    break;
                                }
                            }
                            catch (Exception e)
                            {
                                client.Disconnect();

                                if (packet.Msg != TCPMsg.MSG_CHAT_ADVANCED_FEATURES_PROTOCOL)
                                {
                                    Log("packet read fail from " + client.ExternalIP + " " + packet.Msg, e);
                                }
                                else if (packet.Packet.ToArray().Length >= 3)
                                {
                                    Log(
                                        "packet read fail from " + client.ExternalIP + " " +
                                        (TCPMsg)packet.Packet.ToArray()[2], e);
                                }
                                else
                                {
                                    Log("packet read fail from " + client.ExternalIP + " (Advanced Protocol Exploit)", e);
                                }


                                break;
                            }
                        }
                    }

                    if (client.IsLeaf)
                    {
                        continue;
                    }

                    client.SendReceive();

                    if (client.SocketConnected)
                    {
                        client.EnforceRules(time);
                    }
                }
            }

            UserPool.AUsers.ForEachWhere(x => x.Disconnect(), x => !x.SocketConnected);
            UserPool.AUsers.RemoveAll(x => !x.SocketConnected || x.IsLeaf);
        }
Пример #4
0
        private void ServerThread()
        {
            this.terminate = false;

            FilterImporter.DoTasks();
            ObSalt.Init();
            CaptchaManager.Load();
            FloodControl.Reset();
            Stats.Reset();
            UserPool.Build();
            core.LinkHub.LeafPool.Build();
            Captcha.Initialize();
            UserHistory.Initialize();
            AccountManager.LoadPasswords();
            BanSystem.LoadBans();
            IdleManager.Reset();
            Proxies.Start(Helpers.UnixTime);
            IgnoreManager.init();

            if (Settings.Get <bool>("roomsearch"))
            {
                UdpChannelList.Start();
            }

            ulong last_update_check  = 0;
            ulong fast_ping_timer    = Time.Now;
            ulong channel_push_timer = (Time.Now - 1200000);
            ulong reset_floods_timer = Time.Now;
            ulong room_search_timer  = (Time.Now - 1800000);
            bool  can_web_chat       = Settings.Get <bool>("enabled", "web");

            core.LinkHub.LinkMode link_mode = (core.LinkHub.LinkMode)Settings.Get <int>("link_mode");
            Linker = new LinkLeaf.LinkClient();

            if (link_mode == LinkHub.LinkMode.Hub)
            {
                Linker.ConnectLocal();
            }

            Events.ServerStarted();

            while (true)
            {
                if (this.terminate)
                {
                    break;
                }

                ulong time = Time.Now;

                if (time > (last_update_check + (30 * 60 * 1000)))
                {
                    last_update_check = time;
                    CheckLatestVersion();
                }

                if (time > (fast_ping_timer + 2000))
                {
                    fast_ping_timer = time;

                    UserPool.AUsers.ForEachWhere(x => x.SendPacket(TCPOutbound.FastPing()),
                                                 x => x.LoggedIn && x.FastPing);

                    BanSystem.AutoClearBans();
                    Avatars.CheckAvatars(time);
                }

                if (time > (reset_floods_timer + 60000))
                {
                    reset_floods_timer = time;
                    FloodControl.Reset();
                    Proxies.Updater(Helpers.UnixTime);
                }

                this.udp.ServiceUdp(time);
                this.CheckTCPListener(time);
                this.ServiceAresSockets(time);
                this.ServiceLeaves(link_mode, time);
                this.ServiceWW();
                Linker.Service(time);

                if (can_web_chat)
                {
                    this.ServiceWebSockets(time);

                    if (time > (channel_push_timer + 1200000))
                    {
                        channel_push_timer = time;
                        ib0t.ChannelPusher.Push();
                    }
                }

                if (time > (room_search_timer + 1800000))
                {
                    room_search_timer = time;

                    if (Settings.Get <bool>("roomsearch"))
                    {
                        UdpChannelList.Update();
                    }
                }

                Events.CycleTick();
                Thread.Sleep(25);
            }
        }