Exemple #1
0
 public void OnDisconnect(ClientPeer client)
 {
     if (accountCache.IsOnline(client))
     {
         accountCache.Offlint(client);
     }
 }
Exemple #2
0
 /// <summary>
 /// 创建角色
 /// </summary>
 /// <param name="client"></param>
 /// <param name="name"></param>
 private void Create(ClientPeer client, string name)
 {
     SingleExecute.Instance.Execute(() =>
     {
         if (!accountCache.IsOnline(client))
         {
             client.Send(OpCode.USER, UserCode.CREATE_SRES, -1);//非法登录
             Console.WriteLine("创建角色---非法登录");
             return;
         }
         int accountId = accountCache.GetId(client);
         if (userCache.isExist(accountId))
         {
             client.Send(OpCode.USER, UserCode.CREATE_SRES, -2);//重复创建
             Console.WriteLine("创建角色---重复创建");
             return;
         }
         if (userCache.isRepeatName(name))
         {
             client.Send(OpCode.USER, UserCode.CREATE_SRES, -3);//已被使用
             Console.WriteLine("创建角色---名字已被使用");
             return;
         }
         userCache.Create(name, accountId);
         client.Send(OpCode.USER, UserCode.CREATE_SRES, -0);//创建成功
         Console.WriteLine("创建角色---创建成功");
     });
 }
Exemple #3
0
        /// <summary>
        /// 创建角色
        /// </summary>
        /// <param name="client">客户端连接对象</param>
        /// <param name="name">用户名</param>
        private void Create(ClientPeer client, string name)
        {
            SingleExecute.Instance.Execute(() =>
            {
                //判断是否在线
                if (!accountCache.IsOnline(client))
                {
                    msg.OpCode  = MsgType.User;
                    msg.SubCode = UserCode.CreateCharacterResult;
                    msg.State   = UserCode.AccountNotOnline;
                    client.Send(msg);
                    return;
                }
                int id = accountCache.GetId(client);
                //判断当前账号是否有角色
                if (userCache.IsExist(id))
                {
                    msg.OpCode  = MsgType.User;
                    msg.SubCode = UserCode.CreateCharacterResult;
                    msg.State   = UserCode.UserExist;
                    client.Send(msg);
                    return;
                }
                //创建角色
                userCache.Create(name, id);

                msg.OpCode  = MsgType.User;
                msg.SubCode = UserCode.CreateCharacterResult;
                msg.State   = UserCode.Success;
                client.Send(msg);
            });
        }
Exemple #4
0
 /// <summary>
 /// 创建角色
 /// </summary>
 /// <param name="client">客户端的连接对象</param>
 /// <param name="name">客户端传过来的名字</param>
 private void create(ClientPeer client, string name)
 {
     SingleExecute.Instance.Execute(
         delegate()
     {
         //判读这个客户    端是不是非法登录
         if (!accountCache.IsOnline(client))
         {
             client.Send(OpCode.USER, UserCode.CREATE_SRES, -1);    //"客户端非法登录"
             return;
         }
         //获取账号id
         int accountId = accountCache.GetId(client);
         //判断一下 这个账号以前有没有角色
         if (userCache.IsExist(accountId))
         {
             client.Send(OpCode.USER, UserCode.CREATE_SRES, -2);    //"已经有角色 不能重复创建"
             return;
         }
         //没有问题 才可以创建
         userCache.Create(name, accountId);
         client.Send(OpCode.USER, UserCode.CREATE_SRES, 0);    //"创建成功"
     }
         );
 }
        /// <summary>
        /// 创建角色
        /// </summary>
        public void Creat(ClientPeer client, string name)
        {
            SingleExecute.Instance.Execute(() => {
                //这个客户端是不是非法登陆
                if (!accountCache.IsOnline(client))
                {
                    //非法登陆
                    user.Set("非法登陆");
                    client.StartSend(OpCode.USER, UserCode.CREAT_SRES, user);
                    Console.WriteLine("非法登陆");
                    return;
                }

                //获取账号id
                int accountId = accountCache.GetID(client);
                //判断有没有角色
                if (userCache.IsExist(accountId))
                {
                    //重复创建
                    user.Set("重复创建");
                    client.StartSend(OpCode.USER, UserCode.CREAT_SRES, user);
                    Console.WriteLine("重复创建");
                    return;
                }
                //创建角色
                userCache.Creat(name, accountId);
                user.Set("创建角色成功");
                client.StartSend(OpCode.USER, UserCode.CREAT_SRES, user);
                Console.WriteLine("创建角色成功");
            });
        }
