Ejemplo n.º 1
0
        public override void ExecuteCommand(GameUserSession session, SubRequestInfo requestInfo)
        {
            try
            {
                InitInData(requestInfo.Body, session);

                if (Data != null)
                {
                    session.GameAttr.UserOpenId = this.Data.OpenId;

                    var msgData = HandleData(session, this.Data);
                    if (msgData != null)
                    {
                        GameMessageHandle.Push(msgData, session);
                    }
                }
            }
            catch (Exception ex)
            {
                GameMessageHandle.PushErrorMsg(ex.Message, session);
            }

            if (session.Connected)
            {
                GameMessageHandle.Run(session.GameServer);
            }
        }
Ejemplo n.º 2
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     foreach (var p in requestInfo.Body.Split(' '))
     {
         session.Send(p);
     }
 }
Ejemplo n.º 3
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     foreach (var p in requestInfo.Body.Split(' '))
     {
         session.Send(p);
     }
 }
Ejemplo n.º 4
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     var paramsArray = requestInfo.Body.Split(' ');
     for (var i = 0; i < paramsArray.Length; i++)
     {
         session.Send(paramsArray[i]);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 第二个参数
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static string ToSecParam(this SubRequestInfo info)
        {
            var key  = info.Key;
            var body = info.Body;

            string secondParam = body.Substring(body.IndexOf(" ") + 1);

            return(secondParam);
        }
Ejemplo n.º 6
0
        public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
        {
            var paramsArray = requestInfo.Data.Split(' ');

            for (var i = 0; i < paramsArray.Length; i++)
            {
                session.SendResponse(paramsArray[i]);
            }
        }
Ejemplo n.º 7
0
        public override void ExecuteCommand(CRMSession session, SubRequestInfo requestInfo)
        {
            var message = session.Name + ": " + requestInfo.Body;

            foreach (var s in session.AppServer.GetAllSessions())
            {
                s.Send(message);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// XXXX {}#
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static SendBaseModel ToBaseModel(this SubRequestInfo info)
        {
            var key  = info.Key;
            var body = info.Body;

            var request = JsonHelper.DeserializeJsonToObject <SendBaseModel>(body);

            return(request);
        }
Ejemplo n.º 9
0
 public void ExcuteRequestPackage(SubRequestInfo requestInfo)
 {
     try
     {
         ExcuteRequestPackage(new ipp_Package(requestInfo.Body));
     }
     catch (Exception e)
     {
         this.Send(Encoding.Default.GetBytes("Error"), 0, 5);
     }
 }
Ejemplo n.º 10
0
        public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
        {
            try
            {
                var    request    = requestInfo.ToSendModel();
                string firstParam = requestInfo.ToFirstParam();
                var    toSessions = MyAppServer.Sessions;


                if (string.IsNullOrWhiteSpace(firstParam))
                {
                    Logger.Error("命令发送错误");
                    return;
                }
                //else if (request.Content == null)
                //{
                //    toSessions = toSessions.Where(s => s.Address == request.ToDeviceId).ToList();
                //    toSessions.ForEach(s =>
                //    {
                //        s.Send(firstParam, request);
                //    });
                //}
                //else if (request.Content != null)
                //{
                //if (firstParam.ToLower() == "reply") //回复
                //{
                //    toSessions = toSessions.Where(s => s.Address == request.FromDeviceId).ToList();
                //}
                //else //发送
                //{
                //    var fromDevice = MyAppServer.Sessions.FirstOrDefault(s => s.SessionId == session.SessionID);
                //    request.FromDeviceId = fromDevice.IP + "," + fromDevice.DeviceId;

                //    var toDevice = request.ToDeviceId.ToDeivce();
                //    toSessions = toSessions.Where(s => s.Address == request.ToDeviceId).ToList();

                //}

                var fromDevice = MyAppServer.Sessions.FirstOrDefault(s => s.SessionId == session.SessionID);
                request.FromDeviceId = fromDevice.Address;

                toSessions = toSessions.Where(s => s.Address == request.ToDeviceId).ToList();
                toSessions.ForEach(s =>
                {
                    s.Send(firstParam, request);
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message + "");
            }
        }
Ejemplo n.º 11
0
        public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
        {
            try
            {
                TestLogger.Log(requestInfo.ToString2());
                var request = requestInfo.ToBaseModel();
                var obj     = JsonHelper.DeserializeJsonToObject <ConnectionModel>(request.Content + "");

                var sessions = MyAppServer.Sessions
                               .Where(s => s.AppSession != null)
                               .ToList();
                sessions.ForEach(s =>
                {
                    if (!string.IsNullOrEmpty(s.DeviceId))
                    {
                        s.SetIdState = SetIdState.HadSet;
                    }
                    else
                    {
                        s.SetIdState = SetIdState.NotSet;
                    }
                });



                var data = sessions.Select(s => new
                {
                    s.Ip,
                    s.DeviceId,
                    s.SetIdState,
                    s.IsThree
                }).ToList();

                string message = "Reply " + JsonHelper.SerializeObject(new SendBaseModel
                {
                    Content = new ReplyModel
                    {
                        Data    = data,
                        Message = Encoding.UTF8.GetBytes("获取成功").ToString(),
                        Success = 1
                    },
                    CommandId = request.CommandId
                });
                TestLogger.Log(message);

                session.Send(message);
            }
            catch (Exception ex)
            {
                TestLogger.Log(ex.Message + "");
            }
        }
Ejemplo n.º 12
0
 public override void ExecuteCommand(AMSession session, SubRequestInfo requestInfo)
 {
     if (!string.IsNullOrEmpty(requestInfo.Body))
     {
         var sessions = session.AppServer.GetSessions(s => s.SessionID != session.SessionID);
         foreach (var s in sessions)
         {
             s.TrySend(requestInfo.Body);
         }
     }
     else
     {
         session.TrySend(JsonConvert.SerializeObject(new { type = "error", message = "请输入要发送的消息体" }));
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 第一个参数
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static string ToFirstParam(this SubRequestInfo info)
        {
            string firstParam = "";

            try
            {
                var key  = info.Key;
                var body = info.Body;


                firstParam = body.Substring(0, body.IndexOf(" "));
            }
            catch (Exception)
            {
                firstParam = "";
            }
            return(firstParam);
        }
Ejemplo n.º 14
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     try
     {
         Logger.Error(requestInfo.ToString2());
         var request = requestInfo.ToBaseModel();
         var obj     = JsonHelper.DeserializeJsonToObject <ChangeAllModel>(request.Content + "");
         if (obj != null)
         {
             MyAppServer.Sessions.Where(s => s.AppSession != null).ToList().ForEach(s =>
             {
                 s.Send("change", request);
             });
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message);
     }
 }
Ejemplo n.º 15
0
        public override void ExecuteCommand(AMSession session, SubRequestInfo requestInfo)
        {
            if (!string.IsNullOrEmpty(requestInfo.Body))
            {
                VerifyIdentity auth = JsonConvert.DeserializeObject <VerifyIdentity>(requestInfo.Body);
                if (string.IsNullOrEmpty(auth.identity) && string.IsNullOrEmpty(auth.terminal))
                {
                    session.TrySend(JsonConvert.SerializeObject(new { type = "error", message = "请输入身份验证信息" }));
                }
                else
                {
                    session.Terminal = auth.terminal;
                    if (!string.IsNullOrEmpty(auth.identity))
                    {
                        session.Identity = auth.identity;
                    }
                    else
                    {
                        session.Identity = session.SessionID;
                    }

                    //表示验证成功,客户端可以记录重连了。
                    session.TrySend(JsonConvert.SerializeObject(new { type = "verifyed", message = session.SessionID }));
                    if (auth.terminal == "display")
                    {
                        if (session.AppServer.GetAllSessions().Any(s => s.Terminal == "control"))
                        {
                            var control = session.AppServer.GetSessions(s => s.Terminal == "control").FirstOrDefault();
                            control.TrySend(JsonConvert.SerializeObject(new { type = "displayed", message = "显示已接入,可以进行控制" }));
                        }
                    }
                    session.TrySend(JsonConvert.SerializeObject(new { type = "log", message = "身份验证成功。终端是:" + session.Terminal + ",身份是:" + session.Identity }));
                }
            }
            else
            {
                session.TrySend(JsonConvert.SerializeObject(new { type = "error", message = "请输入身份验证信息" }));
            }
        }
Ejemplo n.º 16
0
        protected override void HandleUnknownCommand(SubRequestInfo requestInfo)
        {
            var remoteEndPoint = this.RemoteEndPoint.Address.ToString();

            Logger.Trace("Executing command: {0}. Device: {1}. IP: {2} ", requestInfo.Key, this.DeviceId, remoteEndPoint);

            try
            {
                var messageString = requestInfo.Key + " " + requestInfo.Body;

                var commandResolver = new CommandResolver(messageString);
                var command         = commandResolver.GetCommand();

                var commandExecutor = _commandExecutorCreator();
                commandExecutor.Execute(this, command);

                Logger.Trace("Executed command: {0}. Device: {1}. IP: {2}.", requestInfo.Key, this.DeviceId, remoteEndPoint);
            }
            catch (Exception ex)
            {
                Logger.Error("Executed command with Exception: {0}. Device: {1}. IP: {2}. Exception: {3}",
                             requestInfo.Key, this.DeviceId, remoteEndPoint, ex.ToString());
            }
        }
Ejemplo n.º 17
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     session.SendResponse(requestInfo.Data);
 }
Ejemplo n.º 18
0
 protected override void HandleUnknownCommand(SubRequestInfo requestInfo)
 {
     base.HandleUnknownCommand(requestInfo);
 }
Ejemplo n.º 19
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     session.ProtocolProcessor.SendPing(session, new byte[0]);
 }
Ejemplo n.º 20
0
 public override void ExecuteCommand(CustomSession session, SubRequestInfo requestInfo)
 {
     var paramArray = requestInfo.Body.Split('#');
 }
Ejemplo n.º 21
0
 public override void ExecuteCommand(TripSession session, SubRequestInfo requestInfo)
 {
     session.ExcuteRequestPackage(requestInfo);
 }
Ejemplo n.º 22
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     session.ProtocolProcessor.SendPing(session, new byte[0]);
 }
Ejemplo n.º 23
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     session.Send(requestInfo.Body);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Send XXXX {}#
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static SendBaseModel ToSendModel(this SubRequestInfo info)
        {
            var request = JsonHelper.DeserializeJsonToObject <SendBaseModel>(info.ToSecParam());

            return(request);
        }
Ejemplo n.º 25
0
        public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
        {
            var paramArray = requestInfo.Body.Split(' ');

            session.Send((int.Parse(paramArray[0]) + int.Parse(paramArray[1])).ToString());
        }
Ejemplo n.º 26
0
        public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
        {
            try
            {
                TestLogger.Log(requestInfo.ToString2());
                var    request    = requestInfo.ToSendModel();
                string firstParam = requestInfo.ToFirstParam();
                var    toSessions = MyAppServer.Sessions;


                if (string.IsNullOrWhiteSpace(firstParam))
                {
                    TestLogger.Log("命令发送错误");
                    return;
                }
                else if (request.Content == null)
                {
                    var toDevice = request.ToDeviceId.ToDeivce();
                    toSessions = toSessions.Where(s => s.DeviceId == toDevice.DeviceId && s.Ip == toDevice.Ip).ToList();
                    toSessions.ForEach(s =>
                    {
                        var message = firstParam + "#";
                        TestLogger.Log(message);
                        s.Send(message);
                    });
                }
                else if (request.Content != null)
                {
                    if (firstParam.ToLower() == "reply") //回复
                    {
                        var fromDevice = request.FromDeviceId.ToDeivce();
                        if (fromDevice != null)
                        {
                            toSessions = toSessions.Where(s => s.DeviceId == fromDevice.DeviceId && s.Ip == fromDevice.DeviceId).ToList();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else //发送
                    {
                        var fromDevice = MyAppServer.Sessions.FirstOrDefault(s => s.SessionId == session.SessionID);
                        if (fromDevice != null)
                        {
                            request.FromDeviceId = fromDevice.Ip + "," + fromDevice.DeviceId;

                            var toDevice = request.ToDeviceId.ToDeivce();
                            toSessions = toSessions.Where(s => s.DeviceId == toDevice.DeviceId && s.Ip == toDevice.Ip).ToList();
                        }
                        else
                        {
                            return;
                        }
                    }

                    toSessions.ForEach(s =>
                    {
                        var message = CommandHelper.GetCmdStr(firstParam, request);
                        TestLogger.Log(message);
                        s.Send(message);
                    });
                }
            }
            catch (Exception ex)
            {
                TestLogger.Log(ex.Message + "");
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Handle Unknown request
 /// </summary>
 /// <param name="content">The package sub content.</param>
 protected override void HandleUnknownCommand(SubRequestInfo content)
 {
     Logger.Debug($"Manager::HandleUnknownRequest - Unknown package. Content: {content}");
 }
Ejemplo n.º 28
0
 public static string ToString2(this SubRequestInfo value)
 {
     return(value.Key + " " + value.Body);
 }
Ejemplo n.º 29
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     session.Close();
 }
Ejemplo n.º 30
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     session.SendResponse(requestInfo.Data);
 }
Ejemplo n.º 31
0
 public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
 {
     session.Close();
 }
Ejemplo n.º 32
0
 public override void ExecuteCommand(MessageSocketSession session, SubRequestInfo requestInfo)
 {
     session.EventMessageServerSessionExcute(new Model.EventMessageServerModel(EnumMessageInfo.Log, "Status", session.SessionID));
     session.Cookies["ConnectTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
     session.Send(Model.EnumCommand.Status.ToString());
 }