Beispiel #1
0
        public IMXRT_FlexSPI(Machine machine) : base(machine)
        {
            IRQ = new GPIO();
            RegistersCollection = new DoubleWordRegisterCollection(this);
            lutMemory           = new byte[NumberOfLUTs * 4];

            rxQueue = new RandomAccessQueue(FifoDepth * 4);
            txQueue = new RandomAccessQueue(FifoDepth * 4);

            commandsEngine = new CommandsEngine(this);

            DefineRegisters();
            UpdateInterrupts();
        }
Beispiel #2
0
        public void Receive(ThePalaceEntities dbContext, object message)
        {
            var sessionState  = ((Message)message).sessionState;
            var protocol      = ((Message)message).protocol;
            var inboundPacket = (Protocols.MSG_TALK)protocol;
            var chatStr       = inboundPacket.text;

            Logger.ConsoleLog($"MSG_TALK[{sessionState.UserID}]: {chatStr}");

            if (CommandsEngine.Eval(dbContext, sessionState.UserID, 0, chatStr))
            {
                return;
            }

            if (!sessionState.Authorized)
            {
                if ((sessionState.userFlags & (int)UserFlags.U_Gag) != 0)
                {
                    return;
                }
            }

            SessionManager.SendToRoomID(sessionState.RoomID, 0, inboundPacket, EventTypes.MSG_TALK, (Int32)sessionState.UserID);
        }
        public static void Init()
        {
            threadManageConnections_InMilliseconds = ConfigManager.GetValue <int>("ThreadManageConnections_InMilliseconds", 750).Value;
            threadRefreshSettings_InMilliseconds   = ConfigManager.GetValue <int>("ThreadRefreshSettings_InMilliseconds", 15000).Value;
            threadManageAssets_InMilliseconds      = ConfigManager.GetValue <int>("ThreadManageAssets_InMilliseconds", 100).Value;
            threadManageFiles_InMilliseconds       = ConfigManager.GetValue <int>("ThreadManageFiles_InMilliseconds", 100).Value;
            threadManageQueue_InMilliseconds       = ConfigManager.GetValue <int>("ThreadManageQueue_InMilliseconds", 100).Value;
            threadAbortWait_InMilliseconds         = ConfigManager.GetValue <int>("ThreadAbortWait_InMilliseconds", 1000).Value;
            threadPause_InMilliseconds             = ConfigManager.GetValue <int>("ThreadPause_InMilliseconds", 500).Value;
            //threadWait_InMilliseconds = ConfigManager.GetValue<int>("ThreadWait_InMilliseconds", 60000).Value;
            threadManageAssetsMax = ConfigManager.GetValue <int>("ThreadManageAssetsMax", 4).Value;
            threadManageFilesMax  = ConfigManager.GetValue <int>("ThreadManageFilesMax", 4).Value;
            threadManageQueueMax  = ConfigManager.GetValue <int>("ThreadManageQueueMax", 4).Value;

            manageAssetsOutboundQueueSignalEvent.Reset();
            manageFilesQueueSignalEvent.Reset();
            manageMessagesQueueSignalEvent.Reset();
            serverShutdown.Reset();

            for (var j = 0; j < threadManageQueueMax; j++)
            {
                Action manageQueue = () =>
                {
                    do
                    {
                        SessionManager.ManageMessages();

                        manageMessagesQueueSignalEvent.WaitOne();

                        Thread.Sleep(threadManageQueue_InMilliseconds);
                    } while (!IsThreadAborted());
                };
                tasks[$"{nameof(manageQueue)}-{j}"] = Task.Factory.StartNew(manageQueue, cancelTokenSrc.Token);
            }

            for (var j = 0; j < threadManageFilesMax; j++)
            {
                Action manageFiles = () =>
                {
                    do
                    {
                        FileLoader.ManageFiles();

                        manageFilesQueueSignalEvent.WaitOne();

                        Thread.Sleep(threadManageFiles_InMilliseconds);
                    } while (!IsThreadAborted());
                };
                tasks[$"{nameof(manageFiles)}-{j}"] = Task.Factory.StartNew(manageFiles, cancelTokenSrc.Token);
            }


            for (var j = 0; j < threadManageAssetsMax; j++)
            {
                Action manageAssetsOutboundQueue = () =>
                {
                    do
                    {
                        AssetLoader.ManageAssetsOutboundQueue();

                        manageAssetsOutboundQueueSignalEvent.WaitOne();

                        Thread.Sleep(threadManageAssets_InMilliseconds);
                    } while (!IsThreadAborted());
                };
                tasks[$"{nameof(manageAssetsOutboundQueue)}-{j}"] = Task.Factory.StartNew(manageAssetsOutboundQueue, cancelTokenSrc.Token);
            }

            Action manageAssetsInboundQueue = () =>
            {
                do
                {
                    AssetLoader.ManageAssetsInboundQueue();

                    manageAssetsInboundQueueSignalEvent.WaitOne();

                    Thread.Sleep(threadManageAssets_InMilliseconds);
                } while (!IsThreadAborted());
            };

            tasks[nameof(manageAssetsInboundQueue)] = Task.Factory.StartNew(manageAssetsInboundQueue, cancelTokenSrc.Token);

            Action manageConnections = () =>
            {
                do
                {
                    PalaceAsyncSocket.ManageConnections();
                    //ProxyAsyncSocket.ManageConnections();
                    WebAsyncSocket.ManageConnections();

                    Thread.Sleep(threadManageConnections_InMilliseconds);
                } while (!IsThreadAborted());
            };

            tasks[nameof(manageConnections)] = Task.Factory.StartNew(manageConnections, cancelTokenSrc.Token);

            Action refreshSettings = () =>
            {
                do
                {
                    ServerState.RefreshSettings();

                    Thread.Sleep(threadRefreshSettings_InMilliseconds);
                } while (!IsThreadAborted());
            };

            tasks[nameof(refreshSettings)] = Task.Factory.StartNew(refreshSettings, cancelTokenSrc.Token);

            Action palaceAsyncSocket = () =>
            {
                do
                {
                    PalaceAsyncSocket.Init();

                    Thread.Sleep(threadRefreshSettings_InMilliseconds);
                } while (!IsThreadAborted());
            };

            tasks[nameof(palaceAsyncSocket)] = Task.Factory.StartNew(palaceAsyncSocket, cancelTokenSrc.Token);

            //Action proxyAsyncSocket = () =>
            //{
            //    do
            //    {
            //        ProxyAsyncSocket.Init();

            //        Thread.Sleep(threadRefreshSettings_InMilliseconds);
            //    } while (!IsThreadAborted());
            //};
            //tasks[nameof(proxyAsyncSocket)] = Task.Factory.StartNew(proxyAsyncSocket, cancelTokenSrc.Token);
#if (DEBUG)
            Action consoleInputThread = () =>
            {
                do
                {
                    var line = Console.ReadLine();

                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    using (var dbContext = Database.For <ThePalaceEntities>())
                    {
                        CommandsEngine.Eval(dbContext, 0xFFFFFFFF, 0, line);
                    }
                } while (!IsThreadAborted());
            };
            tasks[nameof(consoleInputThread)] = Task.Factory.StartNew(consoleInputThread, cancelTokenSrc.Token);
#endif
            WebAsyncSocket.Init();

            do
            {
                serverShutdown.WaitOne();
            } while (!IsThreadAborted());
        }
        public void Receive(ThePalaceEntities dbContext, object message)
        {
            var sessionState  = ((Message)message).sessionState;
            var protocol      = ((Message)message).protocol;
            var inboundPacket = (Protocols.MSG_XWHISPER)protocol;
            var chatStr       = inboundPacket.text;

            Logger.ConsoleLog($"MSG_XWHISPER[{sessionState.UserID} -> {inboundPacket.target}]: {chatStr}");

            if (CommandsEngine.Eval(dbContext, sessionState.UserID, inboundPacket.target, chatStr))
            {
                return;
            }

            if (!sessionState.Authorized)
            {
                if ((sessionState.userFlags & (int)UserFlags.U_Gag) != 0)
                {
                    return;
                }
            }

            if (!SessionManager.sessionStates.ContainsKey(inboundPacket.target))
            {
                var outboundPack = new Protocols.MSG_XTALK
                {
                    text = "Sorry, was unable to locate that user."
                };

                sessionState.Send(outboundPack, EventTypes.MSG_XTALK, 0);

                return;
            }

            var targetSessionState = SessionManager.sessionStates[inboundPacket.target];

            if (targetSessionState.RoomID == sessionState.RoomID && (targetSessionState.userFlags & (int)UserFlags.U_RejectPrivate) != 0)
            {
                var outboundPack = new Protocols.MSG_XTALK
                {
                    text = "Sorry, but this user has whispers turned off."
                };

                sessionState.Send(outboundPack, EventTypes.MSG_XTALK, 0);
            }
            else if (targetSessionState.RoomID != sessionState.RoomID && (targetSessionState.userFlags & (int)UserFlags.U_RejectEsp) != 0)
            {
                var outboundPack = new Protocols.MSG_XTALK
                {
                    text = "Sorry, but this user has ESP turned off."
                };

                sessionState.Send(outboundPack, EventTypes.MSG_XTALK, 0);
            }
            else
            {
                sessionState.Send(inboundPacket, EventTypes.MSG_XWHISPER, (Int32)sessionState.UserID);

                targetSessionState.Send(inboundPacket, EventTypes.MSG_XWHISPER, (Int32)sessionState.UserID);
            }
        }