public void RegisterTextInterface(ITextInterfaceControl textInterface) { textInterface.AddToken("Create", "^create"); textInterface.AddToken("Close", "^close"); textInterface.AddToken("Lobby", "^lobby"); textInterface.AddToken("Join", "^join"); textInterface.AddToken("Leave", "^leave"); textInterface.AddToken("Player", "^player"); textInterface.AddToken("Add", "^add"); textInterface.AddToken("Remove", "^remove"); textInterface.AddToken("From", "^from"); textInterface.AddToken("To", "^to"); textInterface.AddRule(ParserSequence.Start().Token("Lobby").Token("Create").String("Name").Number("GameId").Number("Host").End(), (c) => Command_CreateLobby(c.Get <int>("Host"), c.Get <int>("GameId"), c.Get <string>("Name"))); textInterface.AddRule(ParserSequence.Start().Token("Lobby").Number("LobbyId").Token("Join").Number("ConnectionId").End(), (c) => Command_JoinLobby(c.Get <int>("ConnectionId"), c.Get <int>("LobbyId"))); textInterface.AddRule(ParserSequence.Start().Token("Lobby").Number("LobbyId").Token("Close").End(), (c) => Command_CloseLobby(c.Get <int>("LobbyId"))); textInterface.AddRule(ParserSequence.Start().Token("Lobby").Number("LobbyId").Token("Leave").End(), (c) => Command_LeaveLobby(c.Get <int>("LobbyId"))); textInterface.AddRule(ParserSequence.Start().Token("Lobby").Token("Player").Token("Remove").Number("PlayerId").End(), (c) => Command_RemovePlayerFromLobby(c.Get <int>("PlayerId"))); textInterface.AddRule(ParserSequence.Start().Token("Lobby").Token("Player").Token("Add").Number("PlayerId").End(), (c) => Command_AddPlayerToLobby(c.Get <int>("PlayerId"))); }
public void RegisterTextInterface(ITextInterfaceControl textInterface) { textInterface.AddToken("Players", "^players"); textInterface.AddToken("Add", "^add"); textInterface.AddToken("Remove", "^remove"); textInterface.AddToken("Rename", "^rename"); textInterface.AddToken("Player", "^player"); /* * textInterface.AddRule(new CommandParserRule( * ParserSequence.Create(), * (c) => * { * }, * "example")); */ textInterface.AddRule(new CommandParserRule( ParserSequence.Start().Token("Player").End(), (c) => { return(PlayersCommand()); })); textInterface.AddRule(new CommandParserRule( ParserSequence.Start().Token("Player").Number("Id").End(), (c) => { return(ConnectionPlayersCommand(c.Get <int>("Id"))); })); textInterface.AddRule(new CommandParserRule( ParserSequence.Start().Token("Player").Token("Add").String("Name").Number("Id").End(), (c) => { return(AddPlayerCommand(c.Get <string>("Name"), c.Get <int>("Id"))); })); textInterface.AddRule(new CommandParserRule( ParserSequence.Start().Token("Player").Token("Remove").Number("Id").End(), (c) => { return(RemovePlayerCommand(c.Get <int>("Id"))); })); textInterface.AddRule(new CommandParserRule( ParserSequence.Start().Token("Player").Token("Rename").Number("Id").String("Name").End(), (c) => { return(RenamePlayerCommand(c.Get <int>("Id"), c.Get <string>("Name"))); })); }
public void RegisterTextInterface(ITextInterfaceControl textInterface) { textInterface.AddToken("State", "^state"); textInterface.AddRule(new CommandParserRule( ParserSequence.Start().Token("State").String("Module").End(), (c) => { string module = c.Get <string>("Module"); string output = "state of module " + module + ": \n"; output += "--------------------------------------\n"; output += Logic.GetDetailedState(module) + "\n"; output += "--------------------------------------\n"; return(output); })); }
public IParserSequence Token(string token) { ParserSequence cur; if (InnerToken == null) { cur = this; } else { cur = new ParserSequence(); Next = cur; cur.Previous = this; } cur.InnerToken = token; return(cur); }
public void RegisterTextInterface(ITextInterfaceControl textInterface) { textInterface.AddToken("Dummies", "^dummies"); textInterface.AddToken("Dummy", "^dummy"); textInterface.AddToken("Create", "^create"); textInterface.AddToken("Remove", "^remove"); textInterface.AddToken("Connect", "^connect"); textInterface.AddToken("Disconnect", "^disconnect"); textInterface.AddRule(ParserSequence.Start().Token("Dummies").End(), (c) => { var msg = "Dummies (" + Data.ClientDic.Count + ")"; if (Data.ClientDic.Count != 0) { msg += "\n "; } msg += String.Join("\n ", Data.ClientDic.Values); return(msg); }); textInterface.AddRule(ParserSequence.Start().Token("Create").Token("Dummy").End(), (c) => { return(CreateDummy(null, true)); }); textInterface.AddRule(ParserSequence.Start().Token("Create").Token("Dummies").Number("Count").End(), (c) => { for (int i = 0; i < c.Get <int>("Count"); i++) { CreateDummy(null, true); } return("Created and connected dummies!"); }); textInterface.AddRule(ParserSequence.Start().Token("Create").Token("Dummy").Boolean("Connect").End(), (c) => { return(CreateDummy(null, c.Get <bool>("Connect"))); }); textInterface.AddRule(ParserSequence.Start().Token("Create").Token("Dummy").String("Name").End(), (c) => { return(CreateDummy(c.Get <string>("Name"), true)); }); textInterface.AddRule(ParserSequence.Start().Token("Create").Token("Dummy").String("Name").Boolean("Connect").End(), (c) => { return(CreateDummy(c.Get <string>("Name"), c.Get <bool>("Connect"))); }); textInterface.AddRule(ParserSequence.Start().Token("Remove").Token("Dummy").String("Name").End(), (c) => { return(RemoveDummy(c.Get <string>("Name"))); }); textInterface.AddRule(ParserSequence.Start().Token("Remove").Token("Dummy").Number("Id").End(), (c) => { return(RemoveDummy(c.Get <int>("Id"))); }); textInterface.AddRule(ParserSequence.Start().Token("Connect").Token("Dummy").Number("Id").End(), (c) => { return(ConnectDummy(c.Get <int>("Id"))); }); textInterface.AddRule(ParserSequence.Start().Token("Connect").Token("Dummy").String("Name").End(), (c) => { return(ConnectDummy(c.Get <string>("Name"))); }); textInterface.AddRule(ParserSequence.Start().Token("Disconnect").Token("Dummy").Number("Id").End(), (c) => { return(DisconnectDummy(c.Get <int>("Id"))); }); textInterface.AddRule(ParserSequence.Start().Token("Disconnect").Token("Dummy").String("Name").End(), (c) => { return(DisconnectDummy(c.Get <string>("Name"))); }); }
public void RegisterTextInterface(ITextInterfaceControl textInterface) { textInterface.AddToken("Chats", "^chats"); textInterface.AddToken("Chat", "^chat"); textInterface.AddToken("Create", "^create"); textInterface.AddToken("Remove", "^remove"); textInterface.AddToken("To", "^to"); textInterface.AddToken("From", "^from"); textInterface.AddToken("Add", "^add"); textInterface.AddToken("Remove", "^remove"); textInterface.AddToken("Send", "^send"); textInterface.AddToken("As", "^as"); textInterface.AddToken("Details", "^details"); textInterface.AddToken("History", "^history"); textInterface.AddRule(ParserSequence.Start().Token("Chat").Token("History").String("ChatName").End(), (c) => { var chat = GetChat(c.Get <string>("ChatName")); return(ChatHistory(chat, -1)); }); textInterface.AddRule(ParserSequence.Start().Token("Chat").Token("History").Number("ChatId").End(), (c) => { var chat = GetChat(c.Get <int>("ChatId")); return(ChatHistory(chat, -1)); }); textInterface.AddRule(ParserSequence.Start().Token("Chat").Token("History").String("ChatName").Number("Max").End(), (c) => { var chat = GetChat(c.Get <string>("ChatName")); return(ChatHistory(chat, c.Get <int>("Max"))); }); textInterface.AddRule(ParserSequence.Start().Token("Chat").Token("History").Number("ChatId").Number("Max").End(), (c) => { var chat = GetChat(c.Get <int>("ChatId")); return(ChatHistory(chat, c.Get <int>("Max"))); }); textInterface.AddRule(ParserSequence.Start().Token("Chat").Token("Details").String("ChatName").End(), (c) => { ChatRoom chat = GetChat(c.Get <string>("ChatName")); return(ChatDetails(chat)); }); textInterface.AddRule(ParserSequence.Start().Token("Chat").Token("Details").Number("ChatId").End(), (c) => { ChatRoom chat = GetChat(c.Get <int>("ChatId")); return(ChatDetails(chat)); }); textInterface.AddRule(ParserSequence.Start().Token("Send").String("Message").Token("To").String("ChatName").End(), (c) => { try { ChatRoom chat = GetChat(c.Get <string>("ChatName")); return(SendMessage(chat, c.Get <string>("Message"), null)); } catch (Exception ex) { return(ex.Message); } }); textInterface.AddRule(ParserSequence.Start().Token("Send").String("Message").Token("To").Number("ChatId").End(), (c) => { try { ChatRoom chat = GetChat(c.Get <int>("ChatId")); return(SendMessage(chat, c.Get <string>("Message"), null)); } catch (Exception ex) { return(ex.Message); } }); textInterface.AddRule(ParserSequence.Start().Token("Send").String("Message").Token("To").String("ChatName").Token("As").String("Signature").End(), (c) => { try { ChatRoom chat = GetChat(c.Get <string>("ChatName")); return(SendMessage(chat, c.Get <string>("Message"), c.Get <string>("Signature"))); } catch (Exception ex) { return(ex.Message); } }); textInterface.AddRule(ParserSequence.Start().Token("Send").String("Message").Token("To").Number("ChatId").Token("As").String("Signature").End(), (c) => { try { ChatRoom chat = GetChat(c.Get <int>("ChatId")); return(SendMessage(chat, c.Get <string>("Message"), c.Get <string>("Signature"))); } catch (Exception ex) { return(ex.Message); } }); textInterface.AddRule(ParserSequence.Start().Token("Chats").End(), (c) => { return(Chats()); }); textInterface.AddRule(ParserSequence.Start().Token("Remove").Token("Chat").Number("Id").End(), (c) => { try { return(CloseChat(GetChat(c.Get <int>("Id")))); } catch (Exception ex) { return(ex.Message); } }); textInterface.AddRule(ParserSequence.Start().Token("Remove").Token("Chat").String("ChatName").End(), (c) => { try { return(CloseChat(GetChat(c.Get <string>("ChatName")))); } catch (Exception ex) { return(ex.Message); } }); textInterface.AddRule(ParserSequence.Start().Token("Create").Token("Chat").String("Name").End(), (c) => { return(CreateChat(c.Get <string>("Name"), false)); }); textInterface.AddRule(ParserSequence.Start().Token("Create").Token("Chat").String("Name").Boolean("AutoClose").End(), (c) => { return(CreateChat(c.Get <string>("Name"), c.Get <bool>("AutoClose"))); }); textInterface.AddRule(ParserSequence.Start().Token("Add").Number("ConId").Token("To").Token("Chat").Number("ChatId").End(), (c) => { var chat = GetChat(c.Get <int>("ChatId")); return(AddConnectionToChat(c.Get <int>("ConId"), chat)); }); textInterface.AddRule(ParserSequence.Start().Token("Add").Number("ConId").Token("To").Token("Chat").String("ChatName").End(), (c) => { var chat = GetChat(c.Get <string>("ChatName")); return(AddConnectionToChat(c.Get <int>("ConId"), chat)); }); textInterface.AddRule(ParserSequence.Start().Token("Remove").Number("ConId").Token("From").Token("Chat").Number("ChatId").End(), (c) => RemoveConnectionFromChat(c.Get <int>("ConId"), GetChat(c.Get <int>("ChatId")))); textInterface.AddRule(ParserSequence.Start().Token("Remove").Number("ConId").Token("From").Token("Chat").String("ChatName").End(), (c) => RemoveConnectionFromChat(c.Get <int>("ConId"), GetChat(c.Get <int>("ChatId")))); }
public void AddRule(ParserSequence sequence, CommandDelegate command) { AddRule(new CommandParserRule(sequence, command, null)); }
public TextInterfaceLogic() { AddToken("Start", "^start"); AddToken("Close", "^close"); AddToken("Server", "^server"); AddToken("Modules", "^modules"); AddToken("Connections", "^connections"); AddToken("Kick", "^kick"); AddToken("Help", "^help"); AddToken("Reset", "^reset"); /* * AddRule(new CommandParserRule( * ParserSequence.Create(), * (context) => * { * })); */ AddRule(new CommandParserRule( ParserSequence.Start().Token("Reset").End(), (c) => ResetCommand(Server.Port))); AddRule(new CommandParserRule( ParserSequence.Start().Token("Reset").Number("Port").End(), (c) => ResetCommand(c.Get <int>("Port")))); AddRule(new CommandParserRule( ParserSequence.Start().Token("Start").Token("Server").End(), (c) => StartServer(100))); AddRule(new CommandParserRule( ParserSequence.Start().Token("Start").Token("Server").Number("Port").End(), (c) => StartServer(c.Get <int>("Port")))); AddRule(new CommandParserRule( ParserSequence.Start().Token("Close").Token("Server").End(), (context) => { Server.ShutDown(); return("Server closed!"); })); AddRule(new CommandParserRule( ParserSequence.Start().Token("Connections").End(), (context) => { string result = "Connections (" + Server.ConnectionStorage.Connections.Count + ")"; foreach (var c in Server.ConnectionStorage.Connections) { result += "\n " + c.ToString(); } return(result); })); AddRule(new CommandParserRule( ParserSequence.Start().Token("Kick").Number("Id").End(), (context) => { return(Kick(context.Get <int>("Id"), null)); })); AddRule(new CommandParserRule( ParserSequence.Start().Token("Kick").Number("Id").String("Msg").End(), (context) => { return(Kick(context.Get <int>("Id"), context.Get <string>("Msg"))); })); AddRule(new CommandParserRule( ParserSequence.Start().Token("Help").End(), (context) => { return("valid commands:\n " + String.Join("\n ", _parser.Examples)); })); AddRule(new CommandParserRule( ParserSequence.Start().Token("Modules").Number("Id").End(), (context) => { return(ConnectionModules(context.Get <int>("Id"))); })); AddRule(new CommandParserRule( ParserSequence.Start().Token("Modules").End(), (context) => { return("loaded modules:\n " + String.Join("\n ", Server.Framework.Modules.Select(m => m.Name))); })); }
public void AddRule(ParserSequence sequence, CommandDelegate command, string example) { AddRule(new CommandParserRule(sequence, command, example)); }
public ParserRule(ParserSequence sequence, T command) : this(sequence, command, null) { Sequence = sequence; Command = command; }
public ParserRule(ParserSequence sequence, T command, string example) { Sequence = sequence; Command = command; Example = example; }
public CommandParserRule(ParserSequence sequence, CommandDelegate command) : base(sequence, command) { }
public CommandParserRule(ParserSequence sequence, CommandDelegate command, string example) : base(sequence, command, example) { }