Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.47 KB | None | 0 0
  1. <?php
  2.  
  3. $Mod_New = new m_commands;
  4.  
  5. class m_commands
  6. {
  7. public $Index;
  8.  
  9. public $Channels = array('#katie', '#katie.test');
  10.  
  11. // Variable to store the MySQL connection in.
  12. public $MySQL;
  13.  
  14. public $Server = 'localhost';
  15. public $User = 'fuckyou';
  16. public $Password = 'fuckyou';
  17.  
  18. // SA-MP ban file.
  19. public $BanFile = 'samp.ban';
  20.  
  21. function Loaded ()
  22. {
  23. //$this->SQLConnect();
  24. }
  25.  
  26. function In ($rawstring)
  27. {
  28. global $Bot;
  29.  
  30. $Head = $Bot[$this->Index];
  31.  
  32. if ($this->Index != 'Parent') return;
  33.  
  34. // Get the event.
  35. $Event = strtoupper($Head->In->Parts[1]);
  36.  
  37. switch ($Event)
  38. {
  39. case 'PRIVMSG':
  40. // Parts of the message.
  41. $params = explode(' ', $Head->In->PostColon);
  42.  
  43. // Clean it up.
  44. foreach ($params as $key => $prt) {
  45. $params[$key] = trim($prt);
  46. }
  47.  
  48. // Check that the channel the command is being used in is one of our channels.
  49. foreach ($this->Channels as $Chan => $Channel) {
  50. if (strtolower($Head->In->Channel) == strtolower($Channel))
  51. {
  52. // User is halfop or higher.
  53. if ($Head->IsHalfop($Head->In->Nickname, $Head->In->Channel))
  54. {
  55. switch ($params[0])
  56. {
  57. case '!test2':
  58.  
  59. $censored = array(
  60. 'fuck' => 'f**ck',
  61. 'sobeit' => 'i use cheats',
  62. '/ofc' => 'bad word'
  63. };
  64.  
  65. continue;
  66.  
  67. case '!sampbanip':
  68. // Make sure the user has specified an IP to ban.
  69. if ($params[1] && !$params[2])
  70. {
  71. $ip = $params[1];
  72. $banlist = file_get_contents($this->BanFile);
  73. $banlist .= "".$ip." [".date("d/m/y")." | ".date("H:i:s")."] - banned by ".$Head->In->Nickname."\r\n";
  74. file_put_contents($this->BanFile,$banlist);
  75. $Head->Out->PrivMsg( $Head->In->Channel, "(sa-mp) IP:4 ".$ip."1 banned");
  76. // Reload bans file.
  77. $Bot['Parent']->Module['m_echoserv']->RconCommand('reloadbans');
  78. }
  79. // Check if the user has been extra generous and given us a reason too.
  80. elseif ($params[1] && $params[2])
  81. {
  82. $ip = $params[1];
  83. $params = $this->Clear($params,1);
  84. $reason = trim(implode( " ", $params));
  85. $banlist = file_get_contents($this->BanFile);
  86. $banlist .= "".$ip." [".date("d/m/y")." | ".date("H:i:s")."] - banned by ".$Head->In->Nickname." - ".$reason."\r\n";
  87. file_put_contents($this->BanFile,$banlist);
  88. $Head->Out->PrivMsg( $Head->In->Channel, "(sa-mp) IP:4 ".$ip."1 banned");
  89. $Bot['Parent']->Module['m_echoserv']->RconCommand('reloadbans');
  90. }
  91. // Check if they didnt give us anything at all.
  92. else
  93. {
  94. $Head->Out->PrivMsg( $Head->In->Channel, "4Error:1 The correct syntax is !banip <ip> <reason> (Optional)");
  95. }
  96.  
  97. continue;
  98.  
  99. case '!sampunbanip':
  100. $banfile = file_get_contents($this->BanFile);
  101. $banlist = explode("\n", $banfile);
  102.  
  103. if (!strlen($params[1]))
  104. {
  105. $this->SendMessage($Head->In->Channel, "4Usage: !sampunbanip <ip-address>");
  106. return 1;
  107. }
  108.  
  109. $foundip = false;
  110.  
  111. for($i = (count($banlist) - 1); $i >= 0; $i--) {
  112. $pos = strpos($banlist[$i], $params[1]);
  113. if ($pos !== false) {
  114. unset($banlist[$i]);
  115. $foundip = true;
  116. break;
  117. }
  118. }
  119.  
  120. if ($foundip == true) {
  121. $banFileAsString = implode("\n", $banlist);
  122. file_put_contents($this->BanFile,$banFileAsString);
  123.  
  124. $Bot['Parent']->Module['m_echoserv']->RconCommand('reloadbans');
  125.  
  126. $this->SendMessage($Head->In->Channel, "(sa-mp) IP:3 ".$params[1]."1 unbanned.");
  127. }
  128. else
  129. {
  130. $this->SendMessage($Head->In->Channel, "(sa-mp) The IP 3".$params[1]." was not found.");
  131. }
  132.  
  133. continue;
  134.  
  135. case '!isbanned':
  136. $this->CheckSQL();
  137.  
  138. $ip = $params[1];
  139.  
  140. if (!strlen($ip)) {
  141. $this->SendMessage($Head->In->Channel, "4Usage: !isbanned <ipaddress>");
  142. return 1;
  143. }
  144.  
  145. if (!$this->IsBanned($ip)) {
  146. $this->SendMessage($Head->In->Channel, "IP3 ".$ip." is not banned.");
  147. return 1;
  148. }
  149.  
  150. $Query = sprintf("SELECT * FROM `bans` WHERE `ip` = '%s' ORDER BY `bandate` DESC LIMIT 1", $ip);
  151.  
  152. $Result = mysql_query($Query);
  153.  
  154. while ($row = mysql_fetch_array($Result, MYSQL_ASSOC))
  155. {
  156. $message = sprintf("IP4 %s is banned: [%s] - %s - By admin %s for %s", $ip, $row['bandate'], $row['name'], $row['banner'], $row['reason']);
  157. $this->SendMessage($Head->In->Channel, $message);
  158. }
  159.  
  160. continue;
  161.  
  162. case '!banip':
  163. $this->CheckSQL();
  164.  
  165. $ip = $params[1];
  166.  
  167. if (!strlen($ip)) {
  168. $this->SendMessage($Head->In->Channel, "4Usage: !banip <ip> <reason (Optional)>");
  169. return 1;
  170. }
  171.  
  172. $params = $this->Clear($params,1);
  173. $reason = trim(implode( " ", $params));
  174.  
  175. $tot = $this->GetTotalBans() + 1;
  176.  
  177. if (!strlen($reason)) {
  178. $Query = sprintf("INSERT INTO `bans` (`banid`, `ip`, `name`, `banner`, `reason`, `bandate`)
  179. values (%d, '%s', 'IRC Ban', '%s', 'No reason given', NOW())", $tot, $ip, $Head->In->Nickname);
  180. } else {
  181. $Query = sprintf("INSERT INTO `bans` (`banid`, `ip`, `name`, `banner`, `reason`, `bandate`)
  182. values (%d, '%s', 'IRC Ban', '%s', '^%s', NOW())", $tot, $ip, $Head->In->Nickname, $reason);
  183. }
  184.  
  185. if (!mysql_query($Query)) {
  186. $this->SendMessage($Head->In->Channel, "4Error: Unable to ban IP.");
  187. return false;
  188. }
  189.  
  190. $this->SendMessage($Head->In->Channel, "4Banned: ".$ip);
  191.  
  192. continue;
  193.  
  194. case '!unbanip':
  195. $this->CheckSQL();
  196.  
  197. $ip = $params[1];
  198.  
  199. if (!strlen($ip))
  200. {
  201. $this->SendMessage($Head->In->Channel, "4Usage: !unbanip <ip>");
  202. return 1;
  203. }
  204.  
  205. if (!$this->UnbanIP($ip)) {
  206. $this->SendMessage($Head->In->Channel, "4Error: Unable to unban IP.");
  207. return false;
  208. }
  209.  
  210. $this->SendMessage($Head->In->Channel, "4Unbanned: ".$ip);
  211.  
  212. continue;
  213.  
  214. case '!lastban':
  215. $this->CheckSQL();
  216.  
  217. if ($this->GetTotalBans() == 0) return $this->SendMessage($Head->In->Channel, "4No bans found.");
  218.  
  219. $Result = mysql_query("SELECT * FROM `bans` ORDER BY `banid` DESC LIMIT 1");
  220.  
  221. while ($row = mysql_fetch_array($Result, MYSQL_ASSOC))
  222. {
  223. $this->SendMessage($Head->In->Channel, "4Last banned IP: [".$row['bandate']."] ".$row['name']." (IP:".$row['ip'].") - banned by Admin ".$row['banner']." for ".$row['reason']);
  224. }
  225.  
  226. continue;
  227.  
  228. case '!lastbans':
  229. $this->CheckSQL();
  230.  
  231. if ($this->GetTotalBans() == 0) return $this->SendMessage($Head->In->Channel, "4No bans found.");
  232.  
  233. $Result = mysql_query("SELECT * FROM `bans` ORDER BY `banid` DESC LIMIT 5");
  234.  
  235. $this->SendMessage($Head->In->Channel, "4Last 5 banned IP addresses:");
  236.  
  237. while ($row = mysql_fetch_array($Result, MYSQL_ASSOC))
  238. {
  239. $this->SendMessage($Head->In->Channel, "[".$row['bandate']."] ".$row['name']." (IP:".$row['ip'].") - banned by Admin ".$row['banner']." for ".$row['reason']);
  240. }
  241.  
  242. continue;
  243.  
  244. case '!unbanlast':
  245. $this->CheckSQL();
  246.  
  247. if ($this->GetTotalBans() == 0) return $this->SendMessage($Head->In->Channel, "4No bans found.");
  248.  
  249. $Result = mysql_query("SELECT * FROM `bans` ORDER BY `banid` DESC LIMIT 1");
  250.  
  251.  
  252. while ($row = mysql_fetch_array($Result, MYSQL_ASSOC))
  253. {
  254. $this->SendMessage($Head->In->Channel, "4Unbanned: [".$row['bandate']."] ".$row['name']." (IP:".$row['ip'].") - banned by Admin ".$row['banner']." for ".$row['reason']);
  255. $this->UnbanIP($row['ip']);
  256. }
  257.  
  258. continue;
  259.  
  260. case '!lastip':
  261. $this->CheckSQL();
  262.  
  263. if (!strlen($params[1]))
  264. {
  265. $this->SendMessage($Head->In->Channel, "4Usage: !lastip <playername>");
  266. return 1;
  267. }
  268.  
  269. $Query = sprintf("SELECT * FROM `playerjoins` WHERE `player` = '%s'", $params[1]);
  270. $Result = mysql_query($Query);
  271.  
  272. $tot = mysql_num_rows($Result);
  273.  
  274. if ($tot == 0)
  275. {
  276. return $this->SendMessage($Head->In->Channel, "4Player not found.");
  277. }
  278.  
  279. $Query = sprintf("SELECT * FROM `playerjoins` WHERE `player` = '%s' ORDER BY `date` DESC LIMIT 1", $params[1]);
  280.  
  281. $result = mysql_query($Query);
  282.  
  283. while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
  284. {
  285. $message = sprintf("4%s last joined with IP: %s (%s)", $row['player'], $row['ip'], $row['date']);
  286.  
  287. $this->SendMessage($Head->In->Channel, $message);
  288. }
  289.  
  290. continue;
  291.  
  292. case '!bancount':
  293. $this->CheckSQL();
  294.  
  295. $admin = $params[1];
  296.  
  297. if (!strlen($admin)) {
  298. $this->SendMessage($Head->In->Channel, "4Usage: !bancount <admin>");
  299. return 1;
  300. }
  301.  
  302. $total = $this->GetBanCount($admin);
  303.  
  304. $this->SendMessage($Head->In->Channel, "".$admin." has banned a total of ".$total." player(s).");
  305.  
  306. continue;
  307.  
  308. case '!searchbans':
  309. $this->CheckSQL();
  310.  
  311. $search = $params[1];
  312.  
  313. if (!strlen($search)) {
  314. $this->SendMessage($Head->In->Channel, "4Usage: !searchbans <name/IP>");
  315. return 1;
  316. }
  317.  
  318. $ip = false;
  319. $text = false;
  320.  
  321. if ($this->validip($search)) {
  322. $ip = true;
  323. } else {
  324. $text = true;
  325. }
  326.  
  327. if ($text == true)
  328. {
  329. $Query = sprintf("SELECT * FROM `bans` WHERE `name` = '%s'", $search);
  330. }
  331. else
  332. {
  333. $Query = sprintf("SELECT * FROM `bans` WHERE `ip` = '%s'", $search);
  334. }
  335.  
  336. $Result = mysql_query($Query);
  337.  
  338. $found = mysql_num_rows($Result);
  339.  
  340. if ($found == 0) {
  341. $this->SendMessage($Head->In->Channel, "4No matches found.");
  342. } else {
  343. if ($text == true) {
  344. $Query = sprintf("SELECT * FROM `bans` WHERE `name` = '%s'", $search);
  345. } else {
  346. $Query = sprintf("SELECT * FROM `bans` WHERE `ip` = '%s'", $search);
  347. }
  348.  
  349. $Result = mysql_query($Query);
  350.  
  351. while ($row = mysql_fetch_array($Result, MYSQL_ASSOC)) {
  352. $Message = sprintf("4Matching ban: %s (%s) - By Admin %s for %s. 3(%s)", $row['name'], $row['ip'], $row['banner'], $row['reason'], $row['bandate']);
  353.  
  354. Distribute($Head->In->Channel, $Message);
  355. }
  356. }
  357.  
  358. continue;
  359.  
  360. case '!why':
  361. $this->CheckSQL();
  362.  
  363. $name = $params[1];
  364.  
  365. if (!strlen($params[1]))
  366. {
  367. $this->SendMessage($Head->In->Channel, "4Usage: !why <playername>");
  368. return 1;
  369. }
  370.  
  371. $Query = sprintf("SELECT * FROM `logs` WHERE `player` = '%s'", $name);
  372.  
  373. $Result = mysql_query($Query);
  374.  
  375. $tot = mysql_num_rows($Result);
  376.  
  377. if ($tot == 0)
  378. {
  379. $this->SendMessage($Head->In->Channel, "4Player not found.");
  380. return 1;
  381. }
  382.  
  383. $Query = sprintf("SELECT * FROM `logs` WHERE `player` = '%s' ORDER BY `date` DESC", $name);
  384.  
  385. $Result = mysql_query($Query);
  386.  
  387. $this->SendMessage($Head->In->Channel, "4*** Player log of ".$name." (".$tot." record(s))");
  388.  
  389. while ($row = mysql_fetch_array($Result, MYSQL_ASSOC))
  390. {
  391. $message = sprintf("4[%s] 3(%s by %s): %s", $row['date'], $row['type'], $row['admin'], $row['reason']);
  392. $this->SendMessage($Head->In->Channel, $message);
  393. }
  394.  
  395. continue;
  396.  
  397. case '!addnote':
  398. $this->CheckSQL();
  399.  
  400. $player = $params[1];
  401. $params = $this->Clear($params,1);
  402. $reason = trim(implode( " ", $params));
  403.  
  404. if (!strlen($player) || !strlen($reason)) {
  405. $this->SendMessage($Head->In->Channel, "4Usage: !addnote <playername> <reason>");
  406. return 1;
  407. }
  408.  
  409. $Query = sprintf("INSERT INTO `logs` (`logid`, `player`, `admin`, `reason`, `type`, `date`)
  410. values (NULL, '%s', '%s', '%s', 'Note', NOW())", $player, $Head->In->Nickname, $reason);
  411.  
  412. if (!mysql_query($Query)) {
  413. $this->SendMessage($Head->In->Channel, "There was an error with the database.");
  414. return 1;
  415. }
  416.  
  417. $this->SendMessage($Head->In->Channel, "4Note successfully added.");
  418.  
  419. continue;
  420. }
  421. }
  422.  
  423. if ($Head->IsOp($Head->In->Nickname, $Head->In->Channel))
  424. {
  425. }
  426.  
  427. if ($Head->IsAdmin($Head->In->Nickname, $Head->In->Channel))
  428. {
  429. switch ($params[0])
  430. {
  431. case '!dc':
  432. if (!$this->CheckSQL()) {
  433. $this->SendMessage($Head->In->Channel, "4Error: Cannot disconnect from server. (Not connected)");
  434. return 1;
  435. }
  436.  
  437. mysql_close($this->MySQL);
  438.  
  439. $this->SendMessage($Head->In->Channel, "10*** MySQL connection closed.");
  440.  
  441. continue;
  442.  
  443. case '!reconnect':
  444. if ($this->CheckSQL()) {
  445. $this->SendMessage($Head->In->Channel, "4Error: MySQL connection active, no reconnection needed");
  446. return 1;
  447. }
  448.  
  449. $this->SendMessage($Head->In->Channel, "10*** Attempting reconnection to MySQL server..");
  450.  
  451. if (!$this->SQLConnect()) {
  452. $this->SendMessage($Head->In->Channel, "10*** Connection to MySQL server failed: ".mysql_error($this->MySQL));
  453. return 1;
  454. }
  455.  
  456. $this->SendMessage($Head->In->Channel, "10*** Connection to MySQL server successful.");
  457.  
  458. continue;
  459.  
  460. case '!checksql':
  461.  
  462. if (!$this->CheckSQL()) {
  463. return $this->SendMessage($Head->In->Channel, "10*** No MySQL connection active.");
  464. }
  465.  
  466. $this->SendMessage($Head->In->Channel, "10*** MySQL connection is active.");
  467.  
  468. continue;
  469. }
  470. }
  471. }
  472. }
  473. }
  474. }
  475.  
  476. // Send message to specified channel.
  477. function SendMessage ($channel, $message)
  478. {
  479. global $Bot;
  480.  
  481. $string = sprintf("PRIVMSG %s %s", $channel, $message);
  482.  
  483. $Bot['Parent']->Send($string);
  484. }
  485.  
  486. function Clear( $parts, $number )
  487. {
  488. for ($i = 0; $i <= $number; $i++) {
  489. $parts[$i] = "";
  490. }
  491. return $parts;
  492. }
  493.  
  494. function IsRegistered ($player)
  495. {
  496. $Query = sprintf("SELECT * FROM `users` WHERE `username` = '%s'", $player);
  497.  
  498. $Result = mysql_query($Query);
  499.  
  500. if (mysql_num_rows($Result) == 0)
  501. return false;
  502.  
  503. return true;
  504. }
  505.  
  506. function IsBanned ($ip)
  507. {
  508. $Query = sprintf("SELECT * FROM `bans` WHERE `ip` = '%s'", $ip);
  509.  
  510. $Result = mysql_query($Query);
  511.  
  512. if (mysql_num_rows($Result) == 0)
  513. return false;
  514.  
  515. return true;
  516. }
  517.  
  518. function BanIP ($ip, $banner, $reason)
  519. {
  520. $nextid = GetTotalBans() + 1;
  521.  
  522. $Query = sprintf("INSERT INTO `bans` (`banid`, `ip`, `name`, `banner`, `reason`, `bandate`)
  523. values (%d, '%s', 'IRC Ban', '%s', '%s', NOW())", $nextid, $ip, $banner, $reason);
  524.  
  525. if (!mysql_query($Query))
  526. return false;
  527.  
  528. return true;
  529. }
  530.  
  531. function UnbanIP ($ip)
  532. {
  533. if (!$this->IsBanned($ip)) return false;
  534.  
  535. $Query = sprintf("DELETE FROM `bans` WHERE `ip` = '%s'", $ip);
  536.  
  537. if (!mysql_query($Query))
  538. return false;
  539.  
  540. return true;
  541. }
  542.  
  543. function GetTotalBans ()
  544. {
  545. $Result = mysql_query('SELECT * FROM `bans`');
  546.  
  547. $Tot = mysql_num_rows($Result);
  548.  
  549. return $Tot;
  550. }
  551.  
  552. function GetBanCount ($admin)
  553. {
  554. $Query = sprintf("SELECT * FROM `logs` WHERE `admin` = '%s' AND `type` = 'ban'", $admin);
  555.  
  556. $Result = mysql_query($Query);
  557.  
  558. return mysql_num_rows($Result);
  559. }
  560.  
  561. function validip($ip)
  562. {
  563. if (!empty($ip) && ip2long($ip)!=-1) {
  564. $reserved_ips = array (
  565. array('0.0.0.0','2.255.255.255'),
  566. array('10.0.0.0','10.255.255.255'),
  567. array('127.0.0.0','127.255.255.255'),
  568. array('169.254.0.0','169.254.255.255'),
  569. array('172.16.0.0','172.31.255.255'),
  570. array('192.0.2.0','192.0.2.255'),
  571. array('192.168.0.0','192.168.255.255'),
  572. array('255.255.255.0','255.255.255.255')
  573. );
  574.  
  575. foreach ($reserved_ips as $r) {
  576. $min = ip2long($r[0]);
  577. $max = ip2long($r[1]);
  578. if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
  579. }
  580. return true;
  581. } else {
  582. return false;
  583. }
  584. }
  585.  
  586. function SQLConnect()
  587. {
  588. global $Bot;
  589.  
  590. $this->MySQL = mysql_connect($this->Server, $this->User, $this->Password);
  591.  
  592. if (!$this->MySQL) {
  593. $Bot[$this->Index]->Output("Unable to connect to MySQL server. (".$this->User."@".$this->Server.")");
  594. return false;
  595. }
  596.  
  597. mysql_select_db('PTP', $this->MySQL);
  598.  
  599. $Bot[$this->Index]->Output("Connected to MySQL server. (".$this->User."@".$this->Server.")");
  600.  
  601. return true;
  602. }
  603.  
  604. function CheckSQL ()
  605. {
  606. if (!mysql_ping()) {
  607. $this->SQLConnect();
  608. return false;
  609. }
  610.  
  611. return true;
  612. }
  613. }
  614.  
  615. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement