コード例 #1
0
        public ServerMessageHandler(ServerMessageManager manager)
        {
            this.m_started = true;

            this.m_sendQueue         = new ConcurrentQueue <QueueItem>();
            this.m_receiveQueue      = new ConcurrentQueue <ServerMessage>();
            this.m_sendResetEvent    = new AutoResetEvent(false);
            this.m_receiveResetEvent = new AutoResetEvent(false);
            this.m_messageManager    = manager;
            this.m_sendThread        = new Thread(this.Send);
            this.m_sendThread.Start();
            this.m_receiveThread = new Thread(this.Receive);
            this.m_receiveThread.Start();
        }
コード例 #2
0
        private void Receive()
        {
            while (this.m_started)
            {
                this.m_receiveResetEvent.WaitOne();

                while (this.m_receiveQueue.TryDequeue(out ServerMessage message))
                {
                    try
                    {
                        switch (message.GetMessageCategory())
                        {
                        case ServerMessageCategory.ACCOUNT:
                            this.m_messageManager.OnReceiveAccountMessage((ServerAccountMessage)message);
                            break;

                        case ServerMessageCategory.REQUEST:
                            this.m_messageManager.OnReceiveRequestMessage((ServerRequestMessage)message);
                            break;

                        case ServerMessageCategory.SESSION:
                            this.m_messageManager.OnReceiveSessionMessage((ServerSessionMessage)message);
                            break;

                        case ServerMessageCategory.RESPONSE:
                            ServerRequestManager.ResponseReceived((ServerResponseMessage)message);
                            break;

                        case ServerMessageCategory.CORE:
                            if (!ServerMessageManager.ReceiveCoreMessage((ServerCoreMessage)message))
                            {
                                this.m_messageManager.OnReceiveCoreMessage((ServerCoreMessage)message);
                            }
                            break;

                        default:
                            Logging.Error("ServerMessageHandler.receive: unknown message category: " + message.GetMessageCategory());
                            break;
                        }
                    }
                    catch (Exception exception)
                    {
                        Logging.Warning("ServerMessageHandler.receive: exception when the handle of message type " + message.GetMessageType() + ", trace: " + exception);
                    }
                }
            }
        }
コード例 #3
0
        internal static bool ReceiveCoreMessage(ServerCoreMessage message)
        {
            switch (message.GetMessageType())
            {
            case ServerMessageType.PING:
                ServerMessageManager.SendMessage(new PongMessage(), message.Sender);
                return(true);

            case ServerMessageType.SERVER_STATUS:
                ServerStatusMessage serverStatusMessage = (ServerStatusMessage)message;
                ServerStatus.SetStatus(serverStatusMessage.Type, serverStatusMessage.Time, serverStatusMessage.NextTime);
                return(true);

            default:
                return(false);
            }
        }