Exemple #6
0
        /// <summary>
        /// 登录处理
        /// </summary>
        private void login(MyClient client, AccountDto account)
        {
            OperationResponse response =
                new OperationResponse((byte)OpCode.Account, new Dictionary <byte, object>());

            response.Parameters[80] = AccountCode.Login;
            if (!cache.IsMatch(account.Account, account.Password))
            {
                response.DebugMessage = "账号密码不匹配.";
                response.ReturnCode   = -1;
                client.SendOperationResponse(response, new SendParameters());
                return;
            }
            else if (cache.IsOnline(client))
            {
                response.DebugMessage = "玩家在线.";
                response.ReturnCode   = -2;
                client.SendOperationResponse(response, new SendParameters());
                return;
            }
            else
            {
                cache.Online(client, account.Account, account.Password);
                response.DebugMessage = "登陆成功.";
                response.ReturnCode   = 0;
                client.SendOperationResponse(response, new SendParameters());
            }
        }
Exemple #7
0
 /// <summary>
 /// 抢地主
 /// </summary>
 /// <param name="clientPeer">客户端连接对象</param>
 /// <param name="value">请求参数</param>
 private void Grab(ClientPeer clientPeer, bool value)
 {
     SingleExcute.Instance.Excute(() =>
     {
         if (accountCache.IsOnline(clientPeer) == false)
         {
             return;
         }
         int aid = accountCache.GetId(clientPeer);
         int uid = userModelCache.GetUserIdByAid(aid);
         FightRoomModel fightRoom = fightRoomCache.GetFightRoomByUid(uid);
         if (value == true)
         {
             fightRoom.SetLandlord(uid);
             fightRoom.Sort(uid);
             //发送抢地主消息(包括抢地主的角色Id和底牌数据)给每个客户端发消息
             Brocast(fightRoom, OpCode.FIGHT, FightCode.GRAB_LANDLORD_BRO, new GrabDto(uid, fightRoom.TableCardList, fightRoom.GetPlayerModel(uid).CardDtos));
             //通知该玩家出牌
             Brocast(fightRoom, OpCode.FIGHT, FightCode.TURN_DEAL_BRO, uid);
         }
         else
         {
             //发送不抢地主的消息
             int nextUid = fightRoom.GetNext(uid);
             Brocast(fightRoom, OpCode.FIGHT, FightCode.TURN_GRAB_BRO, nextUid);
         }
     });
 }
Exemple #8
0
        private void Login(ClientPeer client, string account, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (!accountCache.IsExist(account))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -1);
                    Console.WriteLine(string.Format("Error:Account doesn't exist!"));
                    return;
                }
                if (!accountCache.IsMatch(account, password))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -2);
                    Console.WriteLine(string.Format("Error:Password dosen't match!"));
                    return;
                }
                if (accountCache.IsOnline(account))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -3);
                    Console.WriteLine(string.Format("Error:Account is online!"));
                    return;
                }

                accountCache.OnLine(client, account);
                client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, 0);
                Console.WriteLine(string.Format("Sign in Successfully!"));
            });
        }
Exemple #9
0
        /// <summary>
        /// 登录处理
        /// </summary>
        /// <param name="acc"></param>
        /// <param name="pwd"></param>
        private void OnLogin(MobaClient client, string acc, string pwd)
        {
            //无效检查
            if (acc == null || pwd == null)
            {
                return;
            }

            if (cache.IsOnline(acc))
            {
                this.Send(client, OpCode.AccountCode, OpAccount.Login, -1, "玩家在线");
                return;
            }
            //验证账号密码是否合法
            bool res = cache.Match(acc, pwd);

            if (res == true)
            {
                cache.OnLine(acc, client);
                this.Send(client, OpCode.AccountCode, OpAccount.Login, 0, "登录成功");
            }
            else
            {
                this.Send(client, OpCode.AccountCode, OpAccount.Login, -2, "账号密码错误");
            }
        }
Exemple #10
0
        /// <summary>
        /// 登录账号,返回一个ErrorCode,用户登录情况的枚举
        /// </summary>
        /// <param name="token"></param>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ErrorCode Login(UserToken token, string account, string password)
        {
            //验证账号密码的合法性
            if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
            {
                return(ErrorCode.AccountPasswordIsNotSafe);
            }
            //验证账号是否注册
            if (!accountCache.HasAccount(account))
            {
                return(ErrorCode.NotHasAccount);
            }

            //验证是否已经登录
            if (accountCache.IsOnline(token))
            {
                return(ErrorCode.HasLogin);
            }
            //验证账号密码是否匹配
            if (!accountCache.Matching(account, password))
            {
                return(ErrorCode.NotMatch);
            }
            //上线
            accountCache.Online(token, account);
            return(ErrorCode.Success);
        }
