示例#1
0
        /// <summary>
        /// 进入匹配
        /// </summary>
        /// <param name="client"></param>
        private void Enter(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                socketMsg.State = MatchCode.Success;

                int userId = userCache.GetClientUserId(client);
                //判断是否已在匹配房间
                if (matchCache.IsMatching(userId))
                {
                    socketMsg.OpCode  = MsgType.Match;
                    socketMsg.SubCode = MatchCode.EnterMatch_Result;
                    socketMsg.State   = MatchCode.Repeat_Match;
                    client.Send(socketMsg);
                    return;
                }
                //进入房间
                MatchRoom room = matchCache.Enter(userId, client);
                //广播信息
                socketMsg.OpCode  = MsgType.Match;
                socketMsg.SubCode = MatchCode.EnterMatch_Broadcast_Result;
                //新进入房间的玩家信息
                var userInfo    = userCache.GetUserInfo(userId);
                socketMsg.value = EntityHelper.Mapping <UserCharacterDto, UserCharacterInfo>(userInfo);
                room.Brocast(socketMsg, client);
                //返回给客户端数据
                MatchRoomDto dto  = MakeRoomDto(room);
                socketMsg.SubCode = MatchCode.EnterMatch_Result;
                socketMsg.value   = dto;

                client.Send(socketMsg);
            });
        }
示例#2
0
        /// <summary>
        /// 获取角色信息
        /// </summary>
        /// <param name="client"></param>
        private void GetInfo(ClientPeer client)
        {
            SingleExecute.Instance.Execute(delegate
            {
                //判断是否非法登录
                //if (!accountCache.IsOnline(client))
                //{
                //    client.Send(OpCode.USER, UserCode.GET_INFO_SRES, -1); //非法登录
                //    return;
                //}
                int accountId = accountCache.GetId(client);

                if (userCache.IsExist(accountId) == false)
                {
                    client.Send(OpCode.USER, UserCode.GET_INFO_SRES, null); //没有角色
                    return;
                }

                //代码执行到这里 代表有角色
                if (userCache.IsOnLine(client) == false) //防止二次调用上线的方法 所以进行二次判断
                {
                    OnLine(client);
                }
                //发送到客户端角色信息
                UserModel model = userCache.GetModelByAccountID(accountId);
                UserDto dto     = new UserDto(model.id, model.name, model.been, model.lv, model.exp, model.winCount, model.loseCount, model.runCount);
                client.Send(OpCode.USER, UserCode.GET_INFO_SRES, dto); //成功
            });
        }
示例#3
0
        private void Login(ClientPeer client, string account, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (accountCache.IsExist(account) == false)
                {
                    //账号不存在
                    //client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, "账号错误");
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -1);
                    return;
                }
                if (accountCache.IsMatch(account, password) == false)
                {
                    //账号密码不匹配
                    //client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, "账号密码不匹配");
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -2);
                    return;
                }
                if (accountCache.IsOnline(account))
                {
                    //账号已经登录
                    //client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, "账号已登录");
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -3);
                    return;
                }

                accountCache.OnLine(account, client);
                //client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, "登录成功");
                client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, 0);
            });
        }
示例#4
0
        /// <summary>
        /// 进入
        /// </summary>
        void Enter(ClientPeer client)
        {
            SingleExecute.Instance.Execute
            (
                delegate()
            {
                if (!userCache.IsOnLine(client))
                {
                    return;
                }
                int userID = userCache.GetIdByClient(client);
                //判断用户是否已经在用户匹配房间
                if (matchCache.IsMatching(userID))
                {
                    client.Send(OpCode.MATCH, MatchCode.ENTER_SRES, -1);     //重复加入
                    return;
                }
                //正常进入
                MatchRoom room = matchCache.Enter(userID, client);
                //广播给所有用户 有玩家进入  //参数,新进入的玩家ID  不用广播
                UserModel model = userCache.GetModelByUserId(userID);
                UserDto userDto = new UserDto(model.id, model.name, model.been, model.lv, model.exp, model.winCount, model.loseCount, model.runCount);
                room.Brocast(OpCode.MATCH, MatchCode.ENTER_BRO, userDto, client);

                //返回给当前client  房间的数据模型
                MatchRoomDto dto = GetMatchRoomDto(room);
                //给MatchRoomDto中的uidUserDtoDic<int ,userDto>  进行赋值
                //那么需要获取UserModel  房间之中有多个用户
                client.Send(OpCode.MATCH, MatchCode.ENTER_SRES, dto);
            }


            );
        }
