BadScript 2
Loading...
Searching...
No Matches
BadDefaultNetworkClientCommandParser.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4
6
11
16{
21
25 private readonly List<BadNetworkConsoleClientCommand> m_Commands = new List<BadNetworkConsoleClientCommand>();
26
35
39 public IEnumerable<BadNetworkConsoleClientCommand> Commands => m_Commands;
40
41#region IBadNetworkConsoleClientCommandParser Members
42
44 public void ExecuteCommand(string command)
45 {
46 string[] parts = command.Split(new[] { ' ' },
47 StringSplitOptions.RemoveEmptyEntries
48 );
49
50 if (parts.Length == 0)
51 {
52 return;
53 }
54
55 string name = parts[0];
56
58 {
59 if (cmd.Name == name)
60 {
61 cmd.Invoke(parts.Skip(1)
62 .ToArray()
63 );
64
65 return;
66 }
67 }
68
69 BadConsole.WriteLine("Unknown Command: " + name);
70 }
71
72#endregion
73
78 public void AddCommand(Func<BadNetworkConsoleClient, BadNetworkConsoleClientCommand> command)
79 {
80 m_Commands.Add(command(m_Client));
81 }
82}
Wrapper class for the console abstraction.
Definition BadConsole.cs:12
static void WriteLine(string str)
Writes a string to the console and appends a newline.
Definition BadConsole.cs:78
void AddCommand(Func< BadNetworkConsoleClient, BadNetworkConsoleClientCommand > command)
Adds a Command to the Command List.
void Invoke(string[] args)
Executes the Command with the given arguments.
Contains the Console Client Implementation for the Remote Console Abstraction over TCP.