public static async Task Delete <T>(this DBProxyComponent self, long id)
 {
     DBComponent dbComponent = Game.Scene.GetComponent <DBComponent>();
     await dbComponent.GetCollection(typeof(T).Name).DeleteOneAsync(i => i.Id == id);
 }
        protected override async void Run(Session session, C2G_GetFriendTreasure message, Action <G2C_GetFriendTreasure> reply)
        {
            G2C_GetFriendTreasure response = new G2C_GetFriendTreasure();

            try
            {
                //获取房间信息
                DBProxyComponent       proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                List <FriendKeyConsum> consums        = await proxyComponent.QueryJson <FriendKeyConsum>($"{{UId:{message.UId},CreateTime:/^{DateTime.Now.GetCurrentDay()}/}}");

                if (consums.Count > 0)
                {
                    if (consums[0].ConsumCount >= 5)
                    {
                        if (consums[0].GetCount >= 5)
                        {
                            response.Error   = ErrorCode.ERR_Common;
                            response.Message = "今日领取次数已经满5次,不能领取";
                            reply(response);
                            return;
                        }
                        else
                        {
                            //可以领取
                            consums[0].GetCount    += 1;
                            consums[0].ConsumCount -= 5;
                            await proxyComponent.Save(consums[0]);

                            int rd = Common_Random.getRandom(1, 100);
                            if (rd > 69)
                            {
                                //一个话费红包和五千金币
                                await DBCommonUtil.changeWealthWithStr(message.UId, "111:1;1:5000", "好友房开启宝箱获得");

                                response.Reward = "111:1;1:5000";
                            }
                            else if (rd >= 69 && rd < 99)
                            {
                                //二个话费红包和一千金币
                                await DBCommonUtil.changeWealthWithStr(message.UId, "111:2;1:10000", "好友房开启宝箱获得");

                                response.Reward = "111:2;1:10000";
                            }
                            else
                            {
                                //五个话费红包和一千金币
                                await DBCommonUtil.changeWealthWithStr(message.UId, "111:5;1:10000", "好友房开启宝箱获得");

                                response.Reward = "111:5;1:10000";
                            }

                            response.AlGetCount = consums[0].GetCount;
                            response.KeyCount   = consums[0].ConsumCount;
                        }
                    }
                    else
                    {
                        response.Error   = ErrorCode.ERR_Common;
                        response.Message = "今日剩余消耗的钥匙次数不满五个,不能领取";
                        reply(response);
                        return;
                    }
                }
                else
                {
                    response.Error   = ErrorCode.ERR_Common;
                    response.Message = "今日消耗的钥匙不足五个,不能领取";
                    reply(response);
                    return;
                }
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
 /// <summary>
 /// 根據json刪除一筆或多筆紀錄
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="self"></param>
 /// <param name="json"></param>
 /// <returns></returns>
 public static async ETTask DeleteJson <T>(this DBProxyComponent self, string json) where T : ComponentWithId
 {
     Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress);
     DBDeleteJsonResponse dbQueryJsonResponse = (DBDeleteJsonResponse)await session.Call(new DBDeleteJsonRequest { CollectionName = typeof(T).Name, Json = json });
 }
Exemple #4
0
        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);
            }
        }
        protected override async void Run(Session session, C2G_Email message, Action <G2C_Email> reply)
        {
            G2C_Email response = new G2C_Email();

            try
            {
                DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                DBComponent      dbComponent    = Game.Scene.GetComponent <DBComponent>();
                FilterDefinition <ComponentWithId> filterDefinition = new JsonFilterDefinition <ComponentWithId>($"{{UId:{message.Uid}}}");
                List <ComponentWithId>             components       = await dbComponent.GetCollection(typeof(EmailInfo).Name).FindAsync(filterDefinition).Result.ToListAsync();


                List <EmailInfo> listEmail = new List <EmailInfo>();

                // 未读
                for (int i = components.Count - 1; i >= 0; i--)
                {
                    if (((EmailInfo)components[i]).State == 0)
                    {
                        listEmail.Add((EmailInfo)components[i]);

                        if (listEmail.Count >= 50)
                        {
                            break;
                        }
                    }
                }

                // 已读
                if (listEmail.Count < 50)
                {
                    for (int i = components.Count - 1; i >= 0; i--)
                    {
                        if (((EmailInfo)components[i]).State == 1)
                        {
                            listEmail.Add((EmailInfo)components[i]);

                            if (listEmail.Count >= 50)
                            {
                                break;
                            }
                        }
                    }
                }

                List <Email> emailList = new List <Email>();
                for (int i = 0; i < listEmail.Count; ++i)
                {
                    EmailInfo info  = listEmail[i];
                    Email     email = new Email();
                    email.EmailTitle = info.EmailTitle;
                    email.Content    = info.Content;
                    email.State      = info.State;
                    email.RewardItem = info.RewardItem;
                    email.Date       = info.CreateTime;
                    email.EId        = info.EmailId;
                    emailList.Add(email);
                }
                response.EmailInfoList = emailList;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemple #6
0
        protected override async void Run(Session session, C2G_WeekRank message, Action <G2C_WeekRank> reply)
        {
            G2C_WeekRank response = new G2C_WeekRank();

            try
            {
                DBProxyComponent      proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                List <PlayerBaseInfo> info           = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}");

                List <WeekRank> weekRank = await proxyComponent.QueryJson <WeekRank>($"{{UId:{message.UId}}}");

                if (weekRank.Count <= 0)
                {
                    WeekRank weekInfo = ComponentFactory.CreateWithId <WeekRank>(IdGenerater.GenerateId());
                    weekInfo.UId           = message.UId;
                    weekInfo.IsGetGameRank = false;
                    weekInfo.IsGetGoldRank = false;
                    weekInfo.GameIndex     = -1;
                    weekInfo.GoldIndex     = -1;
                    await proxyComponent.Save(weekInfo);
                }
                else
                {
                    response.IsGetGameRank = weekRank[0].IsGetGameRank;
                    response.IsGetGoldRank = weekRank[0].IsGetGoldRank;
                    response.GameIndex     = weekRank[0].GameIndex;
                    response.WealthIndex   = weekRank[0].GoldIndex;
                    reply(response);
                    return;
                }

                weekRank = await proxyComponent.QueryJson <WeekRank>($"{{UId:{message.UId}}}");

                if (CommonUtil.IsMonday())
                {
                    for (int i = 0; i < Game.Scene.GetComponent <RankDataComponent>().GetFWealthRankData().Count; ++i)
                    {
                        if (message.UId == Game.Scene.GetComponent <RankDataComponent>().GetFWealthRankData()[i].UId)
                        {
                            weekRank[0].IsGetGoldRank = true;
                            weekRank[0].GoldIndex     = i + 1;
                            await proxyComponent.Save(weekRank[0]);

                            break;
                        }
                        else
                        {
                            weekRank[0].IsGetGoldRank = false;
                            weekRank[0].GoldIndex     = -1;
                            await proxyComponent.Save(weekRank[0]);
                        }
                    }

                    for (int i = 0; i < Game.Scene.GetComponent <RankDataComponent>().GetFGameRankData().Count; ++i)
                    {
                        if (message.UId == Game.Scene.GetComponent <RankDataComponent>().GetFGameRankData()[i].UId)
                        {
                            weekRank[0].IsGetGameRank = true;
                            weekRank[0].GameIndex     = i + 1;
                            await proxyComponent.Save(weekRank[0]);

                            break;
                        }
                        else
                        {
                            weekRank[0].IsGetGameRank = false;
                            weekRank[0].GameIndex     = -1;
                            await proxyComponent.Save(weekRank[0]);
                        }
                    }
                }
                else
                {
                    weekRank[0].IsGetGameRank = false;
                    weekRank[0].IsGetGoldRank = false;
                    weekRank[0].GameIndex     = -1;
                    weekRank[0].GoldIndex     = -1;
                    await proxyComponent.Save(weekRank[0]);
                }

                response.IsGetGameRank = weekRank[0].IsGetGameRank;
                response.IsGetGoldRank = weekRank[0].IsGetGoldRank;
                response.GameIndex     = weekRank[0].GameIndex;
                response.WealthIndex   = weekRank[0].GoldIndex;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemple #7
0
 public static async Task Save(this DBProxyComponent self, ComponentWithId component, bool needCache, CancellationToken cancellationToken)
 {
     Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress);
     await session.Call(new DBSaveRequest { Component = component, NeedCache = needCache }, cancellationToken);
 }
Exemple #8
0
        protected override async void Run(Session session, C2G_UpdateMainAccount message, Action <G2C_UpdateMainAccount> reply)
        {
            G2C_UpdateMainAccount response    = new G2C_UpdateMainAccount();
            MainAccount           mainAccount = null;

            try
            {
                DBProxyComponent dBProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                var acounts = await dBProxyComponent.Query <MainAccount>("{ '_AccountID': " + message.AccountID + "}");

                if (acounts.Count <= 0)
                {
                }
                else
                {
                    mainAccount = acounts[0] as MainAccount;

                    if (message.InfoID != -1)
                    {
                        mainAccount._InfoID = message.InfoID;
                    }
                    if (message.Account != "")
                    {
                        mainAccount._Account = message.Account;
                    }
                    if (message.Password != "")
                    {
                        mainAccount._Password = message.Password;
                    }
                    if (message.EMail != "")
                    {
                        mainAccount._EMail = message.EMail;
                    }
                    if (message.LastOnlineTime != "")
                    {
                        mainAccount._LastOnlineTime = message.LastOnlineTime;
                    }
                    if (message.CumulativeTime != -1)
                    {
                        mainAccount._CumulativeTime += message.CumulativeTime;
                    }
                    if (message.State != -1)
                    {
                        mainAccount._State = message.State;
                    }
                }

                await dBProxyComponent.Save(mainAccount);

                await dBProxyComponent.SaveLog(mainAccount);

                reply(response);
            }
            catch (Exception e)
            {
                response.IsOk    = false;
                response.Message = "数据库异常";
                ReplyError(response, e, reply);
            }
        }
Exemple #9
0
        protected override async void Run(Session session, C2G_UpdateAccountInfo message, Action <G2C_UpdateAccountInfo> reply)
        {
            G2C_UpdateAccountInfo response    = new G2C_UpdateAccountInfo();
            AccountInfo           accountInfo = null;

            try
            {
                DBProxyComponent dBProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                var acounts = await dBProxyComponent.Query <AccountInfo>("{ '_AccountID': " + message.AccountID + "}");

                if (acounts.Count <= 0)
                {
                    //修改的时候查询不到说明数据库有问题
                    //AccountInfo Info = ComponentFactory.Create<AccountInfo>();
                    //Info._AccountID = message.AccountID;
                    //Info._Name = message.Name;
                    //Info._BornDate = message.BornDate;
                    //Info._IDCardNumber = message.IDCardNumber;
                    //Info._Sex = message.Sex;
                    //Info._IsFinishIdentify = message.IsFinishIdentify;
                    //Info._HeadImage = message.HeadImage;
                    //Info._FingerprintCode = message.FingerprintCode;
                    //Info._UserImpotentLevel = message.UserImpotentLevel;

                    //await dBProxyComponent.Save(Info);
                    //await dBProxyComponent.SaveLog(Info);
                }
                else
                {
                    accountInfo = acounts[0] as AccountInfo;

                    if (message.Name != "")
                    {
                        accountInfo._Name = message.Name;
                    }
                    if (message.BornDate != "")
                    {
                        accountInfo._BornDate = message.BornDate;
                    }
                    if (message.IDCardNumber != "")
                    {
                        accountInfo._IDCardNumber = message.IDCardNumber;
                    }
                    if (message.Sex != -1)
                    {
                        accountInfo._Sex = message.Sex;
                    }
                    if (message.IsFinishIdentify != -1)
                    {
                        accountInfo._IsFinishIdentify = message.IsFinishIdentify;
                    }
                    if (message.HeadImage != "")
                    {
                        accountInfo._HeadImage = message.HeadImage;
                    }
                    if (message.FingerprintCode != "")
                    {
                        accountInfo._FingerprintCode = message.FingerprintCode;
                    }
                    if (message.UserImpotentLevel != -1)
                    {
                        accountInfo._UserImpotentLevel = message.UserImpotentLevel;
                    }
                    if (message.FaceprintCode != "")
                    {
                        accountInfo._FaceprintCode = message.FaceprintCode;
                    }
                    if (message.PrintType != -1)
                    {
                        accountInfo._PrintType = message.PrintType;
                    }
                }

                await dBProxyComponent.Save(accountInfo);

                await dBProxyComponent.SaveLog(accountInfo);

                reply(response);
            }
            catch (Exception e)
            {
                response.IsOk    = false;
                response.Message = "数据库异常";
                ReplyError(response, e, reply);
            }
        }
Exemple #10
0
        protected override async void Run(Session session, A0009_CreateNewCharacter_C2G message, Action <A0009_CreateNewCharacter_G2C> reply)
        {
            A0009_CreateNewCharacter_G2C response = new A0009_CreateNewCharacter_G2C();

            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_UserNotOnline;
                    reply(response);
                    return;
                }

                //获取玩家对象
                User user = session.GetComponent <SessionUserComponent>().User;

                //获取玩家所在大区编号
                DBProxyComponent dbProxy  = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         userInfo = await dbProxy.Query <UserInfo>(user.UserID);

                int GateAppId = RealmHelper.GetGateAppIdFromUserId(userInfo.Id);

                //检查角色名是否可用
                //会得到全部大区的同名角色 需遍历排除
                List <ComponentWithId> result = await dbProxy.Query <Character>($"{{Name:'{message.Name}'}}");

                foreach (var a in result)
                {
                    if (RealmHelper.GetGateAppIdFromUserId(((Character)a).UserID) == GateAppId)
                    {
                        //出现同名角色
                        response.Error = ErrorCode.ERR_CreateNewCharacter;
                        reply(response);
                        return;
                    }
                }

                //检查玩家是否有资格创建新角色
                bool canCreate     = false;
                int  characterSeat = message.Seat; //玩家请求创建的角色位置
                switch (characterSeat)
                {
                case 1:
                    if (userInfo.CharacterID1 == 0)
                    {
                        canCreate = true;
                    }
                    break;

                case 2:
                    if (userInfo.CharacterID2 == 0)
                    {
                        canCreate = true;
                    }
                    break;

                case 3:
                    if (userInfo.CharacterID3 == 0)
                    {
                        canCreate = true;
                    }
                    break;

                default:
                    break;
                }

                //判定为无法创建角色时返回错误消息
                if (!canCreate)
                {
                    //理应不该出现这个错误
                    //当玩家位置满时 点击创建角色按钮应有提示 无法进入创建角色界面
                    Log.Error("玩家当前位置已有角色");
                    response.Error = ErrorCode.ERR_CreateNewCharacter;
                    reply(response);
                    return;
                }

                //新建角色数据 角色可以通过UserID来识别区号 可以不使用CreateWithId方法
                Character character = ComponentFactory.CreateWithId <Character, long>(RealmHelper.GenerateId(), userInfo.Id);
                character.Name     = message.Name;
                character.Level    = 1;
                character.Career   = message.Career;
                character.Pet      = PetType.NonePet;
                character.Skeleton = message.Skeleton;
                switch (character.Career) //初始装备是绑定职业的
                {
                case CareerType.Warror:
                    character.Weapon = WeaponType.Sword;
                    character.Head   = HeadType.Head1;
                    character.Chest  = ChestType.Chest1;
                    character.Hand   = HandType.Hand1;
                    character.Feet   = FeetType.Feet1;
                    break;

                case CareerType.Mage:
                    character.Weapon = WeaponType.Wand;
                    character.Head   = HeadType.Head2;
                    character.Chest  = ChestType.Chest2;
                    character.Hand   = HandType.Hand2;
                    character.Feet   = FeetType.Feet2;
                    break;
                }
                character.Region = RegionType.Village; //初始地图为村庄
                character.X      = 1;                  //设置初始坐标
                character.Y      = 2;
                character.Z      = 3;
                character.Money  = 10;
                character.Mail   = 0;

                //存储数据
                switch (characterSeat)
                {
                case 1:
                    userInfo.CharacterID1 = character.Id;
                    userInfo.LastPlay     = 1;
                    break;

                case 2:
                    userInfo.CharacterID2 = character.Id;
                    userInfo.LastPlay     = 2;
                    break;

                case 3:
                    userInfo.CharacterID3 = character.Id;
                    userInfo.LastPlay     = 3;
                    break;

                default:
                    throw new Exception($"创建新角色错误:{userInfo.Id}");
                }

                await dbProxy.Save(character);

                await dbProxy.Save(userInfo);

                Log.Debug($"新增一个角色{character.Id}");
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemple #11
0
        protected override async void Run(Session session, C2G_QueryAccountInfo message, Action <G2C_QueryAccountInfo> reply)
        {
            G2C_QueryAccountInfo response    = new G2C_QueryAccountInfo();
            AccountInfo          accountInfo = null;

            try
            {
                DBProxyComponent dBProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                var acounts = await dBProxyComponent.Query <AccountInfo>("{ '_AccountID': " + message.AccountID + "}");

                if (acounts.Count <= 0)
                {
                    AccountInfo Info = ComponentFactory.Create <AccountInfo>();
                    Info._AccountID         = message.AccountID;
                    Info._Name              = "皮皮鱼";
                    Info._BornDate          = DateTime.Now.ToString("yyyy-MM-dd");
                    Info._IDCardNumber      = "";
                    Info._Sex               = 0;
                    Info._IsFinishIdentify  = 0;
                    Info._HeadImage         = "";
                    Info._FingerprintCode   = "";
                    Info._UserImpotentLevel = 0;

                    response.Name              = Info._Name;
                    response.BornDate          = Info._BornDate;
                    response.IDCardNumber      = Info._IDCardNumber;
                    response.Sex               = Info._Sex;
                    response.IsFinishIdentify  = Info._IsFinishIdentify;
                    response.HeadImage         = Info._HeadImage;
                    response.FingerprintCode   = Info._FingerprintCode;
                    response.UserImpotentLevel = Info._UserImpotentLevel;
                    response.FaceprintCode     = Info._FaceprintCode;
                    response.PrintType         = Info._PrintType;
                    await dBProxyComponent.Save(Info);

                    await dBProxyComponent.SaveLog(Info);
                }
                else
                {
                    accountInfo = acounts[0] as AccountInfo;

                    response.Name              = accountInfo._Name;
                    response.BornDate          = accountInfo._BornDate;
                    response.IDCardNumber      = accountInfo._IDCardNumber;
                    response.Sex               = accountInfo._Sex;
                    response.IsFinishIdentify  = accountInfo._IsFinishIdentify;
                    response.HeadImage         = accountInfo._HeadImage;
                    response.FingerprintCode   = accountInfo._FingerprintCode;
                    response.UserImpotentLevel = accountInfo._UserImpotentLevel;
                    response.FaceprintCode     = accountInfo._FaceprintCode;
                    response.PrintType         = accountInfo._PrintType;
                    await dBProxyComponent.Save(accountInfo);

                    await dBProxyComponent.SaveLog(accountInfo);
                }

                reply(response);
            }
            catch (Exception e)
            {
                response.Message = "数据库异常";
                ReplyError(response, e, reply);
            }
        }
Exemple #12
0
        protected override async void Run(Session session, C2G_Task message, Action <G2C_Task> reply)
        {
            G2C_Task response = new G2C_Task();

            try
            {
                List <TaskInfo>         taskInfoList         = new List <TaskInfo>();
                DBProxyComponent        proxyComponent       = Game.Scene.GetComponent <DBProxyComponent>();
                ConfigComponent         configCom            = Game.Scene.GetComponent <ConfigComponent>();
                List <TaskProgressInfo> taskProgressInfoList = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{message.uid}}}");

                if (taskProgressInfoList.Count <= 0)
                {
                    for (int j = 0; j < TaskData.getInstance().getDataList().Count; ++j)
                    {
                        TaskProgressInfo info = ComponentFactory.CreateWithId <TaskProgressInfo>(IdGenerater.GenerateId());
                        info.UId         = message.uid;
                        info.Name        = TaskData.getInstance().getDataList()[j].Name;
                        info.TaskId      = (int)TaskData.getInstance().getDataList()[j].Id;
                        info.Target      = TaskData.getInstance().getDataList()[j].Target;
                        info.Reward      = TaskData.getInstance().getDataList()[j].Reward;
                        info.Desc        = TaskData.getInstance().getDataList()[j].Desc;
                        info.CurProgress = 0;
                        await proxyComponent.Save(info);
                    }
                    taskProgressInfoList = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{message.uid}}}");
                }
                else if (taskProgressInfoList.Count < TaskData.getInstance().getDataList().Count)
                {
                    for (int i = 0; i < TaskData.getInstance().getDataList().Count; ++i)
                    {
                        List <TaskProgressInfo> infos = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{message.uid},TaskId:{ TaskData.getInstance().getDataList()[i].Id}}}");

                        if (infos.Count <= 0)
                        {
                            TaskConfig       config = TaskData.getInstance().GetDataByTaskId(TaskData.getInstance().getDataList()[i].Id);
                            TaskProgressInfo info   = ComponentFactory.CreateWithId <TaskProgressInfo>(IdGenerater.GenerateId());
                            info.UId         = message.uid;
                            info.Name        = config.Name;
                            info.TaskId      = (int)config.Id;
                            info.Target      = config.Target;
                            info.Reward      = config.Reward;
                            info.Desc        = config.Desc;
                            info.CurProgress = 0;
                            await proxyComponent.Save(info);
                        }
                    }
                    taskProgressInfoList = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{message.uid}}}");
                }

                for (int i = 0; i < taskProgressInfoList.Count; ++i)
                {
                    TaskInfo         taskInfo     = new TaskInfo();
                    TaskProgressInfo taskProgress = taskProgressInfoList[i];
                    taskInfo.Id         = taskProgress.TaskId;
                    taskInfo.TaskName   = taskProgress.Name;
                    taskInfo.Desc       = taskProgress.Desc;
                    taskInfo.Reward     = taskProgress.Reward;
                    taskInfo.IsComplete = taskProgress.IsComplete;
                    taskInfo.IsGet      = taskProgress.IsGet;
                    taskInfo.Progress   = taskProgress.CurProgress;
                    taskInfo.Target     = taskProgress.Target;
                    taskInfoList.Add(taskInfo);
                }

                response.TaskProgressList = taskInfoList;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        public static void Awake(this DBProxyComponent self)
        {
            StartConfig dbStartConfig = Game.Scene.GetComponent <StartConfigComponent>().DBConfig;

            self.dbAddress = dbStartConfig.GetComponent <InnerConfig>().IPEndPoint;
        }
 public static async Task DeleteAll <T>(this DBProxyComponent self)
 {
     DBComponent dbComponent = Game.Scene.GetComponent <DBComponent>();
     var         filter      = Builders <ComponentWithId> .Filter.Empty;
     await dbComponent.GetCollection(typeof(T).Name).DeleteManyAsync(filter);
 }
        protected override async void Run(Session session, C2R_ThirdLogin message, Action <R2C_ThirdLogin> reply)
        {
            Log.Info("收到第三方登录");

            R2C_ThirdLogin response = new R2C_ThirdLogin();

            try
            {
                DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                bool any = (await proxyComponent.Query <AccountInfo>(a => a.Third_Id == message.Third_Id && a.Token == "")).Any();

                List <AccountInfo> accountInfos = await proxyComponent.QueryJson <AccountInfo>($"{{Third_Id:'{message.Third_Id}'}}");

                // 用户已存在,走登录流程
                if (accountInfos.Count > 0)
                {
                    AccountInfo accountInfo = accountInfos[0];
                    // 黑名单检测
                    if (await DBCommonUtil.CheckIsInBlackList(accountInfo.Id, session))
                    {
                        response.Message = "您的账号存在异常,请联系客服处理。";
                        response.Error   = ErrorCode.ERR_PhoneCodeError;
                        reply(response);
                        return;
                    }
                    // 随机分配一个Gate
                    StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                    IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                    Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                    // 向gate请求一个key,客户端可以拿着这个key连接gate
                    G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                    {
                        UserId = accountInfo.Id
                    });

                    string outerAddress = config.GetComponent <OuterConfig>().IPEndPoint2.ToString();

//                    Log.Warning("Gate的ip:" + outerAddress);

                    response.Address = outerAddress;
                    response.Key     = g2RGetLoginKey.Key;
                    reply(response);

                    // 登录日志
                    await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                }
                // 用户不存在,走注册流程
                else
                {
                    AccountInfo accountInfo = ComponentFactory.CreateWithId <AccountInfo>(UidUtil.createUID());
                    accountInfo.Third_Id      = message.Third_Id;
                    accountInfo.MachineId     = message.MachineId;
                    accountInfo.ChannelName   = message.ChannelName;
                    accountInfo.ClientVersion = message.ClientVersion;

                    await proxyComponent.Save(accountInfo);

                    // 添加用户信息
                    PlayerBaseInfo playerBaseInfo = await DBCommonUtil.addPlayerBaseInfo(accountInfo.Id, "", message.Name, message.Head);

                    // 随机分配一个Gate
                    StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                    IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                    Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                    // 向gate请求一个key,客户端可以拿着这个key连接gate
                    G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                    {
                        UserId = accountInfo.Id
                    });

                    string outerAddress = config.GetComponent <OuterConfig>().IPEndPoint2.ToString();

                    response.Address = outerAddress;
                    response.Key     = g2RGetLoginKey.Key;
                    reply(response);

                    // 登录日志
                    await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
            session.Dispose();
        }
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                //数据库检测(可删)
                //if (message.Account != "abcdef" || message.Password != "111111")
                //{
                //	response.Error = ErrorCode.ERR_AccountOrPasswordError;
                //	reply(response);
                //	return;
                //}



                //TODO 数据库相关功能   mangodb数据库根据json查询条件查询
                DBProxyComponent       dbProxy  = Game.Scene.GetComponent <DBProxyComponent>();
                List <ComponentWithId> accounts = await dbProxy.Query <Account>($"{{\'username\':\'{message.Account}\'}}");

                //如果没有查找到玩家
                if (accounts.Count == 0)
                {
                    Account account = new Account();
                    Log.Debug("账号不存在,正在保存账号");
                    //保存账号
                    await dbProxy.Save(account);
                }
                else
                {
                    Account account = (Account)accounts[0];
                    Log.Debug("查找到了" + accounts);
                    if (message.Password != account.password)
                    {
                        Log.Debug("密码正确");
                        return;
                    }
                }



                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

                string outerAddress = config.GetComponent <OuterConfig>().Address2;

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemple #17
0
        protected override async Task Run(Gamer gamer, C2M_ActorGamerGetTreasure message, Action <M2C_ActorGamerGetTreasure> reply)
        {
            M2C_ActorGamerGetTreasure response = new M2C_ActorGamerGetTreasure();

            try
            {
                DBProxyComponent proxyComponent  = Game.Scene.GetComponent <DBProxyComponent>();
                ConfigComponent  configComponent = Game.Scene.GetComponent <ConfigComponent>();

                //记录数据
                gamer.EndTime = DateTime.Now;
                TimeSpan span         = gamer.EndTime - gamer.StartTime;
                int      totalSeconds = (int)span.TotalSeconds;
                //await DBCommonUtil.RecordGamerTime(gamer.EndTime, false, gamer.UserID);
                await DBCommonUtil.RecordGamerInfo(gamer.UserID, totalSeconds);

                List <GamerInfoDB> gamerInfos = await proxyComponent.QueryJson <GamerInfoDB>($"{{UId:{gamer.UserID}}}");

                if (gamerInfos.Count == 0)
                {
                    response.Error   = ErrorCode.ERR_Common;
                    response.Message = "未到时间";
                    reply(response);
                    return;
                }
                GamerInfoDB gamerInfo = gamerInfos[0];
                gamerInfo.DailyTreasureCount++;
                TreasureConfig config = configComponent.Get(typeof(TreasureConfig), gamerInfo.DailyTreasureCount) as TreasureConfig;

                Log.Debug("config:" + JsonHelper.ToJson(config));

                if (config == null)
                {
                    response.Error   = ErrorCode.ERR_Common;
                    response.Message = "宝箱已领取完";
                }
                else
                {
                    if (gamerInfo.DailyOnlineTime >= config.TotalTime)
                    {
                        await DBCommonUtil.ChangeWealth(gamer.UserID, 1, config.Reward, "游戏内宝箱奖励");

                        await proxyComponent.Save(gamerInfo);

                        //下一个奖励
                        TreasureConfig treasureConfig = (TreasureConfig)configComponent.Get(typeof(TreasureConfig), ++gamerInfo.DailyTreasureCount);
                        //宝箱领完了
                        if (treasureConfig == null)
                        {
                            response.RestSeconds = -1;
                            response.Reward      = config.Reward;
                        }
                        else
                        {
                            response.RestSeconds = treasureConfig.TotalTime - gamerInfo.DailyOnlineTime;
                            response.Reward      = config.Reward;
                        }
                    }
                    else
                    {
                        response.Error   = ErrorCode.ERR_Common;
                        response.Message = "未到时间";
                    }
                }

                reply(response);

                gamer.StartTime = DateTime.Now;
                //await DBCommonUtil.RecordGamerTime(gamer.EndTime, false, gamer.UserID);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }

            await Task.CompletedTask;
        }
        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;
            }
        }
Exemple #19
0
 /// <summary>
 /// 发送消息将组件批量存到数据库
 /// </summary>
 /// <param name="self"></param>
 /// <param name="components">需保持的组件链表</param>
 /// <param name="needCache">是否缓存</param>
 /// <returns></returns>
 public static async Task SaveBatch(this DBProxyComponent self, List <ComponentWithId> components, bool needCache = true)
 {
     Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress);
     await session.Call(new DBSaveBatchRequest { Components = components, NeedCache = needCache });
 }
Exemple #20
0
 public static async ETTask Save(this DBProxyComponent self, ComponentWithId component)
 {
     Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress);
     await session.Call(new DBSaveRequest { Component = component });
 }
Exemple #21
0
 /// <summary>
 /// 保存到LOG  不需要缓存
 /// </summary>
 /// <param name="self"></param>
 /// <param name="component"></param>
 public static async void SaveLog(this DBProxyComponent self, ComponentWithId component)
 {
     Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress);
     await session.Call(new DBSaveRequest { Component = component, NeedCache = false, CollectionName = "Log" });
 }
Exemple #22
0
        private async ETVoid RunAsync(Session session, C2R_RegisterAndLogin message, Action <R2C_RegisterAndLogin> reply)
        {
            Console.WriteLine(" --> C2R_RegisterAndLoginHandler");

            R2C_RegisterAndLogin response = new R2C_RegisterAndLogin();

            try
            {
                Console.WriteLine("account : " + message.Account + " password : "******"dbProxy : " + dbProxy);

                    //查询账号是否存在  使用LINQ和Lambda表达式根据特定条件来查询
                    List <ComponentWithId> result = await dbProxy.Query <AccountInfo>(_account => _account.Account == message.Account);

                    Console.WriteLine("result : " + result);

                    if (result.Count > 0)
                    {
                        Console.WriteLine("result.Count : " + result.Count);

                        response.Error = ErrorCode.ERR_AccountAlreadyRegister;
                        reply(response);
                        return;
                    }
                    Console.WriteLine("新建账号 : ");

                    //新建账号
                    AccountInfo newAccount = ComponentFactory.CreateWithId <AccountInfo>(IdGenerater.GenerateId());
                    newAccount.Account  = message.Account;
                    newAccount.Password = message.Password;

                    Log.Info($"注册新账号:{MongoHelper.ToJson(newAccount)}");

                    //新建用户信息
                    UserInfo newUser = ComponentFactory.CreateWithId <UserInfo>(newAccount.Id);
                    newUser.Nickname = $"用户{message.Account}";
                    newUser.Gold     = 10000;

                    //保存到数据库
                    await dbProxy.Save(newAccount);

                    await dbProxy.Save(newUser);

                    //释放数据库连接
                    dbProxy.Dispose();
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

                string outerAddress = config.GetComponent <OuterConfig>().Address2;

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemple #23
0
        protected override async void Run(Session session, A0008_GetUserInfo_C2G message, Action <A0008_GetUserInfo_G2C> reply)
        {
            A0008_GetUserInfo_G2C response = new A0008_GetUserInfo_G2C();

            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_UserNotOnline;
                    reply(response);
                    return;
                }

                //获取玩家对象
                User user = session.GetComponent <SessionUserComponent>().User;

                DBProxyComponent dbProxy  = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         userInfo = await dbProxy.Query <UserInfo>(user.UserID);

                if (userInfo.CharacterID1 != 0)
                {
                    Character character = await dbProxy.Query <Character>(userInfo.CharacterID1);

                    response.Characters.Add(new CharacterInfo()
                    {
                        Name     = character.Name,
                        Level    = character.Level,
                        Career   = character.Career,
                        Pet      = character.Pet,
                        Skeleton = character.Skeleton,
                        Weapon   = character.Weapon,
                        Region   = character.Region,
                        X        = character.X,
                        Y        = character.Y,
                        Z        = character.Z,
                        Head     = character.Head,
                        Chest    = character.Chest,
                        Hand     = character.Hand,
                        Feet     = character.Feet,
                        Money    = character.Money,
                        Mail     = character.Mail
                    });
                }
                else
                {
                    response.Characters.Add(new CharacterInfo());
                }

                if (userInfo.CharacterID2 != 0)
                {
                    Character character = await dbProxy.Query <Character>(userInfo.CharacterID2);

                    response.Characters.Add(new CharacterInfo()
                    {
                        Name     = character.Name,
                        Level    = character.Level,
                        Career   = character.Career,
                        Pet      = character.Pet,
                        Skeleton = character.Skeleton,
                        Weapon   = character.Weapon,
                        Region   = character.Region,
                        X        = character.X,
                        Y        = character.Y,
                        Z        = character.Z,
                        Head     = character.Head,
                        Chest    = character.Chest,
                        Hand     = character.Hand,
                        Feet     = character.Feet,
                        Money    = character.Money,
                        Mail     = character.Mail
                    });
                }
                else
                {
                    response.Characters.Add(new CharacterInfo());
                }

                if (userInfo.CharacterID3 != 0)
                {
                    Character character = await dbProxy.Query <Character>(userInfo.CharacterID3);

                    response.Characters.Add(new CharacterInfo()
                    {
                        Name     = character.Name,
                        Level    = character.Level,
                        Career   = character.Career,
                        Pet      = character.Pet,
                        Skeleton = character.Skeleton,
                        Weapon   = character.Weapon,
                        Region   = character.Region,
                        X        = character.X,
                        Y        = character.Y,
                        Z        = character.Z,
                        Head     = character.Head,
                        Chest    = character.Chest,
                        Hand     = character.Hand,
                        Feet     = character.Feet,
                        Money    = character.Money,
                        Mail     = character.Mail
                    });
                }
                else
                {
                    response.Characters.Add(new CharacterInfo());
                }

                //设置上次游戏角色
                response.LastPlay = userInfo.LastPlay;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemple #24
0
        //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);
            }
        }