示例#5
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);    //"创建成功"
     }
         );
 }
示例#6
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);
            });
        }
示例#7
0
 /// <summary>
 /// 不出
 /// </summary>
 /// <param name="client"></param>
 private void Pass(ClientPeer client)
 {
     SingleExecute.Instance.Execute(() =>
     {
         if (UserCache.IsOnline(client) == false)
         {
             socketMsg.State = null;
             return;
         }
         int userId        = UserCache.GetClientUserId(client);
         FightRoom room    = FightCache.GetRoomByUId(userId);
         socketMsg.SubCode = FightCode.Pass_Result;
         //当前玩家是最大的出牌者 不能不出牌
         if (room.RoundModel.BiggestUId == userId)
         {
             socketMsg.State = FightCode.出牌;
             client.Send(socketMsg);
             return;
         }
         else
         {
             socketMsg.State = FightCode.Success;
             client.Send(socketMsg);
             Turn(room);
         }
     });
 }
示例#8
0
        private void Regist(ClientPeer client, string account, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (accountCache.IsExist(account))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -1);
                    Console.WriteLine(string.Format("Error:Account already exist!"));
                    return;
                }
                if (string.IsNullOrEmpty(account))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -2);
                    Console.WriteLine(string.Format("Error:Account is invalid"));
                    return;
                }
                if (string.IsNullOrEmpty(password) || password.Length < 4 || password.Length > 16)
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -3);
                    Console.WriteLine(string.Format("Error:Password is invalid"));
                    return;
                }

                accountCache.Create(account, password);
                client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, 0);
                Console.WriteLine(string.Format("Sign Up Successfully!"));
            });
        }
示例#9
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");
     });
 }
示例#10
0
 /// <summary>
 /// Get User Info
 /// </summary>
 /// <param name="client"></param>
 private void GetInfo(ClientPeer client)
 {
     SingleExecute.Instance.Execute(() =>
     {
         if (!accountCache.IsOnline(client))
         {
             client.Send(OpCode.USER, UserCode.GET_INFO_SRES, null);
             Console.WriteLine("Get User Info---User Online");
             return;
         }
         int accountId = accountCache.GetId(client);
         if ((userCache.isExist(accountId)) == false)
         {
             client.Send(OpCode.USER, UserCode.GET_INFO_SRES, null);
             Console.WriteLine("Get User Info---No User Info");
             return;
         }
         //user online
         if (userCache.IsOnline(client) == false)
         {
             Online(client);
         }
         UserModel model = userCache.GetModelByAccountId(accountId);
         UserDto dto     = new UserDto(model.ID, model.Name, model.Been, model.WinCount, model.LoseCount, model.RunCount, model.LV, model.Exp);
         client.Send(OpCode.USER, UserCode.GET_INFO_SRES, dto);
     });
 }
示例#11
0
        public void enter(ClientPeer client)
        {
            SingleExecute.Instance.Execute(delegate()
            {
                if (!userCache.IsOnline(client))
                {
                    return;
                }
                int userId = userCache.GetId(client);
                if (matchCache.IsMatching(userId))
                {
                    //user is matching,matching=already enter room
                    client.Send(OpCode.MATCH, MatchCode.ENTER_SRES, -1);
                    return;
                }
                MatchRoom room = matchCache.Enter(userId, client);

                //broadcast to all user in room except current client
                UserModel model = userCache.GetModelByAccountId(userId);
                UserDto userDto = new UserDto(model.ID, model.Name, model.Been, model.WinCount, model.LoseCount, model.RunCount, model.LV, model.Exp);

                room.Broadcast(OpCode.MATCH, MatchCode.ENTER_BROADCAST, userDto, client);

                //send user's room data to user's client
                MatchRoomDto dto = makeRoomDto(room);
                client.Send(OpCode.MATCH, MatchCode.ENTER_SRES, dto);
                Console.WriteLine("Player enter room......");
            });
        }
示例#12
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="clientPeer"></param>
        /// <param name="acc"></param>
        /// <param name="pwd"></param>
        public void Login(ClientPeer clientPeer, string acc, string pwd)
        {
            SingleExcute.Instance.Excute(() =>
            {
                if (!accountCache.IsExit(acc))
                {
                    //账号不存在
                    clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.LOGIN_SRES, "账号不存在");
                    return;
                }
                if (accountCache.IsOnline(acc))
                {
                    //账号在线
                    clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.LOGIN_SRES, "账号在线");
                    return;
                }

                if (!accountCache.IsMactch(acc, pwd))
                {
                    //账号密码不匹配
                    clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.LOGIN_SRES, "密码错误");
                    return;
                }

                accountCache.Online(acc, clientPeer);
                clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.LOGIN_SRES, "登录成功");
            });
        }
示例#13
0
        /// <summary>
        /// 注册账号
        /// </summary>
        /// <param name="clientPeer"></param>
        /// <param name="acc"></param>
        /// <param name="pwd"></param>
        private void Register(ClientPeer clientPeer, string acc, string pwd)
        {
            SingleExcute.Instance.Excute(() =>
            {
                if (accountCache.IsExit(acc))//账号是否存在
                {
                    clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.REGISTE_SRES, "账号已经存在");
                    return;
                }


                if (string.IsNullOrEmpty(acc))
                {
                    clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.REGISTE_SRES, "输入的账号不合法");
                    return;
                }

                if (pwd.Length < 4 || pwd.Length > 16)
                {
                    clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.REGISTE_SRES, "密码长度不合法");
                    return;
                }

                accountCache.Create(acc, pwd);
                clientPeer.Send(OpCode.ACCOUNT, AccountSubCode.REGISTE_SRES, "注册成功");
            });
        }
示例#14
0
 /// <summary>
 /// 获取角色信息
 /// </summary>
 /// <param name="client"></param>
 private void GetInfo(ClientPeer client)
 {
     SingleExecute.Instance.Execute(() =>
     {
         if (!accountCache.IsOnline(client))
         {
             //client.Send(OpCode.USER, UserCode.GET_INFO_SRES, null);//非法登录
             Console.WriteLine("获取角色信息---非法登录");
             return;
         }
         int accountId = accountCache.GetId(client);
         if ((userCache.isExist(accountId)) == false)
         {
             client.Send(OpCode.USER, UserCode.GET_INFO_SRES, null);//没有角色无法获取信息
             Console.WriteLine("获取角色信息---没有角色无法获取信息");
             return;
         }
         //上线角色
         if (userCache.IsOnline(client) == false)
         {
             Online(client);
         }
         UserModel model = userCache.GetModelByAccountId(accountId);
         UserDto dto     = new UserDto(model.Id, model.Name, model.Been, model.WinCount, model.LoseCount, model.RunCount, model.Lv, model.Exp);
         client.Send(OpCode.USER, UserCode.GET_INFO_SRES, dto);
     });
 }
示例#15
0
        private void Regist(ClientPeer client, string account, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (accountCache.IsExist(account))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -1);
                    Console.WriteLine(string.Format("错误:帐号已经存在"));
                    return;
                }

                if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -2);
                    Console.WriteLine(string.Format("错误:账号不合法"));
                    return;
                }

                if (string.IsNullOrEmpty(password) || password.Length < 4 || password.Length > 16)
                {
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -3);
                    Console.WriteLine(string.Format("错误:密码不合法"));
                    return;
                }

                accountCache.Create(account, password);
                client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, 0);
                Console.WriteLine(string.Format("注册成功"));
            });
        }
示例#16
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="client"></param>
        /// <param name="account"></param>
        /// <param name="password"></param>
        private void Login(ClientPeer client, string username, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                bool res  = userDAO.GetUserByUsername(client.MySqlConn, username);
                User user = userDAO.VerifyUser(client.MySqlConn, username, password);

                if (!res)
                {
                    client.Send(OpCode.User, UserCode.LOGIN, -1);//-1 账号不存在
                    return;
                }

                if (userCache.IsOnline(username))
                {
                    //表示账号在线
                    client.Send(OpCode.User, UserCode.LOGIN, -2);
                    return;
                }

                if (user == null)
                {
                    //表示账号密码不匹配
                    client.Send(OpCode.User, UserCode.LOGIN, -3);
                    return;
                }

                //登陆成功
                userCache.Online(client, username);
                client.Send(OpCode.User, UserCode.LOGIN, 0);
            });
        }
