Esempio n. 1
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            if (BotDesc.Running)
            {
                if (MessageBox.Show("To apply the modification, bots must be restarted.", "warning", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
            }

            DialogResult = DialogResult.OK;

            BotDesc.Name = (string)FPropTable["Name"];

            BotDesc.BotCommands.Clear();

            if (BotDesc.Name.Length == 0)
            {
                BotDesc.Name = "No Name";
            }

            BotDesc.Silenced = (bool)FPropTable["Silence Mode"];
            BotDesc.Count = (int)FPropTable["Count"];

            try
            {
                IPAddress ip_addr = (IPAddress)FPropTable["HostAddress"];
                BotDesc.Host = new IPEndPoint(ip_addr, (int)FPropTable["HostPort"]);

                LuaInterface.Lua lua = new LuaInterface.Lua();

                lua.DoFile(BotDesc.Script);

                LuaInterface.LuaTable bot_cmds = lua.GetTable("BotCommandList");

                if (bot_cmds != null)
                {
                    foreach (object cmd_name in bot_cmds.Keys)
                    {
                        BotEngine.BotCommand cmd = new BotStudio.BotEngine.BotCommand(BotDesc, (string)cmd_name);

                        BotDesc.BotCommands.Add(cmd);

                        LuaInterface.LuaTable param_table = (LuaInterface.LuaTable)bot_cmds[(string)cmd_name];
                        if (param_table == null)
                        {
                            continue;
                        }

                        foreach (object param in param_table.Values)
                        {
                            cmd.Parameters.Add(new BotEngine.BotCommand.Parameter((string)param, ""));
                        }
                    }
                }
            }
            catch(Exception ip_e)
            {
                MessageBox.Show(ip_e.Message);
                AppContext.WriteLog(ip_e.Message);
                DialogResult = DialogResult.None;
                return;
            }
        }