Ejemplo n.º 1
0
        /// <summary>
        /// 玩家中退出房间
        /// </summary>
        /// <param name="clientPeer"></param>
        private void Leave(ClientPeer clientPeer)
        {
            int aid = accountCache.GetId(clientPeer);

            if (aid == -1)
            {
                //客户端未登陆
                return;
            }
            int uid = userModelCache.GetUserIdByAid(aid);

            if (uid == -1)
            {
                //该账号下没有角色
                return;
            }

            FightRoomModel room = fightRoomCache.GetFightRoomByUid(uid);

            if (room != null)
            {
                //战斗还未结束,可以获取到房间数据
                room.Leave(uid);
                //如果房间逃跑用户有三个则直接摧毁房间
                if (room.EscapePlayerId.Count == 3)
                {
                    fightRoomCache.DestoryRoom(room);
                }
            }
            else
            {
                //战斗已结束,无法获取到房间数据,无需处理
            }
        }
Ejemplo n.º 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("创建角色---创建成功");
     });
 }
Ejemplo n.º 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);
            });
        }
Ejemplo n.º 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);    //"创建成功"
     }
         );
 }
Ejemplo n.º 5
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");
     });
 }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取角色信息
        /// </summary>
        private void OnGetInfo(MobaClient client)
        {
            int accId = accountCache.GetId(client);

            if (accId == -1)
            {
                Send(client, OpCode.PlayerCode, OpPlayer.GetInfo, -1, "非法登录");
                return;
            }
            if (playerCache.Has(accId))
            {
                Send(client, OpCode.PlayerCode, OpPlayer.GetInfo, 0, "存在角色");
                return;
            }
            else
            {
                Send(client, OpCode.PlayerCode, OpPlayer.GetInfo, -2, "没有角色");
                return;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 上线的处理
        /// </summary>
        /// <param name="client"></param>
        private void onOnline(MobaClient client)
        {
            int accId    = accountCache.GetId(client);
            int playerId = playerCache.GetId(accId);

            //防止重复在线
            //if (playerCache.IsOnline(client))
            //    return;
            //上线
            playerCache.Online(client, playerId);

            #region 每次上线的时候 要通知好友 显示在线状态

            PlayerModel model = playerCache.GetModel(client);
            if (model != null)
            {
                MobaClient tempClient = null;
                string[]   friends    = model.FriendIdList.Split(',');
                foreach (string item in friends)
                {
                    if (string.IsNullOrEmpty(item))
                    {
                        continue;
                    }
                    int id = int.Parse(item);
                    if (!playerCache.IsOnline(id))
                    {
                        continue;
                    }
                    tempClient = playerCache.GetClient(id);
                    Send(tempClient, OpCode.PlayerCode, OpPlayer.FriendOnline, 0, "此玩家上线", model.Id);
                }
            }
            #endregion

            PlayerDto dto = toDto(playerCache.GetModel(playerId));

            //发送
            Send(client, OpCode.PlayerCode, OpPlayer.Online, 0, "上线成功", JsonMapper.ToJson(dto));
        }
Ejemplo n.º 9
0
 /// <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); //成功
     });
 }
Ejemplo n.º 10
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);//通知房间内玩家有用户离开
     });
 }