diff --git a/BOT.php b/BOT.php index aaca84b..f2447d6 100644 --- a/BOT.php +++ b/BOT.php @@ -20,73 +20,74 @@ 'Visit this page for more information.') : false; //--------------------------------------------------------------------------------------------------------- -/* PHP_EOL shortcuts */ -define('N', PHP_EOL); -define('NN', PHP_EOL.N); + /* PHP_EOL shortcuts */ + define('N', PHP_EOL); + define('NN', PHP_EOL.N); -/* check if the bot was launched from the attached php */ -dirname($_SERVER['PHP_SELF']) == '../..' ? chdir('../../') : false; + /* check if the bot was launched from the attached php */ + dirname($_SERVER['PHP_SELF']) == '../..' ? chdir('../../') : false; -/* simple os check */ -/* PHP 7.2.0 we have PHP_OS_FAMILY */ -strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' ? $GLOBALS['OS'] = 'Linux' : false; + /* simple os check */ + /* PHP 7.2.0 we have PHP_OS_FAMILY */ + strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' ? $GLOBALS['OS'] = 'Linux' : false; -/* hide prompt */ -echo "\e[?25l"; + /* hide prompt */ + echo "\e[?25l"; -/* needed files */ -$botCoreFiles = ['cli.php', - 'misc.php', - 'config.php', - 'core_commands.php', - 'debug.php', - 'define.php', - 'events.php', - 'logo.php', - 'logs.php', - 'plugins.php', - 'socket.php', - 'timers.php', - 'web.php', - 'ctcp.php' - ]; + /* needed files */ + $botCoreFiles = ['cli.php', + 'misc.php', + 'config.php', + 'core_commands.php', + 'debug.php', + 'define.php', + 'events.php', + 'logo.php', + 'logs.php', + 'plugins.php', + 'socket.php', + 'timers.php', + 'web.php', + 'ctcp.php' + ]; -/* check if we got all files */ -foreach ($botCoreFiles as $botCoreFile) { - if (is_file("src/{$botCoreFile}")) { - require_once("src/{$botCoreFile}"); - } else { - echo N; - echo " I need a file '{$botCoreFile}' to work!".NN, - ' You can download missing files from:'.N, - ' https://github.com/S3x0r/MINION/releases'.NN, - ' Terminating program after 10 seconds.'.NN; - !isset($GLOBALS['os']) ? sleep(10) : false; - exit; - } -} + /* check if we got all files */ + foreach ($botCoreFiles as $botCoreFile) { + if (is_file("src/{$botCoreFile}")) { + require_once("src/{$botCoreFile}"); + } else { + echo N; + echo " I need a file '{$botCoreFile}' to work!".NN, + ' You can download missing files from:'.N, + ' https://github.com/S3x0r/MINION/releases'.NN, + ' Terminating program after 10 seconds.'.NN; + !isset($GLOBALS['os']) ? sleep(10) : false; + exit; + } + } -/* if we cannnot write */ -if (!is_writable('BOT.php')) { - echo "\n Bot has no permissions to save files, Check your permissions! Exiting."; - WinSleep(7); - exit; -} else { - !is_dir(LOGSDIR) ? mkdir(LOGSDIR) : false; - !is_dir(DATADIR) ? mkdir(DATADIR) : false; -} + /* if we cannnot write */ + if (!is_writable('BOT.php')) { + echo "\n Bot has no permissions to save files, Check your permissions! Exiting."; + WinSleep(7); + exit; + } else { + !is_dir(LOGSDIR) ? mkdir(LOGSDIR) : false; + !is_dir(DATADIR) ? mkdir(DATADIR) : false; + } //--------------------------------------------------------------------------------------------------------- - /* Check if we got cli args */ - CheckCliArgs(); + + /* Check if we got cli args */ + CheckCliArgs(); - /* Load config */ - LoadConfig(); + /* Load config */ + LoadConfig(); - /* Logging init */ - LogsInit(); + /* Logging init */ + LogsInit(); - /* Load plugins */ - LoadPlugins(); + /* Load plugins */ + LoadPlugins(); - /* Time to connect */ - Connect(); + /* Time to connect */ + Connect(); diff --git a/CONFIG.INI b/CONFIG.INI index 8cbe6a3..90b3d82 100644 --- a/CONFIG.INI +++ b/CONFIG.INI @@ -96,7 +96,7 @@ command_prefix = '!' ctcp_response = 'yes' ; ctcp version response (please do not change it:) -ctcp_version = 'MINION (1.1.3) powered by minions!' +ctcp_version = 'MINION (1.1.4) powered by minions!' ; ctcf finger response ctcp_finger = 'MINION' diff --git a/DOCS/CHANGELOG.TXT b/DOCS/CHANGELOG.TXT index c42cabb..2bc69ca 100644 --- a/DOCS/CHANGELOG.TXT +++ b/DOCS/CHANGELOG.TXT @@ -1,3 +1,8 @@ + + v1.1.4 changes (26.12.2020): + - Plugin: restart - now escapes from parent process + - Plugin: server - now escapes from parent process + - fixed repeated messages on join event v1.1.3 changes (21.12.2020): - registration to bot bug fixed diff --git a/PLUGINS/OWNER/restart.php b/PLUGINS/OWNER/restart.php index 9583cdc..9277604 100644 --- a/PLUGINS/OWNER/restart.php +++ b/PLUGINS/OWNER/restart.php @@ -24,10 +24,6 @@ $plugin_description = "Restarts Bot: {$GLOBALS['CONFIG_CMD_PREFIX']}restart"; $plugin_command = 'restart'; -/* TODO: - - escape from parent process -*/ - function plugin_restart() { /* give op before restart */ @@ -41,8 +37,12 @@ function plugin_restart() /* send cli messages */ cliLog('Restarting BOT...'); - /* execute batch script */ - !isset($GLOBALS['OS']) ? system('START_BOT.BAT') : system('php -f BOT.php'); + if (!isset($GLOBALS['OS'])) { + chdir('src/php'); + runProgram('start php.exe ../../BOT.php'); + } else { + runProgram('php -f BOT.php'); + } exit; } diff --git a/PLUGINS/OWNER/server.php b/PLUGINS/OWNER/server.php index 13fbfd9..d5758d1 100644 --- a/PLUGINS/OWNER/server.php +++ b/PLUGINS/OWNER/server.php @@ -34,7 +34,15 @@ function plugin_server() toServer("QUIT :Changing server..."); - !isset($GLOBALS['OS']) ? system('cd src & cd php & php.exe ../../BOT.php -o '.$GLOBALS['piece1'].' '.$GLOBALS['piece2']) : system('php BOT.php -o '.$GLOBALS['piece1'].' '.$GLOBALS['piece2']); + if (!isset($GLOBALS['OS'])) { + chdir('src/php'); + runProgram('start php.exe ../../BOT.php -o '.$GLOBALS['piece1'].' '.$GLOBALS['piece2']); + exit; + } else { + runProgram('php BOT.php -o '.$GLOBALS['piece1'].' '.$GLOBALS['piece2']); + exit; + } + } elseif (empty($GLOBALS['args'])) { response('You need to specify server address.'); } elseif (empty($GLOBALS['piece2'])) { diff --git a/src/define.php b/src/define.php index 4a9345f..e1681c9 100644 --- a/src/define.php +++ b/src/define.php @@ -19,7 +19,7 @@ exit('This script can\'t be run from a web browser. Use CLI terminal to run it
'. 'Visit this page for more information.') : false; //--------------------------------------------------------------------------------------------------------- - define('VER', '1.1.3'); + define('VER', '1.1.4'); //--------------------------------------------------------------------------------------------------------- define('START_TIME', time()); define('PHP_VER', phpversion()); diff --git a/src/events.php b/src/events.php index ebb3909..1aa602a 100644 --- a/src/events.php +++ b/src/events.php @@ -126,6 +126,19 @@ function on_mode() /* on MODE event */ //--------------------------------------------------------------------------------------------------------- function on_join() { + /* if bot joined */ + if ($GLOBALS['USER'] == getBotNickname()) { + /* 1. set channel from 353 */ + $GLOBALS['BOT_CHANNEL'] = str_replace(':', '', $GLOBALS['rawDataArray'][2]); + + cliLog("[bot] Joined channel: ".getBotChannel()); + + /* 1.check channel modes for cli message */ + toServer("MODE ".getBotChannel()); + + /* FIX: save data for web panel */ + } + /* if user joined channel */ if ($GLOBALS['USER'] != getBotNickname()) { cliLog("[".getBotChannel()."] * {$GLOBALS['USER']} ({$GLOBALS['USER_HOST']}) has joined"); @@ -156,23 +169,11 @@ function on_join() //--------------------------------------------------------------------------------------------------------- function on_353() /* on channel join info */ { - /* when we got confirmation that bot joined channel */ - if (isset($GLOBALS['rawDataArray'][2]) && $GLOBALS['rawDataArray'][2] == getBotNickname()) { - /* 1. set channel from 353 */ - $GLOBALS['BOT_CHANNEL'] = $GLOBALS['rawDataArray'][4]; /* FIX: we can set channel name faster after JOIN event */ - - cliLog("[bot] Joined channel: ".getBotChannel()); - - /* FIX: save data for web panel */ - - /* if bot got op */ - if (isset($GLOBALS['rawDataArray'][5]) && $GLOBALS['rawDataArray'][5] == ':@'.getBotNickname()) { - /* on bot opped event */ - on_bot_opped(); - } - - /* check channel modes */ - toServer("MODE ".getBotChannel()); + $nick = str_replace(':', '', $GLOBALS['rawDataArray'][5]); + + /* if bot opped */ + if ($nick == '@'.getBotNickname()) { + on_bot_opped(); } } //--------------------------------------------------------------------------------------------------------- @@ -393,22 +394,16 @@ function setChannelModesAndBans() } /* set channel modes from config */ - if ($GLOBALS['CONFIG_KEEPCHAN_MODES'] == 'yes') { - toServer('MODE '.getBotChannel()); - - if (BotOpped() == true) { - if (isset($GLOBALS['CHANNEL_MODES']) && $GLOBALS['CHANNEL_MODES'] != $GLOBALS['CONFIG_CHANNEL_MODES']) { - sleep(1); - toServer("MODE ".getBotChannel()." -{$GLOBALS['CHANNEL_MODES']}"); - sleep(1); - toServer("MODE ".getBotChannel()." +{$GLOBALS['CONFIG_CHANNEL_MODES']}"); - } - if (empty($GLOBALS['CHANNEL_MODES'])) { - if (!empty($GLOBALS['CONFIG_CHANNEL_MODES'])) { - sleep(1); - toServer("MODE ".getBotChannel()." +{$GLOBALS['CONFIG_CHANNEL_MODES']}"); - } - } + if ($GLOBALS['CONFIG_KEEPCHAN_MODES'] == 'yes' && BotOpped() == true) { //FIX: keep modes + if (isset($GLOBALS['CHANNEL_MODES']) && $GLOBALS['CHANNEL_MODES'] != $GLOBALS['CONFIG_CHANNEL_MODES']) { + sleep(1); + toServer("MODE ".getBotChannel()." -{$GLOBALS['CHANNEL_MODES']}"); + sleep(1); + toServer("MODE ".getBotChannel()." +{$GLOBALS['CONFIG_CHANNEL_MODES']}"); + } + if (empty($GLOBALS['CHANNEL_MODES']) && !empty($GLOBALS['CONFIG_CHANNEL_MODES'])) { + sleep(1); + toServer("MODE ".getBotChannel()." +{$GLOBALS['CONFIG_CHANNEL_MODES']}"); } } } diff --git a/src/misc.php b/src/misc.php index a410535..35b7413 100644 --- a/src/misc.php +++ b/src/misc.php @@ -304,4 +304,15 @@ function in_array_r($needle, $haystack, $strict = false) { function pluginUsageCli($pluginName) { cliLog("[PLUGIN: {$pluginName}] Used by: {$GLOBALS['USER']} ({$GLOBALS['USER_HOST']}), channel: ".getBotChannel()); -} \ No newline at end of file +} +//--------------------------------------------------------------------------------------------------------- +function runProgram($command) +{ + $descriptorspec = array( + 0 => array("pipe", "r"), + 1 => array("pipe", "w"), + 2 => array("pipe", "w") + ); + + $process = proc_open($command, $descriptorspec, $pipes); +}