Exemple #1
0
        //凭证登陆 就是 userId'|'密码
        public static async Task <AccountInfo> VoucherLogin(this UserComponent userComponent, string userIdAndPassword)
        {
            string[] userIdPassword = userIdAndPassword.Split('|');
            if (userIdPassword.Length != 2)
            {
                return(null);
            }
            try
            {
                long queryUserId = long.Parse(userIdPassword[0]);
                List <AccountInfo> accountInfos = await userComponent.dbProxyComponent.Query <AccountInfo>(AccountInfo =>
                                                                                                           AccountInfo.UserId == queryUserId && AccountInfo.Password == userIdPassword[1]);

                if (accountInfos.Count > 0)
                {
                    return(accountInfos[0]);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            return(null);
        }
Exemple #2
0
        //用户登陆
        public static async Task <AccountInfo> LoginOrRegister(this UserComponent userComponent, string dataStr, int loginType)
        {
            AccountInfo accountInfo = null;

            switch (loginType)
            {
            case LoginType.Editor:
            case LoginType.Tourist:
                accountInfo = await userComponent.EditorLogin(dataStr);

                break;

            case LoginType.WeChat:
                accountInfo = await userComponent.WeChatLogin(dataStr);

                break;

            case LoginType.Voucher:    //检验凭证
                accountInfo = await userComponent.VoucherLogin(dataStr);

                break;

            default:
                Log.Error("不存在的登陆方式:" + loginType);
                break;
            }
            //更新最后登录时间
            if (accountInfo != null)
            {
                accountInfo.LastLoginTime = TimeTool.GetCurrenTimeStamp();
                await userComponent.dbProxyComponent.Save(accountInfo);
            }
            return(accountInfo);
        }
Exemple #3
0
        public static User GetUser(this UserComponent userComponent, long userId)
        {
            User user;

            if (!userComponent.mOnlineUserDic.TryGetValue(userId, out user))
            {
                //Log.Error($"玩家{userId}不存在或不在游戏中");
            }
            return(user);
        }
Exemple #4
0
        public static void BroadCast(this UserComponent self, IActorMessage message)
        {
            User[] users = Game.Scene.GetComponent <UserComponent>().GetAll();
            ActorMessageSenderComponent actorMessageSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();

            foreach (var _user in users)
            {
                UnitGateComponent unitGateComponent = _user.GetComponent <UnitGateComponent>();
                actorMessageSenderComponent.GetWithActorId(unitGateComponent.GateSessionActorId).Send(message);
            }
        }
Exemple #5
0
        //玩家下线事件
        public static async void UserOffline(this UserComponent userComponent, long userId)
        {
            if (userComponent.mOnlineUserDic.ContainsKey(userId))
            {
                userComponent.mOnlineUserDic[userId].IsOnLine = false;
                userComponent.mOnlineUserDic[userId].RemoveComponent <UserGateActorIdComponent>();
                await userComponent.dbProxyComponent.Save(userComponent.mOnlineUserDic[userId]);

                userComponent.mOnlineUserDic.Remove(userId);
            }
        }
Exemple #6
0
        //编辑状态下登陆
        public static async Task <AccountInfo> EditorLogin(this UserComponent userComponent, string account)
        {
            List <AccountInfo> accountInfos = await userComponent.dbProxyComponent.Query <AccountInfo>(AccountInfo => AccountInfo.Account == account);

            if (accountInfos.Count == 0)
            {
                AccountInfo accountInfo = await UserFactory.EditRegisterCreatUser(account);

                accountInfos.Add(accountInfo);
            }
            return(accountInfos[0]);
        }
Exemple #7
0
        public static async Task StopSealOperate(this UserComponent userComponent, StopSealRecord stopSealRecord, IResponse iResponse)
        {
            List <AccountInfo> accountInfos = await userComponent.dbProxyComponent.Query <AccountInfo>(coount => coount.UserId == stopSealRecord.StopSealUserId);

            if (accountInfos.Count > 0)
            {
                accountInfos[0].IsStopSeal = stopSealRecord.IsStopSeal;
                await userComponent.dbProxyComponent.Save(accountInfos[0]);
            }
            else
            {
                iResponse.Message = "用户不存在";
            }
            stopSealRecord.Time = TimeTool.GetCurrenTimeStamp();
            await userComponent.dbProxyComponent.Save(stopSealRecord);
        }
Exemple #8
0
        //根据userId查询User
        public static async Task <User> Query(this UserComponent userComponent, long userId)
        {
            User userInId = userComponent.GetUser(userId);

            if (userInId != null)
            {
                return(userInId);
            }
            List <User> userList = await userComponent.dbProxyComponent.Query <User>(user => user.UserId == userId);

            if (userList.Count > 0)
            {
                return(userList[0]);
            }
            return(null);
        }
        protected override async void Run(Session session, M2U_GetAIUser message, Action <U2M_GetAIUser> reply)
        {
            U2M_GetAIUser response = new U2M_GetAIUser();

            try
            {
                UserComponent userComponent = Game.Scene.GetComponent <UserComponent>();
                response.users = await userComponent.dbProxyComponent.SortQuery <User>(user => true, user => user.Beans == 1, 100);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemple #10
0
        //玩家上线事件
        public static async Task <User> UserOnLine(this UserComponent userComponent, long userId, long sessionActorId)
        {
            User user = userComponent.GetUser(userId);

            if (user != null)
            {
                user.ByCompelAccount();
                user.GetComponent <UserGateActorIdComponent>().ActorId = sessionActorId;
                return(user);//如果User本就在线 发送强制下线消息 就改变一下actorid
            }
            user = await userComponent.Query(userId);

            if (user != null)
            {
                user.AddComponent <UserGateActorIdComponent>().ActorId = sessionActorId;
                userComponent.mOnlineUserDic[user.UserId] = user;
                user.IsOnLine = true;
            }
            return(user);
        }
Exemple #11
0
        //微信登陆
        public static async Task <AccountInfo> WeChatLogin(this UserComponent userComponent, string accessTokenAndOpenid)
        {
            WeChatJsonData weChatJsonData = WeChatJsonAnalysis.HttpGetUserInfoJson(accessTokenAndOpenid);

            if (weChatJsonData == null)
            {
                return(null);
            }
            List <AccountInfo> accountInfos = await userComponent.dbProxyComponent.Query <AccountInfo>(AccountInfo => AccountInfo.Account == weChatJsonData.unionid);

            if (accountInfos.Count == 0)
            {
                AccountInfo accountInfo = await UserFactory.WeChatRegisterCreatUser(weChatJsonData);

                accountInfos.Add(accountInfo);
            }
            accountInfos[0].Password = TimeTool.GetCurrenTimeStamp().ToString();
            await userComponent.dbProxyComponent.Save(accountInfos[0]);

            return(accountInfos[0]);
        }
Exemple #12
0
        protected override void Run(Session session, H2G_GamerCharge message, Action <G2H_GamerCharge> reply)
        {
            G2H_GamerCharge response = new G2H_GamerCharge();

            Log.Info("http传给gate的充值");

            try
            {
                UserComponent userComponent = Game.Scene.GetComponent <UserComponent>();
                User          user          = userComponent.Get(message.UId);

                user?.session?.Call(new Actor_GamerBuyYuanBao()
                {
                    goodsId = message.goodsId
                });
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemple #13
0
        public static async Task <User> SaveUserDB(this UserComponent userComponent, User user)
        {
            await userComponent.dbProxyComponent.Save(user);

            return(user);
        }