示例#17
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("错误:帐号不存在"));
                    return;
                }

                if (!accountCache.IsMatch(account, password))
                {
                    //帐号密码不匹配
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -2);
                    Console.WriteLine(string.Format("错误:帐号密码不匹配"));
                    return;
                }

                if (accountCache.IsOnline(account))
                {
                    //帐号在线
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -3);
                    Console.WriteLine(string.Format("错误:帐号在线"));
                    return;
                }

                //登陆成功
                accountCache.Online(client, account);
                client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, 0);
                Console.WriteLine(string.Format("登陆成功"));
            });
        }
示例#18
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!"));
            });
        }
示例#19
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="client"></param>
        /// <param name="account"></param>
        /// <param name="password"></param>
        private void Regist(ClientPeer client, string account, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (accountCache.IsExist(account))
                {
                    //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "账号已存在");
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -1);
                    return; //账号已存在
                }
                if (string.IsNullOrEmpty(account))
                {
                    // client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "账号为空");
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -2);
                    return;//账号为空
                }
                if (string.IsNullOrEmpty(password))
                {
                    //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "密码不合法");
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -3);
                    return;//密码不合法
                }

                accountCache.Creat(account, password);
                //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "注册成功");
                client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, 0);
            });
        }
示例#20
0
        /// <summary>
        /// 角色上线
        /// </summary>
        /// <param name="client"></param>
        private void Online(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                //判断是否在线
                if (!accountCache.IsOnline(client))
                {
                    msg.OpCode  = MsgType.User;
                    msg.SubCode = UserCode.OnlineResult;
                    msg.State   = UserCode.AccountNotOnline;
                    client.Send(msg);
                    return;
                }
                int id = accountCache.GetId(client);
                if (!userCache.IsExist(id))
                {
                    msg.OpCode  = MsgType.User;
                    msg.SubCode = UserCode.OnlineResult;
                    msg.State   = UserCode.UserExist;
                    client.Send(msg);
                }
                UserCharacterInfo userId = userCache.GetUserInfo(id);
                userCache.Online(client, userId.Id);

                //msg.OpCode = (int)MsgType.User;
                //msg.SubCode = (int)UserCode.OnlineResult;
                //client.Send(msg);
            });
        }
示例#21
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="client"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        private void Regist(ClientPeer client, string username, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                bool res = userDAO.GetUserByUsername(client.MySqlConn, username);
                if (res)
                {
                    //表示当前账号存在
                    client.Send(OpCode.User, UserCode.REGIST_SRES, -1);//-1 代表账号已经存在
                    return;
                }

                if (string.IsNullOrEmpty(username))
                {
                    //表示当前账号不合法
                    client.Send(OpCode.User, UserCode.REGIST_SRES, -2);//-2 代表账号不合法
                    return;
                }

                if (string.IsNullOrEmpty(password) || password.Length < 4 || password.Length > 16)
                {
                    //表示密码不合法
                    client.Send(OpCode.User, UserCode.REGIST_SRES, -3);//-3 表示账号密码不合法
                    return;
                }

                //可以注册了
                userDAO.AddUser(client.MySqlConn, username, password);
                client.Send(OpCode.User, UserCode.REGIST_SRES, 0);//0 代表注册成功
            });
        }
示例#22
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="client"></param>
        /// <param name="account"></param>
        /// <param name="password"></param>
        private void regist(ClientPeer client, string account, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (accountCache.IsExist(account))
                {
                    //表示账号已经存在
                    //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "账号已经存在");
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -1);
                    return;
                }

                if (string.IsNullOrEmpty(account))
                {
                    //表示账号输入不合法
                    //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "账号输入不合法");
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -2);
                    return;
                }

                if (string.IsNullOrEmpty(password) || password.Length < 4 || password.Length > 16)
                {
                    //表示密码不合法
                    //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "密码不合法");
                    client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, -3);
                    return;
                }

                //可以注册了
                accountCache.Creat(account, password);
                //client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, "注册成功");
                client.Send(OpCode.ACCOUNT, AccountCode.REGIST_SRES, 0);
            });
        }
