Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $Mod_New = new m_commands;
- class m_commands
- {
- public $Index;
- public $Channels = array('#katie', '#katie.test');
- // Variable to store the MySQL connection in.
- public $MySQL;
- public $Server = 'localhost';
- public $User = 'fuckyou';
- public $Password = 'fuckyou';
- // SA-MP ban file.
- public $BanFile = 'samp.ban';
- function Loaded ()
- {
- //$this->SQLConnect();
- }
- function In ($rawstring)
- {
- global $Bot;
- $Head = $Bot[$this->Index];
- if ($this->Index != 'Parent') return;
- // Get the event.
- $Event = strtoupper($Head->In->Parts[1]);
- switch ($Event)
- {
- case 'PRIVMSG':
- // Parts of the message.
- $params = explode(' ', $Head->In->PostColon);
- // Clean it up.
- foreach ($params as $key => $prt) {
- $params[$key] = trim($prt);
- }
- // Check that the channel the command is being used in is one of our channels.
- foreach ($this->Channels as $Chan => $Channel) {
- if (strtolower($Head->In->Channel) == strtolower($Channel))
- {
- // User is halfop or higher.
- if ($Head->IsHalfop($Head->In->Nickname, $Head->In->Channel))
- {
- switch ($params[0])
- {
- case '!test2':
- $censored = array(
- 'fuck' => 'f**ck',
- 'sobeit' => 'i use cheats',
- '/ofc' => 'bad word'
- };
- continue;
- case '!sampbanip':
- // Make sure the user has specified an IP to ban.
- if ($params[1] && !$params[2])
- {
- $ip = $params[1];
- $banlist = file_get_contents($this->BanFile);
- $banlist .= "".$ip." [".date("d/m/y")." | ".date("H:i:s")."] - banned by ".$Head->In->Nickname."\r\n";
- file_put_contents($this->BanFile,$banlist);
- $Head->Out->PrivMsg( $Head->In->Channel, "(sa-mp) IP:4 ".$ip."1 banned");
- // Reload bans file.
- $Bot['Parent']->Module['m_echoserv']->RconCommand('reloadbans');
- }
- // Check if the user has been extra generous and given us a reason too.
- elseif ($params[1] && $params[2])
- {
- $ip = $params[1];
- $params = $this->Clear($params,1);
- $reason = trim(implode( " ", $params));
- $banlist = file_get_contents($this->BanFile);
- $banlist .= "".$ip." [".date("d/m/y")." | ".date("H:i:s")."] - banned by ".$Head->In->Nickname." - ".$reason."\r\n";
- file_put_contents($this->BanFile,$banlist);
- $Head->Out->PrivMsg( $Head->In->Channel, "(sa-mp) IP:4 ".$ip."1 banned");
- $Bot['Parent']->Module['m_echoserv']->RconCommand('reloadbans');
- }
- // Check if they didnt give us anything at all.
- else
- {
- $Head->Out->PrivMsg( $Head->In->Channel, "4Error:1 The correct syntax is !banip <ip> <reason> (Optional)");
- }
- continue;
- case '!sampunbanip':
- $banfile = file_get_contents($this->BanFile);
- $banlist = explode("\n", $banfile);
- if (!strlen($params[1]))
- {
- $this->SendMessage($Head->In->Channel, "4Usage: !sampunbanip <ip-address>");
- return 1;
- }
- $foundip = false;
- for($i = (count($banlist) - 1); $i >= 0; $i--) {
- $pos = strpos($banlist[$i], $params[1]);
- if ($pos !== false) {
- unset($banlist[$i]);
- $foundip = true;
- break;
- }
- }
- if ($foundip == true) {
- $banFileAsString = implode("\n", $banlist);
- file_put_contents($this->BanFile,$banFileAsString);
- $Bot['Parent']->Module['m_echoserv']->RconCommand('reloadbans');
- $this->SendMessage($Head->In->Channel, "(sa-mp) IP:3 ".$params[1]."1 unbanned.");
- }
- else
- {
- $this->SendMessage($Head->In->Channel, "(sa-mp) The IP 3".$params[1]." was not found.");
- }
- continue;
- case '!isbanned':
- $this->CheckSQL();
- $ip = $params[1];
- if (!strlen($ip)) {
- $this->SendMessage($Head->In->Channel, "4Usage: !isbanned <ipaddress>");
- return 1;
- }
- if (!$this->IsBanned($ip)) {
- $this->SendMessage($Head->In->Channel, "IP3 ".$ip." is not banned.");
- return 1;
- }
- $Query = sprintf("SELECT * FROM `bans` WHERE `ip` = '%s' ORDER BY `bandate` DESC LIMIT 1", $ip);
- $Result = mysql_query($Query);
- while ($row = mysql_fetch_array($Result, MYSQL_ASSOC))
- {
- $message = sprintf("IP4 %s is banned: [%s] - %s - By admin %s for %s", $ip, $row['bandate'], $row['name'], $row['banner'], $row['reason']);
- $this->SendMessage($Head->In->Channel, $message);
- }
- continue;
- case '!banip':
- $this->CheckSQL();
- $ip = $params[1];
- if (!strlen($ip)) {
- $this->SendMessage($Head->In->Channel, "4Usage: !banip <ip> <reason (Optional)>");
- return 1;
- }
- $params = $this->Clear($params,1);
- $reason = trim(implode( " ", $params));
- $tot = $this->GetTotalBans() + 1;
- if (!strlen($reason)) {
- $Query = sprintf("INSERT INTO `bans` (`banid`, `ip`, `name`, `banner`, `reason`, `bandate`)
- values (%d, '%s', 'IRC Ban', '%s', 'No reason given', NOW())", $tot, $ip, $Head->In->Nickname);
- } else {
- $Query = sprintf("INSERT INTO `bans` (`banid`, `ip`, `name`, `banner`, `reason`, `bandate`)
- values (%d, '%s', 'IRC Ban', '%s', '^%s', NOW())", $tot, $ip, $Head->In->Nickname, $reason);
- }
- if (!mysql_query($Query)) {
- $this->SendMessage($Head->In->Channel, "4Error: Unable to ban IP.");
- return false;
- }
- $this->SendMessage($Head->In->Channel, "4Banned: ".$ip);
- continue;
- case '!unbanip':
- $this->CheckSQL();
- $ip = $params[1];
- if (!strlen($ip))
- {
- $this->SendMessage($Head->In->Channel, "4Usage: !unbanip <ip>");
- return 1;
- }
- if (!$this->UnbanIP($ip)) {
- $this->SendMessage($Head->In->Channel, "4Error: Unable to unban IP.");
- return false;
- }
- $this->SendMessage($Head->In->Channel, "4Unbanned: ".$ip);
- continue;
- case '!lastban':
- $this->CheckSQL();
- if ($this->GetTotalBans() == 0) return $this->SendMessage($Head->In->Channel, "4No bans found.");
- $Result = mysql_query("SELECT * FROM `bans` ORDER BY `banid` DESC LIMIT 1");
- while ($row = mysql_fetch_array($Result, MYSQL_ASSOC))
- {
- $this->SendMessage($Head->In->Channel, "4Last banned IP: [".$row['bandate']."] ".$row['name']." (IP:".$row['ip'].") - banned by Admin ".$row['banner']." for ".$row['reason']);
- }
- continue;
- case '!lastbans':
- $this->CheckSQL();
- if ($this->GetTotalBans() == 0) return $this->SendMessage($Head->In->Channel, "4No bans found.");
- $Result = mysql_query("SELECT * FROM `bans` ORDER BY `banid` DESC LIMIT 5");
- $this->SendMessage($Head->In->Channel, "4Last 5 banned IP addresses:");
- while ($row = mysql_fetch_array($Result, MYSQL_ASSOC))
- {
- $this->SendMessage($Head->In->Channel, "[".$row['bandate']."] ".$row['name']." (IP:".$row['ip'].") - banned by Admin ".$row['banner']." for ".$row['reason']);
- }
- continue;
- case '!unbanlast':
- $this->CheckSQL();
- if ($this->GetTotalBans() == 0) return $this->SendMessage($Head->In->Channel, "4No bans found.");
- $Result = mysql_query("SELECT * FROM `bans` ORDER BY `banid` DESC LIMIT 1");
- while ($row = mysql_fetch_array($Result, MYSQL_ASSOC))
- {
- $this->SendMessage($Head->In->Channel, "4Unbanned: [".$row['bandate']."] ".$row['name']." (IP:".$row['ip'].") - banned by Admin ".$row['banner']." for ".$row['reason']);
- $this->UnbanIP($row['ip']);
- }
- continue;
- case '!lastip':
- $this->CheckSQL();
- if (!strlen($params[1]))
- {
- $this->SendMessage($Head->In->Channel, "4Usage: !lastip <playername>");
- return 1;
- }
- $Query = sprintf("SELECT * FROM `playerjoins` WHERE `player` = '%s'", $params[1]);
- $Result = mysql_query($Query);
- $tot = mysql_num_rows($Result);
- if ($tot == 0)
- {
- return $this->SendMessage($Head->In->Channel, "4Player not found.");
- }
- $Query = sprintf("SELECT * FROM `playerjoins` WHERE `player` = '%s' ORDER BY `date` DESC LIMIT 1", $params[1]);
- $result = mysql_query($Query);
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
- {
- $message = sprintf("4%s last joined with IP: %s (%s)", $row['player'], $row['ip'], $row['date']);
- $this->SendMessage($Head->In->Channel, $message);
- }
- continue;
- case '!bancount':
- $this->CheckSQL();
- $admin = $params[1];
- if (!strlen($admin)) {
- $this->SendMessage($Head->In->Channel, "4Usage: !bancount <admin>");
- return 1;
- }
- $total = $this->GetBanCount($admin);
- $this->SendMessage($Head->In->Channel, "".$admin." has banned a total of ".$total." player(s).");
- continue;
- case '!searchbans':
- $this->CheckSQL();
- $search = $params[1];
- if (!strlen($search)) {
- $this->SendMessage($Head->In->Channel, "4Usage: !searchbans <name/IP>");
- return 1;
- }
- $ip = false;
- $text = false;
- if ($this->validip($search)) {
- $ip = true;
- } else {
- $text = true;
- }
- if ($text == true)
- {
- $Query = sprintf("SELECT * FROM `bans` WHERE `name` = '%s'", $search);
- }
- else
- {
- $Query = sprintf("SELECT * FROM `bans` WHERE `ip` = '%s'", $search);
- }
- $Result = mysql_query($Query);
- $found = mysql_num_rows($Result);
- if ($found == 0) {
- $this->SendMessage($Head->In->Channel, "4No matches found.");
- } else {
- if ($text == true) {
- $Query = sprintf("SELECT * FROM `bans` WHERE `name` = '%s'", $search);
- } else {
- $Query = sprintf("SELECT * FROM `bans` WHERE `ip` = '%s'", $search);
- }
- $Result = mysql_query($Query);
- while ($row = mysql_fetch_array($Result, MYSQL_ASSOC)) {
- $Message = sprintf("4Matching ban: %s (%s) - By Admin %s for %s. 3(%s)", $row['name'], $row['ip'], $row['banner'], $row['reason'], $row['bandate']);
- Distribute($Head->In->Channel, $Message);
- }
- }
- continue;
- case '!why':
- $this->CheckSQL();
- $name = $params[1];
- if (!strlen($params[1]))
- {
- $this->SendMessage($Head->In->Channel, "4Usage: !why <playername>");
- return 1;
- }
- $Query = sprintf("SELECT * FROM `logs` WHERE `player` = '%s'", $name);
- $Result = mysql_query($Query);
- $tot = mysql_num_rows($Result);
- if ($tot == 0)
- {
- $this->SendMessage($Head->In->Channel, "4Player not found.");
- return 1;
- }
- $Query = sprintf("SELECT * FROM `logs` WHERE `player` = '%s' ORDER BY `date` DESC", $name);
- $Result = mysql_query($Query);
- $this->SendMessage($Head->In->Channel, "4*** Player log of ".$name." (".$tot." record(s))");
- while ($row = mysql_fetch_array($Result, MYSQL_ASSOC))
- {
- $message = sprintf("4[%s] 3(%s by %s): %s", $row['date'], $row['type'], $row['admin'], $row['reason']);
- $this->SendMessage($Head->In->Channel, $message);
- }
- continue;
- case '!addnote':
- $this->CheckSQL();
- $player = $params[1];
- $params = $this->Clear($params,1);
- $reason = trim(implode( " ", $params));
- if (!strlen($player) || !strlen($reason)) {
- $this->SendMessage($Head->In->Channel, "4Usage: !addnote <playername> <reason>");
- return 1;
- }
- $Query = sprintf("INSERT INTO `logs` (`logid`, `player`, `admin`, `reason`, `type`, `date`)
- values (NULL, '%s', '%s', '%s', 'Note', NOW())", $player, $Head->In->Nickname, $reason);
- if (!mysql_query($Query)) {
- $this->SendMessage($Head->In->Channel, "There was an error with the database.");
- return 1;
- }
- $this->SendMessage($Head->In->Channel, "4Note successfully added.");
- continue;
- }
- }
- if ($Head->IsOp($Head->In->Nickname, $Head->In->Channel))
- {
- }
- if ($Head->IsAdmin($Head->In->Nickname, $Head->In->Channel))
- {
- switch ($params[0])
- {
- case '!dc':
- if (!$this->CheckSQL()) {
- $this->SendMessage($Head->In->Channel, "4Error: Cannot disconnect from server. (Not connected)");
- return 1;
- }
- mysql_close($this->MySQL);
- $this->SendMessage($Head->In->Channel, "10*** MySQL connection closed.");
- continue;
- case '!reconnect':
- if ($this->CheckSQL()) {
- $this->SendMessage($Head->In->Channel, "4Error: MySQL connection active, no reconnection needed");
- return 1;
- }
- $this->SendMessage($Head->In->Channel, "10*** Attempting reconnection to MySQL server..");
- if (!$this->SQLConnect()) {
- $this->SendMessage($Head->In->Channel, "10*** Connection to MySQL server failed: ".mysql_error($this->MySQL));
- return 1;
- }
- $this->SendMessage($Head->In->Channel, "10*** Connection to MySQL server successful.");
- continue;
- case '!checksql':
- if (!$this->CheckSQL()) {
- return $this->SendMessage($Head->In->Channel, "10*** No MySQL connection active.");
- }
- $this->SendMessage($Head->In->Channel, "10*** MySQL connection is active.");
- continue;
- }
- }
- }
- }
- }
- }
- // Send message to specified channel.
- function SendMessage ($channel, $message)
- {
- global $Bot;
- $string = sprintf("PRIVMSG %s %s", $channel, $message);
- $Bot['Parent']->Send($string);
- }
- function Clear( $parts, $number )
- {
- for ($i = 0; $i <= $number; $i++) {
- $parts[$i] = "";
- }
- return $parts;
- }
- function IsRegistered ($player)
- {
- $Query = sprintf("SELECT * FROM `users` WHERE `username` = '%s'", $player);
- $Result = mysql_query($Query);
- if (mysql_num_rows($Result) == 0)
- return false;
- return true;
- }
- function IsBanned ($ip)
- {
- $Query = sprintf("SELECT * FROM `bans` WHERE `ip` = '%s'", $ip);
- $Result = mysql_query($Query);
- if (mysql_num_rows($Result) == 0)
- return false;
- return true;
- }
- function BanIP ($ip, $banner, $reason)
- {
- $nextid = GetTotalBans() + 1;
- $Query = sprintf("INSERT INTO `bans` (`banid`, `ip`, `name`, `banner`, `reason`, `bandate`)
- values (%d, '%s', 'IRC Ban', '%s', '%s', NOW())", $nextid, $ip, $banner, $reason);
- if (!mysql_query($Query))
- return false;
- return true;
- }
- function UnbanIP ($ip)
- {
- if (!$this->IsBanned($ip)) return false;
- $Query = sprintf("DELETE FROM `bans` WHERE `ip` = '%s'", $ip);
- if (!mysql_query($Query))
- return false;
- return true;
- }
- function GetTotalBans ()
- {
- $Result = mysql_query('SELECT * FROM `bans`');
- $Tot = mysql_num_rows($Result);
- return $Tot;
- }
- function GetBanCount ($admin)
- {
- $Query = sprintf("SELECT * FROM `logs` WHERE `admin` = '%s' AND `type` = 'ban'", $admin);
- $Result = mysql_query($Query);
- return mysql_num_rows($Result);
- }
- function validip($ip)
- {
- if (!empty($ip) && ip2long($ip)!=-1) {
- $reserved_ips = array (
- array('0.0.0.0','2.255.255.255'),
- array('10.0.0.0','10.255.255.255'),
- array('127.0.0.0','127.255.255.255'),
- array('169.254.0.0','169.254.255.255'),
- array('172.16.0.0','172.31.255.255'),
- array('192.0.2.0','192.0.2.255'),
- array('192.168.0.0','192.168.255.255'),
- array('255.255.255.0','255.255.255.255')
- );
- foreach ($reserved_ips as $r) {
- $min = ip2long($r[0]);
- $max = ip2long($r[1]);
- if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
- }
- return true;
- } else {
- return false;
- }
- }
- function SQLConnect()
- {
- global $Bot;
- $this->MySQL = mysql_connect($this->Server, $this->User, $this->Password);
- if (!$this->MySQL) {
- $Bot[$this->Index]->Output("Unable to connect to MySQL server. (".$this->User."@".$this->Server.")");
- return false;
- }
- mysql_select_db('PTP', $this->MySQL);
- $Bot[$this->Index]->Output("Connected to MySQL server. (".$this->User."@".$this->Server.")");
- return true;
- }
- function CheckSQL ()
- {
- if (!mysql_ping()) {
- $this->SQLConnect();
- return false;
- }
- return true;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement