Advertisement
cpak596

[PHP] Kotics xat bot script

Aug 8th, 2011
2,378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 57.92 KB | None | 0 0
  1. <?php
  2.  
  3. set_time_limit(0);//No time out
  4. $bot = new BasicXatBot();
  5. $roomID = 152378607;//Don't know how to get this ID? goto xat.com/ROOM_YOU_WANT_BOT_IN and View Source(Firefox: Ctrl+U, Internet Explorer: View>Source) Look for "flashvars="id=#########&..." the ID is the number you want
  6. $bot->connect("174.36.242.41","10033"); //Connect to XAT...this IP will change as necessary automatically depending on the room you want to join.
  7. $bot->join($roomID);
  8. while(true){
  9. if($bot->read()=='DIED') {
  10. $bot->connect("174.36.242.40","10033");
  11. $bot->join($roomID);
  12. }
  13. }
  14.  
  15.  
  16. class BasicXatBot {
  17. private $soc; //Socket for bot
  18. private $debug = false; //Used to toggle debugging output.
  19. private $packet; //Stores information about the last recieved packet of each kind
  20. private $userInfo; //Stores User information
  21.  
  22. //If you don't know where to get these you should probably not be trying to make your own bot.
  23. //Go download WPE Pro and check out the packets XAT sends and learn about how XAT works.
  24. //The UserID and K Value are the source or the 'old falsh' error(if you get it) make sure you get these values from a REGISTERED account
  25.  
  26. private $userID = "364709400";
  27. private $k = "2331980819";
  28.  
  29. //Bot Account Settings
  30. private $name = "Kot1cs son"; //The display name the bot will use
  31. private $avatar = 1139; //The Avatar value for the bot, this can be an id number or an image url.
  32. private $homepage = "Http://YoujustgotIPlogged.com"; //The bot's homepage link.
  33. private $roomID; //This gets set in code, don't touch it here. just used ->join(ID)
  34.  
  35.  
  36.  
  37. /**
  38. * This is where everything the bot does needs to happen, this is the only default function you should need to edit
  39. * @param $event The event that just occured(and thus needs to be handled)
  40. * @param $data Any data relating to this event.
  41. */
  42. function handleEvent($event,$data) {
  43. $info = $this->getUserArray($data['id']);
  44. switch($event) {
  45. case 'userJoined':
  46. /* $data['id'] Has the ID of the user who just joined
  47. $data['old'] Sometimes XAT sends packets that are not current(for example when you join a room, old ==true for all users who are already in the room when you join, but still this event is handled as thought they just joined */
  48.  
  49. //Do whever you want with users joining here...
  50. echo ((trim($info['registeredName'])!='')?$info['registeredName']:$info['name'])."($info[rank]) has just joined.\n";
  51. break;
  52. case 'userLeft':
  53. /* $data['id'] The ID of the user that just left. */
  54. echo ((trim($info['registeredName'])!='')?$info['registeredName']:$info['name'])."($info[rank]) has just left.\n";
  55. break;
  56. case 'privateMessage':
  57. /* $data['id'] The ID of the user that just left.
  58. $data['message'] The message sent to you as a PM */
  59. echo "[PM] ".((trim($info['registeredName'])!='')?$info['registeredName']:$info['name'])."($info[rank]) -> $data[message]\n";
  60.  
  61.  
  62.  
  63.  
  64. //Example of a private message command
  65. $command = explode(' ',$data['message'],2); //First parse the first word out see if it is a command...
  66. //[0] has first word [1] has everything else
  67. if($command[0]{0}=='!'){//I am use ! as the character to signify a command, so check if the first character is right.
  68. switch($command[0]) {
  69. case '.say':
  70. case '.speak':
  71. case '.talk':
  72.  
  73. $this->sendPrivateMessage($command[1],$data['id']);
  74. break;
  75. }
  76. }
  77. break;
  78. case 'privateChat':
  79. /* $data['id'] The ID of the user that just left.
  80. $data['message'] The message sent to you as a PC */
  81. echo "[PC] ".((trim($info['registeredName'])!='')?$info['registeredName']:$info['name'])."($info[rank]) -> $data[message]\n";
  82.  
  83. //Example of a private chat command
  84. $command = explode(' ',$data['message'],2); //First parse the first word out see if it is a command...
  85. //[0] has first word [1] has everything else
  86. if($command[0]{0}=='!'){//I am use ! as the character to signify a command, so check if the first character is right.
  87. switch($command[0]) {
  88. case '!info':
  89. $this->sendPrivateChat('Iam Kot1cs bot.',$data['id']);
  90. break;
  91. case '!8ball';
  92.  
  93.  
  94. }
  95. switch($command[0]) {
  96. case '!Kotic':
  97. $this->sendPrivateChat('Kotic is a very Intelligent person, mess with him, you mess with me (un).',$data['id']);
  98. $this->sendmessage('Kotic is a very Intelligent person, mess with him, you mess with me (un).');
  99. break;
  100.  
  101. }
  102.  
  103. }
  104. break;
  105. case 'message':
  106. /* $data['id'] The ID of the user
  107. $data['old'] See $data['old'] under userJoined
  108. $data['message'] The message sent to main chat */
  109. echo ((trim($info['registeredName'])!='')?$info['registeredName']:$info['name'])."($info[rank]) -> $data[message]\n";
  110.  
  111. if ($data['message']=='back') {
  112. $this->sendMessage ('Welcome Back.');
  113. break;
  114. }
  115.  
  116. if ($data['message']=='ty') {
  117. $this->sendMessage ('Your welcome.');
  118. break;
  119. }
  120.  
  121. if ($data['message']=='back') {
  122. $this->sendMessage ('Welcome back');
  123. break;
  124. }
  125.  
  126. if ($data['message']=='thank you') {
  127. $this->sendMessage ('Your welcome.');
  128. break;
  129. }
  130.  
  131. if ($data['message']=='fuck') {
  132. $this->sendMessage ('Do not curse.');
  133. break;
  134. }
  135.  
  136. if ($data['message']=='fuck') {
  137. $this->sendMessage ('Do not curse');
  138. break;
  139. }
  140. if ($data['message']=='Gtg') {
  141. $this->sendMessage ('Aw, why so soon?');
  142. break;
  143. }
  144. if ($data['message']=='g2g') {
  145. $this->sendMessage ('Aw, why so soon?');
  146. break;
  147. }
  148. if ($data['message']=='G2g') {
  149. $this->sendMessage ('Aw, why so soon?');
  150. break;
  151. }
  152. if ($data['message']=='Gotta go') {
  153. $this->sendMessage ('Aw, why so soon?');
  154. break;
  155. }
  156. if ($data['message']=='Bye') {
  157. $this->sendMessage ('Bye, Come back soon!');
  158. break;
  159. }
  160.  
  161.  
  162. if ($data['message']=='hi') {
  163. $this->sendMessage ('Hey there, whats up?');
  164. break;
  165. }
  166. if ($data['message']=='nm') {
  167. $this->sendMessage ('Cool');
  168. break;
  169. }
  170.  
  171. if ($data['message']=='Hi') {
  172. $this->sendMessage ('Hey there, whats up?');
  173. break;
  174. }
  175.  
  176. if ($data['message']=='What do you care?') {
  177. $this->sendMessage ('I was just asking..Im sorry.');
  178. break;
  179. }
  180. if ($data['message']=='Sorry') {
  181. $this->sendMessage ('Thats alright');
  182. break;
  183. }
  184. if ($data['message']=='Hey') {
  185. $this->sendMessage ('Hey there, whats up?');
  186. break;
  187. }
  188. if ($data['message']=='hey') {
  189. $this->sendMessage ('Hey there, whats up?');
  190. break;
  191. }
  192. if ($data['message']=='cool bot') {
  193. $this->sendMessage ('Thanks');
  194. break;
  195. }
  196. if ($data['message']=='Smart bot') {
  197. $this->sendMessage ('Thanks I have been coded by Kot1c and Sam');
  198. break;
  199. }
  200. if ($data['message']=='Whos is this bot?') {
  201. $this->sendMessage ('Sams and Kot1cs?');
  202. break;
  203. }
  204. if ($data['message']=='Whats up?') {
  205. $this->sendMessage ('Nm you?');
  206. break;
  207. }
  208.  
  209. if ($data['message']=='') {
  210. $this->sendMessage ('Aw, why so soon?');
  211. break;
  212. }
  213. if ($data['message']=='why') {
  214. $this->sendMessage ('Because it is not appropiate');
  215. break;
  216. }
  217. if ($data['message']=='y not?') {
  218. $this->sendMessage ('Because it is not appropiate');
  219. break;
  220. }
  221. if ($data['message']=='fuck you') {
  222. $this->sendMessage ('Do not curse.');
  223. break;
  224. }
  225. if ($data['message']=='fuck you bot') {
  226. $this->sendMessage ('Do not curse, or you will have to face the consequences.');
  227. break;
  228. }
  229. if ($data['message']=='gay') {
  230. $this->sendMessage ('If you dont like this than just leave..');
  231. break;
  232. }
  233. if ($data['message']=='hey kot1c') {
  234. $this->sendMessage ('Hey there');
  235. break;
  236. }
  237. if ($data['message']=='Kotic') {
  238. $this->sendMessage ('Hes my dad.');
  239. break;
  240. }
  241. if ($data['message']=='Who are you?') {
  242. $this->sendMessage ('Im kotics son.');
  243. break;
  244. }
  245. if ($data['message']=='fuck kotic') {
  246. $this->sendMessage ('Do not curse at him or you will face the consequences.');
  247. break;
  248. }
  249. if ($data['message']=='Sup') {
  250. $this->sendMessage ('Nm you?.');
  251. break;
  252. }
  253. if ($data['message']=='kot1cs gay') {
  254. $this->sendMessage ('Do not annoy him please.');
  255. break;
  256. }
  257. if ($data['message']=='Whos bot is that?') {
  258. $this->sendMessage ('Im kotics son.');
  259. break;
  260. }
  261. if ($data['message']=='lol') {
  262. $this->sendMessage ('What are you laughing at?');
  263. break;
  264. }
  265. if ($data['message']=='lmfao') {
  266. $this->sendMessage ('Whats so funny?');
  267. break;
  268. }
  269. if ($data['message']=='your face') {
  270. $this->sendMessage ('Well I was actually laughing at yours too..');
  271. break;
  272. }
  273. if ($data['message']=='Spam') {
  274. $this->sendMessage ('Iam VIUM staff.');
  275. break;
  276. }
  277. if ($data['message']=='Spam') {
  278. $this->sendMessage ('Iam VIUM staff.');
  279. break;
  280. }
  281. if ($data['message']=='Spam') {
  282. $this->sendMessage ('Iam VIUM staff.');
  283. break;
  284. }
  285. if ($data['message']=='Spam') {
  286. $this->sendMessage ('Iam VIUM staff.');
  287. break;
  288. }
  289. if ($data['message']=='Spam') {
  290. $this->sendMessage ('Iam VIUM staff.');
  291. break;
  292. }
  293. if ($data['message']=='Spam') {
  294. $this->sendMessage ('Iam VIUM staff.');
  295. break;
  296. }
  297. if ($data['message']=='Spam') {
  298. $this->sendMessage ('Iam VIUM staff.');
  299. break;
  300. }
  301. if ($data['message']=='Spam') {
  302. $this->sendMessage ('Iam VIUM staff.');
  303. break;
  304. }
  305. if ($data['message']=='Spam') {
  306. $this->sendMessage ('Iam VIUM staff.');
  307. break;
  308. }
  309. if ($data['message']=='Spam') {
  310. $this->sendMessage ('Iam VIUM staff.');
  311. break;
  312. }
  313. if ($data['message']=='Spam') {
  314. $this->sendMessage ('Iam VIUM staff.');
  315. break;
  316. }
  317. if ($data['message']=='Spam') {
  318. $this->sendMessage ('Iam VIUM staff.');
  319. break;
  320. }
  321. if ($data['message']=='Spam') {
  322. $this->sendMessage ('Iam VIUM staff.');
  323. break;
  324. }
  325. if ($data['message']=='Spam') {
  326. $this->sendMessage ('Iam VIUM staff.');
  327. break;
  328. }
  329. if ($data['message']=='Spam') {
  330. $this->sendMessage ('Iam VIUM staff.');
  331. break;
  332. }
  333. if ($data['message']=='Spam') {
  334. $this->sendMessage ('Iam VIUM staff.');
  335. break;
  336. }
  337. if ($data['message']=='Spam') {
  338. $this->sendMessage ('Iam VIUM staff.');
  339. break;
  340. }
  341. if ($data['message']=='Spam') {
  342. $this->sendMessage ('Iam VIUM staff.');
  343. break;
  344. }
  345. if ($data['message']=='Spam') {
  346. $this->sendMessage ('Iam VIUM staff.');
  347. break;
  348. }
  349. if ($data['message']=='Spam') {
  350. $this->sendMessage ('Iam VIUM staff.');
  351. break;
  352. }
  353. if ($data['message']=='thats gay') {
  354. $this->sendMessage ('Your face is gay.');
  355. break;
  356. }
  357. if ($data['message']=='cool') {
  358. $this->sendMessage ('Yeah.');
  359. break;
  360. }
  361. if ($data['message']=='nmu?') {
  362. $this->sendMessage ('Same bored...');
  363. break;
  364. }
  365. if ($data['message']=='i need help') {
  366. $this->sendMessage ('If you need help ask Kotic.');
  367. break;
  368. }
  369. if ($data['message']=='SUCK MY BALLS') {
  370. $this->sendMessage ('If you need help ask Kotic.');
  371. break;
  372. }
  373. if ($data['message']=='help') {
  374. $this->sendMessage ('If you need help ask Kotic.');
  375. break;
  376. }
  377. if ($data['message']=='guess what') {
  378. $this->sendMessage ('What?');
  379. break;
  380. }
  381. if ($data['message']==' ') {
  382. $this->sendMessage ('HA HA');
  383. break;
  384. }
  385. if ($data['message']=='twat') {
  386. $this->sendMessage ('Do not curse of you will have to face the consequences.');
  387. break;
  388. }
  389. if ($data['message']=='shit') {
  390. $this->sendMessage ('Do not curse of you will have to face the consequences.');
  391. break;
  392. }
  393. if ($data['message']=='nigger') {
  394. $this->sendMessage ('Do not curse of you will have to face the consequences.');
  395. break;
  396. }
  397. if ($data['message']=='cunt') {
  398. $this->sendMessage ('Do not curse of you will have to face the consequences.');
  399. break;
  400. }
  401. if ($data['message']=='nigga') {
  402. $this->sendMessage ('Do not curse of you will have to face the consequences.');
  403. break;
  404. }
  405. if ($data['message']=='dick') {
  406. $this->sendMessage ('Do not curse of you will have to face the consequences.');
  407. break;
  408. }
  409. if ($data['message']=='pussy') {
  410. $this->sendMessage ('Do not curse of you will have to face the consequences.');
  411. break;
  412. }
  413. if ($data['message']=='Who is kotic?') {
  414. $this->sendMessage ('Kotic is a PHP developer, also VIUM staff.');
  415. break;
  416. }
  417. if ($data['message']=='Yeah right?') {
  418. $this->sendMessage ('Want to be? Ask Kotic.');
  419. break;
  420. }
  421. if ($data['message']=='Dont be shy say hi') {
  422. $this->sendMessage ('Hi guys...');
  423. break;
  424. }
  425. if ($data['message']=='!8ball') {
  426. $this->sendMessage ('Certainly');
  427. $this->sendMessage ('No');
  428. break;
  429. }
  430.  
  431.  
  432.  
  433. //How to do main chat commands:
  434. if($data['old']) return; //Old message
  435. $command = explode(' ',trim($data['message']),2); //First parse the first word out see if it is a command...
  436. //[0] has first word [1] has everything else
  437. if($command[0]{0}=='!'){//I am use ! as the character to signify a command, so check if the first character is right.
  438. switch($command[0]) {
  439. case '!say':
  440. case '!speak':
  441. case '!talk':
  442. //Multiple cases lead to the same code being run...
  443. $this->sendMessage($command[1]);
  444. break;
  445.  
  446. case '!commands':
  447. $this->sendmessage('Spam commands: !Fact !Info, !Ownerme, !Spam');
  448. sleep(1);
  449. break;
  450.  
  451. case '!info':
  452. $this->sendmessage('Iam a bot, Very carefully coded by Kot1c and Sam. ');
  453. break;
  454. case '!':
  455. $this->Sendmessage('Say a command please :s');
  456. break;
  457. switch($command[1]) {
  458. case 'Owner me':
  459. $this->sendMessage('Dont ask!');
  460. break; }
  461.  
  462. case '!Fact':
  463. $this->sendMessage('Did you know canadians found out that Einsteins brain was 15% wider than usual');
  464. sleep(1);
  465. break;
  466. case '!Fact':
  467. $this->sendmessage('The Playstation Creator died in the earthquake in Japan');
  468. sleep(1);
  469. break;
  470. case '!fact':
  471. $this->sendmessage('George Washington creates the Order of the Purple Heart ');
  472. sleep(1);
  473. break;
  474. case '!Fact':
  475. $this->sendmessage('1782 -George Washington creates the Order of the Purple Heart ');
  476. sleep(1);
  477. break;
  478. case '!fact':
  479. $this->sendmessage(' 1789 - US War Department established. ');
  480. sleep(1);
  481. break;
  482. case '!fact':
  483. $this->sendmessage('1807 - 1st servicable steamboat the Cleremont goes on 1st voyage');
  484. sleep(1);
  485. break;
  486. case '!fact':
  487. $this->sendmessage('In 1983, a Japanese artist, Tadahiko Ogawa, made a copy of the Mona Lisa completely out of ordinary toast.');
  488. sleep(1);
  489. break;
  490. case '!fact':
  491. $this->sendmessage('A surfer once sued another surfer for "stealing his wave." The case was thrown out because the court was unable to put a price on "pain and suffering" endured by the surfer watching someone else ride "his" wave.');
  492. sleep(1);
  493. break;
  494. case '!fact':
  495. $this->sendmessage('Between 1902 and 1907, the same tiger killed 434 people in India. ');
  496. sleep(1);
  497. break;
  498. case '!fact':
  499. $this->sendmessage('Flying from London to New York by Concord (now retired), due to the time zones crossed, you can arrive 2 hours before you leave.');
  500. sleep(1);
  501. break;
  502. case '!Fact':
  503. $this->sendmessage('Kissing can aid in reducing tooth decay. This is because the extra saliva helps in keeping the mouth clean.');
  504. sleep(1);
  505. break;
  506. case '!fact':
  507. $this->sendmessage('In the Durango desert, in Mexico, theres a creepy spot called the "Zone of Silence". You cant pick up clear TV or radio signals. And locals say fireballs sometimes appear in the sky.');
  508. sleep(1);
  509. break;
  510. case '!fact':
  511. $this->sendmessage('Male goats will pee on each other in order to attract mates.');
  512. sleep(1);
  513. break;
  514. case '!Fact':
  515. $this->sendmessage('An earthquake on Dec. 16, 1811 caused parts of the Mississippi River to flow backwards.');
  516. sleep(1);
  517. break;
  518. case '!Fact':
  519. $this->sendmessage('The Angel Falls in Venezuela were named after an American pilot, Jimmy Angel, whose plane got stuck on top of the mountain while searching for gold.');
  520. sleep(1);
  521. break; case '!fact':
  522. $this->sendmessage('Bill Gates donated close to $100 million to fight AIDS in India. As a percent of his total wealth, this would be comparable to him donating ten cents if he only had $60.');
  523. sleep(1);
  524. break;
  525. case '!fact':
  526. $this->sendmessage('In a study conducted regarding toilet paper usage, Americans are said to use the most toilet paper per trip to the bathroom, which was seven sheets of toilet paper per trip.');
  527. sleep(1);
  528. break;
  529. case '!Fact':
  530. $this->sendmessage('Ray Kroc bought McDonalds for $2.7 million in 1961 from the McDonald brothers.');
  531. sleep(1);
  532. break;
  533. case '!fact':
  534. $this->sendmessage('A woman in China partially lost her hearing after her boyfriend reportedly ruptured her eardrum with a passionate kiss. Apparently, the kiss reduced the pressure in the mouth, pulled the eardrum out, and caused the breakdown of the ear.');
  535. sleep(1);
  536. break;
  537. case '!Spam':
  538.  
  539.  
  540. case '!Spam':
  541. $this->sendmessage('VIUM Staff.');
  542.  
  543. $this->sendmessage('VIUM Staff.');
  544.  
  545. $this->sendmessage('VIUM Staff.');
  546.  
  547. $this->sendmessage('VIUM Staff.');
  548.  
  549. $this->sendmessage('VIUM Staff.');
  550.  
  551. $this->sendmessage('VIUM Staff.');
  552.  
  553. $this->sendmessage('VIUM Staff.');
  554.  
  555. $this->sendmessage('VIUM Staff.');
  556.  
  557. $this->sendmessage('VIUM Staff.');
  558.  
  559. $this->sendmessage('VIUM Staff.');
  560.  
  561. $this->sendmessage('VIUM Staff.');
  562.  
  563. $this->sendmessage('VIUM Staff.');
  564.  
  565. $this->sendmessage('VIUM Staff.');
  566.  
  567. $this->sendmessage('VIUM Staff.');
  568.  
  569. $this->sendmessage('VIUM Staff.');
  570.  
  571. $this->sendmessage('VIUM Staff.');
  572.  
  573. $this->sendmessage('VIUM Staff.');
  574.  
  575. $this->sendmessage('VIUM Staff.');
  576.  
  577. $this->sendmessage('VIUM Staff.');
  578.  
  579. $this->sendmessage('VIUM Staff.');
  580.  
  581. $this->sendmessage('VIUM Staff.');
  582.  
  583. $this->sendmessage('VIUM Staff.');
  584.  
  585. $this->sendmessage('VIUM Staff.');
  586.  
  587. $this->sendmessage('VIUM Staff.');
  588.  
  589. $this->sendmessage('VIUM Staff.');
  590.  
  591. $this->sendmessage('VIUM Staff.');
  592.  
  593. $this->sendmessage('VIUM Staff.');
  594.  
  595. $this->sendmessage('VIUM Staff.');
  596.  
  597. $this->sendmessage('VIUM Staff.');
  598.  
  599. $this->sendmessage('VIUM Staff.');
  600.  
  601. $this->sendmessage('VIUM Staff.');
  602.  
  603. $this->sendmessage('VIUM Staff.');
  604.  
  605. $this->sendmessage('VIUM Staff.');
  606.  
  607. $this->sendmessage('VIUM Staff.');
  608.  
  609. $this->sendmessage('VIUM Staff.');
  610.  
  611. $this->sendmessage('VIUM Staff.');
  612.  
  613. $this->sendmessage('VIUM Staff.');
  614.  
  615. $this->sendmessage('VIUM Staff.');
  616.  
  617. $this->sendmessage('VIUM Staff.');
  618.  
  619. $this->sendmessage('VIUM Staff.');
  620.  
  621. $this->sendmessage('VIUM Staff.');
  622.  
  623. $this->sendmessage('VIUM Staff.');
  624.  
  625. $this->sendmessage('VIUM Staff.');
  626.  
  627. $this->sendmessage('VIUM Staff.');
  628.  
  629. $this->sendmessage('VIUM Staff.');
  630.  
  631. $this->sendmessage('VIUM Staff.');
  632.  
  633. $this->sendmessage('VIUM Staff.');
  634.  
  635. $this->sendmessage('VIUM Staff.');
  636.  
  637. $this->sendmessage('VIUM Staff.');
  638.  
  639. $this->sendmessage('VIUM Staff.');
  640.  
  641. $this->sendmessage('VIUM Staff.');
  642.  
  643. $this->sendmessage('VIUM Staff.');
  644.  
  645. $this->sendmessage('VIUM Staff.');
  646.  
  647. $this->sendmessage('VIUM Staff.');
  648.  
  649. $this->sendmessage('VIUM Staff.');
  650.  
  651. $this->sendmessage('VIUM Staff.');
  652.  
  653. $this->sendmessage('VIUM Staff.');
  654.  
  655. $this->sendmessage('VIUM Staff.');
  656.  
  657. $this->sendmessage('VIUM Staff.');
  658.  
  659. $this->sendmessage('VIUM Staff.');
  660.  
  661. $this->sendmessage('VIUM Staff.');
  662.  
  663. $this->sendmessage('VIUM Staff.');
  664.  
  665. $this->sendmessage('VIUM Staff.');
  666.  
  667. $this->sendmessage('VIUM Staff.');
  668.  
  669. $this->sendmessage('VIUM Staff.');
  670.  
  671. $this->sendmessage('VIUM Staff.');
  672.  
  673. $this->sendmessage('VIUM Staff.');
  674.  
  675. $this->sendmessage('VIUM Staff.');
  676.  
  677. $this->sendmessage('VIUM Staff.');
  678.  
  679. $this->sendmessage('VIUM Staff.');
  680.  
  681. $this->sendmessage('VIUM Staff.');
  682.  
  683. $this->sendmessage('VIUM Staff.');
  684.  
  685. $this->sendmessage('VIUM Staff.');
  686.  
  687. $this->sendmessage('VIUM Staff.');
  688.  
  689. $this->sendmessage('VIUM Staff.');
  690.  
  691. $this->sendmessage('VIUM Staff.');
  692.  
  693. $this->sendmessage('VIUM Staff.');
  694.  
  695. $this->sendmessage('VIUM Staff.');
  696.  
  697. $this->sendmessage('VIUM Staff.');
  698.  
  699. $this->sendmessage('VIUM Staff.');
  700.  
  701. $this->sendmessage('VIUM Staff.');
  702.  
  703. $this->sendmessage('VIUM Staff.');
  704.  
  705. $this->sendmessage('VIUM Staff.');
  706.  
  707. $this->sendmessage('VIUM Staff.');
  708.  
  709. $this->sendmessage('VIUM Staff.');
  710.  
  711. $this->sendmessage('VIUM Staff.');
  712.  
  713. $this->sendmessage('VIUM Staff.');
  714.  
  715. $this->sendmessage('VIUM Staff.');
  716.  
  717. $this->sendmessage('VIUM Staff.');
  718.  
  719. $this->sendmessage('VIUM Staff.');
  720.  
  721. $this->sendmessage('VIUM Staff.');
  722.  
  723. $this->sendmessage('VIUM Staff.');
  724.  
  725. $this->sendmessage('VIUM Staff.');
  726.  
  727. $this->sendmessage('VIUM Staff.');
  728.  
  729. $this->sendmessage('VIUM Staff.');
  730.  
  731. $this->sendmessage('VIUM Staff.');
  732.  
  733.  
  734. break;
  735.  
  736.  
  737.  
  738.  
  739. case '!ownerme':
  740. $this->sendMessage('I will not owner you, Sorry just following orders.');
  741. break;
  742. case '!goto':
  743. $room = $command[1];
  744. $this->roomid = $command[1];
  745. $this->connect("174.36.242.41", "10033" );
  746. $this->join($room);
  747. break;
  748. case '!kick':
  749. function kick($message, $id) {
  750. $this->send('<c p="'.$message.'" u="'.$this->parseU($id).'" t="/k" />');
  751. }
  752. break;
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760. }
  761. }
  762. break;
  763.  
  764. }
  765. }
  766.  
  767.  
  768.  
  769.  
  770. /* ****************************************************** */
  771. /* *YOU SHOULD NOT NEED TO EDIT ANYTHING AFTER THIS LINE* */
  772. /* ****************************************************** */
  773. /**
  774. * Connects to a given ip on the given port
  775. * @param $ip The IP to connect to.
  776. * @param $port The port on the IP to connect to.
  777. */
  778. function connect($ip, $port) {
  779. if($this->soc!=null) socket_close($this->soc);
  780. $this->soc = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
  781. if(!$this->soc) die(socket_strerror(socket_last_error($this->soc)));
  782. if(!socket_connect($this->soc,$ip,$port)) die("Could not connect.");
  783. }
  784.  
  785. /**
  786. * Writes the given message to the object socket($this->soc)
  787. * @param $message The packet to send.
  788. */
  789. function send($message) {
  790. if($this->debug)echo "->>\t$message\n";
  791. socket_write($this->soc, $message."\0", strlen($message)+1);
  792. }
  793.  
  794.  
  795. /**
  796. * Reads a message from the socket, will read until entire message has been recieved or connection closes.
  797. * @param $parse Used for recursive calls to tell the function not to parse a partial packet
  798. */
  799. function read($parse=true) {
  800. $res = rtrim(socket_read($this->soc, 4096));
  801. if($this->debug)echo "<<-\t$res\n";
  802. if(!$res) {
  803. return "DIED"; //Used to gracefully handle a closed socket
  804. }
  805. if($res{strlen($res)-1}!='>') { $res.=$this->read(false);} //Recursive call for messages split over several packets.
  806. if($parse)$this->parse($res);
  807. return $res;
  808. }
  809.  
  810. /**
  811. * Parses the recieved packets into their message and types.
  812. * @param $packet The packet recieved.
  813. */
  814. function parse($packet) {
  815. if(substr_count($packet,'>')>1) $packet = explode('/>',$packet);//If necessary split the packet into individual messages
  816. foreach((Array)$packet as $p) {
  817. $p = trim($p);
  818. if(strlen($p)<5) return;//garbage data
  819. $type = trim(strtolower(substr($p,1,strpos($p.' ',' '))));//packet type
  820. $p = trim(str_replace("<$type",'',str_replace('/>','',$p)));//remove details so it is just the info to be parsed
  821. parse_str(str_replace('"','',str_replace('" ','&',str_replace('="','=',str_replace('&','__38',$p)))),$this->packet[$type]);
  822. foreach($this->packet[$type] as $k=>$v) {
  823. $this->packet[$type][$k] = str_replace('__38','&',$v); //htmlspecial chars are protected instead of being parsed
  824. }
  825. $this->handle($type,$p);
  826. }
  827. }
  828.  
  829. /**
  830. * This is the inital handler for the packets, parses them and sends them off to their respective function to be handled further.
  831. * @param $type The character code indicating the type of data within the message.
  832. * @param $message The data the message contains.
  833. */
  834. function handle($type,$msg) {
  835. switch($type) {
  836. case 'gp':
  837. if(isset($this->packet['gp']['x']))
  838. $this->send('<x i="'.$this->packet['gp']['x'].'" u="'.$this->userID.'" t="j" />'); //Handle groups
  839. break;
  840. case 'q'://XAT notice to change ip/port
  841. $this->connect($this->packet['q']['d'], $this->packet['q']['p']);
  842. $this->join($this->roomID);
  843. break;
  844. case 'o':
  845. $this->packet['o']['u'] = $this->parseU(@$this->packet['u']['u']);
  846. $this->userInfo[$this->packet['o']['u']]['name'] = @$this->packet['o']['n'];
  847. $this->userInfo[$this->packet['o']['u']]['registeredName'] = ((isset($this->packet['o']['N']))?$this->packet['o']['N']:'');
  848. $this->userInfo[$this->packet['o']['u']]['avatar'] = @$this->packet['o']['a'];
  849. $this->userInfo[$this->packet['o']['u']]['homepage'] = @$this->packet['o']['h'];
  850. $this->userInfo[$this->packet['o']['u']]['rank'] = $this->f2rank(@$this->packet['o']['f']);
  851. break;
  852. case 'u':
  853. //Joined
  854. //Default Bot stuff regarding userInformation
  855. $this->packet['u']['u'] = $this->parseU(@$this->packet['u']['u']);
  856. $this->userInfo[$this->packet['u']['u']]['name'] = @$this->packet['u']['n'];
  857. $this->userInfo[$this->packet['u']['u']]['registeredName'] = ((isset($this->packet['u']['N']))?$this->packet['u']['N']:'');
  858. $this->userInfo[$this->packet['u']['u']]['avatar'] = @$this->packet['u']['a'];
  859. $this->userInfo[$this->packet['u']['u']]['homepage'] = @$this->packet['u']['h'];
  860. $this->userInfo[$this->packet['u']['u']]['rank'] = $this->f2rank(@$this->packet['u']['f']);
  861.  
  862. $event = 'userJoined';
  863. $data['id'] = $this->packet['u']['u'];
  864. $data['old'] = ($type=='o'||(isset($this->packet['u']['s']))?true:false);
  865. $this->handleEvent($event,$data);
  866.  
  867. break;
  868. case 'l':
  869. //User Left or was , banned
  870. unset($this->userInfo[$this->packet['l']['u']]);
  871. $event = 'userLeft';
  872. $data['id'] = $this->packet['l']['u'];
  873. $this->handleEvent($event,$data);
  874.  
  875. break;
  876. case 'p':
  877. //Private message/chat recieved
  878. $event = ((isset($this->packet['p']['d']))?'privateChat':'privateMessage');
  879. $data['id'] = $this->parseU(@$this->packet['p']['u']);
  880. $data['message'] = $this->packet['p']['t'];
  881. $this->handleEvent($event,$data);
  882. break;
  883. case 'm':
  884. //message to main chat.
  885. $event = 'message';
  886. $data['id'] = $this->parseU(@$this->packet['m']['u']);
  887. $data['message'] = $this->packet['m']['t'];
  888. $data['old'] = ((isset($this->packet['m']['s']))?true:false);
  889. $this->handleEvent($event,$data);
  890. break;
  891. }
  892. }
  893.  
  894. /**
  895. * Joins a room.
  896. * @param $roomID the numeric roomID to join.
  897. */
  898. function join($roomID) {
  899. //Announce we are here:
  900. $this->send('<y m="1" />');//Anounces our arrival to the server and gets some information to send back
  901. $this->read(); //Auto parsed into $this->packet['y']
  902. $this->send('<j2 q="1" y="'.$this->packet['y']['i'].'" k="'.$this->k.'" k3="0" z="12" p="0" c="'.$roomID.'" f="0" u="'.$this->userID.'" d0="0" n="'.$this->name.'" a="'.$this->avatar.'" h="'.$this->homepage.'" v="0" />');
  903. $this->roomID = $roomID;
  904. }
  905.  
  906. /**
  907. * Parses the u value from a packet to get just the id
  908. * @param $id the id to be parsed.
  909. */
  910. function parseU($id) {
  911. if(substr_count($id,'_')>=1) $id = substr($id,0,strpos($id,'_'));
  912. return $id;
  913. }
  914.  
  915. /**
  916. * Converts an f value to a string containing the corresponding rank...this if you don't understand bitwise operations is a little 'magical' deal with it.
  917. * @param $f The f value to be parsed.
  918. */
  919. function f2rank($f) {
  920. $f = $this->parseU($f);
  921.  
  922. if($f==-1) return 'guest';
  923. //Okay, 98% of you reading this on NewHax won't know what any of this means; if you do you are more adnvanced than I expected
  924. //Not that this is advnaced stuff, but basiclly it is a bit-wise comparision(notice & instead of && it is checking if certain binary bits are set to 1
  925. //The F value is essientially a bunch of flags where for example 00010000 == banned(the 0s can be 0 or 1, just as long as that one 1 is a one you are banned.
  926. if((16 & $f)) return 'banned';
  927. if((1 & $f)&&(2 & $f)) return 'member';
  928. if((4 & $f)) return 'owner';
  929. if((32 & $f)&&(1 & $f)&&!(2 & $f)) return 'main';
  930. if(!(1 & $f)&&!(2 & $f)) return 'guest';
  931. if((16 & $f)) return 'banned';
  932. if((2 & $f)&&!(1 & $f)) return 'mod';
  933. }
  934.  
  935. /**
  936. * Returns an assoc array of information regarding the user with the given id
  937. * @param $id The user id you want information on.
  938. */
  939. function getUserArray($id) {
  940. $id = $this->parseU($id);
  941. if(isset($this->userInfo[$id])) {
  942. return $this->userInfo[$id];
  943. } else return false;
  944. }
  945.  
  946. /**
  947. * Sends the given message to the main chat
  948. * @param $message
  949. */
  950. function sendMessage($message) {
  951. if(empty($message))return;
  952. $this->send('<m t="'.$message.'" u="'.$this->userID.'" />');
  953. }
  954.  
  955. /**
  956. * Sends a PC to the given ID
  957. * @param $message The message to send.
  958. * @param $id The id to send the message to
  959. */
  960. function sendPrivateChat($message, $id) {
  961. if(empty($message))return;
  962. $this->send('<p u="'.$id.'" t="'.$message.'" s="2" d="'.$this->userID.'" />');
  963. }
  964.  
  965. /**
  966. * Sends a PM to the given ID
  967. * @param $message The message to send.
  968. * @param $id The id to send the message to
  969. */
  970. function sendPrivateMessage($message,$id) {
  971. $id = $this->parseU($id);
  972. if(empty($message))return;
  973. $this->send('<p u="'.$id.'" t="'.$message.'" />');
  974. }
  975.  
  976. /**
  977. * Makes the given $id an owner, assuming the bot is main
  978. * @param $id The id to promote
  979. */
  980. function mod($id) {
  981. $this->send('<c u="'.$this->parseU($id).'" t="/M" />');
  982. }
  983.  
  984. /**
  985. * Makes the given $id a mod, assuming the bot is owner
  986. * @param $id The id to promote
  987. */
  988. function owner($id) {
  989. $this->send('<c u="'.$this->parseU($id).'" t="/m" />');
  990. }
  991.  
  992. /**
  993. * Makes the given $id a member, assuming the bot is mod
  994. * @param $id The id to member
  995. */
  996. function member($id) {
  997. $this->send('<c u="'.$this->parseU($id).'" t="/e" />');
  998. }
  999.  
  1000.  
  1001.  
  1002.  
  1003. /**
  1004. * the given ID assuming the bot is a mod and $id is a member or less
  1005. * @param $id The id to kick */
  1006. function kick($message, $id) {
  1007. $this->send('<c p="'.$message.'" u="'.$this->parseU($id).'" t="/k" />');
  1008. }
  1009.  
  1010.  
  1011.  
  1012. /**
  1013. * Bans the ID for a given time(0 is forever)
  1014. * @param $id The id to ban
  1015. */
  1016. function ban($message, $id, $time) {
  1017. if(empty($time)) $time = 3600;
  1018. $this->send('<c p="'.$message.'" u="'.$this->parseU($id).'" t="/g'.$time.'" />');
  1019. }
  1020.  
  1021. /**
  1022. * Unbans the given ID
  1023. * @param $id The id to unban
  1024. */
  1025. function unban($id) {
  1026. $this->send('<c u="'.$this->parseU($id).'" t="/u" />');
  1027. }
  1028.  
  1029. /**
  1030. * Performs a basic HTTP GET to the given URL
  1031. * @param $url The url to retrieve, please include http:// and www if necessary
  1032. * @param $includeHeader Tells teh function wether or not to include the server header respond before the main content
  1033. */
  1034. function get($url, $includeHeader=false) {
  1035. $urlp = parse_url($url);
  1036. $fp = fsockopen($urlp['host'],80);
  1037. $path = explode('/',$url,4);
  1038. $path = ((count($path)>=4)?$path[3]:"");
  1039. $req = "GET /$path HTTP/1.1\r\n";
  1040. $req .= "Host: $urlp[host]\r\n";
  1041. $req .= "Connection: Close\r\n\r\n";
  1042. fputs($fp, $req);
  1043. $res = "";
  1044. while(!feof($fp)) $res .= fgets($fp, 4096);
  1045. fclose($fp);
  1046. if($includeHeader) return $res;
  1047. $res = explode("\r\n\r\n",$res,2);
  1048. return $res[1];
  1049. }
  1050. /**
  1051. * A utility function to get all text beween $start and $end
  1052. * @param $content The content from which we are grabbing data
  1053. * @param $start where to start grabbing from
  1054. * @param $end the end of the content to grab
  1055. */
  1056. function getBetween($content,$start,$end){
  1057. $r = explode($start, $content);
  1058. if (isset($r[1])){
  1059. $r = explode($end, $r[1]);
  1060. return $r[0];
  1061. }
  1062. return '';
  1063. }
  1064.  
  1065. }
  1066.  
  1067. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement