/// <summary> /// Executes the list commands /// </summary> private static void ExecuteListCommand(Guid client, List <string> commandSegments) { commandSegments.RemoveAt(0); if (commandSegments.Count < 1) { return; } if (commandSegments[0].EqualsIgnoreCase("connections")) { ClientHandler.SendMessage(client, $"list:connections:{ClientHandler.ActiveClients.ToCommaSeparatedString()}"); } if (commandSegments[0].EqualsIgnoreCase("participants")) { ClientHandler.SendMessage(client, $"list:participants:{GameManager.Participants.ToCommaSeparatedString()}"); } if (commandSegments[0].EqualsIgnoreCase("spectators")) { ClientHandler.SendMessage(client, $"list:spectators:{GameManager.Spectators.ToCommaSeparatedString()}"); } }
/// <summary> /// Executes a command /// </summary> public static void Execute(Guid client, string command) { try { if (Debug) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"{ClientHandler.GetById(client).Name} sent {command}"); Console.ForegroundColor = ConsoleColor.Gray; } var segments = command.Split(' ').ToList(); if (segments.Count < 1) { return; } if (segments[0].EqualsIgnoreCase("debug")) { Debug = !Debug; } if (segments[0].EqualsIgnoreCase("setname")) { ClientHandler.SetName(client, segments[1]); } if (segments[0].EqualsIgnoreCase("game")) { ExecuteGameCommand(client, segments); } if (segments[0].EqualsIgnoreCase("list")) { ExecuteListCommand(client, segments); } if (segments[0].EqualsIgnoreCase("id")) { ClientHandler.SendMessage(client, $"id:{client}"); } if (segments[0].EqualsIgnoreCase("action")) { ExecuteActionCommand(segments, client); } var c = ClientHandler.GetById(client); if (segments[0].EqualsIgnoreCase("message")) { var msg = command.Remove(0, 8); ClientHandler.Broadcast($"message:{c.Name}:{msg}", client.ToString()); } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(e); Console.ForegroundColor = ConsoleColor.Gray; } }