Guest User

Untitled

a guest
Jun 20th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.14 KB | None | 0 0
  1. #include "xchat-plugin.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6.  
  7. #define PNAME "SNOT-FILTER"
  8. #define PDESC "Unreal/Anope SNOTICE FILTER"
  9. #define PVERSION "0.2"
  10.  
  11.  
  12. static xchat_plugin *ph;
  13.  
  14. static xchat_hook *who_hook;
  15. static xchat_hook *unhook;
  16.  
  17. static const char *clientTab = "-Clients";
  18. static const char *clientWhoCmd = "who +n-m * S";
  19.  
  20. static const char *helpoptab = "-HelpOp";
  21. static const char *HelpOp = "HelpOp";
  22. static const char *helpopWhoCmd = "who +m-m h S";
  23.  
  24. static const char *chatops = "ChatOps";
  25. static const char *chatopsTab = "-ChatOps";
  26. static const char *chatopsWhoCmd = "who +m-m oO S";
  27.  
  28. static const char *adchat = "AdminChat";
  29. static const char *adchatTab = "-AdChat";
  30. static const char *adchatWhoCmd = "who +m-m aA S";
  31.  
  32. static const char *locops = "LocOps";
  33. static const char *locopsTab = "-LocOps";
  34. static const char *locopsWhoCmd = "who +m-m o S";
  35.  
  36. static const char *nachat = "NetAdmin.Chat";
  37. static const char *nachatTab = "-NAChat";
  38. static const char *nachatWhoCmd = "who +m-m N S";
  39.  
  40. static const char *globops = "Global";
  41. static const char *globopsTab = "-GlobOps";
  42. static const char *globopsWhoCmd = "who +m o";
  43.  
  44. static const char *idleTab = "-Idle";
  45. static const char *idleWhoCmd = "who +i *";
  46.  
  47. static const char *whatTab;
  48. static const char *whoCmd;
  49.  
  50. time_t whoStart, whoEnd;
  51. int whoCounter = 0;
  52.  
  53. char clients[20000];
  54.  
  55. /* Server notices */
  56. static int snotice_cb (char *word[], char *word_eol[], void *userdata);
  57.  
  58. /* Who command hook */
  59. static int who_cmd_cb (char *word[], char *word_eol[], void *userdata);
  60.  
  61. /* Who list data */
  62. static int who_list_cb (char *word[], char *word_eol[], void *userdata);
  63.  
  64. /* End of Who List unhooks everything */
  65. static int unhook_who_cb (char *word[], char *word_eol[], void *userdata);
  66.  
  67. /* Blocks certain raw server notices when tabs are open */
  68. static int block_raws_cb (char *word[], char *word_eol[], void *userdata);
  69.  
  70. /* Blocks several text events from printing in -Clients tab */
  71. static int block_prints_cb (char *word[], void *userdata);
  72.  
  73. /* Converts to correct command depending on the channel */
  74. static int helpop_cmd_cb (char *word[], char *word_eol[], void *userdata);
  75.  
  76. /* Needed for -Idle tab command handler */
  77. static int idle_cmd_cb (char *word[], char *word_eol[], void *userdata);
  78.  
  79. /* Joins to fake channel tabs and prints message */
  80. void print_shit (char *word[], char *word_eol[]);
  81.  
  82. /* Creates queries and prints server notices */
  83. void print_to_query (char *tab, char *type, char *msg);
  84.  
  85. /* Helps prevent /who command flooding */
  86. static int check_time ();
  87.  
  88. /* Updates Userlists of fake tabs that are opened */
  89. void update_userlist ();
  90.  
  91. static int searchText (char *text, const char *nicks);
  92.  
  93. static int is_hilight (char *text);
  94.  
  95. void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
  96. {
  97. *name = PNAME;
  98. *desc = PDESC;
  99. *version = PVERSION;
  100. }
  101.  
  102.  
  103. int xchat_plugin_init(xchat_plugin *plugin_handle, char **plugin_name,
  104. char **plugin_desc, char **plugin_version, char *arg)
  105. {
  106. ph = plugin_handle;
  107.  
  108. *plugin_name = PNAME;
  109. *plugin_desc = PDESC;
  110. *plugin_version = PVERSION;
  111.  
  112. xchat_hook_server(ph, "NOTICE", XCHAT_PRI_NORM, snotice_cb, NULL);
  113.  
  114. xchat_hook_command(ph, "who", XCHAT_PRI_NORM, who_cmd_cb, NULL, NULL);
  115. xchat_hook_command(ph, "", XCHAT_PRI_NORM, helpop_cmd_cb, NULL, NULL);
  116. xchat_hook_command(ph, "notinchan", XCHAT_PRI_NORM, idle_cmd_cb, NULL, NULL);
  117.  
  118. xchat_hook_server(ph, "401", XCHAT_PRI_NORM, block_raws_cb, NULL);
  119. xchat_hook_server(ph, "403", XCHAT_PRI_NORM, block_raws_cb, NULL);
  120. xchat_hook_server(ph, "334", XCHAT_PRI_NORM, block_raws_cb, NULL);
  121.  
  122. xchat_hook_print(ph, "Users On Channel", XCHAT_PRI_NORM, block_prints_cb, NULL);
  123. xchat_hook_print(ph, "Part", XCHAT_PRI_NORM, block_prints_cb, NULL);
  124. xchat_hook_print(ph, "Change Nick", XCHAT_PRI_NORM, block_prints_cb, NULL);
  125. xchat_hook_print(ph, "Quit", XCHAT_PRI_NORM, block_prints_cb, NULL);
  126.  
  127. whoStart = time(NULL);
  128.  
  129. xchat_print(ph, "SNOTICES DEBUG LOADED");
  130.  
  131. return XCHAT_EAT_XCHAT;
  132. }
  133.  
  134.  
  135. static int snotice_cb (char *word[], char *word_eol[], void *userdata)
  136. {
  137. static const char *currentServer;
  138. static const char *yourNickname;
  139.  
  140. if (strcmp(word[5], "Notice") == 0) // Notice --
  141. {
  142. if (strcmp(word[7], "Client") == 0) // Clients
  143. {
  144. whatTab = clientTab;
  145. whoCmd = clientWhoCmd;
  146.  
  147. char *userHost, *nickName, *userAddress;
  148.  
  149. currentServer = xchat_get_info(ph, (char*)"server");
  150. yourNickname = xchat_get_info(ph, (char*)"nick");
  151.  
  152. char type[100], text[100];
  153.  
  154. if (strcmp(word[9], "at") == 0) /* Remote */
  155. {
  156. /* Connect */
  157. if (strcmp(word[8], "connecting") == 0)
  158. {
  159. nickName = word[11];
  160. userHost = word[12];
  161. sprintf(type, "%s", "\002\0033[C]");
  162.  
  163. xchat_commandf(ph, "recv :%s 353 %s = %s :%s",
  164. currentServer, yourNickname, whatTab, nickName);
  165. }
  166.  
  167. else /* Exit */
  168. {
  169. userAddress = word[11];
  170. nickName = strdup(userAddress);
  171. userHost = strrchr(nickName, '!');
  172. *userHost++ = '\0';
  173.  
  174. sprintf(type, "%s", "\002\0032[E]");
  175.  
  176. xchat_commandf(ph, "recv :%s!meow@blah.com PART %s",
  177. nickName, whatTab);
  178. }
  179. }
  180.  
  181. else /* local */
  182. {
  183. if (strcmp(word[8], "connecting") == 0) /* Connect */
  184. {
  185. nickName = word[12];
  186. userHost = word[13];
  187. sprintf(type, "%s", "\002\0033[C]");
  188.  
  189. xchat_commandf(ph, "recv :%s 353 %s = %s :%s",
  190. currentServer, yourNickname, whatTab, nickName);
  191. }
  192.  
  193. else /* Exit */
  194. {
  195. nickName = word[9];
  196. userHost = word[10];
  197. sprintf(type, "%s", "\002\0032[E]");
  198.  
  199. xchat_commandf(ph, "recv :%s!meow@blah.com PART %s",
  200. nickName, whatTab);
  201. }
  202. }
  203.  
  204. sprintf(text, "\002%s\017 %s", nickName, userHost);
  205.  
  206. if (!xchat_find_context(ph, currentServer, whatTab))
  207. {
  208. if (check_time() == 1)
  209. {
  210. xchat_commandf(ph, "TIMER 1 %s", whoCmd);
  211. }
  212.  
  213. xchat_commandf(ph, "RECV :%s!blah@blah.net JOIN :%s",
  214. yourNickname, whatTab);
  215. }
  216.  
  217. xchat_set_context(ph, xchat_find_context(ph, currentServer, clientTab));
  218. xchat_emit_print(ph, "Channel Message", type, text, NULL, NULL);
  219. xchat_command(ph, "GUI COLOR 0");
  220.  
  221. return XCHAT_EAT_XCHAT;
  222. }
  223.  
  224. else if (strcmp(word[9], "has") == 0) /* Nick change */
  225. {
  226. char msg[100];
  227.  
  228. if (strcmp(word[13], "to") == 0) /* not forced nick change */
  229. {
  230. sprintf(msg, "is now \002%s\017 %s", word[14], word[8]);
  231. xchat_commandf(ph, "RECV :%s!blah.net NICK :%s", word[7], word[14]);
  232. print_to_query("-NickChange", word[7], msg);
  233.  
  234. return XCHAT_EAT_XCHAT;
  235. }
  236.  
  237. else /* Forced nick change */
  238. {
  239. sprintf(msg, "is now \002%s\017 %s", word[17], word[8]);
  240. xchat_commandf(ph, "RECV :%s!blah.net NICK :%s", word[7], word[17]);
  241. print_to_query("-NickChange", word[7], msg);
  242.  
  243. return XCHAT_EAT_XCHAT;
  244. }
  245.  
  246. return XCHAT_EAT_NONE;
  247. }
  248.  
  249. /* Network Crap */
  250. else if (strcmp(word[7], "(link)") == 0 ||
  251. strcmp(word[7], "Possible") == 0 ||
  252. strcmp(word[7], "Link") == 0)
  253. {
  254. print_to_query("-Global", word[7], word_eol[8]);
  255. return XCHAT_EAT_XCHAT;
  256. }
  257.  
  258. else if (strcmp(word[7], "TS") == 0) /* TS Control */
  259. {
  260. print_to_query("-Services", "TS Control", word_eol[10]);
  261. return XCHAT_EAT_XCHAT;
  262. }
  263.  
  264. return XCHAT_EAT_NONE;
  265. }
  266.  
  267. else if (strcmp(HelpOp, word[5]) == 0) /* HelpOp */
  268. {
  269. whatTab = helpoptab;
  270. whoCmd = helpopWhoCmd;
  271. print_shit(word, word_eol);
  272. }
  273.  
  274. else if (strcmp(chatops, word[5]) == 0) /* ChatOps */
  275. {
  276. whatTab = chatopsTab;
  277. whoCmd = chatopsWhoCmd;
  278. print_shit(word, word_eol);
  279. }
  280.  
  281. else if (strcmp(adchat, word[5]) == 0) /* AdChat */
  282. {
  283. whatTab = adchatTab;
  284. whoCmd = adchatWhoCmd;
  285. print_shit(word, word_eol);
  286. }
  287.  
  288. else if (strcmp(nachat, word[5]) == 0) /* NAChat */
  289. {
  290. whatTab = nachatTab;
  291. whoCmd = nachatWhoCmd;
  292. print_shit(word, word_eol);
  293. }
  294.  
  295. else if (strcmp(locops, word[5]) == 0) /* LocOps */
  296. {
  297. whatTab = locopsTab;
  298. whoCmd = locopsWhoCmd;
  299. print_shit(word, word_eol);
  300. }
  301.  
  302. /* Global */
  303. else if (strcmp(globops, word[5]) == 0 && strcmp("--", word[6]) == 0)
  304. {
  305. char *text, *nick, *text2, *server;
  306.  
  307. char *nickName, *meh, *blah;
  308.  
  309. meh = word[8];
  310. nickName = strdup(meh);
  311. blah = strrchr(nickName, ':');
  312. if (blah)
  313. {
  314. *blah++ = '\0';
  315. }
  316.  
  317. text = strdup(nickName);
  318. text2 = strdup(nickName);
  319.  
  320. nick = strrchr(text, 'S');
  321. server = strrchr(text2, '.');
  322.  
  323. /* Global server notice */
  324. if (server &&
  325. (strcmp(server, ".net") == 0 ||
  326. strcmp(server, ".com") == 0 ||
  327. strcmp(server, ".org") == 0))
  328. {
  329. print_to_query("-Services", nickName, word_eol[9]);
  330. }
  331.  
  332. /* Anope Services message */
  333. else if (nick && strcmp(nick, "Serv") == 0)
  334. {
  335. print_to_query("-Services", nickName, word_eol[9]);
  336. }
  337.  
  338. else /* If opers are actually communicating */
  339. {
  340. whatTab = globopsTab;
  341. whoCmd = globopsWhoCmd;
  342. print_shit(word, word_eol);
  343. }
  344.  
  345. return XCHAT_EAT_XCHAT;
  346. }
  347.  
  348. /* Need to test these */
  349. else if (strcmp("Stats", word[4]) == 0 ||
  350. strcmp("Forbidding", word[4]) == 0 ||
  351. strcmp("Failed", word[4]) == 0 ||
  352. strcmp("[Spamfilter]", word[4]) == 0 ||
  353. strcmp("(link)", word[4]) == 0 ||
  354. strcmp("(sync)", word[4]) == 0)
  355. {
  356. print_to_query("-Global", word[4], word_eol[5]);
  357. return XCHAT_EAT_NONE;
  358. }
  359.  
  360. /* Need to test */
  361. else if (strcmp("OperOverride", word[5]) == 0 ||
  362. strcmp("Flood", word[5]) == 0)
  363. {
  364. print_to_query("-Global", word[5], word_eol[7]);
  365. return XCHAT_EAT_NONE;
  366. }
  367.  
  368. /* Need to test */
  369. else if (strcmp("Spamfilter", word[5]) == 0) /* Spamfilter */
  370. {
  371. print_to_query("-Global", word[5], word_eol[6]);
  372. return XCHAT_EAT_NONE;
  373. }
  374.  
  375. /* Expired & Permament Bans */
  376. else if (strcmp("Expiring", word[5]) == 0 || strcmp("Permanent", word[5]) == 0)
  377. {
  378. print_to_query("-Bans", word[5], word_eol[6]);
  379. }
  380.  
  381. else if (strcmp("removed", word[5]) == 0) /* Removed Bans */
  382. {
  383. print_to_query("-Bans", "Removed", word_eol[4]);
  384. }
  385.  
  386. /* Added Server Bans */
  387. else if (strcmp("added", word[6]) == 0 && strcmp("for", word[7]) == 0)
  388. {
  389. print_to_query("-Bans", "Added", word_eol[5]);
  390. }
  391.  
  392. /* Added Global Server Bans */
  393. else if (strcmp("added", word[7]) == 0 && strcmp("for", word[8]) == 0)
  394. {
  395. print_to_query("-Bans", "Added", word_eol[5]);
  396. }
  397.  
  398. else if (strcmp("did a /whois on you.", word_eol[7]) == 0) /* whois */
  399. {
  400. print_to_query("-Global", word[5], word_eol[7]);
  401. }
  402.  
  403. /* When people oper up */
  404. else if (strcmp("is", word[7]) == 0 && strcmp("now", word[8]) == 0)
  405. {
  406. if (check_time() == 1)
  407. {
  408. update_userlist();
  409. }
  410.  
  411. print_to_query("-Global", "Oper", word_eol[5]);
  412. }
  413.  
  414. else if (strcmp("KILL", word_eol[8]) == 0) /* Kills */
  415. {
  416. print_to_query("-Bans", "Kill", word_eol[9]);
  417. }
  418.  
  419. else
  420. {
  421. return XCHAT_EAT_NONE;
  422. }
  423.  
  424. return XCHAT_EAT_XCHAT;
  425. }
  426.  
  427.  
  428. static int idle_cmd_cb (char *word[], char *word_eol[], void *userdata)
  429. {
  430. whatTab = idleTab;
  431. whoCmd = idleWhoCmd;
  432.  
  433. static const char *yourNickname;
  434. yourNickname = xchat_get_info(ph, (char*)"nick");
  435.  
  436. xchat_commandf(ph, "RECV :%s!blah@blah.net JOIN :%s",
  437. yourNickname, whatTab);
  438.  
  439. xchat_commandf(ph, "TIMER 1 %s", whoCmd);
  440.  
  441. if (who_hook != NULL)
  442. {
  443. xchat_unhook(ph, who_hook);
  444. who_hook = NULL;
  445. }
  446.  
  447. who_hook = xchat_hook_server(ph, "352", XCHAT_PRI_NORM, who_list_cb, NULL);
  448.  
  449. return XCHAT_EAT_NONE;
  450. }
  451.  
  452.  
  453. static int who_cmd_cb (char *word[], char *word_eol[], void *userdata)
  454. {
  455. if ((strcmp(clientWhoCmd, word_eol[1]) == 0) ||
  456. (strcmp(locopsWhoCmd, word_eol[1]) == 0) ||
  457. (strcmp(helpopWhoCmd, word_eol[1]) == 0) ||
  458. (strcmp(nachatWhoCmd, word_eol[1]) == 0) ||
  459. (strcmp(adchatWhoCmd, word_eol[1]) == 0) ||
  460. (strcmp(chatopsWhoCmd, word_eol[1]) == 0)||
  461. (strcmp(globopsWhoCmd, word_eol[1]) == 0))
  462. {
  463. if (who_hook != NULL)
  464. {
  465. xchat_unhook(ph, who_hook);
  466. who_hook = NULL;
  467. }
  468.  
  469. who_hook = xchat_hook_server(ph, "352", XCHAT_PRI_NORM, who_list_cb, NULL);
  470. }
  471.  
  472. return XCHAT_EAT_NONE;
  473. }
  474.  
  475.  
  476. static int who_list_cb (char *word[], char *word_eol[], void *userdata)
  477. {
  478. if (who_hook && strcmp(whatTab, idleTab) != 0)
  479. {
  480. clients[0] = ':';
  481. strcat(clients, word[8]);
  482. strcat(clients, " ");
  483.  
  484. if (unhook != NULL)
  485. {
  486. xchat_unhook(ph, unhook);
  487. unhook = NULL;
  488. }
  489.  
  490. unhook = xchat_hook_server(ph, "315", XCHAT_PRI_NORM, unhook_who_cb, NULL);
  491. }
  492.  
  493. else if (who_hook && strcmp(whatTab, idleTab) == 0 && word[4][0] != '#')
  494. {
  495. clients[0] = ':';
  496. strcat(clients, word[8]);
  497. strcat(clients, " ");
  498.  
  499. if (unhook != NULL)
  500. {
  501. xchat_unhook(ph, unhook);
  502. unhook = NULL;
  503. }
  504.  
  505. unhook = xchat_hook_server(ph, "315", XCHAT_PRI_NORM, unhook_who_cb, NULL);
  506. }
  507.  
  508. return XCHAT_EAT_XCHAT;
  509. }
  510.  
  511.  
  512. static int unhook_who_cb (char *word[], char *word_eol[], void *userdata)
  513. {
  514. xchat_unhook(ph, who_hook);
  515.  
  516. static const char *currentServer;
  517. static const char *yourNickname;
  518.  
  519. currentServer = xchat_get_info(ph, (char*)"server");
  520. yourNickname = xchat_get_info(ph, (char*)"nick");
  521.  
  522. xchat_commandf(ph, "RECV :%s 353 %s = %s %s",
  523. currentServer, yourNickname, whatTab, clients);
  524.  
  525. sprintf(clients, "%s", ":");
  526.  
  527. xchat_unhook(ph, unhook);
  528.  
  529. return XCHAT_EAT_XCHAT;
  530. }
  531.  
  532.  
  533. static int helpop_cmd_cb (char *word[], char *word_eol[], void *userdata)
  534. {
  535. static const char *currentTab;
  536.  
  537. currentTab = xchat_get_info(ph, (char*)"channel");
  538.  
  539. if (currentTab[0] == '-')
  540. {
  541. if (strcmp(currentTab, helpoptab) == 0)
  542. {
  543. xchat_commandf(ph, "helpop :%s", word_eol[1]);
  544. }
  545. else if (strcmp(currentTab, chatopsTab) == 0)
  546. {
  547. xchat_commandf(ph, "chatops :%s", word_eol[1]);
  548. }
  549. else if (strcmp(currentTab, adchatTab) == 0)
  550. {
  551. xchat_commandf(ph, "adchat :%s", word_eol[1]);
  552. }
  553. else if (strcmp(currentTab, nachatTab) == 0)
  554. {
  555. xchat_commandf(ph, "nachat :%s", word_eol[1]);
  556. }
  557. else if (strcmp(currentTab, locopsTab) == 0)
  558. {
  559. xchat_commandf(ph, "locops :%s", word_eol[1]);
  560. }
  561. else if (strcmp(currentTab, globopsTab) == 0)
  562. {
  563. xchat_commandf(ph, "globops :%s", word_eol[1]);
  564. }
  565.  
  566. else /* Blocks -Queries too */
  567. {
  568. xchat_printf(ph, "You cannot talk in %s", currentTab);
  569. }
  570. }
  571.  
  572. else
  573. {
  574. return XCHAT_EAT_NONE;
  575. }
  576.  
  577. return XCHAT_EAT_XCHAT;
  578. }
  579.  
  580.  
  581. /* Joins the fake channel to communicate with opers */
  582. void print_shit (char *word[], char *word_eol[])
  583. {
  584. static const char *currentServer;
  585. static const char *yourNickname;
  586.  
  587. currentServer = xchat_get_info(ph, (char*)"server");
  588. yourNickname = xchat_get_info(ph, (char*)"nick");
  589.  
  590. if (!xchat_find_context(ph, currentServer, whatTab))
  591. {
  592. xchat_commandf(ph, "RECV :%s!blah@blah.net JOIN :%s",
  593. yourNickname, whatTab);
  594.  
  595. xchat_commandf(ph, "TIMER 1 %s", whoCmd);
  596. }
  597.  
  598. if (strcmp(whatTab, helpoptab) == 0)
  599. {
  600. char *nickName;
  601. nickName = word[8];
  602.  
  603. xchat_set_context(ph, xchat_find_context(ph, currentServer, whatTab));
  604.  
  605. if (strcmp("me", word[10]) == 0)
  606. {
  607. if (strcmp(yourNickname, nickName) == 0)
  608. {
  609. xchat_emit_print(ph, "Your Action", nickName, word_eol[11], NULL, NULL);
  610. }
  611. else if (is_hilight(word_eol[11]))
  612. {
  613. xchat_emit_print(ph, "Channel Action Hilight", nickName, word_eol[11], NULL, NULL);
  614. xchat_command(ph, "GUI COLOR 2");
  615. }
  616. else
  617. {
  618. xchat_emit_print(ph, "Channel Action", nickName, word_eol[11], NULL, NULL);
  619. }
  620. }
  621. else
  622. {
  623. if (strcmp(yourNickname, nickName) == 0)
  624. {
  625. xchat_emit_print(ph, "Your Message", nickName, word_eol[10], NULL, NULL);
  626. }
  627. else if (is_hilight(word_eol[10]))
  628. {
  629. xchat_emit_print(ph, "Channel Msg Hilight", nickName, word_eol[10], NULL, NULL);
  630. xchat_command(ph, "GUI COLOR 2");
  631. }
  632. else
  633. {
  634. xchat_emit_print(ph, "Channel Message", nickName, word_eol[10], NULL, NULL);
  635. }
  636. }
  637. }
  638.  
  639. else
  640. {
  641. char *nickName, *meh, *blah;
  642.  
  643. meh = word[8];
  644. nickName = strdup(meh);
  645. blah = strrchr(nickName, ':');
  646. if (blah)
  647. {
  648. *blah++ = '\0';
  649. }
  650.  
  651. xchat_set_context(ph, xchat_find_context(ph, currentServer, whatTab));
  652.  
  653. if (strcmp("me", word[9]) == 0)
  654. {
  655. if (strcmp(yourNickname, nickName) == 0)
  656. {
  657. xchat_emit_print(ph, "Your Action", nickName, word_eol[10], NULL, NULL);
  658. }
  659. else if (is_hilight(word_eol[10]))
  660. {
  661. xchat_emit_print(ph, "Channel Action Hilight", nickName, word_eol[10], NULL, NULL);
  662. xchat_command(ph, "GUI COLOR 2");
  663. }
  664. else
  665. {
  666. xchat_emit_print(ph, "Channel Action", nickName, word_eol[10], NULL, NULL);
  667. }
  668. }
  669. else
  670. {
  671. if (strcmp(yourNickname, nickName) == 0)
  672. {
  673. xchat_emit_print(ph, "Your Message", nickName, word_eol[9], NULL, NULL);
  674. }
  675. else if (is_hilight(word_eol[9]))
  676. {
  677. xchat_emit_print(ph, "Channel Msg Hilight", nickName, word_eol[9], NULL, NULL);
  678. xchat_command(ph, "GUI COLOR 2");
  679. }
  680. else
  681. {
  682. xchat_emit_print(ph, "Channel Message", nickName, word_eol[9], NULL, NULL);
  683. }
  684. }
  685. }
  686. }
  687.  
  688. static int is_hilight (char *text)
  689. {
  690. int i;
  691. const char *str;
  692.  
  693. if (xchat_get_prefs(ph, "irc_extra_hilight", &str, &i) == 1)
  694. {
  695. if (searchText(text, str))
  696. {
  697. return 1;
  698. }
  699. }
  700. return 0;
  701. }
  702.  
  703. static int searchText (char *text, const char *nicks)
  704. {
  705. char *S;
  706. const char *n;
  707.  
  708. if (nicks == NULL)
  709. {
  710. return 0;
  711. }
  712.  
  713. S = strdup(nicks);
  714. n = strtok(S, ",");
  715.  
  716. while (n != NULL)
  717. {
  718. if((strstr(text, n)))
  719. {
  720. return 1;
  721. }
  722. n = strtok (NULL, ",");
  723. }
  724. return 0;
  725. }
  726.  
  727.  
  728. void print_to_query (char *tab, char *type, char *msg)
  729. {
  730. static const char *currentServer;
  731.  
  732. currentServer = xchat_get_info(ph, (char*)"server");
  733.  
  734. if (!xchat_find_context(ph, currentServer, tab))
  735. {
  736. xchat_commandf(ph, "QUERY -nofocus %s", tab);
  737. }
  738.  
  739. xchat_set_context(ph, xchat_find_context(ph, currentServer, tab));
  740.  
  741. xchat_emit_print(ph, "Private Message to Dialog", type, msg, NULL, NULL);
  742. }
  743.  
  744.  
  745. /* For when a fake channel tab is open */
  746. static int block_raws_cb (char *word[], char *word_eol[], void *userdata)
  747. {
  748. static const char *currentServer;
  749.  
  750. currentServer = xchat_get_info(ph, (char*)"server");
  751.  
  752. if (xchat_find_context(ph, currentServer, clientTab) ||
  753. xchat_find_context(ph, currentServer, idleTab) ||
  754. xchat_find_context(ph, currentServer, helpoptab) ||
  755. xchat_find_context(ph, currentServer, adchatTab) ||
  756. xchat_find_context(ph, currentServer, nachatTab) ||
  757. xchat_find_context(ph, currentServer, locopsTab) ||
  758. xchat_find_context(ph, currentServer, chatopsTab)||
  759. xchat_find_context(ph, currentServer, globopsTab))
  760. {
  761. return XCHAT_EAT_XCHAT;
  762. }
  763.  
  764. return XCHAT_EAT_NONE;
  765. }
  766.  
  767. /* Keeps -Clients tab clean */
  768. static int block_prints_cb (char *word[], void *userdata)
  769. {
  770. static const char *currentChannel;
  771.  
  772. currentChannel = xchat_get_info(ph, (char*)"channel");
  773.  
  774. if (strcmp(word[1], clientTab) == 0 || strcmp(currentChannel, clientTab) == 0)
  775. {
  776. return XCHAT_EAT_XCHAT;
  777. }
  778.  
  779. return XCHAT_EAT_NONE;
  780. }
  781.  
  782.  
  783. static int check_time()
  784. {
  785. double timeDiff;
  786.  
  787. whoCounter++;
  788. whoEnd = time(NULL);
  789.  
  790. timeDiff = difftime(whoEnd, whoStart);
  791.  
  792. /* When 2 to 3 have opered within 2 seconds */
  793. if (timeDiff >= 2.0 && whoCounter <= 3)
  794. {
  795. whoCounter = 0;
  796. return 1;
  797. }
  798.  
  799. whoStart = time(NULL);
  800.  
  801. return 0;
  802. }
  803.  
  804.  
  805. void update_userlist ()
  806. {
  807. static const char *currentServer;
  808.  
  809. currentServer = xchat_get_info(ph, (char*)"server");
  810.  
  811. if (xchat_find_context(ph, currentServer, helpoptab))
  812. {
  813. xchat_commandf(ph, "TIMER 1 %s", helpopWhoCmd);
  814. }
  815. if (xchat_find_context(ph, currentServer, adchatTab))
  816. {
  817. xchat_commandf(ph, "TIMER 3 %s", adchatWhoCmd);
  818. }
  819. if (xchat_find_context(ph, currentServer, nachatTab))
  820. {
  821. xchat_commandf(ph, "TIMER 6 %s", nachatWhoCmd);
  822. }
  823. if (xchat_find_context(ph, currentServer, locopsTab))
  824. {
  825. xchat_commandf(ph, "TIMER 9 %s", locopsWhoCmd);
  826. }
  827. if (xchat_find_context(ph, currentServer, chatopsTab))
  828. {
  829. xchat_commandf(ph, "TIMER 12 %s", chatopsWhoCmd);
  830. }
  831. if (xchat_find_context(ph, currentServer, globopsTab))
  832. {
  833. xchat_commandf(ph, "TIMER 15 %s", globopsWhoCmd);
  834. }
  835. }
  836.  
  837.  
  838. int xchat_plugin_deinit (void)
  839. {
  840. if (unhook != NULL)
  841. {
  842. xchat_unhook(ph, unhook);
  843. unhook = NULL;
  844. }
  845.  
  846. if (who_hook != NULL)
  847. {
  848. xchat_unhook(ph, who_hook);
  849. who_hook = NULL;
  850. }
  851.  
  852. xchat_print(ph, "SNOTICES UNLOADED\n");
  853.  
  854. return XCHAT_EAT_XCHAT;
  855. }
Add Comment
Please, Sign In to add comment