void JoinRoom(int node, int roomId) { Debug.Log("ReceiveJoinRoomPacket"); MatchingResponse response = new MatchingResponse(); response.roomId = -1; response.request = MatchingRequestId.JoinRoom; int memberNum = 0; if (rooms_.ContainsKey(roomId) == true) { RoomContent room = rooms_[roomId]; m_members[node].roomId = roomId; response.result = MatchingResult.MemberIsFull; for (int i = 0; i < maxMemberNum; ++i) { if (room.members[i] == -1) { // 자리가 있음. room.members[i] = node; rooms_[roomId] = room; response.result = MatchingResult.Success; response.roomId = roomId; response.name = room.name; break; } } // 정원 체크. for (int i = 0; i < room.members.Length; ++i) { if (room.members[i] != -1) { ++memberNum; } } } else { Debug.Log("JoinRoom failed."); response.result = MatchingResult.RoomIsGone; response.name = ""; } MatchingResponsePacket packet = new MatchingResponsePacket(response); network_.SendReliable <MatchingResponse>(node, packet); }
void CreateRoom(int node, string name, int level) { Debug.Log("ReceiveCreateRoomRequest"); MatchingResponse response = new MatchingResponse(); response.request = MatchingRequestId.CreateRoom; if (rooms_.Count < maxRoomNum) { RoomContent room = new RoomContent(); room.roomId = roomIndex; room.name = name; room.level = level; // 자기 자신을 맨앞으로 설정. room.members[0] = node; m_members[node].roomId = roomIndex; rooms_.Add(roomIndex, room); ++roomIndex; response.result = MatchingResult.Success; response.roomId = room.roomId; response.name = ""; string str = "Request node:" + node + " Created room id:" + response.roomId; Debug.Log(str); } else { response.result = MatchingResult.RoomIsFull; response.roomId = -1; Debug.Log("Create room failed."); } MatchingResponsePacket packet = new MatchingResponsePacket(response); network_.SendReliable <MatchingResponse>(node, packet); }
//매칭 응답 패킷 받기 //매칭 중, 매칭 잡힘 처리 public void OnReceiveMatchingResponsePacket(PacketId id, byte[] data) { //MatchingPacketId에 대한 처리해주기 MatchingResponsePacket packet = new MatchingResponsePacket(data); MatchingResponseData packetData = packet.GetPacket(); if (packetData.request == MatchingPacketId.MatchingResponse) { if (packetData.result == MatchingResult.Success) { Debug.Log("매칭중~~~~~~~"); //매칭 중인것을 클라이언트에 표시해야 함 ChangeMatchingState(MatchingState.WaitMatchingResult); } else { Debug.Log("매칭 실패"); ChangeMatchingState(MatchingState.Nothing); } } //매칭이 잡힘 else if (packetData.request == MatchingPacketId.MatchingCatch) { myInfo = -1; if (packetData.result == MatchingResult.Success) { myInfo = packetData.myInfo; //내 정보 상대 정보 저장. //수락 여부 버튼 띄우기. SoundManager.instance.PlaySound("Lobby_Matching", 1f); ChangeMatchingState(MatchingState.SelectMatchingResult); } else { Debug.Log("매칭 잡힘 실패"); ChangeMatchingState(MatchingState.Nothing); } } }
// // 패킷 수신 처리. // void OnReceiveMatchingResponse(int node, PacketId id, byte[] data) { MatchingResponsePacket packet = new MatchingResponsePacket(data); MatchingResponse response = packet.GetPacket(); string str = "ReceiveMatchingResponse:" + response.request; Debug.Log(str); switch (response.request) { case MatchingRequestId.CreateRoom: CreateRoomResponse(response.result, response.roomId); break; case MatchingRequestId.JoinRoom: JoinRoomResponse(response.result, response.roomId); break; default: Debug.Log("Unknown request."); break; } }
void JoinRoom(int node, int roomId) { Debug.Log("ReceiveJoinRoomPacket"); MatchingResponse response = new MatchingResponse(); response.roomId = -1; response.request = MatchingRequestId.JoinRoom; int memberNum = 0; if (rooms_.ContainsKey(roomId) == true) { RoomContent room = rooms_[roomId]; m_members[node].roomId = roomId; response.result = MatchingResult.MemberIsFull; for (int i = 0; i < maxMemberNum; ++i) { if (room.members[i] == -1) { // 자리가 있음. room.members[i] = node; rooms_[roomId] = room; response.result = MatchingResult.Success; response.roomId = roomId; response.name = room.name; break; } } // 정원 체크. for (int i = 0; i < room.members.Length; ++i) { if (room.members[i] != -1) { ++memberNum; } } } else { Debug.Log("JoinRoom failed."); response.result = MatchingResult.RoomIsGone; response.name = ""; } MatchingResponsePacket packet = new MatchingResponsePacket(response); network_.SendReliable<MatchingResponse>(node, packet); }
void CreateRoom(int node, string name, int level) { Debug.Log("ReceiveCreateRoomRequest"); MatchingResponse response = new MatchingResponse(); response.request = MatchingRequestId.CreateRoom; if (rooms_.Count < maxRoomNum) { RoomContent room = new RoomContent(); room.roomId = roomIndex; room.name = name; room.level = level; // 자기 자신을 맨앞으로 설정. room.members[0] = node; m_members[node].roomId = roomIndex; rooms_.Add(roomIndex, room); ++roomIndex; response.result = MatchingResult.Success; response.roomId = room.roomId; response.name = ""; string str = "Request node:" + node + " Created room id:" + response.roomId; Debug.Log(str); } else { response.result = MatchingResult.RoomIsFull; response.roomId = -1; Debug.Log("Create room failed."); } MatchingResponsePacket packet = new MatchingResponsePacket(response); network_.SendReliable<MatchingResponse>(node, packet); }
// // 패킷 수신 처리. // void OnReceiveMatchingResponse(int node, PacketId id, byte[] data) { MatchingResponsePacket packet = new MatchingResponsePacket(data); MatchingResponse response = packet.GetPacket(); string str = "ReceiveMatchingResponse:" + response.request; Debug.Log(str); switch (response.request) { case MatchingRequestId.CreateRoom: CreateRoomResponse(response.result, response.roomId); break; case MatchingRequestId.JoinRoom: JoinRoomResponse(response.result, response.roomId) ; break; default: Debug.Log("Unknown request."); break; } }