Exemplo n.º 1
0
        private void ServiceLeaves(core.LinkHub.LinkMode mode, ulong time)
        {
            foreach (core.LinkHub.Leaf leaf in core.LinkHub.LeafPool.Leaves)
            {
                core.LinkHub.LinkPacket packet = null;

                while ((packet = leaf.NextReceivedPacket) != null && leaf.SocketConnected)
                {
                    try
                    {
                        core.LinkHub.HubProcessor.Eval(leaf, packet.Msg, packet.Packet, time, mode);
                    }
                    catch (Exception e)
                    {
                        leaf.Disconnect();
                        Log("packet read fail from leaf " + leaf.Ident + " " + packet.Msg, e);
                        break;
                    }
                }

                leaf.SendReceive();

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

            core.LinkHub.LeafPool.Leaves.ForEachWhere(x => x.Disconnect(), x => !x.SocketConnected);
            core.LinkHub.LeafPool.Leaves.RemoveAll(x => !x.SocketConnected);
        }
Exemplo n.º 2
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);
            }
        }