private void Server_CreateRoom(CreateRoomPacket packet, Socket socket) { var room = new Room { Description = packet.Description, Name = packet.Name, RoomPassword = packet.RoomPassword, AdminPassword = packet.AdminPassword }; rooms.Add(room); SendPacket(socket, PacketHelper.Serialize(new UpdateRoomsPacket(rooms))); }
//방 생성 -> Server public void CreateRoom(string roomName, int dungeonId, int dungeonLevel) { Debug.Log("방 생성"); CreateRoomData createRoomData = new CreateRoomData(dungeonId, dungeonLevel, roomName); CreateRoomPacket createRoomPacket = new CreateRoomPacket(createRoomData); createRoomPacket.SetPacketId((int)ClientPacketId.CreateRoom); DataPacket packet = new DataPacket(CreatePacket(createRoomPacket), null); sendMsgs.Enqueue(packet); }
public bool Process(NetIncomingMessage msg) { msg.Position = 0; short opcode = msg.ReadInt16(); switch (opcode) { case JoinRoomPacket.OpCode: { JoinRoomPacket joinPacketInfo = new JoinRoomPacket(msg.ReadString()); GameRoom room = NetworkSessionContainer.NetworkSessions.GameRooms.FirstOrDefault(); //= NetworkSessionContainer.NetworkSessions.GameRooms.Where(x => x.Name == joinPacketInfo.RoomName).FirstOrDefault(); UserSession sendingUser = NetworkSessionContainer.NetworkSessions.UserSessions .Where(x => x.Connection == msg.SenderConnection).FirstOrDefault(); if (room != null) { /*if (room.Join(sendingUser)) // jak user sie nie podłączył, wysyła wiadomość osiągnięto limit graczy * { * Console.WriteLine($"Dołączył do pokoju {sendingUser.ID}"); * //Poinformowanie uzytkownika o tym że pokuj jest pełny * * room.Start(room.Master); //USUNAĆ * }*/ } else { //Poinformowanie uzytkownika o nie odnaleźieniu pokoju } break; } case CreateRoomPacket.OpCode: { CreateRoomPacket createRoomPacke = new CreateRoomPacket(); createRoomPacke.Private = msg.ReadBoolean(); createRoomPacke.Name = msg.ReadString(); Console.WriteLine("próba ytworzenia room"); // if (!NetworkSessionContainer.NetworkSessions.GameRooms.Any(x=>x.Master.Connection==msg.SenderConnection || x.PlayersInRoomCollection.Any(y=>y.Connection== msg.SenderConnection))) { Console.WriteLine($"Stworzono room \nNazwa:{createRoomPacke.Name}\nPrzez:{NetworkSessionContainer.NetworkSessions.UserSessions.Where(x=>x.Connection==msg.SenderConnection).FirstOrDefault().ID}"); } break; } } return(true); }
public ServerPacketId CreateRoom(byte[] data) { Console.WriteLine(tcpPacket.client.RemoteEndPoint.ToString() + " 방 생성"); CreateRoomPacket createRoomPacket = new CreateRoomPacket(data); CreateRoomData createRoomData = createRoomPacket.GetData(); Console.WriteLine("방 타입 : " + (int)createRoomData.mapType + "방 제목 : " + createRoomData.roomName); int index = roomManager.CreateRoom(tcpPacket.client, ((TcpClient)LoginUser [tcpPacket.client]).Id, createRoomData.roomName, (int)createRoomData.mapType); if (index != 0) { Console.WriteLine("방 생성 성공"); } else { Console.WriteLine("방 생성 실패"); } msg[0] = (byte)index; return(ServerPacketId.RoomCreateResult); }
/// <summary> /// Creates a new chat room on the server. /// </summary> /// <param name="newRoom">The new room to create.</param> public void CreateRoom(NewRoom newRoom) { CreateRoomPacket packet = new CreateRoomPacket(newRoom.Name, newRoom.Description, newRoom.RoomPassword, newRoom.AdminPassword); SendPacket(PacketHelper.Serialize(packet)); }
//방 생성 public void CreateRoom(DataPacket packet) { Console.WriteLine(packet.client.RemoteEndPoint.ToString() + "방 생성"); CreateRoomPacket createRoomPacket = new CreateRoomPacket(packet.msg); CreateRoomData createRoomData = createRoomPacket.GetData(); string id = ""; try { id = loginUser[packet.client]; } catch { Console.WriteLine("현재 로그인 되어있지 않은 아이디 입니다."); return; } int characterId = userState[id].characterId; if (characterId == -1) { Console.WriteLine("캐릭터가 선택되지 않았습니다."); return; } Console.WriteLine("Id : " + id); Console.WriteLine("characterId : " + characterId); Console.WriteLine("방 제목 : " + createRoomData.RoomName); int result = roomManager.CreateRoom(packet.client, database.GetHeroData(id, characterId), createRoomData); Console.WriteLine("방 생성 번호 : " + result); RoomNumberData resultData = new RoomNumberData(result); RoomNumberPacket resultPacket = new RoomNumberPacket(resultData); resultPacket.SetPacketId((int)ServerPacketId.CreateRoomNumber); byte[] msg = CreatePacket(resultPacket); packet = new DataPacket(msg, packet.client); lock (sendLock) { sendMsgs.Enqueue(packet); } List <string> clients = new List <string>(loginUser.Values); foreach (string client in clients) { if (userState.ContainsKey(client)) { if (userState[client].state == -1) { packet = new DataPacket(new byte[0], FindSocketWithId(client)); RequestRoomList(packet); } } } }
public void Recive(NetIncomingMessage msg) { msg.Position = 0; short opcode = msg.ReadInt16(); switch (opcode) { case JoinRoomPacket.OpCode: { JoinRoomPacket joinPacketInfo = new JoinRoomPacket(""); string name = msg.ReadString(); GameRoom GameStateWithRooms = NetworkSessionContainer.NetworkSessions.GameRooms.Where(x => x.Room.Name == name).FirstOrDefault(); UserSession sendingUser = NetworkSessionContainer.NetworkSessions.UserSessions .Where(x => x.Connection == msg.SenderConnection).FirstOrDefault(); if (GameStateWithRooms != null) { if (GameStateWithRooms.Room.Join(sendingUser)) // jak user sie nie podłączył, wysyła wiadomość osiągnięto limit graczy { Console.WriteLine($"Dołączył {sendingUser.Name} do pokoju {GameStateWithRooms.Room.Name} "); sendingUser.UserGameState = new GameRoomState(sendingUser, GameStateWithRooms); } } else { //Poinformowanie uzytkownika o nie odnaleźieniu pokoju } if (GameStateWithRooms.Room.RoomMember.Count == 2) { Console.WriteLine($"{GameStateWithRooms.Room.Name} Wystartował "); GameStateWithRooms.Start(); } break; } case CreateRoomPacket.OpCode: { CreateRoomPacket newRoom = new CreateRoomPacket(); msg.ReadAllProperties(newRoom); if (!NetworkSessionContainer.NetworkSessions.GameRooms.Any(x => x.Room.RoomMember.Exists(y => y.Connection == msg.SenderConnection) == true)) { UserSession masterSession = NetworkSessionContainer.NetworkSessions.UserSessions.FirstOrDefault(x => x.Connection == msg.SenderConnection); GameRoom newGameRoom = new GameRoom(masterSession, newRoom.Name, 8); newGameRoom.Room.Master = masterSession; //Wyciek pamięci przed zmianą statusu ostatniego gracza trzeba usunąć element z listy //Dać też heart beat jak sypnie to dowidzenia masterSession.UserGameState = new GameRoomState(masterSession, newGameRoom); NetworkSessionContainer.NetworkSessions.GameRooms.Add(newGameRoom); } break; } } }