private void DisconnectFromRoom(ClientController clientController, RoomUsersContainer roomDisconnect) { if (_roomsContainer.RoomExist(roomDisconnect)) { _roomsContainer.RemoveUserFromRoom(roomDisconnect); foreach (string user in roomDisconnect.GetRoomUsersList()) { Console.WriteLine("User {0} disconnect from room {1}", user, roomDisconnect.GetRoom().Name); } SendCommandToAllClients(clientController, new CommandContainer(CommandType.RoomList, _roomsContainer)); } else { Console.WriteLine("Room {0} does not exists", roomDisconnect.GetRoom().Name); SendCommandToClient(clientController, new CommandContainer(CommandType.RoomDoesNotExists, null)); } }
private void CreateRoom(ClientController clientController, RoomContainer newRoom) { var newRoomUsers = new RoomUsersContainer(newRoom); if (!_roomsContainer.RoomExist(newRoomUsers)) { _roomsContainer.AddRoom(newRoomUsers); _messagesContainer.AddRoomArchive(new RoomArchiveContainer(newRoom)); Console.WriteLine("New room created {0}", newRoomUsers.GetRoom().Name); SendCommandToClient(clientController, new CommandContainer(CommandType.RoomCreated, null)); SendCommandToAllClients(clientController, new CommandContainer(CommandType.RoomList, _roomsContainer)); } else { Console.WriteLine("Room {0} already exists", newRoomUsers.GetRoom().Name); SendCommandToClient(clientController, new CommandContainer(CommandType.RoomAlreadyExists, null)); } }
private void OpenRoomWindow(string roomName) { if (_client.Connected) { if (!IsRoomWindowOpened(roomName)) { RoomFrm roomWindow = new RoomFrm(_client, roomName); _roomWindowsList.Add(roomWindow); roomWindow.FormClosed += new FormClosedEventHandler(roomWindow_FormClosed); roomWindow.StartPosition = FormStartPosition.CenterParent; roomWindow.Show(this); RoomUsersContainer roomUser = new RoomUsersContainer(new RoomContainer(roomName, "")); roomUser.AddUser(_client.UserName); _client.SendCommand(new CommandContainer(CommandType.ConnectToRoom, roomUser)); _client.SendCommand(new CommandContainer(CommandType.RequestRoomArchive, new RoomContainer(roomUser.GetRoom().Name))); } } }