/// <summary> /// 用户开始匹配 /// </summary> /// <param name="client"></param> private void StartMatch(ClientPeer client) { SingleExecute.Instance.Execute(() => { int userId = user.GetId(client); if (match.IsMatching(userId)) { return; } MatchRoom room = match.Enter(userId, client); //构造一个自身信息UserDto ui需要更新什么信息就构造什么信息 UserModel model = user.GetModelById(userId); UserDto userDto = new UserDto(); userDto.Set("", model.id, model.name, model.beens, model.winCount, model.loseCount, model.runCount, model.lv, model.exp); //对房间内其他玩家进行广播 新用户 加入了房间 room.Brocast(OpCode.MATCHROOM, MatchRoomCode.STARTMATCH_BRO, userDto, client); //将匹配到的房间号给玩家 var roomDto = MakeRoomDto(room); client.StartSend(OpCode.MATCHROOM, MatchRoomCode.STARTMATCH_SRES, roomDto); Console.WriteLine(string.Format("玩家 : {0} 匹配到房间 :{1}", userDto.name, room.id)); //int index = -1; //for (int i = 0; i < roomDto.uIdList.Count; i++) //{ // Console.WriteLine(roomDto.uIdList[i]); // if (roomDto.uIdList[i] == userDto.id) // { // index = i + 1; // } //} //Console.WriteLine(string.Format("有{1}个人。第{0}个进来的",index,roomDto.uIdList.Count)); }); }
/// <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); }); }
/// <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); } ); }
/// <summary> /// 进入 /// </summary> /// <param name="client"></param> private void enter(ClientPeer client) { SingleExecute.Instance.Execute(delegate() { if (!userCache.IsOnline(client)) { return; } int userId = userCache.GetId(client); //如果用户已经在匹配房间等待了 那就无视 if (matchCache.IsMatching(userId)) { //client.Send(OpCode.MATCH, MatchCode.ENTER_SRES, -1);//重复加入 return; } //正常进入 MatchRoom room = matchCache.Enter(userId, client); //广播给房间内除了当前客户端的其他用户,有新玩家加入了 参数:新进入的玩家的用户id UserModel model = userCache.GetModelById(userId); UserDto userDto = new UserDto(model.Id, model.Name, model.Been, model.WinCount, model.LoseCount, model.RunCount, model.Lv, model.Exp); room.Brocast(OpCode.MATCH, MatchCode.ENTER_BRO, userDto, client); //返回给当前客户端 给他房间的数据模型 MatchRoomDto dto = makeRoomDto(room); client.Send(OpCode.MATCH, MatchCode.ENTER_SRES, dto); Console.WriteLine("有玩家进入匹配房间"); }); }
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......"); }); }
/// <summary> /// 进入 /// </summary> /// <param name="client"></param> private void enter(ClientPeer client) { SingleExecute.Instance.Execute( delegate() { int userId = userCache.GetId(client); //正常进入 MatchRoom room = matchCache.Enter(userId, client); // 返回给当前客户端 给他房间的数据模型 MatchRoomDto dto = makeRoomDto(room); client.Send(OpCode.MATCH, MatchCode.ENTER_SRES, dto); //广播给房间内所有的用户,有玩家进入了 //参数:新进入玩家的用户id UserModel model = userCache.GetModelById(userId); UserDto userDto = new UserDto(model.Id, model.Name, model.Been, model.WinCount, model.LoseCount, model.RunCount, model.Lv, model.Exp); // 返回给当前客户端 给他房间的数据模型 room.Brocast(OpCode.MATCH, MatchCode.ENTER_BRO, userDto, client); Console.WriteLine("有玩家进入匹配房间"); }); }
/// <summary> /// 进入匹配 /// </summary> /// <param name="client"></param> private void Enter(ClientPeer client) { SingleExecute.Instance.Execute(() => { 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; socketMsg.State = MatchCode.Success; room.Brocast(socketMsg); //返回给客户端数据 MatchRoomDto roomDto = new MatchRoomDto { ReadyUIdList = room.ReadyUIdList }; foreach (var uId in room.UIdClientDict.Keys) { var info = userCache.GetUserInfo(uId); UserCharacterDto userCharacter = EntityHelper.Mapping <UserCharacterDto, UserCharacterInfo>(info); roomDto.UIdClientDict.Add(uId, userCharacter); } socketMsg.value = roomDto; client.Send(socketMsg); }); }