public ConsoleCommandResponse Help() { var response = new ConsoleCommandResponse(); foreach (var o in _commands) { response.AppendMessage(PrettyFormat(o)); } return response; }
public ConsoleCommandResponse Echo(string content) { if(string.IsNullOrEmpty(content)) //Throw an error if we're missing content { throw new CommandArgumentException("Invalid command - missing argument for echo {phrase_to_be_echoed}"); } var response = new ConsoleCommandResponse(); response.AppendMessage(content); _session.SendResponseAsync(response.Serialize()); return response; }
public ConsoleResponder(Action<string> sendAllMethod) { _sendAllMethod = sendAllMethod; _commands = new CommandSet() { new CommandArgument("echo|-e|--echo","Echoes a simple response back from the server. Sample usage:\n\t\t\t" + "$echo \"Hi!\"\n\t\t\t" + "Server: \"Hi!\"", v => _response = Echo(v.FirstOrDefault())), new CommandArgument("help|-h|--help","{help} explains all of the available commands. " + "Can be used at the end of each individual command (--help) for command-specific instructions.", v => _session.SendResponseAsync(Help().Serialize())), new CommandArgument("net|--net","{net} performs some network communication and status operations.", v => {}, //No-op for good ole' net new CommandSet() { new CommandArgument("send", "{net send} sends a message to another client on the network", v => NetSend(v[0],v[1])) }) }; }
public ConsoleCommandResponse NetSend(string target, string content) { var response = new ConsoleCommandResponse(); response.AppendMessage(string.Format("Message from [{0}]", _session.SessionID)); response.AppendMessage(content); if (_sendAllMethod == null) { //Send the result back to just the current user _session.SendResponseAsync(response.Serialize()); } else { _sendAllMethod.Invoke(response.Serialize()); } return response; }
public ConsoleCommandResponse IpConfig() { var response = new ConsoleCommandResponse(); return response; }
void socketServer_NewMessageReceived(WebSocketSession session, string e) { var command = JsonConvert.DeserializeObject<ConsoleCommand>(e); try { IConsoleResponder r = new ConsoleResponder(SendToAll); r.ProcessResponse(command, session); } catch(Exception ex) { var response = new ConsoleCommandResponse(); response.AppendMessage("Server Error! :("); response.AppendMessage(ex.Message); session.SendResponseAsync(response.Serialize()); } }