public static void RoomJoin(int _fromClient, Packet _packet) { int _roomId = _packet.ReadInt(); bool isJoin = false; if (_roomId == -1) { Server.clients[_fromClient].LeaveRoom(); return; } if (_roomId == 0) { foreach (KeyValuePair <int, Room> item in Server.rooms) { if (item.Value.isPrivate) { continue; } if (item.Value.isStart) { continue; } if (item.Value.curPlayerCount == 0) { continue; } if (item.Value.maxPlayerCount <= item.Value.curPlayerCount) { continue; } isJoin = Server.rooms[item.Key].JoinPlayer(_fromClient); break; } ServerSend.SendRoomJoinStatus(_fromClient, isJoin); return; } if (Server.rooms[_roomId].isPrivate) { bool _isPrivate = _packet.ReadBool(); string _password = _packet.ReadString(); if (_isPrivate == false || _password != Server.rooms[_roomId].password) { isJoin = false; ServerSend.SendRoomJoinStatus(_fromClient, isJoin); return; } } isJoin = Server.rooms[_roomId].JoinPlayer(_fromClient); ServerSend.SendRoomJoinStatus(_fromClient, isJoin); return; }
//3 public static void RoomCreate(int _fromClient, Packet _packet) { int _roomId = Util.GetEmptyRoomId(); bool isJoin = false; string _name = _packet.ReadString(); bool _isPrivate = _packet.ReadBool(); string _password = _packet.ReadString(); if (_roomId == 0) { ServerSend.SendRoomJoinStatus(_fromClient, isJoin); return; } isJoin = Server.rooms[_roomId].JoinPlayer(_fromClient); if (isJoin) { Server.rooms[_roomId].SetRoom(_name, _isPrivate, _password); Console.WriteLine($"(userName: {Server.clients[_fromClient].userName}, clientId: {_fromClient}) create Room. (roomid: {_roomId}, roomName: {_name})."); } ServerSend.SendRoomJoinStatus(_fromClient, isJoin); return; }