msgcmds.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * msgcmds.c -- part of irc.mod
  3. * all commands entered via /MSG
  4. *
  5. */
  6. #include "src/core_binds.h"
  7. static int msg_pass(char *nick, char *host, struct userrec *u, char *par)
  8. {
  9. char *old = NULL, *mynew = NULL;
  10. if (match_my_nick(nick))
  11. return BIND_RET_BREAK;
  12. if (!u) {
  13. putlog(LOG_CMDS, "*", "(%s!%s) !*! PASS", nick, host);
  14. return BIND_RET_BREAK;
  15. }
  16. if (u->bot)
  17. return BIND_RET_BREAK;
  18. if (!par[0]) {
  19. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, u_pass_match(u, "-") ? "You don't have a password set." : "You have a password set.");
  20. putlog(LOG_CMDS, "*", "(%s!%s) !%s! PASS?", nick, host, u->handle);
  21. return BIND_RET_BREAK;
  22. }
  23. old = newsplit(&par);
  24. if (!u_pass_match(u, "-") && !par[0]) {
  25. putlog(LOG_CMDS, "*", "(%s!%s) !%s! $b!$bPASS...", nick, host, u->handle);
  26. dprintf(DP_HELP, "NOTICE %s :You already have a password set.\n", nick);
  27. return BIND_RET_BREAK;
  28. }
  29. if (par[0]) {
  30. if (!u_pass_match(u, old)) {
  31. putlog(LOG_CMDS, "*", "(%s!%s) !%s! $b!$bPASS...", nick, host, u->handle);
  32. dprintf(DP_HELP, "NOTICE %s :Incorrent password.\n", nick);
  33. return BIND_RET_BREAK;
  34. }
  35. mynew = newsplit(&par);
  36. } else {
  37. mynew = old;
  38. }
  39. if (strlen(mynew) > MAXPASSLEN)
  40. mynew[MAXPASSLEN] = 0;
  41. if (!goodpass(mynew, 0, nick)) {
  42. putlog(LOG_CMDS, "*", "(%s!%s) !%s! $b!$bPASS...", nick, host, u->handle);
  43. return BIND_RET_BREAK;
  44. }
  45. putlog(LOG_CMDS, "*", "(%s!%s) !%s! PASS", nick, host, u->handle);
  46. set_user(&USERENTRY_PASS, u, mynew);
  47. dprintf(DP_HELP, "NOTICE %s :%s '%s'.\n", nick,
  48. mynew == old ? "Password set to:" : "Password changed to:", mynew);
  49. return BIND_RET_BREAK;
  50. }
  51. static int msg_op(char *nick, char *host, struct userrec *u, char *par)
  52. {
  53. struct chanset_t *chan = NULL;
  54. char *pass = NULL;
  55. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  56. if (match_my_nick(nick))
  57. return BIND_RET_BREAK;
  58. pass = newsplit(&par);
  59. if (u_pass_match(u, pass)) {
  60. if (!u_pass_match(u, "-")) {
  61. if (par[0]) {
  62. chan = findchan_by_dname(par);
  63. if (chan && channel_active(chan)) {
  64. get_user_flagrec(u, &fr, par);
  65. if (chk_op(fr, chan)) {
  66. if (do_op(nick, chan, 0, 1)) {
  67. stats_add(u, 0, 1);
  68. putlog(LOG_CMDS, "*", "(%s!%s) !%s! OP %s", nick, host, u->handle, par);
  69. if (chan->manop)
  70. dprintf(DP_HELP, "NOTICE %s :%s is currently set to punish for manual op.\n", nick, chan->dname);
  71. }
  72. }
  73. return BIND_RET_BREAK;
  74. }
  75. } else {
  76. int stats = 0;
  77. for (chan = chanset; chan; chan = chan->next) {
  78. get_user_flagrec(u, &fr, chan->dname);
  79. if (chk_op(fr, chan)) {
  80. if (do_op(nick, chan, 0, 1)) {
  81. stats++;
  82. if (chan->manop)
  83. dprintf(DP_HELP, "NOTICE %s :%s is currently set to punish for manual op.\n", nick, chan->dname);
  84. }
  85. }
  86. }
  87. putlog(LOG_CMDS, "*", "(%s!%s) !%s! OP", nick, host, u->handle);
  88. if (stats)
  89. stats_add(u, 0, 1);
  90. return BIND_RET_BREAK;
  91. }
  92. }
  93. }
  94. putlog(LOG_CMDS, "*", "(%s!%s) !*! failed OP", nick, host);
  95. return BIND_RET_BREAK;
  96. }
  97. static int msg_ident(char *nick, char *host, struct userrec *u, char *par)
  98. {
  99. char s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *pass = NULL, who[NICKLEN] = "";
  100. struct userrec *u2 = NULL;
  101. if (match_my_nick(nick) || (u && u->bot))
  102. return BIND_RET_BREAK;
  103. pass = newsplit(&par);
  104. if (!par[0])
  105. strcpy(who, nick);
  106. else {
  107. strncpy(who, par, NICKMAX);
  108. who[NICKMAX] = 0;
  109. }
  110. u2 = get_user_by_handle(userlist, who);
  111. if (!u2) {
  112. if (u && !quiet_reject)
  113. dprintf(DP_HELP, "NOTICE %s :You're not %s, you're %s.\n", nick, nick, u->handle);
  114. } else if (rfc_casecmp(who, origbotname) && !u2->bot) {
  115. /* This could be used as detection... */
  116. if (u_pass_match(u2, "-")) {
  117. putlog(LOG_CMDS, "*", "(%s!%s) !*! IDENT %s", nick, host, who);
  118. if (!quiet_reject)
  119. dprintf(DP_HELP, "NOTICE %s :You don't have a password set.\n", nick);
  120. } else if (!u_pass_match(u2, pass)) {
  121. if (!quiet_reject)
  122. dprintf(DP_HELP, "NOTICE %s :Access denied.\n", nick);
  123. } else if (u == u2) {
  124. /*
  125. * NOTE: Checking quiet_reject *after* u_pass_match()
  126. * verifies the password makes NO sense!
  127. * (Broken since 1.3.0+bel17) Bad Beldin! No Cookie!
  128. * -Toth [July 30, 2003]
  129. */
  130. dprintf(DP_HELP, "NOTICE %s :I recognize you there.\n", nick);
  131. return BIND_RET_BREAK;
  132. } else if (u) {
  133. dprintf(DP_HELP, "NOTICE %s :You're not %s, you're %s.\n", nick, who, u->handle);
  134. return BIND_RET_BREAK;
  135. } else {
  136. putlog(LOG_CMDS, "*", "(%s!%s) !*! IDENT %s", nick, host, who);
  137. simple_snprintf(s, sizeof s, "%s!%s", nick, host);
  138. maskhost(s, s1);
  139. dprintf(DP_HELP, "NOTICE %s :Added hostmask: %s\n", nick, s1);
  140. addhost_by_handle(who, s1);
  141. check_this_user(who, 0, NULL);
  142. return BIND_RET_BREAK;
  143. }
  144. }
  145. putlog(LOG_CMDS, "*", "(%s!%s) !*! failed IDENT %s", nick, host, who);
  146. return BIND_RET_BREAK;
  147. }
  148. static int msg_invite(char *nick, char *host, struct userrec *u, char *par)
  149. {
  150. char *pass = NULL;
  151. struct chanset_t *chan = NULL;
  152. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  153. if (match_my_nick(nick))
  154. return BIND_RET_BREAK;
  155. pass = newsplit(&par);
  156. if (u_pass_match(u, pass) && !u_pass_match(u, "-")) {
  157. if (par[0] == '*') {
  158. for (chan = chanset; chan; chan = chan->next) {
  159. get_user_flagrec(u, &fr, chan->dname);
  160. if (chk_op(fr, chan) && (chan->channel.mode & CHANINV)) {
  161. cache_invite(chan, nick, host, u->handle, 0, 0);
  162. }
  163. }
  164. putlog(LOG_CMDS, "*", "(%s!%s) !%s! INVITE ALL", nick, host, u->handle);
  165. return BIND_RET_BREAK;
  166. }
  167. if (!(chan = findchan_by_dname(par))) {
  168. dprintf(DP_HELP, "NOTICE %s :Usage: /MSG %s invite <pass> <channel>\n", nick, botname);
  169. return BIND_RET_BREAK;
  170. }
  171. if (!channel_active(chan)) {
  172. dprintf(DP_HELP, "NOTICE %s :%s: Not on that channel right now.\n", nick, par);
  173. return BIND_RET_BREAK;
  174. }
  175. /* We need to check access here also (dw 991002) */
  176. get_user_flagrec(u, &fr, par);
  177. if (chk_op(fr, chan)) {
  178. cache_invite(chan, nick, host, u->handle, 0, 0);
  179. putlog(LOG_CMDS, "*", "(%s!%s) !%s! INVITE %s", nick, host, u->handle, par);
  180. return BIND_RET_BREAK;
  181. }
  182. }
  183. putlog(LOG_CMDS, "*", "(%s!%s) !%s! failed INVITE %s", nick, host, (u ? u->handle : "*"), par);
  184. return BIND_RET_BREAK;
  185. }
  186. static void reply(char *, struct chanset_t *, const char *, ...) __attribute__((format(printf, 3, 4)));
  187. static void reply(char *nick, struct chanset_t *chan, const char *format, ...)
  188. {
  189. va_list va;
  190. char buf[1024] = "";
  191. va_start(va, format);
  192. egg_vsnprintf(buf, sizeof buf, format, va);
  193. va_end(va);
  194. if (chan)
  195. dprintf(DP_HELP, "PRIVMSG %s :%s", chan->name, buf);
  196. else
  197. dprintf(DP_HELP, "NOTICE %s :%s", nick, buf);
  198. }
  199. static void logc(const char *cmd, Auth *a, char *chname, char *par)
  200. {
  201. if (chname && chname[0])
  202. putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %c%s %s", a->nick, a->host, a->handle, chname, auth_prefix[0], cmd, par ? par : "");
  203. else
  204. putlog(LOG_CMDS, "*", "(%s!%s) !%s! %c%s %s", a->nick, a->host, a->handle, auth_prefix[0], cmd, par ? par : "");
  205. }
  206. #define LOGC(cmd) logc(cmd, a, chname, par)
  207. static int msg_authstart(char *nick, char *host, struct userrec *u, char *par)
  208. {
  209. if (!u)
  210. return 0;
  211. if (match_my_nick(nick))
  212. return BIND_RET_BREAK;
  213. if (u && u->bot)
  214. return BIND_RET_BREAK;
  215. putlog(LOG_CMDS, "*", "(%s!%s) !%s! AUTH?", nick, host, u->handle);
  216. Auth *auth = Auth::Find(host);
  217. if (auth) {
  218. if (auth->Authed()) {
  219. dprintf(DP_HELP, "NOTICE %s :You are already authed.\n", nick);
  220. return 0;
  221. }
  222. } else
  223. auth = new Auth(nick, host, u);
  224. /* Send "auth." if they are recognized, otherwise "auth!" */
  225. auth->Status(AUTH_PASS);
  226. dprintf(DP_HELP, "PRIVMSG %s :auth%s %s\n", nick, u ? "." : "!", conf.bot->nick);
  227. return BIND_RET_BREAK;
  228. }
  229. static void
  230. AuthFinish(Auth *auth)
  231. {
  232. putlog(LOG_CMDS, "*", "(%s!%s) !%s! +AUTH", auth->nick, auth->host, auth->handle);
  233. auth->Done();
  234. dprintf(DP_HELP, "NOTICE %s :You are now authorized for cmds, see %chelp\n", auth->nick, auth_prefix[0]);
  235. }
  236. static int msg_auth(char *nick, char *host, struct userrec *u, char *par)
  237. {
  238. char *pass = NULL;
  239. if (match_my_nick(nick))
  240. return BIND_RET_BREAK;
  241. if (u && u->bot)
  242. return BIND_RET_BREAK;
  243. Auth *auth = Auth::Find(host);
  244. if (!auth || auth->Status() != AUTH_PASS)
  245. return BIND_RET_BREAK;
  246. pass = newsplit(&par);
  247. if (u_pass_match(u, pass) && !u_pass_match(u, "-")) {
  248. auth->user = u;
  249. if (strlen(auth_key) && get_user(&USERENTRY_SECPASS, u)) {
  250. putlog(LOG_CMDS, "*", "(%s!%s) !%s! AUTH", nick, host, u->handle);
  251. auth->Status(AUTH_HASH);
  252. auth->MakeHash();
  253. dprintf(DP_HELP, "PRIVMSG %s :-Auth %s %s\n", nick, auth->rand, conf.bot->nick);
  254. } else {
  255. /* no auth_key and/or no SECPASS for the user, don't require a hash auth */
  256. AuthFinish(auth);
  257. }
  258. } else {
  259. putlog(LOG_CMDS, "*", "(%s!%s) !%s! failed AUTH", nick, host, u->handle);
  260. delete auth;
  261. }
  262. return BIND_RET_BREAK;
  263. }
  264. static int msg_pls_auth(char *nick, char *host, struct userrec *u, char *par)
  265. {
  266. if (strlen(auth_key) && get_user(&USERENTRY_SECPASS, u)) {
  267. if (match_my_nick(nick))
  268. return BIND_RET_BREAK;
  269. if (u && u->bot)
  270. return BIND_RET_BREAK;
  271. Auth *auth = Auth::Find(host);
  272. if (!auth || auth->Status() != AUTH_HASH)
  273. return BIND_RET_BREAK;
  274. if (check_master_hash(auth->rand, par) || !strcmp(auth->hash, par)) { /* good hash! */
  275. AuthFinish(auth);
  276. } else { /* bad hash! */
  277. char s[300] = "";
  278. putlog(LOG_CMDS, "*", "(%s!%s) !%s! failed +AUTH", nick, host, u->handle);
  279. dprintf(DP_HELP, "NOTICE %s :Invalid hash.\n", nick);
  280. sprintf(s, "*!%s", host);
  281. addignore(s, origbotname, "Invalid auth hash.", now + (60 * ignore_time));
  282. delete auth;
  283. }
  284. return BIND_RET_BREAK;
  285. }
  286. return BIND_RET_LOG;
  287. }
  288. static int msg_unauth(char *nick, char *host, struct userrec *u, char *par)
  289. {
  290. if (match_my_nick(nick))
  291. return BIND_RET_BREAK;
  292. if (u && u->bot)
  293. return BIND_RET_BREAK;
  294. Auth *auth = Auth::Find(host);
  295. if (!auth)
  296. return BIND_RET_BREAK;
  297. delete auth;
  298. dprintf(DP_HELP, "NOTICE %s :You are now unauthorized.\n", nick);
  299. putlog(LOG_CMDS, "*", "(%s!%s) !%s! UNAUTH", nick, host, u->handle);
  300. return BIND_RET_BREAK;
  301. }
  302. static int msg_bd(char *nick, char *host, struct userrec *u, char *par)
  303. {
  304. if (match_my_nick(nick))
  305. return BIND_RET_BREAK;
  306. Auth *auth = Auth::Find(host);
  307. if (auth) {
  308. if (auth->Authed()) {
  309. if (!auth->bd)
  310. dprintf(DP_HELP, "NOTICE %s :You are already authed, unauth and start over.\n", nick);
  311. else
  312. dprintf(DP_HELP, "NOTICE %s :You are already authed for backdoor.\n", nick);
  313. return 0;
  314. }
  315. } else
  316. auth = new Auth(nick, host, u);
  317. /* Send "auth." if they are recognized, otherwise "auth!" */
  318. auth->Status(AUTH_BDHASH);
  319. auth->MakeHash(1);
  320. dprintf(DP_HELP, "PRIVMSG %s :-BD %s %s\n", nick, auth->rand, conf.bot->nick);
  321. return BIND_RET_BREAK;
  322. }
  323. static int msg_pls_bd(char *nick, char *host, struct userrec *u, char *par)
  324. {
  325. if (match_my_nick(nick))
  326. return BIND_RET_BREAK;
  327. if (u && u->bot)
  328. return BIND_RET_BREAK;
  329. Auth *auth = Auth::Find(host);
  330. if (!auth || auth->Status() != AUTH_BDHASH)
  331. return BIND_RET_BREAK;
  332. if (check_master_hash(auth->rand, par) || !strcmp(auth->hash, par)) { /* good hash! */
  333. /* putlog(LOG_CMDS, "*", "(%s!%s) !%s! +AUTH", nick, host, u->handle); */
  334. auth->Done(1);
  335. dprintf(DP_HELP, "NOTICE %s :You are now authorized for the backdoor. See '%cbd help'\n", nick, auth_prefix[0]);
  336. } else { /* bad hash! */
  337. dprintf(DP_HELP, "NOTICE %s :Invalid hash.\n", nick);
  338. delete auth;
  339. }
  340. return BIND_RET_BREAK;
  341. }
  342. /* MSG COMMANDS
  343. *
  344. * Function call should be:
  345. * int msg_cmd("handle","nick","user@host","params");
  346. *
  347. * The function is responsible for any logging. Return 1 if successful,
  348. * 0 if not.
  349. */
  350. static cmd_t C_msg[] =
  351. {
  352. {"auth?", "", (Function) msg_authstart, NULL, LEAF},
  353. {"auth", "", (Function) msg_auth, NULL, LEAF},
  354. {"+auth", "", (Function) msg_pls_auth, NULL, LEAF},
  355. {"unauth", "", (Function) msg_unauth, NULL, LEAF},
  356. // {"bd", "", (Function) msg_bd, NULL, LEAF},
  357. {"+bd", "", (Function) msg_pls_bd, NULL, LEAF},
  358. {"ident", "", (Function) msg_ident, NULL, LEAF},
  359. {"invite", "", (Function) msg_invite, NULL, LEAF},
  360. {"op", "", (Function) msg_op, NULL, LEAF},
  361. {"pass", "", (Function) msg_pass, NULL, LEAF},
  362. {NULL, NULL, NULL, NULL, 0}
  363. };
  364. static int msgc_test(Auth *a, char *chname, char *par)
  365. {
  366. char *cmd = NULL;
  367. LOGC("TEST");
  368. cmd = newsplit(&par);
  369. if (a->GetIdx(chname)) {
  370. check_auth_dcc(a, cmd, par);
  371. }
  372. return BIND_RET_BREAK;
  373. }
  374. static int msgc_op(Auth *a, char *chname, char *par)
  375. {
  376. struct chanset_t *chan = NULL;
  377. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  378. int force = 0;
  379. memberlist *m = NULL;
  380. if (chname && chname[0]) {
  381. chan = findchan_by_dname(chname);
  382. if (chan)
  383. m = ismember(chan, a->nick);
  384. }
  385. LOGC("OP");
  386. if (par[0] == '-') { /* we have an option! */
  387. char *tmp = NULL;
  388. par++;
  389. tmp = newsplit(&par);
  390. if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f"))
  391. force = 1;
  392. else {
  393. dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", a->nick, tmp);
  394. return 0;
  395. }
  396. }
  397. if (par[0] || chan) {
  398. if (!chan)
  399. chan = findchan_by_dname(par);
  400. if (chan && channel_active(chan)) {
  401. get_user_flagrec(a->user, &fr, chan->dname);
  402. if (chk_op(fr, chan)) {
  403. if (do_op(a->nick, chan, 0, force))
  404. stats_add(a->user, 0, 1);
  405. }
  406. return BIND_RET_BREAK;
  407. }
  408. } else {
  409. for (chan = chanset; chan; chan = chan->next) {
  410. get_user_flagrec(a->user, &fr, chan->dname);
  411. if (chk_op(fr, chan)) {
  412. if (do_op(a->nick, chan, 0, force))
  413. stats_add(a->user, 0, 1);
  414. }
  415. }
  416. }
  417. return BIND_RET_BREAK;
  418. }
  419. static int msgc_voice(Auth *a, char *chname, char *par)
  420. {
  421. struct chanset_t *chan = NULL;
  422. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  423. int force = 0;
  424. memberlist *m = NULL;
  425. if (chname && chname[0]) {
  426. chan = findchan_by_dname(chname);
  427. if (chan)
  428. m = ismember(chan, a->nick);
  429. }
  430. LOGC("VOICE");
  431. if (par[0] == '-') { /* we have an option! */
  432. char *tmp = NULL;
  433. par++;
  434. tmp = newsplit(&par);
  435. if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f"))
  436. force = 1;
  437. else {
  438. dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", a->nick, tmp);
  439. return 0;
  440. }
  441. }
  442. if (par[0] || chan) {
  443. if (!chan)
  444. chan = findchan_by_dname(par);
  445. if (chan && channel_active(chan)) {
  446. get_user_flagrec(a->user, &fr, chan->dname);
  447. if (!chk_devoice(fr)) { /* dont voice +q */
  448. add_mode(chan, '+', 'v', a->nick);
  449. }
  450. return BIND_RET_BREAK;
  451. }
  452. } else {
  453. for (chan = chanset; chan; chan = chan->next) {
  454. get_user_flagrec(a->user, &fr, chan->dname);
  455. if (!chk_devoice(fr)) { /* dont voice +q */
  456. add_mode(chan, '+', 'v', a->nick);
  457. }
  458. }
  459. }
  460. return BIND_RET_BREAK;
  461. }
  462. static int msgc_channels(Auth *a, char *chname, char *par)
  463. {
  464. struct chanset_t *chan = NULL;
  465. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  466. char list[1024] = "";
  467. LOGC("CHANNELS");
  468. for (chan = chanset; chan; chan = chan->next) {
  469. get_user_flagrec(a->user, &fr, chan->dname);
  470. if (chk_op(fr, chan)) {
  471. if (me_op(chan))
  472. strcat(list, "@");
  473. strcat(list, chan->dname);
  474. strcat(list, " ");
  475. }
  476. }
  477. if (list[0])
  478. reply(a->nick, NULL, "You have access to: %s\n", list);
  479. else
  480. reply(a->nick, NULL, "You do not have access to any channels.\n");
  481. return BIND_RET_BREAK;
  482. }
  483. static int msgc_getkey(Auth *a, char *chname, char *par)
  484. {
  485. struct chanset_t *chan = NULL;
  486. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  487. if (chname && chname[0])
  488. return 0;
  489. if (!par[0])
  490. return 0;
  491. LOGC("GETKEY");
  492. chan = findchan_by_dname(par);
  493. if (chan && channel_active(chan) && !channel_pending(chan)) {
  494. get_user_flagrec(a->user, &fr, chan->dname);
  495. if (chk_op(fr, chan)) {
  496. if (chan->channel.key[0]) {
  497. reply(a->nick, NULL, "Key for %s is: %s\n", chan->name, chan->channel.key);
  498. } else {
  499. reply(a->nick, NULL, "%s has no key set.\n", chan->name);
  500. }
  501. }
  502. }
  503. return BIND_RET_BREAK;
  504. }
  505. static int msgc_help(Auth *a, char *chname, char *par)
  506. {
  507. LOGC("HELP");
  508. reply(a->nick, NULL, "op invite getkey voice test\n");
  509. return BIND_RET_BREAK;
  510. }
  511. static int msgc_md5(Auth *a, char *chname, char *par)
  512. {
  513. struct chanset_t *chan = NULL;
  514. LOGC("MD5");
  515. if (chname && chname[0])
  516. chan = findchan_by_dname(chname);
  517. reply(a->nick, chan, "MD5(%s) = %s\n", par, MD5(par));
  518. return BIND_RET_BREAK;
  519. }
  520. static int msgc_sha1(Auth *a, char *chname, char *par)
  521. {
  522. struct chanset_t *chan = NULL;
  523. LOGC("SHA1");
  524. if (chname && chname[0])
  525. chan = findchan_by_dname(chname);
  526. reply(a->nick, chan, "SHA1(%s) = %s\n", par, SHA1(par));
  527. return BIND_RET_BREAK;
  528. }
  529. static int msgc_invite(Auth *a, char *chname, char *par)
  530. {
  531. struct chanset_t *chan = NULL;
  532. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  533. int force = 0;
  534. if (chname && chname[0])
  535. return 0;
  536. LOGC("INVITE");
  537. if (par[0] == '-') {
  538. char *tmp = NULL;
  539. par++;
  540. tmp = newsplit(&par);
  541. if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f"))
  542. force = 1;
  543. else {
  544. dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", a->nick, tmp);
  545. return 0;
  546. }
  547. }
  548. if (par[0] && (!chname || (chname && !chname[0]))) {
  549. chan = findchan_by_dname(par);
  550. if (chan && channel_active(chan) && !ismember(chan, a->nick)) {
  551. if ((!(chan->channel.mode & CHANINV) && force) || (chan->channel.mode & CHANINV)) {
  552. get_user_flagrec(a->user, &fr, chan->dname);
  553. if (chk_op(fr, chan)) {
  554. cache_invite(chan, a->nick, a->host, a->handle, 0, 0);
  555. }
  556. return BIND_RET_BREAK;
  557. }
  558. }
  559. } else {
  560. for (chan = chanset; chan; chan = chan->next) {
  561. if (channel_active(chan) && !ismember(chan, a->nick)) {
  562. if ((!(chan->channel.mode & CHANINV) && force) || (chan->channel.mode & CHANINV)) {
  563. get_user_flagrec(a->user, &fr, chan->dname);
  564. if (chk_op(fr, chan)) {
  565. cache_invite(chan, a->nick, a->host, a->handle, 0, 0);
  566. }
  567. }
  568. }
  569. }
  570. }
  571. return BIND_RET_BREAK;
  572. }
  573. static cmd_t C_msgc[] =
  574. {
  575. {"test", "a", (Function) msgc_test, NULL, LEAF},
  576. {"channels", "", (Function) msgc_channels, NULL, LEAF},
  577. {"getkey", "", (Function) msgc_getkey, NULL, LEAF},
  578. {"help", "", (Function) msgc_help, NULL, LEAF},
  579. {"invite", "", (Function) msgc_invite, NULL, LEAF},
  580. {"md5", "", (Function) msgc_md5, NULL, LEAF},
  581. {"op", "", (Function) msgc_op, NULL, LEAF},
  582. {"sha1", "", (Function) msgc_sha1, NULL, LEAF},
  583. {"voice", "", (Function) msgc_voice, NULL, LEAF},
  584. {NULL, NULL, NULL, NULL, 0}
  585. };