// 充值金额 static async Task <string> RechargeNum(string time, string channelName) { if (string.IsNullOrEmpty(channelName)) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <Log_Recharge> listData = await proxyComponent.QueryJsonDBInfos <Log_Recharge>(time); int num = 0; for (int i = 0; i < listData.Count; i++) { num += listData[i].Price; } return("充值金额:" + num + "\r\n"); } else { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <Log_Recharge> listData = await proxyComponent.QueryJsonDBInfos <Log_Recharge>(time); int num = 0; for (int i = 0; i < listData.Count; i++) { AccountInfo accountInfo = await DBCommonUtil.getAccountInfo(listData[i].Uid); if (accountInfo.ChannelName.CompareTo(channelName) == 0) { num += listData[i].Price; } } return("充值金额:" + num + "\r\n"); } }
// 导入老用户 static async Task <string> LoadOldUserCount(string time, string channelName) { if (string.IsNullOrEmpty(channelName)) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <Log_OldUserBind> listData = await proxyComponent.QueryJsonDBInfos <Log_OldUserBind>(time); return("导入老用户:" + listData.Count + "\r\n"); } else { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <Log_OldUserBind> listData = await proxyComponent.QueryJsonDBInfos <Log_OldUserBind>(time); int count = 0; for (int i = 0; i < listData.Count; i++) { AccountInfo accountInfo = await DBCommonUtil.getAccountInfo(listData[i].Uid); if (accountInfo.ChannelName.CompareTo(channelName) == 0) { ++count; } } return("导入老用户:" + count + "\r\n"); } }
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_PlayerInfo message, Action <G2C_PlayerInfo> reply) { // Log.Info(JsonHelper.ToJson(message)); G2C_PlayerInfo response = new G2C_PlayerInfo(); try { User user = session.GetComponent <SessionUserComponent>()?.User; if (user == null) { response.Error = ErrorCode.ERR_Common; reply(response); session.Dispose(); return; } DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <PlayerBaseInfo> playerInfo = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{user.UserID}}}"); List <OtherData> otherDatas = await proxyComponent.QueryJson <OtherData>($"{{UId:{user.UserID}}}"); response.PlayerInfo = new PlayerInfo(); int fKeyCount = await DBCommonUtil.GetUserFriendKeyNum(user.UserID); if (playerInfo != null) { response.Message = "数据库里已存在玩家的基本信息,返回玩家信息"; response.PlayerInfo.Name = playerInfo[0].Name; response.PlayerInfo.GoldNum = playerInfo[0].GoldNum; response.PlayerInfo.WingNum = playerInfo[0].WingNum; response.PlayerInfo.HuaFeiNum = playerInfo[0].HuaFeiNum; response.PlayerInfo.Icon = playerInfo[0].Icon; response.PlayerInfo.IsRealName = playerInfo[0].IsRealName; AccountInfo accountInfo = await DBCommonUtil.getAccountInfo(user.UserID); response.PlayerInfo.Phone = accountInfo.Phone; response.PlayerInfo.PlayerSound = playerInfo[0].PlayerSound; response.PlayerInfo.RestChangeNameCount = playerInfo[0].RestChangeNameCount; response.PlayerInfo.VipTime = playerInfo[0].VipTime; response.PlayerInfo.EmogiTime = playerInfo[0].EmogiTime; response.PlayerInfo.MaxHua = playerInfo[0].MaxHua; response.PlayerInfo.WinGameCount = playerInfo[0].WinGameCount; response.PlayerInfo.IsGiveFriendKey = playerInfo[0].IsGiveFriendKey; response.PlayerInfo.FriendKeyCount = fKeyCount; response.PlayerInfo.Score = playerInfo[0].Score; List <ChengjiuInfo> infos = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{user.UserID},TaskId:{102}}}"); if (infos.Count > 0) { response.PlayerInfo.TotalGameCount = infos[0].CurProgress; } if (otherDatas.Count > 0) { response.OwnIcon = otherDatas[0].OwnIcon; } // 今天是否签到过 { List <DailySign> dailySigns = await proxyComponent.QueryJson <DailySign>($"{{CreateTime:/^{DateTime.Now.GetCurrentDay()}/,Uid:{user.UserID}}}"); if (dailySigns.Count == 0) { response.PlayerInfo.IsSign = false; } else { response.PlayerInfo.IsSign = true; } } { //端午节活动是否结束 // List<DuanwuDataBase> duanwuDataBases = await proxyComponent.QueryJson<DuanwuDataBase>($"{{UId:{user.UserID}}}"); // string curTime = CommonUtil.getCurTimeNormalFormat(); // if (string.CompareOrdinal(curTime, duanwuDataBases[0].EndTime) >= 0) // { // long goldNum = 0; // if (duanwuDataBases[0].ZongziCount > 0) // { // goldNum = duanwuDataBases[0].ZongziCount * 100; // duanwuDataBases[0].ZongziCount = 0; // //添加邮件 // await DBCommonUtil.SendMail(user.UserID, "端午粽香", $"端午活动已结束,剩余粽子已转换为金币存入您的账号,兑换比例:一个粽子=100金币,您获得{goldNum}金币", $"1:{goldNum}"); // await proxyComponent.Save(duanwuDataBases[0]); // } // } } reply(response); return; } response.Message = "Account数据库里不存在该用户"; response.PlayerInfo = null; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
//1,刷新所有配置表 2,发送邮件 3,解散房间 4,增减黑名单 5,生成报表 6,查看用户信息 7,强制离线 8,修改用户信息 9,查看游戏内信息 protected override async void Run(Session session, C2G_GM message, Action <G2C_GM> reply) { G2C_GM response = new G2C_GM(); try { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); if (Game.Scene.GetComponent <ConfigComponent>() != null) { Game.Scene.RemoveComponent <ConfigComponent>(); } Game.Scene.AddComponent <ConfigComponent>(); 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); switch (message.Type) { case 1: { //刷新所有配置表 List <PlayerBaseInfo> allInfos = await proxyComponent.QueryJsonDBInfos <PlayerBaseInfo>(); { //商城 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().Clear(); ShopData.getInstance().getDataList().AddRange(shopList); } { //任务 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().Clear(); TaskData.getInstance().getDataList().AddRange(taskList); for (int i = 0; i < allInfos.Count; ++i) { List <TaskProgressInfo> taskInfos = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{allInfos[i].Id}}}"); //无论删减任务 都要刷新一下任务的数据库 for (int j = 0; j < taskInfos.Count; ++j) { TaskConfig config = TaskData.getInstance().GetDataByTaskId(taskInfos[j].TaskId); if (config != null) { taskInfos[j].Name = config.Name; taskInfos[j].Target = config.Target; taskInfos[j].Reward = config.Reward; taskInfos[j].Desc = config.Desc; await proxyComponent.Save(taskInfos[j]); } } #region 增加任务先不管 update时会重新添加 //if (TaskData.getInstance().getDataList().Count > taskInfos.Count) //{ // //增加了新任务 // for (int j = 0; j < TaskData.getInstance().getDataList().Count; ++j) // { // List<TaskProgressInfo> progresses = await proxyComponent.QueryJson<TaskProgressInfo>($"{{UId:{allInfos[i].Id},TaskId:{TaskData.getInstance().getDataList()[j].Id}}}"); // if (progresses.Count <= 0) // { // TaskProgressInfo progress = // ComponentFactory.CreateWithId<TaskProgressInfo>(IdGenerater.GenerateId()); // progress.IsGet = false; // progress.UId = allInfos[i].Id; // progress.Name = TaskData.getInstance().getDataList()[j].Name; // progress.TaskId = (int)TaskData.getInstance().getDataList()[j].Id; // progress.IsComplete = false; // progress.Target = TaskData.getInstance().getDataList()[j].Target; // progress.Reward = TaskData.getInstance().getDataList()[j].Reward; // progress.Desc = TaskData.getInstance().getDataList()[j].Desc; // progress.CurProgress = 0; // await proxyComponent.Save(progress); // } // } //} #endregion if (TaskData.getInstance().getDataList().Count < taskInfos.Count) { for (int j = 0; j < taskInfos.Count; ++j) { TaskConfig config = TaskData.getInstance().GetDataByTaskId(taskInfos[j].TaskId); List <TaskProgressInfo> progresses = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{allInfos[i].Id},TaskId:{taskInfos[j].TaskId}}}"); if (config == null) { if (progresses.Count > 0) { //删除该任务 await proxyComponent.Delete <TaskProgressInfo>(progresses[0].Id); } } } } } { //成就 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().Clear(); ChengjiuData.getInstance().getDataList().AddRange(chengjiuList); for (int i = 0; i < allInfos.Count; ++i) { List <ChengjiuInfo> chengjiuInfos = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{allInfos[i].Id}}}"); //无论删减任务 都要刷新一下任务的数据库 for (int j = 0; j < chengjiuInfos.Count; ++j) { ChengjiuConfig config = ChengjiuData.getInstance().GetDataByChengjiuId(chengjiuInfos[j].TaskId); if (config != null) { chengjiuInfos[j].Name = config.Name; chengjiuInfos[j].Target = config.Target; chengjiuInfos[j].Reward = config.Reward; chengjiuInfos[j].Desc = config.Desc; await proxyComponent.Save(chengjiuInfos[j]); } } #region 增加(暂时先不管 Update时会新加) //if (ChengjiuData.getInstance().getDataList().Count > chengjiuInfos.Count) //{ // //增加了新成就 // for (int j = chengjiuInfos.Count; j < ChengjiuData.getInstance().getDataList().Count; ++j) // { // List<ChengjiuInfo> progresses = await proxyComponent.QueryJson<ChengjiuInfo>($"{{UId:{allInfos[i].Id},TaskId:{ChengjiuData.getInstance().getDataList()[j].Id}}}"); // if (progresses.Count <= 0) // { // Log.Debug("增加新成就"); // ChengjiuInfo progress = // ComponentFactory.CreateWithId<ChengjiuInfo>(IdGenerater.GenerateId()); // progress.IsGet = false; // progress.UId = allInfos[i].Id; // progress.Name = ChengjiuData.getInstance().getDataList()[j].Name; // progress.TaskId = (int)ChengjiuData.getInstance().getDataList()[j].Id; // progress.IsComplete = false; // progress.Target = ChengjiuData.getInstance().getDataList()[j].Target; // progress.Reward = ChengjiuData.getInstance().getDataList()[j].Reward; // progress.Desc = ChengjiuData.getInstance().getDataList()[j].Desc; // progress.CurProgress = 0; // await proxyComponent.Save(progress); // } // } //} #endregion if (ChengjiuData.getInstance().getDataList().Count < chengjiuInfos.Count) { for (int j = 0; j < chengjiuInfos.Count; ++j) { ChengjiuConfig config = ChengjiuData.getInstance().GetDataByChengjiuId(chengjiuInfos[j].TaskId); List <ChengjiuInfo> progresses = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{allInfos[i].Id},TaskId:{chengjiuInfos[j].TaskId}}}"); if (config == null) { if (progresses.Count > 0) { //删除该成就 await proxyComponent.Delete <ChengjiuInfo>(progresses[0].Id); } } } } } } } } break; case 2: { //发送邮件 uid为空则为给全部玩家发送邮件 if (message.UId != -1) { Log.Debug("Mail" + message.UId + message.Title + message.Content + message.Reward); await DBCommonUtil.SendMail(message.UId, message.Title, message.Content, message.Reward); } else { //分批发还是全部一次性发 List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJsonDBInfos <PlayerBaseInfo>(); if (playerBaseInfos.Count > 0) { for (int i = 0; i < playerBaseInfos.Count; ++i) { await DBCommonUtil.SendMail(playerBaseInfos[i].Id, message.Title, message.Content, message.Reward); } } } } break; case 3: { //解散房间 M2G_GMInfo m2G_GMInfo = (M2G_GMInfo)await mapSession.Call(new G2M_GMInfo() { Type = 3, Uid = message.UId }); response.Error = m2G_GMInfo.Error; response.Message = m2G_GMInfo.Message; } break; case 4: { //增减黑名单(根据玩家IP) List <BlackList> blackList = await proxyComponent.QueryJson <BlackList>($"{{ip:'{message.IP}'}}"); if (string.IsNullOrEmpty(message.EndTime)) { //删除黑名单 if (blackList.Count > 0) { blackList[0].EndTime = "2000-01-01 00:00:00"; await proxyComponent.Save(blackList[0]); } } else { if (blackList.Count > 0) { blackList[0].EndTime = message.EndTime; await proxyComponent.Save(blackList[0]); } else { BlackList list = ComponentFactory.CreateWithId <BlackList>(IdGenerater.GenerateId()); list.Uid = message.UId; list.ip = message.IP; list.EndTime = message.EndTime; list.Reason = message.Reason; await proxyComponent.Save(list); } } } break; case 5: { //生成报表 string logData = await DataStatistics.Start(message.CreateBaobiaoTime, message.Content); response.LogData = logData; } break; case 6: //查看用户信息 List <PlayerBaseInfo> infos = new List <PlayerBaseInfo>(); AccountInfo accountInfo = null; List <Log_Login> logLogins = new List <Log_Login>(); if (message.UId != 0) { infos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}"); accountInfo = await DBCommonUtil.getAccountInfo(message.UId); logLogins = await proxyComponent.QueryJson <Log_Login>($"{{Uid:{message.UId}}}"); } else if (!string.IsNullOrEmpty(message.Name)) { infos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{Name:'{message.Name}'}}"); if (infos.Count > 0) { accountInfo = await DBCommonUtil.getAccountInfo(infos[0].Id); logLogins = await proxyComponent.QueryJson <Log_Login>($"{{Uid:{infos[0].Id}}}"); } } if (infos.Count > 0) { PlayerInfo info = new PlayerInfo(); info.Name = infos[0].Name; info.GoldNum = infos[0].GoldNum; info.WingNum = infos[0].WingNum; info.HuaFeiNum = infos[0].HuaFeiNum; info.IsRealName = infos[0].IsRealName; info.VipTime = infos[0].VipTime; info.EmogiTime = infos[0].EmogiTime; info.MaxHua = infos[0].MaxHua; info.TotalGameCount = infos[0].TotalGameCount; info.WinGameCount = infos[0].WinGameCount; response.UId = infos[0].Id; M2G_GMInfo m2G_GMInfo = (M2G_GMInfo)await mapSession.Call(new G2M_GMInfo() { Type = 6, Uid = message.UId }); Log.Debug(m2G_GMInfo.Type + ""); response.IsInGame = m2G_GMInfo.Type; if (logLogins.Count > 0) { response.LastOnlineTime = logLogins[logLogins.Count - 1].CreateTime; } if (accountInfo != null) { info.Phone = accountInfo.Phone; response.RegisterTime = accountInfo.CreateTime; response.Channel = accountInfo.ChannelName; } response.Info = info; response.Ip = logLogins[logLogins.Count - 1].ip; } else { response.Message = "不存在该用户信息"; response.Error = ErrorCode.ERR_Exception; response.Info = null; } break; case 7: { //强制玩家离线 UserComponentSystem.ForceOffline(message.UId, message.Reason); } break; case 8: { //更改用户信息 if (message.UId == -1) { List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJsonDBInfos <PlayerBaseInfo>(); if (playerBaseInfos.Count > 0) { for (int i = 0; i < playerBaseInfos.Count; ++i) { if (!message.Icon.Equals("0")) { playerBaseInfos[0].Icon = message.Icon; await proxyComponent.Save(playerBaseInfos[0]); } if (message.RestChangeNameCount != 0) { playerBaseInfos[0].RestChangeNameCount = message.RestChangeNameCount; await proxyComponent.Save(playerBaseInfos[0]); } if (!message.Prop.Equals("0")) { await DBCommonUtil.changeWealthWithStr(playerBaseInfos[i].Id, message.Prop, "GM中增加玩家道具"); } } } } else { List <PlayerBaseInfo> playerInfos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}"); if (playerInfos.Count > 0) { if (!message.Icon.Equals("0")) { playerInfos[0].Icon = message.Icon; await proxyComponent.Save(playerInfos[0]); } if (message.RestChangeNameCount != 0) { playerInfos[0].RestChangeNameCount = message.RestChangeNameCount; await proxyComponent.Save(playerInfos[0]); } if (!message.Prop.Equals("0")) { await DBCommonUtil.changeWealthWithStr(message.UId, message.Prop, "GM中增加玩家道具"); } } else { response.Error = ErrorCode.ERR_Exception; response.Message = "用户不存在,请检查UID是否正确"; } } } break; case 9: { //查看游戏内信息 M2G_GetRoomInfo getRoomInfo = (M2G_GetRoomInfo)await mapSession.Call(new G2M_GetRoomInfo()); response.Room = new RoomInfo(); response.Room.NewRoomCount = getRoomInfo.NewRoomCount; response.Room.NewTotalPlayerInGameCount = getRoomInfo.NewTotalPlayerInGameCount; response.Room.JingRoomCount = getRoomInfo.JingRoomCount; response.Room.JingTotalPlayerInGameCount = getRoomInfo.JingTotalPlayerInGameCount; } break; case 10: { // 发送通知 UserComponentSystem.EmergencyNotice(message.UId, message.Content); } break; case 11: { //session int count = Game.Scene.GetComponent <NetOuterComponent>().sessions.Count; response.Channel = count.ToString(); } break; case 12: { //改变玩家好友房钥匙 long uid = message.UId; // -1代表给所有人发 int num = message.RestChangeNameCount; string endTime = message.EndTime; // 如果是删除钥匙,此参数可以为空 string reason = message.Reason; if (uid != -1) { if (num > 0) { await DBCommonUtil.AddFriendKey(uid, num, endTime, reason); } else if (num < 0) { await DBCommonUtil.DeleteFriendKey(uid, -num, reason); } } else { List <AccountInfo> listData = await proxyComponent.QueryJsonDBInfos <AccountInfo>(); for (int i = 0; i < listData.Count; i++) { if (num > 0) { await DBCommonUtil.AddFriendKey(listData[i].Id, num, endTime, reason); } else if (num < 0) { await DBCommonUtil.DeleteFriendKey(listData[i].Id, -num, reason); } } } } break; } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public static async Task <PlayerBaseInfo> addPlayerBaseInfo(long uid, string Phone, string name, string head) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); ConfigComponent configCom = Game.Scene.GetComponent <ConfigComponent>(); AccountInfo accountInfo = await DBCommonUtil.getAccountInfo(uid); List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{uid}}}"); if (playerBaseInfos.Count > 0) { return(playerBaseInfos[0]); } PlayerBaseInfo playerBaseInfo = ComponentFactory.CreateWithId <PlayerBaseInfo>(IdGenerater.GenerateId()); playerBaseInfo.Id = uid; if (string.IsNullOrEmpty(name)) { playerBaseInfo.Name = uid.ToString(); } else { List <PlayerBaseInfo> playerBaseInfos_temp = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{Name:'{name}'}}"); // 昵称已经有人用了 if (playerBaseInfos_temp.Count > 0) { playerBaseInfo.Name = (name + uid.ToString().Substring(6)); } playerBaseInfo.Name = name; } if (string.IsNullOrEmpty(head)) { int random = Common_Random.getRandom(1, 5); //百分之五十的概率随机生成男生或女生头像 int rate = Common_Random.getRandom(1, 100); if (rate <= 50) { playerBaseInfo.Icon = $"f_icon{random}"; } else { playerBaseInfo.Icon = $"m_icon{random}"; } } else { playerBaseInfo.Icon = head; } if (accountInfo != null) { accountInfo.Phone = Phone; } else { Log.Error("addPlayerBaseInfo() accountInfo==null uid = " + uid); } playerBaseInfo.PlayerSound = Common_Random.getRandom(1, 4); await proxyComponent.Save(playerBaseInfo); await proxyComponent.Save(accountInfo); Log.Debug("增加新用户完毕"); //// 插入任务数据 //{ // Log.Debug("增加新用户任务"); // for (int i = 1; i < configCom.GetAll(typeof(TaskConfig)).Length + 1; ++i) // { // int id = 100 + i; // TaskConfig config = (TaskConfig) configCom.Get(typeof(TaskConfig), id); // TaskProgressInfo progress = // ComponentFactory.CreateWithId<TaskProgressInfo>(IdGenerater.GenerateId()); // progress.IsGet = false; // progress.UId = uid; // progress.Name = config.Name; // progress.TaskId = (int) config.Id; // progress.IsComplete = false; // progress.Target = config.Target; // progress.Reward = config.Reward; // progress.Desc = config.Desc; // progress.CurProgress = 0; // await proxyComponent.Save(progress); // } // Log.Debug("增加新用户任务完毕"); //} //插入新用户成就 //{ // Log.Debug("增加新用户成就"); // for (int i = 1; i < configCom.GetAll(typeof(ChengjiuConfig)).Length + 1; ++i) // { // int id = 100 + i; // ChengjiuConfig config = (ChengjiuConfig) configCom.Get(typeof(ChengjiuConfig), id); // ChengjiuInfo chengjiu = ComponentFactory.CreateWithId<ChengjiuInfo>(IdGenerater.GenerateId()); // chengjiu.IsGet = false; // chengjiu.UId = uid; // chengjiu.Name = config.Name; // chengjiu.TaskId = (int) config.Id; // chengjiu.IsComplete = false; // chengjiu.Target = config.Target; // chengjiu.Reward = config.Reward; // chengjiu.Desc = config.Desc; // chengjiu.CurProgress = 0; // await proxyComponent.Save(chengjiu); // } // Log.Debug("增加新用户成就完毕"); //} return(playerBaseInfo); }
// 游戏人数 static async Task <string> GameUserCount(string time, string channelName) { if (string.IsNullOrEmpty(channelName)) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <Log_Game> listData = await proxyComponent.QueryJsonDBInfos <Log_Game>(time); List <long> listPlayer = new List <long>(); for (int i = 0; i < listData.Count; i++) { { bool isFind = false; for (int j = 0; j < listPlayer.Count; j++) { if (listPlayer[j] == listData[i].Player1_uid) { isFind = true; break; } } if (!isFind) { listPlayer.Add(listData[i].Player1_uid); } } { bool isFind = false; for (int j = 0; j < listPlayer.Count; j++) { if (listPlayer[j] == listData[i].Player2_uid) { isFind = true; break; } } if (!isFind) { listPlayer.Add(listData[i].Player2_uid); } } { bool isFind = false; for (int j = 0; j < listPlayer.Count; j++) { if (listPlayer[j] == listData[i].Player3_uid) { isFind = true; break; } } if (!isFind) { listPlayer.Add(listData[i].Player3_uid); } } { bool isFind = false; for (int j = 0; j < listPlayer.Count; j++) { if (listPlayer[j] == listData[i].Player4_uid) { isFind = true; break; } } if (!isFind) { listPlayer.Add(listData[i].Player4_uid); } } } return("游戏人数:" + listPlayer.Count + "\r\n"); } else { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <Log_Game> listData = await proxyComponent.QueryJsonDBInfos <Log_Game>(time); List <long> listPlayer = new List <long>(); for (int i = 0; i < listData.Count; i++) { { bool isFind = false; for (int j = 0; j < listPlayer.Count; j++) { if (listPlayer[j] == listData[i].Player1_uid) { isFind = true; break; } } if (!isFind) { listPlayer.Add(listData[i].Player1_uid); } } { bool isFind = false; for (int j = 0; j < listPlayer.Count; j++) { if (listPlayer[j] == listData[i].Player2_uid) { isFind = true; break; } } if (!isFind) { listPlayer.Add(listData[i].Player2_uid); } } { bool isFind = false; for (int j = 0; j < listPlayer.Count; j++) { if (listPlayer[j] == listData[i].Player3_uid) { isFind = true; break; } } if (!isFind) { listPlayer.Add(listData[i].Player3_uid); } } { bool isFind = false; for (int j = 0; j < listPlayer.Count; j++) { if (listPlayer[j] == listData[i].Player4_uid) { isFind = true; break; } } if (!isFind) { listPlayer.Add(listData[i].Player4_uid); } } } int count = 0; for (int i = 0; i < listPlayer.Count; i++) { AccountInfo accountInfo = await DBCommonUtil.getAccountInfo(listPlayer[i]); if (accountInfo.ChannelName.CompareTo(channelName) == 0) { ++count; } } return("游戏人数:" + count + "\r\n"); } }