Exemple #25
0
        protected override async void Run(Session session, C2G_BuyItem message, Action <G2C_BuyItem> reply)
        {
            G2C_BuyItem response = new G2C_BuyItem();

            try
            {
                DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                ShopConfig config = ConfigHelp.Get <ShopConfig>(message.ShopId);
                int        shopId = CommonUtil.splitStr_Start(config.Items.ToString(), ':');
                int        count  = CommonUtil.splitStr_End(config.Items.ToString(), ':');
                int        cost   = 0;
                if (await DBCommonUtil.IsVIP(message.UId))
                {
                    cost = config.VipPrice;
                }
                else
                {
                    cost = config.Price;
                }

                await DBCommonUtil.ChangeWealth(message.UId, config.CurrencyType, -cost, $"花费{cost}元宝购买商品{config.Name}");

                List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}");

                switch (config.CurrencyType)
                {
                //金币
                case 1:
                    response.Wealth   = playerBaseInfos[0].GoldNum;
                    response.ShopType = 2;
                    break;

                //元宝
                case 2:
                    response.Wealth   = playerBaseInfos[0].WingNum;
                    response.ShopType = 1;
                    break;
                }
                //购买金币
                if (shopId == 1)
                {
                    await DBCommonUtil.ChangeWealth(message.UId, 1, count, $"商城购买{count}金币");
                }
                else if (shopId == 112)
                {
                    await DBCommonUtil.AddFriendKey(message.UId, count, "-1", $"商城购买{count}个{config.Name}道具");
                }
                else
                {
                    List <UserBag> itemInfos = await proxyComponent.QueryJson <UserBag>($"{{UId:{message.UId},BagId:{shopId}}}");

                    await DBCommonUtil.ChangeWealth(message.UId, shopId, count, $"商城购买{count}个{config.Name}道具");
                }

                response.Count = count;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemple #26
0
        protected override async void Run(Session session, C2R_PhoneLogin message, Action <R2C_PhoneLogin> reply)
        {
            Log.Info(JsonHelper.ToJson(message));
            R2C_PhoneLogin response = new R2C_PhoneLogin();

            try
            {
                DBProxyComponent   proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                List <AccountInfo> accountInfos   = await proxyComponent.QueryJson <AccountInfo>($"{{Phone:'{message.Phone}'}}");

                // 用验证码登录
                if (message.Code.CompareTo("") != 0)
                {
                    // 先校验验证码
                    {
                        string str = HttpUtil.CheckSms("0", message.Phone, message.Code);
                        if (!CommonUtil.checkSmsCode(str))
                        {
                            response.Message = "验证码错误";
                            response.Error   = ErrorCode.ERR_PhoneCodeError;
                            reply(response);
                            return;
                        }
                    }
                    // 用户已存在,走登录流程
                    if (accountInfos.Count > 0)
                    {
                        AccountInfo accountInfo = accountInfos[0];

                        // 黑名单检测
                        if (await DBCommonUtil.CheckIsInBlackList(accountInfo.Id, session))
                        {
                            response.Message = "您的账号存在异常,请联系客服处理。";
                            response.Error   = ErrorCode.ERR_PhoneCodeError;
                            reply(response);
                            return;
                        }

                        // 更新Token
                        accountInfo.Token = CommonUtil.getToken(message.Phone);
                        await proxyComponent.Save(accountInfo);

                        // 随机分配一个Gate
                        StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                        IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                        Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                        // 向gate请求一个key,客户端可以拿着这个key连接gate
                        G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                        {
                            UserId = accountInfo.Id
                        });

                        string outerAddress = config.GetComponent <OuterConfig>().IPEndPoint2.ToString();

                        response.Address = outerAddress;
                        response.Key     = g2RGetLoginKey.Key;
                        response.Token   = accountInfo.Token;
                        reply(response);
                        // 登录日志
                        await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                    }
                    // 用户不存在,走注册流程
                    else
                    {
                        AccountInfo accountInfo = ComponentFactory.CreateWithId <AccountInfo>(UidUtil.createUID());
                        accountInfo.Phone         = message.Phone;
                        accountInfo.Token         = CommonUtil.getToken(message.Phone);
                        accountInfo.MachineId     = message.MachineId;
                        accountInfo.ChannelName   = message.ChannelName;
                        accountInfo.ClientVersion = message.ClientVersion;

                        await proxyComponent.Save(accountInfo);

                        // 添加用户信息
                        PlayerBaseInfo playerBaseInfo = await DBCommonUtil.addPlayerBaseInfo(accountInfo.Id, accountInfo.Phone, "", "");

                        // 随机分配一个Gate
                        StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                        IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                        Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                        // 向gate请求一个key,客户端可以拿着这个key连接gate
                        G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                        {
                            UserId = accountInfo.Id
                        });

                        string outerAddress = config.GetComponent <OuterConfig>().IPEndPoint2.ToString();

                        response.Address = outerAddress;
                        response.Key     = g2RGetLoginKey.Key;
                        response.Token   = accountInfo.Token;
                        reply(response);
                        // 登录日志
                        await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                    }
                }
                // 用Token登录
                else if (message.Token.CompareTo("") != 0)
                {
                    if (accountInfos.Count > 0)
                    {
                        AccountInfo accountInfo = accountInfos[0];

                        // 黑名单检测
                        if (await DBCommonUtil.CheckIsInBlackList(accountInfo.Id, session))
                        {
                            response.Message = "您的账号存在异常,请联系客服处理。";
                            response.Error   = ErrorCode.ERR_PhoneCodeError;
                            reply(response);
                            return;
                        }

                        if (accountInfo?.Token?.CompareTo(message.Token) == 0)
                        {
                            // 随机分配一个Gate
                            StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                            IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                            Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                            // 向gate请求一个key,客户端可以拿着这个key连接gate
                            G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                            {
                                UserId = accountInfo.Id
                            });

                            string outerAddress = config.GetComponent <OuterConfig>().IPEndPoint2.ToString();

                            response.Address = outerAddress;
                            response.Key     = g2RGetLoginKey.Key;
                            response.Token   = accountInfo.Token;
                            reply(response);

                            // 登录日志
                            await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                        }
                        else
                        {
                            response.Message = "Token失效,请重新验证登录";
                            response.Error   = ErrorCode.ERR_TokenError;
                            reply(response);
                            return;
                        }
                    }
                    else
                    {
                        response.Message = "用户不存在";
                        response.Error   = ErrorCode.ERR_AccountNoExist;
                        reply(response);
                        return;
                    }
                }
                // 传的数据错误
                else
                {
                    response.Message = "请求参数缺失";
                    response.Error   = ErrorCode.ERR_ParamError;
                    reply(response);
                    return;
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
            session.Dispose();
        }
        protected override async void Run(Session session, C2G_AddressManager message, Action <G2C_AddressManager> reply)
        {
            G2C_AddressManager response = new G2C_AddressManager();

            try
            {
                Log.Debug("地址管理");
                DBProxyComponent dBProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                //读取数据表
                if (message.DoState == 1)
                {
                    var acounts = await dBProxyComponent.Query <UserAdress>("{'_AccountID' : " + message.AccountID + "}");

                    if (acounts.Count == 1)
                    {
                        foreach (UserAdress item in acounts)
                        {
                            response.InfoID     = item._InfoID;
                            response.AdressList = RepeatedFieldAndListChangeTool.ListToRepeatedField(item._AdressList);
                        }
                        response.IsSuccess = true;
                        response.Message   = MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + "拿取数据成功";
                    }
                    else if (acounts.Count == 0)
                    {
                        response.IsSuccess = false;
                        response.Message   = MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + "无数据";
                    }
                    else
                    {
                        response.IsSuccess = false;
                        response.Message   = MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + "地址数据错误";
                    }
                }
                //操作数据表
                else if (message.DoState == 2)
                {
                    Log.Debug("操作数据表");
                    var acounts = await dBProxyComponent.Query <UserAdress>("{'_AccountID' : " + message.AccountID + "}");

                    //修改
                    if (acounts.Count == 1)
                    {
                        foreach (UserAdress item in acounts)
                        {
                            if (message.AddressType == 1)
                            {
                                item._AdressList.Insert(0, message.DetailsAddress);
                                await dBProxyComponent.Save(item);

                                response.IsSuccess = true;
                                response.Message   = MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + "修改地址成功";
                            }
                            if (message.AddressType == 2)
                            {
                                item._AdressList.Remove(message.DetailsAddress);
                                await dBProxyComponent.Save(item);

                                response.IsSuccess = true;
                                response.Message   = MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + "修改地址成功";
                            }
                        }
                    }
                    //保存数据表
                    else if (acounts.Count == 0)
                    {
                        UserAdress adressData = ComponentFactory.Create <UserAdress>();

                        adressData._AccountID  = message.AccountID;
                        adressData._InfoID     = adressData.Id;
                        adressData._AdressList = new List <string>();

                        await dBProxyComponent.Save(adressData);

                        Log.Debug(MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + "添加地址成功");

                        response.IsSuccess = true;
                        response.Message   = MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + "添加地址成功";
                    }
                    else
                    {
                        response.IsSuccess = false;
                        response.Message   = MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + "地址数据错误";
                    }
                }

                reply(response);
            }
            catch (Exception e)
            {
                response.IsSuccess = false;
                response.Message   = MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + "数据库异常";
                ReplyError(response, e, reply);
            }
        }