示例#23
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("创建角色---创建成功");
     });
 }
示例#24
0
 /// <summary>
 /// 获取角色信息
 /// </summary>
 /// <param name="client"></param>
 private void getInfo(ClientPeer client)
 {
     SingleExecute.Instance.Execute(delegate()
     {
         //判断这个客户端是不是非法登录
         if (!accountCache.IsOnline(client))
         {
             //client.Send(OpCode.USER, UserCode.GET_INFO_SRES, null);//"非法登录"
             return;
         }
         int accountId = accountCache.GetId(client);
         if (userCache.IsExist(accountId) == false)
         {
             client.Send(OpCode.USER, UserCode.GET_INFO_SRES, null);//"没有创建角色不能获取信息"
             return;
         }
         //代码执行到这里 就代表有角色
         //上线角色
         online(client);
         //给客户端发送自己的角色信息
         UserModel model = userCache.GetModelByAccountId(accountId);
         UserDto dto     = new UserDto(model.Id, model.Name, model.Been, model.WinCount, model.LoseCount, model.RunCount, model.Lv, model.Exp);
         client.Send(OpCode.USER, UserCode.GET_INFO_SRES, dto);//"获取成功"
     });
 }
示例#25
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="client"></param>
        /// <param name="account"></param>
        /// <param name="password"></param>
        private void login(ClientPeer client, string account, string password)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (!accountCache.IsExist(account))
                {
                    //表示账号不存在
                    //client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, "账号不存在");
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -1);
                    return;
                }

                if (accountCache.IsOnline(account))
                {
                    //表示账号在线
                    //client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, "账号在线");
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -2);
                    return;
                }

                if (!accountCache.IsMatch(account, password))
                {
                    //表示账号密码不匹配
                    //client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, "账号密码不匹配");
                    client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, -3);
                    return;
                }

                //登陆成功
                accountCache.Online(client, account);
                //client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, "登陆成功");
                client.Send(OpCode.ACCOUNT, AccountCode.LOGIN, 0);
            });
        }
示例#26
0
        /// <summary>
        /// 不出的处理
        /// </summary>
        /// <param name="client"></param>
        private void Pass(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                //玩家在线
                if (user.IsOnLine(client) == false)
                {
                    return;
                }

                int userId     = user.GetIdByClient(client);
                FightRoom room = fight.GetRoom(userId);

                //2中情况

                if (room.roundModel.BiggestUid == userId)
                {
                    //我是最大的  我必须得出
                    client.Send(OpCode.FIGHT, FightCode.PASS_SRES, -1);
                    return;
                }
                else
                {   //可以不出
                    client.Send(OpCode.FIGHT, FightCode.PASS_SRES, 0);
                    Turn(room);
                }
            }
                );
        }
示例#27
0
        /// <summary>
        /// 不出的处理
        /// </summary>
        /// <param name="client"></param>
        private void pass(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                () =>
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                //必须确保在线
                int userId = userCache.GetId(client);
                //if()
                FightRoom room = fightCache.GetRoomByUId(userId);

                //分两种情况
                if (room.roundModel.BiggestUId == userId)
                {
                    //当前玩家是最大出牌者 没管它 他不能不出
                    client.Send(OpCode.FIGHT, FightCode.PASS_SRES, -1);
                    return;
                }
                else
                {
                    //可以不出
                    client.Send(OpCode.FIGHT, FightCode.PASS_SRES, 0);
                    turn(room);
                }
            });
        }
