aimclassw.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371
  1. <?php
  2. /*
  3. * PHPTOCLIB: A library for AIM connectivity through PHP using the TOC protocal.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. /**
  21. * The version of PHPTOCLIB we are running right now
  22. *
  23. * @access private
  24. * @var int
  25. */
  26. define("PHPTOCLIB_VERSION","1.0.0 RC1");
  27. // Prevents Script from Timing Out
  28. //set_time_limit(0);
  29. // Constant Declarations
  30. /**
  31. * Maximum size for a direct connection IM in bytes
  32. *
  33. * @access private
  34. * @var int
  35. */
  36. define("MAX_DIM_SIZE",3072); //Default to 3kb
  37. /**
  38. * Internally used for message type
  39. *
  40. * @access private
  41. * @var int
  42. */
  43. define("AIM_TYPE_WARN",74);
  44. /**
  45. * Internally used for message type
  46. *
  47. * @access private
  48. * @var int
  49. */
  50. define("AIM_TYPE_MSG",75);
  51. /**
  52. * Internally used for message type
  53. *
  54. * @access private
  55. * @var int
  56. */
  57. define("AIM_TYPE_UPDATEBUDDY",76);
  58. /**
  59. * Internally used for message type
  60. *
  61. * @access private
  62. * @var int
  63. */
  64. define("AIM_TYPE_SIGNON",77);
  65. /**
  66. * Internally used for message type
  67. *
  68. * @access private
  69. * @var int
  70. */
  71. define("AIM_TYPE_NICK",78);
  72. /**
  73. * Internally used for message type
  74. *
  75. * @access private
  76. * @var int
  77. */
  78. define("AIM_TYPE_ERROR",79);
  79. /**
  80. * Internally used for message type
  81. *
  82. * @access private
  83. * @var int
  84. */
  85. define("AIM_TYPE_CHATJ",80);
  86. /**
  87. * Internally used for message type
  88. *
  89. * @access private
  90. * @var int
  91. */
  92. define("AIM_TYPE_CHATI",81);
  93. /**
  94. * Internally used for message type
  95. *
  96. * @access private
  97. * @var int
  98. */
  99. define("AIM_TYPE_CHATUPDBUD",82);
  100. /**
  101. * Internally used for message type
  102. *
  103. * @access private
  104. * @var int
  105. */
  106. define("AIM_TYPE_CHATINV",83);
  107. /**
  108. * Internally used for message type
  109. *
  110. * @access private
  111. * @var int
  112. */
  113. define("AIM_TYPE_CHATLE",84);
  114. /**
  115. * Internally used for message type
  116. *
  117. * @access private
  118. * @var int
  119. */
  120. define("AIM_TYPE_URL",85);
  121. /**
  122. * Internally used for message type
  123. *
  124. * @access private
  125. * @var int
  126. */
  127. define("AIM_TYPE_NICKSTAT",86);
  128. /**
  129. * Internally used for message type
  130. *
  131. * @access private
  132. * @var int
  133. */
  134. define("AIM_TYPE_PASSSTAT",87);
  135. /**
  136. * Internally used for message type
  137. *
  138. * @access private
  139. * @var int
  140. */
  141. define("AIM_TYPE_RVOUSP",88);
  142. /**
  143. * Internally used for message type
  144. *
  145. * @access private
  146. * @var int
  147. */
  148. define("AIM_TYPE_NOT_IMPLEMENTED",666);
  149. /**
  150. * Internally used for connection type
  151. *
  152. * Internal type for a normal connection
  153. *
  154. * @access private
  155. * @var int
  156. */
  157. define("CONN_TYPE_NORMAL",1);
  158. /**
  159. * Internally used for connection type
  160. *
  161. * Internal type of a Dirct Connection
  162. *
  163. * @access private
  164. * @var int
  165. */
  166. define("CONN_TYPE_DC",2);
  167. /**
  168. * Internally used for connection type
  169. *
  170. *Internal type for a file transfer connection
  171. *
  172. * @access private
  173. * @var int
  174. */
  175. define("CONN_TYPE_FT",3);
  176. /**
  177. * Internally used for connection type
  178. *
  179. *Internal type for a file get connection
  180. *
  181. * @access private
  182. * @var int
  183. */
  184. define("CONN_TYPE_FTG",4);
  185. /**
  186. * Maximum size for a TOC packet
  187. *
  188. * @access private
  189. * @var int
  190. */
  191. define("MAX_PACKLENGTH",2048);
  192. /**
  193. * TOC packet type
  194. *
  195. * @access private
  196. * @var int
  197. */
  198. define("SFLAP_TYPE_SIGNON",1);
  199. /**
  200. * TOC packet type
  201. *
  202. * @access private
  203. * @var int
  204. */
  205. define("SFLAP_TYPE_DATA",2);
  206. /**
  207. * TOC packet type
  208. *
  209. * @access private
  210. * @var int
  211. */
  212. define("SFLAP_TYPE_ERROR",3);
  213. /**
  214. * TOC packet type
  215. *
  216. * @access private
  217. * @var int
  218. */
  219. define("SFLAP_TYPE_SIGNOFF",4);
  220. /**
  221. * TOC packet type
  222. *
  223. * @access private
  224. * @var int
  225. */
  226. define("SFLAP_TYPE_KEEPALIVE",5);
  227. /**
  228. * TOC packet type
  229. *
  230. * @access private
  231. * @var int
  232. */
  233. define("SFLAP_MAX_LENGTH",1024);
  234. /**
  235. * Service UID for a voice connection
  236. *
  237. * @access private
  238. * @var int
  239. */
  240. define('VOICE_UID', '09461341-4C7F-11D1-8222-444553540000');
  241. /**
  242. * Service UID for file sending
  243. *
  244. * @access private
  245. * @var int
  246. */
  247. define('FILE_SEND_UID', '09461343-4C7F-11D1-8222-444553540000');
  248. /**
  249. * Service UID for file getting
  250. *
  251. * @access private
  252. * @var int
  253. */
  254. define('FILE_GET_UID', '09461348-4C7F-11D1-8222-444553540000');
  255. /**
  256. * Service UID for Direct connections
  257. *
  258. * @access private
  259. * @var int
  260. */
  261. define('IMAGE_UID', '09461345-4C7F-11D1-8222-444553540000');
  262. /**
  263. * Service UID for Buddy Icons
  264. *
  265. * @access private
  266. * @var int
  267. */
  268. define('BUDDY_ICON_UID', '09461346-4C7F-11D1-8222-444553540000');
  269. /**
  270. * Service UID for stocks
  271. *
  272. * @access private
  273. * @var int
  274. */
  275. define('STOCKS_UID', '09461347-4C7F-11D1-8222-444553540000');
  276. /**
  277. * Service UID for games
  278. *
  279. * @access private
  280. * @var int
  281. */
  282. define('GAMES_UID', '0946134a-4C7F-11D1-8222-444553540000');
  283. /**
  284. * FLAP return code
  285. *
  286. * @access private
  287. * @var int
  288. */
  289. define("SFLAP_SUCCESS",0);
  290. /**
  291. * FLAP return code
  292. *
  293. * @access private
  294. * @var int
  295. */
  296. define("SFLAP_ERR_UNKNOWN",1);
  297. /**
  298. * FLAP return code
  299. *
  300. * @access private
  301. * @var int
  302. */
  303. define("SFLAP_ERR_ARGS",2);
  304. /**
  305. * FLAP return code
  306. *
  307. * @access private
  308. * @var int
  309. */
  310. define("SFLAP_ERR_LENGTH",3);
  311. /**
  312. * FLAP return code
  313. *
  314. * @access private
  315. * @var int
  316. */
  317. define("SFLAP_ERR_READ",4);
  318. /**
  319. * FLAP return code
  320. *
  321. * @access private
  322. * @var int
  323. */
  324. define("SFLAP_ERR_SEND",5);
  325. /**
  326. * FLAP version number
  327. *
  328. * @access private
  329. * @var int
  330. */
  331. define("SFLAP_FLAP_VERSION",1);
  332. /**
  333. * FLAP TLV code
  334. *
  335. * @access private
  336. * @var int
  337. */
  338. define("SFLAP_TLV_TAG",1);
  339. /**
  340. * Bytes in a FLAP header
  341. *
  342. * @access private
  343. * @var int
  344. */
  345. define("SFLAP_HEADER_LEN",6);
  346. /**
  347. * PHPTocLib AIM Class
  348. *
  349. * @author Jeremy Bryant <pickleman78@users.sourceforge.net>
  350. * @author Rajiv Makhijani <rajiv@blue-tech.org>
  351. * @package phptoclib
  352. * @version 1.0RC1
  353. * @copyright 2005
  354. * @access public
  355. *
  356. */
  357. class Aim
  358. {
  359. /**
  360. * AIM ScreenName
  361. *
  362. * @var String
  363. * @access private
  364. */
  365. var $myScreenName;
  366. /**
  367. * AIM Password (Plain Text)
  368. *
  369. * @var String
  370. * @access private
  371. */
  372. var $myPassword;
  373. /**
  374. * AIM TOC Server
  375. *
  376. * @var String
  377. * @access public
  378. */
  379. var $myServer="toc.oscar.aol.com";
  380. /**
  381. * AIM Formatted ScreenName
  382. *
  383. * @var String
  384. * @access private
  385. */
  386. var $myFormatSN;
  387. /**
  388. * AIM TOC Server Port
  389. *
  390. * @var String
  391. * @access public
  392. */
  393. var $myPort="5190";
  394. /**
  395. * Profile Data
  396. * Use setProfile() to update
  397. *
  398. * @var String
  399. * @access private
  400. */
  401. var $myProfile="Powered by phpTOCLib. Please visit http://sourceforge.net/projects/phptoclib for more information"; //The profile of the bot
  402. /**
  403. * Socket Connection Resource ID
  404. *
  405. * @var Resource
  406. * @access private
  407. */
  408. var $myConnection; //Connection resource ID
  409. /**
  410. * Roasted AIM Password
  411. *
  412. * @var String
  413. * @access private
  414. */
  415. var $myRoastedPass;
  416. /**
  417. * Last Message Recieved From Server
  418. *
  419. * @var String
  420. * @access private
  421. */
  422. var $myLastReceived;
  423. /**
  424. * Current Seq Number Used to Communicate with Server
  425. *
  426. * @var Integer
  427. * @access private
  428. */
  429. var $mySeqNum;
  430. /**
  431. * Current Warning Level
  432. * Getter: getWarning()
  433. * Setter: setWarning()
  434. *
  435. * @var Integer
  436. * @access private
  437. */
  438. var $myWarnLevel; //Warning Level of the bot
  439. /**
  440. * Auth Code
  441. *
  442. * @var Integer
  443. * @access private
  444. */
  445. var $myAuthCode;
  446. /**
  447. * Buddies
  448. * Getter: getBuddies()
  449. *
  450. * @var Array
  451. * @access private
  452. */
  453. var $myBuddyList;
  454. /**
  455. * Blocked Buddies
  456. * Getter: getBlocked()
  457. *
  458. * @var Array
  459. * @access private
  460. */
  461. var $myBlockedList;
  462. /**
  463. * Permited Buddies
  464. * Getter: getBlocked()
  465. *
  466. * @var Array
  467. * @access private
  468. */
  469. var $myPermitList;
  470. /**
  471. * Permit/Deny Mode
  472. * 1 - Allow All
  473. * 2 - Deny All
  474. * 3 - Permit only those on your permit list
  475. * 4 - Permit all those not on your deny list
  476. *
  477. * @var Integer
  478. * @access private
  479. */
  480. var $myPdMode;
  481. //Below variables added 4-29 by Jeremy: Implementing chat
  482. /**
  483. * Contains Chat Room Info
  484. * $myChatRooms['roomid'] = people in room
  485. *
  486. * @var Array
  487. * @access private
  488. */
  489. var $myChatRooms;
  490. //End of chat implementation
  491. /**
  492. * Event Handler Functions
  493. *
  494. * @var Array
  495. * @access private
  496. */
  497. var $myEventHandlers = array();
  498. /**
  499. * Array of direct connection objects(including file transfers)
  500. *
  501. * @var Array
  502. * @access private
  503. */
  504. var $myDirectConnections = array();
  505. /**
  506. * Array of the actual connections
  507. *
  508. * @var Array
  509. * @access private
  510. */
  511. var $myConnections = array();
  512. /**
  513. * The current state of logging
  514. *
  515. * @var Boolean
  516. * @access private
  517. */
  518. var $myLogging = false;
  519. /**
  520. * Constructor
  521. *
  522. * Permit/Deny Mode Options
  523. * 1 - Allow All
  524. * 2 - Deny All
  525. * 3 - Permit only those on your permit list
  526. * 4 - Permit all those not on your deny list
  527. *
  528. * @param String $sn AIM Screenname
  529. * @param String $password AIM Password
  530. * @param Integer $pdmode Permit/Deny Mode
  531. * @access public
  532. */
  533. function Aim($sn, $password, $pdmode)
  534. {
  535. //Constructor assignment
  536. $this->myScreenName = $this->normalize($sn);
  537. $this->myPassword = $password;
  538. $this->myRoastedPass = $this->roastPass($password);
  539. $this->mySeqNum = 1;
  540. $this->myConnection = 0;
  541. $this->myWarnLevel = 0;
  542. $this->myAuthCode = $this->makeCode();
  543. $this->myPdMode = $pdmode;
  544. $this->myFormatSN = $this->myScreenName;
  545. $this->log("PHPTOCLIB v" . PHPTOCLIB_VERSION . " Object Created");
  546. }
  547. /**
  548. * Enables debug logging (Logging is disabled by default)
  549. *
  550. *
  551. * @access public
  552. * @return void
  553. */
  554. function setLogging($enable)
  555. {
  556. $this->myLogging=$enable;
  557. }
  558. function log($data)
  559. {
  560. if($this->myLogging){
  561. error_log($data);
  562. }
  563. }
  564. /**
  565. * Logs a packet
  566. *
  567. *
  568. * @access private
  569. * @param Array $packary Packet
  570. * @param String $in Prepend
  571. * @return void
  572. */
  573. function logPacket($packary,$in)
  574. {
  575. if(!$this->myLogging || sizeof($packary)<=0 || (@strlen($packary['decoded'])<=0 && @isset($packary['decoded'])))
  576. return;
  577. $towrite=$in . ": ";
  578. foreach($packary as $k=>$d)
  579. {
  580. $towrite.=$k . ":" . $d . "\r\n";
  581. }
  582. $towrite.="\r\n\r\n";
  583. $this->log($towrite);
  584. }
  585. /**
  586. * Roasts/Hashes Password
  587. *
  588. * @param String $password Password
  589. * @access private
  590. * @return String Roasted Password
  591. */
  592. function roastPass($password)
  593. {
  594. $roaststring = 'Tic/Toc';
  595. $roasted_password = '0x';
  596. for ($i = 0; $i < strlen($password); $i++)
  597. $roasted_password .= bin2hex($password[$i] ^ $roaststring[($i % 7)]);
  598. return $roasted_password;
  599. }
  600. /**
  601. * Access Method for myScreenName
  602. *
  603. * @access public
  604. * @param $formated Returns formatted Screenname if true as returned by server
  605. * @return String Screenname
  606. */
  607. function getMyScreenName($formated = false)
  608. {
  609. if ($formated)
  610. {
  611. return $this->myFormatSN;
  612. }
  613. else
  614. {
  615. return $this->normalize($this->myScreenName);
  616. }
  617. }
  618. /**
  619. * Generated Authorization Code
  620. *
  621. * @access private
  622. * @return Integer Auth Code
  623. */
  624. function makeCode()
  625. {
  626. $sn = ord($this->myScreenName[0]) - 96;
  627. $pw = ord($this->myPassword[0]) - 96;
  628. $a = $sn * 7696 + 738816;
  629. $b = $sn * 746512;
  630. $c = $pw * $a;
  631. return $c - $a + $b + 71665152;
  632. }
  633. /**
  634. * Reads from Socket
  635. *
  636. * @access private
  637. * @return String Data
  638. */
  639. function sflapRead()
  640. {
  641. if ($this->socketcheck($this->myConnection))
  642. {
  643. $this->log("Disconnected.... Reconnecting in 60 seconds");
  644. sleep(60);
  645. $this->signon();
  646. }
  647. $header = fread($this->myConnection,SFLAP_HEADER_LEN);
  648. if (strlen($header) == 0)
  649. {
  650. $this->myLastReceived = "";
  651. return "";
  652. }
  653. $header_data = unpack("aast/Ctype/nseq/ndlen", $header);
  654. $this->log(" . ", false);
  655. $packet = fread($this->myConnection, $header_data['dlen']);
  656. if (strlen($packet) <= 0 && $sockinfo['blocked'])
  657. $this->derror("Could not read data");
  658. if ($header_data['type'] == SFLAP_TYPE_SIGNON)
  659. {
  660. $packet_data=unpack("Ndecoded", $packet);
  661. }
  662. if ($header_data['type'] == SFLAP_TYPE_KEEPALIVE)
  663. {
  664. $this->myLastReceived = '';
  665. return 0;
  666. }
  667. else if (strlen($packet)>0)
  668. {
  669. $packet_data = unpack("a*decoded", $packet);
  670. }
  671. $this->log("socketcheck check now");
  672. if ($this->socketcheck($this->myConnection))
  673. {
  674. $this->derror("Connection ended unexpectedly");
  675. }
  676. $data = array_merge($header_data, $packet_data);
  677. $this->myLastReceived = $data;
  678. $this->logPacket($data,"in");
  679. return $data;
  680. }
  681. /**
  682. * Sends Data on Socket
  683. *
  684. * @param String $sflap_type Type
  685. * @param String $sflap_data Data
  686. * @param boolean $no_null No Null
  687. * @param boolean $formatted Format
  688. * @access private
  689. * @return String Roasted Password
  690. */
  691. function sflapSend($sflap_type, $sflap_data, $no_null, $formatted)
  692. {
  693. $packet = "";
  694. if (strlen($sflap_data) >= MAX_PACKLENGTH)
  695. $sflap_data = substr($sflap_data,0,MAX_PACKLENGTH);
  696. if ($formatted)
  697. {
  698. $len = strlen($sflap_len);
  699. $sflap_header = pack("aCnn",'*', $sflap_type, $this->mySeqNum, $len);
  700. $packet = $sflap_header . $sflap_data;
  701. } else {
  702. if (!$no_null)
  703. {
  704. $sflap_data = str_replace("\0","", trim($sflap_data));
  705. $sflap_data .= "\0";
  706. }
  707. $data = pack("a*", $sflap_data);
  708. $len = strlen($sflap_data);
  709. $header = pack("aCnn","*", $sflap_type, $this->mySeqNum, $len);
  710. $packet = $header . $data;
  711. }
  712. //Make sure we are still connected
  713. if ($this->socketcheck($this->myConnection))
  714. {
  715. $this->log("Disconnected.... reconnecting in 60 seconds");
  716. sleep(60);
  717. $this->signon();
  718. }
  719. $sent = fputs($this->myConnection, $packet) or $this->derror("Error sending packet to AIM");
  720. $this->mySeqNum++;
  721. sleep(ceil($this->myWarnLevel/10));
  722. $this->logPacket(array($sflap_type,$sflap_data),"out");
  723. }
  724. /**
  725. * Escape the thing that TOC doesn't like,that would be
  726. * ",', $,{,},[,]
  727. *
  728. * @param String $data Data to Escape
  729. * @see decodeData
  730. * @access private
  731. * @return String $data Escaped Data
  732. */
  733. function encodeData($data)
  734. {
  735. $data = str_replace('"','\"', $data);
  736. $data = str_replace('$','\$', $data);
  737. $data = str_replace("'","\'", $data);
  738. $data = str_replace('{','\{', $data);
  739. $data = str_replace('}','\}', $data);
  740. $data = str_replace('[','\[', $data);
  741. $data = str_replace(']','\]', $data);
  742. return $data;
  743. }
  744. /**
  745. * Unescape data TOC has escaped
  746. * ",', $,{,},[,]
  747. *
  748. * @param String $data Data to Unescape
  749. * @see encodeData
  750. * @access private
  751. * @return String $data Unescape Data
  752. */
  753. function decodeData($data)
  754. {
  755. $data = str_replace('\"','"', $data);
  756. $data = str_replace('\$','$', $data);
  757. $data = str_replace("\'","'", $data);
  758. $data = str_replace('\{','{', $data);
  759. $data = str_replace('\}','}', $data);
  760. $data = str_replace('\[','[', $data);
  761. $data = str_replace('\]',']', $data);
  762. $data = str_replace('&quot;','"', $data);
  763. $data = str_replace('&amp;','&', $data);
  764. return $data;
  765. }
  766. /**
  767. * Normalize ScreenName
  768. * no spaces and all lowercase
  769. *
  770. * @param String $nick ScreenName
  771. * @access public
  772. * @return String $nick Normalized ScreenName
  773. */
  774. function normalize($nick)
  775. {
  776. $nick = str_replace(" ","", $nick);
  777. $nick = strtolower($nick);
  778. return $nick;
  779. }
  780. /**
  781. * Sets internal info with update buddy
  782. * Currently only sets warning level
  783. *
  784. * @access public
  785. * @return void
  786. */
  787. function setMyInfo()
  788. {
  789. //Sets internal values bvase on the update buddy command
  790. $this->log("Setting my warning level ...");
  791. $this->sflapSend(SFLAP_TYPE_DATA,"toc_get_status " . $this->normalize($this->myScreenName),0,0);
  792. //The rest of this will now be handled by the other functions. It is assumed
  793. //that we may have other data queued in the socket, do we should just add this
  794. //message to the queue instead of trying to set it in here
  795. }
  796. /**
  797. * Connects to AIM and Signs On Using Info Provided in Constructor
  798. *
  799. * @access public
  800. * @return void
  801. */
  802. function signon()
  803. {
  804. $this->log("Ready to sign on to the server");
  805. $this->myConnection = fsockopen($this->myServer, $this->myPort, $errno, $errstr,10) or die("$errorno:$errstr");
  806. $this->log("Connected to server");
  807. $this->mySeqNum = (time() % 65536); //Select an arbitrary starting point for
  808. //sequence numbers
  809. if (!$this->myConnection)
  810. $this->derror("Error connecting to toc.oscar.aol.com");
  811. $this->log("Connected to AOL");
  812. //Send the flapon packet
  813. fputs($this->myConnection,"FLAPON\r\n\n\0"); //send the initial handshake
  814. $this->log("Sent flapon");
  815. $this->sflapRead(); //Make sure the server responds with what we expect
  816. if (!$this->myLastReceived)
  817. $this->derror("Error sending the initialization string");
  818. //send the FLAP SIGNON packet back with what it needs
  819. //There are 2 parts to the signon packet. They are sent in succession, there
  820. //is no indication if either packet was correctly sent
  821. $signon_packet = pack("Nnna".strlen($this->myScreenName),1,1,strlen($this->myScreenName), $this->myScreenName);
  822. $this->sflapSend(SFLAP_TYPE_SIGNON, $signon_packet,1,0);
  823. $this->log("sent signon packet part one");
  824. $signon_packet_part2 = 'toc2_signon login.oscar.aol.com 29999 ' . $this->myScreenName . ' ' . $this->myRoastedPass . ' english-US "TIC:TOC2:REVISION" 160 ' . $this->myAuthCode;
  825. $this->log($signon_packet_part2 . "");
  826. $this->sflapSend(SFLAP_TYPE_DATA, $signon_packet_part2,0,0);
  827. $this->log("Sent signon packet part 2... Awaiting response...");
  828. $this->sflapRead();
  829. $this->log("Received Sign on packet, beginning initilization...");
  830. $message = $this->getLastReceived();
  831. $this->log($message . "\n");
  832. if (strstr($message,"ERROR:"))
  833. {
  834. $this->onError($message);
  835. die("Fatal signon error");
  836. }
  837. stream_set_timeout($this->myConnection,2);
  838. //The information sent before the config2 command is utterly useless to us
  839. //So we will just skim through them until we reach it
  840. //Add the first entry to the connection array
  841. $this->myConnections[] = $this->myConnection;
  842. //UPDATED 4/12/03: Now this will use the receive function and send the
  843. //received messaged to the assigned handlers. This is where the signon
  844. //method has no more use
  845. $this->log("Done with signon proccess");
  846. //socket_set_blocking($this->myConnection,false);
  847. }
  848. /**
  849. * Sends Instant Message
  850. *
  851. * @param String $to Message Recipient SN
  852. * @param String $message Message to Send
  853. * @param boolean $auto Sent as Auto Response / Away Message Style
  854. * @access public
  855. * @return void
  856. */
  857. function sendIM($to, $message, $auto = false)
  858. {
  859. if ($auto) $auto = "auto";
  860. else $auto = "";
  861. $to = $this->normalize($to);
  862. $message = $this->encodeData($message);
  863. $command = 'toc2_send_im "' . $to . '" "' . $message . '" ' . $auto;
  864. $this->sflapSend(SFLAP_TYPE_DATA, trim($command),0,0);
  865. $cleanedmessage = str_replace("<br>", " ", $this->decodeData($message));
  866. $cleanedmessage = strip_tags($cleanedmessage);
  867. $this->log("TO - " . $to . " : " . $cleanedmessage);
  868. }
  869. /**
  870. * Set Away Message
  871. *
  872. * @param String $message Away message (some HTML supported).
  873. * Use null to remove the away message
  874. * @access public
  875. * @return void
  876. */
  877. function setAway($message)
  878. {
  879. $message = $this->encodeData($message);
  880. $command = 'toc_set_away "' . $message . '"';
  881. $this->sflapSend(SFLAP_TYPE_DATA, trim($command),0,0);
  882. $this->log("SET AWAY MESSAGE - " . $this->decodeData($message));
  883. }
  884. /**
  885. * Fills Buddy List
  886. * Not implemented fully yet
  887. *
  888. * @access public
  889. * @return void
  890. */
  891. function setBuddyList()
  892. {
  893. //This better be the right message
  894. $message = $this->myLastReceived['decoded'];
  895. if (strpos($message,"CONFIG2:") === false)
  896. {
  897. $this->log("setBuddyList cannot be called at this time because I got $message");
  898. return false;
  899. }
  900. $people = explode("\n",trim($message,"\n"));
  901. //The first 3 elements of the array are who knows what, element 3 should be
  902. //a letter followed by a person
  903. for($i = 1; $i<sizeof($people); $i++)
  904. {
  905. @list($mode, $name) = explode(":", $people[$i]);
  906. switch($mode)
  907. {
  908. case 'p':
  909. $this->myPermitList[] = $name;
  910. break;
  911. case 'd':
  912. $this->myBlockedList[] = $name;
  913. break;
  914. case 'b':
  915. $this->myBuddyList[] = $name;
  916. break;
  917. case 'done':
  918. break;
  919. default:
  920. //
  921. }
  922. }
  923. }
  924. /**
  925. * Adds buddy to Permit list
  926. *
  927. * @param String $buddy Buddy's Screenname
  928. * @access public
  929. * @return void
  930. */
  931. function addPermit($buddy)
  932. {
  933. $this->sflapSend(SFLAP_TYPE_DATA,"toc2_add_permit " . $this->normalize($buddy),0,0);
  934. $this->myPermitList[] = $this->normalize($buddy);
  935. return 1;
  936. }
  937. /**
  938. * Blocks buddy
  939. *
  940. * @param String $buddy Buddy's Screenname
  941. * @access public
  942. * @return void
  943. */
  944. function blockBuddy($buddy)
  945. {
  946. $this->sflapSend(SFLAP_TYPE_DATA,"toc2_add_deny " . $this->normalize($buddy),0,0);
  947. $this->myBlockedList[] = $this->normalize($buddy);
  948. return 1;
  949. }
  950. /**
  951. * Returns last message received from server
  952. *
  953. * @access private
  954. * @return String Last Message from Server
  955. */
  956. function getLastReceived()
  957. {
  958. if (@$instuff = $this->myLastReceived['decoded']){
  959. return $this->myLastReceived['decoded'];
  960. }else{
  961. return;
  962. }
  963. }
  964. /**
  965. * Returns Buddy List
  966. *
  967. * @access public
  968. * @return array Buddy List
  969. */
  970. function getBuddies()
  971. {
  972. return $this->myBuddyList;
  973. }
  974. /**
  975. * Returns Permit List
  976. *
  977. * @access public
  978. * @return array Permit List
  979. */
  980. function getPermit()
  981. {
  982. return $this->myPermitList;
  983. }
  984. /**
  985. * Returns Blocked Buddies
  986. *
  987. * @access public
  988. * @return array Blocked List
  989. */
  990. function getBlocked()
  991. {
  992. return $this->myBlockedList;
  993. }
  994. /**
  995. * Reads and returns data from server
  996. *
  997. * This is a wrapper for $Aim->sflap_read(), and only returns the $this->myLastReceived['data']
  998. * portion of the message. It is preferred that you do not call $Aim->sflap_read() and use this
  999. * function instead. This function has a return value. Calling this prevents the need to call
  1000. * $Aim->getLastReceived()
  1001. *
  1002. * @access public
  1003. * @return String Data recieved from server
  1004. */
  1005. function read_from_aim()
  1006. {
  1007. $this->sflapRead();
  1008. $returnme = $this->getLastReceived();
  1009. return $returnme;
  1010. }
  1011. /**
  1012. * Sets current internal warning level
  1013. *
  1014. * This allows you to update the bots warning level when warned.
  1015. *
  1016. * @param int Warning Level %
  1017. * @access private
  1018. * @return void
  1019. */
  1020. function setWarningLevel($warnlevel)
  1021. {
  1022. $this->myWarnLevel = $warnlevel;
  1023. }
  1024. /**
  1025. * Warns / "Evils" a User
  1026. *
  1027. * To successfully warn another user they must have sent you a message.
  1028. * There is a limit on how much and how often you can warn another user.
  1029. * Normally when you warn another user they are aware who warned them,
  1030. * however there is the option to warn anonymously. When warning anon.
  1031. * note that the warning is less severe.
  1032. *
  1033. * @param String $to Screenname to warn
  1034. * @param boolean $anon Warn's anonymously if true. (default = false)
  1035. * @access public
  1036. * @return void
  1037. */
  1038. function warnUser($to, $anon = false)
  1039. {
  1040. if (!$anon)
  1041. $anon = '"norm"';
  1042. else
  1043. $anon = '"anon"';
  1044. $this->sflapSend(SFLAP_TYPE_DATA,"toc_evil " . $this->normalize($to) . " $anon",0,0);
  1045. }
  1046. /**
  1047. * Returns warning level of bot
  1048. *
  1049. * @access public
  1050. * @return void
  1051. */
  1052. function getWarningLevel()
  1053. {
  1054. return $this->myWarningLevel;
  1055. }
  1056. /**
  1057. * Sets bot's profile/info
  1058. *
  1059. * Limited to 1024 bytes.
  1060. *
  1061. * @param String $profiledata Profile Data (Can contain limited html: br,hr,font,b,i,u etc)
  1062. * @param boolean $poweredby If true, appends link to phpTOCLib project to profile
  1063. * @access public
  1064. * @return void
  1065. */
  1066. function setProfile($profiledata, $poweredby = false)
  1067. {
  1068. if ($poweredby == false){
  1069. $this->myProfile = $profiledata;
  1070. }else{
  1071. $this->myProfile = $profiledata . "<font size=1 face=tahoma><br><br>Powered by phpTOCLib<br>http://sourceforge.net/projects/phptoclib</font>";
  1072. }
  1073. $this->sflapSend(SFLAP_TYPE_DATA,"toc_set_info \"" . $this->encodeData($this->myProfile) . "\"",0,0);
  1074. $this->setMyInfo();
  1075. $this->log("Profile has been updated...");
  1076. }
  1077. //6/29/04 by Jeremy:
  1078. //Added mthod to accept a rvous,decline it, and
  1079. //read from the rvous socket
  1080. //Decline
  1081. /**
  1082. * Declines a direct connection request (rvous)
  1083. *
  1084. * @param String $nick ScreenName request was from
  1085. * @param String $cookie Request cookie (from server)
  1086. * @param String $uuid UUID
  1087. *
  1088. * @access public
  1089. * @return void
  1090. */
  1091. function declineRvous($nick, $cookie, $uuid)
  1092. {
  1093. $nick = $this->normalize($nick);
  1094. $this->sflapSend(SFLAP_TYPE_DATA,"toc_rvous_cancel $nick $cookie $uuid",0,0);
  1095. }
  1096. /**
  1097. * Accepts a direct connection request (rvous)
  1098. *
  1099. * @param String $nick ScreenName request was from
  1100. * @param String $cookie Request cookie (from server)
  1101. * @param String $uuid UUID
  1102. * @param String $vip IP of User DC with
  1103. * @param int $port Port number to connect to
  1104. *
  1105. * @access public
  1106. * @return void
  1107. */
  1108. function acceptRvous($nick, $cookie, $uuid, $vip, $port)
  1109. {
  1110. $this->sflapSend(SFLAP_TYPE_DATA,"toc_rvous_accept $nick $cookie $uuid",0,0);
  1111. //Now open the connection to that user
  1112. if ($uuid == IMAGE_UID)
  1113. {
  1114. $dcon = new Dconnect($vip, $port);
  1115. }
  1116. else if ($uuid == FILE_SEND_UID)
  1117. {
  1118. $dcon = new FileSendConnect($vip, $port);
  1119. }
  1120. if (!$dcon->connected)
  1121. {
  1122. $this->log("The connection failed");
  1123. return false;
  1124. }
  1125. //Place this dcon object inside the array
  1126. $this->myDirectConnections[] = $dcon;
  1127. //Place the socket in an array to
  1128. $this->myConnections[] = $dcon->sock;
  1129. //Get rid of the first packet because its worthless
  1130. //and confusing
  1131. $dcon->readDIM();
  1132. //Assign the cookie
  1133. $dcon->cookie = $dcon->lastReceived['cookie'];
  1134. $dcon->connectedTo = $this->normalize($nick);
  1135. return $dcon;
  1136. }
  1137. /**
  1138. * Sends a Message over a Direct Connection
  1139. *
  1140. * Only works if a direct connection is already established with user
  1141. *
  1142. * @param String $to Message Recipient SN
  1143. * @param String $message Message to Send
  1144. *
  1145. * @access public
  1146. * @return void
  1147. */
  1148. function sendDim($to, $message)
  1149. {
  1150. //Find the connection
  1151. for($i = 0;$i<sizeof($this->myDirectConnections);$i++)
  1152. {
  1153. if ($this->normalize($to) == $this->myDirectConnections[$i]->connectedTo && $this->myDirectConnections[$i]->type == CONN_TYPE_DC)
  1154. {
  1155. $dcon = $this->myDirectConnections[$i];
  1156. break;
  1157. }
  1158. }
  1159. if (!$dcon)
  1160. {
  1161. $this->log("Could not find a direct connection to $to");
  1162. return false;
  1163. }
  1164. $dcon->sendMessage($message, $this->normalize($this->myScreenName));
  1165. return true;
  1166. }
  1167. /**
  1168. * Closes an established Direct Connection
  1169. *
  1170. * @param DConnect $dcon Direct Connection Object to Close
  1171. *
  1172. * @access public
  1173. * @return void
  1174. */
  1175. function closeDcon($dcon)
  1176. {
  1177. $nary = array();
  1178. for($i = 0;$i<sizeof($this->myConnections);$i++)
  1179. {
  1180. if ($dcon->sock == $this->myConnections[$i])
  1181. unset($this->myConnections[$i]);
  1182. }
  1183. $this->myConnections = array_values($this->myConnections);
  1184. unset($nary);
  1185. $nary2 = array();
  1186. for($i = 0;$i<sizeof($this->myDirectConnections);$i++)
  1187. {
  1188. if ($dcon == $this->myDirectConnections[$i])
  1189. unset($this->myDirectConnections[$i]);
  1190. }
  1191. $this->myDirectConnections = array_values($this->myDirectConnections);
  1192. $dcon->close();
  1193. unset($dcon);
  1194. }
  1195. //Added 4/29/04 by Jeremy:
  1196. //Various chat related methods
  1197. /**
  1198. * Accepts a Chat Room Invitation (Joins room)
  1199. *
  1200. * @param String $chatid ID of Chat Room
  1201. *
  1202. * @access public
  1203. * @return void
  1204. */
  1205. function joinChat($chatid)
  1206. {
  1207. $this->sflapSend(SFLAP_TYPE_DATA,"toc_chat_accept " . $chatid,0,0);
  1208. }
  1209. /**
  1210. * Leaves a chat room
  1211. *
  1212. * @param String $chatid ID of Chat Room
  1213. *
  1214. * @access public
  1215. * @return void
  1216. */
  1217. function leaveChat($chatid)
  1218. {
  1219. $this->sflapSend(SFLAP_TYPE_DATA,"toc_chat_leave " . $chatid,0,0);
  1220. }
  1221. /**
  1222. * Sends a message in a chat room
  1223. *
  1224. * @param String $chatid ID of Chat Room
  1225. * @param String $message Message to send
  1226. *
  1227. * @access public
  1228. * @return void
  1229. */
  1230. function chatSay($chatid, $message)
  1231. {
  1232. $this->sflapSend(SFLAP_TYPE_DATA,"toc_chat_send " . $chatid . " \"" . $this->encodeData($message) . "\"",0,0);
  1233. }
  1234. /**
  1235. * Invites a user to a chat room
  1236. *
  1237. * @param String $chatid ID of Chat Room
  1238. * @param String $who Screenname of user
  1239. * @param String $message Note to include with invitiation
  1240. *
  1241. * @access public
  1242. * @return void
  1243. */
  1244. function chatInvite($chatid, $who, $message)
  1245. {
  1246. $who = $this->normalize($who);
  1247. $this->sflapSend(SFLAP_TYPE_DATA,"toc_chat_invite " . $chatid . " \"" . $this->encodeData($message) . "\" " . $who,0,0);
  1248. }
  1249. /**
  1250. * Joins/Creates a new chat room
  1251. *
  1252. * @param String $name Name of the new chat room
  1253. * @param String $exchange Exchange of new chat room
  1254. *
  1255. * @access public
  1256. * @return void
  1257. */
  1258. function joinNewChat($name, $exchange)
  1259. {
  1260. //Creates a new chat
  1261. $this->sflapSend(SFLAP_TYPE_DATA,"toc_chat_join " . $exchange . " \"" . $name . "\"",0,0);
  1262. }
  1263. /**
  1264. * Disconnect error handler, attempts to reconnect in 60 seconds
  1265. *
  1266. * @param String $message Error message (desc of where error encountered etc)
  1267. *
  1268. * @access private
  1269. * @return void
  1270. */
  1271. function derror($message)
  1272. {
  1273. $this->log($message);
  1274. $this->log("Error");
  1275. fclose($this->myConnection);
  1276. if ((time() - $GLOBALS['errortime']) < 600){
  1277. $this->log("Reconnecting in 60 Seconds");
  1278. sleep(60);
  1279. }
  1280. $this->signon();
  1281. $GLOBALS['errortime'] = time();
  1282. }
  1283. /**
  1284. * Returns connection type of socket (main or rvous etc)
  1285. *
  1286. * Helper method for recieve()
  1287. *
  1288. * @param Resource $sock Socket to determine type for
  1289. *
  1290. * @access private
  1291. * @return void
  1292. * @see receive
  1293. */
  1294. function connectionType($sock)
  1295. {
  1296. //Is it the main connection?
  1297. if ($sock == $this->myConnection)
  1298. return CONN_TYPE_NORMAL;
  1299. else
  1300. {
  1301. for($i = 0;$i<sizeof($this->myDirectConnections);$i++)
  1302. {
  1303. if ($sock == $this->myDirectConnections[$i]->sock)
  1304. return $this->myDirectConnections[$i]->type;
  1305. }
  1306. }
  1307. return false;
  1308. }
  1309. /**
  1310. * Checks for new data and calls appropriate methods
  1311. *
  1312. * This method is usually called in an infinite loop to keep checking for new data
  1313. *
  1314. * @access public
  1315. * @return void
  1316. * @see connectionType
  1317. */
  1318. function receive()
  1319. {
  1320. //This function will be used to get the incoming data
  1321. //and it will be used to call the event handlers
  1322. //First, get an array of sockets that have data that is ready to be read
  1323. $ready = array();
  1324. $ready = $this->myConnections;
  1325. $numrdy = stream_select($ready, $w = NULL, $x = NULL,NULL);
  1326. //Now that we've waited for something, go through the $ready
  1327. //array and read appropriately
  1328. for($i = 0;$i<sizeof($ready);$i++)
  1329. {
  1330. //Get the type
  1331. $type = $this->connectionType($ready[$i]);
  1332. if ($type == CONN_TYPE_NORMAL)
  1333. {
  1334. //Next step:Get the data sitting in the socket
  1335. $message = $this->read_from_aim();
  1336. if (strlen($message) <= 0)
  1337. {
  1338. return;
  1339. }
  1340. //Third step: Get the command from the server
  1341. @list($cmd, $rest) = explode(":", $message);
  1342. //Fourth step, take the command, test the type, and pass it off
  1343. //to the correct internal handler. The internal handler will
  1344. //do what needs to be done on the class internals to allow
  1345. //it to work, then proceed to pass it off to the user created handle
  1346. //if there is one
  1347. $this->log($cmd);
  1348. switch($cmd)
  1349. {
  1350. case 'SIGN_ON':
  1351. $this->onSignOn($message);
  1352. break;
  1353. case 'CONFIG2':
  1354. $this->onConfig($message);
  1355. break;
  1356. case 'ERROR':
  1357. $this->onError($message);
  1358. break;
  1359. case 'NICK':
  1360. $this->onNick($message);
  1361. break;
  1362. case 'IM_IN2':
  1363. $this->onImIn($message);
  1364. break;
  1365. case 'UPDATE_BUDDY2':
  1366. $this->onUpdateBuddy($message);
  1367. break;
  1368. case 'EVILED':
  1369. $this->onWarn($message);
  1370. break;
  1371. case 'CHAT_JOIN':
  1372. $this->onChatJoin($message);
  1373. break;
  1374. case 'CHAT_IN':
  1375. $this->onChatIn($message);
  1376. break;
  1377. case 'CHAT_UPDATE_BUDDY':
  1378. $this->onChatUpdate($message);
  1379. break;
  1380. case 'CHAT_INVITE':
  1381. $this->onChatInvite($message);
  1382. break;
  1383. case 'CHAT_LEFT':
  1384. $this->onChatLeft($message);
  1385. break;
  1386. case 'GOTO_URL':
  1387. $this->onGotoURL($message);
  1388. break;
  1389. case 'DIR_STATUS':
  1390. $this->onDirStatus($message);
  1391. break;
  1392. case 'ADMIN_NICK_STATUS':
  1393. $this->onAdminNick($message);
  1394. break;
  1395. case 'ADMIN_PASSWD_STATUS':
  1396. $this->onAdminPasswd($message);
  1397. break;
  1398. case 'PAUSE':
  1399. $this->onPause($message);
  1400. break;
  1401. case 'RVOUS_PROPOSE':
  1402. $this->onRvous($message);
  1403. break;
  1404. default:
  1405. $this->log("Fell through: $message");
  1406. $this->CatchAll($message);
  1407. break;
  1408. }
  1409. }
  1410. else
  1411. {
  1412. for($j = 0;$j<sizeof($this->myDirectConnections);$j++)
  1413. {
  1414. if ($this->myDirectConnections[$j]->sock == $ready[$i])
  1415. {
  1416. $dcon = $this->myDirectConnections[$j];
  1417. break;
  1418. }
  1419. }
  1420. //Now read from the dcon
  1421. if ($dcon->type == CONN_TYPE_DC)
  1422. {
  1423. if ($dcon->readDIM() == false)
  1424. {
  1425. $this->closeDcon($dcon);
  1426. continue;
  1427. }
  1428. $message['message'] = $dcon->lastMessage;
  1429. if ($message['message'] == "too big")
  1430. {
  1431. $this->sendDim("Connection dropped because you sent a message larger that " . MAX_DCON_SIZE . " bytes.", $dcon->connectedTo);
  1432. $this->closeDcon($dcon);
  1433. continue;
  1434. }
  1435. $message['from'] = $dcon->connectedTo;
  1436. $this->onDimIn($message);
  1437. }
  1438. }
  1439. }
  1440. $this->conn->myLastReceived="";
  1441. //Now get out of this function because the handlers should take care
  1442. //of everything
  1443. }
  1444. //The next block of code is all the event handlers needed by the class
  1445. //Some are left blank and only call the users handler because the class
  1446. //either does not support the command, or cannot do anything with it
  1447. // ---------------------------------------------------------------------
  1448. /**
  1449. * Direct IM In Event Handler
  1450. *
  1451. * Called when Direct IM is received.
  1452. * Call's user handler (if available) for DimIn.
  1453. *
  1454. * @access private
  1455. * @param String $data Raw message from server
  1456. * @return void
  1457. */
  1458. function onDimIn($data)
  1459. {
  1460. $this->callHandler("DimIn", $data);
  1461. }
  1462. /**
  1463. * Sign On Event Handler
  1464. *
  1465. * Called when Sign On event occurs.
  1466. * Call's user handler (if available) for SIGN_ON.
  1467. *
  1468. * @access private
  1469. * @param String $data Raw message from server
  1470. * @return void
  1471. */
  1472. function onSignOn($data)
  1473. {
  1474. $this->callHandler("SignOn", $data);
  1475. }
  1476. /**
  1477. * Config Event Handler
  1478. *
  1479. * Called when Config data received.
  1480. * Call's user handler (if available) for Config.
  1481. *
  1482. * Loads buddy list and other info
  1483. *
  1484. * @access private
  1485. * @param String $data Raw message from server
  1486. * @return void
  1487. */
  1488. function onConfig($data)
  1489. {
  1490. $this->log("onConfig Message: " . $data);
  1491. if (strpos($data,"CONFIG2:") === false)
  1492. {
  1493. $this->log("get_buddy_list cannot be called at this time because I got $data");
  1494. //return false;
  1495. }
  1496. $people = explode("\n",trim($data,"\n"));
  1497. //The first 3 elements of the array are who knows what, element 3 should be
  1498. //a letter followed by a person
  1499. //AIM decided to add this wonderful new feature, the recent buddy thing, this kind of
  1500. //messes this funtion up, so we need to adapt it... unfortuneately, its not really
  1501. //clear how this works, so we are just going to add their name to the permit list.
  1502. //Recent buddies I believe are in the format
  1503. //number:name:number.... I think the first number counts down from 25 how long its
  1504. //been... but I don't know the second number,,,,
  1505. //TODO: Figure out the new recent buddies system
  1506. //Note: adding that at the bottom is a quick hack and may have adverse consequences...
  1507. for($i = 1;$i<sizeof($people);$i++)
  1508. {
  1509. @list($mode, $name) = explode(":", $people[$i]);
  1510. switch($mode)
  1511. {
  1512. case 'p':
  1513. $this->myPermitList[] = $name;
  1514. break;
  1515. case 'd':
  1516. $this->myBlockedList[] = $name;
  1517. break;
  1518. case 'b':
  1519. $this->myBuddyList[] = $name;
  1520. break;
  1521. case 'done':
  1522. break;
  1523. default:
  1524. //This is assumed to be recent buddies...
  1525. $this->myPermitList[]=$name;
  1526. }
  1527. }
  1528. //We only get the config message once, so now we should send our pd mode
  1529. $this->sflapSend(SFLAP_TYPE_DATA,"toc2_set_pdmode " . $this->myPdMode,0,0);
  1530. //Adds yourself to the permit list
  1531. //This is to fix an odd behavior if you have nobody on your list
  1532. //the server won't send the config command... so this takes care of it
  1533. $this->sflapSend(SFLAP_TYPE_DATA,"toc2_add_permit " . $this->normalize($this->myScreenName),0,0);
  1534. //Now we allow the user to send a list, update anything they want, etc
  1535. $this->callHandler("Config", $data);
  1536. //Now that we have taken care of what the user wants, send the init_done message
  1537. $this->sflapSend(SFLAP_TYPE_DATA,"toc_init_done",0,0);
  1538. //'VOICE_UID'
  1539. //'FILE_GET_UID'
  1540. //'IMAGE_UID'
  1541. //'BUDDY_ICON_UID'
  1542. //'STOCKS_UID'
  1543. //'GAMES_UID'
  1544. $this->sflapSend(SFLAP_TYPE_DATA, "toc_set_caps " . IMAGE_UID . " " . FILE_SEND_UID ." " . FILE_GET_UID . " " . BUDDY_ICON_UID . "",0,0);
  1545. }
  1546. /**
  1547. * Error Event Handler
  1548. *
  1549. * Called when an Error occurs.
  1550. * Call's user handler (if available) for Error.
  1551. *
  1552. * @access private
  1553. * @param String $data Raw message from server
  1554. * @return void
  1555. */
  1556. function onError($data)
  1557. {
  1558. static $errarg = '';
  1559. static $ERRORS = array(
  1560. 0=>'Success',
  1561. 901 =>'$errarg not currently available',
  1562. 902 =>'Warning of $errarg not currently available',
  1563. 903 =>'A message has been dropped, you are exceeding
  1564. the server speed limit',
  1565. 911 =>'Error validating input',
  1566. 912 =>'Invalid account',
  1567. 913 =>'Error encountered while processing request',
  1568. 914 =>'Service unavailable',
  1569. 950 =>'Chat in $errarg is unavailable.',
  1570. 960 =>'You are sending message too fast to $errarg',
  1571. 961 =>'You missed an im from $errarg because it was too big.',
  1572. 962 =>'You missed an im from $errarg because it was sent too fast.',
  1573. 970 =>'Failure',
  1574. 971 =>'Too many matches',
  1575. 972 =>'Need more qualifiers',
  1576. 973 =>'Dir service temporarily unavailable',
  1577. 974 =>'Email lookup restricted',
  1578. 975 =>'Keyword Ignored',
  1579. 976 =>'No Keywords',
  1580. 977 =>'Language not supported',
  1581. 978 =>'Country not supported',
  1582. 979 =>'Failure unknown $errarg',
  1583. 980 =>'Incorrect nickname or password.',
  1584. 981 =>'The service is temporarily unavailable.',
  1585. 982 =>'Your warning level is currently too high to sign on.',
  1586. 983 =>'You have been connecting and
  1587. disconnecting too frequently. Wait 10 minutes and try again.
  1588. If you continue to try, you will need to wait even longer.',
  1589. 989 =>'An unknown signon error has occurred $errarg'
  1590. );
  1591. $data_array = explode(":", $data);
  1592. for($i=0; $i<count($data_array); $i++)
  1593. {
  1594. switch($i)
  1595. {
  1596. case 0:
  1597. $cmd = $data_array[$i];
  1598. break;
  1599. case 1:
  1600. $errornum = $data_array[$i];
  1601. break;
  1602. case 2:
  1603. $errargs = $data_array[$i];
  1604. break;
  1605. }
  1606. }
  1607. eval("\$errorstring=\"\$ERRORS[" . $errornum . "]\";");
  1608. $string = "\$errorstring=\"\$ERRORS[$errornum]\";";
  1609. //This is important information! We need
  1610. // a A different outputter for errors
  1611. // b Just to echo it
  1612. //I'm just going to do a straight echo here, becuse we assume that
  1613. //the user will NEED to see this error. An option to supress it will
  1614. //come later I think. Perhaps if we did an error reporting level, similar
  1615. //to PHP's, and we could probably even use PHP's error outputting system
  1616. //I think that may be an idea....
  1617. $this->log($errorstring . "\n");
  1618. $this->callHandler("Error", $data);
  1619. }
  1620. /**
  1621. * Nick Event Handler
  1622. *
  1623. * Called when formatted own ScreenName is receieved
  1624. * Call's user handler (if available) for Nick.
  1625. *
  1626. * @access private
  1627. * @param String $data Raw message from server
  1628. * @return void
  1629. */
  1630. function onNick($data)
  1631. {
  1632. //This is our nick, so set a field called "myFormatSN" which will represent
  1633. //the actual name given by the server to us, NOT the normalized screen name
  1634. @list($cmd, $nick) = explode(":", $data);
  1635. $this->myFormatSN = $nick;
  1636. $this->callHandler("Nick", $data);
  1637. }
  1638. /**
  1639. * IM In Event Handler
  1640. *
  1641. * Called when an Instant Message is received.
  1642. * Call's user handler (if available) for IMIn.
  1643. *
  1644. * @access private
  1645. * @param String $data Raw message from server
  1646. * @return void
  1647. */
  1648. function onImIn($data)
  1649. {
  1650. //Perhaps we should add an internal log for debugging purposes??
  1651. //But now, this should probably be handled by the user purely
  1652. $this->callHandler("IMIn", $data);
  1653. }
  1654. /**
  1655. * UpdateBuddy Event Handler
  1656. *
  1657. * Called when a Buddy Update is receieved.
  1658. * Call's user handler (if available) for UpdateBuddy.
  1659. * If info is about self, updates self info (Currently ownly warning).
  1660. *
  1661. * ToDo: Keep track of idle, warning etc on Buddy List
  1662. *
  1663. * @access private
  1664. * @param String $data Raw message from server
  1665. * @return void
  1666. */
  1667. function onUpdateBuddy($data)
  1668. {
  1669. //Again, since our class currently does not deal with other people without
  1670. //outside help, then this is also probably best left to the user. Though
  1671. //we should probably allow this to replace the setMyInfo function above
  1672. //by handling the input if and only if it is us
  1673. //Check and see that this is the command expected
  1674. if (strpos($data,"UPDATE_BUDDY2:") == -1)
  1675. {
  1676. $this->log("A different message than expected was received");
  1677. return false;
  1678. }
  1679. //@list($cmd, $info['sn'], $info['online'], $info['warnlevel'], $info['signon'], $info['idle'], $info['uc']) = explode(":", $command['incoming']);
  1680. //@list($cmd, $sn, $online, $warning, $starttime, $idletime, $uc) = explode(":", $data);
  1681. $info = $this->getMessageInfo($data);
  1682. if ($this->normalize($info['sn']) == $this->normalize($this->myScreenName))
  1683. {
  1684. $warning = rtrim($info['warnlevel'],"%");
  1685. $this->myWarnLevel = $warning;
  1686. $this->log("My warning level is $this->myWarnLevel %");
  1687. }
  1688. $this->callHandler("UpdateBuddy", $data);
  1689. }
  1690. /**
  1691. * Warning Event Handler
  1692. *
  1693. * Called when bot is warned.
  1694. * Call's user handler (if available) for Warn.
  1695. * Updates internal warning level
  1696. *
  1697. * @access private
  1698. * @param String $data Raw message from server
  1699. * @return void
  1700. */
  1701. function onWarn($data)
  1702. {
  1703. /*
  1704. For reference:
  1705. $command['incoming'] .= ":0";
  1706. $it = explode(":", $command['incoming']);
  1707. $info['warnlevel'] = $it[1];
  1708. $info['from'] = $it[2];
  1709. */
  1710. //SImply update our warning level
  1711. //@list($cmd, $newwarn, $user) = explode(":", $data);
  1712. $info = $this->getMessageInfo($data);
  1713. $this->setWarningLevel(trim($info['warnlevel'],"%"));
  1714. $this->log("My warning level is $this->myWarnLevel %");
  1715. $this->callHandler("Warned", $data);
  1716. }
  1717. /**
  1718. * Chat Join Handler
  1719. *
  1720. * Called when bot joins a chat room.
  1721. * Call's user handler (if available) for ChatJoin.
  1722. * Adds chat room to internal chat room list.
  1723. *
  1724. * @access private
  1725. * @param String $data Raw message from server
  1726. * @return void
  1727. */
  1728. function onChatJoin($data)
  1729. {
  1730. @list($cmd, $rmid, $rmname) = explode(":", $data);
  1731. $this->myChatRooms[$rmid] = 0;
  1732. $this->callHandler("ChatJoin", $data);
  1733. }
  1734. /**
  1735. * Returns number of chat rooms bot is in
  1736. *
  1737. * @access public
  1738. * @param String $data Raw message from server
  1739. * @return int
  1740. */
  1741. function getNumChats()
  1742. {
  1743. return count($this->myChatRooms);
  1744. }
  1745. /**
  1746. * Chat Update Handler
  1747. *
  1748. * Called when bot received chat room data (user update).
  1749. * Call's user handler (if available) for ChatUpdate.
  1750. *
  1751. * @access private
  1752. * @param String $data Raw message from server
  1753. * @return void
  1754. */
  1755. function onChatUpdate($data)
  1756. {
  1757. $stuff = explode(":", $data);
  1758. $people = sizeof($stuff);
  1759. $people -= 2;
  1760. $this->callHandler("ChatUpdate", $data);
  1761. }
  1762. /**
  1763. * Chat Message In Handler
  1764. *
  1765. * Called when chat room message is received.
  1766. * Call's user handler (if available) for ChatIn.
  1767. *
  1768. * @access private
  1769. * @param String $data Raw message from server
  1770. * @return void
  1771. */
  1772. function onChatIn($data)
  1773. {
  1774. $this->callHandler("ChatIn", $data);
  1775. }
  1776. /**
  1777. * Chat Invite Handler
  1778. *
  1779. * Called when bot is invited to a chat room.
  1780. * Call's user handler (if available) for ChatInvite.
  1781. *
  1782. * @access private
  1783. * @param String $data Raw message from server
  1784. * @return void
  1785. */
  1786. function onChatInvite($data)
  1787. {
  1788. //@list($cmd, $name, $id, $from, $data) = explode(":", $data,6);
  1789. //$data = explode(":",$data,6);
  1790. //$nm = array();
  1791. //@list($nm['cmd'],$nm['name'],$nm['id'],$nm['from'],$nm['message']) = $data;
  1792. $this->callHandler("ChatInvite", $data);
  1793. }
  1794. /**
  1795. * Chat Left Handler
  1796. *
  1797. * Called when bot leaves a chat room
  1798. * Call's user handler (if available) for ChatLeft.
  1799. *
  1800. * @access private
  1801. * @param String $data Raw message from server
  1802. * @return void
  1803. */
  1804. function onChatLeft($data)
  1805. {
  1806. $info = $this->getMessageInfo($data);
  1807. unset($this->myChatRooms[$info['chatid']]);
  1808. $this->callHandler("ChatLeft", $data);
  1809. }
  1810. /**
  1811. * Goto URL Handler
  1812. *
  1813. * Called on GotoURL.
  1814. * Call's user handler (if available) for GotoURL.
  1815. * No detailed info available for this / Unsupported.
  1816. *
  1817. * @access private
  1818. * @param String $data Raw message from server
  1819. * @return void
  1820. */
  1821. function onGotoURL($data)
  1822. {
  1823. //This is of no use to the internal class
  1824. $this->callHandler("GotoURL", $data);
  1825. }
  1826. /**
  1827. * Dir Status Handler
  1828. *
  1829. * Called on DirStatus.
  1830. * Call's user handler (if available) for DirStatus.
  1831. * No detailed info available for this / Unsupported.
  1832. *
  1833. * @access private
  1834. * @param String $data Raw message from server
  1835. * @return void
  1836. */
  1837. function onDirStatus($data)
  1838. {
  1839. //This is not currently suported
  1840. $this->callHandler("DirStatus", $data);
  1841. }
  1842. /**
  1843. * AdminNick Handler
  1844. *
  1845. * Called on AdminNick.
  1846. * Call's user handler (if available) for AdminNick.
  1847. * No detailed info available for this / Unsupported.
  1848. *
  1849. * @access private
  1850. * @param String $data Raw message from server
  1851. * @return void
  1852. */
  1853. function onAdminNick($data)
  1854. {
  1855. //NOt particularly useful to us
  1856. $this->callHandler("AdminNick", $data);
  1857. }
  1858. /**
  1859. * AdminPasswd Handler
  1860. *
  1861. * Called on AdminPasswd.
  1862. * Call's user handler (if available) for AdminPasswd.
  1863. * No detailed info available for this / Unsupported.
  1864. *
  1865. * @access private
  1866. * @param String $data Raw message from server
  1867. * @return void
  1868. */
  1869. function onAdminPasswd($data)
  1870. {
  1871. //Also not particlualry useful to the internals
  1872. $this->callHandler("AdminPasswd", $data);
  1873. }
  1874. /**
  1875. * Pause Handler
  1876. *
  1877. * Called on Pause.
  1878. * Call's user handler (if available) for Pause.
  1879. * No detailed info available for this / Unsupported.
  1880. *
  1881. * @access private
  1882. * @param String $data Raw message from server
  1883. * @return void
  1884. */
  1885. function onPause($data)
  1886. {
  1887. //This is pretty useless to us too...
  1888. $this->callHandler("Pause", $data);
  1889. }
  1890. /**
  1891. * Direct Connection Handler
  1892. *
  1893. * Called on Direct Connection Request(Rvous).
  1894. * Call's user handler (if available) for Rvous.
  1895. *
  1896. * @access private
  1897. * @param String $data Raw message from server
  1898. * @return void
  1899. */
  1900. function onRvous($data)
  1901. {
  1902. $this->callHandler("Rvous", $data);
  1903. }
  1904. /**
  1905. * CatchAll Handler
  1906. *
  1907. * Called for unrecognized commands.
  1908. * Logs unsupported messages to array.
  1909. * Call's user handler (if available) for CatchAll.
  1910. *
  1911. * @access private
  1912. * @param String $data Raw message from server
  1913. * @return void
  1914. */
  1915. function CatchAll($data)
  1916. {
  1917. //Add to a log of unsupported messages.
  1918. $this->unsupported[] = $data;
  1919. //$this->log($data);
  1920. //print_r($data);
  1921. $this->callHandler("CatchAll", $data);
  1922. }
  1923. /**
  1924. * Calls User Handler
  1925. *
  1926. * Calls registered handler for a specific event.
  1927. *
  1928. * @access private
  1929. * @param String $event Command (event) name (Rvous etc)
  1930. * @param String $data Raw message from server
  1931. * @see registerHandler
  1932. * @return void
  1933. */
  1934. function callHandler($event, $data)
  1935. {
  1936. if (isset($this->myEventHandlers[$event]))
  1937. {
  1938. //$function = $this->myEventHandlers[$event] . "(\$data);";
  1939. //eval($function);
  1940. call_user_func($this->myEventHandlers[$event], $data);
  1941. }
  1942. else
  1943. {
  1944. $this->noHandler($data);
  1945. }
  1946. }
  1947. /**
  1948. * Registers a user handler
  1949. *
  1950. * Handler List
  1951. * SignOn, Config, ERROR, NICK, IMIn, UpdateBuddy, Eviled, Warned, ChatJoin
  1952. * ChatIn, ChatUpdate, ChatInvite, ChatLeft, GotoURL, DirStatus, AdminNick
  1953. * AdminPasswd, Pause, Rvous, DimIn, CatchAll
  1954. *
  1955. * @access private
  1956. * @param String $event Event name
  1957. * @param String $handler User function to call
  1958. * @see callHandler
  1959. * @return boolean Returns true if successful
  1960. */
  1961. function registerHandler($event, $handler)
  1962. {
  1963. if (is_callable($handler))
  1964. {
  1965. $this->myEventHandlers[$event] = $handler;
  1966. return true;
  1967. }
  1968. else
  1969. {
  1970. return false;
  1971. }
  1972. }
  1973. /**
  1974. * No user handler method fall back.
  1975. *
  1976. * Does nothing with message.
  1977. *
  1978. * @access public
  1979. * @param String $message Raw server message
  1980. * @return void
  1981. */
  1982. function noHandler($message)
  1983. {
  1984. //This function intentionally left blank
  1985. //This is where the handlers will fall to for now. I plan on including a more
  1986. //efficent check to avoid the apparent stack jumps that this code will produce
  1987. //But for now, just fall into here, and be happy
  1988. return;
  1989. }
  1990. //GLOBAL FUNCTIONS
  1991. /**
  1992. * Finds type, and returns as part of array ['type']
  1993. * Puts message in ['incoming']
  1994. *
  1995. * Helper method for getMessageInfo.
  1996. *
  1997. * @access public
  1998. * @param String $message Raw server message
  1999. * @see msg_parse
  2000. * @see getMessageInfo
  2001. * @return array
  2002. */
  2003. static function msg_type($message)
  2004. {
  2005. $command = array();
  2006. @list($cmd, $rest) = explode(":", $message);
  2007. switch($cmd)
  2008. {
  2009. case 'IM_IN2':
  2010. $type = AIM_TYPE_MSG;
  2011. break;
  2012. case 'UPDATE_BUDDY2':
  2013. $type = AIM_TYPE_UPDATEBUDDY;
  2014. break;
  2015. case 'EVILED':
  2016. $type = AIM_TYPE_WARN;
  2017. break;
  2018. case 'SIGN_ON':
  2019. $type = AIM_TYPE_SIGNON;
  2020. break;
  2021. case 'NICK':
  2022. $type = AIM_TYPE_NICK;
  2023. break;
  2024. case 'ERROR':
  2025. $type = AIM_TYPE_ERROR;
  2026. break;
  2027. case 'CHAT_JOIN':
  2028. $type = AIM_TYPE_CHATJ;
  2029. break;
  2030. case 'CHAT_IN':
  2031. $type = AIM_TYPE_CHATI;
  2032. break;
  2033. case 'CHAT_UPDATE_BUDDY':
  2034. $type = AIM_TYPE_CHATUPDBUD;
  2035. break;
  2036. case 'CHAT_INVITE':
  2037. $type = AIM_TYPE_CHATINV;
  2038. break;
  2039. case 'CHAT_LEFT':
  2040. $type = AIM_TYPE_CHATLE;
  2041. break;
  2042. case 'GOTO_URL':
  2043. $type = AIM_TYPE_URL;
  2044. break;
  2045. case 'ADMIN_NICK_STATUS':
  2046. $type = AIM_TYPE_NICKSTAT;
  2047. break;
  2048. case 'ADMIN_PASSWD_STATUS':
  2049. $type = AIM_TYPE_PASSSTAT;
  2050. break;
  2051. case 'RVOUS_PROPOSE':
  2052. $type = AIM_TYPE_RVOUSP;
  2053. break;
  2054. default:
  2055. $type = AIM_TYPE_NOT_IMPLEMENTED;
  2056. break;
  2057. }
  2058. $command['type'] = $type;
  2059. $command['incoming'] = $message;
  2060. return $command;
  2061. }
  2062. /**
  2063. * Parses message and splits into info array
  2064. *
  2065. * Helper method for getMessageInfo.
  2066. *
  2067. * @access public
  2068. * @param String $command Message and type (after msg_type)
  2069. * @see msg_type
  2070. * @see getMessageInfo
  2071. * @return array
  2072. */
  2073. static function msg_parse($command)
  2074. {
  2075. $info = array();
  2076. switch($command['type'])
  2077. {
  2078. case AIM_TYPE_WARN:
  2079. $command['incoming'] .= ":0";
  2080. $it = explode(":", $command['incoming']);
  2081. $info['warnlevel'] = $it[1];
  2082. $info['from'] = $it[2];
  2083. break;
  2084. case AIM_TYPE_MSG:
  2085. $it = explode(":", $command['incoming'],5);
  2086. $info['auto'] = $it[2];
  2087. $info['from'] = $it[1];
  2088. $info['message'] = $it[4];
  2089. break;
  2090. case AIM_TYPE_UPDATEBUDDY:
  2091. @list($cmd, $info['sn'], $info['online'], $info['warnlevel'], $info['signon'], $info['idle'], $info['uc']) = explode(":", $command['incoming']);
  2092. break;
  2093. case AIM_TYPE_SIGNON:
  2094. @list($cmd, $info['version']) = explode(":", $command['incoming']);
  2095. break;
  2096. case AIM_TYPE_NICK:
  2097. @list($cmd, $info['nickname']) = explode(":", $command['incoming']);
  2098. break;
  2099. case AIM_TYPE_ERROR:
  2100. @list($cmd, $info['errorcode'], $info['args']) = explode(":", $command['incoming']);
  2101. break;
  2102. case AIM_TYPE_CHATJ:
  2103. @list($cmd, $info['chatid'], $info['chatname']) = explode(":", $command['incoming']);
  2104. break;
  2105. case AIM_TYPE_CHATI:
  2106. @list($cmd, $info['chatid'], $info['user'], $info['whisper'], $info['message']) = explode(":", $command['incoming'],5);
  2107. break;
  2108. case AIM_TYPE_CHATUPDBUD:
  2109. @list($cmd, $info['chatid'], $info['inside'], $info['userlist']) = explode(":", $command['incoming'],3);
  2110. break;
  2111. case AIM_TYPE_CHATINV:
  2112. @list($cmd, $info['chatname'], $info['chatid'], $info['from'], $info['message']) = explode(":", $command['incoming'],5);
  2113. break;
  2114. case AIM_TYPE_CHATLE:
  2115. @list($cmd, $info['chatid']) = explode(":", $command['incoming']);
  2116. break;
  2117. case AIM_TYPE_URL:
  2118. @list($cmd, $info['windowname'], $info['url']) = explode(":", $command['incoming'],3);
  2119. break;
  2120. case AIM_TYPE_RVOUSP:
  2121. @list($cmd,$info['user'],$info['uuid'],$info['cookie'],$info['seq'],$info['rip'],$info['pip'],$info['vip'],$info['port'],$info['tlvs']) = explode(":",$command['incoming'],10);
  2122. break;
  2123. case AIM_TYPE_NICKSTAT:
  2124. case AIM_TYPE_PASSSTAT:
  2125. @list($cmd, $info['returncode'], $info['opt']) = explode(":", $command['incoming'],3);
  2126. break;
  2127. default:
  2128. $info['command'] = $command['incoming'];
  2129. }
  2130. return $info;
  2131. }
  2132. /**
  2133. * Returns a parsed message
  2134. *
  2135. * Calls msg_parse(msg_type( to first determine message type and then parse accordingly
  2136. *
  2137. * @access public
  2138. * @param String $command Raw server message
  2139. * @see msg_type
  2140. * @see msg_parse
  2141. * @return array
  2142. */
  2143. static function getMessageInfo($message)
  2144. {
  2145. return self::msg_parse(self::msg_type($message));
  2146. }
  2147. /**
  2148. * Checks socket for end of file
  2149. *
  2150. * @access public
  2151. * @param Resource $socket Socket to check
  2152. * @return boolean true if end of file (socket)
  2153. */
  2154. static function socketcheck($socket){
  2155. $info = stream_get_meta_data($socket);
  2156. return $info['eof'];
  2157. //return(feof($socket));
  2158. }
  2159. }
  2160. ?>