protected override async void Run(Session session, C2G_FriendRoomInfo message, Action <G2C_FriendRoomInfo> reply) { G2C_FriendRoomInfo response = new G2C_FriendRoomInfo(); try { //获取房间信息 DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); User user = session.GetComponent <SessionUserComponent>().User; List <PlayerBaseInfo> playerInfoList = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}"); if (playerInfoList.Count > 0) { response.Score = playerInfoList[0].Score; if (!playerInfoList[0].IsGiveFriendKey) { string endTime = CommonUtil.timeAddDays(CommonUtil.getCurDataNormalFormat(), 1); //每天赠送好友房钥匙 await DBCommonUtil.AddFriendKey(message.UId, 3, endTime, "每天赠送3把好友房钥匙"); playerInfoList[0].IsGiveFriendKey = true; response.IsGiveFriendKey = true; Log.Debug(response.IsGiveFriendKey + "bool"); await proxyComponent.Save(playerInfoList[0]); } else { //今天已经赠送好友房钥匙 } } { //向map服务器发送请求 ConfigComponent configCom = Game.Scene.GetComponent <ConfigComponent>(); StartConfigComponent _config = Game.Scene.GetComponent <StartConfigComponent>(); IPEndPoint mapIPEndPoint = _config.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint; Session mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapIPEndPoint); M2G_FriendRoomInfo m2GFriendRoomInfo = (M2G_FriendRoomInfo)await mapSession.Call(new G2M_FriendRoomInfo() { }); response.Info = m2GFriendRoomInfo.Info; int keyCount = await DBCommonUtil.GetUserFriendKeyNum(message.UId); response.KeyCount = keyCount; } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
// 检查是否在黑名单中 public static async Task <bool> CheckIsInBlackList(long uid, Session session) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <string> list = new List <string>(); CommonUtil.splitStr(session.RemoteAddress.ToString(), list, ':'); if (list.Count > 0) { List <BlackList> blackLists = await proxyComponent.QueryJson <BlackList>($"{{ip:'{list[0]}'}}"); if (blackLists.Count > 0) { if (blackLists[0].EndTime.CompareTo(CommonUtil.getCurDataNormalFormat()) > 0) { return(true); } } } return(false); }
public static async Task Start(string channelName) { try { string time = CommonUtil.timeAddDays(CommonUtil.getCurDataNormalFormat(), -1); time = Convert.ToDateTime(time).ToString("yyyy-MM-dd"); string logData = ""; if (string.IsNullOrEmpty(channelName)) { logData = "渠道:所有\r\n"; } else { logData = "渠道:" + channelName + "\r\n"; } logData += await NewUser(time, channelName); logData += await DailyLogin(time, channelName); logData += await LoadOldUserCount(time, channelName); logData += await CiLiu(time, channelName); logData += await RechargeNum(time, channelName); logData += await RechargeUserNum(time, channelName); logData += await GameCount(time, channelName); logData += await GameUserCount(time, channelName); writeLogToLocalNow(logData); } catch (Exception ex) { } }
// 记录文本日志到本地 static void writeLogToLocalNow(string data) { data = CommonUtil.getCurTimeNormalFormat() + ":\r\n" + data; StreamWriter sw = null; try { string folderPath = AppDomain.CurrentDomain.BaseDirectory + "../BaoBiao/"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } string filePath = folderPath + "/" + CommonUtil.getCurDataNormalFormat() + ".txt"; if (!File.Exists(filePath)) { File.Create(filePath).Close(); } sw = new StreamWriter(filePath, true); sw.WriteLine(data); //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); } catch (Exception ex) { Log.Error("writeLogToLocalNow异常:" + ex); } finally { sw.Close(); } }
// 扣除玩家好友房钥匙 public static async Task DeleteFriendKey(long uid, int num, string reason) { try { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <FriendKey> listData = await proxyComponent.QueryJsonDB <FriendKey>($"{{Uid:{uid}}}"); int count = 0; // 先删非永久的并且在有效期以内的 for (int i = 0; i < listData.Count; i++) { if (count < num) { if (listData[i].endTime.CompareTo("-1") != 0) { if (listData[i].endTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { ++count; await proxyComponent.Delete <FriendKey>(listData[i].Id); } } } else { break; } } // 后删永久的 for (int i = 0; i < listData.Count; i++) { if (count < num) { if (listData[i].endTime.CompareTo("-1") == 0) { ++count; await proxyComponent.Delete <FriendKey>(listData[i].Id); } } else { break; } } await Log_ChangeWealth(uid, 112, -num, reason); //Log.Info("修改完后玩家:" + uid + "钥匙数量为:" + await GetUserFriendKeyNum(uid)); // 好友房活动 { string startTime = "2018-08-01"; string endTime = "2018-08-07"; if (String.CompareOrdinal(CommonUtil.getCurDataNormalFormat(), startTime) >= 1 && String.CompareOrdinal(CommonUtil.getCurDataNormalFormat(), endTime) <= 0) { List <FriendKeyConsum> consums = await proxyComponent.QueryJson <FriendKeyConsum>($"{{UId:{uid},CreateTime:/^{DateTime.Now.GetCurrentDay()}/}}"); if (consums.Count > 0) { consums[0].ConsumCount += count; await proxyComponent.Save(consums[0]); } else { FriendKeyConsum consum = ComponentFactory.CreateWithId <FriendKeyConsum>(IdGenerater.GenerateId()); consum.UId = uid; consum.ConsumCount = count; consum.GetCount = 0; await proxyComponent.Save(consum); } } } } catch (Exception e) { Log.Error("DeleteFriendKey异常:" + e); } }