static public bool isCanUseEmoji() { if (PlayerInfoComponent.Instance.GetPlayerInfo().EmogiTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { return(true); } return(false); }
public static bool isVIP(PlayerInfo info) { if (info.VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { return(true); } return(false); }
public static async Task <string> getRecord(long uid) { string jsonData = ""; List <FriendRoomRecordInfo> listData = new List <FriendRoomRecordInfo>(); DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); DBComponent dbComponent = Game.Scene.GetComponent <DBComponent>(); string time = CommonUtil.timeAddDays(CommonUtil.getCurTimeNormalFormat(), -90); var filter1 = (Builders <Log_Game> .Filter.Gt("CreateTime", time) & Builders <Log_Game> .Filter.Eq("RoomName", "好友房")) & (Builders <Log_Game> .Filter.Eq("Player1_uid", uid) | Builders <Log_Game> .Filter.Eq("Player2_uid", uid) | Builders <Log_Game> .Filter.Eq("Player3_uid", uid) | Builders <Log_Game> .Filter.Eq("Player4_uid", uid)); List <Log_Game> list = await dbComponent.GetDBDataCollection <Log_Game>(typeof(Log_Game).Name).Find(filter1).ToListAsync(); Log.Debug(JsonHelper.ToJson(list) + "====="); int roomNum = -1; FriendRoomRecordInfo FriendRoomRecordInfo = null; for (int i = list.Count - 1; i >= 0; i--) { // 如果房间号跟之前的不一样,说明这是另一局的 if (list[i].RoomNum != roomNum) { // 最多显示50条 if (listData.Count >= 50) { break; } roomNum = list[i].RoomNum; FriendRoomRecordInfo = new FriendRoomRecordInfo(); listData.Add(FriendRoomRecordInfo); FriendRoomRecordInfo.result = 1; FriendRoomRecordInfo.allScore = 100; FriendRoomRecordInfo.roomNum = list[i].RoomNum; FriendRoomRecordInfo.time = list[i].CreateTime; } // 每一小局对局信息 { FriendRoomRecordInfo.gameList.Add(new FriendRoomRecordInfo.ResultDetails(new List <string>() { list[i].Player1_info, list[i].Player2_info, list[i].Player3_info, list[i].Player4_info, }, list[i].CreateTime)); } } jsonData = JsonConvert.SerializeObject(listData); Log.Debug("------------------" + jsonData); return(jsonData); }
protected override async void Run(Session session, C2G_Share message, Action <G2C_Share> reply) { G2C_Share response = new G2C_Share(); try { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); // 分享增加转盘次数 { List <Log_UseZhuanPan> log_UseZhuanPan = await proxyComponent.QueryJson <Log_UseZhuanPan>($"{{CreateTime:/^{DateTime.Now.GetCurrentDay()}/,Uid:{ message.Uid}}}"); PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(message.Uid); // 贵族 if (playerBaseInfo.VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { if (log_UseZhuanPan.Count == 4) { Log.Debug("该用户是贵族,游戏增加的转盘次数已用完,通过分享增加次数"); playerBaseInfo.ZhuanPanCount = 1; await proxyComponent.Save(playerBaseInfo); } } else { if (log_UseZhuanPan.Count == 3) { Log.Debug("该用户是普通玩家,游戏增加的转盘次数已用完,通过分享增加次数"); playerBaseInfo.ZhuanPanCount = 1; await proxyComponent.Save(playerBaseInfo); } } } // 分享日志 { Log_Share log_Share = ComponentFactory.CreateWithId <Log_Share>(IdGenerater.GenerateId()); log_Share.Uid = message.Uid; await proxyComponent.Save(log_Share); } reply(response); } catch (Exception e) { Log.Debug(e.ToString()); ReplyError(response, e, reply); } }
public static async Task <bool> IsVIP(long uid) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <PlayerBaseInfo> infos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{uid}}}"); if (infos.Count > 0) { if (infos[0].VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { return(true); } } else { Log.Error("用户:" + uid + "playerbaseInfo数据不存在"); } return(false); }
// 记录文本日志到本地 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 <int> GetUserFriendKeyNum(long uid) { 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 (listData[i].endTime.CompareTo("-1") == 0) { ++count; } else { if (listData[i].endTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { ++count; } else { await proxyComponent.Delete <FriendKey>(listData[i].Id); } } } return(count); } catch (Exception e) { Log.Error("GetUserFriendKeyNum异常:" + e); return(0); } }
protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { long userId = Game.Scene.GetComponent <NjmjGateSessionKeyComponent>().Get(message.Key); if (userId == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(response); return; } // 检测是否已存在 UserComponentSystem.CheckIsExistTheUser(userId); //创建User对象 User user = UserFactory.Create(userId, session); await user.AddComponent <MailBoxComponent>().AddLocation(); //添加心跳包 session.AddComponent <HeartBeatComponent>().CurrentTime = TimeHelper.ClientNowSeconds(); //添加User对象关联到Session上 session.AddComponent <SessionUserComponent>().User = user; //添加消息转发组件 session.AddComponent <MailBoxComponent, string>(ActorType.GateSession); response.PlayerId = user.Id; response.Uid = userId; ConfigComponent configCom = Game.Scene.GetComponent <ConfigComponent>(); DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); { //商城 if (ShopData.getInstance().getDataList().Count == 0) { List <ShopConfig> shopList = new List <ShopConfig>(); for (int i = 1; i < configCom.GetAll(typeof(ShopConfig)).Length + 1; ++i) { int id = 1000 + i; ShopConfig config = (ShopConfig)configCom.Get(typeof(ShopConfig), id); shopList.Add(config); } ShopData.getInstance().getDataList().AddRange(shopList); } //#region AddShopInfo List <ShopInfo> shopInfoList = new List <ShopInfo>(); for (int i = 0; i < ShopData.getInstance().getDataList().Count; ++i) { ShopConfig config = ShopData.getInstance().getDataList()[i]; ShopInfo info = new ShopInfo(); info.Id = (int)config.Id; info.Name = config.Name; info.Price = config.Price; info.ShopType = config.shopType; info.Desc = config.Desc; info.CurrencyType = config.CurrencyType; info.Items = config.Items; info.Icon = config.Icon; info.VipPrice = config.VipPrice; shopInfoList.Add(info); } response.ShopInfoList = shopInfoList; } { //任务 if (TaskData.getInstance().getDataList().Count == 0) { List <TaskConfig> taskList = new List <TaskConfig>(); for (int i = 1; i < configCom.GetAll(typeof(TaskConfig)).Length + 1; ++i) { int id = 100 + i; TaskConfig config = (TaskConfig)configCom.Get(typeof(TaskConfig), id); taskList.Add(config); } TaskData.getInstance().getDataList().AddRange(taskList); } } { //成就 if (ChengjiuData.getInstance().getDataList().Count == 0) { List <ChengjiuConfig> chengjiuList = new List <ChengjiuConfig>(); for (int i = 1; i < configCom.GetAll(typeof(ChengjiuConfig)).Length + 1; ++i) { int id = 100 + i; ChengjiuConfig config = (ChengjiuConfig)configCom.Get(typeof(ChengjiuConfig), id); chengjiuList.Add(config); } ChengjiuData.getInstance().getDataList().AddRange(chengjiuList); } } List <UserBag> bagInfoList = await proxyComponent.QueryJson <UserBag>($"{{UId:{userId}}}"); response.BagList = new List <Bag>(); List <Bag> bagList = new List <Bag>(); for (int i = 0; i < bagInfoList.Count; ++i) { Bag bag = new Bag(); bag.ItemId = bagInfoList[i].BagId; bag.Count = bagInfoList[i].Count; bagList.Add(bag); } response.BagList = bagList; PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(userId); // 老用户检测 { try { AccountInfo accountInfo = await DBCommonUtil.getAccountInfo(userId); if (accountInfo.OldAccountState == 1) { string url = "http://fksq.hy51v.com:10086/CheckIsOldUser?machine_id=" + accountInfo.MachineId + "&game_id=217"; string str = HttpUtil.GetHttp(url); Log.Debug("web地址:" + url); Log.Debug("判断是否是老用户:" + str); JObject result = JObject.Parse(str); string old_uid = (string)result.GetValue("old_uid"); // 不是老用户 if (string.IsNullOrEmpty(old_uid)) { accountInfo.OldAccountState = 3; await proxyComponent.Save(accountInfo); } // 是老用户 else { List <Log_OldUserBind> log_OldUserBinds = await proxyComponent.QueryJson <Log_OldUserBind>($"{{macId:'{accountInfo.MachineId}'}}"); if (log_OldUserBinds.Count > 0) { accountInfo.OldAccountState = 3; await proxyComponent.Save(accountInfo); } else { accountInfo.OldAccountState = 2; await proxyComponent.Save(accountInfo); // 记录绑定日志 { Log_OldUserBind log_OldUserBind = ComponentFactory.CreateWithId <Log_OldUserBind>(IdGenerater.GenerateId()); log_OldUserBind.Uid = userId; log_OldUserBind.OldUid = old_uid; log_OldUserBind.macId = accountInfo.MachineId; log_OldUserBind.isSendReward = 1; await proxyComponent.Save(log_OldUserBind); } { url = ("http://fksq.hy51v.com:10086/GetOldNjmjData?UserId=" + old_uid); str = HttpUtil.GetHttp(url); result = JObject.Parse(str); int moneyAmount = (int)result.GetValue("moneyAmount"); int gIngotAmount = (int)result.GetValue("gIngotAmount"); Log.Debug("老用户金币=" + moneyAmount + " 元宝=" + gIngotAmount); playerBaseInfo.GoldNum = moneyAmount; playerBaseInfo.WingNum = gIngotAmount; await proxyComponent.Save(playerBaseInfo); await DBCommonUtil.changeWealthWithStr(userId, "111:10;2:10", "老用户赠送"); } // 发送老用户广播 Actor_OldUser actor_OldUser = new Actor_OldUser(); actor_OldUser.OldAccount = old_uid; Game.Scene.GetComponent <UserComponent>().BroadCastToSingle(actor_OldUser, userId); } } } else if (accountInfo.OldAccountState == 2) { List <Log_OldUserBind> log_OldUserBinds = await proxyComponent.QueryJson <Log_OldUserBind>($"{{macId:'{accountInfo.MachineId}'}}"); if (log_OldUserBinds.Count > 0) { if (log_OldUserBinds[0].isSendReward != 1) { log_OldUserBinds[0].isSendReward = 1; await proxyComponent.Save(log_OldUserBinds[0]); await DBCommonUtil.SendMail(userId, "更新游戏奖励", "亲爱的玩家,南京麻将最新版本更新了,特意送上更新奖励,请笑纳,祝您游戏愉快!", "111:10;2:10"); } } } } catch (Exception ex) { Log.Error("检测是否是老用户出错:" + ex); } } #region 用户活动所获得的头像数据 List <OtherData> otherDatas = await proxyComponent.QueryJson <OtherData>($"{{UId:{userId}}}"); if (otherDatas.Count > 0) { response.ownIcon = otherDatas[0].OwnIcon; } #endregion reply(response); session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); // vip上线全服广播 { if (playerBaseInfo.VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { Actor_LaBa actor_LaBa = new Actor_LaBa(); actor_LaBa.LaBaContent = "贵族玩家" + playerBaseInfo.Name + "上线啦!"; Game.Scene.GetComponent <UserComponent>().BroadCast(actor_LaBa); } } } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async void Run(Session session, C2G_DailySignState message, Action <G2C_DailySignState> reply) { G2C_DailySignState response = new G2C_DailySignState(); try { // 当前连续签到天数 int curLianXuSignDays = 1; bool TodayIsSign = false; DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <DailySign> dailySigns = await proxyComponent.QueryJson <DailySign>($"{{Uid:{message.Uid}}}"); dailySigns.Sort(delegate(DailySign x, DailySign y) { return(x.CreateTime.CompareTo(y.CreateTime)); }); if (dailySigns.Count > 0) { int tianshucha = CommonUtil.tianshucha(dailySigns[dailySigns.Count - 1].CreateTime, CommonUtil.getCurTimeNormalFormat()); if (tianshucha == 0) { TodayIsSign = true; curLianXuSignDays = 1; if (dailySigns.Count >= 2) { for (int i = dailySigns.Count - 1; i >= 1; i--) { int temp = CommonUtil.tianshucha(dailySigns[i - 1].CreateTime, dailySigns[i].CreateTime); if (temp > 1) { break; } else if (temp == 1) { ++curLianXuSignDays; } } } } } { response.TodayIsSign = TodayIsSign; response.TodayReward = C2G_DailySignHandler.getReward(curLianXuSignDays); response.TomorrowReward = C2G_DailySignHandler.getReward(curLianXuSignDays + 1); reply(response); } } catch (Exception e) { ReplyError(response, e, reply); } }
public async Task useProp(G2C_UseItem response, long uid, int prop_id) { string endTime = ""; DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <PlayerBaseInfo> playerBaseInfoList = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{uid}}}"); PlayerBaseInfo playerBaseInfo = playerBaseInfoList[0]; switch (prop_id) { // 表情包 case 104: { // 未过期 if (playerBaseInfo.EmogiTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { endTime = (CommonUtil.timeAddDays(playerBaseInfo.EmogiTime, 30)); } // 已过期 else { endTime = (CommonUtil.timeAddDays(CommonUtil.getCurTimeNormalFormat(), 30)); } playerBaseInfo.EmogiTime = endTime; response.time = endTime; await proxyComponent.Save(playerBaseInfo); } break; // VIP7天体验卡 case 107: { // 未过期 if (playerBaseInfo.VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { endTime = (CommonUtil.timeAddDays(playerBaseInfo.VipTime, 7)); } // 已过期 else { endTime = (CommonUtil.timeAddDays(CommonUtil.getCurTimeNormalFormat(), 7)); } playerBaseInfo.VipTime = endTime; response.time = endTime; await proxyComponent.Save(playerBaseInfo); } break; // VIP月卡 case 108: { // 未过期 if (playerBaseInfo.VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { endTime = (CommonUtil.timeAddDays(playerBaseInfo.VipTime, 30)); } // 已过期 else { endTime = (CommonUtil.timeAddDays(CommonUtil.getCurTimeNormalFormat(), 30)); } playerBaseInfo.VipTime = endTime; response.time = endTime; await proxyComponent.Save(playerBaseInfo); } break; // VIP季卡 case 109: { // 未过期 if (playerBaseInfo.VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { endTime = (CommonUtil.timeAddDays(playerBaseInfo.VipTime, 90)); } // 已过期 else { endTime = (CommonUtil.timeAddDays(CommonUtil.getCurTimeNormalFormat(), 90)); } playerBaseInfo.VipTime = endTime; response.time = endTime; await proxyComponent.Save(playerBaseInfo); } break; // 话费礼包 case 111: { int huafei = Common_Random.getRandom(5, 20); string reward = ("3:" + huafei); response.reward = reward; await DBCommonUtil.changeWealthWithStr(playerBaseInfo.Id, reward, "道具使用:拆话费礼包获得的话费"); } break; } }
// 扣除玩家好友房钥匙 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); } }
public static async Task Log_Login(long uid, Session session, string clientVersion) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); ConfigComponent configCom = Game.Scene.GetComponent <ConfigComponent>(); List <Log_Login> log_Logins = await proxyComponent.QueryJson <Log_Login>( $"{{CreateTime:/^{DateTime.Now.GetCurrentDay()}/,Uid:{uid}}}"); if (log_Logins.Count == 0) { // 今天第一天登录,做一些处理 Log.Debug("今天第一天登录"); // 重置转盘次数 { List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{uid}}}"); if (playerBaseInfos.Count > 0) { playerBaseInfos[0].ZhuanPanCount = 0; if (playerBaseInfos[0].VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { playerBaseInfos[0].ZhuanPanCount = 1; } //重置赠送好友房钥匙 playerBaseInfos[0].IsGiveFriendKey = false; await proxyComponent.Save(playerBaseInfos[0]); } else { Log.Warning($"玩家{uid}的PlayerBaseInfo为null"); } } // 重置任务 { List <TaskProgressInfo> progressList = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{uid}}}"); if (progressList.Count > 0) { for (int i = 0; i < progressList.Count; ++i) { progressList[i].IsGet = false; progressList[i].IsComplete = false; progressList[i].CurProgress = 0; await proxyComponent.Save(progressList[i]); } } } //重置每天在线时长和宝箱次数 { List <GamerInfoDB> gamerInfo = await proxyComponent.QueryJson <GamerInfoDB>($"{{UId:{uid}}}"); if (gamerInfo.Count > 0) { gamerInfo[0].DailyOnlineTime = 0; gamerInfo[0].DailyTreasureCount = 0; await proxyComponent.Save(gamerInfo[0]); } } } Log_Login log_Login = ComponentFactory.CreateWithId <Log_Login>(IdGenerater.GenerateId()); log_Login.Uid = uid; log_Login.ip = session.RemoteAddress.ToString(); log_Login.clientVersion = clientVersion; await proxyComponent.Save(log_Login); }
protected override async void Run(Session session, C2G_DailySign message, Action <G2C_DailySign> reply) { G2C_DailySign response = new G2C_DailySign(); try { // 当前连续签到天数 int curLianXuSignDays = 1; DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <DailySign> dailySigns = await proxyComponent.QueryJson <DailySign>($"{{Uid:{message.Uid}}}"); dailySigns.Sort(delegate(DailySign x, DailySign y) { return(x.CreateTime.CompareTo(y.CreateTime)); }); if (dailySigns.Count > 0) { int tianshucha = CommonUtil.tianshucha(dailySigns[dailySigns.Count - 1].CreateTime, CommonUtil.getCurTimeNormalFormat()); if (tianshucha == 0) { // 今天已经签到过 response.Error = ErrorCode.TodayHasSign; response.Message = "今天已签到,请明天再试"; reply(response); return; } else if (tianshucha == 1) { curLianXuSignDays = 2; if (dailySigns.Count >= 2) { for (int i = dailySigns.Count - 1; i >= 1; i--) { int temp = CommonUtil.tianshucha(dailySigns[i - 1].CreateTime, dailySigns[i].CreateTime); if (temp > 1) { break; } else if (temp == 1) { ++curLianXuSignDays; } } } } } { string reward = getReward(curLianXuSignDays); // 更新用户数据 await DBCommonUtil.changeWealthWithStr(message.Uid, reward, "每日签到"); response.Reward = reward; response.TomorrowReward = getReward(curLianXuSignDays + 1); reply(response); DailySign dailySign = ComponentFactory.CreateWithId <DailySign>(IdGenerater.GenerateId()); dailySign.Uid = message.Uid; dailySign.Reward = reward; await proxyComponent.Save(dailySign); } } catch (Exception e) { ReplyError(response, e, reply); } }