Esempio n. 1
0
        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")));
            }));
        }
Esempio n. 2
0
        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")));
        }
Esempio n. 3
0
        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);
            }));
        }
Esempio n. 4
0
        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")));
            });
        }
Esempio n. 5
0
        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"))));
        }