// 断开连接(Session/Disconnect) public static MQActionVoidResult Disconnect(string sessionId, ValueTypeParam <ClientTypeEnum> param) { Session session = SessionPool.RemoveByClientId(sessionId, param.Value); if (session != null && param.Value == ClientTypeEnum.Bet) { AccountMapping.RemoveBetServer(session); } else if (session != null && param.Value == ClientTypeEnum.Client) { AccountMapping.RemoveClients(session); } return(MQActionVoidResult.Ok()); }
/// <summary> /// 收到扫水结果 /// </summary> /// <param name="content">扫水结果</param> private void CollectResultEvent(CollectResult content) { CollectInformation ci = new CollectInformation(); ci.CollectPlatform = content.Platform; ci.CollectSessionID = content.CollectSessionID; ci.MaxBetMoney = content.MaxBetMoney; ci.Number = content.Number; var count = BetProcessPool.SetBetProcessCollect(content.Id, ci); //如果扫水完成 if (count == 0) { var colls = BetProcessPool.GetCollectByID(content.Id); if (null != colls) { //分析扫水结果 //->暂缺 //开始下注 foreach (CollectInformation item in colls) { //设置分配好的下注平台 BetProcessPool.AddBetListItemInBetProcess(content.Id, item.CollectPlatform); Task.Run(() => { BetContent bet = new BetContent(); bet.Id = content.Id; bet.BetPlatformEnum = item.CollectPlatform; bet.BuyerSessionID = content.BuyerSessionID; bet.ClientSessionID = content.ClientSessionID; bet.InputType = 1; //号码类型 bet.Money = 1; // 分配的金额 bet.Number = item.Number; MQActionVoidResult result = PublicData.RequestSocket.RequestSendReceive <MQActionVoidResult>(IdKeyData.Create(PublicData.SessionId, "Bet/AddBet", bet)); if (null != result && result.IsOK) { //记录命令发送成功 } else { //记录命令发送失败 } }); } } } }
/// <summary> /// 执行命令(返回json字符串) /// </summary> /// <param name="sessionId">客户端id</param> /// <param name="cmdText">Controler/Action</param> /// <param name="mqData">MQ数据</param> /// <returns></returns> public string ExecCmd(string sessionId, string cmdText, byte[] mqData) { if (_cmdActions.ContainsKey(cmdText)) { // (统一拦截Action的异常信息) try { MethodInfo method = _cmdActions[cmdText]; // todo 要放开检查校验逻辑(不重要不紧急,如果放开需要调整各Action权限检查) ////if (PublicData.IsStopped && //// method.GetCustomAttribute(typeof(NoNeedBettingStartAttribute)) == null) ////{ //// return JsonUtil.Serialize(MQActionVoidResult.Error(CommonErrors.CenterServerNotStart)); ////} // Action参数反序列号 List <object> arguments = new List <object>() { sessionId }; var paramsInfo = method.GetParameters(); if (paramsInfo.Length > 1) { arguments.Add(JsonUtil.Deserialize(mqData, paramsInfo[1].ParameterType)); } // 执行Action object result = method.Invoke(null, arguments.ToArray()); return(JsonUtil.Serialize(result)); } catch (Exception ex) { return(JsonUtil.Serialize(MQActionVoidResult.Error(ex.Message))); } } else if (cmdText == "IsRunning") { return(JsonUtil.Serialize(MQActionVoidResult.Ok())); } else { return(JsonUtil.Serialize(MQActionVoidResult.Error($"不存在命令:{cmdText}"))); } }
/// <summary> /// 处理下单结果 /// </summary> /// <param name="content"></param> private void BetContentEvent(BetContentResult content) { //收到下注结果 if (null != content) { BetInformation bet = new BetInformation(); bet.BetAccount = content.BetAccount; bet.BetMoney = content.BetMoney; bet.BetPlatform = content.BetPlatformEnum; bet.BetSessionID = content.BetSessionID; bet.DeleteOrderID = content.DeleteOrderID; bet.Number = content.Number; bet.Odds = content.Odds; bet.OperateTime = content.BetTime; bet.OrderID = content.OrderID; bet.Money = content.Money; //符合赔率 if (bet.Odds >= 9000) { bet.Status = ResultStatus.Success; } else { //退码 bet.Status = ResultStatus.Deleting; content.ResultStatus = ResultStatus.Deleting; MQActionVoidResult result = PublicData.RequestSocket.RequestSendReceive <MQActionVoidResult>(IdKeyData.Create(PublicData.SessionId, "Bet/DeleteBet", content)); if (null != result && result.IsOK) { //记录命令发送成功 } else { //记录命令发送失败 } } var count = BetProcessPool.SetBetProcessBetContent(content.Id, bet); if (count == 0) { //下单完成 可能存在已经退水了的 } } }
// 各个服务端发送心跳数据 public static MQActionVoidResult Heartbeat(string sessionId, HeartbeatParam param) { Session session = SessionPool.GetByClientId(sessionId, param.ClientType); if (session != null) { session.Heartbeat = DateTime.Now; if (param.platform.HasValue) { session.platform = param.platform; } return(MQActionVoidResult.Ok()); } else { return(MQActionVoidResult.Error($"{param.ClientType.ToClientTypeString()}连接中心服务器超时,请关闭重启")); } }
public static MQActionVoidResult ChangePassword(string sessionId, ChangePasswordParam param) { Session session = SessionPool.GetByClientId(sessionId, ClientTypeEnum.Client); if (session == null) { return(MQActionVoidResult.Error(CommonErrors.NotConnectingCenterServer)); } string result = SysMemberService.Instance.ChangePassword(session.SysmemberId, param); if (result == "1") { return(MQActionVoidResult.Ok()); } else { return(MQActionVoidResult.Error(result)); } }
/// <summary> /// 发送心跳线程 /// </summary> private void ThreadHeartbeat() { int heartbeatErrorCount = 0; while (!PublicData.CancellationToken.IsCancellationRequested && heartbeatErrorCount < 5) { try { MQActionVoidResult result = PublicData.RequestSocket.RequestSendReceive <MQActionVoidResult>( IdKeyData.Create(PublicData.SessionId, "Session/Heartbeat", new HeartbeatParam() { ClientType = ClientTypeEnum.Bet })); if (result.IsOK) { heartbeatErrorCount = 0; } else { heartbeatErrorCount++; LogError(Environment.NewLine + "投注服务端心跳失败,错误信息:" + result.ErrorMsg); } } catch (Exception ex) { heartbeatErrorCount++; LogError(Environment.NewLine + "Request发送心跳异常,错误信息:" + Environment.NewLine + ex.StackTrace); } Thread.Sleep(TimeSpan.FromSeconds(2)); } if (heartbeatErrorCount >= 5) { _mustClose = true; this.Close(); } }
/// <summary> /// 扫水线程 /// </summary> private void BetCollect() { var betProc = BetProcessPool.GetBetProcess(); if (null != betProc) { Collect col = new Collect(); col.Id = betProc.Id; col.BuyerSessionID = PublicData.SessionId; col.ClientSessionID = betProc.ClientSessionID; col.Number = betProc.Number; MQActionVoidResult result = PublicData.RequestSocket.RequestSendReceive <MQActionVoidResult>(IdKeyData.Create(PublicData.SessionId, "Collect/PushCollect", col)); if (null != result && result.IsOK) { //记录命令发送成功 } else { //记录命令发送失败 } } }
/// <summary> /// 发送心跳线程,保持与中心服务器连接 /// </summary> private void ThreadHeartbeat() { int heartbeatErrorCount = 0; while (!PublicData.CancellationToken.IsCancellationRequested && heartbeatErrorCount < 5) { try { MQActionVoidResult result = PublicData.RequestSocket.RequestSendReceive <MQActionVoidResult>( IdKeyData.Create(PublicData.SessionId, "Session/Heartbeat", new HeartbeatParam() { ClientType = ClientTypeEnum.Client })); if (result.IsOK) { heartbeatErrorCount = 0; } else { heartbeatErrorCount++; LogUtil.Warn(Environment.NewLine + "控盘端心跳失败,错误信息:" + result.ErrorMsg); } } catch (Exception ex) { heartbeatErrorCount++; LogUtil.Warn(Environment.NewLine + "控盘端Request发送心跳异常,错误信息:" + Environment.NewLine + ex.StackTrace); } Thread.Sleep(TimeSpan.FromSeconds(2)); } if (heartbeatErrorCount >= 5) { MessageBoxEx.Alert("您已掉线,请关闭重新启动!"); } }