ParseENums.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is Vision.
  13. *
  14. * The Initial Developer of the Original Code is The Vision Team.
  15. * Portions created by The Vision Team are
  16. * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
  17. * Reserved.
  18. *
  19. * Contributor(s): Wade Majors <wade@ezri.org>
  20. * Rene Gollent
  21. * Todd Lair
  22. * Andrew Bazan
  23. * Jamie Wilkinson
  24. * Bjorn Oksholen
  25. */
  26. #include <Entry.h>
  27. #include <Menu.h>
  28. #include <Notification.h>
  29. #include <Roster.h>
  30. #include "ClientWindow.h"
  31. #include "NotifyList.h"
  32. #include "ParseENums.h"
  33. #include "ServerAgent.h"
  34. #include "StatusView.h"
  35. #include "Utilities.h"
  36. #include "Vision.h"
  37. #include "WindowList.h"
  38. #include <arpa/inet.h>
  39. #include <ctype.h>
  40. #include <math.h>
  41. #include <netdb.h>
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <sys/socket.h>
  45. bool
  46. ServerAgent::ParseENums (const char *data, const char *sWord)
  47. {
  48. int num (atoi (sWord));
  49. switch (num)
  50. {
  51. case ZERO: // 0
  52. {
  53. // wasn't a numeric, or the server is playing tricks on us
  54. }
  55. return false;
  56. case ERR_UNKNOWNCOMMAND: // 421
  57. {
  58. BString tempString (RestOfString (data, 4)),
  59. badCmd (GetWord (data, 4));
  60. if (badCmd == "VISION_LAG_CHECK")
  61. {
  62. int32 difference (system_time() - fLagCheck);
  63. if (difference > 0)
  64. {
  65. int32 secs (difference / 1000000);
  66. int32 milli (difference / 1000 - secs * 1000);
  67. char lag[15] = "";
  68. sprintf (lag, "%ld.%03ld", secs, milli);
  69. fMyLag = lag;
  70. fLagCount = 0;
  71. fCheckingLag = false;
  72. fMsgr.SendMessage (M_LAG_CHANGED);
  73. }
  74. }
  75. else
  76. {
  77. tempString.RemoveFirst (":");
  78. tempString.Append ("\n");
  79. Display (tempString.String());
  80. }
  81. }
  82. return true;
  83. case RPL_WELCOME: // 001
  84. case RPL_YOURHOST: // 002
  85. case RPL_CREATED: // 003
  86. case RPL_MYINFO: // 004
  87. {
  88. fIsConnecting = false;
  89. fIsConnected = true;
  90. fSMsgr.SendMessage (M_CONNECTED);
  91. fInitialMotd = true;
  92. fRetry = 0;
  93. if (fNetworkData.FindBool ("lagCheck"))
  94. {
  95. fMyLag = "0.000";
  96. fMsgr.SendMessage (M_LAG_CHANGED);
  97. }
  98. BString theNick (GetWord (data, 3));
  99. fMyNick = theNick;
  100. if (!IsHidden())
  101. vision_app->pClientWin()->pStatusView()->SetItemValue (STATUS_NICK,
  102. theNick.String());
  103. BString theMsg (RestOfString (data, 4));
  104. theMsg.RemoveFirst (":");
  105. theMsg.Prepend ("* ");
  106. theMsg.Append ("\n");
  107. Display (theMsg.String());
  108. if (num == RPL_MYINFO)
  109. {
  110. // set "real" hostname
  111. fServerHostName = (GetWord (data, 1));
  112. fServerHostName.RemoveFirst (":");
  113. BString hostName (fId.String());
  114. hostName += " - [";
  115. hostName += fServerHostName.String();
  116. hostName += "]";
  117. fAgentWinItem->SetName (hostName.String());
  118. // detect IRCd
  119. fIrcdtype = IRCD_STANDARD;
  120. if (theMsg.FindFirst("hybrid") > 0)
  121. fIrcdtype = IRCD_HYBRID;
  122. // ultimate and unreal share the same numerics, so treat them with the same
  123. // identifier for now
  124. else if ((theMsg.FindFirst("UltimateIRCd") > 0) || (theMsg.FindFirst("Unreal") > 0))
  125. fIrcdtype = IRCD_ULTIMATE;
  126. else if (theMsg.FindFirst("comstud") > 0)
  127. fIrcdtype = IRCD_COMSTUD;
  128. else if (theMsg.FindFirst("u2.") > 0)
  129. fIrcdtype = IRCD_UNDERNET;
  130. else if (theMsg.FindFirst("PTlink") > 0)
  131. fIrcdtype = IRCD_PTLINK;
  132. else if (theMsg.FindFirst ("CR") > 0)
  133. fIrcdtype = IRCD_CONFERENCEROOM;
  134. else if (theMsg.FindFirst ("nn-") > 0)
  135. fIrcdtype = IRCD_NEWNET;
  136. }
  137. }
  138. return true;
  139. case RPL_PROTOCTL: // 005
  140. {
  141. // this numeric also serves as RPL_NNMAP on Newnet
  142. BString theMsg (RestOfString (data, 4));
  143. theMsg.RemoveFirst (":");
  144. theMsg.Append ("\n");
  145. switch (fIrcdtype)
  146. {
  147. case IRCD_NEWNET:
  148. {
  149. // RPL_NNMAP
  150. Display (theMsg.String());
  151. }
  152. break;
  153. default:
  154. {
  155. // RPL_PROTOCTL
  156. theMsg.Prepend ("* ");
  157. Display (theMsg.String());
  158. }
  159. }
  160. }
  161. return true;
  162. case RPL_LUSERHIGHESTCONN: // 250
  163. case RPL_LUSERCLIENT: // 251
  164. case RPL_LUSEROP: // 252
  165. case RPL_LUSERUNKNOWN: // 253
  166. case RPL_LUSERCHANNELS: // 254
  167. case RPL_LUSERME: // 255
  168. case RPL_LUSERLOCAL: // 265
  169. case RPL_LUSERGLOBAL: // 266
  170. {
  171. BString theMsg (RestOfString (data, 4));
  172. theMsg.RemoveFirst (":");
  173. theMsg.Prepend ("* ");
  174. theMsg.Append ("\n");
  175. Display (theMsg.String());
  176. }
  177. return true;
  178. /// strip and send to server agent ///
  179. case RPL_ULMAP: // 006
  180. case RPL_ULMAPEND: // 007
  181. case RPL_U2MAP: // 015
  182. case RPL_U2MAPEND: // 017
  183. case RPL_TRACELINK: // 200
  184. case RPL_TRACECONNECTING: // 201
  185. case RPL_TRACEHANDSHAKE: // 202
  186. case RPL_TRACEUNKNOWN: // 203
  187. case RPL_TRACEOPERATOR: // 204
  188. case RPL_TRACEUSER: // 205
  189. case RPL_TRACESERVER: // 206
  190. case RPL_TRACENEWTYPE: // 208
  191. case RPL_TRACECLASS: // 209
  192. case RPL_STATSLINKINFO: // 211
  193. case RPL_STATSCOMMANDS: // 212
  194. case RPL_STATSCLINE: // 213
  195. case RPL_STATSNLINE: // 214
  196. case RPL_STATSILINE: // 215
  197. case RPL_STATSKLINE: // 216
  198. case RPL_STATSQLINE: // 217
  199. case RPL_STATSYLINE: // 218
  200. case RPL_ENDOFSTATS: // 219
  201. case RPL_STATSBLINE: // 220
  202. case RPL_DALSTATSE: // 223
  203. case RPL_DALSTATSF: // 224
  204. case RPL_DALSTATSZ: // 225
  205. case RPL_DALSTATSN: // 226
  206. case RPL_DALSTATSG: // 227
  207. case RPL_STATSLLINE: // 241
  208. case RPL_STATSUPTIME: // 242
  209. case RPL_STATSOLINE: // 243
  210. case RPL_STATSHLINE: // 244
  211. case RPL_STATSSLINE: // 245
  212. case RPL_DALSTATSX: // 246
  213. case RPL_STATSXLINE: // 247
  214. case RPL_STATSPLINE: // 249
  215. case RPL_ADMINME: // 256
  216. case RPL_ADMINLOC1: // 257
  217. case RPL_ADMINLOC2: // 258
  218. case RPL_ADMINEMAIL: // 259
  219. case RPL_TRACELOG: // 261
  220. case RPL_ENDOFTRACE: // 262
  221. case RPL_SILELIST: // 271
  222. case RPL_ENDOFSILELIST: // 272
  223. case RPL_ENDOFWHO: // 315
  224. case RPL_CHANSERVURL: // 328
  225. case RPL_COMMANDSYNTAX: // 334
  226. case RPL_VERSION: // 351
  227. case RPL_WHOREPLY: // 352
  228. case RPL_BANLIST: // 367
  229. case RPL_ENDOFBANLIST: // 368
  230. case RPL_INFO: // 371
  231. case RPL_ENDOFINFO: // 374
  232. case RPL_YOUREOPER: // 381
  233. case RPL_REHASHING: // 382
  234. case RPL_TIME: // 391
  235. case ERR_NOORIGIN: // 409
  236. case ERR_NOTEXTTOSEND: // 412
  237. case ERR_TOOMANYAWAY: // 429
  238. case ERR_NICKCHANGETOOFAST: // 438
  239. case ERR_TARGETCHANGETOOFAST: // 439
  240. case ERR_SUMMONDISABLED: // 445
  241. case ERR_USERSDISABLED: // 446
  242. case ERR_NOTREGISTERED: // 451
  243. case ERR_NEEDMOREPARMS: // 461
  244. case ERR_PASSWDMISMATCH: // 464
  245. case ERR_YOUREBANNEDCREEP: // 465
  246. case ERR_NOPRIVILEGES: // 481
  247. case ERR_NOOPERHOST: // 491
  248. case ERR_USERSDONTMATCH: // 502
  249. case ERR_SILELISTFULL: // 511
  250. case ERR_TOOMANYWATCH: // 512
  251. case ERR_TOOMANYDCC: // 514
  252. case ERR_CANTINVITE: // 518
  253. case ERR_LISTSYNTAX: // 521
  254. case ERR_WHOSYNTAX: // 522
  255. case ERR_WHOLIMEXCEED: // 523
  256. case RPL_LOGON: // 600
  257. case RPL_LOGOFF: // 601
  258. case RPL_WATCHOFF: // 602
  259. case RPL_WATCHSTAT: // 603
  260. case RPL_NOWON: // 604
  261. case RPL_NOWOFF: // 605
  262. case RPL_WATCHLIST: // 606
  263. case RPL_ENDOFWATCHLIST: // 607
  264. case RPL_DCCALLOWLIST: // 618
  265. case RPL_DCCALLOWEND: // 619
  266. case RPL_DCCALLOW: // 620
  267. {
  268. BString tempString (RestOfString (data, 4));
  269. tempString.RemoveFirst (":");
  270. tempString.Append ("\n");
  271. Display (tempString.String());
  272. }
  273. return true;
  274. case RPL_UMODEIS: // 221
  275. {
  276. BString theMode (GetWord (data, 4)),
  277. tempString (S_PENUM_CURMODE);
  278. tempString += theMode;
  279. tempString += '\n';
  280. BMessage msg (M_DISPLAY);
  281. PackDisplay (&msg, tempString.String(), C_WHOIS);
  282. PostActive (&msg);
  283. }
  284. return true;
  285. /// strip and send to active agent ///
  286. case RPL_TRYAGAIN: // 263
  287. case RPL_UNAWAY: // 305
  288. case RPL_NOWAWAY: // 306
  289. case ERR_NOSUCHNICK: // 401
  290. case ERR_NOSUCHSERVER: // 402
  291. case ERR_NOSUCHCHANNEL: // 403
  292. case ERR_CANNOTSENDTOCHAN: // 404
  293. case ERR_TOOMANYCHANNELS: // 405
  294. case ERR_WASNOSUCHNICK: // 406
  295. case ERR_TOOMANYTARGETS: // 407
  296. case ERR_NOCOLORSONCHAN: // 408
  297. case ERR_YOUCANTDOTHAT: // 460
  298. case ERR_CHANOPRIVSNEEDED: // 482
  299. {
  300. BString tempString ("[x] ");
  301. if (num == ERR_CHANOPRIVSNEEDED)
  302. tempString += RestOfString (data, 5);
  303. else
  304. tempString += RestOfString (data, 4);
  305. tempString.RemoveFirst (":");
  306. tempString.Append ("\n");
  307. BMessage msg (M_DISPLAY);
  308. PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  309. PostActive (&msg);
  310. }
  311. return true;
  312. case RPL_AWAY: // 301
  313. {
  314. BString theNick (GetWord(data, 4));
  315. BString tempString ("[x] "),
  316. theReason (RestOfString(data, 5));
  317. theReason.RemoveFirst(":");
  318. tempString += "Away: ";
  319. tempString += theReason;
  320. tempString += '\n';
  321. if (fRemoteAwayMessages.find(theNick) != fRemoteAwayMessages.end())
  322. {
  323. if (fRemoteAwayMessages[theNick] == theReason)
  324. {
  325. return true;
  326. }
  327. }
  328. fRemoteAwayMessages[theNick] = theReason;
  329. BMessage msg (M_DISPLAY);
  330. PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  331. PostActive (&msg);
  332. }
  333. return true;
  334. case RPL_USERHOST: // 302
  335. {
  336. BString theHost (GetWord (data, 4)),
  337. theHostname (GetAddress (theHost.String()));
  338. theHost.RemoveFirst (":");
  339. BString tempString (RestOfString (data, 4));
  340. tempString.RemoveFirst (":");
  341. tempString.Append ("\n");
  342. Display (tempString.String());
  343. if (fGetLocalIP && (tempString.IFindFirst (fMyNick.String()) == 0))
  344. {
  345. fGetLocalIP = false;
  346. hostent *hp = gethostbyname (theHostname.String());
  347. if (hp != NULL)
  348. {
  349. char addr_buf[16];
  350. in_addr *addr = (in_addr *)hp->h_addr_list[0];
  351. strcpy(addr_buf, inet_ntoa(*addr));
  352. fLocalip = addr_buf;
  353. #if 0
  354. printf("hostname found: %s\n", fLocalip.String());
  355. #endif
  356. return true;
  357. }
  358. else if (isdigit(theHostname[0]))
  359. {
  360. fLocalip = theHostname;
  361. #if 0
  362. printf("hostname found: %s\n", fLocalip.String());
  363. #endif
  364. return true;
  365. }
  366. #if 0
  367. else
  368. {
  369. printf("lookup failed, unable to resolve host\n");
  370. }
  371. #endif
  372. }
  373. if (theHost != "-9z99" && theHost != "")
  374. {
  375. BMessage *dnsmsg (new BMessage);
  376. dnsmsg->AddString ("lookup", theHostname.String());
  377. ClientAgent *client (ActiveClient());
  378. if (client)
  379. dnsmsg->AddPointer("agent", client);
  380. else
  381. dnsmsg->AddPointer("agent", this);
  382. thread_id lookupThread = spawn_thread (
  383. DNSLookup,
  384. "dns_lookup",
  385. B_LOW_PRIORITY,
  386. dnsmsg);
  387. resume_thread (lookupThread);
  388. }
  389. }
  390. return true;
  391. case RPL_ISON: // 303
  392. {
  393. BString nicks (RestOfString (data, 4));
  394. BString onlined, offlined;
  395. nicks.RemoveFirst (":");
  396. int hasChanged (0);
  397. BMessage msg (M_NOTIFYLIST_UPDATE);
  398. for (int32 i = 0; i < fNotifyNicks.CountItems(); i++)
  399. {
  400. NotifyListItem *item (((NotifyListItem *)fNotifyNicks.ItemAt(i)));
  401. int32 nickidx (nicks.IFindFirst(item->Text()));
  402. // make sure that the nick isn't a partial match.
  403. if ((nickidx >= 0) &&
  404. ((nicks[nickidx + strlen(item->Text())] == ' ') || (nicks[nickidx + strlen(item->Text())] == '\0')))
  405. {
  406. if (item->GetState() != true)
  407. {
  408. item->SetState (true);
  409. hasChanged = 1;
  410. if (onlined.Length())
  411. onlined << ", ";
  412. onlined << item->Text();
  413. }
  414. }
  415. else
  416. {
  417. if (item->GetState() == true)
  418. {
  419. item->SetState (false);
  420. hasChanged = 2;
  421. if (offlined.Length())
  422. offlined << ", ";
  423. offlined << item->Text();
  424. }
  425. }
  426. }
  427. if (offlined.Length())
  428. {
  429. BNotification notification(B_INFORMATION_NOTIFICATION);
  430. notification.SetGroup(BString("Vision"));
  431. entry_ref ref = vision_app->AppRef();
  432. notification.SetOnClickFile(&ref);
  433. notification.SetTitle(fServerName.String());
  434. BString content;
  435. content << offlined;
  436. if (offlined.FindFirst(' ') > -1)
  437. content << " are offline";
  438. else
  439. content << " is offline";
  440. notification.SetContent(content);
  441. notification.Send();
  442. }
  443. if (onlined.Length())
  444. {
  445. BNotification notification(B_INFORMATION_NOTIFICATION);
  446. notification.SetGroup(BString("Vision"));
  447. entry_ref ref = vision_app->AppRef();
  448. notification.SetOnClickFile(&ref);
  449. notification.SetTitle(fServerName.String());
  450. BString content;
  451. content << onlined;
  452. if (onlined.FindFirst(' ') > -1)
  453. content << " are online";
  454. else
  455. content << " is online";
  456. notification.SetContent(content);
  457. notification.Send();
  458. }
  459. fNotifyNicks.SortItems(SortNotifyItems);
  460. msg.AddPointer ("list", &fNotifyNicks);
  461. msg.AddPointer ("source", this);
  462. msg.AddInt32 ("change", hasChanged);
  463. Window()->PostMessage (&msg);
  464. }
  465. return true;
  466. case RPL_WHOISIDENTIFIED: // 307
  467. {
  468. BString theInfo (RestOfString (data, 5));
  469. theInfo.RemoveFirst (":");
  470. if (theInfo == "-9z99")
  471. {
  472. // USERIP reply? (RPL_U2USERIP)
  473. BString tempString (RestOfString (data, 4));
  474. tempString.RemoveFirst (":");
  475. tempString.Append ("\n");
  476. Display (tempString.String());
  477. return true;
  478. }
  479. BMessage display (M_DISPLAY);
  480. BString buffer;
  481. buffer += "[x] ";
  482. buffer += theInfo;
  483. buffer += "\n";
  484. PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  485. PostActive (&display);
  486. }
  487. return true;
  488. case RPL_WHOISADMIN: // 308
  489. case RPL_WHOISSERVICESADMIN: // 309
  490. case RPL_WHOISHELPOP: // 310
  491. case RPL_WHOISOPERATOR: // 313
  492. case RPL_WHOISREGNICK: // 320
  493. case RPL_WHOISACTUALLY: // 338
  494. case RPL_WHOISMASK: // 550
  495. case RPL_WHOWASIP: // 612
  496. case RPL_WHOISUSERMODESALT: // 614
  497. case RPL_WHOISUSERMODES: // 615
  498. case RPL_WHOISREALHOSTNAME: // 616
  499. {
  500. BString theInfo (RestOfString (data, 5));
  501. theInfo.RemoveFirst (":");
  502. BMessage display (M_DISPLAY);
  503. BString buffer;
  504. buffer += "[x] ";
  505. buffer += theInfo;
  506. buffer += "\n";
  507. PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  508. PostActive (&display);
  509. }
  510. return true;
  511. case RPL_WHOISUSER: // 311
  512. {
  513. BString theNick (GetWord (data, 4)),
  514. theIdent (GetWord (data, 5)),
  515. theAddress (GetWord (data, 6)),
  516. theName (RestOfString (data, 8));
  517. theName.RemoveFirst (":");
  518. BMessage display (M_DISPLAY);
  519. BString buffer;
  520. buffer += "[x] ";
  521. buffer += theNick;
  522. buffer += " (";
  523. buffer += theIdent;
  524. buffer += "@";
  525. buffer += theAddress;
  526. buffer += ")\n";
  527. buffer += "[x] ";
  528. buffer += theName;
  529. buffer += "\n";
  530. PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  531. PostActive (&display);
  532. }
  533. return true;
  534. case RPL_WHOISSERVER: // 312
  535. {
  536. BString theNick (GetWord (data, 4)),
  537. theServer (GetWord (data, 5)),
  538. theInfo (RestOfString (data, 6));
  539. theInfo.RemoveFirst (":");
  540. BMessage display (M_DISPLAY);
  541. BString buffer;
  542. buffer += "[x] Server: ";
  543. buffer += theServer;
  544. buffer += " (";
  545. buffer += theInfo;
  546. buffer += ")\n";
  547. PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  548. PostActive (&display);
  549. }
  550. return true;
  551. case RPL_WHOWASUSER: // 314
  552. {
  553. BString theNick (GetWord (data, 4)),
  554. theIdent (GetWord (data, 5)),
  555. theAddress (GetWord (data, 6)),
  556. theName (RestOfString (data, 8)),
  557. tempString ("[x] ");
  558. theName.RemoveFirst (":");
  559. tempString += theNick;
  560. tempString += " " S_PENUM_WHOWAS " (";
  561. tempString += theIdent;
  562. tempString += "@";
  563. tempString += theAddress;
  564. tempString += ")\n";
  565. BMessage msg (M_DISPLAY);
  566. PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  567. PostActive (&msg);
  568. }
  569. return true;
  570. case RPL_WHOISIDLE: // 317
  571. {
  572. BString theNick (GetWord (data, 4)),
  573. tempString ("[x] "),
  574. tempString2 ("[x] "),
  575. theTime (GetWord (data, 5)),
  576. signOnTime (GetWord (data, 6));
  577. int64 idleTime (strtoul(theTime.String(), NULL, 0));
  578. tempString += S_PENUM_IDLE;
  579. tempString += DurationString(idleTime * 1000 * 1000);
  580. tempString += "\n";
  581. int32 serverTime = strtoul(signOnTime.String(), NULL, 0);
  582. struct tm ptr;
  583. time_t st;
  584. char str[80];
  585. st = serverTime;
  586. localtime_r (&st, &ptr);
  587. strftime (str,80,"%A %b %d %Y %I:%M %p %Z", &ptr);
  588. BString signOnTimeParsed (str);
  589. signOnTimeParsed.RemoveAll ("\n");
  590. tempString2 += S_PENUM_SIGNON;
  591. tempString2 += signOnTimeParsed;
  592. tempString2 += "\n";
  593. BMessage msg (M_DISPLAY);
  594. PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  595. PostActive (&msg);
  596. PackDisplay (&msg, tempString2.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  597. PostActive (&msg);
  598. }
  599. return true;
  600. case RPL_ENDOFWHOIS: // 318
  601. case RPL_ENDOFNAMES: // 366
  602. case RPL_ENDOFWHOWAS: // 369
  603. {
  604. // nothing
  605. }
  606. return true;
  607. case RPL_WHOISCHANNELS: // 319
  608. {
  609. BString theChannels (RestOfString (data, 5));
  610. theChannels.RemoveFirst(":");
  611. BMessage display (M_DISPLAY);
  612. BString buffer;
  613. buffer += S_PENUM_WHOIS_CHANNELS;
  614. buffer += theChannels;
  615. buffer += "\n";
  616. PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  617. PostActive (&display);
  618. }
  619. return true;
  620. case RPL_LISTSTART: // 321
  621. {
  622. BMessage msg (M_LIST_BEGIN);
  623. if (fListAgent)
  624. vision_app->pClientWin()->DispatchMessage(&msg, (BView *)fListAgent);
  625. }
  626. return true;
  627. case RPL_LIST: // 322
  628. {
  629. BMessage msg (M_LIST_EVENT);
  630. BString channel (GetWord (data, 4)),
  631. users (GetWord (data, 5)),
  632. topic (RestOfString (data, 6));
  633. topic.RemoveFirst (":");
  634. msg.AddString ("channel", channel.String());
  635. msg.AddString ("users", users.String());
  636. msg.AddString ("topic", topic.String());
  637. if (fListAgent)
  638. vision_app->pClientWin()->DispatchMessage(&msg, (BView *)fListAgent);
  639. }
  640. return true;
  641. case RPL_LISTEND: // 323
  642. {
  643. BMessage msg (M_LIST_DONE);
  644. if (fListAgent)
  645. vision_app->pClientWin()->DispatchMessage(&msg, (BView *)fListAgent);
  646. }
  647. return true;
  648. case RPL_CHANNELMODEIS: // 324
  649. {
  650. BString theChan (GetWord (data, 4)),
  651. theMode (GetWord (data, 5)),
  652. tempStuff (RestOfString (data, 6));
  653. if (tempStuff != "-9z99")
  654. {
  655. theMode.Append(" ");
  656. theMode.Append(tempStuff); // avoid extra space w/o params
  657. }
  658. ClientAgent *aClient (ActiveClient()),
  659. *theClient (Client (theChan.String()));
  660. BString tempString(S_PENUM_CHANMODE);
  661. tempString += theChan;
  662. tempString += ": ";
  663. tempString += theMode;
  664. tempString += '\n';
  665. BMessage msg (M_CHANNEL_MODES);
  666. msg.AddString ("msgz", tempString.String());
  667. msg.AddString ("chan", theChan.String());
  668. msg.AddString ("mode", theMode.String());
  669. if (theClient)
  670. theClient->fMsgr.SendMessage (&msg);
  671. else if (aClient)
  672. aClient->fMsgr.SendMessage (&msg);
  673. else
  674. Display (tempString.String(), C_OP);
  675. }
  676. return true;
  677. case RPL_CHANNELMLOCK: // 325
  678. {
  679. BString theChan (GetWord (data, 4)),
  680. mLock (GetWord (data, 8)),
  681. lockMessage (S_PENUM_MLOCK);
  682. lockMessage += theChan;
  683. lockMessage += ": ";
  684. lockMessage += mLock;
  685. lockMessage += "\n";
  686. BMessage display (M_DISPLAY);
  687. PackDisplay (&display, lockMessage.String(), C_OP, C_BACKGROUND, F_TEXT);
  688. ClientAgent *theClient (Client (theChan.String()));
  689. if (theClient)
  690. theClient->fMsgr.SendMessage (&display);
  691. else
  692. fMsgr.SendMessage (&display);
  693. }
  694. return true;
  695. case RPL_CHANNELCREATED: // 329
  696. {
  697. BString theChan (GetWord (data, 4)),
  698. theTime (GetWord (data, 5)),
  699. tempString;
  700. int32 serverTime (strtoul(theTime.String(), NULL, 0));
  701. struct tm ptr;
  702. time_t st;
  703. char str[80];
  704. st = serverTime;
  705. localtime_r (&st, &ptr);
  706. strftime (str,80,"%a %b %d %Y %I:%M %p %Z",&ptr);
  707. BString theTimeParsed (str);
  708. theTimeParsed.RemoveAll ("\n");
  709. tempString += theChan;
  710. tempString += " " S_PENUM_CHANCREATED " ";
  711. tempString += theTimeParsed;
  712. tempString += '\n';
  713. Display (tempString.String());
  714. }
  715. return true;
  716. case RPL_NOTOPIC: // 331
  717. {
  718. BString theChan (GetWord (data, 4)),
  719. tempString (S_PENUM_NO_TOPIC);
  720. tempString += theChan;
  721. tempString += '\n';
  722. BMessage msg (M_DISPLAY);
  723. PackDisplay (&msg, tempString.String(), C_ERROR);
  724. PostActive (&msg);
  725. }
  726. return true;
  727. case RPL_TOPIC: // 332
  728. {
  729. BString theChannel (GetWord (data, 4)),
  730. theTopic (RestOfString (data, 5));
  731. ClientAgent *client (Client (theChannel.String()));
  732. theTopic.RemoveFirst (":");
  733. if (client)
  734. {
  735. BMessage display (M_DISPLAY);
  736. BString buffer;
  737. buffer += S_PENUM_DISP_TOPIC;
  738. buffer += theTopic;
  739. buffer += '\n';
  740. PackDisplay (&display, buffer.String(), C_WHOIS);
  741. BMessage msg (M_CHANNEL_TOPIC);
  742. msg.AddString ("topic", theTopic.String());
  743. msg.AddMessage ("display", &display);
  744. if (client->fMsgr.IsValid())
  745. client->fMsgr.SendMessage (&msg);
  746. }
  747. }
  748. return true;
  749. case RPL_TOPICSET: // 333
  750. {
  751. BString channel (GetWord (data, 4)),
  752. user (GetWord (data, 5)),
  753. theTime (GetWord (data, 6));
  754. int32 serverTime (strtoul(theTime.String(), NULL, 0));
  755. struct tm ptr;
  756. time_t st;
  757. char str[80];
  758. st = serverTime;
  759. localtime_r (&st, &ptr);
  760. strftime (str,80,"%A %b %d %Y %I:%M %p %Z",&ptr);
  761. BString theTimeParsed (str);
  762. theTimeParsed.RemoveAll ("\n");
  763. ClientAgent *client (Client (channel.String()));
  764. if (client)
  765. {
  766. BMessage display (M_DISPLAY);
  767. BString buffer;
  768. buffer += S_PENUM_TOPIC_SET_BY;
  769. buffer += user;
  770. buffer += " @ ";
  771. buffer += theTimeParsed;
  772. buffer += '\n';
  773. PackDisplay (&display, buffer.String(), C_WHOIS);
  774. if (client->fMsgr.IsValid())
  775. client->fMsgr.SendMessage (&display);
  776. }
  777. }
  778. return true;
  779. case RPL_INVITING: // 341
  780. {
  781. BString channel (GetWord (data, 5)),
  782. theNick (GetWord (data, 4)),
  783. tempString;
  784. tempString += "*** ";
  785. tempString += theNick;
  786. tempString += S_PENUM_INVITING;
  787. tempString += channel;
  788. tempString += ".\n";
  789. BMessage display (M_DISPLAY);
  790. PackDisplay (&display, tempString.String(), C_WHOIS);
  791. PostActive (&display);
  792. }
  793. return true;
  794. case RPL_NAMEREPLY: // 353
  795. {
  796. BString channel (GetWord (data, 5)),
  797. names (RestOfString (data, 6));
  798. ClientAgent *client (Client (channel.String()));
  799. names.RemoveFirst (":");
  800. BString tempString (S_PENUM_NAMEREPLY);
  801. tempString += channel;
  802. tempString += ": ";
  803. tempString += names;
  804. tempString += '\n';
  805. Display (tempString.String(), C_TEXT);
  806. if (client) // in the channel
  807. {
  808. BMessage msg (M_CHANNEL_NAMES);
  809. BString nick;
  810. int32 place (1);
  811. while ((nick = GetWord (names.String(), place)) != "-9z99")
  812. {
  813. const char *sNick (nick.String());
  814. bool founder (false),
  815. protect (false),
  816. op (false),
  817. voice (false),
  818. helper (false),
  819. ignored;
  820. if (nick[0] == '*')
  821. {
  822. ++sNick;
  823. founder = true;
  824. }
  825. else if (nick[0] == '!')
  826. {
  827. ++sNick;
  828. protect = true;
  829. }
  830. else if (nick[0] == '@')
  831. {
  832. ++sNick;
  833. op = true;
  834. }
  835. else if (nick[0] == '+')
  836. {
  837. ++sNick;
  838. voice = true;
  839. }
  840. else if (nick[0] == '%')
  841. {
  842. ++sNick;
  843. helper = true;
  844. }
  845. ignored = false;
  846. // BMessage aMsg (M_IS_IGNORED), reply;
  847. // aMsg.AddString ("server", fServerName.String());
  848. // aMsg.AddString ("nick", sNick);
  849. // be_app_messenger.SendMessage (&aMsg, &reply);
  850. // reply.FindBool ("ignored", &ignored);
  851. msg.AddString ("nick", nick.String());
  852. msg.AddBool ("founder", founder);
  853. msg.AddBool ("protect", protect);
  854. msg.AddBool ("op", op);
  855. msg.AddBool ("voice", voice);
  856. msg.AddBool ("helper", helper);
  857. msg.AddBool ("ignored", ignored);
  858. ++place;
  859. }
  860. if (client->fMsgr.IsValid())
  861. client->fMsgr.SendMessage (&msg);
  862. }
  863. }
  864. return true;
  865. case RPL_MOTD: // 372
  866. case RPL_MOTDALT: // 378
  867. case RPL_OPERMOTDSTART: // 609
  868. case RPL_OPERMOTD: // 610
  869. case RPL_OPERENDOFMOTD: // 611
  870. {
  871. BString tempString (RestOfString(data, 4));
  872. tempString.RemoveFirst (":");
  873. tempString.Append ("\n");
  874. Display (tempString.String(), C_SERVER, C_BACKGROUND, F_SERVER);
  875. }
  876. return true;
  877. case RPL_MOTDSTART: // 375
  878. {
  879. BString tempString (S_PENUM_SERVER_MOTD "\n");
  880. Display (tempString.String(), C_SERVER, C_BACKGROUND, F_SERVER);
  881. }
  882. return true;
  883. case RPL_ENDOFMOTD: // 376
  884. case ERR_NOMOTD: // 422
  885. {
  886. BString tempString (RestOfString (data, 4));
  887. tempString.RemoveFirst (":");
  888. tempString.Append ("\n");
  889. Display (tempString.String(), C_SERVER, C_BACKGROUND, F_SERVER);
  890. if (fInitialMotd && fCmds.Length())
  891. {
  892. BMessage msg (M_SUBMIT_INPUT);
  893. const char *place (fCmds.String()), *eol;
  894. msg.AddInt32 ("which", PASTE_MULTI_NODELAY);
  895. while ((eol = strchr (place, '\n')) != 0)
  896. {
  897. BString line;
  898. line.Append (place, eol - place);
  899. msg.AddString ("data", line.String());
  900. ParseAutoexecChans (line);
  901. place = eol + 1;
  902. }
  903. if (*place)
  904. {
  905. // check in case this was the only line
  906. ParseAutoexecChans (BString(place));
  907. msg.AddString ("data", place);
  908. }
  909. msg.AddInt32 ("which", 3);
  910. msg.AddBool ("autoexec", true);
  911. fMsgr.SendMessage (&msg);
  912. }
  913. if (fLocalip_private)
  914. {
  915. BString IPCommand ("/userhost ");
  916. IPCommand += fMyNick;
  917. ParseCmd (IPCommand.String());
  918. }
  919. if (fReconnecting)
  920. {
  921. const char *reString;
  922. reString = S_PENUM_RECON_SUCCESS "\n";
  923. Display (reString, C_ERROR);
  924. DisplayAll (reString, C_ERROR, C_BACKGROUND, F_SERVER);
  925. fMsgr.SendMessage (M_REJOIN_ALL);
  926. fReconnecting = false;
  927. }
  928. fInitialMotd = false;
  929. }
  930. return true;
  931. case RPL_USERSSTART: // 392
  932. {
  933. // empty for now
  934. }
  935. return true;
  936. case RPL_USERS: // 393
  937. {
  938. // empty for now
  939. }
  940. return true;
  941. case ERR_ERRONEOUSNICKNAME: // 432
  942. case ERR_NICKNAMEINUSE: // 433
  943. case ERR_RESOURCEUNAVAILABLE: // 437
  944. {
  945. BString theNick (GetWord (data, 4));
  946. if (fIsConnecting)
  947. {
  948. BString nextNick (GetNextNick());
  949. if (nextNick != "")
  950. {
  951. Display (S_PENUM_NICKINUSE1);
  952. Display (theNick.String());
  953. Display (S_PENUM_NICKINUSE2);
  954. Display (nextNick.String());
  955. Display ("\"\n");
  956. BString tempString ("NICK ");
  957. tempString += nextNick;
  958. SendData (tempString.String());
  959. return true;
  960. }
  961. else
  962. {
  963. Display (S_PENUM_ALLNICKSUSED1 "\n");
  964. Display (S_PENUM_ALLNICKSUSED2 "\n");
  965. return true;
  966. }
  967. }
  968. BString tempString;
  969. tempString += S_PENUM_NICKINUSE3;
  970. tempString += theNick;
  971. tempString += S_PENUM_NICKINUSE4 "\n";
  972. BMessage display (M_DISPLAY);
  973. PackDisplay (&display, tempString.String(), C_NICK);
  974. PostActive (&display);
  975. }
  976. return true;
  977. case ERR_USERNOTINCHANNEL: // 441
  978. {
  979. BString theChannel (GetWord (data, 5)),
  980. theNick (GetWord (data, 4)),
  981. tempString ("[x] ");
  982. tempString += theNick;
  983. tempString += S_PENUM_NOTINCHANNEL;
  984. tempString += theChannel;
  985. tempString += ".\n";
  986. BMessage msg (M_DISPLAY);
  987. PackDisplay (&msg, tempString.String(), C_ERROR);
  988. PostActive (&msg);
  989. }
  990. return true;
  991. case ERR_NOTONCHANNEL: // 442
  992. {
  993. BString theChannel (GetWord (data, 4)),
  994. tempString (S_PENUM_ME_NOTINCHANNEL);
  995. tempString += theChannel;
  996. tempString += ".\n";
  997. BMessage msg (M_DISPLAY);
  998. PackDisplay (&msg, tempString.String(), C_ERROR);
  999. PostActive (&msg);
  1000. }
  1001. return true;
  1002. case ERR_USERONCHANNEL: // 443
  1003. {
  1004. BString theChannel (GetWord (data, 5)),
  1005. theNick (GetWord (data, 4)),
  1006. tempString ("[x] ");
  1007. tempString += theNick;
  1008. tempString += S_PENUM_ALREADYINCHANNEL;
  1009. tempString += theChannel;
  1010. tempString += ".\n";
  1011. BMessage msg (M_DISPLAY);
  1012. PackDisplay (&msg, tempString.String(), C_ERROR);
  1013. PostActive (&msg);
  1014. }
  1015. return true;
  1016. case ERR_KEYSET: // 467
  1017. {
  1018. BString theChannel (GetWord (data, 4)),
  1019. tempString (S_PENUM_KEY_ALREADY_SET);
  1020. tempString += theChannel;
  1021. tempString += ".\n";
  1022. BMessage msg (M_DISPLAY);
  1023. PackDisplay (&msg, tempString.String(), C_ERROR);
  1024. PostActive (&msg);
  1025. }
  1026. return true;
  1027. case ERR_UNKNOWNMODE: // 472
  1028. {
  1029. BString theMode (GetWord (data, 4)),
  1030. tempString (S_PENUM_UNKNOWNCHANMODE);
  1031. tempString += theMode;
  1032. tempString += "'\n";
  1033. BMessage msg (M_DISPLAY);
  1034. PackDisplay (&msg, tempString.String(), C_QUIT);
  1035. PostActive (&msg);
  1036. }
  1037. return true;
  1038. case ERR_INVITEONLYCHAN: // 473
  1039. {
  1040. BString theChan (GetWord (data, 4)),
  1041. tempString ("[x] "),
  1042. theReason (RestOfString (data, 5));
  1043. theReason.RemoveFirst(":");
  1044. theReason.ReplaceLast("channel", theChan.String());
  1045. tempString += theReason;
  1046. tempString += S_PENUM_INVITE_ONLY "\n";
  1047. BMessage msg (M_DISPLAY);
  1048. PackDisplay (&msg, tempString.String(), C_QUIT, C_BACKGROUND, F_SERVER);
  1049. PostActive (&msg);
  1050. RemoveAutoexecChan (theChan);
  1051. }
  1052. return true;
  1053. case ERR_BANNEDFROMCHAN: // 474
  1054. {
  1055. BString theChan (GetWord (data, 4)),
  1056. tempString ("[x] "),
  1057. theReason (RestOfString (data, 5));
  1058. theReason.RemoveFirst(":");
  1059. theReason.ReplaceLast("channel", theChan.String());
  1060. tempString += theReason;
  1061. tempString += S_PENUM_BANNED "\n";
  1062. BMessage msg (M_DISPLAY);
  1063. PackDisplay (&msg, tempString.String(), C_QUIT, C_BACKGROUND, F_SERVER);
  1064. PostActive (&msg);
  1065. RemoveAutoexecChan (theChan);
  1066. }
  1067. return true;
  1068. case ERR_BADCHANNELKEY: // 475
  1069. {
  1070. BString theChan (GetWord(data, 4)),
  1071. theReason (RestOfString(data, 5)),
  1072. tempString("[x] ");
  1073. theReason.RemoveFirst(":");
  1074. theReason.ReplaceLast("channel", theChan.String());
  1075. tempString += theReason;
  1076. tempString += S_PENUM_BADCHANKEY "\n";
  1077. BMessage msg (M_DISPLAY);
  1078. PackDisplay (&msg, tempString.String(), C_QUIT, C_BACKGROUND, F_SERVER);
  1079. PostActive (&msg);
  1080. RemoveAutoexecChan (theChan);
  1081. }
  1082. return true;
  1083. case ERR_UMODEUNKNOWNFLAG: // 501
  1084. {
  1085. BMessage msg (M_DISPLAY);
  1086. BString buffer;
  1087. buffer += S_PENUM_UNKNOWNMODE "\n";
  1088. PackDisplay (&msg, buffer.String(), C_QUIT);
  1089. PostActive (&msg);
  1090. }
  1091. return true;
  1092. // not sure what these numerics are,
  1093. // but they are usually on-connect messages
  1094. case RPL_290: // 290
  1095. case RPL_291: // 291
  1096. case RPL_292: // 292
  1097. {
  1098. BString tempString (RestOfString(data, 4));
  1099. tempString.RemoveFirst (":");
  1100. tempString.Append ("\n");
  1101. tempString.Prepend ("- ");
  1102. Display (tempString.String());
  1103. }
  1104. return true;
  1105. case RPL_WHOISREGISTEREDBOT: // 617
  1106. {
  1107. // conflicts with RPL_DCCALLOWCHANGE
  1108. BString theNick (GetWord (data, 4)),
  1109. theMessage (RestOfString (data, 5)),
  1110. tempString;
  1111. theNick.RemoveFirst (":");
  1112. theMessage.RemoveFirst (":");
  1113. theMessage.Append ("\n");
  1114. switch (fIrcdtype)
  1115. {
  1116. case IRCD_ULTIMATE:
  1117. {
  1118. tempString += "[@] ";
  1119. tempString += theMessage;
  1120. BMessage msg (M_DISPLAY);
  1121. PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER);
  1122. PostActive (&msg);
  1123. }
  1124. break;
  1125. default:
  1126. {
  1127. tempString += theNick;
  1128. tempString += " ";
  1129. tempString += theMessage;
  1130. Display (tempString.String());
  1131. }
  1132. }
  1133. }
  1134. return true;
  1135. default:
  1136. break;
  1137. }
  1138. return false;
  1139. }