Exemple #11
0
 private void Create(ClientPeer client, string name)
 {
     SingleExecute.Instance.Execute(() =>
     {
         if (!accountCache.IsOnline(client))
         {
             client.Send(OpCode.USER, UserCode.CREATE_SRES, -1);
             Console.WriteLine("Create User--Illegal Login");
             return;
         }
         int accountId = accountCache.GetId(client);
         if (userCache.isExist(accountId))
         {
             client.Send(OpCode.USER, UserCode.CREATE_SRES, -2);
             Console.WriteLine("Create User--Repeat Create");
             return;
         }
         if (userCache.isRepeatName(name))
         {
             client.Send(OpCode.USER, UserCode.CREATE_SRES, -3);
             Console.WriteLine("Create User--Name Is Exist");
             return;
         }
         userCache.Create(name, accountId);
         client.Send(OpCode.USER, UserCode.CREATE_SRES, 0);
         Console.WriteLine("Create User--Create Successfully");
     });
 }
        /// <summary>
        /// 创建角色
        /// </summary>
        private void createUser(ClientPeer client, string name)
        {
            if (!accountCache.IsOnline(client))
            {
                return;
            }
            int accid = accountCache.GetId(client);

            if (userModelCache.IsExistUserModel(accid))
            {
                return;
            }
            UserModel userModel = userModelCache.CreateUserModel(accid, name);
            UserDto   userDto   = new UserDto(userModel.Id, userModel.Name, userModel.Been, userModel.Win, userModel.Fail, userModel.Escape, userModel.Lv, userModel.Exp);

            client.Send(OpCode.USER, UserSubCode.CREATE_USER_SRES, userDto);
        }
 /// <summary>
 /// 创建角色
 /// </summary>
 /// <param name="client"></param>
 /// <param name="name"></param>
 private void Creat(ClientPeer client, string name)
 {
     SingleExecute.Instance.Execute(delegate
     {
         //判断客户端是否非法登录
         if (!accountCache.IsOnline(client))
         {
             client.Send(OpCode.USER, UserCode.CREAT_SRES, -1); //非法登录
             return;
         }
         //客户端正常登录   获取ACCOUNTID
         int accountId = accountCache.GetId(client);
         //根据id判断是否有角色
         if (userCache.IsExist(accountId))
         {
             client.Send(OpCode.USER, UserCode.CREAT_SRES, -2); //已经有角色 无法重复创建
             return;
         }
         //创建ing
         userCache.Creat(name, accountId);
         client.Send(OpCode.USER, UserCode.CREAT_SRES, 0); //成功
     });
 }
Exemple #14
0
 /// <summary>
 /// 离开房间
 /// </summary>
 /// <param name="clientPeer"></param>
 private void leave(ClientPeer clientPeer)
 {
     SingleExcute.Instance.Excute(() =>
     {
         if (!accountCache.IsOnline(clientPeer))//判断用户是否在线
         {
             return;
         }
         int accid = accountCache.GetId(clientPeer);
         if (!userModelCache.IsExistUserModel(accid))//判断是否存在角色
         {
             return;
         }
         int uid = userModelCache.GetModelByAccid(accid).Id;
         if (!roomCache.IsMatching(uid))//判断当前用户已经在匹配队列
         {
             return;
         }
         RoomModel roomModel = roomCache.GetRoomModelByUid(uid);
         roomCache.LeaveRoom(uid);
         roomModel.Brocast(uid, clientPeer, OpCode.MATCH, MatchCode.LEAVE_ROOM_BRO);//通知房间内玩家有用户离开
     });
 }
Exemple #15
0
 private int Login(UserToken token, string username, string password)
 {
     if (username == null ||
         password == null ||
         username.Equals("") ||
         password.Equals("") ||
         !cacheInstance.HasAccount(username) ||
         cacheInstance.IsOnline(username) ||
         !cacheInstance.Match(username, password))
     {
         return(Protocol.COMMAND_LOGIN_FAIL);
     }
     cacheInstance.Online(token, username);
     return(Protocol.COMMAND_LOGIN_SUCCESS);
 }
Exemple #16
0
 /// <summary>
 /// 登录处理
 /// </summary>
 /// <param name="acc"></param>
 /// <param name="pwd"></param>
 private void onLogin(MobaClient client, string acc, string pwd)
 {
     if (acc == null || pwd == null)
     {
         return;
     }
     //验证在线...
     if (cache.IsOnline(acc))
     {
         this.Send(client, OpCode.AccountCode, OpAccount.Login, -1, "玩家在线");
         return;
     }
     if (cache.Match(acc, pwd))
     {
         cache.Online(acc, client);
         this.Send(client, OpCode.AccountCode, OpAccount.Login, 0, "登录成功");
     }
     else
     {
         this.Send(client, OpCode.AccountCode, OpAccount.Login, -2, "账号或密码错误");
     }
 }