Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.06 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Sweater\Plugins;
  4. use Sweater;
  5. use Sweater\Exceptions;
  6. use Silk;
  7.  
  8. class Commands extends BasePlugin {
  9.  
  10. protected $arrDependencies = ['Bot'];
  11. protected $intVersion = 0.5;
  12. protected $strAuthor = 'Arthur'; /* 3/4 oh this file was made by myself (Kevin),
  13. credits go to Arthur for the source though */
  14. public $blnConstructor = true;
  15. public $blnGame = true;
  16.  
  17. private $arrCommands = [
  18. 'AC' => 'handleAddCoins',
  19. 'AF' => 'handleAddFurniture',
  20. 'AI' => 'handleBuyInventory',
  21. 'NICK' => 'handleNicknameChange',
  22. 'PING' => 'handleSendPing',
  23. 'PONG' => 'handleSendPong',
  24. 'UI' => 'handleUpdateIgloo',
  25. 'JR' => 'handleJoinRoom',
  26. 'USERS' => 'handleshowOnline',
  27.  
  28. 'NG' => 'handleUpdateNameglow',
  29. 'NC' => 'handleUpdateNameColour',
  30. 'TITLE' => 'handleUpdateTitle',
  31. 'M' => 'handleUpdateMood',
  32. 'SP' => 'handleUpdateSpeed',
  33. 'BC' => 'handleUpdateBubbleColor',
  34. 'BT' => 'handleUpdateBubbleTextColor',
  35. 'CG' => 'handleUpdateChatGlow',
  36. 'PG' => 'handleUpdatePenguinGlow',
  37. 'MG' => 'handleUpdateMoodGlow',
  38. 'MC' => 'handleUpdateMoodColor',
  39. 'RC' => 'handleUpdateRingColor',
  40. 'SG' => 'handleUpdateSnowBallGlow',
  41. 'SS' => 'handleUpdateSize',
  42. 'ALPHA' => 'handleUpdateAlpha',
  43.  
  44. 'KICK' => 'handleKickPlayer',
  45. 'BAN' => 'handleBanPlayer',
  46. 'UNBAN' => 'handleUnbanPlayer'
  47. ];
  48.  
  49. private $objBot;
  50.  
  51. // Over-ride functions
  52.  
  53. function getOnlineStatus($intPlayer){
  54. $intPlayer = $strUsername;
  55. $blnOnline = isset($this->arrClientsByID[$intPlayer]);
  56. return $blnOnline;
  57. }
  58.  
  59. public function handleConstruction(){
  60. $this->addCustomXtHandler('m#sm', 'handlePlayerMessage');
  61. $this->objBot = $this->objServer->arrPlugins['Bot'];
  62. }
  63.  
  64. private function handleUpdateNameglow(Array $arrArguments, Sweater\Client $objClient) {
  65. if(count($arrArguments) == 0){
  66. $this->objBot->sendMessage('You have removed your NameGlow', $objClient);
  67. $objClient->setNameglow("");
  68. }else{
  69. list($Ng) = $arrArguments;
  70.  
  71. if(preg_match('/^[a-f0-9]{6}$/i', $Ng)) {
  72. $objClient->setNameglow('0x' . $Ng);
  73. $this->objBot->sendMessage('You have updated your NameGlow', $objClient);
  74. }
  75. }
  76. }
  77.  
  78. private function handleUpdateMoodGlow(Array $arrArguments, Sweater\Client $objClient) {
  79. if(count($arrArguments) == 0){
  80. $this->objBot->sendMessage('You have removed your Moodglow', $objClient);
  81. $objClient->setMoodGlow("");
  82. }else{
  83. list($mg) = $arrArguments;
  84.  
  85. if(preg_match('/^[a-f0-9]{6}$/i', $mg)) {
  86. $objClient->setMoodGlow('0x' . $mg);
  87. $this->objBot->sendMessage('You have updated your NameGlow', $objClient);
  88. }
  89. }
  90. }
  91.  
  92. private function handleUpdateMoodColor(Array $arrArguments, Sweater\Client $objClient) {
  93. if(count($arrArguments) == 0){
  94. $this->objBot->sendMessage('You have removed your Moodcolor', $objClient);
  95. $objClient->setMoodColor("");
  96. }else{
  97. list($mc) = $arrArguments;
  98.  
  99. if(preg_match('/^[a-f0-9]{6}$/i', $mc)) {
  100. $objClient->setMoodColor('0x' . $mc);
  101. $this->objBot->sendMessage('You have updated your Moodcolor', $objClient);
  102. }
  103. }
  104. }
  105.  
  106. private function handleUpdatePenguinGlow(Array $arrArguments, Sweater\Client $objClient) {
  107. if(count($arrArguments) == 0){
  108. $this->objBot->sendMessage('You have removed your Penguinglow', $objClient);
  109. $objClient->setPenguinGlow("");
  110. }else{
  111. list($pg) = $arrArguments;
  112.  
  113. if(preg_match('/^[a-f0-9]{6}$/i', $pg)) {
  114. $objClient->setPenguinGlow('0x' . $pg);
  115. $this->objBot->sendMessage('You have updated your Penguinglow', $objClient);
  116. }
  117. }
  118. }
  119.  
  120. private function handleUpdateRingColor(Array $arrArguments, Sweater\Client $objClient) {
  121. if(count($arrArguments) == 0){
  122. $this->objBot->sendMessage('You have removed your Ringcolor', $objClient);
  123. $objClient->setRingColor("");
  124. }else{
  125. list($rc) = $arrArguments;
  126.  
  127. if(preg_match('/^[a-f0-9]{6}$/i', $rc)) {
  128. $objClient->setRingColor('0x' . $rc);
  129. $this->objBot->sendMessage('You have updated your Ringcolor', $objClient);
  130. }
  131. }
  132. }
  133.  
  134. private function handleUpdateSnowBallGlow(Array $arrArguments, Sweater\Client $objClient) {
  135. if(count($arrArguments) == 0){
  136. $this->objBot->sendMessage('You have removed your Snowball glow', $objClient);
  137. $objClient->setSnowballGlow("");
  138. }else{
  139. list($sg) = $arrArguments;
  140.  
  141. if(preg_match('/^[a-f0-9]{6}$/i', $sg)) {
  142. $objClient->setSnowballGlow('0x' . $sg);
  143. $this->objBot->sendMessage('You have updated your Snowball glow', $objClient);
  144. }
  145. }
  146. }
  147.  
  148. private function handleUpdateChatGlow(Array $arrArguments, Sweater\Client $objClient) {
  149. if(count($arrArguments) == 0){
  150. $this->objBot->sendMessage('You have removed your Chatglow', $objClient);
  151. $objClient->setChatGlow("");
  152. }else{
  153. list($cg) = $arrArguments;
  154.  
  155. if(preg_match('/^[a-f0-9]{6}$/i', $cg)) {
  156. $objClient->setChatGlow('0x' . $cg);
  157. $this->objBot->sendMessage('You have updated your Chatglow', $objClient);
  158. }
  159. }
  160. }
  161.  
  162. private function handleUpdateBubbleColor(Array $arrArguments, Sweater\Client $objClient) {
  163. if(count($arrArguments) == 0){
  164. $this->objBot->sendMessage('You have removed your Bubblecolor', $objClient);
  165. $objClient->setBubbleColor("");
  166. }else{
  167. list($bc) = $arrArguments;
  168.  
  169. if(preg_match('/^[a-f0-9]{6}$/i', $bc)) {
  170. $objClient->setBubbleColor('0x' . $bc);
  171. $this->objBot->sendMessage('You have updated your Bubblecolor', $objClient);
  172. }
  173. }
  174. }
  175.  
  176. private function handleUpdateBubbleTextColor(Array $arrArguments, Sweater\Client $objClient) {
  177. if(count($arrArguments) == 0){
  178. $this->objBot->sendMessage('You have removed your BubbleTextColor', $objClient);
  179. $objClient->setBubbleTextColor("");
  180. }else{
  181. list($btc) = $arrArguments;
  182.  
  183. if(preg_match('/^[a-f0-9]{6}$/i', $btc)) {
  184. $objClient->setBubbleTextColor('0x' . $btc);
  185. $this->objBot->sendMessage('You have updated your BubbleTextColor', $objClient);
  186. }
  187. }
  188. }
  189.  
  190. private function handleUpdateTitle(Array $arrArguments, Sweater\Client $objClient) {
  191. if(count($arrArguments) == 0){
  192. $this->objBot->sendMessage('You have removed your Title', $objClient);
  193. $objClient->setTitle("");
  194. }else{
  195. list($title) = $arrArguments;
  196.  
  197. $objClient->setTitle($title);
  198. $this->objBot->sendMessage('You have updated your Title', $objClient);
  199. }
  200. }
  201.  
  202. private function handleUpdateNameColour(Array $arrArguments, Sweater\Client $objClient) {
  203. if(count($arrArguments) == 0){
  204. $this->objBot->sendMessage('You have removed your Namecolor', $objClient);
  205. $objClient->setNamecolour("");
  206. }else{
  207. list($nc) = $arrArguments;
  208.  
  209. if(preg_match('/^[a-f0-9]{6}$/i', $nc)) {
  210. $objClient->setNamecolour('0x' . $nc);
  211. $this->objBot->sendMessage('You have updated your Namecolor', $objClient);
  212. }
  213. }
  214. }
  215.  
  216. private function handleUpdateSpeed(Array $arrArguments, Sweater\Client $objClient) {
  217. if(count($arrArguments) == 0){
  218. $this->objBot->sendMessage('You have removed your Speed', $objClient);
  219. $objClient->setSpeed("4");
  220. }else{
  221. list($sp) = $arrArguments;
  222.  
  223. if(is_numeric($sp)) {
  224. $objClient->setSpeed($sp);
  225. $this->objBot->sendMessage('You have updated your Speed', $objClient);
  226. }
  227. }
  228. }
  229.  
  230. private function handleUpdateSize(Array $arrArguments, Sweater\Client $objClient) {
  231. if(count($arrArguments) == 0){
  232. $this->objBot->sendMessage('You have removed your size', $objClient);
  233. $objClient->setSize("100");
  234. }else{
  235. list($size) = $arrArguments;
  236.  
  237. if(is_numeric($size)) {
  238. $objClient->setSize($size);
  239. $this->objBot->sendMessage('You have updated your size', $objClient);
  240. }
  241. }
  242. }
  243.  
  244. private function handleUpdateAlpha(Array $arrArguments, Sweater\Client $objClient) {
  245. if(count($arrArguments) == 0){
  246. $this->objBot->sendMessage('You have removed your transparency', $objClient);
  247. $objClient->setAlpha("100");
  248. }else{
  249. list($alpha) = $arrArguments;
  250.  
  251. if(is_numeric($alpha)) {
  252. $objClient->setAlpha($alpha);
  253. $this->objBot->sendMessage('You have updated your transparency', $objClient);
  254. }
  255. }
  256. }
  257.  
  258. private function handleUpdateMood(Array $arrArguments, Sweater\Client $objClient){
  259. if(count($arrArguments) == ""){
  260. $this->objBot->sendMessage($objClient, "You have removed your mood");
  261. $objClient->setMood("");
  262. }else{
  263. list($m) = $arrArguments;
  264.  
  265. $objClient->setMood($m);
  266. $this->objBot->sendMessage('You have updated your mood', $objClient);
  267. }
  268. }
  269.  
  270. private function handleAddCoins(Array $arrArguments, Sweater\Client $objClient){
  271. Silk\Logger::Log('Adding coins!');
  272. list($intCoins) = $arrArguments;
  273. if(is_numeric($intCoins) && $intCoins < 5001 && $objClient->getCoins() < 1000000){
  274. $objClient->addCoins($intCoins);
  275. $objClient->sendXt('zo', $objClient->getIntRoom(), $objClient->getCoins());
  276. }
  277. }
  278.  
  279. private function handleAddFurniture(Array $arrArguments, Sweater\Client $objClient){
  280. list($intFurniture) = $arrArguments;
  281. if(array_key_exists($intFurniture, $this->arrFurniture)){
  282. $objClient->addFurniture($intFurniture);
  283. }
  284. }
  285.  
  286. private function handleBuyInventory(Array $arrArguments, Sweater\Client $objClient){
  287. Silk\Logger::Log('Purchashing item!');
  288. list($intItem) = $arrArguments;
  289. if(array_key_exists($intItem, $this->objServer->arrItems)){
  290. $objClient->addItem($intItem);
  291. }
  292. }
  293.  
  294. private function handleNicknameChange(Array $arrArguments, Sweater\Client $objClient){
  295. if($objClient->getModerator()){
  296. list($strUsername) = $arrArguments;
  297. $objClient->setNickname($strUsername);
  298. $intRoom = $objClient->getExtRoom();
  299. $blnIgloo = $intRoom > 1000;
  300. $strMethod = $blnIgloo ? 'handleJoinPlayer' : 'handleJoinRoom';
  301. $this->objServer->$strMethod([4 => $intRoom, 0, 0], $objClient);
  302. }
  303. }
  304.  
  305. private function handleJoinRoom(Array $arrArguments, Sweater\Client $objClient){
  306. list($intRoom) = $arrArguments;
  307. $blnIgloo = $intRoom > 1000;
  308. if ($intRoom > 1000) {
  309. $objClient->sendError(213);
  310. return $this->removeClient($objClient->resSocket);
  311. }
  312. $strMethod = $blnIgloo ? 'handleJoinPlayer' : 'handleJoinRoom';
  313. $this->objServer->$strMethod([4 => $intRoom, 0, 0], $objClient);
  314. }
  315.  
  316. private function handleShowOnline(Array $arrArguments, Sweater\Client $objClient) {
  317. $intCount = count($this->objServer->arrClientsByID);
  318. if($intCount >= 2) {
  319. $this->objBot->sendMessage("There are {$intCount} penguins online" , $objClient);
  320. } else{
  321. $this->objBot->sendMessage("You are the only penguin online", $objClient);
  322. }
  323. }
  324.  
  325. private function handleSendPing(Array $arrArguments, Sweater\Client $objClient){
  326. $this->objBot->sendMessage("Ping", $objClient);
  327. }
  328.  
  329. private function handleSendPong(Array $arrArguments, Sweater\Client $objClient){
  330. $this->objBot->sendMessage("Pong, funny eh ?", $objClient);
  331. }
  332.  
  333. private function handleUpdateIgloo(Array $arrArguments, Sweater\Client $objClient){
  334. list($intIgloo) = $arrArguments;
  335. $objClient->updateIgloo($intIgloo);
  336. }
  337.  
  338. private function handleKickPlayer(Array $arrArguments, Sweater\Client $objClient){
  339. if($objClient->getModerator()){
  340. list($strTarget) = $arrArguments;
  341. $objClient = $this->objServer->getClientByName($strTarget);
  342. if($objClient){
  343. $objClient->sendXt('e', -1, 5);
  344. $this->objServer->removeClient($objClient->resSocket);
  345. }
  346. }
  347. }
  348.  
  349. private function handleBanPlayer(Array $arrArguments, Sweater\Client $objClient){
  350. if($objClient->getModerator()){
  351. list($strTarget) = $arrArguments;
  352. $objClient = $this->objServer->getClientByName($strTarget);
  353. if($objClient){
  354. $objClient->sendXt('e', -1, 800);
  355. $objClient->updateColumn("Banned", 1);
  356. $this->objServer->removeClient($objClient->resSocket);
  357. }
  358. }
  359. }
  360.  
  361. private function handleUnbanPlayer(Array $arrArguments, Sweater\Client $objClient){
  362. if($objClient->getModerator()){
  363. list($strTarget) = $arrArguments;
  364. $objClient = $this->objServer->getClientByName($strTarget);
  365. if($objClient){
  366. $objClient->updateColumn("Banned", 0);
  367. }
  368. }
  369. }
  370.  
  371. // Parses message to get commands argument(s), and calls command handler
  372. // This shouldn't require any editing
  373. protected function handlePlayerMessage(Array $arrPacket, Sweater\Client $objClient){
  374. $strMessage = $arrPacket[5];
  375. $blnCommand = substr($strMessage, 0, 1) == '!';
  376. if($blnCommand){
  377. $strStripped = substr($strMessage, 1);
  378. $blnArguments = strpos($strStripped, ' ') > -1;
  379. $arrArguments = [];
  380. if($blnArguments){
  381. $arrArguments = explode(' ', $strStripped);
  382. $strCommand = $arrArguments[0];
  383. unset($arrArguments[0]);
  384. $arrArguments = array_values($arrArguments);
  385. unset($arrFixed);
  386. } else {
  387. $strCommand = $strStripped;
  388. }
  389. $strCommand = strtoupper($strCommand);
  390. if(array_key_exists($strCommand, $this->arrCommands)){
  391. $strHandler = $this->arrCommands[$strCommand];
  392. call_user_func([$this, $strHandler], $arrArguments, $objClient);
  393. }
  394. }
  395. }
  396.  
  397. }
  398.  
  399. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement