/// <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)); }); }
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> public void OnDisconnect(ClientPeer client) { if (!userCache.IsOnline(client)) { return; } int userId = userCache.GetClientUserId(client); if (matchCache.IsMatching(userId)) { Leave(client); } }
public void OnDisConnect(ClientPeer client) { if (!userCache.IsOnLine(client)) { return; } int userId = userCache.GetIdByClient(client); if (matchCache.IsMatching(userId)) { Leave(client); } }
public void OnDisconnect(ClientPeer client) { if (!userCache.IsOnline(client)) //玩家不在线 { return; } int userId = userCache.GetId(client); if (matchCache.IsMatching(userId)) //玩家匹配中 { leave(client); } }
public void Chat(ClientPeer client, int type) { SingleExecute.Instance.Execute(() => { if (!user.IsOnLine(client)) { return; } int userId = user.GetId(client); //匹配场景 if (match.IsMatching(userId)) { MatchRoom mr = match.GetRoom(userId); ChatDto dto = new ChatDto(userId, type); mr.Brocast(OpCode.CHAT, ChatCode.CHAT_SRES, dto); } else if (fight.IsFighting(userId)) { //战斗场景 FightRoom mr = fight.GetRoom(userId); ChatDto dto = new ChatDto(userId, type); //fight.(OpCode.CHAT, ChatCode.CHAT_SRES, dto); Brocast(mr, OpCode.CHAT, ChatCode.CHAT_SRES, dto); } }); }
/// <summary> /// 发送消息 /// </summary> /// <param name="client"></param> /// <param name="socketMsg"></param> private void ChatRequest(ClientPeer client, SocketMsg socketMsg) { if (!userCache.IsOnline(client)) { return; } int userId = userCache.GetClientUserId(client); ChatDto chatDto = new ChatDto { UserId = userId, Type = (int)socketMsg.value }; //向当前匹配房间所有玩家广播消息 if (matchCache.IsMatching(userId)) { MatchRoom room = matchCache.GetRoom(userId); socketMsg.OpCode = MsgType.Chat; socketMsg.SubCode = ChatCode.Result; socketMsg.value = chatDto; room.Brocast(socketMsg); } else if (true) { } }
private void ChatRequest(ClientPeer client, int chatType) { //接收到的是类型 //返回什么 ? 所以创建一个数据传输模型DTO //谁发的? //需要一个userId 所以获取userCache if (userCache.IsOnLine(client) == false) { return; } int userId = userCache.GetIdByClient(client); ChatDto chatDto = new ChatDto(userId, chatType); //发给谁? //通过matchCache 获取房间 通过房间告诉其他玩家(挨个告诉 全体广播) if (matchCache.IsMatching(userId)) { MatchRoom mRoom = matchCache.GetRoom(userId); mRoom.Brocast(OpCode.CHAT, ChatCode.SRES, chatDto); } else if (false) { //在战斗房间内 //TODO } }
private void chatRequest(ClientPeer client, int chatType) { //接收到的是 聊天类型 //返回的是什么? if (userCache.IsOnline(client) == false) { return; } int userId = userCache.GetId(client); //谁? 发送者的id userID //发了什么? 聊天的类型 chatType ChatDto dto = new ChatDto(userId, chatType); //给谁? 房间内的每一个玩家 if (matchCache.IsMatching(userId)) { MatchRoom mRoom = matchCache.GetRoom(userId); mRoom.Brocast(OpCode.CHAT, ChatCode.SRES, dto); } else if (false) { //在这里检测战斗房间 //TODO } }
private void chatRequest(ClientPeer client, int chatType) { if (userCache.IsOnline(client) == false) { return; } int userId = userCache.GetId(client); ChatDto chatDto = new ChatDto(userId, chatType); if (matchCache.IsMatching(userId)) { MatchRoom mRoom = matchCache.GetRoom(userId); mRoom.Brocast(OpCode.CHAT, ChatCode.SERS, chatDto); Console.WriteLine("快捷喊话:" + chatDto.ChatType); } else if (fightCache.IsFighting(userId)) { FightRoom fightRoom = fightCache.GetRoomByUId(userId); fightRoom.Brocast(OpCode.CHAT, ChatCode.SERS, chatDto); Console.WriteLine("快捷喊话:" + chatDto.ChatType); } }
private void chatRequest(ClientPeer client, int chatType) { if (userCache.IsOnline(client) == false) { return; } int userId = userCache.GetId(client); //获取发送者的id userId //发送 ChatDto dto = new ChatDto(userId, chatType); //广播给房间内的玩家 if (matchCache.IsMatching(userId)) { MatchRoom mRoom = matchCache.GetRoom(userId); mRoom.Brocast(OpCode.CHAT, ChatCode.SRES, dto); } if (fightCache.IsFighting(userId)) { FightRoom fRoom = fightCache.GetRoomByUId(userId); fRoom.Brocast(OpCode.CHAT, ChatCode.SRES, dto, client); } }