Exemple #28
0
        protected override async void Run(Session session, C2G_UpdateDealOrder message, Action <G2C_UpdateDealOrder> reply)
        {
            G2C_UpdateDealOrder response  = new G2C_UpdateDealOrder();
            DealOrder           DealOrder = null;

            try
            {
                DBProxyComponent dBProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                var acounts = await dBProxyComponent.Query <DealOrder>("{ '_AccountID': " + message.ByInvAccountID + "}");

                if (acounts.Count <= 0)
                {
                    //修改的时候查询不到说明数据库有问题
                }
                else
                {
                    DealOrder = acounts[0] as DealOrder;

                    if (message.ByInvAccountID != -1)
                    {
                        DealOrder._ByInvAccountID = message.ByInvAccountID;
                    }
                    if (message.ProductID != -1)
                    {
                        DealOrder._ProductID = message.ProductID;
                    }
                    if (message.InvItemList.Count != 0)
                    {
                        DealOrder._InvItemList = RepeatedFieldAndListChangeTool.RepeatedFieldToList(message.InvItemList);
                    }
                    if (message.InvProductPoint != -1)
                    {
                        DealOrder._InvProductPoint = message.InvProductPoint;
                    }
                    if (message.InvProductDiamond != -1)
                    {
                        DealOrder._InvProductDiamond = message.InvProductDiamond;
                    }
                    if (message.ByInvItemList.count != 0)
                    {
                        DealOrder._InvItemList = RepeatedFieldAndListChangeTool.RepeatedFieldToList(message.ByInvItemList);
                    }
                    if (message.ByInvProductPoint != -1)
                    {
                        DealOrder._ByInvProductPoint = message.ByInvProductPoint;
                    }
                    if (message.ByInvProductDiamond != -1)
                    {
                        DealOrder._ByInvProductDiamond = message.ByInvProductDiamond;
                    }
                    if (message.MessageList.count != 0)
                    {
                        DealOrder._InvItemList = RepeatedFieldAndListChangeTool.RepeatedFieldToList(message.MessageList);
                    }
                    if (message.CreateDate != "")
                    {
                        DealOrder._CreateDate = message.CreateDate;
                    }
                    if (message.DealDate != "")
                    {
                        DealOrder._DealDate = message.DealDate;
                    }
                    if (message.InvIP != "")
                    {
                        DealOrder._InvIP = message.InvIP;
                    }
                    if (message.ByInvIP != "")
                    {
                        DealOrder._ByInvIP = message.ByInvIP;
                    }
                    if (message.State != -1)
                    {
                        DealOrder._State = message.State;
                    }
                }

                await dBProxyComponent.Save(DealOrder);

                await dBProxyComponent.SaveLog(DealOrder);

                reply(response);
            }
            catch (Exception e)
            {
                response.IsOk    = false;
                response.Message = "数据库异常";
                ReplyError(response, e, reply);
            }
        }
        public static void Awake(this DBProxyComponent self)
        {
            StartConfig dbStartConfig = StartConfigComponent.Instance.DBConfig;

            self.dbAddress = dbStartConfig.GetComponent <InnerConfig>().IPEndPoint;
        }
Exemple #30
0
        // 扣除玩家好友房钥匙
        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);
            }
        }