diff --git a/classes/commandhandler.class.php b/classes/commandhandler.class.php index 5b3c112..997f337 100644 --- a/classes/commandhandler.class.php +++ b/classes/commandhandler.class.php @@ -13,7 +13,7 @@ Class CommandHandler extends Singleton { - public $m_aCommands = array(); + private $m_aCommands = array(); private $m_sTable; public function __construct() @@ -67,6 +67,16 @@ public function _listCommands($privilege) return $sRet; } + public function _getCommandPermission($key) + { + return $this->m_aCommands[$key]['privilege']; + } + + public function _getCommandDescription($key) + { + return $this->m_aCommands[$key]['description']; + } + private function _getPermission($privilege) { $iPermission = Privileges::LEVEL_NONE; diff --git a/classes/privileges.class.php b/classes/privileges.class.php index 51118e5..5e9efc3 100644 --- a/classes/privileges.class.php +++ b/classes/privileges.class.php @@ -182,8 +182,7 @@ public static function IsBotAdmin($sIdent) { if(in_array($sIdent, self::$m_aAdmins)) return true; - else - return false; + return false; } public static function AddBotAdmin($sIdent) diff --git a/pawn/echo.pwn b/pawn/echo.pwn index a301759..8f7641d 100644 --- a/pawn/echo.pwn +++ b/pawn/echo.pwn @@ -1,11 +1,19 @@ -// (c) 2009, BlueG -// updated 2014 BlueG +/** + * SA-MP IRC echo script + * - reads and parses IRC data + * + * @author BlueG (2009, updated in 2014 and 2016) + * @package mYsTeRy-v2 + * @access public + * @version 2.1a + */ + #include #define COLOR 0xFFFFFF -#define MAX_IRC_NAME 30 //FFSNetwork NICKLEN=30 -#define IRC_ACTION_FILE "commands.txt" +#define MAX_IRC_NAME 31 //IRC.tl -> NICKLEN=31 +#define IRC_ACTION_FILE "irc.txt" #define NULL 0 #define isnull(%1) \ @@ -17,6 +25,28 @@ new g_maxPlayers, public ReadActions(); +new pColor[MAX_PLAYERS]; + +// IRC colors +new aColors[][11] = { + {"white"}, + {"black"}, + {"blue"}, + {"green"}, + {"red"}, + {"brown"}, + {"purple"}, + {"orange"}, + {"yellow"}, + {"lightgreen"}, + {"teal"}, + {"lightcyan"}, + {"lightblue"}, + {"pink"}, + {"grey"}, + {"silver"} +}; + new aWeaponNames[][32] = { {"Unarmed (Fist)"}, // 0 {"Brass Knuckles"}, // 1 @@ -78,7 +108,7 @@ public OnFilterScriptInit() seekPosition += iLen; fclose(log); } - SetTimer("ProcessIRCRequests", 2000, true); + SetTimer("ProcessIRCRequests", 1000, true); g_maxPlayers = GetMaxPlayers(); return 1; } @@ -98,8 +128,7 @@ stock GetPlayerCount() public ProcessIRCRequests(); public ProcessIRCRequests() { - new - string[256], + new string[256], idx = 0, reason[128], action[32], @@ -107,7 +136,7 @@ public ProcessIRCRequests() playerid, pName[MAX_PLAYER_NAME], message[128], - sLen; + sLen; if(fexist(IRC_ACTION_FILE)) { log = fopen(IRC_ACTION_FILE, io_read); fseek(log, seekPosition, seek_start); @@ -150,6 +179,11 @@ public ProcessIRCRequests() } } } + if(pCount > 0) + strdel(szPlayers, strlen(szPlayers)-1, strlen(szPlayers)); + else + format(szPlayers, sizeof szPlayers, "No players online."); + WriteEcho(szPlayers); } if(!strcmp(action, "[pm]", true)) { playerid = ReturnUser(strtok(string, idx)); @@ -192,6 +226,7 @@ public OnPlayerConnect(playerid) new string[256]; format(string, sizeof string, "[b][%d][/b][color=blue] *** %s has joined the server", playerid, Playername(playerid)); WriteEcho(string); + pColor[playerid] = random(sizeof(aColors)); return 1; } @@ -222,7 +257,7 @@ public OnPlayerDeath(playerid, killerid, reason) public OnPlayerText(playerid, text[]) { new string[256]; - format(string, sizeof string, "[color=lightblue][%d] [color=lightblue]%s: [color=black]%s", playerid, Playername(playerid), text); + format(string, sizeof string, "[color=lightblue][%d] [color=%s]%s: [color=black]%s", playerid, aColors[pColor[playerid]], Playername(playerid), text); WriteEcho(string); return 1; } @@ -241,7 +276,7 @@ WriteEcho(string[]) return 1; } -Playername(playerid) +stock Playername(playerid) { new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, sizeof pName); @@ -266,6 +301,7 @@ IsNumeric(const string[]) return 1; } +// (c) Y_Less ReturnUser(text[], playerid = INVALID_PLAYER_ID) { new pos = 0; diff --git a/plugins/commands.plugin.php b/plugins/commands.plugin.php index 0c2c7fc..ec57a0e 100644 --- a/plugins/commands.plugin.php +++ b/plugins/commands.plugin.php @@ -24,12 +24,15 @@ public function __construct() ->_registerCommand('!plugins', $this, 'plugins', Privileges::LEVEL_BOT_ADMIN, 'Displays a list of all active plugin instances.') ->_registerCommand('!ident', $this, 'ident', Privileges::LEVEL_NONE, 'Shows your current ident.') ->_registerCommand('!mem', $this, 'mem', Privileges::LEVEL_NONE, 'Shows the bots current memory usage.') - ->_registerCommand('!uptime', $this, 'uptime', Privileges::LEVEL_NONE, 'Shows how long the bot has been up.'); + ->_registerCommand('!uptime', $this, 'uptime', Privileges::LEVEL_NONE, 'Shows how long the bot has been up.') + ->_registerCommand('!help', $this, 'help', Privileges::LEVEL_NONE, 'Commands help.'); echo '>> Commands plugin has been loaded.' . PHP_EOL; } public function cmds($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; if(Privileges::IsBotAdmin($sIdent)) $priv = Privileges::LEVEL_BOT_ADMIN; else @@ -39,6 +42,8 @@ public function cmds($bot, $sUser, $sRecipient, $aParams, $sIdent) public function join($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; if(count($aParams) < 1) $bot->Say($sRecipient, "[b][color=red]Syntax:[/color][/b] !join (#channel) [key]"); else @@ -50,6 +55,8 @@ public function join($bot, $sUser, $sRecipient, $aParams, $sIdent) public function part($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; if(count($aParams) < 1) $bot->Say($sRecipient, "[b][color=red]Syntax:[/color][/b] !part (#channel) [part message]"); else @@ -61,6 +68,8 @@ public function part($bot, $sUser, $sRecipient, $aParams, $sIdent) public function quit($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; if(is_array($aParams)) $bot->Quit(implode(" ", $aParams)); else @@ -69,6 +78,8 @@ public function quit($bot, $sUser, $sRecipient, $aParams, $sIdent) public function boteval($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; if(is_array($aParams)) { $sEval = implode(" ", $aParams); ob_start(); @@ -85,6 +96,8 @@ public function boteval($bot, $sUser, $sRecipient, $aParams, $sIdent) public function addcmd($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; if(count($aParams) < 3) { $bot->Say($sRecipient, "[b][color=red]Syntax:[/color][/b] !addcmd (command) (privilege) (phpcode)"); } else { @@ -107,6 +120,8 @@ public function addcmd($bot, $sUser, $sRecipient, $aParams, $sIdent) public function delcmd($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; if(count($aParams) < 1) { $bot->Say($sRecipient, "[b][color=red]Syntax:[/color][/b] !delcmd (command)"); } else { @@ -119,6 +134,8 @@ public function delcmd($bot, $sUser, $sRecipient, $aParams, $sIdent) public function load($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; if(count($aParams) < 1) { $bot->Say($sRecipient, "[b][color=red]Syntax:[/color][/b] !load (plugin name)"); } else { @@ -151,6 +168,8 @@ public function load($bot, $sUser, $sRecipient, $aParams, $sIdent) public function unload($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; if(count($aParams) < 1) { $bot->Say($sRecipient, "[b][color=red]Syntax:[/color][/b] !unload (plugin name)"); } else { @@ -166,6 +185,8 @@ public function unload($bot, $sUser, $sRecipient, $aParams, $sIdent) public function plugins($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; $sPlugins = NULL; $ptr = Plugins::getInstance(); reset($ptr->m_aPlugins); @@ -183,6 +204,8 @@ public function plugins($bot, $sUser, $sRecipient, $aParams, $sIdent) public function ident($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; $bot->Notice( $sUser, "Your ident is ".$sIdent @@ -191,6 +214,8 @@ public function ident($bot, $sUser, $sRecipient, $aParams, $sIdent) public function mem($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; $bot->Say( $sRecipient, "Current memory usage is [b]".Misc::formatBytes(memory_get_usage(), "MB")."[/b]" @@ -199,6 +224,8 @@ public function mem($bot, $sUser, $sRecipient, $aParams, $sIdent) public function uptime($bot, $sUser, $sRecipient, $aParams, $sIdent) { + if($bot->_isChild()) + return; $sUptime = time() - $bot->m_aPing["Uptime"]; $bot->PM( $sRecipient, @@ -206,6 +233,27 @@ public function uptime($bot, $sUser, $sRecipient, $aParams, $sIdent) ); } + public function help($bot, $sUser, $sRecipient, $aParams, $sIdent) + { + if($bot->_isChild()) + return; + if(count($aParams) < 1) { + $bot->Say($sRecipient, "[b][color=red]Syntax:[/color][/b] !help (command)"); + } else { + $key = NULL; + $key = (object)$key; + if($this->Handler->_commandExists($aParams[0], $key)) { + if(Privileges::GetUserPrivilege($sUser, $sRecipient) >= $this->Handler->_getCommandPermission($key->index) || Privileges::IsBotAdmin($sIdent)) { + $bot->Say($sRecipient, '[b]Command:[/b] '.$aParams[0]); + $bot->Say($sRecipient, '-> '.$this->Handler->_getCommandDescription($key->index)); + } + } else { + $bot->Say($sRecipient, "[b][color=red]Error:[/color][/b] Command: `".$aParams[0]."` does not exist!"); + } + } + + } + } ?> \ No newline at end of file diff --git a/plugins/samp-echo.plugin.php b/plugins/samp-echo.plugin.php index bbc8bba..451927a 100644 --- a/plugins/samp-echo.plugin.php +++ b/plugins/samp-echo.plugin.php @@ -7,7 +7,7 @@ * @author BlueG * @package mYsTeRy-v2 * @access public - * @version 2.0a + * @version 2.1a */ Class SAMPEcho extends Main @@ -136,7 +136,7 @@ public function onCommand($bot, $command, $params, $user, $recipient, $ident) } else { $this->m_pConfig['ticks_echo'] = $params[0]; $bot->Say($recipient, ">> Tickrate has been changed"); - } + } } case '!say': if(count($params) > 0 && $this->m_bEcho) {