Example #1
0
        public static WsControllerMessage FromJson(string json)
        {
            var jobject = new JSONObject(json);

            var msg = new WsControllerMessage
            {
                AckId  = jobject.HasField("ackId") ? jobject["ackId"].Int : -1,
                OpCode = jobject.HasField("opcode") ? jobject["opcode"].String : string.Empty,
                Data   = jobject.HasField("data") ? jobject["data"] : JSONObject.Null
            };

            return(msg);
        }
Example #2
0
        private void HttpServerModule_OnUpdateEvent()
        {
            if (messageQueueData.Count <= 0)
            {
                return;
            }

            lock (messageQueueData)
            {
                while (messageQueueData.Count > 0)
                {
                    try
                    {
                        var msg = WsControllerMessage.FromJson(messageQueueData.Dequeue());

                        if (messageHandlers.ContainsKey(msg.OpCode))
                        {
                            messageHandlers[msg.OpCode].Handle(msg, this);
                        }
                        else
                        {
                            msg.Error = $"No handler with opcode [{msg.OpCode}] found";
                            msg.Data  = null;

                            Send(msg.ToString());
                        }
                    }
                    catch (Exception e)
                    {
                        var msg = new WsControllerMessage
                        {
                            Error = e.Message,
                            Data  = null
                        };

                        Send(msg.ToString());
                    }
                }
            }
        }
Example #3
0
 public void Handle(WsControllerMessage message, WsControllerService service)
 {
     OnMessage?.Invoke(message, service);
 }