Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pBlueG committed May 30, 2016
1 parent c233ffc commit 0b25f6a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 16 deletions.
12 changes: 11 additions & 1 deletion classes/commandhandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

Class CommandHandler extends Singleton
{
public $m_aCommands = array();
private $m_aCommands = array();
private $m_sTable;

public function __construct()
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions classes/privileges.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
56 changes: 46 additions & 10 deletions pawn/echo.pwn
Original file line number Diff line number Diff line change
@@ -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 <a_samp>

#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) \
Expand All @@ -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
Expand Down Expand Up @@ -78,7 +108,7 @@ public OnFilterScriptInit()
seekPosition += iLen;
fclose(log);
}
SetTimer("ProcessIRCRequests", 2000, true);
SetTimer("ProcessIRCRequests", 1000, true);
g_maxPlayers = GetMaxPlayers();
return 1;
}
Expand All @@ -98,16 +128,15 @@ stock GetPlayerCount()
public ProcessIRCRequests();
public ProcessIRCRequests()
{
new
string[256],
new string[256],
idx = 0,
reason[128],
action[32],
admin[MAX_IRC_NAME],
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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -241,7 +276,7 @@ WriteEcho(string[])
return 1;
}

Playername(playerid)
stock Playername(playerid)
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof pName);
Expand All @@ -266,6 +301,7 @@ IsNumeric(const string[])
return 1;
}

// (c) Y_Less
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
Expand Down
50 changes: 49 additions & 1 deletion plugins/commands.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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]"
Expand All @@ -199,13 +224,36 @@ 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,
"I have been up for ".Misc::SecondsToString($sUptime)
);
}

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!");
}
}

}

}

?>
4 changes: 2 additions & 2 deletions plugins/samp-echo.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author BlueG
* @package mYsTeRy-v2
* @access public
* @version 2.0a
* @version 2.1a
*/

Class SAMPEcho extends Main
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0b25f6a

Please sign in to comment.