private static void GoToMenuOption(int option, GameLogic controller) { if (GameIsOff(controller)) { if (option == 1) { if (controller.GetClients().Count == 0) { Console.WriteLine("\n -> There are no logged players.\n"); } else { Console.WriteLine(); controller.GetClients().ForEach(client => { Console.WriteLine( $"- {client.Username} \tConnected: {client.ConnectionsCount} times"); }); Console.WriteLine(); } } else if (option == 2) { if (controller.GetCurrentPlayers().Count == 0) { Console.WriteLine("\n -> There are no players in current game.\n"); } else { Console.WriteLine(); controller.GetCurrentPlayers().ForEach(player => { if (player.Client.ConnectedSince == null) { return; } Console.WriteLine( $"- {player.Client.Username} \tConnected: {player.Client.ConnectionsCount}times"); }); Console.WriteLine(); } } } else { Console.WriteLine("\n -> Game in process, try again when it has finished.\n"); } }
public void ListAllClients(Connection connection, Request request) { try { Client loggedUser = CurrentClient(request); List <Client> clients = gameLogic.GetClients(); string[] clientsUsernames = clients.Where(client => !client.Equals(loggedUser)).Select(c => c.Username) .ToArray(); connection.SendMessage(BuildResponse(ResponseCode.Ok, clientsUsernames)); } catch (RecordNotFoundException e) { connection.SendMessage(BuildResponse(ResponseCode.NotFound, e.Message)); } catch (ClientNotConnectedException e) { connection.SendMessage(BuildResponse(ResponseCode.Unauthorized, e.Message)); } }