示例#28
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="client"></param>
        /// <param name="info"></param>
        private void Regist(ClientPeer client, UserInfoDto info)
        {
            SingleExecute.Instance.Execute(() =>
            {
                var msg = new SocketMsg
                {
                    OpCode  = MsgType.Account,
                    SubCode = AccountCode.Regist_Check,
                    State   = AccountCode.Success
                };
                if (string.IsNullOrEmpty(info.Account))
                {
                    msg.State = AccountCode.AccountEntryIsIllegal;
                    client.Send(msg);
                    return;
                }

                if (string.IsNullOrEmpty(info.Password) || info.Password.Length < 4 || info.Password.Length > 16)
                {
                    msg.State = AccountCode.ThePasswordIsIllegal;
                    client.Send(msg);
                    return;
                }
                if (accountCache.IsExist(info.Account))
                {
                    msg.State = AccountCode.AccountAlreadyExists;
                    client.Send(msg);
                    return;
                }
                //查询数据库是否存在当前账号
                //var db = DatabaseHelper.GetInstance();
                //var userInfo = db.Queryable<UserInfo>().Where(w => w.Account == info.Account).ToList();
                //if (userInfo.Count > 0)
                //{
                //    msg.value = MsgType.AccountAlreadyExists;
                //    client.Send(msg);
                //    return;
                //}

                //可以注册了 放入缓存
                accountCache.Create(info.Account, info.Password);
                //try
                //{
                //    var user = new UserInfo
                //    {
                //        Account = info.Account,
                //        Password = info.Password
                //    };
                //    db.Insertable(user).ExecuteCommand();
                //}
                //catch (Exception e)
                //{
                //    Console.WriteLine(e.Message);
                //    throw;
                //}

                client.Send(msg);
            });
        }
示例#29
0
        /// <summary>
        /// 出牌的处理
        /// </summary>
        private void Deal(ClientPeer client, DealDto dto)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                //玩家在线
                if (user.IsOnLine(client) == false)
                {
                    return;
                }

                int userId = user.GetIdByClient(client);

                if (userId != dto.userId)      //DTO的ID可以用来做验证。
                {
                    return;
                }
                FightRoom room = fight.GetRoom(userId);
                //玩家出牌
                //掉线  在线
                if (room.LeaveUidList.Contains(userId))
                {
                    //自动出牌
                    Turn(room);
                }
                //玩家在线
                bool canDeal = room.DealCard(dto.length, dto.type, dto.weight, userId, dto.selectCardList);
                if (canDeal == false)
                {
                    //压不住
                    client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, -1);
                    return;
                }
                else
                {
                    //发送给出牌者
                    client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, 0);
                    List <CardDto> remainCardList = room.GetPlayerCard(userId);
                    dto.remainCardList            = remainCardList;
                    //广播
                    Brocast(room, OpCode.FIGHT, FightCode.DEAL_BRO, dto);
                    //检测下 剩余牌  为0 就赢了
                    if (remainCardList.Count == 0)
                    {
                        //游戏结束
                        GameOver(userId, room);
                    }
                    else
                    {
                        //转换玩家
                        Turn(room);
                    }
                }
            }
                );
        }
示例#30
0
        /// <summary>
        /// 出牌的处理
        /// </summary>
        private void deal(ClientPeer client, DealDto dto)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                //必须确保在线
                int userId = userCache.GetId(client);
                if (userId != dto.UserId)
                {
                    return;
                }
                //if()
                FightRoom room = fightCache.GetRoomByUId(userId);

                //玩家出牌  2种
                //玩家已经中途退出 掉线
                if (room.LeaveUIdList.Contains(userId))
                {
                    //直接转换出牌
                    turn(room);
                }
                //玩家还在
                bool canDeal = room.DeadCard(dto.Type, dto.Weight, dto.Length, userId, dto.SelectCardList);
                if (canDeal == false)
                {
                    //玩家出的牌管不上上一个玩家出的牌
                    client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, -1);
                    return;
                }
                else
                {
                    //给自身客户端 发送一个出牌成功的消息
                    client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, 0);
                    //广播 给所有的客户端
                    List <CardDto> remainCardList = room.GetPlayerModel(userId).CardList;
                    dto.RemainCardList            = remainCardList;
                    brocast(room, OpCode.FIGHT, FightCode.DEAL_BRO, dto);
                    //检测一下剩余手牌 如果手牌数为0 那就游戏结束了
                    if (remainCardList.Count == 0)
                    {
                        //游戏结束
                        gameOver(userId, room);
                    }
                    else
                    {
                        //直接转换出牌
                        turn(room);
                    }
                }
            });
        }