cmds.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588
  1. /*
  2. * cmds.c -- handles:
  3. * commands from a user via dcc
  4. * (split in 2, this portion contains no-irc commands)
  5. *
  6. * dprintf'ized, 3nov1995
  7. *
  8. * $Id: cmds.c,v 1.34 2000/01/17 16:14:45 per Exp $
  9. */
  10. /*
  11. * Copyright (C) 1997 Robey Pointer
  12. * Copyright (C) 1999, 2000 Eggheads
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27. */
  28. #include "main.h"
  29. #include "tandem.h"
  30. #include "modules.h"
  31. #include <ctype.h>
  32. extern struct chanset_t *chanset;
  33. extern struct dcc_t *dcc;
  34. extern struct userrec *userlist;
  35. extern tcl_timer_t *timer, *utimer;
  36. extern int dcc_total, remote_boots, backgrd, make_userfile, do_restart;
  37. extern int conmask, require_p, must_be_owner;
  38. extern Tcl_Interp *interp;
  39. extern char botnetnick[], origbotname[], ver[];
  40. extern char network[], owner[], spaces[];
  41. extern time_t now, online_since;
  42. /* add hostmask to a bot's record if possible */
  43. static int add_bot_hostmask(int idx, char *nick)
  44. {
  45. struct chanset_t *chan;
  46. memberlist *m;
  47. char s[UHOSTLEN];
  48. for (chan = chanset; chan; chan = chan->next) {
  49. if (channel_active(chan)) {
  50. m = ismember(chan, nick);
  51. if (m) {
  52. struct userrec *u;
  53. simple_sprintf(s, "%s!%s", m->nick, m->userhost);
  54. u = get_user_by_host(s);
  55. if (u) {
  56. dprintf(idx, "(Can't add userhost for %s because it matches %s)\n",
  57. nick, u->handle);
  58. return 0;
  59. }
  60. simple_sprintf(s, "*!%s", m->userhost);
  61. dprintf(idx, "(Added hostmask for %s from %s)\n", nick, chan->name);
  62. addhost_by_handle(nick, s);
  63. return 1;
  64. }
  65. }
  66. }
  67. return 0;
  68. }
  69. static void tell_who(struct userrec *u, int idx, int chan)
  70. {
  71. int i, k, ok = 0, atr = u ? u->flags : 0, len;
  72. char s[1024]; /* temp fix - 1.4 has a better one */
  73. if (chan == 0)
  74. dprintf(idx, "Party line members: (* = owner, + = master, @ = op)\n");
  75. else {
  76. simple_sprintf(s, "assoc %d", chan);
  77. if ((Tcl_Eval(interp, s) != TCL_OK) || !interp->result[0])
  78. dprintf(idx,
  79. "People on channel %s%d: (* = owner, + = master, @ = op)\n",
  80. (chan < 100000) ? "" : "*", chan % 100000);
  81. else
  82. dprintf(idx,
  83. "People on channel '%s' (%s%d): (* = owner, + = master, @ = op)\n",
  84. interp->result, (chan < 100000) ? "" : "*", chan % 100000);
  85. }
  86. for (i = 0; i < dcc_total; i++)
  87. if (dcc[i].type == &DCC_CHAT)
  88. if (dcc[i].u.chat->channel == chan) {
  89. spaces[len = HANDLEN - strlen(dcc[i].nick)] = 0;
  90. if (atr & USER_OWNER) {
  91. sprintf(s, " [%.2lu] %c%s%s %s",
  92. dcc[i].sock, (geticon(i) == '-' ? ' ' : geticon(i)),
  93. dcc[i].nick, spaces, dcc[i].host);
  94. } else {
  95. sprintf(s, " %c%s%s %s",
  96. (geticon(i) == '-' ? ' ' : geticon(i)),
  97. dcc[i].nick, spaces, dcc[i].host);
  98. }
  99. spaces[len] = ' ';
  100. if (atr & USER_MASTER) {
  101. if (dcc[i].u.chat->con_flags)
  102. sprintf(&s[strlen(s)], " (con:%s)",
  103. masktype(dcc[i].u.chat->con_flags));
  104. }
  105. if (now - dcc[i].timeval > 300) {
  106. unsigned long days, hrs, mins;
  107. days = (now - dcc[i].timeval) / 86400;
  108. hrs = ((now - dcc[i].timeval) - (days * 86400)) / 3600;
  109. mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
  110. if (days > 0)
  111. sprintf(&s[strlen(s)], " (idle %lud%luh)", days, hrs);
  112. else if (hrs > 0)
  113. sprintf(&s[strlen(s)], " (idle %luh%lum)", hrs, mins);
  114. else
  115. sprintf(&s[strlen(s)], " (idle %lum)", mins);
  116. }
  117. dprintf(idx, "%s\n", s);
  118. if (dcc[i].u.chat->away != NULL)
  119. dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
  120. }
  121. for (i = 0; i < dcc_total; i++)
  122. if (dcc[i].type == &DCC_BOT) {
  123. if (!ok) {
  124. ok = 1;
  125. dprintf(idx, "Bots connected:\n");
  126. }
  127. strcpy(s, ctime(&dcc[i].timeval));
  128. strcpy(s, &s[1]);
  129. s[9] = 0;
  130. strcpy(s, &s[7]);
  131. s[2] = ' ';
  132. strcpy(&s[7], &s[10]);
  133. s[12] = 0;
  134. spaces[len = HANDLEN - strlen(dcc[i].nick)] = 0;
  135. if (atr & USER_OWNER) {
  136. dprintf(idx, " [%.2lu] %s%c%s%s (%s) %s\n",
  137. dcc[i].sock, dcc[i].status & STAT_CALLED ? "<-" : "->",
  138. dcc[i].status & STAT_SHARE ? '+' : ' ',
  139. dcc[i].nick, spaces, s, dcc[i].u.bot->version);
  140. } else {
  141. dprintf(idx, " %s%c%s%s (%s) %s\n",
  142. dcc[i].status & STAT_CALLED ? "<-" : "->",
  143. dcc[i].status & STAT_SHARE ? '+' : ' ',
  144. dcc[i].nick, spaces, s, dcc[i].u.bot->version);
  145. }
  146. spaces[len] = ' ';
  147. }
  148. ok = 0;
  149. for (i = 0; i < dcc_total; i++) {
  150. if ((dcc[i].type == &DCC_CHAT) && (dcc[i].u.chat->channel != chan)) {
  151. if (!ok) {
  152. ok = 1;
  153. dprintf(idx, "Other people on the bot:\n");
  154. }
  155. spaces[len = HANDLEN - strlen(dcc[i].nick)] = 0;
  156. if (atr & USER_OWNER) {
  157. sprintf(s, " [%.2lu] %c%s%s ",
  158. dcc[i].sock,
  159. (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick,
  160. spaces);
  161. } else {
  162. sprintf(s, " %c%s%s ",
  163. (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick,
  164. spaces);
  165. }
  166. spaces[len] = ' ';
  167. if (atr & USER_MASTER) {
  168. if (dcc[i].u.chat->channel < 0)
  169. strcat(s, "(-OFF-) ");
  170. else if (dcc[i].u.chat->channel == 0)
  171. strcat(s, "(party) ");
  172. else
  173. sprintf(&s[strlen(s)], "(%5d) ", dcc[i].u.chat->channel);
  174. }
  175. strcat(s, dcc[i].host);
  176. if (atr & USER_MASTER) {
  177. if (dcc[i].u.chat->con_flags)
  178. sprintf(&s[strlen(s)], " (con:%s)",
  179. masktype(dcc[i].u.chat->con_flags));
  180. }
  181. if (now - dcc[i].timeval > 300) {
  182. k = (now - dcc[i].timeval) / 60;
  183. if (k < 60)
  184. sprintf(&s[strlen(s)], " (idle %dm)", k);
  185. else
  186. sprintf(&s[strlen(s)], " (idle %dh%dm)", k / 60, k % 60);
  187. }
  188. dprintf(idx, "%s\n", s);
  189. if (dcc[i].u.chat->away != NULL)
  190. dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
  191. }
  192. if ((atr & USER_MASTER) && (dcc[i].type->flags & DCT_SHOWWHO) &&
  193. (dcc[i].type != &DCC_CHAT)) {
  194. if (!ok) {
  195. ok = 1;
  196. dprintf(idx, "Other people on the bot:\n");
  197. }
  198. spaces[len = HANDLEN - strlen(dcc[i].nick)] = 0;
  199. if (atr & USER_OWNER) {
  200. sprintf(s, " [%.2lu] %c%s%s (files) %s",
  201. dcc[i].sock, dcc[i].status & STAT_CHAT ? '+' : ' ',
  202. dcc[i].nick, spaces, dcc[i].host);
  203. } else {
  204. sprintf(s, " %c%s%s (files) %s",
  205. dcc[i].status & STAT_CHAT ? '+' : ' ',
  206. dcc[i].nick, spaces, dcc[i].host);
  207. }
  208. spaces[len] = ' ';
  209. dprintf(idx, "%s\n", s);
  210. }
  211. }
  212. }
  213. static void cmd_botinfo(struct userrec *u, int idx, char *par)
  214. {
  215. char s[512], s2[32];
  216. struct chanset_t *chan;
  217. time_t now2;
  218. int hr, min;
  219. Context;
  220. chan = chanset;
  221. now2 = now - online_since;
  222. s2[0] = 0;
  223. if (now2 > 86400) {
  224. int days = now2 / 86400;
  225. /* days */
  226. sprintf(s2, "%d day", days);
  227. if (days >= 2)
  228. strcat(s2, "s");
  229. strcat(s2, ", ");
  230. now2 -= days * 86400;
  231. }
  232. hr = (time_t) ((int) now2 / 3600);
  233. now2 -= (hr * 3600);
  234. min = (time_t) ((int) now2 / 60);
  235. sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
  236. putlog(LOG_CMDS, "*", "#%s# botinfo", dcc[idx].nick);
  237. simple_sprintf(s, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  238. botnet_send_infoq(-1, s);
  239. s[0] = 0;
  240. if (module_find("server", 0, 0)) {
  241. while (chan != NULL) {
  242. if (!channel_secret(chan)) {
  243. if ((strlen(s) + strlen(chan->name) + strlen(network)
  244. + strlen(botnetnick) + strlen(ver) + 1) >= 490) {
  245. strcat(s,"++ ");
  246. break; /* yeesh! */
  247. }
  248. strcat(s, chan->name);
  249. strcat(s, ", ");
  250. }
  251. chan = chan->next;
  252. }
  253. if (s[0]) {
  254. s[strlen(s) - 2] = 0;
  255. dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
  256. ver, network, s, s2);
  257. } else
  258. dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
  259. ver, network, BOT_NOCHANNELS, s2);
  260. } else
  261. dprintf(idx, "*** [%s] %s <NO_IRC> [UP %s]\n", botnetnick, ver, s2);
  262. }
  263. static void cmd_whom(struct userrec *u, int idx, char *par)
  264. {
  265. if (par[0] == '*') {
  266. putlog(LOG_CMDS, "*", "#%s# whom %s", dcc[idx].nick, par);
  267. answer_local_whom(idx, -1);
  268. return;
  269. } else if (dcc[idx].u.chat->channel < 0) {
  270. dprintf(idx, "You have chat turned off.\n");
  271. return;
  272. }
  273. putlog(LOG_CMDS, "*", "#%s# whom %s", dcc[idx].nick, par);
  274. if (!par[0]) {
  275. answer_local_whom(idx, dcc[idx].u.chat->channel);
  276. } else {
  277. int chan = -1;
  278. if ((par[0] < '0') || (par[0] > '9')) {
  279. Tcl_SetVar(interp, "chan", par, 0);
  280. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  281. interp->result[0]) {
  282. chan = atoi(interp->result);
  283. }
  284. if (chan <= 0) {
  285. dprintf(idx, "No such channel.\n");
  286. return;
  287. }
  288. } else
  289. chan = atoi(par);
  290. if ((chan < 0) || (chan > 99999)) {
  291. dprintf(idx, "Channel # out of range: must be 0-99999\n");
  292. return;
  293. }
  294. answer_local_whom(idx, chan);
  295. }
  296. }
  297. static void cmd_me(struct userrec *u, int idx, char *par)
  298. {
  299. int i;
  300. if (dcc[idx].u.chat->channel < 0) {
  301. dprintf(idx, "You have chat turned off.\n");
  302. return;
  303. }
  304. if (!par[0]) {
  305. dprintf(idx, "Usage: me <action>\n");
  306. return;
  307. }
  308. if (dcc[idx].u.chat->away != NULL)
  309. not_away(idx);
  310. for (i = 0; i < dcc_total; i++)
  311. if ((dcc[i].type->flags & DCT_CHAT) &&
  312. (dcc[i].u.chat->channel == dcc[idx].u.chat->channel) &&
  313. ((i != idx) || (dcc[i].status & STAT_ECHO)))
  314. dprintf(i, "* %s %s\n", dcc[idx].nick, par);
  315. botnet_send_act(idx, botnetnick, dcc[idx].nick,
  316. dcc[idx].u.chat->channel, par);
  317. check_tcl_act(dcc[idx].nick, dcc[idx].u.chat->channel, par);
  318. }
  319. static void cmd_motd(struct userrec *u, int idx, char *par)
  320. {
  321. int i;
  322. if (par[0]) {
  323. putlog(LOG_CMDS, "*", "#%s# motd %s", dcc[idx].nick, par);
  324. if (!strcasecmp(par, botnetnick))
  325. show_motd(idx);
  326. else {
  327. i = nextbot(par);
  328. if (i < 0)
  329. dprintf(idx, "That bot isn't connected.\n");
  330. else {
  331. char x[40];
  332. simple_sprintf(x, "%s%d:%s@%s",
  333. (u->flags & USER_HIGHLITE) ?
  334. ((dcc[idx].status & STAT_TELNET) ? "#" : "!") : "",
  335. dcc[idx].sock, dcc[idx].nick, botnetnick);
  336. botnet_send_motd(i, x, par);
  337. }
  338. }
  339. } else {
  340. putlog(LOG_CMDS, "*", "#%s# motd", dcc[idx].nick);
  341. show_motd(idx);
  342. }
  343. }
  344. static void cmd_away(struct userrec *u, int idx, char *par)
  345. {
  346. if (strlen(par) > 60)
  347. par[60] = 0;
  348. set_away(idx, par);
  349. }
  350. static void cmd_back(struct userrec *u, int idx, char *par)
  351. {
  352. not_away(idx);
  353. }
  354. static void cmd_newpass(struct userrec *u, int idx, char *par)
  355. {
  356. char *new;
  357. if (!par[0]) {
  358. dprintf(idx, "Usage: newpass <newpassword>\n");
  359. return;
  360. }
  361. new = newsplit(&par);
  362. if (strlen(new) > 16)
  363. new[16] = 0;
  364. if (strlen(new) < 6) {
  365. dprintf(idx, "Please use at least 6 characters.\n");
  366. return;
  367. }
  368. set_user(&USERENTRY_PASS, u, new);
  369. putlog(LOG_CMDS, "*", "#%s# newpass...", dcc[idx].nick);
  370. dprintf(idx, "Changed password to '%s'\n", new);
  371. }
  372. static void cmd_bots(struct userrec *u, int idx, char *par)
  373. {
  374. putlog(LOG_CMDS, "*", "#%s# bots", dcc[idx].nick);
  375. tell_bots(idx);
  376. }
  377. static void cmd_bottree(struct userrec *u, int idx, char *par)
  378. {
  379. putlog(LOG_CMDS, "*", "#%s# bottree", dcc[idx].nick);
  380. tell_bottree(idx, 0);
  381. }
  382. static void cmd_vbottree(struct userrec *u, int idx, char *par)
  383. {
  384. putlog(LOG_CMDS, "*", "#%s# vbottree", dcc[idx].nick);
  385. tell_bottree(idx, 1);
  386. }
  387. static void cmd_rehelp(struct userrec *u, int idx, char *par)
  388. {
  389. putlog(LOG_CMDS, "*", "#%s# rehelp", dcc[idx].nick);
  390. dprintf(idx, "Reload help cache...\n");
  391. reload_help_data();
  392. }
  393. static void cmd_help(struct userrec *u, int idx, char *par)
  394. {
  395. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  396. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  397. if (par[0]) {
  398. putlog(LOG_CMDS, "*", "#%s# help %s", dcc[idx].nick, par);
  399. if (!strcmp(par, "all"))
  400. tellallhelp(idx, "all", &fr);
  401. else if (strchr(par, '*') || strchr(par, '?')) {
  402. char *p = par;
  403. /* Check if the search pattern only consists of '*' and/or '?'
  404. * If it does, show help for "all" instead of listing all help
  405. * entries. */
  406. for (p = par; *p && ((*p == '*') || (*p == '?')); p++);
  407. if (*p)
  408. tellwildhelp(idx, par, &fr);
  409. else
  410. tellallhelp(idx, "all", &fr);
  411. } else
  412. tellhelp(idx, par, &fr, 0);
  413. } else {
  414. putlog(LOG_CMDS, "*", "#%s# help", dcc[idx].nick);
  415. if (glob_op(fr) || glob_botmast(fr) || chan_op(fr))
  416. tellhelp(idx, "help", &fr, 0);
  417. else
  418. tellhelp(idx, "helpparty", &fr, 0);
  419. }
  420. }
  421. static void cmd_addlog(struct userrec *u, int idx, char *par)
  422. {
  423. if (!par[0]) {
  424. dprintf(idx, "Usage: addlog <message>\n");
  425. return;
  426. }
  427. dprintf(idx, "Placed entry in the log file.\n");
  428. putlog(LOG_MISC, "*", "%s: %s", dcc[idx].nick, par);
  429. }
  430. static void cmd_who(struct userrec *u, int idx, char *par)
  431. {
  432. int i;
  433. if (par[0]) {
  434. if (dcc[idx].u.chat->channel < 0) {
  435. dprintf(idx, "You have chat turned off.\n");
  436. return;
  437. }
  438. putlog(LOG_CMDS, "*", "#%s# who %s", dcc[idx].nick, par);
  439. if (!strcasecmp(par, botnetnick))
  440. tell_who(u, idx, dcc[idx].u.chat->channel);
  441. else {
  442. i = nextbot(par);
  443. if (i < 0) {
  444. dprintf(idx, "That bot isn't connected.\n");
  445. } else if (dcc[idx].u.chat->channel > 99999)
  446. dprintf(idx, "You are on a local channel\n");
  447. else {
  448. char s[40];
  449. simple_sprintf(s, "%d:%s@%s", dcc[idx].sock,
  450. dcc[idx].nick, botnetnick);
  451. botnet_send_who(i, s, par, dcc[idx].u.chat->channel);
  452. }
  453. }
  454. } else {
  455. putlog(LOG_CMDS, "*", "#%s# who", dcc[idx].nick);
  456. if (dcc[idx].u.chat->channel < 0)
  457. tell_who(u, idx, 0);
  458. else
  459. tell_who(u, idx, dcc[idx].u.chat->channel);
  460. }
  461. }
  462. static void cmd_whois(struct userrec *u, int idx, char *par)
  463. {
  464. if (!par[0]) {
  465. dprintf(idx, "Usage: whois <handle>\n");
  466. return;
  467. }
  468. putlog(LOG_CMDS, "*", "#%s# whois %s", dcc[idx].nick, par);
  469. tell_user_ident(idx, par, u ? (u->flags & USER_MASTER) : 0);
  470. }
  471. static void cmd_match(struct userrec *u, int idx, char *par)
  472. {
  473. int start = 1, limit = 20;
  474. char *s, *s1, *chname;
  475. if (!par[0]) {
  476. dprintf(idx, "Usage: match <nick/host> [[skip] count]\n");
  477. return;
  478. }
  479. putlog(LOG_CMDS, "*", "#%s# match %s", dcc[idx].nick, par);
  480. s = newsplit(&par);
  481. if (strchr(CHANMETA, par[0]) != NULL)
  482. chname = newsplit(&par);
  483. else
  484. chname = "";
  485. if (atoi(par) > 0) {
  486. s1 = newsplit(&par);
  487. if (atoi(par) > 0) {
  488. start = atoi(s1);
  489. limit = atoi(par);
  490. } else
  491. limit = atoi(s1);
  492. }
  493. tell_users_match(idx, s, start, limit, u ? (u->flags & USER_MASTER) : 0,
  494. chname);
  495. }
  496. static void cmd_uptime(struct userrec *u, int idx, char *par)
  497. {
  498. putlog(LOG_CMDS, "*", "#%s# uptime", dcc[idx].nick);
  499. tell_verbose_uptime(idx);
  500. }
  501. static void cmd_status(struct userrec *u, int idx, char *par)
  502. {
  503. int atr = u ? u->flags : 0;
  504. if (!strcasecmp(par, "all")) {
  505. if (!(atr & USER_MASTER)) {
  506. dprintf(idx, "You do not have Bot Master privileges.\n");
  507. return;
  508. }
  509. putlog(LOG_CMDS, "*", "#%s# status all", dcc[idx].nick);
  510. tell_verbose_status(idx);
  511. tell_mem_status_dcc(idx);
  512. dprintf(idx, "\n");
  513. tell_settings(idx);
  514. do_module_report(idx, 1, NULL);
  515. } else {
  516. putlog(LOG_CMDS, "*", "#%s# status", dcc[idx].nick);
  517. tell_verbose_status(idx);
  518. tell_mem_status_dcc(idx);
  519. do_module_report(idx, 0, NULL);
  520. }
  521. }
  522. static void cmd_dccstat(struct userrec *u, int idx, char *par)
  523. {
  524. putlog(LOG_CMDS, "*", "#%s# dccstat", dcc[idx].nick);
  525. tell_dcc(idx);
  526. }
  527. static void cmd_boot(struct userrec *u, int idx, char *par)
  528. {
  529. int i, files = 0, ok = 0;
  530. char *who;
  531. struct userrec *u2;
  532. if (!par[0]) {
  533. dprintf(idx, "Usage: boot nick[@bot]\n");
  534. return;
  535. }
  536. who = newsplit(&par);
  537. if (strchr(who, '@') != NULL) {
  538. char whonick[512];
  539. splitc(whonick, who, '@');
  540. whonick[20] = 0;
  541. if (!strcasecmp(who, botnetnick)) {
  542. cmd_boot(u, idx, whonick);
  543. return;
  544. }
  545. if (remote_boots > 0) {
  546. i = nextbot(who);
  547. if (i < 0) {
  548. dprintf(idx, "No such bot connected.\n");
  549. return;
  550. }
  551. botnet_send_reject(i, dcc[idx].nick, botnetnick, whonick,
  552. who, par[0] ? par : dcc[idx].nick);
  553. putlog(LOG_BOTS, "*", "#%s# boot %s@%s (%s)", dcc[idx].nick, whonick,
  554. who, par[0] ? par : dcc[idx].nick);
  555. } else
  556. dprintf(idx, "Remote boots are disabled here.\n");
  557. return;
  558. }
  559. for (i = 0; i < dcc_total; i++)
  560. if (!strcasecmp(dcc[i].nick, who) && !ok &&
  561. (dcc[i].type->flags & DCT_CANBOOT)) {
  562. u2 = get_user_by_handle(userlist, dcc[i].nick);
  563. if (u2 && (u2->flags & USER_OWNER) &&
  564. strcasecmp(dcc[idx].nick, who)) {
  565. dprintf(idx, "Can't boot the bot owner.\n");
  566. return;
  567. }
  568. if (u2 && (u2->flags & USER_MASTER) &&
  569. !(u && (u->flags & USER_MASTER))) {
  570. dprintf(idx, "Can't boot a bot master.\n");
  571. return;
  572. }
  573. files = (dcc[i].type->flags & DCT_FILES);
  574. if (files)
  575. dprintf(idx, "Booted %s from the file section.\n", dcc[i].nick);
  576. else
  577. dprintf(idx, "Booted %s from the bot.\n", dcc[i].nick);
  578. putlog(LOG_CMDS, "*", "#%s# boot %s %s", dcc[idx].nick, who, par);
  579. do_boot(i, dcc[idx].nick, par);
  580. ok = 1;
  581. }
  582. if (!ok)
  583. dprintf(idx, "Who? No such person on the party line.\n");
  584. }
  585. static void cmd_console(struct userrec *u, int idx, char *par)
  586. {
  587. char *nick, s[2], s1[512];
  588. int dest = 0, i, ok = 0, pls, md;
  589. struct flag_record fr =
  590. {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  591. module_entry *me;
  592. if (!par[0]) {
  593. dprintf(idx, "Your console is %s: %s (%s)\n",
  594. dcc[idx].u.chat->con_chan,
  595. masktype(dcc[idx].u.chat->con_flags),
  596. maskname(dcc[idx].u.chat->con_flags));
  597. return;
  598. }
  599. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  600. strcpy(s1, par);
  601. nick = newsplit(&par);
  602. /* don't remove '+' as someone couldn't have '+' in CHANMETA cause
  603. * he doesn't use br0ken IRCnet ++rtc */
  604. if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
  605. for (i = 0; i < dcc_total; i++)
  606. if (!strcasecmp(nick, dcc[i].nick) &&
  607. (dcc[i].type == &DCC_CHAT) && (!ok)) {
  608. ok = 1;
  609. dest = i;
  610. }
  611. if (!ok) {
  612. dprintf(idx, "No such user on the party line!\n");
  613. return;
  614. }
  615. nick[0] = 0;
  616. } else
  617. dest = idx;
  618. if (!nick[0])
  619. nick = newsplit(&par);
  620. /* ugly hack for modeless channels -- rtc */
  621. if ((nick [0] == '+' && findchan(nick)) ||
  622. (nick [0] != '+' && strchr(CHANMETA "*", nick[0]))) {
  623. if (strcmp(nick, "*") && !findchan(nick)) {
  624. dprintf(idx, "Invalid console channel: %s\n", nick);
  625. return;
  626. }
  627. get_user_flagrec(u, &fr, nick);
  628. if (!chan_op(fr) && !(glob_op(fr) && !chan_deop(fr))) {
  629. dprintf(idx, "You don't have op or master access to channel %s\n",
  630. nick);
  631. return;
  632. }
  633. strncpy(dcc[dest].u.chat->con_chan, nick, 80);
  634. dcc[dest].u.chat->con_chan[80] = 0;
  635. nick[0] = 0;
  636. if ((dest == idx) && !glob_master(fr) && !chan_master(fr))
  637. /* consoling to another channel for self */
  638. dcc[dest].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_WALL);
  639. }
  640. if (!nick[0])
  641. nick = newsplit(&par);
  642. pls = 1;
  643. if (nick[0]) {
  644. if ((nick[0] != '+') && (nick[0] != '-'))
  645. dcc[dest].u.chat->con_flags = 0;
  646. for (; *nick; nick++) {
  647. if (*nick == '+')
  648. pls = 1;
  649. else if (*nick == '-')
  650. pls = 0;
  651. else {
  652. s[0] = *nick;
  653. s[1] = 0;
  654. md = logmodes(s);
  655. if ((dest == idx) && !glob_master(fr) && pls) {
  656. if (chan_master(fr))
  657. md &= ~(LOG_FILES | LOG_LEV1 | LOG_LEV2 | LOG_LEV3 |
  658. LOG_LEV4 | LOG_LEV5 | LOG_LEV6 | LOG_LEV7 |
  659. LOG_LEV8 | LOG_DEBUG);
  660. else
  661. md &= ~(LOG_MISC | LOG_CMDS | LOG_FILES | LOG_LEV1 |
  662. LOG_LEV2 | LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
  663. LOG_LEV6 | LOG_LEV7 | LOG_LEV8 | LOG_WALL |
  664. LOG_DEBUG);
  665. }
  666. if (!glob_owner(fr) && pls)
  667. md &= ~(LOG_RAW | LOG_SRVOUT | LOG_BOTNET | LOG_BOTSHARE);
  668. if (!glob_botmast(fr) && pls)
  669. md &= ~LOG_BOTS;
  670. if (pls)
  671. dcc[dest].u.chat->con_flags |= md;
  672. else
  673. dcc[dest].u.chat->con_flags &= ~md;
  674. }
  675. }
  676. }
  677. putlog(LOG_CMDS, "*", "#%s# console %s", dcc[idx].nick, s1);
  678. if (dest == idx) {
  679. dprintf(idx, "Set your console to %s: %s (%s)\n",
  680. dcc[idx].u.chat->con_chan,
  681. masktype(dcc[idx].u.chat->con_flags),
  682. maskname(dcc[idx].u.chat->con_flags));
  683. } else {
  684. dprintf(idx, "Set console of %s to %s: %s (%s)\n", dcc[dest].nick,
  685. dcc[dest].u.chat->con_chan,
  686. masktype(dcc[dest].u.chat->con_flags),
  687. maskname(dcc[dest].u.chat->con_flags));
  688. dprintf(dest, "%s set your console to %s: %s (%s)\n", dcc[idx].nick,
  689. dcc[dest].u.chat->con_chan,
  690. masktype(dcc[dest].u.chat->con_flags),
  691. maskname(dcc[dest].u.chat->con_flags));
  692. }
  693. /* new style autosave -- drummer,07/25/1999*/
  694. if ((me = module_find("console", 1, 1))) {
  695. Function *func = me->funcs;
  696. (func[CONSOLE_DOSTORE]) (dest);
  697. }
  698. }
  699. static void cmd_pls_bot(struct userrec *u, int idx, char *par)
  700. {
  701. char *handle, *addr, *p, *q, *host;
  702. struct userrec *u1;
  703. struct bot_addr *bi;
  704. if (!par[0])
  705. dprintf(idx, "Usage: +bot <handle> <address[:telnet-port[/relay-port]]> [host]\n");
  706. else {
  707. handle = newsplit(&par);
  708. addr = newsplit(&par);
  709. if (strlen(handle) > HANDLEN)
  710. handle[HANDLEN] = 0; /* max len = XX .. for the moment :) */
  711. if (get_user_by_handle(userlist, handle))
  712. dprintf(idx, "Someone already exists by that name.\n");
  713. else if (strchr(BADHANDCHARS, handle[0]) != NULL)
  714. dprintf(idx, "You can't start a botnick with '%c'.\n", handle[0]);
  715. else {
  716. if (strlen(addr) > 60)
  717. addr[60] = 0;
  718. putlog(LOG_CMDS, "*", "#%s# +bot %s %s", dcc[idx].nick, handle, addr);
  719. userlist = adduser(userlist, handle, "none", "-", USER_BOT);
  720. u1 = get_user_by_handle(userlist, handle);
  721. bi = user_malloc(sizeof(struct bot_addr));
  722. q = strchr(addr, ':');
  723. if (!q) {
  724. bi->address = user_malloc(strlen(addr) + 1);
  725. strcpy(bi->address, addr);
  726. bi->telnet_port = 3333;
  727. bi->relay_port = 3333;
  728. } else {
  729. bi->address = user_malloc(q - addr + 1);
  730. strncpy(bi->address, addr, q - addr);
  731. bi->address[q - addr] = 0;
  732. p = q + 1;
  733. bi->telnet_port = atoi(p);
  734. q = strchr(p, '/');
  735. if (!q) {
  736. bi->relay_port = bi->telnet_port;
  737. } else {
  738. bi->relay_port = atoi(q + 1);
  739. }
  740. }
  741. set_user(&USERENTRY_BOTADDR, u1, bi);
  742. dprintf(idx, "Added bot '%s' with address '%s' and no password.\n",
  743. handle, addr);
  744. host = newsplit(&par);
  745. if (host[0]) {
  746. addhost_by_handle(handle, host);
  747. } else if (!add_bot_hostmask(idx, handle))
  748. dprintf(idx, "You'll want to add a hostmask if this bot will ever %s",
  749. "be on any channels that I'm on.\n");
  750. }
  751. }
  752. }
  753. static void cmd_chnick(struct userrec *u, int idx, char *par)
  754. {
  755. char hand[HANDLEN + 1], newhand[HANDLEN + 1];
  756. int i, atr = u ? u->flags : 0, atr2;
  757. struct userrec *u2;
  758. strncpy(hand, newsplit(&par), sizeof(hand));
  759. hand[HANDLEN] = 0;
  760. strncpy(newhand, newsplit(&par), sizeof(newhand));
  761. newhand[HANDLEN] = 0;
  762. if (!hand[0] || !newhand[0]) {
  763. dprintf(idx, "Usage: chnick <oldnick> <newnick>\n");
  764. return;
  765. }
  766. for (i = 0; i < strlen(newhand); i++)
  767. if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
  768. newhand[i] = '?';
  769. if (strchr(BADHANDCHARS, newhand[0]) != NULL)
  770. dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with %c\n",
  771. newhand[0]);
  772. else if (get_user_by_handle(userlist, newhand) &&
  773. strcasecmp(hand, newhand))
  774. dprintf(idx, "Somebody is already using %s.\n", newhand);
  775. else {
  776. u2 = get_user_by_handle(userlist, hand);
  777. atr2 = u2 ? u2->flags : 0;
  778. if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
  779. !(atr2 & USER_BOT))
  780. dprintf(idx, "You can't change nick for non-bots.\n");
  781. else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
  782. dprintf(idx, "You can't change shared bot's nick.\n");
  783. else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
  784. strcasecmp(dcc[idx].nick, hand))
  785. dprintf(idx, "Can't change the bot owner's handle.\n");
  786. else if (isowner(hand) && strcasecmp(dcc[idx].nick, hand))
  787. dprintf(idx, "Can't change the permanent bot owner's handle.\n");
  788. else if (!strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
  789. nextbot(hand) != -1))
  790. dprintf(idx, "Hey! That's MY name!\n");
  791. else if (change_handle(u2, newhand)) {
  792. putlog(LOG_CMDS, "*", "#%s# chnick %s %s", dcc[idx].nick,
  793. hand, newhand);
  794. dprintf(idx, "Changed.\n");
  795. } else
  796. dprintf(idx, "Failed.\n");
  797. }
  798. }
  799. static void cmd_nick(struct userrec *u, int idx, char *par)
  800. {
  801. char oldnick[HANDLEN + 1], newnick[HANDLEN + 1];
  802. int i;
  803. strncpy(newnick, newsplit(&par), HANDLEN);
  804. newnick[HANDLEN] = 0;
  805. if (!newnick[0]) {
  806. dprintf(idx, "Usage: nick <new-handle>\n");
  807. return;
  808. }
  809. for (i = 0; i < strlen(newnick); i++)
  810. if ((newnick[i] <= 32) || (newnick[i] >= 127) || (newnick[i] == '@'))
  811. newnick[i] = '?';
  812. if (strchr(BADHANDCHARS, newnick[0]) != NULL) {
  813. dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with '%c'\n",
  814. newnick[0]);
  815. } else if (get_user_by_handle(userlist, newnick) &&
  816. strcasecmp(dcc[idx].nick, newnick)) {
  817. dprintf(idx, "Somebody is already using %s.\n", newnick);
  818. } else if (!strcasecmp(newnick, botnetnick)) {
  819. dprintf(idx, "Hey! That's MY name!\n");
  820. } else {
  821. strncpy(oldnick, dcc[idx].nick, HANDLEN);
  822. oldnick[HANDLEN] = 0;
  823. if (change_handle(u, newnick)) {
  824. putlog(LOG_CMDS, "*", "#%s# nick %s", oldnick, newnick);
  825. dprintf(idx, "Okay, changed.\n");
  826. } else
  827. dprintf(idx, "Failed.\n");
  828. }
  829. }
  830. static void cmd_chpass(struct userrec *u, int idx, char *par)
  831. {
  832. char *handle, *new;
  833. int atr = u ? u->flags : 0, l;
  834. if (!par[0])
  835. dprintf(idx, "Usage: chpass <handle> [password]\n");
  836. else {
  837. handle = newsplit(&par);
  838. u = get_user_by_handle(userlist, handle);
  839. if (!u)
  840. dprintf(idx, "No such user.\n");
  841. else if ((atr & USER_BOTMAST) && !(atr & USER_MASTER) &&
  842. !(u->flags & USER_BOT))
  843. dprintf(idx, "You can't change password for non-bots.\n");
  844. else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
  845. dprintf(idx, "You can't change shared bot's password.\n");
  846. else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
  847. strcasecmp(handle, dcc[idx].nick))
  848. dprintf(idx, "Can't change the bot owner's password.\n");
  849. else if (isowner(handle) && strcasecmp(dcc[idx].nick, handle))
  850. dprintf(idx, "Can't change the permanent bot owner's password.\n");
  851. else if (!par[0]) {
  852. putlog(LOG_CMDS, "*", "#%s# chpass %s [nothing]", dcc[idx].nick,
  853. handle);
  854. set_user(&USERENTRY_PASS, u, NULL);
  855. dprintf(idx, "Removed password.\n");
  856. } else {
  857. l = strlen(new = newsplit(&par));
  858. if (l > 16)
  859. new[16] = 0;
  860. if (l < 6)
  861. dprintf(idx, "Please use at least 6 characters.\n");
  862. else {
  863. set_user(&USERENTRY_PASS, u, new);
  864. putlog(LOG_CMDS, "*", "#%s# chpass %s [something]", dcc[idx].nick,
  865. handle);
  866. dprintf(idx, "Changed password.\n");
  867. }
  868. }
  869. }
  870. }
  871. static void cmd_chaddr(struct userrec *u, int idx, char *par)
  872. {
  873. char *handle, *addr, *p, *q;
  874. struct bot_addr *bi;
  875. struct userrec *u1;
  876. if (!par[0]) {
  877. dprintf(idx, "Usage: chaddr <botname> <address:botport#/userport#>\n");
  878. return;
  879. }
  880. handle = newsplit(&par);
  881. addr = newsplit(&par);
  882. if (strlen(addr) > UHOSTMAX)
  883. addr[UHOSTMAX] = 0;
  884. u1 = get_user_by_handle(userlist, handle);
  885. if (!u1 || !(u1->flags & USER_BOT)) {
  886. dprintf(idx, "Useful only for tandem bots.\n");
  887. return;
  888. }
  889. if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
  890. dprintf(idx, "You can't change shared bot's address.\n");
  891. return;
  892. }
  893. putlog(LOG_CMDS, "*", "#%s# chaddr %s %s", dcc[idx].nick, handle, addr);
  894. dprintf(idx, "Changed bot's address.\n");
  895. bi = user_malloc(sizeof(struct bot_addr));
  896. q = strchr(addr, ':');
  897. if (!q) {
  898. bi->address = user_malloc(strlen(addr) + 1);
  899. strcpy(bi->address, addr);
  900. bi->telnet_port = 3333;
  901. bi->relay_port = 3333;
  902. } else {
  903. bi->address = user_malloc(q - addr + 1);
  904. strncpy(bi->address, addr, q - addr);
  905. bi->address[q - addr] = 0;
  906. p = q + 1;
  907. bi->telnet_port = atoi(p);
  908. q = strchr(p, '/');
  909. if (!q) {
  910. bi->relay_port = bi->telnet_port;
  911. } else {
  912. bi->relay_port = atoi(q + 1);
  913. }
  914. }
  915. set_user(&USERENTRY_BOTADDR, u1, bi);
  916. }
  917. static void cmd_comment(struct userrec *u, int idx, char *par)
  918. {
  919. char *handle;
  920. struct userrec *u1;
  921. if (!par[0]) {
  922. dprintf(idx, "Usage: comment <handle> <newcomment>\n");
  923. return;
  924. }
  925. handle = newsplit(&par);
  926. u1 = get_user_by_handle(userlist, handle);
  927. if (!u1) {
  928. dprintf(idx, "No such user!\n");
  929. return;
  930. }
  931. if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
  932. strcasecmp(handle, dcc[idx].nick)) {
  933. dprintf(idx, "Can't change comment on the bot owner.\n");
  934. return;
  935. }
  936. putlog(LOG_CMDS, "*", "#%s# comment %s %s", dcc[idx].nick, handle, par);
  937. if (!strcasecmp(par, "none")) {
  938. dprintf(idx, "Okay, comment blanked.\n");
  939. set_user(&USERENTRY_COMMENT, u1, NULL);
  940. return;
  941. }
  942. dprintf(idx, "Changed comment.\n");
  943. set_user(&USERENTRY_COMMENT, u1, par);
  944. }
  945. static void cmd_restart(struct userrec *u, int idx, char *par)
  946. {
  947. putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
  948. if (!backgrd) {
  949. dprintf(idx, "You can not .restart a bot when running -n (due to tcl)\n");
  950. return;
  951. }
  952. dprintf(idx, "Restarting.\n");
  953. if (make_userfile) {
  954. putlog(LOG_MISC, "*",
  955. "Uh, guess you don't need to create a new userfile.");
  956. make_userfile = 0;
  957. }
  958. write_userfile(-1);
  959. putlog(LOG_MISC, "*", "Restarting ...");
  960. wipe_timers(interp, &utimer);
  961. wipe_timers(interp, &timer);
  962. do_restart = idx;
  963. }
  964. static void cmd_rehash(struct userrec *u, int idx, char *par)
  965. {
  966. putlog(LOG_CMDS, "*", "#%s# rehash", dcc[idx].nick);
  967. dprintf(idx, "Rehashing.\n");
  968. if (make_userfile) {
  969. putlog(LOG_MISC, "*",
  970. "Uh, guess you don't need to create a new userfile.");
  971. make_userfile = 0;
  972. }
  973. write_userfile(-1);
  974. putlog(LOG_MISC, "*", "Rehashing ...");
  975. do_restart = -2;
  976. }
  977. static void cmd_reload(struct userrec *u, int idx, char *par)
  978. {
  979. putlog(LOG_CMDS, "*", "#%s# reload", dcc[idx].nick);
  980. dprintf(idx, "Reloading user file...\n");
  981. reload();
  982. }
  983. /* this get replaced in server.so with a version that handles the server */
  984. void cmd_die(struct userrec *u, int idx, char *par)
  985. {
  986. char s[1024];
  987. putlog(LOG_CMDS, "*", "#%s# die %s", dcc[idx].nick, par);
  988. if (par[0]) {
  989. simple_sprintf(s, "BOT SHUTDOWN (%s: %s)", dcc[idx].nick, par);
  990. } else {
  991. simple_sprintf(s, "BOT SHUTDOWN (authorized by %s)", dcc[idx].nick);
  992. }
  993. chatout("*** %s\n", s);
  994. botnet_send_chat(-1, botnetnick, s);
  995. botnet_send_bye();
  996. write_userfile(-1);
  997. simple_sprintf(s, "DIE BY %s!%s (%s)", dcc[idx].nick,
  998. dcc[idx].host, par[0] ? par : "request");
  999. fatal(s, 0);
  1000. }
  1001. static void cmd_debug(struct userrec *u, int idx, char *par)
  1002. {
  1003. if (!strcasecmp(par, "help")) {
  1004. putlog(LOG_CMDS, "*", "#%s# debug help", dcc[idx].nick);
  1005. debug_help(idx);
  1006. } else {
  1007. putlog(LOG_CMDS, "*", "#%s# debug", dcc[idx].nick);
  1008. debug_mem_to_dcc(idx);
  1009. }
  1010. }
  1011. static void cmd_simul(struct userrec *u, int idx, char *par)
  1012. {
  1013. char *nick;
  1014. int i, ok = 0;
  1015. nick = newsplit(&par);
  1016. if (!par[0]) {
  1017. dprintf(idx, "Usage: simul <nick> <text>\n");
  1018. return;
  1019. }
  1020. if (isowner(nick)) {
  1021. dprintf(idx, "Unable to '.simul' permanent owners.\n");
  1022. return;
  1023. }
  1024. for (i = 0; i < dcc_total; i++)
  1025. if (!strcasecmp(nick, dcc[i].nick) && !ok &&
  1026. (dcc[i].type->flags & DCT_SIMUL)) {
  1027. putlog(LOG_CMDS, "*", "#%s# simul %s %s", dcc[idx].nick, nick, par);
  1028. if (dcc[i].type && dcc[i].type->activity) {
  1029. dcc[i].type->activity(i, par, strlen(par));
  1030. ok = 1;
  1031. }
  1032. }
  1033. if (!ok)
  1034. dprintf(idx, "No such user on the party line.\n");
  1035. }
  1036. static void cmd_link(struct userrec *u, int idx, char *par)
  1037. {
  1038. char *s;
  1039. int i;
  1040. if (!par[0]) {
  1041. dprintf(idx, "Usage: link [some-bot] <new-bot>\n");
  1042. return;
  1043. }
  1044. putlog(LOG_CMDS, "*", "#%s# link %s", dcc[idx].nick, par);
  1045. s = newsplit(&par);
  1046. if (!par[0] || !strcasecmp(par, botnetnick))
  1047. botlink(dcc[idx].nick, idx, s);
  1048. else {
  1049. char x[40];
  1050. i = nextbot(s);
  1051. if (i < 0) {
  1052. dprintf(idx, "No such bot online.\n");
  1053. return;
  1054. }
  1055. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1056. botnet_send_link(i, x, s, par);
  1057. }
  1058. }
  1059. static void cmd_unlink(struct userrec *u, int idx, char *par)
  1060. {
  1061. int i;
  1062. char *bot;
  1063. if (!par[0]) {
  1064. dprintf(idx, "Usage: unlink <bot> [reason]\n");
  1065. return;
  1066. }
  1067. putlog(LOG_CMDS, "*", "#%s# unlink %s", dcc[idx].nick, par);
  1068. bot = newsplit(&par);
  1069. i = nextbot(bot);
  1070. if (i < 0) {
  1071. botunlink(idx, bot, par);
  1072. return;
  1073. }
  1074. /* if we're directly connected to that bot, just do it
  1075. * (is nike gunna sue?) */
  1076. if (!strcasecmp(dcc[i].nick, bot))
  1077. botunlink(idx, bot, par);
  1078. else {
  1079. char x[40];
  1080. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1081. botnet_send_unlink(i, x, lastbot(bot), bot, par);
  1082. }
  1083. }
  1084. static void cmd_relay(struct userrec *u, int idx, char *par)
  1085. {
  1086. if (!par[0]) {
  1087. dprintf(idx, "Usage: relay <bot>\n");
  1088. return;
  1089. }
  1090. putlog(LOG_CMDS, "*", "#%s# relay %s", dcc[idx].nick, par);
  1091. tandem_relay(idx, par, 0);
  1092. }
  1093. static void cmd_save(struct userrec *u, int idx, char *par)
  1094. {
  1095. putlog(LOG_CMDS, "*", "#%s# save", dcc[idx].nick);
  1096. dprintf(idx, "Saving user file...\n");
  1097. write_userfile(-1);
  1098. }
  1099. static void cmd_backup(struct userrec *u, int idx, char *par)
  1100. {
  1101. putlog(LOG_CMDS, "*", "#%s# backup", dcc[idx].nick);
  1102. dprintf(idx, "Backing up the user file...\n");
  1103. backup_userfile();
  1104. }
  1105. static void cmd_trace(struct userrec *u, int idx, char *par)
  1106. {
  1107. int i;
  1108. char x[NOTENAMELEN + 11], y[11];
  1109. if (!par[0]) {
  1110. dprintf(idx, "Usage: trace <botname>\n");
  1111. return;
  1112. }
  1113. if (!strcasecmp(par, botnetnick)) {
  1114. dprintf(idx, "That's me! Hiya! :)\n");
  1115. return;
  1116. }
  1117. i = nextbot(par);
  1118. if (i < 0) {
  1119. dprintf(idx, "Unreachable bot.\n");
  1120. return;
  1121. }
  1122. putlog(LOG_CMDS, "*", "#%s# trace %s", dcc[idx].nick, par);
  1123. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1124. simple_sprintf(y, ":%d", now);
  1125. botnet_send_trace(i, x, par, y);
  1126. }
  1127. static void cmd_binds(struct userrec *u, int idx, char *par)
  1128. {
  1129. putlog(LOG_CMDS, "*", "#%s# binds %s", dcc[idx].nick, par);
  1130. tell_binds(idx, par);
  1131. }
  1132. static void cmd_banner(struct userrec *u, int idx, char *par)
  1133. {
  1134. char s[1024];
  1135. int i;
  1136. if (!par[0]) {
  1137. dprintf(idx, "Usage: banner <message>\n");
  1138. return;
  1139. }
  1140. simple_sprintf(s, "\007\007### Botwide:[%s] %s\n", dcc[idx].nick, par);
  1141. for (i = 0; i < dcc_total; i++)
  1142. if (dcc[i].type->flags & DCT_MASTER)
  1143. dprintf(i, "%s", s);
  1144. }
  1145. /* after messing with someone's user flags, make sure the dcc-chat flags
  1146. * are set correctly */
  1147. int check_dcc_attrs(struct userrec *u, int oatr)
  1148. {
  1149. int i, stat;
  1150. char *p, *q, s[121];
  1151. /* if it matches someone in the owner list, make sure he/she has +n */
  1152. if (!u)
  1153. return 0;
  1154. /* make sure default owners are +n */
  1155. if (owner[0]) {
  1156. q = owner;
  1157. p = strchr(q, ',');
  1158. while (p) {
  1159. strncpy(s, q, p - q);
  1160. s[p - q] = 0;
  1161. rmspace(s);
  1162. if (!strcasecmp(u->handle, s))
  1163. u->flags = sanity_check(u->flags | USER_OWNER);
  1164. q = p + 1;
  1165. p = strchr(q, ',');
  1166. }
  1167. strcpy(s, q);
  1168. rmspace(s);
  1169. if (!strcasecmp(u->handle, s))
  1170. u->flags = sanity_check(u->flags | USER_OWNER);
  1171. }
  1172. for (i = 0; i < dcc_total; i++) {
  1173. if ((dcc[i].type->flags & DCT_MASTER) &&
  1174. (!strcasecmp(u->handle, dcc[i].nick))) {
  1175. stat = dcc[i].status;
  1176. if ((dcc[i].type == &DCC_CHAT) &&
  1177. ((u->flags & (USER_OP | USER_MASTER | USER_OWNER |
  1178. USER_BOTMAST))
  1179. != (oatr & (USER_OP | USER_MASTER | USER_OWNER |
  1180. USER_BOTMAST)))) {
  1181. botnet_send_join_idx(i, -1);
  1182. }
  1183. if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
  1184. struct flag_record fr =
  1185. {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  1186. dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
  1187. LOG_FILES | LOG_LEV1 | LOG_LEV2 |
  1188. LOG_LEV3 | LOG_LEV4 | LOG_LEV5 |
  1189. LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
  1190. LOG_WALL | LOG_DEBUG);
  1191. get_user_flagrec(u, &fr, NULL);
  1192. if (!chan_master(fr))
  1193. dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
  1194. dprintf(i, "*** POOF! ***\n");
  1195. dprintf(i, "You are no longer a master on this bot.\n");
  1196. }
  1197. if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
  1198. dcc[i].u.chat->con_flags |= conmask;
  1199. dprintf(i, "*** POOF! ***\n");
  1200. dprintf(i, "You are now a master on this bot.\n");
  1201. }
  1202. if (!(oatr & USER_BOTMAST) && (u->flags & USER_BOTMAST)) {
  1203. dprintf(i, "### POOF! ###\n");
  1204. dprintf(i, "You are now a botnet master on this bot.\n");
  1205. }
  1206. if ((oatr & USER_BOTMAST) && !(u->flags & USER_BOTMAST)) {
  1207. dprintf(i, "### POOF! ###\n");
  1208. dprintf(i, "You are no longer a botnet master on this bot.\n");
  1209. }
  1210. if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
  1211. dprintf(i, "@@@ POOF! @@@\n");
  1212. dprintf(i, "You are now an OWNER of this bot.\n");
  1213. }
  1214. if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
  1215. dprintf(i, "@@@ POOF! @@@\n");
  1216. dprintf(i, "You are no longer an owner of this bot.\n");
  1217. }
  1218. if ((stat & STAT_PARTY) && (u->flags & USER_OP))
  1219. stat &= ~STAT_PARTY;
  1220. if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
  1221. !(u->flags & USER_MASTER))
  1222. stat |= STAT_PARTY;
  1223. if ((stat & STAT_CHAT) && !(u->flags & USER_PARTY) &&
  1224. !(u->flags & USER_MASTER) &&
  1225. (!(u->flags & USER_OP) || require_p))
  1226. stat &= ~STAT_CHAT;
  1227. if ((dcc[i].type->flags & DCT_FILES) && !(stat & STAT_CHAT) &&
  1228. ((u->flags & USER_MASTER) || (u->flags & USER_PARTY) ||
  1229. ((u->flags & USER_OP) && !require_p)))
  1230. stat |= STAT_CHAT;
  1231. dcc[i].status = stat;
  1232. /* check if they no longer have access to wherever they are */
  1233. /* DON'T kick someone off the party line just cuz they lost +p
  1234. * (pinvite script removes +p after 5 mins automatically) */
  1235. if ((dcc[i].type->flags & DCT_FILES) && !(u->flags & USER_XFER) &&
  1236. !(u->flags & USER_MASTER)) {
  1237. dprintf(i, "-+- POOF! -+-\n");
  1238. dprintf(i, "You no longer have file area access.\n\n");
  1239. putlog(LOG_MISC, "*", "DCC user [%s]%s removed from file system",
  1240. dcc[i].nick, dcc[i].host);
  1241. if (dcc[i].status & STAT_CHAT) {
  1242. struct chat_info *ci;
  1243. ci = dcc[i].u.file->chat;
  1244. nfree(dcc[i].u.file);
  1245. dcc[i].u.chat = ci;
  1246. dcc[i].status &= (~STAT_CHAT);
  1247. dcc[i].type = &DCC_CHAT;
  1248. if (dcc[i].u.chat->channel >= 0) {
  1249. chanout_but(-1, dcc[i].u.chat->channel,
  1250. "*** %s has returned.\n", dcc[i].nick);
  1251. Context;
  1252. if (dcc[i].u.chat->channel < 100000)
  1253. botnet_send_join_idx(i, -1);
  1254. }
  1255. } else {
  1256. killsock(dcc[i].sock);
  1257. lostdcc(i);
  1258. }
  1259. }
  1260. }
  1261. if ((dcc[i].type == &DCC_BOT) && !strcasecmp(u->handle, dcc[i].nick)) {
  1262. if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
  1263. dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
  1264. if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
  1265. dcc[i].status |= STAT_LEAF;
  1266. }
  1267. }
  1268. return u->flags;
  1269. }
  1270. int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
  1271. int ochatr)
  1272. {
  1273. int i, found = 0, atr = u ? u->flags : 0;
  1274. struct chanset_t *chan;
  1275. if (!u)
  1276. return 0;
  1277. chan = chanset;
  1278. for (i = 0; i < dcc_total; i++) {
  1279. if ((dcc[i].type->flags & DCT_MASTER) &&
  1280. !strcasecmp(u->handle, dcc[i].nick)) {
  1281. if ((dcc[i].type == &DCC_CHAT) &&
  1282. ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
  1283. != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
  1284. botnet_send_join_idx(i, -1);
  1285. if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
  1286. if (!(atr & USER_MASTER))
  1287. dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
  1288. dprintf(i, "*** POOF! ***\n");
  1289. dprintf(i, "You are no longer a master on %s.\n", chname);
  1290. }
  1291. if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
  1292. dcc[i].u.chat->con_flags |= conmask;
  1293. if (!(atr & USER_MASTER))
  1294. dcc[i].u.chat->con_flags &=
  1295. ~(LOG_LEV1 | LOG_LEV2 | LOG_LEV3 | LOG_LEV4 |
  1296. LOG_LEV5 | LOG_LEV6 | LOG_LEV7 | LOG_LEV8 |
  1297. LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
  1298. dprintf(i, "*** POOF! ***\n");
  1299. dprintf(i, "You are now a master on %s.\n", chname);
  1300. }
  1301. if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
  1302. dprintf(i, "@@@ POOF! @@@\n");
  1303. dprintf(i, "You are now an OWNER of %s.\n", chname);
  1304. }
  1305. if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
  1306. dprintf(i, "@@@ POOF! @@@\n");
  1307. dprintf(i, "You are no longer an owner of %s.\n", chname);
  1308. }
  1309. if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
  1310. (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
  1311. ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
  1312. (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
  1313. struct flag_record fr =
  1314. {FR_CHAN, 0, 0, 0, 0, 0};
  1315. while (chan && !found) {
  1316. get_user_flagrec(u, &fr, chan->name);
  1317. if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
  1318. found = 1;
  1319. else
  1320. chan = chan->next;
  1321. }
  1322. if (!chan)
  1323. chan = chanset;
  1324. if (chan)
  1325. strcpy(dcc[i].u.chat->con_chan, chan->name);
  1326. else
  1327. strcpy(dcc[i].u.chat->con_chan, "*");
  1328. }
  1329. }
  1330. }
  1331. return chflags;
  1332. }
  1333. static void cmd_chattr(struct userrec *u, int idx, char *par)
  1334. {
  1335. char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
  1336. struct chanset_t *chan = NULL;
  1337. struct userrec *u2;
  1338. struct flag_record pls = {0, 0, 0, 0, 0, 0},
  1339. mns = {0, 0, 0, 0, 0, 0},
  1340. user = {0, 0, 0, 0, 0, 0};
  1341. module_entry *me;
  1342. int fl = -1, of = 0, ocf = 0;
  1343. if (!par[0]) {
  1344. dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
  1345. return;
  1346. }
  1347. hand = newsplit(&par);
  1348. u2 = get_user_by_handle(userlist, hand);
  1349. if (!u2) {
  1350. dprintf(idx, "No such user!\n");
  1351. return;
  1352. }
  1353. /* Parse args */
  1354. if (par[0]) {
  1355. arg = newsplit(&par);
  1356. if (par[0]) {
  1357. /* .chattr <handle> <changes> <channel> */
  1358. chg = arg;
  1359. arg = newsplit(&par);
  1360. chan = findchan(arg);
  1361. } else {
  1362. chan = findchan(arg);
  1363. /* ugly hack for modeless channels -- rtc */
  1364. if (!(arg[0] == '+' && chan) &&
  1365. !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
  1366. /* .chattr <handle> <changes> */
  1367. chg = arg;
  1368. chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
  1369. arg = NULL;
  1370. }
  1371. /* .chattr <handle> <channel>: nothing to do... */
  1372. }
  1373. }
  1374. /* arg: pointer to channel name, NULL if none specified
  1375. * chan: pointer to channel structure, NULL if none found or none specified
  1376. * chg: pointer to changes, NULL if none specified
  1377. */
  1378. Assert(!(!arg && chan));
  1379. if (arg && !chan) {
  1380. dprintf(idx, "No channel record for %s.\n", arg);
  1381. return;
  1382. }
  1383. if (chg) {
  1384. if (!arg && strpbrk(chg, "&|")) {
  1385. /* .chattr <handle> *[&|]*: use console channel if found... */
  1386. if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
  1387. arg = NULL;
  1388. else
  1389. chan = findchan(arg);
  1390. if (arg && !chan) {
  1391. dprintf (idx, "Invalid console channel %s.\n", arg);
  1392. return;
  1393. }
  1394. } else if (arg && !strpbrk(chg, "&|")) {
  1395. Context;
  1396. tmpchg = nmalloc(strlen(chg) + 2);
  1397. strcpy (tmpchg, "|");
  1398. strcat (tmpchg, chg);
  1399. chg = tmpchg;
  1400. }
  1401. }
  1402. par = arg;
  1403. user.match = FR_GLOBAL;
  1404. if (chan)
  1405. user.match |= FR_CHAN;
  1406. get_user_flagrec(u, &user, chan ? chan->name : 0);
  1407. if (!chan && !glob_botmast(user)) {
  1408. dprintf(idx, "You do not have Bot Master privileges.\n");
  1409. if (tmpchg)
  1410. nfree(tmpchg);
  1411. return;
  1412. }
  1413. if (chan && !glob_master(user) && !chan_master(user)) {
  1414. dprintf(idx, "You do not have channel master privileges for channel %s\n",
  1415. par);
  1416. if (tmpchg)
  1417. nfree(tmpchg);
  1418. return;
  1419. }
  1420. user.match &= fl;
  1421. if (chg) {
  1422. pls.match = user.match;
  1423. break_down_flags(chg, &pls, &mns);
  1424. /* no-one can change these flags on-the-fly */
  1425. pls.global &= ~(USER_BOT);
  1426. mns.global &= ~(USER_BOT);
  1427. if (chan) {
  1428. pls.chan &= ~(BOT_SHARE);
  1429. mns.chan &= ~(BOT_SHARE);
  1430. }
  1431. if (!glob_owner(user)) {
  1432. pls.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
  1433. mns.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
  1434. if (chan) {
  1435. pls.chan &= ~USER_OWNER;
  1436. mns.chan &= ~USER_OWNER;
  1437. }
  1438. if (!glob_master(user)) {
  1439. pls.global &= USER_PARTY | USER_XFER;
  1440. mns.global &= USER_PARTY | USER_XFER;
  1441. if (!glob_botmast(user)) {
  1442. pls.global = 0;
  1443. mns.global = 0;
  1444. }
  1445. }
  1446. }
  1447. if (chan && !chan_owner(user) && !glob_owner(user)) {
  1448. pls.chan &= ~USER_MASTER;
  1449. mns.chan &= ~USER_MASTER;
  1450. if (!chan_master(user) && !glob_master(user)) {
  1451. pls.chan = 0;
  1452. mns.chan = 0;
  1453. }
  1454. }
  1455. get_user_flagrec(u2, &user, par);
  1456. if (user.match & FR_GLOBAL) {
  1457. of = user.global;
  1458. user.global = sanity_check((user.global |pls.global) &~mns.global);
  1459. user.udef_global = (user.udef_global | pls.udef_global)
  1460. & ~mns.udef_global;
  1461. }
  1462. if (chan) {
  1463. ocf = user.chan;
  1464. user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
  1465. user.global);
  1466. user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
  1467. }
  1468. set_user_flagrec(u2, &user, par);
  1469. }
  1470. if (chan)
  1471. putlog(LOG_CMDS, "*", "#%s# (%s) chattr %s %s",
  1472. dcc[idx].nick, chan ? chan->name : "*", hand, chg ? chg : "");
  1473. else
  1474. putlog(LOG_CMDS, "*", "#%s# chattr %s %s", dcc[idx].nick, hand,
  1475. chg ? chg : "");
  1476. /* get current flags and display them */
  1477. if (user.match & FR_GLOBAL) {
  1478. user.match = FR_GLOBAL;
  1479. if (chg)
  1480. check_dcc_attrs(u2, of);
  1481. get_user_flagrec(u2, &user, NULL);
  1482. build_flags(work, &user, NULL);
  1483. if (work[0] != '-')
  1484. dprintf(idx, "Global flags for %s are now +%s\n", hand, work);
  1485. else
  1486. dprintf(idx, "No global flags for %s.\n", hand);
  1487. }
  1488. if (chan) {
  1489. user.match = FR_CHAN;
  1490. get_user_flagrec(u2, &user, par);
  1491. user.chan &= ~BOT_SHARE;
  1492. if (chg)
  1493. check_dcc_chanattrs(u2, chan->name, user.chan, ocf);
  1494. build_flags(work, &user, NULL);
  1495. if (work[0] != '-')
  1496. dprintf(idx, "Channel flags for %s on %s are now +%s\n", hand,
  1497. chan->name, work);
  1498. else
  1499. dprintf(idx, "No flags for %s on %s.\n", hand, chan->name);
  1500. if (chg && (me = module_find("irc", 0, 0))) {
  1501. Function *func = me->funcs;
  1502. if (chan)
  1503. (func[IRC_RECHECK_CHANNEL]) (chan, 0);
  1504. }
  1505. }
  1506. if (tmpchg)
  1507. nfree(tmpchg);
  1508. }
  1509. static void cmd_botattr(struct userrec *u, int idx, char *par)
  1510. {
  1511. char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
  1512. struct chanset_t *chan = NULL;
  1513. struct userrec *u2;
  1514. struct flag_record pls =
  1515. {0, 0, 0, 0, 0, 0}, mns =
  1516. {0, 0, 0, 0, 0, 0}, user =
  1517. {0, 0, 0, 0, 0, 0};
  1518. int idx2;
  1519. if (!par[0]) {
  1520. dprintf(idx, "Usage: botattr <handle> [changes] [channel]\n");
  1521. return;
  1522. }
  1523. hand = newsplit(&par);
  1524. u2 = get_user_by_handle(userlist, hand);
  1525. if (!u2 || !(u2->flags & USER_BOT)) {
  1526. dprintf(idx, "No such bot!\n");
  1527. return;
  1528. }
  1529. for (idx2 = 0; idx2 < dcc_total; idx2++)
  1530. if ((dcc[idx2].type != &DCC_RELAY) && !strcasecmp(dcc[idx2].nick, hand))
  1531. break;
  1532. if (idx2 != dcc_total) {
  1533. dprintf(idx, "You may not change the attributes of a directly linked bot.\n");
  1534. return;
  1535. }
  1536. /* Parse args */
  1537. if (par[0]) {
  1538. arg = newsplit(&par);
  1539. if (par[0]) {
  1540. /* .botattr <handle> <changes> <channel> */
  1541. chg = arg;
  1542. arg = newsplit(&par);
  1543. chan = findchan(arg);
  1544. } else {
  1545. chan = findchan(arg);
  1546. /* ugly hack for modeless channels -- rtc */
  1547. if (!(arg[0] == '+' && chan) &&
  1548. !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
  1549. /* .botattr <handle> <changes> */
  1550. chg = arg;
  1551. chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
  1552. arg = NULL;
  1553. }
  1554. /* .botattr <handle> <channel>: nothing to do... */
  1555. }
  1556. }
  1557. /* arg: pointer to channel name, NULL if none specified
  1558. * chan: pointer to channel structure, NULL if none found or none specified
  1559. * chg: pointer to changes, NULL if none specified
  1560. */
  1561. Assert(!(!arg && chan));
  1562. if (arg && !chan) {
  1563. dprintf(idx, "No channel record for %s.\n", arg);
  1564. return;
  1565. }
  1566. if (chg) {
  1567. if (!arg && strpbrk(chg, "&|")) {
  1568. /* botattr <handle> *[&|]*: use console channel if found... */
  1569. if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
  1570. arg = NULL;
  1571. else
  1572. chan = findchan(arg);
  1573. if (arg && !chan) {
  1574. dprintf (idx, "Invalid console channel %s.\n", arg);
  1575. return;
  1576. }
  1577. } else if (arg && !strpbrk(chg, "&|")) {
  1578. Context;
  1579. tmpchg = nmalloc(strlen(chg) + 2);
  1580. strcpy (tmpchg, "|");
  1581. strcat (tmpchg, chg);
  1582. chg = tmpchg;
  1583. }
  1584. }
  1585. par = arg;
  1586. user.match = FR_GLOBAL;
  1587. get_user_flagrec(u, &user, chan ? chan->name : 0);
  1588. if (!glob_botmast(user)) {
  1589. dprintf(idx, "You do not have Bot Master privileges.\n");
  1590. if (tmpchg)
  1591. nfree(tmpchg);
  1592. return;
  1593. }
  1594. if (chg) {
  1595. user.match = FR_BOT | (chan ? FR_CHAN : 0);
  1596. pls.match = user.match;
  1597. break_down_flags(chg, &pls, &mns);
  1598. /* no-one can change these flags on-the-fly */
  1599. pls.global &=~BOT_BOT;
  1600. mns.global &=~BOT_BOT;
  1601. if (chan && glob_owner(user)) {
  1602. pls.chan &= BOT_SHARE;
  1603. mns.chan &= BOT_SHARE;
  1604. } else {
  1605. pls.chan = 0;
  1606. mns.chan = 0;
  1607. }
  1608. if (!glob_owner(user)) {
  1609. pls.bot &= ~(BOT_SHARE | BOT_GLOBAL);
  1610. mns.bot &= ~(BOT_SHARE | BOT_GLOBAL);
  1611. }
  1612. user.match = FR_BOT | (chan ? FR_CHAN : 0);
  1613. get_user_flagrec(u2, &user, par);
  1614. user.bot = (user.bot | pls.bot) & ~mns.bot;
  1615. if ((user.bot & BOT_SHARE) == BOT_SHARE)
  1616. user.bot &= ~BOT_SHARE;
  1617. if (chan)
  1618. user.chan = (user.chan | pls.chan) & ~mns.chan;
  1619. set_user_flagrec(u2, &user, par);
  1620. }
  1621. if (chan)
  1622. putlog(LOG_CMDS, "*", "#%s# (%s) botattr %s %s",
  1623. dcc[idx].nick, chan->name, hand, chg ? chg : "");
  1624. else
  1625. putlog(LOG_CMDS, "*", "#%s# botattr %s %s", dcc[idx].nick, hand,
  1626. chg ? chg : "");
  1627. /* get current flags and display them */
  1628. if (!chan || pls.bot || mns.bot) {
  1629. user.match = FR_BOT;
  1630. get_user_flagrec(u2, &user, NULL);
  1631. build_flags(work, &user, NULL);
  1632. if (work[0] != '-')
  1633. dprintf(idx, "Bot flags for %s are now +%s\n", hand, work);
  1634. else
  1635. dprintf(idx, "No bot flags for %s.\n", hand);
  1636. }
  1637. if (chan) {
  1638. user.match = FR_CHAN;
  1639. get_user_flagrec(u2, &user, par);
  1640. user.chan &= BOT_SHARE;
  1641. build_flags(work, &user, NULL);
  1642. if (work[0] != '-')
  1643. dprintf(idx, "Bot flags for %s on %s are now +%s\n", hand,
  1644. chan->name, work);
  1645. else
  1646. dprintf(idx, "No bot flags for %s on %s.\n", hand, chan->name);
  1647. }
  1648. if (tmpchg)
  1649. nfree(tmpchg);
  1650. }
  1651. static void cmd_chat(struct userrec *u, int idx, char *par)
  1652. {
  1653. char *arg;
  1654. int newchan, oldchan;
  1655. module_entry *me;
  1656. arg = newsplit(&par);
  1657. if (!strcasecmp(arg, "off")) {
  1658. /* turn chat off */
  1659. if (dcc[idx].u.chat->channel < 0) {
  1660. dprintf(idx, "You weren't in chat anyway!\n");
  1661. return;
  1662. } else {
  1663. dprintf(idx, "Leaving chat mode...\n");
  1664. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
  1665. dcc[idx].u.chat->channel);
  1666. chanout_but(-1, dcc[idx].u.chat->channel,
  1667. "*** %s left the party line.\n",
  1668. dcc[idx].nick);
  1669. Context;
  1670. if (dcc[idx].u.chat->channel < 100000)
  1671. botnet_send_part_idx(idx, "");
  1672. }
  1673. dcc[idx].u.chat->channel = (-1);
  1674. } else {
  1675. if (arg[0] == '*') {
  1676. if (((arg[1] < '0') || (arg[1] > '9'))) {
  1677. if (arg[1] == 0)
  1678. newchan = 0;
  1679. else {
  1680. Tcl_SetVar(interp, "chan", arg, 0);
  1681. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  1682. interp->result[0])
  1683. newchan = atoi(interp->result);
  1684. else
  1685. newchan = -1;
  1686. }
  1687. if (newchan < 0) {
  1688. dprintf(idx, "No channel by that name.\n");
  1689. return;
  1690. }
  1691. } else
  1692. newchan = 100000 + atoi(arg + 1);
  1693. if (newchan < 100000 || newchan > 199999) {
  1694. dprintf(idx, "Channel # out of range: local channels must be *0-*99999\n");
  1695. return;
  1696. }
  1697. } else {
  1698. if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
  1699. if (!strcasecmp(arg, "on"))
  1700. newchan = 0;
  1701. else {
  1702. Tcl_SetVar(interp, "chan", arg, 0);
  1703. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  1704. interp->result[0])
  1705. newchan = atoi(interp->result);
  1706. else
  1707. newchan = -1;
  1708. }
  1709. if (newchan < 0) {
  1710. dprintf(idx, "No channel by that name.\n");
  1711. return;
  1712. }
  1713. } else
  1714. newchan = atoi(arg);
  1715. if ((newchan < 0) || (newchan > 99999)) {
  1716. dprintf(idx, "Channel # out of range: must be between 0 and 99999.\n");
  1717. return;
  1718. }
  1719. }
  1720. /* if coming back from being off the party line, make sure they're
  1721. * not away */
  1722. if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
  1723. not_away(idx);
  1724. if (dcc[idx].u.chat->channel == newchan) {
  1725. if (newchan == 0) {
  1726. dprintf(idx, "You're already on the party line!\n");
  1727. return;
  1728. } else {
  1729. dprintf(idx, "You're already on channel %s%d!\n",
  1730. (newchan < 100000) ? "" : "*", newchan % 100000);
  1731. return;
  1732. }
  1733. } else {
  1734. oldchan = dcc[idx].u.chat->channel;
  1735. if (oldchan >= 0)
  1736. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
  1737. if (oldchan == 0) {
  1738. chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
  1739. Context;
  1740. } else if (oldchan > 0) {
  1741. chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
  1742. Context;
  1743. }
  1744. dcc[idx].u.chat->channel = newchan;
  1745. if (newchan == 0) {
  1746. dprintf(idx, "Entering the party line...\n");
  1747. chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
  1748. Context;
  1749. } else {
  1750. dprintf(idx, "Joining channel '%s'...\n", arg);
  1751. chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
  1752. Context;
  1753. }
  1754. check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
  1755. dcc[idx].sock, dcc[idx].host);
  1756. if (newchan < 100000)
  1757. botnet_send_join_idx(idx, oldchan);
  1758. else if (oldchan < 100000)
  1759. botnet_send_part_idx(idx, "");
  1760. }
  1761. }
  1762. /* new style autosave here too -- rtc, 09/28/1999*/
  1763. if ((me = module_find("console", 1, 1))) {
  1764. Function *func = me->funcs;
  1765. (func[CONSOLE_DOSTORE]) (idx);
  1766. }
  1767. }
  1768. static void cmd_echo(struct userrec *u, int idx, char *par)
  1769. {
  1770. module_entry *me;
  1771. if (!par[0]) {
  1772. dprintf(idx, "Echo is currently %s.\n", dcc[idx].status & STAT_ECHO ?
  1773. "on" : "off");
  1774. return;
  1775. }
  1776. if (!strcasecmp(par, "on")) {
  1777. dprintf(idx, "Echo turned on.\n");
  1778. dcc[idx].status |= STAT_ECHO;
  1779. } else if (!strcasecmp(par, "off")) {
  1780. dprintf(idx, "Echo turned off.\n");
  1781. dcc[idx].status &= ~STAT_ECHO;
  1782. } else {
  1783. dprintf(idx, "Usage: echo <on/off>\n");
  1784. return;
  1785. }
  1786. /* new style autosave here too -- rtc, 09/28/1999*/
  1787. if ((me = module_find("console", 1, 1))) {
  1788. Function *func = me->funcs;
  1789. (func[CONSOLE_DOSTORE]) (idx);
  1790. }
  1791. }
  1792. int stripmodes(char *s)
  1793. {
  1794. int res = 0;
  1795. for (; *s; s++)
  1796. switch (tolower(*s)) {
  1797. case 'b':
  1798. res |= STRIP_BOLD;
  1799. break;
  1800. case 'c':
  1801. res |= STRIP_COLOR;
  1802. break;
  1803. case 'r':
  1804. res |= STRIP_REV;
  1805. break;
  1806. case 'u':
  1807. res |= STRIP_UNDER;
  1808. break;
  1809. case 'a':
  1810. res |= STRIP_ANSI;
  1811. break;
  1812. case 'g':
  1813. res |= STRIP_BELLS;
  1814. break;
  1815. case '*':
  1816. res |= STRIP_ALL;
  1817. break;
  1818. }
  1819. return res;
  1820. }
  1821. char *stripmasktype(int x)
  1822. {
  1823. static char s[20];
  1824. char *p = s;
  1825. if (x & STRIP_BOLD)
  1826. *p++ = 'b';
  1827. if (x & STRIP_COLOR)
  1828. *p++ = 'c';
  1829. if (x & STRIP_REV)
  1830. *p++ = 'r';
  1831. if (x & STRIP_UNDER)
  1832. *p++ = 'u';
  1833. if (x & STRIP_ANSI)
  1834. *p++ = 'a';
  1835. if (x & STRIP_BELLS)
  1836. *p++ = 'g';
  1837. if (p == s)
  1838. *p++ = '-';
  1839. *p = 0;
  1840. return s;
  1841. }
  1842. static char *stripmaskname(int x)
  1843. {
  1844. static char s[161];
  1845. int i = 0;
  1846. s[i] = 0;
  1847. if (x & STRIP_BOLD)
  1848. i += my_strcpy(s + i, "bold, ");
  1849. if (x & STRIP_COLOR)
  1850. i += my_strcpy(s + i, "color, ");
  1851. if (x & STRIP_REV)
  1852. i += my_strcpy(s + i, "reverse, ");
  1853. if (x & STRIP_UNDER)
  1854. i += my_strcpy(s + i, "underline, ");
  1855. if (x & STRIP_ANSI)
  1856. i += my_strcpy(s + i, "ansi, ");
  1857. if (x & STRIP_BELLS)
  1858. i += my_strcpy(s + i, "bells, ");
  1859. if (!i)
  1860. strcpy(s, "none");
  1861. else
  1862. s[i - 2] = 0;
  1863. return s;
  1864. }
  1865. static void cmd_strip(struct userrec *u, int idx, char *par)
  1866. {
  1867. char *nick, *changes, *c, s[2];
  1868. int dest = 0, i, pls, md, ok = 0;
  1869. module_entry *me;
  1870. if (!par[0]) {
  1871. dprintf(idx, "Your current strip settings are: %s (%s)\n",
  1872. stripmasktype(dcc[idx].u.chat->strip_flags),
  1873. stripmaskname(dcc[idx].u.chat->strip_flags));
  1874. return;
  1875. }
  1876. nick = newsplit(&par);
  1877. if ((nick[0] != '+') && (nick[0] != '-') && u &&
  1878. (u->flags & USER_MASTER)) {
  1879. for (i = 0; i < dcc_total; i++)
  1880. if (!strcasecmp(nick, dcc[i].nick) && (dcc[i].type == &DCC_CHAT) &&
  1881. !ok) {
  1882. ok = 1;
  1883. dest = i;
  1884. }
  1885. if (!ok) {
  1886. dprintf(idx, "No such user on the party line!\n");
  1887. return;
  1888. }
  1889. changes = par;
  1890. } else {
  1891. changes = nick;
  1892. nick = "";
  1893. dest = idx;
  1894. }
  1895. c = changes;
  1896. if ((c[0] != '+') && (c[0] != '-'))
  1897. dcc[dest].u.chat->strip_flags = 0;
  1898. s[1] = 0;
  1899. for (pls = 1; *c; c++) {
  1900. switch (*c) {
  1901. case '+':
  1902. pls = 1;
  1903. break;
  1904. case '-':
  1905. pls = 0;
  1906. break;
  1907. default:
  1908. s[0] = *c;
  1909. md = stripmodes(s);
  1910. if (pls == 1)
  1911. dcc[dest].u.chat->strip_flags |= md;
  1912. else
  1913. dcc[dest].u.chat->strip_flags &= ~md;
  1914. }
  1915. }
  1916. if (nick[0])
  1917. putlog(LOG_CMDS, "*", "#%s# strip %s %s", dcc[idx].nick, nick, changes);
  1918. else
  1919. putlog(LOG_CMDS, "*", "#%s# strip %s", dcc[idx].nick, changes);
  1920. if (dest == idx) {
  1921. dprintf(idx, "Your strip settings are: %s (%s)\n",
  1922. stripmasktype(dcc[idx].u.chat->strip_flags),
  1923. stripmaskname(dcc[idx].u.chat->strip_flags));
  1924. } else {
  1925. dprintf(idx, "Strip setting for %s: %s (%s)\n", dcc[dest].nick,
  1926. stripmasktype(dcc[dest].u.chat->strip_flags),
  1927. stripmaskname(dcc[dest].u.chat->strip_flags));
  1928. dprintf(dest, "%s set your strip settings to: %s (%s)\n", dcc[idx].nick,
  1929. stripmasktype(dcc[dest].u.chat->strip_flags),
  1930. stripmaskname(dcc[dest].u.chat->strip_flags));
  1931. }
  1932. /* new style autosave here too -- rtc, 09/28/1999*/
  1933. if ((me = module_find("console", 1, 1))) {
  1934. Function *func = me->funcs;
  1935. (func[CONSOLE_DOSTORE]) (dest);
  1936. }
  1937. }
  1938. static void cmd_su(struct userrec *u, int idx, char *par)
  1939. {
  1940. int atr = u ? u->flags : 0;
  1941. struct flag_record fr = {FR_ANYWH | FR_CHAN | FR_GLOBAL, 0, 0, 0, 0, 0};
  1942. Context;
  1943. u = get_user_by_handle(userlist, par);
  1944. if (!par[0])
  1945. dprintf(idx, "Usage: su <user>\n");
  1946. else if (!u)
  1947. dprintf(idx, "No such user.\n");
  1948. else if (u->flags & USER_BOT)
  1949. dprintf(idx, "Can't su to a bot... then again, why would you wanna?\n");
  1950. else if (dcc[idx].u.chat->su_nick)
  1951. dprintf(idx, "You cannot currently double .su, try .su'ing directly\n");
  1952. else {
  1953. get_user_flagrec(u, &fr, NULL);
  1954. if ((!glob_party(fr) && (require_p || !(glob_op(fr) || chan_op(fr)))) &&
  1955. !(atr & USER_BOTMAST))
  1956. dprintf(idx, "No party line access permitted for %s.\n", par);
  1957. else {
  1958. correct_handle(par);
  1959. putlog(LOG_CMDS, "*", "#%s# su %s", dcc[idx].nick, par);
  1960. if (!(atr & USER_OWNER) ||
  1961. ((atr & USER_OWNER) && !(isowner(dcc[idx].nick))) ||
  1962. ((u->flags & USER_OWNER) && (isowner(par)))) {
  1963. /* This check is only important for non-owners */
  1964. if (u_pass_match(u, "-")) {
  1965. dprintf(idx, "No password set for user. You may not .su to them\n");
  1966. return;
  1967. }
  1968. if (dcc[idx].u.chat->channel < 100000)
  1969. botnet_send_part_idx(idx, "");
  1970. chanout_but(-1, dcc[idx].u.chat->channel,
  1971. "*** %s left the party line.\n", dcc[idx].nick);
  1972. Context;
  1973. /* store the old nick in the away section, for weenies who can't get
  1974. * their password right ;) */
  1975. if (dcc[idx].u.chat->away != NULL)
  1976. nfree(dcc[idx].u.chat->away);
  1977. dcc[idx].u.chat->away = get_data_ptr(strlen(dcc[idx].nick) + 1);
  1978. strcpy(dcc[idx].u.chat->away, dcc[idx].nick);
  1979. dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
  1980. strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
  1981. dcc[idx].user = u;
  1982. strcpy(dcc[idx].nick, par);
  1983. dprintf(idx, "Enter password for %s%s\n", par,
  1984. (dcc[idx].status & STAT_TELNET) ? "\377\373\001" : "");
  1985. dcc[idx].type = &DCC_CHAT_PASS;
  1986. } else if (atr & USER_OWNER) {
  1987. if (dcc[idx].u.chat->channel < 100000)
  1988. botnet_send_part_idx(idx, "");
  1989. chanout_but(-1, dcc[idx].u.chat->channel,
  1990. "*** %s left the party line.\n", dcc[idx].nick);
  1991. dprintf(idx, "Setting your username to %s.\n", par);
  1992. if (atr & USER_MASTER)
  1993. dcc[idx].u.chat->con_flags = conmask;
  1994. dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
  1995. strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
  1996. dcc[idx].user = u;
  1997. strcpy(dcc[idx].nick, par);
  1998. dcc_chatter(idx);
  1999. }
  2000. }
  2001. }
  2002. }
  2003. static void cmd_fixcodes(struct userrec *u, int idx, char *par)
  2004. {
  2005. if (dcc[idx].status & STAT_ECHO) {
  2006. dcc[idx].status |= STAT_TELNET;
  2007. dcc[idx].status &= ~STAT_ECHO;
  2008. dprintf(idx, "Turned on telnet codes\n");
  2009. putlog(LOG_CMDS, "*", "#%s# fixcodes (telnet on)", dcc[idx].nick);
  2010. return;
  2011. }
  2012. if (dcc[idx].status & STAT_TELNET) {
  2013. dcc[idx].status |= STAT_ECHO;
  2014. dcc[idx].status &= ~STAT_TELNET;
  2015. dprintf(idx, "Turned off telnet codes\n");
  2016. putlog(LOG_CMDS, "*", "#%s# fixcodes (telnet off)", dcc[idx].nick);
  2017. return;
  2018. }
  2019. }
  2020. static void cmd_page(struct userrec *u, int idx, char *par)
  2021. {
  2022. int a;
  2023. module_entry *me;
  2024. if (!par[0]) {
  2025. if (dcc[idx].status & STAT_PAGE) {
  2026. dprintf(idx, "Currently paging outputs to %d lines.\n",
  2027. dcc[idx].u.chat->max_line);
  2028. } else
  2029. dprintf(idx, "You dont have paging on.\n");
  2030. return;
  2031. }
  2032. a = atoi(par);
  2033. if (!strcasecmp(par, "off") || (a == 0 && par[0] == 0)) {
  2034. dcc[idx].status &= ~STAT_PAGE;
  2035. dcc[idx].u.chat->max_line = 0x7ffffff; /* flush_lines needs this */
  2036. while (dcc[idx].u.chat->buffer)
  2037. flush_lines(idx, dcc[idx].u.chat);
  2038. dprintf(idx, "Paging turned off.\n");
  2039. putlog(LOG_CMDS, "*", "#%s# page off", dcc[idx].nick);
  2040. } else if (a > 0) {
  2041. dprintf(idx, "Paging turned on, stopping every %d lines.\n", a);
  2042. dcc[idx].status |= STAT_PAGE;
  2043. dcc[idx].u.chat->max_line = a;
  2044. dcc[idx].u.chat->line_count = 0;
  2045. dcc[idx].u.chat->current_lines = 0;
  2046. putlog(LOG_CMDS, "*", "#%s# page %d", dcc[idx].nick, a);
  2047. return;
  2048. } else {
  2049. dprintf(idx, "Usage: page <off or #>\n");
  2050. return;
  2051. }
  2052. /* new style autosave here too -- rtc, 09/28/1999*/
  2053. if ((me = module_find("console", 1, 1))) {
  2054. Function *func = me->funcs;
  2055. (func[CONSOLE_DOSTORE]) (idx);
  2056. }
  2057. }
  2058. /* evaluate a Tcl command, send output to a dcc user */
  2059. static void cmd_tcl(struct userrec *u, int idx, char *msg)
  2060. {
  2061. int code;
  2062. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2063. dprintf(idx, MISC_NOSUCHCMD);
  2064. return;
  2065. }
  2066. debug1("tcl: evaluate (.tcl): %s", msg);
  2067. code = Tcl_GlobalEval(interp, msg);
  2068. if (code == TCL_OK)
  2069. dumplots(idx, "Tcl: ", interp->result);
  2070. else
  2071. dumplots(idx, "TCL error: ", interp->result);
  2072. }
  2073. /* perform a 'set' command */
  2074. static void cmd_set(struct userrec *u, int idx, char *msg)
  2075. {
  2076. int code;
  2077. char s[512];
  2078. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2079. dprintf(idx, MISC_NOSUCHCMD);
  2080. return;
  2081. }
  2082. putlog(LOG_CMDS, "*", "#%s# set %s", dcc[idx].nick, msg);
  2083. strcpy(s, "set ");
  2084. if (!msg[0]) {
  2085. strcpy(s, "info globals");
  2086. Tcl_Eval(interp, s);
  2087. dumplots(idx, "global vars: ", interp->result);
  2088. return;
  2089. }
  2090. strcpy(s + 4, msg);
  2091. code = Tcl_Eval(interp, s);
  2092. if (code == TCL_OK) {
  2093. if (!strchr(msg, ' '))
  2094. dumplots(idx, "currently: ", interp->result);
  2095. else
  2096. dprintf(idx, "Ok, set.\n");
  2097. } else
  2098. dprintf(idx, "Error: %s\n", interp->result);
  2099. }
  2100. static void cmd_module(struct userrec *u, int idx, char *par)
  2101. {
  2102. Context;
  2103. putlog(LOG_CMDS, "*", "#%s# module %s", dcc[idx].nick, par);
  2104. do_module_report(idx, 2, par[0] ? par : NULL);
  2105. }
  2106. static void cmd_loadmod(struct userrec *u, int idx, char *par)
  2107. {
  2108. const char *p;
  2109. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2110. dprintf(idx, MISC_NOSUCHCMD);
  2111. return;
  2112. }
  2113. Context;
  2114. if (!par[0]) {
  2115. dprintf(idx, "%s: loadmod <module>\n", USAGE);
  2116. } else {
  2117. p = module_load(par);
  2118. if (p)
  2119. dprintf(idx, "%s: %s %s\n", par, MOD_LOADERROR, p);
  2120. else {
  2121. putlog(LOG_CMDS, "*", "#%s# loadmod %s", dcc[idx].nick, par);
  2122. dprintf(idx, "%s %s\n", MOD_LOADED, par);
  2123. }
  2124. }
  2125. Context;
  2126. }
  2127. static void cmd_unloadmod(struct userrec *u, int idx, char *par)
  2128. {
  2129. char *p;
  2130. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2131. dprintf(idx, MISC_NOSUCHCMD);
  2132. return;
  2133. }
  2134. Context;
  2135. if (!par[0]) {
  2136. dprintf(idx, "%s: unloadmod <module>\n", USAGE);
  2137. } else {
  2138. p = module_unload(par, dcc[idx].nick);
  2139. if (p)
  2140. dprintf(idx, "%s %s: %s\n", MOD_UNLOADERROR, par, p);
  2141. else {
  2142. putlog(LOG_CMDS, "*", "#%s# unloadmod %s", dcc[idx].nick, par);
  2143. dprintf(idx, "%s %s\n", MOD_UNLOADED, par);
  2144. }
  2145. }
  2146. }
  2147. static void cmd_pls_ignore(struct userrec *u, int idx, char *par)
  2148. {
  2149. char *who;
  2150. char s[UHOSTLEN];
  2151. if (!par[0]) {
  2152. dprintf(idx, "Usage: +ignore <hostmask> [comment]\n");
  2153. return;
  2154. }
  2155. who = newsplit(&par);
  2156. remove_gunk(who);
  2157. if (!par[0])
  2158. par = "requested";
  2159. else if (strlen(par) > 65)
  2160. par[65] = 0;
  2161. if (strlen(who) > UHOSTMAX - 4)
  2162. who[UHOSTMAX - 4] = 0;
  2163. /* fix missing ! or @ BEFORE continuing - sounds familiar */
  2164. if (!strchr(who, '!')) {
  2165. if (!strchr(who, '@'))
  2166. simple_sprintf(s, "%s!*@*", who);
  2167. else
  2168. simple_sprintf(s, "*!%s", who);
  2169. } else if (!strchr(who, '@'))
  2170. simple_sprintf(s, "%s@*", who);
  2171. else
  2172. strcpy(s, who);
  2173. if (match_ignore(s)) {
  2174. dprintf(idx, "That already matches an existing ignore.\n");
  2175. return;
  2176. }
  2177. dprintf(idx, "Now ignoring: %s (%s)\n", s, par);
  2178. addignore(s, dcc[idx].nick, par, 0L);
  2179. putlog(LOG_CMDS, "*", "#%s# +ignore %s %s", dcc[idx].nick, s, par);
  2180. }
  2181. static void cmd_mns_ignore(struct userrec *u, int idx, char *par)
  2182. {
  2183. char buf[UHOSTLEN];
  2184. if (!par[0]) {
  2185. dprintf(idx, "Usage: -ignore <hostmask | ignore #>\n");
  2186. return;
  2187. }
  2188. strncpy(buf, par, UHOSTMAX);
  2189. buf[UHOSTMAX] = 0;
  2190. if (delignore(buf)) {
  2191. putlog(LOG_CMDS, "*", "#%s# -ignore %s", dcc[idx].nick, buf);
  2192. dprintf(idx, "No longer ignoring: %s\n", buf);
  2193. } else
  2194. dprintf(idx, "Can't find that ignore.\n");
  2195. }
  2196. static void cmd_ignores(struct userrec *u, int idx, char *par)
  2197. {
  2198. putlog(LOG_CMDS, "*", "#%s# ignores %s", dcc[idx].nick, par);
  2199. tell_ignores(idx, par);
  2200. }
  2201. static void cmd_pls_user(struct userrec *u, int idx, char *par)
  2202. {
  2203. char *handle, *host;
  2204. if (!par[0]) {
  2205. dprintf(idx, "Usage: +user <handle> <hostmask>\n");
  2206. return;
  2207. }
  2208. handle = newsplit(&par);
  2209. host = newsplit(&par);
  2210. if (strlen(handle) > HANDLEN)
  2211. handle[HANDLEN] = 0; /* max len = XX */
  2212. if (get_user_by_handle(userlist, handle))
  2213. dprintf(idx, "Someone already exists by that name.\n");
  2214. else if (strchr(BADNICKCHARS, handle[0]) != NULL)
  2215. dprintf(idx, "You can't start a nick with '%c'.\n", handle[0]);
  2216. else if (!strcasecmp(handle, botnetnick))
  2217. dprintf(idx, "Hey! That's MY name!\n");
  2218. else {
  2219. putlog(LOG_CMDS, "*", "#%s# +user %s %s", dcc[idx].nick, handle, host);
  2220. userlist = adduser(userlist, handle, host, "-", 0);
  2221. dprintf(idx, "Added %s (%s) with no password or flags.\n", handle, host);
  2222. }
  2223. }
  2224. static void cmd_mns_user(struct userrec *u, int idx, char *par)
  2225. {
  2226. char *handle;
  2227. struct userrec *u2;
  2228. if (!par[0]) {
  2229. dprintf(idx, "Usage: -user <nick>\n");
  2230. return;
  2231. }
  2232. handle = newsplit(&par);
  2233. u2 = get_user_by_handle(userlist, handle);
  2234. if (!u2 || !u) {
  2235. dprintf(idx, "No such user!\n");
  2236. return;
  2237. }
  2238. if (isowner(u2->handle)) {
  2239. dprintf(idx, "Can't remove the permanent bot owner!\n");
  2240. return;
  2241. }
  2242. if ((u2->flags & USER_OWNER) && !(u->flags & USER_OWNER)) {
  2243. dprintf(idx, "Can't remove the bot owner!\n");
  2244. return;
  2245. }
  2246. if ((u2->flags & USER_BOT) && (bot_flags(u2) & BOT_SHARE) &&
  2247. !(u->flags & USER_OWNER)) {
  2248. dprintf(idx, "You can't remove shared bots.\n");
  2249. return;
  2250. }
  2251. if ((u->flags & USER_BOTMAST) && !(u->flags & USER_MASTER) &&
  2252. !(u2->flags & USER_BOT)) {
  2253. dprintf(idx, "Can't remove users who aren't bots!\n");
  2254. return;
  2255. }
  2256. if (deluser(handle)) {
  2257. putlog(LOG_CMDS, "*", "#%s# -user %s", dcc[idx].nick, handle);
  2258. dprintf(idx, "Deleted %s.\n", handle);
  2259. } else
  2260. dprintf(idx, "Failed.\n");
  2261. }
  2262. static void cmd_pls_host(struct userrec *u, int idx, char *par)
  2263. {
  2264. char *handle, *host;
  2265. struct userrec *u2;
  2266. struct list_type *q;
  2267. struct flag_record fr =
  2268. {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  2269. Context;
  2270. handle = newsplit(&par);
  2271. if (!par[0]) {
  2272. dprintf(idx, "Usage: +host <handle> <newhostmask>\n");
  2273. return;
  2274. }
  2275. host = newsplit(&par);
  2276. u2 = get_user_by_handle(userlist, handle);
  2277. if (!u2) {
  2278. dprintf(idx, "No such user.\n");
  2279. return;
  2280. }
  2281. for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next)
  2282. if (!strcasecmp(q->extra, host)) {
  2283. dprintf(idx, "That hostmask is already there.\n");
  2284. return;
  2285. }
  2286. get_user_flagrec(u, &fr, NULL);
  2287. if ((u->flags & USER_BOTMAST) && !(u->flags & USER_MASTER) &&
  2288. !(u2->flags & USER_BOT) && !chan_master(fr)) {
  2289. dprintf(idx, "You can't add hostmasks to non-bots.\n");
  2290. return;
  2291. }
  2292. if (!(u->flags & USER_OWNER) && (u2->flags & USER_BOT) &&
  2293. (bot_flags(u2) & BOT_SHARE)) {
  2294. dprintf(idx, "You can't add hostmasks to share-bots.\n");
  2295. return;
  2296. }
  2297. if ((u2->flags & USER_OWNER) &&
  2298. !(u->flags & USER_OWNER) && strcasecmp(handle, dcc[idx].nick)) {
  2299. dprintf(idx, "Can't add hostmasks to the bot owner.\n");
  2300. return;
  2301. }
  2302. putlog(LOG_CMDS, "*", "#%s# +host %s %s", dcc[idx].nick, handle, host);
  2303. addhost_by_handle(handle, host);
  2304. dprintf(idx, "Added '%s' to %s\n", host, handle);
  2305. }
  2306. static void cmd_mns_host(struct userrec *u, int idx, char *par)
  2307. {
  2308. char *handle, *host;
  2309. struct userrec *u2;
  2310. struct flag_record fr =
  2311. {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  2312. if (!par[0]) {
  2313. dprintf(idx, "Usage: -host [handle] <hostmask>\n");
  2314. return;
  2315. }
  2316. handle = newsplit(&par);
  2317. if (par[0]) {
  2318. host = newsplit(&par);
  2319. u2 = get_user_by_handle(userlist, handle);
  2320. } else {
  2321. host = handle;
  2322. handle = dcc[idx].nick;
  2323. u2 = u;
  2324. }
  2325. if (!u2 || !u) {
  2326. dprintf(idx, "No such user.\n");
  2327. return;
  2328. }
  2329. if (strcasecmp(handle, dcc[idx].nick)) {
  2330. get_user_flagrec(u, &fr, NULL);
  2331. if (!(u2->flags & USER_BOT) && !(u->flags & USER_MASTER) &&
  2332. !chan_master(fr)) {
  2333. dprintf(idx, "You can't remove hostmasks from non-bots.\n");
  2334. return;
  2335. } else if ((u2->flags & USER_BOT) && (bot_flags(u2) & BOT_SHARE) &&
  2336. !(u->flags & USER_OWNER)) {
  2337. dprintf(idx, "You can't remove hostmask from a shared bot.\n");
  2338. return;
  2339. } else if ((u2->flags & USER_OWNER) && !(u->flags & USER_OWNER) &&
  2340. (u2 != u)) {
  2341. dprintf(idx, "Can't remove hostmasks from the bot owner.\n");
  2342. return;
  2343. } else if (!(u->flags & USER_BOTMAST) && !chan_master(fr)) {
  2344. dprintf(idx, "Permission denied.\n");
  2345. return;
  2346. }
  2347. }
  2348. if (delhost_by_handle(handle, host)) {
  2349. putlog(LOG_CMDS, "*", "#%s# -host %s %s", dcc[idx].nick, handle, host);
  2350. dprintf(idx, "Removed '%s' from %s\n", host, handle);
  2351. } else
  2352. dprintf(idx, "Failed.\n");
  2353. }
  2354. static void cmd_modules(struct userrec *u, int idx, char *par)
  2355. {
  2356. int ptr;
  2357. Context;
  2358. if (!par[0])
  2359. dprintf(idx, "Usage: modules <bot>\n");
  2360. else {
  2361. putlog(LOG_CMDS, "*", "#%s# modules %s", dcc[idx].nick, par);
  2362. if ((ptr = nextbot(par)) >= 0)
  2363. dprintf(ptr, "v %s %s %d:%s\n", botnetnick, par, dcc[idx].sock,
  2364. dcc[idx].nick);
  2365. else
  2366. dprintf(idx, "No such bot online.\n");
  2367. }
  2368. }
  2369. /* DCC CHAT COMMANDS */
  2370. /* function call should be:
  2371. * int cmd_whatever(idx,"parameters");
  2372. * as with msg commands, function is responsible for any logging
  2373. */
  2374. cmd_t C_dcc[] =
  2375. {
  2376. {"+bot", "t", (Function) cmd_pls_bot, NULL},
  2377. {"+host", "tm|m", (Function) cmd_pls_host, NULL},
  2378. {"+ignore", "m", (Function) cmd_pls_ignore, NULL},
  2379. {"+user", "m", (Function) cmd_pls_user, NULL},
  2380. {"-bot", "t", (Function) cmd_mns_user, NULL},
  2381. {"-host", "", (Function) cmd_mns_host, NULL},
  2382. {"-ignore", "m", (Function) cmd_mns_ignore, NULL},
  2383. {"-user", "m", (Function) cmd_mns_user, NULL},
  2384. {"addlog", "to|o", (Function) cmd_addlog, NULL},
  2385. {"away", "", (Function) cmd_away, NULL},
  2386. {"back", "", (Function) cmd_back, NULL},
  2387. {"backup", "m|m", (Function) cmd_backup, NULL},
  2388. {"banner", "t", (Function) cmd_banner, NULL},
  2389. {"binds", "m", (Function) cmd_binds, NULL},
  2390. {"boot", "t", (Function) cmd_boot, NULL},
  2391. {"botattr", "t", (Function) cmd_botattr, NULL},
  2392. {"botinfo", "t", (Function) cmd_botinfo, NULL},
  2393. {"bots", "", (Function) cmd_bots, NULL},
  2394. {"bottree", "t", (Function) cmd_bottree, NULL},
  2395. {"chaddr", "t", (Function) cmd_chaddr, NULL},
  2396. {"chat", "", (Function) cmd_chat, NULL},
  2397. {"chattr", "m|m", (Function) cmd_chattr, NULL},
  2398. {"chnick", "t", (Function) cmd_chnick, NULL},
  2399. {"chpass", "t", (Function) cmd_chpass, NULL},
  2400. {"comment", "m", (Function) cmd_comment, NULL},
  2401. {"console", "to|o", (Function) cmd_console, NULL},
  2402. {"dccstat", "t", (Function) cmd_dccstat, NULL},
  2403. {"debug", "m", (Function) cmd_debug, NULL},
  2404. {"die", "n", (Function) cmd_die, NULL},
  2405. {"echo", "", (Function) cmd_echo, NULL},
  2406. {"fixcodes", "", (Function) cmd_fixcodes, NULL},
  2407. {"help", "", (Function) cmd_help, NULL},
  2408. {"ignores", "m", (Function) cmd_ignores, NULL},
  2409. {"link", "t", (Function) cmd_link, NULL},
  2410. {"loadmod", "n", (Function) cmd_loadmod, NULL},
  2411. {"match", "to|o", (Function) cmd_match, NULL},
  2412. {"me", "", (Function) cmd_me, NULL},
  2413. {"module", "m", (Function) cmd_module, NULL},
  2414. {"modules", "n", (Function) cmd_modules, NULL},
  2415. {"motd", "", (Function) cmd_motd, NULL},
  2416. {"newpass", "", (Function) cmd_newpass, NULL},
  2417. {"nick", "", (Function) cmd_nick, NULL},
  2418. {"page", "", (Function) cmd_page, NULL},
  2419. {"quit", "", (Function) 0, NULL},
  2420. {"rehash", "m", (Function) cmd_rehash, NULL},
  2421. {"rehelp", "n", (Function) cmd_rehelp, NULL},
  2422. {"relay", "t", (Function) cmd_relay, NULL},
  2423. {"reload", "m|m", (Function) cmd_reload, NULL},
  2424. {"restart", "m", (Function) cmd_restart, NULL},
  2425. {"save", "m|m", (Function) cmd_save, NULL},
  2426. {"set", "n", (Function) cmd_set, NULL},
  2427. {"simul", "n", (Function) cmd_simul, NULL},
  2428. {"status", "m|m", (Function) cmd_status, NULL},
  2429. {"strip", "", (Function) cmd_strip, NULL},
  2430. {"su", "", (Function) cmd_su, NULL},
  2431. {"tcl", "n", (Function) cmd_tcl, NULL},
  2432. {"trace", "", (Function) cmd_trace, NULL},
  2433. {"unlink", "t", (Function) cmd_unlink, NULL},
  2434. {"unloadmod", "n", (Function) cmd_unloadmod, NULL},
  2435. {"uptime", "m|m", (Function) cmd_uptime, NULL},
  2436. {"vbottree", "t", (Function) cmd_vbottree, NULL},
  2437. {"who", "", (Function) cmd_who, NULL},
  2438. {"whois", "to|o", (Function) cmd_whois, NULL},
  2439. {"whom", "", (Function) cmd_whom, NULL},
  2440. {0, 0, 0, 0}
  2441. };