irc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * ngIRCd -- The Next Generation IRC Daemon
  3. * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * Please read the file COPYING, README and AUTHORS for more information.
  10. */
  11. #include "portab.h"
  12. /**
  13. * @file
  14. * IRC commands
  15. */
  16. #include "imp.h"
  17. #include <assert.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include "ngircd.h"
  21. #include "conn-func.h"
  22. #include "conf.h"
  23. #include "channel.h"
  24. #include "conn-encoding.h"
  25. #include "defines.h"
  26. #include "irc-write.h"
  27. #include "log.h"
  28. #include "match.h"
  29. #include "messages.h"
  30. #include "parse.h"
  31. #include "tool.h"
  32. #include "exp.h"
  33. #include "irc.h"
  34. static char *Option_String PARAMS((CONN_ID Idx));
  35. static bool Send_Message PARAMS((CLIENT *Client, REQUEST *Req, int ForceType,
  36. bool SendErrors));
  37. static bool Send_Message_Mask PARAMS((CLIENT *from, char *command,
  38. char *targetMask, char *message,
  39. bool SendErrors));
  40. /**
  41. * Check if a list limit is reached and inform client accordingly.
  42. *
  43. * @param From The client.
  44. * @param Count Reply item count.
  45. * @param Limit Reply limit.
  46. * @param Name Name of the list.
  47. * @return true if list limit has been reached; false otherwise.
  48. */
  49. GLOBAL bool
  50. IRC_CheckListTooBig(CLIENT *From, const int Count, const int Limit,
  51. const char *Name)
  52. {
  53. assert(From != NULL);
  54. assert(Count >= 0);
  55. assert(Limit > 0);
  56. assert(Name != NULL);
  57. if (Count < Limit)
  58. return false;
  59. (void)IRC_WriteStrClient(From,
  60. "NOTICE %s :%s list limit (%d) reached!",
  61. Client_ID(From), Name, Limit);
  62. IRC_SetPenalty(From, 2);
  63. return true;
  64. }
  65. GLOBAL bool
  66. IRC_ERROR( CLIENT *Client, REQUEST *Req )
  67. {
  68. assert( Client != NULL );
  69. assert( Req != NULL );
  70. if (Client_Type(Client) != CLIENT_GOTPASS
  71. && Client_Type(Client) != CLIENT_GOTPASS_2813
  72. && Client_Type(Client) != CLIENT_UNKNOWNSERVER
  73. && Client_Type(Client) != CLIENT_SERVER
  74. && Client_Type(Client) != CLIENT_SERVICE) {
  75. LogDebug("Ignored ERROR command from \"%s\" ...",
  76. Client_Mask(Client));
  77. IRC_SetPenalty(Client, 2);
  78. return CONNECTED;
  79. }
  80. if (Req->argc < 1)
  81. Log(LOG_NOTICE, "Got ERROR from \"%s\"!",
  82. Client_Mask(Client));
  83. else
  84. Log(LOG_NOTICE, "Got ERROR from \"%s\": \"%s\"!",
  85. Client_Mask(Client), Req->argv[0]);
  86. return CONNECTED;
  87. } /* IRC_ERROR */
  88. /**
  89. * Handler for the IRC "KILL" command.
  90. *
  91. * This function implements the IRC command "KILL" wich is used to selectively
  92. * disconnect clients. It can be used by IRC operators and servers, for example
  93. * to "solve" nick collisions after netsplits. See RFC 2812 section 3.7.1.
  94. *
  95. * Please note that this function is also called internally, without a real
  96. * KILL command being received over the network! Client is Client_ThisServer()
  97. * in this case, and the prefix in Req is NULL.
  98. *
  99. * @param Client The client from which this command has been received
  100. * or Client_ThisServer() when generated interanlly.
  101. * @param Req Request structure with prefix and all parameters.
  102. * @returns CONNECTED or DISCONNECTED.
  103. */
  104. GLOBAL bool
  105. IRC_KILL( CLIENT *Client, REQUEST *Req )
  106. {
  107. CLIENT *prefix, *c;
  108. char reason[COMMAND_LEN], *msg;
  109. CONN_ID my_conn, conn;
  110. assert (Client != NULL);
  111. assert (Req != NULL);
  112. if (Client_Type(Client) != CLIENT_SERVER && !Client_OperByMe(Client))
  113. return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
  114. Client_ID(Client));
  115. if (Req->argc != 2)
  116. return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
  117. Client_ID(Client), Req->command);
  118. /* Get prefix (origin); use the client if no prefix is given. */
  119. if (Req->prefix)
  120. prefix = Client_Search(Req->prefix);
  121. else
  122. prefix = Client;
  123. /* Log a warning message and use this server as origin when the
  124. * prefix (origin) is invalid. */
  125. if (!prefix) {
  126. Log(LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!",
  127. Req->prefix );
  128. prefix = Client_ThisServer();
  129. }
  130. if (Client != Client_ThisServer())
  131. Log(LOG_NOTICE|LOG_snotice,
  132. "Got KILL command from \"%s\" for \"%s\": %s",
  133. Client_Mask(prefix), Req->argv[0], Req->argv[1]);
  134. /* Build reason string: Prefix the "reason" if the originator is a
  135. * regular user, so users can't spoof KILLs of servers. */
  136. if (Client_Type(Client) == CLIENT_USER)
  137. snprintf(reason, sizeof(reason), "KILLed by %s: %s",
  138. Client_ID(Client), Req->argv[1]);
  139. else
  140. strlcpy(reason, Req->argv[1], sizeof(reason));
  141. /* Inform other servers */
  142. IRC_WriteStrServersPrefix(Client, prefix, "KILL %s :%s",
  143. Req->argv[0], reason);
  144. /* Save ID of this connection */
  145. my_conn = Client_Conn( Client );
  146. /* Do we host such a client? */
  147. c = Client_Search( Req->argv[0] );
  148. if( c )
  149. {
  150. if(( Client_Type( c ) != CLIENT_USER ) &&
  151. ( Client_Type( c ) != CLIENT_GOTNICK ))
  152. {
  153. /* Target of this KILL is not a regular user, this is
  154. * invalid! So we ignore this case if we received a
  155. * regular KILL from the network and try to kill the
  156. * client/connection anyway (but log an error!) if the
  157. * origin is the local server. */
  158. if( Client != Client_ThisServer( ))
  159. {
  160. /* Invalid KILL received from remote */
  161. if( Client_Type( c ) == CLIENT_SERVER )
  162. msg = ERR_CANTKILLSERVER_MSG;
  163. else
  164. msg = ERR_NOPRIVILEGES_MSG;
  165. return IRC_WriteStrClient( Client, msg,
  166. Client_ID( Client ));
  167. }
  168. Log( LOG_ERR, "Got KILL for invalid client type: %d, \"%s\"!",
  169. Client_Type( c ), Req->argv[0] );
  170. }
  171. /* Kill the client NOW:
  172. * - Close the local connection (if there is one),
  173. * - Destroy the CLIENT structure for remote clients.
  174. * Note: Conn_Close() removes the CLIENT structure as well. */
  175. conn = Client_Conn( c );
  176. if(conn > NONE)
  177. Conn_Close(conn, NULL, reason, true);
  178. else
  179. Client_Destroy(c, NULL, reason, false);
  180. }
  181. else
  182. Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
  183. /* Are we still connected or were we killed, too? */
  184. if(( my_conn > NONE ) && ( Conn_GetClient( my_conn )))
  185. return CONNECTED;
  186. else
  187. return DISCONNECTED;
  188. } /* IRC_KILL */
  189. /**
  190. * Handler for the IRC command NOTICE.
  191. */
  192. GLOBAL bool
  193. IRC_NOTICE(CLIENT *Client, REQUEST *Req)
  194. {
  195. return Send_Message(Client, Req, CLIENT_USER, false);
  196. } /* IRC_NOTICE */
  197. /**
  198. * Handler for the IRC command PRIVMSG.
  199. */
  200. GLOBAL bool
  201. IRC_PRIVMSG(CLIENT *Client, REQUEST *Req)
  202. {
  203. return Send_Message(Client, Req, CLIENT_USER, true);
  204. } /* IRC_PRIVMSG */
  205. /**
  206. * Handler for the IRC command SQUERY.
  207. */
  208. GLOBAL bool
  209. IRC_SQUERY(CLIENT *Client, REQUEST *Req)
  210. {
  211. return Send_Message(Client, Req, CLIENT_SERVICE, true);
  212. } /* IRC_SQUERY */
  213. GLOBAL bool
  214. IRC_TRACE( CLIENT *Client, REQUEST *Req )
  215. {
  216. CLIENT *from, *target, *c;
  217. CONN_ID idx, idx2;
  218. char user[CLIENT_USER_LEN];
  219. assert( Client != NULL );
  220. assert( Req != NULL );
  221. /* Bad number of arguments? */
  222. if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
  223. /* Search sender */
  224. if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
  225. else from = Client;
  226. if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
  227. /* Search target */
  228. if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
  229. else target = Client_ThisServer( );
  230. /* Forward command to other server? */
  231. if( target != Client_ThisServer( ))
  232. {
  233. if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
  234. /* Send RPL_TRACELINK back to initiator */
  235. idx = Client_Conn( Client ); assert( idx > NONE );
  236. idx2 = Client_Conn( Client_NextHop( target )); assert( idx2 > NONE );
  237. if( ! IRC_WriteStrClient( from, RPL_TRACELINK_MSG, Client_ID( from ), PACKAGE_NAME, PACKAGE_VERSION, Client_ID( target ), Client_ID( Client_NextHop( target )), Option_String( idx2 ), time( NULL ) - Conn_StartTime( idx2 ), Conn_SendQ( idx ), Conn_SendQ( idx2 ))) return DISCONNECTED;
  238. /* Forward command */
  239. IRC_WriteStrClientPrefix( target, from, "TRACE %s", Req->argv[0] );
  240. return CONNECTED;
  241. }
  242. /* Infos about all connected servers */
  243. c = Client_First( );
  244. while( c )
  245. {
  246. if( Client_Conn( c ) > NONE )
  247. {
  248. /* Local client */
  249. if( Client_Type( c ) == CLIENT_SERVER )
  250. {
  251. /* Server link */
  252. strlcpy( user, Client_User( c ), sizeof( user ));
  253. if( user[0] == '~' ) strlcpy( user, "unknown", sizeof( user ));
  254. if( ! IRC_WriteStrClient( from, RPL_TRACESERVER_MSG, Client_ID( from ), Client_ID( c ), user, Client_Hostname( c ), Client_Mask( Client_ThisServer( )), Option_String( Client_Conn( c )))) return DISCONNECTED;
  255. }
  256. if(( Client_Type( c ) == CLIENT_USER ) && ( strchr( Client_Modes( c ), 'o' )))
  257. {
  258. /* IRC Operator */
  259. if( ! IRC_WriteStrClient( from, RPL_TRACEOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
  260. }
  261. }
  262. c = Client_Next( c );
  263. }
  264. IRC_SetPenalty( Client, 3 );
  265. return IRC_WriteStrClient( from, RPL_TRACEEND_MSG, Client_ID( from ), Conf_ServerName, PACKAGE_NAME, PACKAGE_VERSION, NGIRCd_DebugLevel );
  266. } /* IRC_TRACE */
  267. GLOBAL bool
  268. IRC_HELP( CLIENT *Client, REQUEST *Req )
  269. {
  270. COMMAND *cmd;
  271. assert( Client != NULL );
  272. assert( Req != NULL );
  273. /* Bad number of arguments? */
  274. if( Req->argc > 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
  275. cmd = Parse_GetCommandStruct( );
  276. while( cmd->name )
  277. {
  278. if( ! IRC_WriteStrClient( Client, "NOTICE %s :%s", Client_ID( Client ), cmd->name )) return DISCONNECTED;
  279. cmd++;
  280. }
  281. IRC_SetPenalty( Client, 2 );
  282. return CONNECTED;
  283. } /* IRC_HELP */
  284. static char *
  285. #ifdef ZLIB
  286. Option_String(CONN_ID Idx)
  287. #else
  288. Option_String(UNUSED CONN_ID Idx)
  289. #endif
  290. {
  291. static char option_txt[8];
  292. #ifdef ZLIB
  293. UINT16 options;
  294. options = Conn_Options(Idx);
  295. #endif
  296. strcpy(option_txt, "F"); /* No idea what this means, but the
  297. * original ircd sends it ... */
  298. #ifdef ZLIB
  299. if(options & CONN_ZIP) /* zlib compression supported. */
  300. strcat(option_txt, "z");
  301. #endif
  302. return option_txt;
  303. } /* Option_String */
  304. static bool
  305. Send_Message(CLIENT * Client, REQUEST * Req, int ForceType, bool SendErrors)
  306. {
  307. CLIENT *cl, *from;
  308. CL2CHAN *cl2chan;
  309. CHANNEL *chan;
  310. char *currentTarget = Req->argv[0];
  311. char *lastCurrentTarget = NULL;
  312. char *message = NULL;
  313. assert(Client != NULL);
  314. assert(Req != NULL);
  315. if (Req->argc == 0) {
  316. if (!SendErrors)
  317. return CONNECTED;
  318. return IRC_WriteStrClient(Client, ERR_NORECIPIENT_MSG,
  319. Client_ID(Client), Req->command);
  320. }
  321. if (Req->argc == 1) {
  322. if (!SendErrors)
  323. return CONNECTED;
  324. return IRC_WriteStrClient(Client, ERR_NOTEXTTOSEND_MSG,
  325. Client_ID(Client));
  326. }
  327. if (Req->argc > 2) {
  328. if (!SendErrors)
  329. return CONNECTED;
  330. return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
  331. Client_ID(Client), Req->command);
  332. }
  333. if (Client_Type(Client) == CLIENT_SERVER)
  334. from = Client_Search(Req->prefix);
  335. else
  336. from = Client;
  337. if (!from)
  338. return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
  339. Client_ID(Client), Req->prefix);
  340. #ifdef ICONV
  341. if (Client_Conn(Client) > NONE)
  342. message = Conn_EncodingFrom(Client_Conn(Client), Req->argv[1]);
  343. else
  344. #endif
  345. message = Req->argv[1];
  346. /* handle msgtarget = msgto *("," msgto) */
  347. currentTarget = strtok_r(currentTarget, ",", &lastCurrentTarget);
  348. ngt_UpperStr(Req->command);
  349. while (currentTarget) {
  350. /* Check for and handle valid <msgto> of form:
  351. * RFC 2812 2.3.1:
  352. * msgto = channel / ( user [ "%" host ] "@" servername )
  353. * msgto =/ ( user "%" host ) / targetmask
  354. * msgto =/ nickname / ( nickname "!" user "@" host )
  355. */
  356. if (strchr(currentTarget, '!') == NULL)
  357. /* nickname */
  358. cl = Client_Search(currentTarget);
  359. else
  360. cl = NULL;
  361. if (cl == NULL) {
  362. /* If currentTarget isn't a nickname check for:
  363. * user ["%" host] "@" servername
  364. * user "%" host
  365. * nickname "!" user "@" host
  366. */
  367. char target[COMMAND_LEN];
  368. char * nick = NULL;
  369. char * user = NULL;
  370. char * host = NULL;
  371. char * server = NULL;
  372. strlcpy(target, currentTarget, COMMAND_LEN);
  373. server = strchr(target, '@');
  374. if (server) {
  375. *server = '\0';
  376. server++;
  377. }
  378. host = strchr(target, '%');
  379. if (host) {
  380. *host = '\0';
  381. host++;
  382. }
  383. user = strchr(target, '!');
  384. if (user) {
  385. /* msgto form: nick!user@host */
  386. *user = '\0';
  387. user++;
  388. nick = target;
  389. host = server; /* not "@server" but "@host" */
  390. } else {
  391. user = target;
  392. }
  393. for (cl = Client_First(); cl != NULL; cl = Client_Next(cl)) {
  394. if (Client_Type(cl) != CLIENT_USER &&
  395. Client_Type(cl) != CLIENT_SERVICE)
  396. continue;
  397. if (nick != NULL && host != NULL) {
  398. if (strcasecmp(nick, Client_ID(cl)) == 0 &&
  399. strcasecmp(user, Client_User(cl)) == 0 &&
  400. strcasecmp(host, Client_HostnameDisplayed(cl)) == 0)
  401. break;
  402. else
  403. continue;
  404. }
  405. if (strcasecmp(user, Client_User(cl)) != 0)
  406. continue;
  407. if (host != NULL && strcasecmp(host,
  408. Client_HostnameDisplayed(cl)) != 0)
  409. continue;
  410. if (server != NULL && strcasecmp(server,
  411. Client_ID(Client_Introducer(cl))) != 0)
  412. continue;
  413. break;
  414. }
  415. }
  416. if (cl) {
  417. /* Target is a user, enforce type */
  418. #ifndef STRICT_RFC
  419. if (Client_Type(cl) != ForceType &&
  420. !(ForceType == CLIENT_USER &&
  421. (Client_Type(cl) == CLIENT_USER ||
  422. Client_Type(cl) == CLIENT_SERVICE))) {
  423. #else
  424. if (Client_Type(cl) != ForceType) {
  425. #endif
  426. if (SendErrors && !IRC_WriteStrClient(
  427. from, ERR_NOSUCHNICK_MSG,Client_ID(from),
  428. currentTarget))
  429. return DISCONNECTED;
  430. goto send_next_target;
  431. }
  432. #ifndef STRICT_RFC
  433. if (ForceType == CLIENT_SERVICE &&
  434. (Conn_Options(Client_Conn(Client_NextHop(cl)))
  435. & CONN_RFC1459)) {
  436. /* SQUERY command but RFC 1459 link: convert
  437. * request to PRIVMSG command */
  438. Req->command = "PRIVMSG";
  439. }
  440. #endif
  441. if (Client_HasMode(cl, 'b') &&
  442. !Client_HasMode(from, 'R') &&
  443. !Client_HasMode(from, 'o') &&
  444. !(Client_Type(from) == CLIENT_SERVER) &&
  445. !(Client_Type(from) == CLIENT_SERVICE)) {
  446. if (SendErrors && !IRC_WriteStrClient(from,
  447. ERR_NONONREG_MSG,
  448. Client_ID(from), Client_ID(cl)))
  449. return DISCONNECTED;
  450. goto send_next_target;
  451. }
  452. if (Client_HasMode(cl, 'C')) {
  453. cl2chan = Channel_FirstChannelOf(cl);
  454. while (cl2chan) {
  455. chan = Channel_GetChannel(cl2chan);
  456. if (Channel_IsMemberOf(chan, from))
  457. break;
  458. cl2chan = Channel_NextChannelOf(cl, cl2chan);
  459. }
  460. if (!cl2chan) {
  461. if (SendErrors && !IRC_WriteStrClient(
  462. from, ERR_NOTONSAMECHANNEL_MSG,
  463. Client_ID(from), Client_ID(cl)))
  464. return DISCONNECTED;
  465. goto send_next_target;
  466. }
  467. }
  468. if (SendErrors && (Client_Type(Client) != CLIENT_SERVER)
  469. && strchr(Client_Modes(cl), 'a')) {
  470. /* Target is away */
  471. if (!IRC_WriteStrClient(from, RPL_AWAY_MSG,
  472. Client_ID(from),
  473. Client_ID(cl),
  474. Client_Away(cl)))
  475. return DISCONNECTED;
  476. }
  477. if (Client_Conn(from) > NONE) {
  478. Conn_UpdateIdle(Client_Conn(from));
  479. }
  480. if (!IRC_WriteStrClientPrefix(cl, from, "%s %s :%s",
  481. Req->command, Client_ID(cl),
  482. message))
  483. return DISCONNECTED;
  484. } else if (ForceType != CLIENT_SERVICE
  485. && (chan = Channel_Search(currentTarget))) {
  486. if (!Channel_Write(chan, from, Client, Req->command,
  487. SendErrors, message))
  488. return DISCONNECTED;
  489. } else if (ForceType != CLIENT_SERVICE
  490. /* $#: server/target mask, RFC 2812, sec. 3.3.1 */
  491. && strchr("$#", currentTarget[0])
  492. && strchr(currentTarget, '.')) {
  493. /* targetmask */
  494. if (!Send_Message_Mask(from, Req->command, currentTarget,
  495. message, SendErrors))
  496. return DISCONNECTED;
  497. } else {
  498. if (!SendErrors)
  499. return CONNECTED;
  500. if (!IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG,
  501. Client_ID(from), currentTarget))
  502. return DISCONNECTED;
  503. }
  504. send_next_target:
  505. currentTarget = strtok_r(NULL, ",", &lastCurrentTarget);
  506. if (currentTarget)
  507. Conn_SetPenalty(Client_Conn(Client), 1);
  508. }
  509. return CONNECTED;
  510. } /* Send_Message */
  511. static bool
  512. Send_Message_Mask(CLIENT * from, char * command, char * targetMask,
  513. char * message, bool SendErrors)
  514. {
  515. CLIENT *cl;
  516. bool client_match;
  517. char *mask = targetMask + 1;
  518. const char *check_wildcards;
  519. cl = NULL;
  520. if (strchr(Client_Modes(from), 'o') == NULL) {
  521. if (!SendErrors)
  522. return true;
  523. return IRC_WriteStrClient(from, ERR_NOPRIVILEGES_MSG,
  524. Client_ID(from));
  525. }
  526. /*
  527. * RFC 2812, sec. 3.3.1 requires that targetMask have at least one
  528. * dot (".") and no wildcards ("*", "?") following the last one.
  529. */
  530. check_wildcards = strrchr(targetMask, '.');
  531. assert(check_wildcards != NULL);
  532. if (check_wildcards &&
  533. check_wildcards[strcspn(check_wildcards, "*?")])
  534. {
  535. if (!SendErrors)
  536. return true;
  537. return IRC_WriteStrClient(from, ERR_WILDTOPLEVEL, targetMask);
  538. }
  539. /* #: hostmask, see RFC 2812, sec. 3.3.1 */
  540. if (targetMask[0] == '#') {
  541. for (cl = Client_First(); cl != NULL; cl = Client_Next(cl)) {
  542. if (Client_Type(cl) != CLIENT_USER)
  543. continue;
  544. client_match = MatchCaseInsensitive(mask, Client_Hostname(cl));
  545. if (client_match)
  546. if (!IRC_WriteStrClientPrefix(cl, from, "%s %s :%s",
  547. command, Client_ID(cl), message))
  548. return false;
  549. }
  550. } else {
  551. assert(targetMask[0] == '$'); /* $: server mask, see RFC 2812, sec. 3.3.1 */
  552. for (cl = Client_First(); cl != NULL; cl = Client_Next(cl)) {
  553. if (Client_Type(cl) != CLIENT_USER)
  554. continue;
  555. client_match = MatchCaseInsensitive(mask,
  556. Client_ID(Client_Introducer(cl)));
  557. if (client_match)
  558. if (!IRC_WriteStrClientPrefix(cl, from, "%s %s :%s",
  559. command, Client_ID(cl), message))
  560. return false;
  561. }
  562. }
  563. return CONNECTED;
  564. } /* Send_Message_Mask */
  565. /* -eof- */