cmds.c 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172
  1. /*
  2. * cmds.c -- handles:
  3. * commands from a user via dcc
  4. * (split in 3, this portion contains no-irc commands)
  5. *
  6. */
  7. #include "main.h"
  8. #include "tandem.h"
  9. #include "modules.h"
  10. #include "help.h"
  11. #include "bg.h"
  12. #include <ctype.h>
  13. #include <stdlib.h>
  14. #include <pwd.h>
  15. #include <sys/types.h>
  16. #ifdef HAVE_UNAME
  17. #include <sys/utsname.h>
  18. #endif
  19. extern struct chanset_t *chanset;
  20. extern struct dcc_t *dcc;
  21. extern struct userrec *userlist;
  22. extern tcl_timer_t *timer, *utimer;
  23. extern int dcc_total, remote_boots, backgrd,
  24. do_restart, conmask, must_be_owner,
  25. strict_host, quiet_save, cfg_count,
  26. server_lag, egg_numver, localhub;
  27. extern unsigned long otraffic_irc, otraffic_irc_today,
  28. itraffic_irc, itraffic_irc_today,
  29. otraffic_bn, otraffic_bn_today,
  30. itraffic_bn, itraffic_bn_today,
  31. otraffic_dcc, otraffic_dcc_today,
  32. itraffic_dcc, itraffic_dcc_today,
  33. otraffic_trans, otraffic_trans_today,
  34. itraffic_trans, itraffic_trans_today,
  35. otraffic_unknown, otraffic_unknown_today,
  36. itraffic_unknown, itraffic_unknown_today;
  37. extern Tcl_Interp *interp;
  38. extern char botnetnick[], origbotname[], ver[], network[],
  39. owner[], quit_msg[], dcc_prefix[], pid_file[],
  40. botname[], *binname, version[], egg_version[];
  41. extern time_t now, online_since, buildts;
  42. extern module_entry *module_list;
  43. extern struct cfg_entry CFG_MOTD, **cfg;
  44. extern tand_t *tandbot;
  45. static char *btos(unsigned long);
  46. mycmds cmds[500]; //the list of dcc cmds for help system
  47. int cmdi = 0;
  48. #ifdef HUB
  49. static void tell_who(struct userrec *u, int idx, int chan)
  50. {
  51. int i, k, ok = 0, atr = u ? u->flags : 0;
  52. int nicklen;
  53. char format[81];
  54. char s[1024]; /* temp fix - 1.4 has a better one */
  55. if (!chan)
  56. dprintf(idx, "%s (* = %s, + = %s, @ = %s)\n",
  57. BOT_PARTYMEMBS, MISC_OWNER, MISC_MASTER, MISC_OP);
  58. else {
  59. simple_sprintf(s, "assoc %d", chan);
  60. if ((Tcl_Eval(interp, s) != TCL_OK) || !interp->result[0])
  61. dprintf(idx, "%s %s%d: (* = %s, + = %s, @ = %s)\n",
  62. BOT_PEOPLEONCHAN,
  63. (chan < GLOBAL_CHANS) ? "" : "*",
  64. chan % GLOBAL_CHANS,
  65. MISC_OWNER, MISC_MASTER, MISC_OP);
  66. else
  67. dprintf(idx, "%s '%s' (%s%d): (* = %s, + = %s, @ = %s)\n",
  68. BOT_PEOPLEONCHAN, interp->result,
  69. (chan < GLOBAL_CHANS) ? "" : "*",
  70. chan % GLOBAL_CHANS,
  71. MISC_OWNER, MISC_MASTER, MISC_OP);
  72. }
  73. /* calculate max nicklen */
  74. nicklen = 0;
  75. for (i = 0; i < dcc_total; i++) {
  76. if(strlen(dcc[i].nick) > nicklen)
  77. nicklen = strlen(dcc[i].nick);
  78. }
  79. if(nicklen < 9) nicklen = 9;
  80. for (i = 0; i < dcc_total; i++)
  81. if (dcc[i].type == &DCC_CHAT)
  82. if (dcc[i].u.chat->channel == chan) {
  83. if (atr & USER_OWNER) {
  84. egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us %%s", nicklen);
  85. sprintf(s, format,
  86. dcc[i].sock, (geticon(i) == '-' ? ' ' : geticon(i)),
  87. dcc[i].nick, dcc[i].host);
  88. } else {
  89. egg_snprintf(format, sizeof format, " %%c%%-%us %%s", nicklen);
  90. sprintf(s, format,
  91. (geticon(i) == '-' ? ' ' : geticon(i)),
  92. dcc[i].nick, dcc[i].host);
  93. }
  94. if (atr & USER_MASTER) {
  95. if (dcc[i].u.chat->con_flags)
  96. sprintf(&s[strlen(s)], " (con:%s)",
  97. masktype(dcc[i].u.chat->con_flags));
  98. }
  99. if (now - dcc[i].timeval > 300) {
  100. unsigned long days, hrs, mins;
  101. days = (now - dcc[i].timeval) / 86400;
  102. hrs = ((now - dcc[i].timeval) - (days * 86400)) / 3600;
  103. mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
  104. if (days > 0)
  105. sprintf(&s[strlen(s)], " (idle %lud%luh)", days, hrs);
  106. else if (hrs > 0)
  107. sprintf(&s[strlen(s)], " (idle %luh%lum)", hrs, mins);
  108. else
  109. sprintf(&s[strlen(s)], " (idle %lum)", mins);
  110. }
  111. dprintf(idx, "%s\n", s);
  112. if (dcc[i].u.chat->away != NULL)
  113. dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
  114. }
  115. for (i = 0; i < dcc_total; i++)
  116. if (dcc[i].type == &DCC_BOT) {
  117. if (!ok) {
  118. ok = 1;
  119. dprintf(idx, STR("Bots connected:\n"));
  120. }
  121. #ifdef S_UTCTIME
  122. egg_strftime(s, 14, "%d %b %H:%M %Z", gmtime(&dcc[i].timeval));
  123. #else /* !S_UTCTIME */
  124. egg_strftime(s, 14, "%d %b %H:%M %Z", localtime(&dcc[i].timeval));
  125. #endif /* S_UTCTIME */
  126. if (atr & USER_OWNER) {
  127. egg_snprintf(format, sizeof format, " [%%.2lu] %%s%%c%%-%us (%%s) %%s\n",
  128. nicklen);
  129. dprintf(idx, format,
  130. dcc[i].sock, dcc[i].status & STAT_CALLED ? "<-" : "->",
  131. dcc[i].status & STAT_SHARE ? '+' : ' ',
  132. dcc[i].nick, s, dcc[i].u.bot->version);
  133. } else {
  134. egg_snprintf(format, sizeof format, " %%s%%c%%-%us (%%s) %%s\n", nicklen);
  135. dprintf(idx, format,
  136. dcc[i].status & STAT_CALLED ? "<-" : "->",
  137. dcc[i].status & STAT_SHARE ? '+' : ' ',
  138. dcc[i].nick, s, dcc[i].u.bot->version);
  139. }
  140. }
  141. ok = 0;
  142. for (i = 0; i < dcc_total; i++) {
  143. if ((dcc[i].type == &DCC_CHAT) && (dcc[i].u.chat->channel != chan)) {
  144. if (!ok) {
  145. ok = 1;
  146. dprintf(idx, STR("Other people on the bot:\n"));
  147. }
  148. if (atr & USER_OWNER) {
  149. egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us ", nicklen);
  150. sprintf(s, format, dcc[i].sock,
  151. (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick);
  152. } else {
  153. egg_snprintf(format, sizeof format, " %%c%%-%us ", nicklen);
  154. sprintf(s, format,
  155. (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick);
  156. }
  157. if (atr & USER_MASTER) {
  158. if (dcc[i].u.chat->channel < 0)
  159. strcat(s, "(-OFF-) ");
  160. else if (!dcc[i].u.chat->channel)
  161. strcat(s, "(party) ");
  162. else
  163. sprintf(&s[strlen(s)], "(%5d) ", dcc[i].u.chat->channel);
  164. }
  165. strcat(s, dcc[i].host);
  166. if (atr & USER_MASTER) {
  167. if (dcc[i].u.chat->con_flags)
  168. sprintf(&s[strlen(s)], " (con:%s)",
  169. masktype(dcc[i].u.chat->con_flags));
  170. }
  171. if (now - dcc[i].timeval > 300) {
  172. k = (now - dcc[i].timeval) / 60;
  173. if (k < 60)
  174. sprintf(&s[strlen(s)], " (idle %dm)", k);
  175. else
  176. sprintf(&s[strlen(s)], " (idle %dh%dm)", k / 60, k % 60);
  177. }
  178. dprintf(idx, "%s\n", s);
  179. if (dcc[i].u.chat->away != NULL)
  180. dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
  181. }
  182. if ((atr & USER_MASTER) && (dcc[i].type->flags & DCT_SHOWWHO) &&
  183. (dcc[i].type != &DCC_CHAT)) {
  184. if (!ok) {
  185. ok = 1;
  186. dprintf(idx, STR("Other people on the bot:\n"));
  187. }
  188. if (atr & USER_OWNER) {
  189. egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us (files) %%s",
  190. nicklen);
  191. sprintf(s, format,
  192. dcc[i].sock, dcc[i].status & STAT_CHAT ? '+' : ' ',
  193. dcc[i].nick, dcc[i].host);
  194. } else {
  195. egg_snprintf(format, sizeof format, " %%c%%-%us (files) %%s", nicklen);
  196. sprintf(s, format,
  197. dcc[i].status & STAT_CHAT ? '+' : ' ',
  198. dcc[i].nick, dcc[i].host);
  199. }
  200. dprintf(idx, "%s\n", s);
  201. }
  202. }
  203. }
  204. static void cmd_botinfo(struct userrec *u, int idx, char *par)
  205. {
  206. char s[512], s2[32];
  207. struct chanset_t *chan;
  208. time_t now2;
  209. int hr, min;
  210. putlog(LOG_CMDS, "*", STR("#%s# botinfo"), dcc[idx].nick);
  211. now2 = now - online_since;
  212. s2[0] = 0;
  213. if (now2 > 86400) {
  214. int days = now2 / 86400;
  215. /* Days */
  216. sprintf(s2, "%d day", days);
  217. if (days >= 2)
  218. strcat(s2, "s");
  219. strcat(s2, ", ");
  220. now2 -= days * 86400;
  221. }
  222. hr = (time_t) ((int) now2 / 3600);
  223. now2 -= (hr * 3600);
  224. min = (time_t) ((int) now2 / 60);
  225. sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
  226. simple_sprintf(s, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  227. botnet_send_infoq(-1, s);
  228. s[0] = 0;
  229. if (module_find("server", 0, 0)) {
  230. for (chan = chanset; chan; chan = chan->next) {
  231. if (!channel_secret(chan)) {
  232. if ((strlen(s) + strlen(chan->dname) + strlen(network)
  233. + strlen(botnetnick) + strlen(ver) + 1) >= 490) {
  234. strcat(s,"++ ");
  235. break; /* yeesh! */
  236. }
  237. strcat(s, chan->dname);
  238. strcat(s, ", ");
  239. }
  240. }
  241. if (s[0]) {
  242. s[strlen(s) - 2] = 0;
  243. dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
  244. ver, network, s, s2);
  245. } else
  246. dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
  247. ver, network, BOT_NOCHANNELS, s2);
  248. } else
  249. dprintf(idx, STR("*** [%s] %s <NO_IRC> [UP %s]\n"), botnetnick, ver, s2);
  250. }
  251. #endif /* HUB */
  252. static void cmd_whom(struct userrec *u, int idx, char *par)
  253. {
  254. if (par[0] == '*') {
  255. putlog(LOG_CMDS, "*", STR("#%s# whom %s"), dcc[idx].nick, par);
  256. answer_local_whom(idx, -1);
  257. return;
  258. } else if (dcc[idx].u.chat->channel < 0) {
  259. dprintf(idx, STR("You have chat turned off.\n"));
  260. return;
  261. }
  262. putlog(LOG_CMDS, "*", STR("#%s# whom %s"), dcc[idx].nick, par);
  263. if (!par[0]) {
  264. answer_local_whom(idx, dcc[idx].u.chat->channel);
  265. } else {
  266. int chan = -1;
  267. if ((par[0] < '0') || (par[0] > '9')) {
  268. Tcl_SetVar(interp, "chan", par, 0);
  269. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  270. interp->result[0]) {
  271. chan = atoi(interp->result);
  272. }
  273. if (chan <= 0) {
  274. dprintf(idx, STR("No such channel exists.\n"));
  275. return;
  276. }
  277. } else
  278. chan = atoi(par);
  279. if ((chan < 0) || (chan > 99999)) {
  280. dprintf(idx, STR("Channel number out of range: must be between 0 and 99999.\n"));
  281. return;
  282. }
  283. answer_local_whom(idx, chan);
  284. }
  285. }
  286. #ifdef HUB
  287. static void cmd_config(struct userrec *u, int idx, char *par)
  288. {
  289. /*
  290. .config
  291. Usage + available entry list
  292. .config name
  293. Show current value + description
  294. .config name value
  295. Set
  296. */
  297. char *name;
  298. struct cfg_entry *cfgent = NULL;
  299. int cnt, i;
  300. putlog(LOG_CMDS, "*", STR("#%s# config %s"), dcc[idx].nick, par);
  301. if (!par[0]) {
  302. char *outbuf = nmalloc(1);
  303. outbuf[0] = 0;
  304. dprintf(idx, STR("Usage: config [name [value|-]]\n"));
  305. dprintf(idx, STR("Defined config entry names:\n"));
  306. cnt = 0;
  307. for (i = 0; i < cfg_count; i++) {
  308. if ((cfg[i]->flags & CFGF_GLOBAL) && (cfg[i]->describe)) {
  309. if (!cnt) {
  310. outbuf = nrealloc(outbuf, 2 + 1);
  311. sprintf(outbuf, " ");
  312. }
  313. outbuf = nrealloc(outbuf, strlen(outbuf) + strlen(cfg[i]->name) + 1 + 1);
  314. sprintf(outbuf, STR("%s%s "), outbuf, cfg[i]->name);
  315. cnt++;
  316. if (cnt == 10) {
  317. dprintf(idx, "%s\n", outbuf);
  318. cnt = 0;
  319. }
  320. }
  321. }
  322. if (cnt)
  323. dprintf(idx, "%s\n", outbuf);
  324. if (outbuf)
  325. nfree(outbuf);
  326. return;
  327. }
  328. name = newsplit(&par);
  329. for (i = 0; !cfgent && (i < cfg_count); i++)
  330. if (!strcmp(cfg[i]->name, name))
  331. cfgent=cfg[i];
  332. if (!cfgent || !cfgent->describe) {
  333. dprintf(idx, STR("No such config entry\n"));
  334. return;
  335. }
  336. if (!par[0]) {
  337. cfgent->describe(cfgent, idx);
  338. if (!cfgent->gdata)
  339. dprintf(idx, STR("No current value\n"));
  340. else {
  341. dprintf(idx, STR("Currently: %s\n"), cfgent->gdata);
  342. }
  343. return;
  344. }
  345. if (strlen(par) >= 2048) {
  346. dprintf(idx, STR("Value can't be longer than 2048 chars"));
  347. return;
  348. }
  349. set_cfg_str(NULL, cfgent->name, par);
  350. if (!cfgent->gdata)
  351. dprintf(idx, STR("Now: (not set)\n"));
  352. else {
  353. dprintf(idx, STR("Now: %s\n"), cfgent->gdata);
  354. }
  355. #ifdef HUB
  356. write_userfile(idx);
  357. #endif /* HUB */
  358. }
  359. static void cmd_botconfig(struct userrec *u, int idx, char *par)
  360. {
  361. struct userrec *u2;
  362. char *p;
  363. struct xtra_key *k;
  364. struct cfg_entry *cfgent;
  365. int i, cnt;
  366. /* botconfig bot [name [value]] */
  367. putlog(LOG_CMDS, "*", STR("#%s# botconfig %s"), dcc[idx].nick, par);
  368. if (!par[0]) {
  369. dprintf(idx, STR("Usage: botconfig bot [name [value|-]]\n"));
  370. cnt=0;
  371. for (i=0; i < cfg_count; i++) {
  372. if (cfg[i]->flags & CFGF_LOCAL) {
  373. dprintf(idx, STR("%s "), cfg[i]->name);
  374. cnt++;
  375. if (cnt == 10) {
  376. dprintf(idx, "\n");
  377. cnt=0;
  378. }
  379. }
  380. }
  381. if (cnt > 0)
  382. dprintf(idx, "\n");
  383. return;
  384. }
  385. p = newsplit(&par);
  386. u2 = get_user_by_handle(userlist, p);
  387. if (!u2) {
  388. dprintf(idx, STR("No such user.\n"));
  389. return;
  390. }
  391. if (!(u2->flags & USER_BOT)) {
  392. dprintf(idx, STR("%s isn't a bot.\n"), p);
  393. return;
  394. }
  395. if (!par[0]) {
  396. for (i = 0; i < cfg_count; i++) {
  397. if ((cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe)) {
  398. k = get_user(&USERENTRY_CONFIG, u2);
  399. while (k && strcmp(k->key, cfg[i]->name))
  400. k=k->next;
  401. if (k)
  402. dprintf(idx, STR(" %s: %s\n"), k->key, k->data);
  403. else
  404. dprintf(idx, STR(" %s: (not set)\n"), cfg[i]->name);
  405. }
  406. }
  407. return;
  408. }
  409. p = newsplit(&par);
  410. cfgent=NULL;
  411. for (i = 0; !cfgent && (i < cfg_count); i++)
  412. if (!strcmp(cfg[i]->name, p) && (cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe))
  413. cfgent=cfg[i];
  414. if (!cfgent) {
  415. dprintf(idx, STR("No such configuration value\n"));
  416. return;
  417. }
  418. if (par[0]) {
  419. char tmp[100];
  420. set_cfg_str(u2->handle, cfgent->name, (strcmp(par, "-")) ? par : NULL);
  421. egg_snprintf(tmp, sizeof tmp, "%s %s", cfgent->name, par);
  422. update_mod(u2->handle, dcc[idx].nick, "botconfig", tmp);
  423. dprintf(idx, STR("Now: "));
  424. #ifdef HUB
  425. write_userfile(idx);
  426. #endif /* HUB */
  427. } else {
  428. if (cfgent->describe)
  429. cfgent->describe(cfgent, idx);
  430. }
  431. k = get_user(&USERENTRY_CONFIG, u2);
  432. while (k && strcmp(k->key, cfgent->name))
  433. k = k->next;
  434. if (k)
  435. dprintf(idx, STR(" %s: %s\n"), k->key, k->data);
  436. else
  437. dprintf(idx, STR(" %s: (not set)\n"), cfgent->name);
  438. }
  439. #ifdef S_DCCPASS
  440. static void cmd_cmdpass(struct userrec *u, int idx, char *par)
  441. {
  442. struct tcl_bind_mask_b *hm;
  443. char *cmd = NULL, *pass = NULL;
  444. int i, l = 0;
  445. /* cmdpass [command [newpass]] */
  446. cmd = newsplit(&par);
  447. putlog(LOG_CMDS, "*", STR("#%s# cmdpass %s ..."), dcc[idx].nick, cmd[0] ? cmd : "");
  448. pass = newsplit(&par);
  449. if (!cmd[0] || par[0]) {
  450. dprintf(idx, STR("Usage: %scmdpass <command> [password]\n"), dcc_prefix);
  451. dprintf(idx, STR(" if no password is specified, the commands password is reset\n"));
  452. return;
  453. }
  454. for (i = 0; cmd[i]; i++)
  455. cmd[i] = tolower(cmd[i]);
  456. if (!egg_strcasecmp(cmd, "op")) l++;
  457. else if (!egg_strcasecmp(cmd, "act")) l++;
  458. else if (!egg_strcasecmp(cmd, "adduser")) l++;
  459. else if (!egg_strcasecmp(cmd, "channel")) l++;
  460. else if (!egg_strcasecmp(cmd, "deluser")) l++;
  461. else if (!egg_strcasecmp(cmd, "deop")) l++;
  462. else if (!egg_strcasecmp(cmd, "devoice")) l++;
  463. else if (!egg_strcasecmp(cmd, "getkey")) l++;
  464. else if (!egg_strcasecmp(cmd, "find")) l++;
  465. else if (!egg_strcasecmp(cmd, "invite")) l++;
  466. else if (!egg_strcasecmp(cmd, "kick")) l++;
  467. else if (!egg_strcasecmp(cmd, "kickban")) l++;
  468. else if (!egg_strcasecmp(cmd, "mdop")) l++;
  469. else if (!egg_strcasecmp(cmd, "msg")) l++;
  470. else if (!egg_strcasecmp(cmd, "reset")) l++;
  471. else if (!egg_strcasecmp(cmd, "resetbans")) l++;
  472. else if (!egg_strcasecmp(cmd, "resetexempts")) l++;
  473. else if (!egg_strcasecmp(cmd, "resetinvites")) l++;
  474. else if (!egg_strcasecmp(cmd, "say")) l++;
  475. else if (!egg_strcasecmp(cmd, "topic")) l++;
  476. else if (!egg_strcasecmp(cmd, "voice")) l++;
  477. else if (!egg_strcasecmp(cmd, "clearqueue")) l++;
  478. else if (!egg_strcasecmp(cmd, "dump")) l++;
  479. else if (!egg_strcasecmp(cmd, "jump")) l++;
  480. else if (!egg_strcasecmp(cmd, "servers")) l++;
  481. else if (!egg_strcasecmp(cmd, "authed")) l++;
  482. if (!l) {
  483. for (hm = H_dcc->first; hm; hm = hm->next)
  484. if (!egg_strcasecmp(cmd, hm->mask))
  485. break;
  486. if (!hm) {
  487. dprintf(idx, STR("No such DCC command\n"));
  488. return;
  489. }
  490. }
  491. if (pass[0]) {
  492. char epass[36], tmp[256];
  493. if (!isowner(u->handle) && has_cmd_pass(cmd)) {
  494. putlog(LOG_MISC, "*", STR("%s attempted to change command password for %s - not perm owner"), dcc[idx].nick, cmd);
  495. dprintf(idx, STR("Perm owners only.\n"));
  496. return;
  497. }
  498. encrypt_pass(pass, epass);
  499. sprintf(tmp, STR("%s %s"), cmd, epass);
  500. if (has_cmd_pass(cmd))
  501. dprintf(idx, STR("Changed command password for %s\n"), cmd);
  502. else
  503. dprintf(idx, STR("Set command password for %s to '%s'\n"), cmd, pass);
  504. set_cmd_pass(tmp, 1);
  505. } else {
  506. if (!isowner(u->handle)) {
  507. putlog(LOG_MISC, "*", STR("%s attempted to remove command password for %s - not perm owner"), dcc[idx].nick, cmd);
  508. dprintf(idx, STR("Perm owners only.\n"));
  509. return;
  510. }
  511. set_cmd_pass(cmd, 1);
  512. dprintf(idx, STR("Removed command password for %s\n"), cmd);
  513. }
  514. #ifdef HUB
  515. write_userfile(idx);
  516. #endif /* HUB */
  517. }
  518. #endif /* S_DCCPASS */
  519. static void cmd_lagged(struct userrec *u, int idx, char *par)
  520. {
  521. /* Lists botnet lag to *directly connected* bots */
  522. int i;
  523. putlog(LOG_CMDS, "*", STR("#%s# lagged %s"), u->handle, par);
  524. for (i = 0; i < dcc_total; i++) {
  525. if (dcc[i].type == &DCC_BOT) {
  526. dprintf(idx, STR("%9s - %i seconds\n"), dcc[i].nick, (dcc[i].pingtime > 120) ? (now - dcc[i].pingtime) : dcc[i].pingtime);
  527. }
  528. }
  529. }
  530. #endif /* HUB */
  531. static void cmd_me(struct userrec *u, int idx, char *par)
  532. {
  533. int i;
  534. if (dcc[idx].u.chat->channel < 0) {
  535. dprintf(idx, STR("You have chat turned off.\n"));
  536. return;
  537. }
  538. if (!par[0]) {
  539. dprintf(idx, STR("Usage: me <action>\n"));
  540. return;
  541. }
  542. if (dcc[idx].u.chat->away != NULL)
  543. not_away(idx);
  544. for (i = 0; i < dcc_total; i++)
  545. if ((dcc[i].type->flags & DCT_CHAT) &&
  546. (dcc[i].u.chat->channel == dcc[idx].u.chat->channel) &&
  547. ((i != idx) || (dcc[i].status & STAT_ECHO)))
  548. dprintf(i, "* %s %s\n", dcc[idx].nick, par);
  549. botnet_send_act(idx, botnetnick, dcc[idx].nick,
  550. dcc[idx].u.chat->channel, par);
  551. check_tcl_act(dcc[idx].nick, dcc[idx].u.chat->channel, par);
  552. }
  553. static void cmd_motd(struct userrec *u, int idx, char *par)
  554. {
  555. putlog(LOG_CMDS, "*", STR("#%s# motd %s"), dcc[idx].nick, par);
  556. if (par[0] && (u->flags & USER_MASTER)) {
  557. char *s;
  558. s = nmalloc(strlen(par) + 1 + strlen(dcc[idx].nick) + 10 + 1 + 1); /* +2: ' 'x2 */
  559. sprintf(s, STR("%s %lu %s"), dcc[idx].nick, now, par);
  560. set_cfg_str(NULL, "motd", s);
  561. nfree(s);
  562. dprintf(idx, STR("Motd set\n"));
  563. #ifdef HUB
  564. write_userfile(idx);
  565. #endif /* HUB */
  566. } else {
  567. show_motd(idx);
  568. }
  569. }
  570. static void cmd_about(struct userrec *u, int idx, char *par)
  571. {
  572. char c[80];
  573. putlog(LOG_CMDS, "*", STR("#%s# about"), dcc[idx].nick);
  574. dprintf(idx, STR("Wraith botpack by bryan\n"));
  575. egg_strftime(c, sizeof c, "%c %Z", gmtime(&buildts));
  576. dprintf(idx, STR("Version: %s (%d) \n"), egg_version, egg_numver);
  577. dprintf(idx, STR("Build: %s (%lu)\n"), c, buildts);
  578. dprintf(idx, STR("(written from a base of Eggdrop 1.6.12)\n"));
  579. dprintf(idx, STR("..with credits and thanks to the following:\n"));
  580. dprintf(idx, STR(" \n"));
  581. dprintf(idx, STR(" * Eggdrop team for developing such a great bot to code off of.\n"));
  582. dprintf(idx, STR(" * $bEinride$b and $bievil$b for taking eggdrop1.4.3 and making their very effecient botpack Ghost.\n"));
  583. dprintf(idx, STR(" * $bryguy$b for beta testing, providing code, finding bugs, and providing input.\n"));
  584. dprintf(idx, STR(" * $bSFC$b for providing compile shells, continuous input, feature suggestions, and testing.\n"));
  585. dprintf(idx, STR(" * $bxmage$b for beta testing.\n"));
  586. dprintf(idx, STR(" * $bpasswd$b for beta testing, and his dedication to finding bugs.\n"));
  587. dprintf(idx, STR(" * $bpgpkeys$b for finding bugs, and providing input.\n"));
  588. dprintf(idx, STR(" * $bqFox$b for providing an mIRC $md5() alias, not requiring a dll or >6.03\n"));
  589. dprintf(idx, STR(" * $bSith_Lord$b helping test ipv6 on the bot (admin@elitepackets.com)\n"));
  590. dprintf(idx, STR(" * $bExcelsior$b for finding a bug on BSD with the ipv6, and for celdrop which inspired many features.\n"));
  591. dprintf(idx, STR(" * $bsyt$b for giving me inspiration to code a more secure bot.\n"));
  592. dprintf(idx, STR(" * $Blackjac$b for helping with the bx auth script with his Sentinel script.\n"));
  593. dprintf(idx, STR(" * $bMystikal$b for various bugs\n"));
  594. dprintf(idx, STR(" \n"));
  595. dprintf(idx, STR("The following botpacks gave me inspiration and ideas (no code):\n"));
  596. dprintf(idx, STR(" * $uawptic$u by $blordoptic$b\n"));
  597. dprintf(idx, STR(" * $uoptikz$u by $bryguy$b and $blordoptic$b\n"));
  598. dprintf(idx, STR(" * $uceldrop$u by $bexcelsior$b\n"));
  599. dprintf(idx, STR(" * $ugenocide$u by $Crazi$b, $bDor$b, $bpsychoid$b, and $bAce24$b\n"));
  600. dprintf(idx, STR(" * $utfbot$u by $bwarknite$b and $bloslinux$b\n"));
  601. }
  602. static void cmd_away(struct userrec *u, int idx, char *par)
  603. {
  604. if (strlen(par) > 60)
  605. par[60] = 0;
  606. set_away(idx, par);
  607. }
  608. static void cmd_back(struct userrec *u, int idx, char *par)
  609. {
  610. not_away(idx);
  611. }
  612. static void cmd_newpass(struct userrec *u, int idx, char *par)
  613. {
  614. char *new, pass[16];
  615. putlog(LOG_CMDS, "*", STR("#%s# newpass..."), dcc[idx].nick);
  616. if (!par[0]) {
  617. dprintf(idx, STR("Usage: newpass <newpassword>\n"));
  618. return;
  619. }
  620. new = newsplit(&par);
  621. if (!strcmp(new, "rand")) {
  622. make_rand_str(pass, 15);
  623. } else {
  624. if (strlen(new) < 6) {
  625. dprintf(idx, STR("Please use at least 6 characters.\n"));
  626. return;
  627. } else {
  628. sprintf(pass, "%s", new);
  629. }
  630. }
  631. if (strlen(pass) > 15)
  632. pass[15] = 0;
  633. if (!goodpass(pass, idx, NULL))
  634. return;
  635. set_user(&USERENTRY_PASS, u, pass);
  636. dprintf(idx, STR("Changed your password to: %s\n"), pass);
  637. #ifdef HUB
  638. write_userfile(idx);
  639. #endif /* HUB */
  640. }
  641. static void cmd_secpass(struct userrec *u, int idx, char *par)
  642. {
  643. char *new, pass[16];
  644. putlog(LOG_CMDS, "*", STR("#%s# secpass..."), dcc[idx].nick);
  645. if (!par[0]) {
  646. dprintf(idx, STR("Usage: secpass <newsecpass>\nIf you use \"rand\" as the secpass, a random pass will be chosen.\n"));
  647. return;
  648. }
  649. new = newsplit(&par);
  650. if (!strcmp(new, "rand")) {
  651. make_rand_str(pass, 15);
  652. } else {
  653. if (strlen(new) < 6) {
  654. dprintf(idx, STR("Please use at least 6 characters.\n"));
  655. return;
  656. } else {
  657. sprintf(pass, "%s", new);
  658. }
  659. }
  660. if (strlen(pass) > 15)
  661. pass[15] = 0;
  662. set_user(&USERENTRY_SECPASS, u, pass);
  663. dprintf(idx, STR("Changed your secpass to: %s.\n"), pass);
  664. #ifdef HUB
  665. write_userfile(idx);
  666. #endif /* HUB */
  667. }
  668. #ifdef HUB
  669. static void cmd_bots(struct userrec *u, int idx, char *par)
  670. {
  671. putlog(LOG_CMDS, "*", STR("#%s# bots"), dcc[idx].nick);
  672. tell_bots(idx);
  673. }
  674. static void cmd_downbots(struct userrec *u, int idx, char *par)
  675. {
  676. struct userrec *u2;
  677. int cnt = 0, tot = 0;
  678. char work[128] = "";
  679. putlog(LOG_CMDS, "*", STR("#%s# downbots"), dcc[idx].nick);
  680. for (u2 = userlist; u2; u2 = u2->next) {
  681. if (u2->flags & USER_BOT) {
  682. if (egg_strcasecmp(u2->handle, botnetnick)) {
  683. if (nextbot(u2->handle) == -1) {
  684. strcat(work, u2->handle);
  685. cnt++;
  686. tot++;
  687. if (cnt == 10) {
  688. dprintf(idx, STR("Down bots: %s\n"), work);
  689. work[0] = 0;
  690. cnt = 0;
  691. } else
  692. strcat(work, " ");
  693. }
  694. }
  695. }
  696. }
  697. if (work[0])
  698. dprintf(idx, STR("Down bots: %s\n"), work);
  699. dprintf(idx, STR("(Total down: %d)\n"), tot);
  700. }
  701. static void cmd_bottree(struct userrec *u, int idx, char *par)
  702. {
  703. putlog(LOG_CMDS, "*", STR("#%s# bottree"), dcc[idx].nick);
  704. tell_bottree(idx, 0);
  705. }
  706. static void cmd_vbottree(struct userrec *u, int idx, char *par)
  707. {
  708. putlog(LOG_CMDS, "*", STR("#%s# vbottree"), dcc[idx].nick);
  709. tell_bottree(idx, 1);
  710. }
  711. #endif /* HUB */
  712. int my_cmp (const mycmds *c1, const mycmds *c2)
  713. {
  714. return strcmp (c1->name, c2->name);
  715. }
  716. static void cmd_nohelp(struct userrec *u, int idx, char *par)
  717. {
  718. int i;
  719. char *buf = nmalloc(1);
  720. buf[0] = 0;
  721. qsort(cmds, cmdi, sizeof(mycmds), (int (*)()) &my_cmp);
  722. for (i = 0; i < cmdi; i++) {
  723. int o, found = 0;
  724. for (o = 0; (help[o].cmd) && (help[o].desc); o++)
  725. if (!egg_strcasecmp(help[o].cmd, cmds[i].name)) found++;
  726. if (!found) {
  727. buf = nrealloc(buf, strlen(buf) + 2 + strlen(cmds[i].name) + 1);
  728. strcat(buf, cmds[i].name);
  729. strcat(buf, ", ");
  730. }
  731. }
  732. buf[strlen(buf) - 1] = 0;
  733. dumplots(idx, "", buf);
  734. }
  735. static void cmd_help(struct userrec *u, int idx, char *par)
  736. {
  737. char flg[100];
  738. int fnd = 0, done = 0, nowild = 0;
  739. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  740. char *fcats, temp[100], buf[2046], match[20];
  741. egg_snprintf(temp, sizeof temp, "a|- a|a n|- n|n m|- m|m mo|o m|o i|- o|o o|- p|- -|-");
  742. fcats = temp;
  743. putlog(LOG_CMDS, "*", STR("#%s# help %s"), dcc[idx].nick, par);
  744. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  745. build_flags(flg, &fr, NULL);
  746. if (!par[0]) {
  747. sprintf(match, "*");
  748. } else {
  749. if (!strchr(par, '*') && !strchr(par, '?'))
  750. nowild++;
  751. sprintf(match, "%s", newsplit(&par));
  752. }
  753. if (!nowild)
  754. dprintf(idx, STR("Showing help topics matching '%s' for flags: (%s)\n"), match, flg);
  755. qsort(cmds, cmdi, sizeof(mycmds), (int (*)()) &my_cmp);
  756. buf[0] = 0;
  757. /* even if we have nowild, we loop to conserve code/space */
  758. while (!done) {
  759. int i = 0, end = 0, first = 1, n, hi;
  760. char *flag;
  761. flag = newsplit(&fcats);
  762. if (!flag[0])
  763. done = 1;
  764. for (n = 0; n < cmdi; n++) { /* loop each command */
  765. if (!flagrec_ok(&cmds[n].flags, &fr) || !wild_match(match, cmds[n].name))
  766. continue;
  767. fnd++;
  768. if (nowild) {
  769. flg[0] = 0;
  770. build_flags(flg, &(cmds[n].flags), NULL);
  771. dprintf(idx, STR("Showing you help for '%s' (%s):\n"), match, flg);
  772. for (hi = 0; (help[hi].cmd) && (help[hi].desc); hi++) {
  773. if (!egg_strcasecmp(match, help[hi].cmd)) {
  774. if (help[hi].garble)
  775. showhelp(idx, &fr, degarble(help[hi].garble, help[hi].desc));
  776. else
  777. showhelp(idx, &fr, help[hi].desc);
  778. }
  779. }
  780. done = 1;
  781. break;
  782. } else {
  783. flg[0] = 0;
  784. build_flags(flg, &(cmds[n].flags), NULL);
  785. if (!strcmp(flg, flag)) {
  786. if (first) {
  787. dprintf(idx, "%s\n", buf[0] ? buf : "");
  788. dprintf(idx, STR("# DCC (%s)\n"), flag);
  789. sprintf(buf, " ");
  790. }
  791. if (end && !first) {
  792. dprintf(idx, "%s\n", buf[0] ? buf : "");
  793. /* we dumped the buf to dprintf, now start a new one... */
  794. sprintf(buf, " ");
  795. }
  796. sprintf(buf, "%s%-14.14s", buf[0] ? buf : "", cmds[n].name);
  797. first = 0;
  798. end = 0;
  799. i++;
  800. }
  801. if (i >= 5) {
  802. end = 1;
  803. i = 0;
  804. }
  805. }
  806. }
  807. }
  808. if (buf && buf[0])
  809. dprintf(idx, "%s\n", buf);
  810. if (fnd)
  811. dprintf(idx, STR("--End help listing\n"));
  812. if (!strcmp(match, "*")) {
  813. dprintf(idx, STR("For individual command help, type: %shelp <command>\n"), dcc_prefix);
  814. } else if (!fnd) {
  815. dprintf(idx, STR("No match for '%s'.\n"), match);
  816. }
  817. dprintf(idx, STR("If you have flags on a channel, type %sconsole #chan to possibly see more commands.\n"), dcc_prefix);
  818. }
  819. static void cmd_addlog(struct userrec *u, int idx, char *par)
  820. {
  821. putlog(LOG_CMDS, "*", STR("#%s# addlog %s"), dcc[idx].nick, par);
  822. putlog(LOG_MISC, "*", "%s: %s", dcc[idx].nick, par);
  823. if (!par[0]) {
  824. dprintf(idx, STR("Usage: addlog <message>\n"));
  825. return;
  826. }
  827. dprintf(idx, STR("Placed entry in the log file.\n"));
  828. }
  829. #ifdef HUB
  830. static void cmd_who(struct userrec *u, int idx, char *par)
  831. {
  832. int i;
  833. if (par[0]) {
  834. if (dcc[idx].u.chat->channel < 0) {
  835. dprintf(idx, STR("You have chat turned off.\n"));
  836. return;
  837. }
  838. putlog(LOG_CMDS, "*", STR("#%s# who %s"), dcc[idx].nick, par);
  839. if (!egg_strcasecmp(par, botnetnick))
  840. tell_who(u, idx, dcc[idx].u.chat->channel);
  841. else {
  842. i = nextbot(par);
  843. if (i < 0) {
  844. dprintf(idx, STR("That bot isn't connected.\n"));
  845. } else if (dcc[idx].u.chat->channel > 99999)
  846. dprintf(idx, STR("You are on a local channel.\n"));
  847. else {
  848. char s[40];
  849. simple_sprintf(s, "%d:%s@%s", dcc[idx].sock,
  850. dcc[idx].nick, botnetnick);
  851. botnet_send_who(i, s, par, dcc[idx].u.chat->channel);
  852. }
  853. }
  854. } else {
  855. putlog(LOG_CMDS, "*", STR("#%s# who"), dcc[idx].nick);
  856. if (dcc[idx].u.chat->channel < 0)
  857. tell_who(u, idx, 0);
  858. else
  859. tell_who(u, idx, dcc[idx].u.chat->channel);
  860. }
  861. }
  862. #endif /* HUB */
  863. static void cmd_whois(struct userrec *u, int idx, char *par)
  864. {
  865. if (!par[0]) {
  866. dprintf(idx, STR("Usage: whois <handle>\n"));
  867. return;
  868. }
  869. putlog(LOG_CMDS, "*", STR("#%s# whois %s"), dcc[idx].nick, par);
  870. tell_user_ident(idx, par, u ? (u->flags & USER_MASTER) : 0);
  871. }
  872. static void cmd_match(struct userrec *u, int idx, char *par)
  873. {
  874. int start = 1, limit = 20;
  875. char *s, *s1, *chname;
  876. if (!par[0]) {
  877. dprintf(idx, STR("Usage: match <nick/host> [[skip] count]\n"));
  878. return;
  879. }
  880. putlog(LOG_CMDS, "*", STR("#%s# match %s"), dcc[idx].nick, par);
  881. s = newsplit(&par);
  882. if (strchr(CHANMETA, par[0]) != NULL)
  883. chname = newsplit(&par);
  884. else
  885. chname = "";
  886. if (atoi(par) > 0) {
  887. s1 = newsplit(&par);
  888. if (atoi(par) > 0) {
  889. start = atoi(s1);
  890. limit = atoi(par);
  891. } else
  892. limit = atoi(s1);
  893. }
  894. tell_users_match(idx, s, start, limit, u ? (u->flags & USER_MASTER) : 0,
  895. chname);
  896. }
  897. static void cmd_update(struct userrec *u, int idx, char *par)
  898. {
  899. putlog(LOG_CMDS, "*", STR("#%s# update %s"), dcc[idx].nick, par);
  900. #ifdef LEAF
  901. if (!localhub)
  902. dprintf(idx, STR("Please use this command on the first listed in the conf for this user@box\n"));
  903. #endif /* LEAF */
  904. if (!par[0])
  905. dprintf(idx, STR("Usage: update <binname>\n"));
  906. updatebin(idx, par, 0);
  907. }
  908. static void cmd_uptime(struct userrec *u, int idx, char *par)
  909. {
  910. putlog(LOG_CMDS, "*", STR("#%s# uptime"), dcc[idx].nick);
  911. tell_verbose_uptime(idx);
  912. }
  913. static void cmd_userlist(struct userrec *u, int idx, char *par)
  914. {
  915. int cnt = 0, tt = 0;
  916. putlog(LOG_CMDS, "*", STR("#%s# userlist"), dcc[idx].nick);
  917. for (u=userlist;u;u=u->next) {
  918. if ((u->flags & USER_BOT) && (u->flags & USER_CHANHUB)) {
  919. if (cnt)
  920. dprintf(idx, ", ");
  921. else
  922. dprintf(idx, STR("Chathubs: "));
  923. dprintf(idx, u->handle);
  924. cnt++;
  925. tt++;
  926. if (cnt == 15) {
  927. dprintf(idx, "\n");
  928. cnt=0;
  929. }
  930. }
  931. }
  932. if (cnt)
  933. dprintf(idx, "\n");
  934. cnt=0;
  935. #ifdef HUB
  936. for (u=userlist;u;u=u->next) {
  937. if (!(u->flags & USER_BOT) && (u->flags & USER_ADMIN)) {
  938. if (cnt)
  939. dprintf(idx, ", ");
  940. else
  941. dprintf(idx, STR("Admins : "));
  942. dprintf(idx, u->handle);
  943. cnt++;
  944. tt++;
  945. if (cnt == 15) {
  946. dprintf(idx, "\n");
  947. cnt=0;
  948. }
  949. }
  950. }
  951. if (cnt)
  952. dprintf(idx, "\n");
  953. cnt=0;
  954. for (u=userlist;u;u=u->next) {
  955. if (!(u->flags & (USER_BOT | USER_ADMIN)) && (u->flags & USER_OWNER)) {
  956. if (cnt)
  957. dprintf(idx, ", ");
  958. else
  959. dprintf(idx, STR("Owners : "));
  960. dprintf(idx, u->handle);
  961. cnt++;
  962. tt++;
  963. if (cnt == 15) {
  964. dprintf(idx, "\n");
  965. cnt=0;
  966. }
  967. }
  968. }
  969. if (cnt)
  970. dprintf(idx, "\n");
  971. cnt=0;
  972. for (u=userlist;u;u=u->next) {
  973. if (!(u->flags & (USER_BOT | USER_OWNER)) && (u->flags & USER_MASTER)) {
  974. if (cnt)
  975. dprintf(idx, ", ");
  976. else
  977. dprintf(idx, STR("Masters : "));
  978. dprintf(idx, u->handle);
  979. cnt++;
  980. tt++;
  981. if (cnt == 15) {
  982. dprintf(idx, "\n");
  983. cnt=0;
  984. }
  985. }
  986. }
  987. if (cnt)
  988. dprintf(idx, "\n");
  989. cnt=0;
  990. #endif /* HUB */
  991. for (u=userlist;u;u=u->next) {
  992. #ifdef HUB
  993. if (!(u->flags & (USER_BOT | USER_MASTER)) && (u->flags & USER_OP)) {
  994. #else /* !HUB */
  995. if (!(u->flags & USER_BOT) && (u->flags & USER_OP)) {
  996. #endif /* HUB */
  997. if (cnt)
  998. dprintf(idx, ", ");
  999. else
  1000. dprintf(idx, STR("Ops : "));
  1001. dprintf(idx, u->handle);
  1002. cnt++;
  1003. tt++;
  1004. if (cnt == 15) {
  1005. dprintf(idx, "\n");
  1006. cnt=0;
  1007. }
  1008. }
  1009. }
  1010. if (cnt)
  1011. dprintf(idx, "\n");
  1012. cnt=0;
  1013. for (u=userlist;u;u=u->next) {
  1014. if (!(u->flags & (USER_BOT | USER_OP))) {
  1015. if (cnt)
  1016. dprintf(idx, ", ");
  1017. else
  1018. dprintf(idx, STR("Users : "));
  1019. dprintf(idx, u->handle);
  1020. cnt++;
  1021. tt++;
  1022. if (cnt==15) {
  1023. dprintf(idx, "\n");
  1024. cnt=0;
  1025. }
  1026. }
  1027. }
  1028. if (cnt)
  1029. dprintf(idx, "\n");
  1030. cnt=0;
  1031. dprintf(idx, STR("Total users: %d\n"), tt);
  1032. }
  1033. static void cmd_channels(struct userrec *u, int idx, char *par) {
  1034. putlog(LOG_CMDS, "*", STR("#%s# channels %s"), dcc[idx].nick, par);
  1035. if (par[0] && (u->flags & USER_MASTER)) {
  1036. struct userrec *user;
  1037. user = get_user_by_handle(userlist, par);
  1038. if (user)
  1039. show_channels(idx, par);
  1040. else
  1041. dprintf(idx, STR("There is no user by that name.\n"));
  1042. } else
  1043. show_channels(idx, NULL);
  1044. if ((u->flags & USER_MASTER) && !(par && par[0]))
  1045. dprintf(idx, STR("You can also %schannels <user>\n"), dcc_prefix);
  1046. }
  1047. static void cmd_status(struct userrec *u, int idx, char *par)
  1048. {
  1049. int atr = u ? u->flags : 0;
  1050. if (!egg_strcasecmp(par, "all")) {
  1051. if (!(atr & USER_MASTER)) {
  1052. dprintf(idx, STR("You do not have Bot Master privileges.\n"));
  1053. return;
  1054. }
  1055. putlog(LOG_CMDS, "*", STR("#%s# status all"), dcc[idx].nick);
  1056. tell_verbose_status(idx);
  1057. tell_mem_status_dcc(idx);
  1058. dprintf(idx, "\n");
  1059. tell_settings(idx);
  1060. do_module_report(idx, 1, NULL);
  1061. } else {
  1062. putlog(LOG_CMDS, "*", STR("#%s# status"), dcc[idx].nick);
  1063. tell_verbose_status(idx);
  1064. tell_mem_status_dcc(idx);
  1065. do_module_report(idx, 0, NULL);
  1066. }
  1067. }
  1068. #ifdef HUB
  1069. static void cmd_dccstat(struct userrec *u, int idx, char *par)
  1070. {
  1071. putlog(LOG_CMDS, "*", STR("#%s# dccstat"), dcc[idx].nick);
  1072. tell_dcc(idx);
  1073. }
  1074. #endif /* HUB */
  1075. static void cmd_boot(struct userrec *u, int idx, char *par)
  1076. {
  1077. int i, ok = 0;
  1078. char *who;
  1079. struct userrec *u2;
  1080. if (!par[0]) {
  1081. dprintf(idx, STR("Usage: boot nick[@bot]\n"));
  1082. return;
  1083. }
  1084. who = newsplit(&par);
  1085. if (strchr(who, '@') != NULL) {
  1086. char whonick[HANDLEN + 1];
  1087. splitcn(whonick, who, '@', HANDLEN + 1);
  1088. if (!egg_strcasecmp(who, botnetnick)) {
  1089. cmd_boot(u, idx, whonick);
  1090. return;
  1091. }
  1092. if (remote_boots > 0) {
  1093. i = nextbot(who);
  1094. if (i < 0) {
  1095. dprintf(idx, STR("No such bot connected.\n"));
  1096. return;
  1097. }
  1098. botnet_send_reject(i, dcc[idx].nick, botnetnick, whonick,
  1099. who, par[0] ? par : dcc[idx].nick);
  1100. putlog(LOG_BOTS, "*", STR("#%s# boot %s@%s (%s)"), dcc[idx].nick, whonick,
  1101. who, par[0] ? par : dcc[idx].nick);
  1102. } else
  1103. dprintf(idx, STR("Remote boots are disabled here.\n"));
  1104. return;
  1105. }
  1106. for (i = 0; i < dcc_total; i++)
  1107. if (!egg_strcasecmp(dcc[i].nick, who)
  1108. && !ok && (dcc[i].type->flags & DCT_CANBOOT)) {
  1109. u2 = get_user_by_handle(userlist, dcc[i].nick);
  1110. if (u2 && (u2->flags & USER_OWNER)
  1111. && egg_strcasecmp(dcc[idx].nick, who)) {
  1112. dprintf(idx, STR("You can't boot a bot owner.\n"));
  1113. return;
  1114. }
  1115. if (u2 && (u2->flags & USER_MASTER) && !(u && (u->flags & USER_MASTER))) {
  1116. dprintf(idx, STR("You can't boot a bot master.\n"));
  1117. return;
  1118. }
  1119. dprintf(idx, STR("Booted %s from the party line.\n"), dcc[i].nick);
  1120. putlog(LOG_CMDS, "*", STR("#%s# boot %s %s"), dcc[idx].nick, who, par);
  1121. do_boot(i, dcc[idx].nick, par);
  1122. ok = 1;
  1123. }
  1124. if (!ok)
  1125. dprintf(idx, STR("Who? No such person on the party line.\n"));
  1126. }
  1127. static void cmd_console(struct userrec *u, int idx, char *par)
  1128. {
  1129. char *nick, s[2], s1[512];
  1130. int dest = 0, i, ok = 0, pls, md;
  1131. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  1132. module_entry *me;
  1133. struct chanset_t *chan;
  1134. if (!par[0]) {
  1135. dprintf(idx, STR("Your console is %s: %s (%s).\n"),
  1136. dcc[idx].u.chat->con_chan,
  1137. masktype(dcc[idx].u.chat->con_flags),
  1138. maskname(dcc[idx].u.chat->con_flags));
  1139. return;
  1140. }
  1141. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  1142. strcpy(s1, par);
  1143. nick = newsplit(&par);
  1144. /* Don't remove '+' as someone couldn't have '+' in CHANMETA cause
  1145. * he doesn't use IRCnet ++rtc.
  1146. */
  1147. if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
  1148. for (i = 0; i < dcc_total; i++)
  1149. if (!egg_strcasecmp(nick, dcc[i].nick) &&
  1150. (dcc[i].type == &DCC_CHAT) && (!ok)) {
  1151. ok = 1;
  1152. dest = i;
  1153. }
  1154. if (!ok) {
  1155. dprintf(idx, STR("No such user on the party line!\n"));
  1156. return;
  1157. }
  1158. nick[0] = 0;
  1159. } else
  1160. dest = idx;
  1161. if (!nick[0])
  1162. nick = newsplit(&par);
  1163. /* Consider modeless channels, starting with '+' */
  1164. if ((nick [0] == '+' && findchan_by_dname(nick)) ||
  1165. (nick [0] != '+' && strchr(CHANMETA "*", nick[0]))) {
  1166. chan = findchan_by_dname(nick);
  1167. if (strcmp(nick, "*") && !chan) {
  1168. dprintf(idx, STR("Invalid console channel: %s.\n"), nick);
  1169. return;
  1170. }
  1171. get_user_flagrec(u, &fr, nick);
  1172. if (strcmp(nick, "*") && private(fr, findchan_by_dname(nick), PRIV_OP)) {
  1173. dprintf(idx, STR("Invalid console channel: %s.\n"), nick);
  1174. return;
  1175. }
  1176. if (!chk_op(fr, findchan_by_dname(nick))) {
  1177. dprintf(idx, STR("You don't have op or master access to channel %s.\n"), nick);
  1178. return;
  1179. }
  1180. strncpyz(dcc[dest].u.chat->con_chan, nick, 81);
  1181. nick[0] = 0;
  1182. if ((dest == idx) && !glob_master(fr) && !chan_master(fr))
  1183. /* Consoling to another channel for self */
  1184. dcc[dest].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_WALL);
  1185. }
  1186. if (!nick[0])
  1187. nick = newsplit(&par);
  1188. pls = 1;
  1189. if (nick[0]) {
  1190. if ((nick[0] != '+') && (nick[0] != '-'))
  1191. dcc[dest].u.chat->con_flags = 0;
  1192. for (; *nick; nick++) {
  1193. if (*nick == '+')
  1194. pls = 1;
  1195. else if (*nick == '-')
  1196. pls = 0;
  1197. else {
  1198. s[0] = *nick;
  1199. s[1] = 0;
  1200. md = logmodes(s);
  1201. if ((dest == idx) && !glob_master(fr) && pls) {
  1202. if (chan_master(fr))
  1203. md &= ~(LOG_FILES | LOG_DEBUG);
  1204. else
  1205. md &= ~(LOG_MISC | LOG_CMDS | LOG_FILES | LOG_WALL |
  1206. LOG_DEBUG);
  1207. }
  1208. if (!glob_owner(fr) && pls)
  1209. md &= ~(LOG_RAW | LOG_SRVOUT | LOG_BOTNET | LOG_BOTSHARE | LOG_ERRORS | LOG_GETIN | LOG_WARN);
  1210. if (!glob_master(fr) && pls)
  1211. md &= ~LOG_BOTS;
  1212. if (pls)
  1213. dcc[dest].u.chat->con_flags |= md;
  1214. else
  1215. dcc[dest].u.chat->con_flags &= ~md;
  1216. }
  1217. }
  1218. }
  1219. putlog(LOG_CMDS, "*", STR("#%s# console %s"), dcc[idx].nick, s1);
  1220. if (dest == idx) {
  1221. dprintf(idx, STR("Set your console to %s: %s (%s).\n"),
  1222. dcc[idx].u.chat->con_chan,
  1223. masktype(dcc[idx].u.chat->con_flags),
  1224. maskname(dcc[idx].u.chat->con_flags));
  1225. } else {
  1226. dprintf(idx, STR("Set console of %s to %s: %s (%s).\n"), dcc[dest].nick,
  1227. dcc[dest].u.chat->con_chan,
  1228. masktype(dcc[dest].u.chat->con_flags),
  1229. maskname(dcc[dest].u.chat->con_flags));
  1230. dprintf(dest, STR("%s set your console to %s: %s (%s).\n"), dcc[idx].nick,
  1231. dcc[dest].u.chat->con_chan,
  1232. masktype(dcc[dest].u.chat->con_flags),
  1233. maskname(dcc[dest].u.chat->con_flags));
  1234. }
  1235. /* New style autosave -- drummer,07/25/1999*/
  1236. if ((me = module_find("console", 0, 0))) {
  1237. Function *func = me->funcs;
  1238. (func[CONSOLE_DOSTORE]) (dest);
  1239. }
  1240. }
  1241. void test_colors(int);
  1242. static void cmd_date(struct userrec *u, int idx, char *par)
  1243. {
  1244. char date[50], utctime[50], ltime[50];
  1245. ltime[0] = utctime[0] = 0;
  1246. putlog(LOG_CMDS, "*", "#%s# date", dcc[idx].nick);
  1247. egg_strftime(date, sizeof date, "%c %Z", localtime(&now));
  1248. #ifndef S_UTCTIME
  1249. sprintf(ltime, "<-- This time is used on the bot.");
  1250. #endif /* !S_UTCTIME */
  1251. dprintf(idx, "%s %s\n", date, (ltime && ltime[0]) ? ltime : "");
  1252. egg_strftime(date, sizeof date, "%c %Z", gmtime(&now));
  1253. #ifdef S_UTCTIME
  1254. sprintf(utctime, "<-- This time is used on the bot.");
  1255. #endif /* S_UTCTIME */
  1256. dprintf(idx, "%s %s\n", date, (utctime && utctime[0]) ? utctime : "");
  1257. }
  1258. #ifdef HUB
  1259. static void cmd_chhandle(struct userrec *u, int idx, char *par)
  1260. {
  1261. char hand[HANDLEN + 1], newhand[HANDLEN + 1];
  1262. int i, atr = u ? u->flags : 0, atr2;
  1263. struct userrec *u2;
  1264. strncpyz(hand, newsplit(&par), sizeof hand);
  1265. strncpyz(newhand, newsplit(&par), sizeof newhand);
  1266. if (!hand[0] || !newhand[0]) {
  1267. dprintf(idx, STR("Usage: chhandle <oldhandle> <newhandle>\n"));
  1268. return;
  1269. }
  1270. for (i = 0; i < strlen(newhand); i++)
  1271. if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
  1272. newhand[i] = '?';
  1273. if (strchr(BADHANDCHARS, newhand[0]) != NULL)
  1274. dprintf(idx, STR("Bizarre quantum forces prevent nicknames from starting with '%c'.\n"),
  1275. newhand[0]);
  1276. else if (get_user_by_handle(userlist, newhand) &&
  1277. egg_strcasecmp(hand, newhand))
  1278. dprintf(idx, STR("Somebody is already using %s.\n"), newhand);
  1279. else {
  1280. u2 = get_user_by_handle(userlist, hand);
  1281. atr2 = u2 ? u2->flags : 0;
  1282. if (!(atr & USER_MASTER) && !(atr2 & USER_BOT))
  1283. dprintf(idx, STR("You can't change handles for non-bots.\n"));
  1284. else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
  1285. dprintf(idx, STR("You can't change share bot's nick.\n"));
  1286. else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
  1287. egg_strcasecmp(dcc[idx].nick, hand))
  1288. dprintf(idx, STR("You can't change a bot owner's handle.\n"));
  1289. else if (isowner(hand) && egg_strcasecmp(dcc[idx].nick, hand))
  1290. dprintf(idx, STR("You can't change a permanent bot owner's handle.\n"));
  1291. else if (!egg_strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
  1292. nextbot(hand) != -1))
  1293. dprintf(idx, STR("Hey! That's MY name!\n"));
  1294. else if (change_handle(u2, newhand)) {
  1295. putlog(LOG_CMDS, "*", STR("#%s# chhandle %s %s"), dcc[idx].nick,
  1296. hand, newhand);
  1297. dprintf(idx, STR("Changed.\n"));
  1298. } else
  1299. dprintf(idx, STR("Failed.\n"));
  1300. #ifdef HUB
  1301. write_userfile(idx);
  1302. #endif /* HUB */
  1303. }
  1304. }
  1305. #endif /* HUB */
  1306. static void cmd_handle(struct userrec *u, int idx, char *par)
  1307. {
  1308. char oldhandle[HANDLEN + 1], newhandle[HANDLEN + 1];
  1309. int i;
  1310. strncpyz(newhandle, newsplit(&par), sizeof newhandle);
  1311. if (!newhandle[0]) {
  1312. dprintf(idx, STR("Usage: handle <new-handle>\n"));
  1313. return;
  1314. }
  1315. for (i = 0; i < strlen(newhandle); i++)
  1316. if ((newhandle[i] <= 32) || (newhandle[i] >= 127) || (newhandle[i] == '@'))
  1317. newhandle[i] = '?';
  1318. if (strchr(BADHANDCHARS, newhandle[0]) != NULL) {
  1319. dprintf(idx, STR("Bizarre quantum forces prevent handle from starting with '%c'.\n"),
  1320. newhandle[0]);
  1321. } else if (get_user_by_handle(userlist, newhandle) &&
  1322. egg_strcasecmp(dcc[idx].nick, newhandle)) {
  1323. dprintf(idx, STR("Somebody is already using %s.\n"), newhandle);
  1324. } else if (!egg_strcasecmp(newhandle, botnetnick)) {
  1325. dprintf(idx, STR("Hey! That's MY name!\n"));
  1326. } else {
  1327. strncpyz(oldhandle, dcc[idx].nick, sizeof oldhandle);
  1328. if (change_handle(u, newhandle)) {
  1329. putlog(LOG_CMDS, "*", STR("#%s# handle %s"), oldhandle, newhandle);
  1330. dprintf(idx, STR("Okay, changed.\n"));
  1331. } else
  1332. dprintf(idx, STR("Failed.\n"));
  1333. #ifdef HUB
  1334. write_userfile(idx);
  1335. #endif /* HUB */
  1336. }
  1337. }
  1338. #ifdef HUB
  1339. static void cmd_chpass(struct userrec *u, int idx, char *par)
  1340. {
  1341. char *handle, *new, pass[16];
  1342. int atr = u ? u->flags : 0, l;
  1343. if (!par[0])
  1344. dprintf(idx, STR("Usage: chpass <handle> [password]\n"));
  1345. else {
  1346. handle = newsplit(&par);
  1347. u = get_user_by_handle(userlist, handle);
  1348. if (!u)
  1349. dprintf(idx, STR("No such user.\n"));
  1350. else if (!(atr & USER_MASTER) && !(u->flags & USER_BOT))
  1351. dprintf(idx, STR("You can't change passwords for non-bots.\n"));
  1352. else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
  1353. dprintf(idx, STR("You can't change a share bot's password.\n"));
  1354. else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
  1355. egg_strcasecmp(handle, dcc[idx].nick))
  1356. dprintf(idx, STR("You can't change a bot owner's password.\n"));
  1357. else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
  1358. dprintf(idx, STR("You can't change a permanent bot owner's password.\n"));
  1359. else if (!par[0]) {
  1360. putlog(LOG_CMDS, "*", STR("#%s# chpass %s [nothing]"), dcc[idx].nick,
  1361. handle);
  1362. set_user(&USERENTRY_PASS, u, NULL);
  1363. dprintf(idx, STR("Removed password.\n"));
  1364. } else {
  1365. int good = 0;
  1366. l = strlen(new = newsplit(&par));
  1367. if (l > 15)
  1368. new[15] = 0;
  1369. if (!strcmp(new, "rand")) {
  1370. make_rand_str(pass, 15);
  1371. good = 1;
  1372. } else {
  1373. if (goodpass(new, idx, NULL)) {
  1374. sprintf(pass, "%s", new);
  1375. good = 1;
  1376. }
  1377. }
  1378. if (strlen(pass) > 15)
  1379. pass[15] = 0;
  1380. if (good) {
  1381. set_user(&USERENTRY_PASS, u, pass);
  1382. putlog(LOG_CMDS, "*", STR("#%s# chpass %s [something]"), dcc[idx].nick, handle);
  1383. dprintf(idx, STR("Password for '%s' changed to: %s\n"), handle, pass);
  1384. #ifdef HUB
  1385. write_userfile(idx);
  1386. #endif /* HUB */
  1387. }
  1388. }
  1389. }
  1390. }
  1391. static void cmd_chsecpass(struct userrec *u, int idx, char *par)
  1392. {
  1393. char *handle, *new, pass[16];
  1394. int atr = u ? u->flags : 0, l;
  1395. if (!par[0])
  1396. dprintf(idx, STR("Usage: chsecpass <handle> [secpass/rand]\n"));
  1397. else {
  1398. handle = newsplit(&par);
  1399. u = get_user_by_handle(userlist, handle);
  1400. if (!u)
  1401. dprintf(idx, STR("No such user.\n"));
  1402. else if (!(atr & USER_MASTER) && !(u->flags & USER_BOT))
  1403. dprintf(idx, STR("You can't change passwords for non-bots.\n"));
  1404. else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
  1405. dprintf(idx, STR("You can't change a share bot's password.\n"));
  1406. else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
  1407. egg_strcasecmp(handle, dcc[idx].nick))
  1408. dprintf(idx, STR("You can't change a bot owner's password.\n"));
  1409. else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
  1410. dprintf(idx, STR("You can't change a permanent bot owner's password.\n"));
  1411. else if (!par[0]) {
  1412. putlog(LOG_CMDS, "*", STR("#%s# chsecpass %s [nothing]"), dcc[idx].nick,
  1413. handle);
  1414. set_user(&USERENTRY_SECPASS, u, NULL);
  1415. dprintf(idx, STR("Removed secpass.\n"));
  1416. } else {
  1417. l = strlen(new = newsplit(&par));
  1418. if (l > 15)
  1419. new[15] = 0;
  1420. if (!strcmp(new, "rand")) {
  1421. make_rand_str(pass, 15);
  1422. } else {
  1423. if (strlen(new) < 6) {
  1424. dprintf(idx, STR("Please use at least 6 characters.\n"));
  1425. return;
  1426. } else {
  1427. sprintf(pass, "%s", new);
  1428. }
  1429. }
  1430. if (strlen(pass) > 15)
  1431. pass[15] = 0;
  1432. set_user(&USERENTRY_SECPASS, u, pass);
  1433. putlog(LOG_CMDS, "*", STR("#%s# chsecpass %s [something]"), dcc[idx].nick, handle);
  1434. dprintf(idx, STR("Secpass for '%s' changed to: %s\n"), handle, pass);
  1435. #ifdef HUB
  1436. write_userfile(idx);
  1437. #endif /* HUB */
  1438. }
  1439. }
  1440. }
  1441. static void cmd_botcmd(struct userrec *u, int idx, char *par)
  1442. {
  1443. tand_t *tbot;
  1444. int cnt = 0, rleaf = (-1), tbots = 0;
  1445. char *botm = NULL, *cmd = NULL;
  1446. botm = newsplit(&par);
  1447. cmd = newsplit(&par);
  1448. if (!botm[0] || !cmd[0]) {
  1449. dprintf(idx, STR("Usage: botcmd <bot> <cmd> [params]\n"));
  1450. return;
  1451. }
  1452. /* the rest of the cmd will be logged remotely */
  1453. putlog(LOG_CMDS, "*", STR("#%s# botcmd %s %s ..."), dcc[idx].nick, botm, cmd);
  1454. if (!strcmp(botm, "*") && (!strcmp(botm, "di") || !strcmp(botm, "die"))) {
  1455. dprintf(idx, STR("Not a good idea.\n"));
  1456. return;
  1457. }
  1458. if (!strcmp(botm, "?")) {
  1459. for (tbot = tandbot; tbot; tbot = tbot->next)
  1460. if (bot_hublevel(get_user_by_handle(userlist, tbot->bot)))
  1461. tbots++;
  1462. rleaf = random() % tbots;
  1463. }
  1464. for (tbot = tandbot; tbot; tbot = tbot->next) {
  1465. if ((rleaf != (-1) && cnt == rleaf) || ((rleaf == (-1) && wild_match(botm, tbot->bot)))) {
  1466. send_remote_simul(idx, tbot->bot, cmd, par ? par : "");
  1467. }
  1468. cnt++;
  1469. }
  1470. if (!cnt) {
  1471. dprintf(idx, STR("No bot matching '%s' linked\n"), botm);
  1472. return;
  1473. }
  1474. }
  1475. static void cmd_hublevel(struct userrec *u, int idx, char *par)
  1476. {
  1477. char *handle, *level;
  1478. struct bot_addr *bi, *obi;
  1479. struct userrec *u1;
  1480. putlog(LOG_CMDS, "*", STR("#%s# hublevel %s"), dcc[idx].nick, par);
  1481. if (!par[0]) {
  1482. dprintf(idx, STR("Usage: hublevel <bot> <level>\n"));
  1483. return;
  1484. }
  1485. handle = newsplit(&par);
  1486. level = newsplit(&par);
  1487. u1 = get_user_by_handle(userlist, handle);
  1488. if (!u1 || !(u1->flags & USER_BOT)) {
  1489. dprintf(idx, STR("Useful only for bots.\n"));
  1490. return;
  1491. }
  1492. dprintf(idx, STR("Changed bot's hublevel.\n"));
  1493. obi = get_user(&USERENTRY_BOTADDR, u1);
  1494. bi = user_malloc(sizeof(struct bot_addr));
  1495. bi->uplink = user_malloc(strlen(obi->uplink) + 1);
  1496. strcpy(bi->uplink, obi->uplink);
  1497. bi->address = user_malloc(strlen(obi->address) + 1);
  1498. strcpy(bi->address, obi->address);
  1499. bi->telnet_port = obi->telnet_port;
  1500. bi->relay_port = obi->relay_port;
  1501. bi->hublevel = atoi(level);
  1502. set_user(&USERENTRY_BOTADDR, u1, bi);
  1503. #ifdef HUB
  1504. write_userfile(idx);
  1505. #endif /* HUB */
  1506. }
  1507. static void cmd_uplink(struct userrec *u, int idx, char *par)
  1508. {
  1509. char *handle, *uplink;
  1510. struct bot_addr *bi, *obi;
  1511. struct userrec *u1;
  1512. putlog(LOG_CMDS, "*", STR("#%s# uplink %s"), dcc[idx].nick, par);
  1513. if (!par[0]) {
  1514. dprintf(idx, STR("Usage: uplink <bot> [uplink]\n"));
  1515. return;
  1516. }
  1517. handle = newsplit(&par);
  1518. uplink = newsplit(&par);
  1519. if (!uplink)
  1520. uplink = "";
  1521. u1 = get_user_by_handle(userlist, handle);
  1522. if (!u1 || !(u1->flags & USER_BOT)) {
  1523. dprintf(idx, STR("Useful only for bots.\n"));
  1524. return;
  1525. }
  1526. if (uplink && uplink[0])
  1527. dprintf(idx, STR("Changed bot's uplink.\n"));
  1528. else
  1529. dprintf(idx, STR("Cleared bot's uplink.\n"));
  1530. obi = get_user(&USERENTRY_BOTADDR, u1);
  1531. bi = user_malloc(sizeof(struct bot_addr));
  1532. bi->uplink = user_malloc(strlen(uplink) + 1);
  1533. strcpy(bi->uplink, uplink);
  1534. bi->address = user_malloc(strlen(obi->address) + 1);
  1535. strcpy(bi->address, obi->address);
  1536. bi->telnet_port = obi->telnet_port;
  1537. bi->relay_port = obi->relay_port;
  1538. bi->hublevel = obi->hublevel;
  1539. set_user(&USERENTRY_BOTADDR, u1, bi);
  1540. #ifdef HUB
  1541. write_userfile(idx);
  1542. #endif /* HUB */
  1543. }
  1544. static void cmd_chaddr(struct userrec *u, int idx, char *par)
  1545. {
  1546. int telnet_port = 3333, relay_port = 3333;
  1547. #ifdef USE_IPV6
  1548. char *handle, *addr, *p, *q, *r;
  1549. #else
  1550. char *handle, *addr, *p, *q;
  1551. #endif /* USE_IPV6 */
  1552. struct bot_addr *bi, *obi;
  1553. struct userrec *u1;
  1554. handle = newsplit(&par);
  1555. if (!par[0]) {
  1556. dprintf(idx, STR("Usage: chaddr <bot> <address[:telnet-port[/relay-port]]>\n"));
  1557. return;
  1558. }
  1559. addr = newsplit(&par);
  1560. if (strlen(addr) > UHOSTMAX)
  1561. addr[UHOSTMAX] = 0;
  1562. u1 = get_user_by_handle(userlist, handle);
  1563. if (!u1 || !(u1->flags & USER_BOT)) {
  1564. dprintf(idx, STR("This command is only useful for tandem bots.\n"));
  1565. return;
  1566. }
  1567. if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
  1568. dprintf(idx, STR("You can't change a share bot's address.\n"));
  1569. return;
  1570. }
  1571. putlog(LOG_CMDS, "*", STR("#%s# chaddr %s %s"), dcc[idx].nick, handle, addr);
  1572. dprintf(idx, STR("Changed bot's address.\n"));
  1573. obi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
  1574. bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
  1575. if (bi) {
  1576. telnet_port = bi->telnet_port;
  1577. relay_port = bi->relay_port;
  1578. }
  1579. bi = user_malloc(sizeof(struct bot_addr));
  1580. bi->uplink = user_malloc(strlen(obi->uplink) + 1);
  1581. strcpy(bi->uplink, obi->uplink);
  1582. bi->hublevel = obi->hublevel;
  1583. q = strchr(addr, ':');
  1584. if (!q) {
  1585. bi->address = user_malloc(strlen(addr) + 1);
  1586. strcpy(bi->address, addr);
  1587. bi->telnet_port = telnet_port;
  1588. bi->relay_port = relay_port;
  1589. } else {
  1590. #ifdef USE_IPV6
  1591. r = strchr(addr, '[');
  1592. if (r) { /* ipv6 notation [3ffe:80c0:225::] */
  1593. *addr++;
  1594. r = strchr(addr, ']');
  1595. bi->address = user_malloc(r - addr + 1);
  1596. strncpyz(bi->address, addr, r - addr + 1);
  1597. addr = r;
  1598. *addr++;
  1599. } else {
  1600. bi->address = user_malloc(q - addr + 1);
  1601. strncpyz(bi->address, addr, q - addr + 1);
  1602. }
  1603. q = strchr(addr, ':');
  1604. if (q) {
  1605. p = q + 1;
  1606. bi->telnet_port = atoi(p);
  1607. q = strchr(p, '/');
  1608. if (!q) {
  1609. bi->relay_port = telnet_port;
  1610. } else {
  1611. bi->relay_port = atoi(q + 1);
  1612. }
  1613. }
  1614. #else /* !USE_IPV6 */
  1615. bi->address = user_malloc(q - addr + 1);
  1616. strncpyz(bi->address, addr, q - addr + 1);
  1617. p = q + 1;
  1618. bi->telnet_port = atoi(p);
  1619. q = strchr(p, '/');
  1620. if (!q)
  1621. bi->relay_port = bi->telnet_port;
  1622. else
  1623. bi->relay_port = atoi(q + 1);
  1624. #endif /* USE_IPV6 */
  1625. }
  1626. set_user(&USERENTRY_BOTADDR, u1, bi);
  1627. #ifdef HUB
  1628. write_userfile(idx);
  1629. #endif /* HUB */
  1630. }
  1631. #endif /* HUB */
  1632. static void cmd_comment(struct userrec *u, int idx, char *par)
  1633. {
  1634. char *handle;
  1635. struct userrec *u1;
  1636. handle = newsplit(&par);
  1637. if (!par[0]) {
  1638. dprintf(idx, STR("Usage: comment <handle> <newcomment/none>\n"));
  1639. return;
  1640. }
  1641. u1 = get_user_by_handle(userlist, handle);
  1642. if (!u1) {
  1643. dprintf(idx, STR("No such user!\n"));
  1644. return;
  1645. }
  1646. if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
  1647. egg_strcasecmp(handle, dcc[idx].nick)) {
  1648. dprintf(idx, STR("You can't change comment on a bot owner.\n"));
  1649. return;
  1650. }
  1651. putlog(LOG_CMDS, "*", STR("#%s# comment %s %s"), dcc[idx].nick, handle, par);
  1652. if (!egg_strcasecmp(par, "none")) {
  1653. dprintf(idx, STR("Okay, comment blanked.\n"));
  1654. set_user(&USERENTRY_COMMENT, u1, NULL);
  1655. return;
  1656. }
  1657. dprintf(idx, STR("Changed comment.\n"));
  1658. update_mod(handle, dcc[idx].nick, "comment", NULL);
  1659. set_user(&USERENTRY_COMMENT, u1, par);
  1660. #ifdef HUB
  1661. write_userfile(idx);
  1662. #endif /* HUB */
  1663. }
  1664. static void cmd_randstring(struct userrec *u, int idx, char *par)
  1665. {
  1666. int len;
  1667. char *rand;
  1668. if (!par[0]) {
  1669. dprintf(idx, "Usage: randstring <len>\n");
  1670. return;
  1671. }
  1672. putlog(LOG_CMDS, "*", STR("#%s# randstring %s"), dcc[idx].nick, par);
  1673. len = atoi(par);
  1674. rand = nmalloc(len + 1);
  1675. make_rand_str(rand, len);
  1676. dprintf(idx, STR("string: %s\n"), rand);
  1677. nfree(rand);
  1678. }
  1679. static void cmd_restart(struct userrec *u, int idx, char *par)
  1680. {
  1681. putlog(LOG_CMDS, "*", STR("#%s# restart"), dcc[idx].nick);
  1682. #ifdef HUB
  1683. write_userfile(idx);
  1684. #endif /* HUB */
  1685. #ifdef LEAF
  1686. {
  1687. module_entry *me;
  1688. if ((me = module_find("server", 0, 0))) {
  1689. Function *func = me->funcs;
  1690. (func[SERVER_NUKESERVER]) ("Restarting...");
  1691. }
  1692. }
  1693. #endif /* LEAF */
  1694. botnet_send_chat(-1, botnetnick, "Restarting...");
  1695. botnet_send_bye();
  1696. fatal("Restarting...", 1);
  1697. usleep(2000 * 500);
  1698. bg_send_quit(BG_ABORT);
  1699. unlink(pid_file); //if this fails it is ok, cron will restart the bot, *hopefully*
  1700. system(binname); //start new bot.
  1701. exit(0);
  1702. }
  1703. #ifdef HUB
  1704. static void cmd_reload(struct userrec *u, int idx, char *par)
  1705. {
  1706. putlog(LOG_CMDS, "*", STR("#%s# reload"), dcc[idx].nick);
  1707. dprintf(idx, STR("Reloading user file...\n"));
  1708. reload();
  1709. }
  1710. #endif /* HUB */
  1711. static void cmd_die(struct userrec *u, int idx, char *par)
  1712. {
  1713. char s1[1024], s2[1024];
  1714. putlog(LOG_CMDS, "*", STR("#%s# die %s"), dcc[idx].nick, par);
  1715. if (par[0]) {
  1716. egg_snprintf(s1, sizeof s1, STR("BOT SHUTDOWN (%s: %s)"), dcc[idx].nick, par);
  1717. egg_snprintf(s2, sizeof s2, STR("DIE BY %s!%s (%s)"), dcc[idx].nick, dcc[idx].host, par);
  1718. strncpyz(quit_msg, par, 1024);
  1719. } else {
  1720. egg_snprintf(s1, sizeof s1, STR("BOT SHUTDOWN (Authorized by %s)"), dcc[idx].nick);
  1721. egg_snprintf(s2, sizeof s2, STR("DIE BY %s!%s (request)"), dcc[idx].nick, dcc[idx].host);
  1722. strncpyz(quit_msg, dcc[idx].nick, 1024);
  1723. }
  1724. kill_bot(s1, s2);
  1725. }
  1726. static void cmd_debug(struct userrec *u, int idx, char *par)
  1727. {
  1728. putlog(LOG_CMDS, "*", STR("#%s# debug"), dcc[idx].nick);
  1729. debug_mem_to_dcc(idx);
  1730. }
  1731. static void cmd_simul(struct userrec *u, int idx, char *par)
  1732. {
  1733. char *nick;
  1734. int i, ok = 0;
  1735. nick = newsplit(&par);
  1736. if (!par[0]) {
  1737. dprintf(idx, STR("Usage: simul <hand> <text>\n"));
  1738. return;
  1739. }
  1740. if (isowner(nick)) {
  1741. dprintf(idx, STR("Unable to '.simul' permanent owners.\n"));
  1742. return;
  1743. }
  1744. for (i = 0; i < dcc_total; i++)
  1745. if (!egg_strcasecmp(nick, dcc[i].nick) && !ok &&
  1746. (dcc[i].type->flags & DCT_SIMUL)) {
  1747. putlog(LOG_CMDS, "*", STR("#%s# simul %s %s"), dcc[idx].nick, nick, par);
  1748. if (dcc[i].type && dcc[i].type->activity) {
  1749. dcc[i].type->activity(i, par, strlen(par));
  1750. ok = 1;
  1751. }
  1752. }
  1753. if (!ok)
  1754. dprintf(idx, STR("No such user on the party line.\n"));
  1755. }
  1756. #ifdef HUB
  1757. static void cmd_link(struct userrec *u, int idx, char *par)
  1758. {
  1759. char *s;
  1760. int i;
  1761. if (!par[0]) {
  1762. dprintf(idx, STR("Usage: link [some-bot] <new-bot>\n"));
  1763. return;
  1764. }
  1765. putlog(LOG_CMDS, "*", STR("#%s# link %s"), dcc[idx].nick, par);
  1766. s = newsplit(&par);
  1767. if (!par[0] || !egg_strcasecmp(par, botnetnick))
  1768. botlink(dcc[idx].nick, idx, s);
  1769. else {
  1770. char x[40];
  1771. i = nextbot(s);
  1772. if (i < 0) {
  1773. dprintf(idx, STR("No such bot online.\n"));
  1774. return;
  1775. }
  1776. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1777. botnet_send_link(i, x, s, par);
  1778. }
  1779. }
  1780. #endif /* HUB */
  1781. static void cmd_unlink(struct userrec *u, int idx, char *par)
  1782. {
  1783. int i;
  1784. char *bot;
  1785. if (!par[0]) {
  1786. dprintf(idx, STR("Usage: unlink <bot> [reason]\n"));
  1787. return;
  1788. }
  1789. putlog(LOG_CMDS, "*", STR("#%s# unlink %s"), dcc[idx].nick, par);
  1790. bot = newsplit(&par);
  1791. i = nextbot(bot);
  1792. if (i < 0) {
  1793. botunlink(idx, bot, par);
  1794. return;
  1795. }
  1796. /* If we're directly connected to that bot, just do it
  1797. * (is nike gunna sue?)
  1798. */
  1799. if (!egg_strcasecmp(dcc[i].nick, bot))
  1800. botunlink(idx, bot, par);
  1801. else {
  1802. char x[40];
  1803. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1804. botnet_send_unlink(i, x, lastbot(bot), bot, par);
  1805. }
  1806. }
  1807. static void cmd_relay(struct userrec *u, int idx, char *par)
  1808. {
  1809. if (!par[0]) {
  1810. dprintf(idx, STR("Usage: relay <bot>\n"));
  1811. return;
  1812. }
  1813. putlog(LOG_CMDS, "*", STR("#%s# relay %s"), dcc[idx].nick, par);
  1814. tandem_relay(idx, par, 0);
  1815. }
  1816. #ifdef HUB
  1817. static void cmd_save(struct userrec *u, int idx, char *par)
  1818. {
  1819. char buf[100], i = 0;
  1820. putlog(LOG_CMDS, "*", STR("#%s# save"), dcc[idx].nick);
  1821. sprintf(buf, "Saving user file...");
  1822. i = write_userfile(-1);
  1823. if (i == 0)
  1824. strcat(buf, "success.");
  1825. else if (i == 1)
  1826. strcat(buf, "failed: No userlist.");
  1827. else if (i == 2)
  1828. strcat(buf, "failed: Cannot open userfile for writing.");
  1829. else if (i == 3)
  1830. strcat(buf, "failed: Problem writing users/chans (see debug).");
  1831. else /* This can't happen. */
  1832. strcat(buf, "failed: Unforseen error");
  1833. buf[99] = 0;
  1834. dprintf(idx, "%s\n", buf);
  1835. }
  1836. static void cmd_backup(struct userrec *u, int idx, char *par)
  1837. {
  1838. putlog(LOG_CMDS, "*", STR("#%s# backup"), dcc[idx].nick);
  1839. dprintf(idx, STR("Backing up the channel & user files...\n"));
  1840. #ifdef HUB
  1841. write_userfile(idx);
  1842. backup_userfile();
  1843. #endif /* HUB */
  1844. }
  1845. static void cmd_trace(struct userrec *u, int idx, char *par)
  1846. {
  1847. int i;
  1848. char x[NOTENAMELEN + 11], y[11];
  1849. if (!par[0]) {
  1850. dprintf(idx, STR("Usage: trace <bot>\n"));
  1851. return;
  1852. }
  1853. if (!egg_strcasecmp(par, botnetnick)) {
  1854. dprintf(idx, STR("That's me! Hiya! :)\n"));
  1855. return;
  1856. }
  1857. i = nextbot(par);
  1858. if (i < 0) {
  1859. dprintf(idx, STR("Unreachable bot.\n"));
  1860. return;
  1861. }
  1862. putlog(LOG_CMDS, "*", STR("#%s# trace %s"), dcc[idx].nick, par);
  1863. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1864. simple_sprintf(y, ":%d", now);
  1865. botnet_send_trace(i, x, par, y);
  1866. }
  1867. static void cmd_binds(struct userrec *u, int idx, char *par)
  1868. {
  1869. putlog(LOG_CMDS, "*", STR("#%s# binds %s"), dcc[idx].nick, par);
  1870. tell_binds(idx, par);
  1871. }
  1872. #endif /* HUB */
  1873. /* After messing with someone's user flags, make sure the dcc-chat flags
  1874. * are set correctly.
  1875. */
  1876. int check_dcc_attrs(struct userrec *u, int oatr)
  1877. {
  1878. int i, stat;
  1879. if (!u)
  1880. return 0;
  1881. /* Make sure default owners are +a */
  1882. if (isowner(u->handle)) {
  1883. u->flags = sanity_check(u->flags | USER_ADMIN);
  1884. }
  1885. for (i = 0; i < dcc_total; i++) {
  1886. if ((dcc[i].type->flags & DCT_MASTER) &&
  1887. (!egg_strcasecmp(u->handle, dcc[i].nick))) {
  1888. stat = dcc[i].status;
  1889. if ((dcc[i].type == &DCC_CHAT) &&
  1890. ((u->flags & (USER_OP | USER_MASTER | USER_OWNER))
  1891. != (oatr & (USER_OP | USER_MASTER | USER_OWNER)))) {
  1892. botnet_send_join_idx(i, -1);
  1893. }
  1894. if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
  1895. struct flag_record fr = {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  1896. dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
  1897. LOG_FILES | LOG_WALL | LOG_DEBUG);
  1898. get_user_flagrec(u, &fr, NULL);
  1899. if (!chan_master(fr))
  1900. dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
  1901. dprintf(i, STR("*** POOF! ***\n"));
  1902. dprintf(i, STR("You are no longer a master on this bot.\n"));
  1903. }
  1904. if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
  1905. dcc[i].u.chat->con_flags |= conmask;
  1906. dprintf(i, STR("*** POOF! ***\n"));
  1907. dprintf(i, STR("You are now a master on this bot.\n"));
  1908. }
  1909. if (!(oatr & USER_PARTY) && (u->flags & USER_PARTY) && dcc[i].u.chat->channel < 0) {
  1910. dprintf(i, "-+- POOF! -+-\n");
  1911. dprintf(i, STR("You now have party line chat access.\n"));
  1912. dprintf(i, STR("To rejoin the partyline, type: %schat on\n"), dcc_prefix);
  1913. }
  1914. if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
  1915. dprintf(i, STR("@@@ POOF! @@@\n"));
  1916. dprintf(i, STR("You are now an OWNER of this bot.\n"));
  1917. }
  1918. if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
  1919. dprintf(i, STR("@@@ POOF! @@@\n"));
  1920. dprintf(i, STR("You are no longer an owner of this bot.\n"));
  1921. }
  1922. if (!(u->flags & USER_PARTY) && dcc[i].u.chat->channel >= 0) { //who cares about old flags, they shouldnt be here anyway.
  1923. dprintf(i, STR("-+- POOF! -+-\n"));
  1924. dprintf(i, STR("You no longer have party line chat access.\n"));
  1925. dprintf(i, STR("Leaving chat mode...\n"));
  1926. chanout_but(-1, dcc[i].u.chat->channel, STR("*** %s left the party line - no chat access.\n"), dcc[i].nick);
  1927. if (dcc[i].u.chat->channel < 100000)
  1928. botnet_send_part_idx(i, "");
  1929. dcc[i].u.chat->channel = (-1);
  1930. }
  1931. if (!(oatr & USER_ADMIN) && (u->flags & USER_ADMIN)) {
  1932. dprintf(i, STR("^^^ POOF! ^^^\n"));
  1933. dprintf(i, STR("You are now an ADMIN of this bot.\n"));
  1934. }
  1935. if ((oatr & USER_ADMIN) && !(u->flags & USER_ADMIN)) {
  1936. dprintf(i, STR("^^^ POOF! ^^^\n"));
  1937. dprintf(i, STR("You are no longer an admin of this bot.\n"));
  1938. }
  1939. if ((stat & STAT_PARTY) && (u->flags & USER_OP))
  1940. stat &= ~STAT_PARTY;
  1941. if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
  1942. !(u->flags & USER_MASTER))
  1943. stat |= STAT_PARTY;
  1944. if (stat & STAT_CHAT) {
  1945. #ifdef HUB
  1946. if (!(u->flags & USER_HUBA))
  1947. stat &= ~STAT_CHAT;
  1948. #endif /* HUB */
  1949. if (ischanhub() && !(u->flags & USER_CHUBA))
  1950. stat &= ~STAT_CHAT;
  1951. }
  1952. if ((u->flags & USER_PARTY))
  1953. stat |= STAT_CHAT;
  1954. dcc[i].status = stat;
  1955. /* Check if they no longer have access to wherever they are.
  1956. */
  1957. #ifdef HUB
  1958. if (!(u->flags & (USER_HUBA))) {
  1959. /* no hub access, drop them. */
  1960. dprintf(i, STR("-+- POOF! -+-\n"));
  1961. dprintf(i, STR("You no longer have hub access.\n\n"));
  1962. do_boot(i, botnetnick, STR("No hub access.\n\n"));
  1963. }
  1964. #else /* !HUB */
  1965. if (ischanhub() && !(u->flags & (USER_CHUBA))) {
  1966. /* no chanhub access, drop them. */
  1967. dprintf(i, STR("-+- POOF! -+-\n"));
  1968. dprintf(i, STR("You no longer have chathub access.\n\n"));
  1969. do_boot(i, botnetnick, STR("No chathub access.\n\n"));
  1970. }
  1971. #endif /* HUB */
  1972. }
  1973. if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
  1974. if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
  1975. dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
  1976. if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
  1977. dcc[i].status |= STAT_LEAF;
  1978. }
  1979. }
  1980. return u->flags;
  1981. }
  1982. int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags, int ochatr)
  1983. {
  1984. int i, found = 0, atr = u ? u->flags : 0;
  1985. struct chanset_t *chan;
  1986. if (!u)
  1987. return 0;
  1988. for (i = 0; i < dcc_total; i++) {
  1989. if ((dcc[i].type->flags & DCT_MASTER) &&
  1990. !egg_strcasecmp(u->handle, dcc[i].nick)) {
  1991. if ((dcc[i].type == &DCC_CHAT) &&
  1992. ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
  1993. != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
  1994. botnet_send_join_idx(i, -1);
  1995. if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
  1996. if (!(atr & USER_MASTER))
  1997. dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
  1998. dprintf(i, STR("*** POOF! ***\n"));
  1999. dprintf(i, STR("You are no longer a master on %s.\n"), chname);
  2000. }
  2001. if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
  2002. dcc[i].u.chat->con_flags |= conmask;
  2003. if (!(atr & USER_MASTER))
  2004. dcc[i].u.chat->con_flags &=
  2005. ~(LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
  2006. dprintf(i, STR("*** POOF! ***\n"));
  2007. dprintf(i, STR("You are now a master on %s.\n"), chname);
  2008. }
  2009. if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
  2010. dprintf(i, STR("@@@ POOF! @@@\n"));
  2011. dprintf(i, STR("You are now an OWNER of %s.\n"), chname);
  2012. }
  2013. if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
  2014. dprintf(i, STR("@@@ POOF! @@@\n"));
  2015. dprintf(i, STR("You are no longer an owner of %s.\n"), chname);
  2016. }
  2017. if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
  2018. (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
  2019. ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
  2020. (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
  2021. struct flag_record fr = {FR_CHAN, 0, 0, 0, 0, 0};
  2022. for (chan = chanset; chan && !found; chan = chan->next) {
  2023. get_user_flagrec(u, &fr, chan->dname);
  2024. if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
  2025. found = 1;
  2026. }
  2027. if (!chan)
  2028. chan = chanset;
  2029. if (chan)
  2030. strcpy(dcc[i].u.chat->con_chan, chan->dname);
  2031. else
  2032. strcpy(dcc[i].u.chat->con_chan, "*");
  2033. }
  2034. }
  2035. }
  2036. return chflags;
  2037. }
  2038. static void cmd_chattr(struct userrec *u, int idx, char *par)
  2039. {
  2040. char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
  2041. struct chanset_t *chan = NULL;
  2042. struct userrec *u2;
  2043. struct flag_record pls = {0, 0, 0, 0, 0, 0},
  2044. mns = {0, 0, 0, 0, 0, 0},
  2045. user = {0, 0, 0, 0, 0, 0},
  2046. ouser = {0, 0, 0, 0, 0, 0};
  2047. module_entry *me;
  2048. int fl = -1, of = 0, ocf = 0;
  2049. if (!par[0]) {
  2050. dprintf(idx, STR("Usage: chattr <handle> [changes] [channel]\n"));
  2051. return;
  2052. }
  2053. hand = newsplit(&par);
  2054. u2 = get_user_by_handle(userlist, hand);
  2055. if (!u2) {
  2056. dprintf(idx, STR("No such user!\n"));
  2057. return;
  2058. }
  2059. /* Parse args */
  2060. if (par[0]) {
  2061. arg = newsplit(&par);
  2062. if (par[0]) {
  2063. /* .chattr <handle> <changes> <channel> */
  2064. chg = arg;
  2065. arg = newsplit(&par);
  2066. chan = findchan_by_dname(arg);
  2067. } else {
  2068. chan = findchan_by_dname(arg);
  2069. /* Consider modeless channels, starting with '+' */
  2070. if (!(arg[0] == '+' && chan) &&
  2071. !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
  2072. /* .chattr <handle> <changes> */
  2073. chg = arg;
  2074. chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
  2075. arg = NULL;
  2076. }
  2077. /* .chattr <handle> <channel>: nothing to do... */
  2078. }
  2079. }
  2080. /* arg: pointer to channel name, NULL if none specified
  2081. * chan: pointer to channel structure, NULL if none found or none specified
  2082. * chg: pointer to changes, NULL if none specified
  2083. */
  2084. Assert(!(!arg && chan));
  2085. if (arg && !chan) {
  2086. dprintf(idx, STR("No channel record for %s.\n"), arg);
  2087. return;
  2088. }
  2089. if (chg) {
  2090. if (!arg && strpbrk(chg, "&|")) {
  2091. /* .chattr <handle> *[&|]*: use console channel if found... */
  2092. if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
  2093. arg = NULL;
  2094. else
  2095. chan = findchan_by_dname(arg);
  2096. if (arg && !chan) {
  2097. dprintf (idx, STR("Invalid console channel %s.\n"), arg);
  2098. return;
  2099. }
  2100. } else if (arg && !strpbrk(chg, "&|")) {
  2101. tmpchg = nmalloc(strlen(chg) + 2);
  2102. strcpy(tmpchg, "|");
  2103. strcat(tmpchg, chg);
  2104. chg = tmpchg;
  2105. }
  2106. }
  2107. par = arg;
  2108. user.match = FR_GLOBAL;
  2109. if (chan)
  2110. user.match |= FR_CHAN;
  2111. get_user_flagrec(u, &user, chan ? chan->dname : 0);
  2112. get_user_flagrec(u2, &ouser, chan ? chan->dname : 0);
  2113. if (chan && !glob_master(user) && !chan_master(user)) {
  2114. dprintf(idx, STR("You do not have channel master privileges for channel %s.\n"),
  2115. par);
  2116. if (tmpchg)
  2117. nfree(tmpchg);
  2118. return;
  2119. }
  2120. if (chan && private(user, chan, PRIV_OP)) {
  2121. dprintf(idx, STR("You do not have access to change flags for %s\n"), chan->dname);
  2122. if (tmpchg)
  2123. nfree(tmpchg);
  2124. return;
  2125. }
  2126. user.match &= fl;
  2127. if (chg) {
  2128. pls.match = user.match;
  2129. break_down_flags(chg, &pls, &mns);
  2130. /* No-one can change these flags on-the-fly */
  2131. pls.global &= ~(USER_BOT);
  2132. mns.global &= ~(USER_BOT);
  2133. if ((pls.global & USER_UPDATEHUB) && (bot_hublevel(u2) == 999)) {
  2134. dprintf(idx, STR("Only a hub can be set as the updatehub.\n"));
  2135. pls.global &= ~(USER_UPDATEHUB);
  2136. }
  2137. /* strip out +p without +i or +j */
  2138. if (((pls.global & USER_PARTY) && !(pls.global & USER_CHUBA) && !(pls.global & USER_HUBA)) && (!glob_huba(ouser) && !glob_chuba(ouser))) {
  2139. dprintf(idx, "Global flag +p requires either chathub or hub access first.\n");
  2140. pls.global &= ~USER_PARTY;
  2141. }
  2142. if (!isowner(u->handle)) {
  2143. if (pls.global & USER_HUBA)
  2144. putlog(LOG_MISC, "*", STR("%s attempted to give %s hub connect access"), dcc[idx].nick, u2->handle);
  2145. if (mns.global & USER_HUBA)
  2146. putlog(LOG_MISC, "*", STR("%s attempted to take away hub connect access from %s"), dcc[idx].nick, u2->handle);
  2147. if (pls.global & USER_UPDATEHUB)
  2148. putlog(LOG_MISC, "*", STR("%s attempted to make %s the updatehub"), dcc[idx].nick, u2->handle);
  2149. if (mns.global & USER_UPDATEHUB)
  2150. putlog(LOG_MISC, "*", STR("%s attempted to take away updatehub status from %s"), dcc[idx].nick, u2->handle);
  2151. if (pls.global & USER_ADMIN)
  2152. putlog(LOG_MISC, "*", STR("%s attempted to give %s admin access"), dcc[idx].nick, u2->handle);
  2153. if (mns.global & USER_ADMIN)
  2154. putlog(LOG_MISC, "*", STR("%s attempted to take away admin access from %s"), dcc[idx].nick, u2->handle);
  2155. if (pls.global & USER_OWNER)
  2156. putlog(LOG_MISC, "*", STR("%s attempted to give owner to %s"), dcc[idx].nick, u2->handle);
  2157. if (mns.global & USER_OWNER)
  2158. putlog(LOG_MISC, "*", STR("%s attempted to take owner away from %s"), dcc[idx].nick, u2->handle);
  2159. pls.global &=~(USER_HUBA | USER_ADMIN | USER_OWNER | USER_UPDATEHUB);
  2160. mns.global &=~(USER_HUBA | USER_ADMIN | USER_OWNER | USER_UPDATEHUB);
  2161. pls.chan &= ~(USER_ADMIN | USER_UPDATEHUB);
  2162. }
  2163. if (chan) {
  2164. pls.chan &= ~(BOT_SHARE | USER_HUBA | USER_CHUBA);
  2165. mns.chan &= ~(BOT_SHARE | USER_HUBA | USER_CHUBA);
  2166. }
  2167. if (!glob_owner(user) && !isowner(u->handle)) {
  2168. pls.global &= ~(USER_CHUBA | USER_OWNER | USER_MASTER | USER_UNSHARED);
  2169. mns.global &= ~(USER_CHUBA | USER_OWNER | USER_MASTER | USER_UNSHARED);
  2170. if (chan) {
  2171. pls.chan &= ~USER_OWNER;
  2172. mns.chan &= ~USER_OWNER;
  2173. }
  2174. }
  2175. if (chan && !chan_owner(user) && !glob_owner(user) && !isowner(u->handle)) {
  2176. pls.chan &= ~USER_MASTER;
  2177. mns.chan &= ~USER_MASTER;
  2178. if (!chan_master(user) && !glob_master(user)) {
  2179. pls.chan = 0;
  2180. mns.chan = 0;
  2181. }
  2182. }
  2183. #ifdef LEAF
  2184. pls.global &=~(USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
  2185. mns.global &=~(USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
  2186. #endif /* LEAF */
  2187. get_user_flagrec(u2, &user, par);
  2188. if (user.match & FR_GLOBAL) {
  2189. of = user.global;
  2190. user.global = sanity_check((user.global |pls.global) &~mns.global);
  2191. user.udef_global = (user.udef_global | pls.udef_global)
  2192. & ~mns.udef_global;
  2193. }
  2194. if (chan) {
  2195. ocf = user.chan;
  2196. user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
  2197. user.global);
  2198. user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
  2199. }
  2200. set_user_flagrec(u2, &user, par);
  2201. }
  2202. if (chan) {
  2203. char tmp[100];
  2204. putlog(LOG_CMDS, "*", STR("#%s# (%s) chattr %s %s"), dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
  2205. egg_snprintf(tmp, sizeof tmp, "chattr %s", chg);
  2206. update_mod(hand, dcc[idx].nick, tmp, chan->dname);
  2207. } else {
  2208. putlog(LOG_CMDS, "*", STR("#%s# chattr %s %s"), dcc[idx].nick, hand, chg ? chg : "");
  2209. update_mod(hand, dcc[idx].nick, "chattr", chg);
  2210. }
  2211. /* Get current flags and display them */
  2212. if (user.match & FR_GLOBAL) {
  2213. user.match = FR_GLOBAL;
  2214. if (chg)
  2215. check_dcc_attrs(u2, of);
  2216. get_user_flagrec(u2, &user, NULL);
  2217. build_flags(work, &user, NULL);
  2218. if (work[0] != '-')
  2219. dprintf(idx, STR("Global flags for %s are now +%s.\n"), hand, work);
  2220. else
  2221. dprintf(idx, STR("No global flags for %s.\n"), hand);
  2222. }
  2223. if (chan) {
  2224. user.match = FR_CHAN;
  2225. get_user_flagrec(u2, &user, par);
  2226. user.chan &= ~BOT_SHARE;
  2227. if (chg)
  2228. check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
  2229. build_flags(work, &user, NULL);
  2230. if (work[0] != '-')
  2231. dprintf(idx, STR("Channel flags for %s on %s are now +%s.\n"), hand,
  2232. chan->dname, work);
  2233. else
  2234. dprintf(idx, STR("No flags for %s on %s.\n"), hand, chan->dname);
  2235. }
  2236. if (chg && (me = module_find("irc", 0, 0))) {
  2237. Function *func = me->funcs;
  2238. (func[IRC_CHECK_THIS_USER]) (hand, 0, NULL);
  2239. }
  2240. if (tmpchg)
  2241. nfree(tmpchg);
  2242. #ifdef HUB
  2243. write_userfile(idx);
  2244. #endif /* HUB */
  2245. }
  2246. static void cmd_chat(struct userrec *u, int idx, char *par)
  2247. {
  2248. char *arg;
  2249. int newchan, oldchan;
  2250. module_entry *me;
  2251. if (!(u->flags & USER_PARTY)) {
  2252. dprintf(idx, STR("You don't have partyline access\n"));
  2253. return;
  2254. }
  2255. arg = newsplit(&par);
  2256. if (!egg_strcasecmp(arg, "off")) {
  2257. /* Turn chat off */
  2258. if (dcc[idx].u.chat->channel < 0) {
  2259. dprintf(idx, STR("You weren't in chat anyway!\n"));
  2260. return;
  2261. } else {
  2262. dprintf(idx, STR("Leaving chat mode...\n"));
  2263. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
  2264. dcc[idx].u.chat->channel);
  2265. chanout_but(-1, dcc[idx].u.chat->channel,
  2266. "*** %s left the party line.\n",
  2267. dcc[idx].nick);
  2268. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  2269. botnet_send_part_idx(idx, "");
  2270. }
  2271. dcc[idx].u.chat->channel = (-1);
  2272. } else {
  2273. if (arg[0] == '*') {
  2274. if (((arg[1] < '0') || (arg[1] > '9'))) {
  2275. if (!arg[1])
  2276. newchan = 0;
  2277. else {
  2278. Tcl_SetVar(interp, "chan", arg, 0);
  2279. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  2280. interp->result[0])
  2281. newchan = atoi(interp->result);
  2282. else
  2283. newchan = -1;
  2284. }
  2285. if (newchan < 0) {
  2286. dprintf(idx, STR("No channel exists by that name.\n"));
  2287. return;
  2288. }
  2289. } else
  2290. newchan = GLOBAL_CHANS + atoi(arg + 1);
  2291. if (newchan < GLOBAL_CHANS || newchan > 199999) {
  2292. dprintf(idx, STR("Channel number out of range: local channels must be *0-*99999.\n"));
  2293. return;
  2294. }
  2295. } else {
  2296. if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
  2297. if (!egg_strcasecmp(arg, "on"))
  2298. newchan = 0;
  2299. else {
  2300. Tcl_SetVar(interp, "chan", arg, 0);
  2301. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  2302. interp->result[0])
  2303. newchan = atoi(interp->result);
  2304. else
  2305. newchan = -1;
  2306. }
  2307. if (newchan < 0) {
  2308. dprintf(idx, STR("No channel exists by that name.\n"));
  2309. return;
  2310. }
  2311. } else
  2312. newchan = atoi(arg);
  2313. if ((newchan < 0) || (newchan > 99999)) {
  2314. dprintf(idx, STR("Channel number out of range: must be between 0 and 99999.\n"));
  2315. return;
  2316. }
  2317. }
  2318. /* If coming back from being off the party line, make sure they're
  2319. * not away.
  2320. */
  2321. if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
  2322. not_away(idx);
  2323. if (dcc[idx].u.chat->channel == newchan) {
  2324. if (!newchan) {
  2325. dprintf(idx, STR("You're already on the party line!\n"));
  2326. return;
  2327. } else {
  2328. dprintf(idx, STR("You're already on channel %s%d!\n"),
  2329. (newchan < GLOBAL_CHANS) ? "" : "*", newchan % GLOBAL_CHANS);
  2330. return;
  2331. }
  2332. } else {
  2333. oldchan = dcc[idx].u.chat->channel;
  2334. if (oldchan >= 0)
  2335. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
  2336. if (!oldchan) {
  2337. chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
  2338. } else if (oldchan > 0) {
  2339. chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
  2340. }
  2341. dcc[idx].u.chat->channel = newchan;
  2342. if (!newchan) {
  2343. dprintf(idx, STR("Entering the party line...\n"));
  2344. chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
  2345. } else {
  2346. dprintf(idx, STR("Joining channel '%s'...\n"), arg);
  2347. chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
  2348. }
  2349. check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
  2350. dcc[idx].sock, dcc[idx].host);
  2351. if (newchan < GLOBAL_CHANS)
  2352. botnet_send_join_idx(idx, oldchan);
  2353. else if (oldchan < GLOBAL_CHANS)
  2354. botnet_send_part_idx(idx, "");
  2355. }
  2356. }
  2357. /* New style autosave here too -- rtc, 09/28/1999*/
  2358. if ((me = module_find("console", 0, 0))) {
  2359. Function *func = me->funcs;
  2360. (func[CONSOLE_DOSTORE]) (idx);
  2361. }
  2362. }
  2363. int exec_str(int idx, char *cmd) {
  2364. char *out, *err, *p, *np;
  2365. if (shell_exec(cmd, NULL, &out, &err)) {
  2366. if (out) {
  2367. dprintf(idx, STR("Result:\n"));
  2368. p=out;
  2369. while (p && p[0]) {
  2370. np=strchr(p, '\n');
  2371. if (np)
  2372. *np++=0;
  2373. dprintf(idx, STR("%s\n"), p);
  2374. p=np;
  2375. }
  2376. dprintf(idx, "\n");
  2377. nfree(out);
  2378. }
  2379. if (err) {
  2380. dprintf(idx, STR("Errors:\n"));
  2381. p=err;
  2382. while (p && p[0]) {
  2383. np=strchr(p, '\n');
  2384. if (np)
  2385. *np++=0;
  2386. dprintf(idx, STR("%s\n"), p);
  2387. p=np;
  2388. }
  2389. dprintf(idx, "\n");
  2390. nfree(err);
  2391. }
  2392. return 1;
  2393. }
  2394. return 0;
  2395. }
  2396. static void cmd_exec(struct userrec *u, int idx, char *par) {
  2397. putlog(LOG_CMDS, "*", STR("#%s# exec %s"), dcc[idx].nick, par);
  2398. #ifdef LEAF
  2399. if (!isowner(u->handle)) {
  2400. putlog(LOG_WARN, "*", STR("%s attempted 'exec' %s"), dcc[idx].nick, par);
  2401. dprintf(idx, STR("exec is only available to permanent owners on leaf bots\n"));
  2402. return;
  2403. }
  2404. #endif /* LEAF */
  2405. if (exec_str(idx, par))
  2406. dprintf(idx, STR("Exec completed\n"));
  2407. else
  2408. dprintf(idx, STR("Exec failed\n"));
  2409. }
  2410. static void cmd_w(struct userrec *u, int idx, char *par) {
  2411. putlog(LOG_CMDS, "*", STR("#%s# w"), dcc[idx].nick);
  2412. if (!exec_str(idx, "w"))
  2413. dprintf(idx, STR("Exec failed\n"));
  2414. }
  2415. static void cmd_ps(struct userrec *u, int idx, char *par) {
  2416. char * buf;
  2417. putlog(LOG_CMDS, "*", STR("#%s# ps %s"), dcc[idx].nick, par);
  2418. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  2419. putlog(LOG_WARN, "*", STR("%s attempted 'ps' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  2420. dprintf(idx, STR("No."));
  2421. return;
  2422. }
  2423. buf=nmalloc(strlen(par)+4);
  2424. sprintf(buf, STR("ps %s"), par);
  2425. if (!exec_str(idx, buf))
  2426. dprintf(idx, STR("Exec failed\n"));
  2427. nfree(buf);
  2428. }
  2429. static void cmd_last(struct userrec *u, int idx, char *par) {
  2430. char user[20], buf[30];
  2431. struct passwd *pw;
  2432. putlog(LOG_CMDS, "*", STR("#%s# last %s"), dcc[idx].nick, par);
  2433. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  2434. putlog(LOG_WARN, "*", STR("%s attempted 'last' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  2435. dprintf(idx, STR("No."));
  2436. return;
  2437. }
  2438. if (par[0]) {
  2439. strncpyz(user, par, sizeof(user));
  2440. } else {
  2441. pw = getpwuid(geteuid());
  2442. if (!pw)
  2443. return;
  2444. strncpyz(user, pw->pw_name, sizeof(user));
  2445. }
  2446. if (!user[0]) {
  2447. dprintf(idx, STR("Can't determine user id for process\n"));
  2448. return;
  2449. }
  2450. sprintf(buf, STR("last %s"), user);
  2451. if (!exec_str(idx, buf))
  2452. dprintf(idx, STR("Failed to execute /bin/sh last\n"));
  2453. }
  2454. static void cmd_echo(struct userrec *u, int idx, char *par)
  2455. {
  2456. module_entry *me;
  2457. if (!par[0]) {
  2458. dprintf(idx, STR("Echo is currently %s.\n"), dcc[idx].status & STAT_ECHO ?
  2459. "on" : "off");
  2460. return;
  2461. }
  2462. if (!egg_strcasecmp(par, "on")) {
  2463. dprintf(idx, STR("Echo turned on.\n"));
  2464. dcc[idx].status |= STAT_ECHO;
  2465. } else if (!egg_strcasecmp(par, "off")) {
  2466. dprintf(idx, STR("Echo turned off.\n"));
  2467. dcc[idx].status &= ~STAT_ECHO;
  2468. } else {
  2469. dprintf(idx, STR("Usage: echo <on/off>\n"));
  2470. return;
  2471. }
  2472. /* New style autosave here too -- rtc, 09/28/1999*/
  2473. if ((me = module_find("console", 0, 0))) {
  2474. Function *func = me->funcs;
  2475. (func[CONSOLE_DOSTORE]) (idx);
  2476. }
  2477. }
  2478. static void cmd_color(struct userrec *u, int idx, char *par)
  2479. {
  2480. module_entry *me;
  2481. char *of;
  2482. putlog(LOG_CMDS, "*", STR("#%s# color %s"), dcc[idx].nick, par);
  2483. if (!par[0]) {
  2484. dprintf(idx, STR("Usage: color <on/off>\n"));
  2485. if (dcc[idx].status & STAT_COLOR)
  2486. dprintf(idx, STR("Color is currently on.\n"));
  2487. else
  2488. dprintf(idx, STR("Color is currently off.\n"));
  2489. return;
  2490. }
  2491. of = newsplit(&par);
  2492. if (!egg_strcasecmp(of, "on")) {
  2493. dcc[idx].status |= STAT_COLOR;
  2494. } else if (!egg_strcasecmp(of, "off")) {
  2495. dcc[idx].status &= ~(STAT_COLOR);
  2496. dprintf(idx, STR("Color turned off.\n"));
  2497. } else {
  2498. return;
  2499. }
  2500. if ((me = module_find("console", 0, 0))) {
  2501. Function *func = me->funcs;
  2502. (func[CONSOLE_DOSTORE]) (idx);
  2503. }
  2504. }
  2505. int stripmodes(char *s)
  2506. {
  2507. int res = 0;
  2508. for (; *s; s++)
  2509. switch (tolower(*s)) {
  2510. case 'b':
  2511. res |= STRIP_BOLD;
  2512. break;
  2513. case 'c':
  2514. res |= STRIP_COLOR;
  2515. break;
  2516. case 'r':
  2517. res |= STRIP_REV;
  2518. break;
  2519. case 'u':
  2520. res |= STRIP_UNDER;
  2521. break;
  2522. case 'a':
  2523. res |= STRIP_ANSI;
  2524. break;
  2525. case 'g':
  2526. res |= STRIP_BELLS;
  2527. break;
  2528. case '*':
  2529. res |= STRIP_ALL;
  2530. break;
  2531. }
  2532. return res;
  2533. }
  2534. char *stripmasktype(int x)
  2535. {
  2536. static char s[20];
  2537. char *p = s;
  2538. if (x & STRIP_BOLD)
  2539. *p++ = 'b';
  2540. if (x & STRIP_COLOR)
  2541. *p++ = 'c';
  2542. if (x & STRIP_REV)
  2543. *p++ = 'r';
  2544. if (x & STRIP_UNDER)
  2545. *p++ = 'u';
  2546. if (x & STRIP_ANSI)
  2547. *p++ = 'a';
  2548. if (x & STRIP_BELLS)
  2549. *p++ = 'g';
  2550. if (p == s)
  2551. *p++ = '-';
  2552. *p = 0;
  2553. return s;
  2554. }
  2555. static char *stripmaskname(int x)
  2556. {
  2557. static char s[161];
  2558. int i = 0;
  2559. s[i] = 0;
  2560. if (x & STRIP_BOLD)
  2561. i += my_strcpy(s + i, "bold, ");
  2562. if (x & STRIP_COLOR)
  2563. i += my_strcpy(s + i, "color, ");
  2564. if (x & STRIP_REV)
  2565. i += my_strcpy(s + i, "reverse, ");
  2566. if (x & STRIP_UNDER)
  2567. i += my_strcpy(s + i, "underline, ");
  2568. if (x & STRIP_ANSI)
  2569. i += my_strcpy(s + i, "ansi, ");
  2570. if (x & STRIP_BELLS)
  2571. i += my_strcpy(s + i, "bells, ");
  2572. if (!i)
  2573. strcpy(s, "none");
  2574. else
  2575. s[i - 2] = 0;
  2576. return s;
  2577. }
  2578. static void cmd_strip(struct userrec *u, int idx, char *par)
  2579. {
  2580. char *nick, *changes, *c, s[2];
  2581. int dest = 0, i, pls, md, ok = 0;
  2582. module_entry *me;
  2583. if (!par[0]) {
  2584. dprintf(idx, STR("Your current strip settings are: %s (%s).\n"),
  2585. stripmasktype(dcc[idx].u.chat->strip_flags),
  2586. stripmaskname(dcc[idx].u.chat->strip_flags));
  2587. return;
  2588. }
  2589. nick = newsplit(&par);
  2590. if ((nick[0] != '+') && (nick[0] != '-') && u &&
  2591. (u->flags & USER_MASTER)) {
  2592. for (i = 0; i < dcc_total; i++)
  2593. if (!egg_strcasecmp(nick, dcc[i].nick) && dcc[i].type == &DCC_CHAT &&
  2594. !ok) {
  2595. ok = 1;
  2596. dest = i;
  2597. }
  2598. if (!ok) {
  2599. dprintf(idx, STR("No such user on the party line!\n"));
  2600. return;
  2601. }
  2602. changes = par;
  2603. } else {
  2604. changes = nick;
  2605. nick = "";
  2606. dest = idx;
  2607. }
  2608. c = changes;
  2609. if ((c[0] != '+') && (c[0] != '-'))
  2610. dcc[dest].u.chat->strip_flags = 0;
  2611. s[1] = 0;
  2612. for (pls = 1; *c; c++) {
  2613. switch (*c) {
  2614. case '+':
  2615. pls = 1;
  2616. break;
  2617. case '-':
  2618. pls = 0;
  2619. break;
  2620. default:
  2621. s[0] = *c;
  2622. md = stripmodes(s);
  2623. if (pls == 1)
  2624. dcc[dest].u.chat->strip_flags |= md;
  2625. else
  2626. dcc[dest].u.chat->strip_flags &= ~md;
  2627. }
  2628. }
  2629. if (nick[0])
  2630. putlog(LOG_CMDS, "*", STR("#%s# strip %s %s"), dcc[idx].nick, nick, changes);
  2631. else
  2632. putlog(LOG_CMDS, "*", STR("#%s# strip %s"), dcc[idx].nick, changes);
  2633. if (dest == idx) {
  2634. dprintf(idx, STR("Your strip settings are: %s (%s).\n"),
  2635. stripmasktype(dcc[idx].u.chat->strip_flags),
  2636. stripmaskname(dcc[idx].u.chat->strip_flags));
  2637. } else {
  2638. dprintf(idx, STR("Strip setting for %s: %s (%s).\n"), dcc[dest].nick,
  2639. stripmasktype(dcc[dest].u.chat->strip_flags),
  2640. stripmaskname(dcc[dest].u.chat->strip_flags));
  2641. dprintf(dest, STR("%s set your strip settings to: %s (%s).\n"), dcc[idx].nick,
  2642. stripmasktype(dcc[dest].u.chat->strip_flags),
  2643. stripmaskname(dcc[dest].u.chat->strip_flags));
  2644. }
  2645. /* Set highlight flag here so user is able to control stripping of
  2646. * bold also as intended -- dw 27/12/1999
  2647. */
  2648. /* New style autosave here too -- rtc, 09/28/1999*/
  2649. if ((me = module_find("console", 0, 0))) {
  2650. Function *func = me->funcs;
  2651. (func[CONSOLE_DOSTORE]) (dest);
  2652. }
  2653. }
  2654. static void cmd_su(struct userrec *u, int idx, char *par)
  2655. {
  2656. int atr = u ? u->flags : 0;
  2657. int ok;
  2658. struct flag_record fr = {FR_ANYWH | FR_CHAN | FR_GLOBAL, 0, 0, 0, 0, 0};
  2659. u = get_user_by_handle(userlist, par);
  2660. if (!par[0])
  2661. dprintf(idx, STR("Usage: su <user>\n"));
  2662. else if (!u)
  2663. dprintf(idx, STR("No such user.\n"));
  2664. else if (u->flags & USER_BOT)
  2665. dprintf(idx, STR("You can't su to a bot... then again, why would you wanna?\n"));
  2666. else if (dcc[idx].u.chat->su_nick)
  2667. dprintf(idx, STR("You cannot currently double .su; try .su'ing directly.\n"));
  2668. else {
  2669. get_user_flagrec(u, &fr, NULL);
  2670. ok = 1;
  2671. #ifdef HUB
  2672. if (!glob_huba(fr))
  2673. ok = 0;
  2674. #else /* !HUB */
  2675. if (ischanhub() && !glob_chuba(fr))
  2676. ok = 0;
  2677. #endif /* LEAF */
  2678. if (!ok)
  2679. dprintf(idx, STR("No party line access permitted for %s.\n"), par);
  2680. else {
  2681. correct_handle(par);
  2682. putlog(LOG_CMDS, "*", STR("#%s# su %s"), dcc[idx].nick, par);
  2683. if (!(atr & USER_OWNER) ||
  2684. ((u->flags & USER_OWNER) && (isowner(par)) &&
  2685. !(isowner(dcc[idx].nick)))) {
  2686. /* This check is only important for non-owners */
  2687. if (u_pass_match(u, "-")) {
  2688. dprintf(idx, STR("No password set for user. You may not .su to them.\n"));
  2689. return;
  2690. }
  2691. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  2692. botnet_send_part_idx(idx, "");
  2693. chanout_but(-1, dcc[idx].u.chat->channel,
  2694. "*** %s left the party line.\n", dcc[idx].nick);
  2695. /* Store the old nick in the away section, for weenies who can't get
  2696. * their password right ;)
  2697. */
  2698. if (dcc[idx].u.chat->away != NULL)
  2699. nfree(dcc[idx].u.chat->away);
  2700. dcc[idx].u.chat->away = get_data_ptr(strlen(dcc[idx].nick) + 1);
  2701. strcpy(dcc[idx].u.chat->away, dcc[idx].nick);
  2702. dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
  2703. strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
  2704. dcc[idx].user = u;
  2705. strcpy(dcc[idx].nick, par);
  2706. /* Display password prompt and turn off echo (send IAC WILL ECHO). */
  2707. dprintf(idx, STR("Enter password for %s%s\n"), par,
  2708. (dcc[idx].status & STAT_TELNET) ? TLN_IAC_C TLN_WILL_C
  2709. TLN_ECHO_C : "");
  2710. dcc[idx].type = &DCC_CHAT_PASS;
  2711. } else if (atr & USER_OWNER) {
  2712. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  2713. botnet_send_part_idx(idx, "");
  2714. chanout_but(-1, dcc[idx].u.chat->channel,
  2715. "*** %s left the party line.\n", dcc[idx].nick);
  2716. dprintf(idx, STR("Setting your username to %s.\n"), par);
  2717. if (atr & USER_MASTER)
  2718. dcc[idx].u.chat->con_flags = conmask;
  2719. dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
  2720. strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
  2721. dcc[idx].user = u;
  2722. strcpy(dcc[idx].nick, par);
  2723. dcc_chatter(idx);
  2724. }
  2725. }
  2726. }
  2727. }
  2728. static void cmd_fixcodes(struct userrec *u, int idx, char *par)
  2729. {
  2730. if (dcc[idx].status & STAT_TELNET) {
  2731. dcc[idx].status |= STAT_ECHO;
  2732. dcc[idx].status &= ~STAT_TELNET;
  2733. dprintf(idx, STR("Turned off telnet codes.\n"));
  2734. putlog(LOG_CMDS, "*", STR("#%s# fixcodes (telnet off)"), dcc[idx].nick);
  2735. } else {
  2736. dcc[idx].status |= STAT_TELNET;
  2737. dcc[idx].status &= ~STAT_ECHO;
  2738. dprintf(idx, STR("Turned on telnet codes.\n"));
  2739. putlog(LOG_CMDS, "*", STR("#%s# fixcodes (telnet on)"), dcc[idx].nick);
  2740. }
  2741. }
  2742. static void cmd_page(struct userrec *u, int idx, char *par)
  2743. {
  2744. int a;
  2745. module_entry *me;
  2746. if (!par[0]) {
  2747. if (dcc[idx].status & STAT_PAGE) {
  2748. dprintf(idx, STR("Currently paging outputs to %d lines.\n"),
  2749. dcc[idx].u.chat->max_line);
  2750. } else
  2751. dprintf(idx, STR("You don't have paging on.\n"));
  2752. return;
  2753. }
  2754. a = atoi(par);
  2755. if ((!a && !par[0]) || !egg_strcasecmp(par, "off")) {
  2756. dcc[idx].status &= ~STAT_PAGE;
  2757. dcc[idx].u.chat->max_line = 0x7ffffff; /* flush_lines needs this */
  2758. while (dcc[idx].u.chat->buffer)
  2759. flush_lines(idx, dcc[idx].u.chat);
  2760. dprintf(idx, STR("Paging turned off.\n"));
  2761. putlog(LOG_CMDS, "*", STR("#%s# page off"), dcc[idx].nick);
  2762. } else if (a > 0) {
  2763. dprintf(idx, STR("Paging turned on, stopping every %d line%s.\n"), a,
  2764. (a != 1) ? "s" : "");
  2765. dcc[idx].status |= STAT_PAGE;
  2766. dcc[idx].u.chat->max_line = a;
  2767. dcc[idx].u.chat->line_count = 0;
  2768. dcc[idx].u.chat->current_lines = 0;
  2769. putlog(LOG_CMDS, "*", STR("#%s# page %d"), dcc[idx].nick, a);
  2770. } else {
  2771. dprintf(idx, STR("Usage: page <off or #>\n"));
  2772. return;
  2773. }
  2774. /* New style autosave here too -- rtc, 09/28/1999*/
  2775. if ((me = module_find("console", 0, 0))) {
  2776. Function *func = me->funcs;
  2777. (func[CONSOLE_DOSTORE]) (idx);
  2778. }
  2779. }
  2780. /* Evaluate a Tcl command, send output to a dcc user.
  2781. */
  2782. #ifdef S_TCLCMDS
  2783. static void cmd_tcl(struct userrec *u, int idx, char *msg)
  2784. {
  2785. int code;
  2786. #ifdef S_PERMONLY
  2787. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2788. dprintf(idx, STR("What? You need '%shelp'\n"), dcc_prefix);
  2789. return;
  2790. }
  2791. #endif /* S_PERMONLY */
  2792. putlog(LOG_CMDS, "*", STR("#%s# tcl %s"), dcc[idx].nick, msg);
  2793. debug1(STR("tcl: evaluate (.tcl): %s"), msg);
  2794. code = Tcl_GlobalEval(interp, msg);
  2795. if (code == TCL_OK)
  2796. dumplots(idx, STR("Tcl: "), interp->result);
  2797. else
  2798. dumplots(idx, STR("Tcl error: "), interp->result);
  2799. }
  2800. #endif /* S_TCLCMDS */
  2801. #ifdef HUB
  2802. #ifdef S_TCLCMDS
  2803. static void cmd_nettcl(struct userrec *u, int idx, char *msg)
  2804. {
  2805. int code;
  2806. char buf[2000];
  2807. #ifdef S_PERMONLY
  2808. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2809. dprintf(idx, STR("What? You need '%shelp'\n"), dcc_prefix);
  2810. return;
  2811. }
  2812. #endif /* S_PERMONLY */
  2813. putlog(LOG_CMDS, "*", STR("#%s# nettcl %s"), dcc[idx].nick, msg);
  2814. egg_snprintf(buf, sizeof buf, "mt %d %s", idx, msg);
  2815. putallbots(buf);
  2816. debug1(STR("tcl: evaluate (.tcl): %s"), msg);
  2817. code = Tcl_GlobalEval(interp, msg);
  2818. if (code == TCL_OK)
  2819. dumplots(idx, STR("Tcl: "), interp->result);
  2820. else
  2821. dumplots(idx, STR("Tcl error: "), interp->result);
  2822. }
  2823. #endif /* S_TCLCMDS */
  2824. static void cmd_newleaf(struct userrec *u, int idx, char *par)
  2825. {
  2826. char *handle,
  2827. *host;
  2828. struct userrec *u1;
  2829. struct bot_addr *bi;
  2830. putlog(LOG_CMDS, "*", STR("#%s# newleaf %s"), dcc[idx].nick, par);
  2831. if (!par[0]) {
  2832. dprintf(idx, STR("Usage: newleaf <handle> [host] [anotherhost]\n"));
  2833. dprintf(idx, STR(" Leafs can't link unless you specify a *!ident@ip hostmask\n"));
  2834. } else {
  2835. handle = newsplit(&par);
  2836. if (strlen(handle) > HANDLEN)
  2837. handle[HANDLEN] = 0;
  2838. if (get_user_by_handle(userlist, handle))
  2839. dprintf(idx, STR("Already got a %s user/bot\n"), handle);
  2840. else if (strchr(BADHANDCHARS, handle[0]) != NULL)
  2841. dprintf(idx, STR("You can't start a botnick with '%c'.\n"), handle[0]);
  2842. else {
  2843. char tmp[81];
  2844. userlist = adduser(userlist, handle, STR("none"), "-", USER_BOT | USER_OP);
  2845. u1 = get_user_by_handle(userlist, handle);
  2846. bi = user_malloc(sizeof(struct bot_addr));
  2847. bi->uplink = user_malloc(strlen(botnetnick) + 1);
  2848. /* strcpy(bi->uplink, botnetnick); */
  2849. strcpy(bi->uplink, "");
  2850. bi->address = user_malloc(1);
  2851. bi->address[0] = 0;
  2852. bi->telnet_port = 3333;
  2853. bi->relay_port = 3333;
  2854. bi->hublevel = 0;
  2855. set_user(&USERENTRY_BOTADDR, u1, bi);
  2856. host = newsplit(&par);
  2857. while ((host) && (host[0])) {
  2858. addhost_by_handle(handle, host);
  2859. host = newsplit(&par);
  2860. }
  2861. /* set_user(&USERENTRY_PASS, u1, SALT2); */
  2862. sprintf(tmp, STR("%lu %s"), time(NULL), u->handle);
  2863. set_user(&USERENTRY_ADDED, u1, tmp);
  2864. dprintf(idx, STR("Added new leaf: %s\n"), handle);
  2865. #ifdef HUB
  2866. write_userfile(idx);
  2867. #endif /* HUB */
  2868. }
  2869. }
  2870. }
  2871. #endif /* HUB */
  2872. static void cmd_pls_ignore(struct userrec *u, int idx, char *par)
  2873. {
  2874. char *who;
  2875. char s[UHOSTLEN];
  2876. unsigned long int expire_time = 0;
  2877. if (!par[0]) {
  2878. dprintf(idx, STR("Usage: +ignore <hostmask> [%%<XdXhXm>] [comment]\n"));
  2879. return;
  2880. }
  2881. who = newsplit(&par);
  2882. if (par[0] == '%') {
  2883. char *p, *p_expire;
  2884. unsigned long int expire_foo;
  2885. p = newsplit(&par);
  2886. p_expire = p + 1;
  2887. while (*(++p) != 0) {
  2888. switch (tolower(*p)) {
  2889. case 'd':
  2890. *p = 0;
  2891. expire_foo = strtol(p_expire, NULL, 10);
  2892. if (expire_foo > 365)
  2893. expire_foo = 365;
  2894. expire_time += 86400 * expire_foo;
  2895. p_expire = p + 1;
  2896. break;
  2897. case 'h':
  2898. *p = 0;
  2899. expire_foo = strtol(p_expire, NULL, 10);
  2900. if (expire_foo > 8760)
  2901. expire_foo = 8760;
  2902. expire_time += 3600 * expire_foo;
  2903. p_expire = p + 1;
  2904. break;
  2905. case 'm':
  2906. *p = 0;
  2907. expire_foo = strtol(p_expire, NULL, 10);
  2908. if (expire_foo > 525600)
  2909. expire_foo = 525600;
  2910. expire_time += 60 * expire_foo;
  2911. p_expire = p + 1;
  2912. }
  2913. }
  2914. }
  2915. if (!par[0])
  2916. par = "requested";
  2917. else if (strlen(par) > 65)
  2918. par[65] = 0;
  2919. if (strlen(who) > UHOSTMAX - 4)
  2920. who[UHOSTMAX - 4] = 0;
  2921. /* Fix missing ! or @ BEFORE continuing */
  2922. if (!strchr(who, '!')) {
  2923. if (!strchr(who, '@'))
  2924. simple_sprintf(s, "%s!*@*", who);
  2925. else
  2926. simple_sprintf(s, "*!%s", who);
  2927. } else if (!strchr(who, '@'))
  2928. simple_sprintf(s, "%s@*", who);
  2929. else
  2930. strcpy(s, who);
  2931. if (match_ignore(s))
  2932. dprintf(idx, STR("That already matches an existing ignore.\n"));
  2933. else {
  2934. dprintf(idx, STR("Now ignoring: %s (%s)\n"), s, par);
  2935. addignore(s, dcc[idx].nick, par, expire_time ? now + expire_time : 0L);
  2936. putlog(LOG_CMDS, "*", STR("#%s# +ignore %s %s"), dcc[idx].nick, s, par);
  2937. #ifdef HUB
  2938. write_userfile(idx);
  2939. #endif /* HUB */
  2940. }
  2941. }
  2942. static void cmd_mns_ignore(struct userrec *u, int idx, char *par)
  2943. {
  2944. char buf[UHOSTLEN];
  2945. if (!par[0]) {
  2946. dprintf(idx, STR("Usage: -ignore <hostmask | ignore #>\n"));
  2947. return;
  2948. }
  2949. strncpyz(buf, par, sizeof buf);
  2950. if (delignore(buf)) {
  2951. putlog(LOG_CMDS, "*", STR("#%s# -ignore %s"), dcc[idx].nick, buf);
  2952. dprintf(idx, STR("No longer ignoring: %s\n"), buf);
  2953. #ifdef HUB
  2954. write_userfile(idx);
  2955. #endif /* HUB */
  2956. } else
  2957. dprintf(idx, STR("That ignore cannot be found.\n"));
  2958. }
  2959. static void cmd_ignores(struct userrec *u, int idx, char *par)
  2960. {
  2961. putlog(LOG_CMDS, "*", STR("#%s# ignores %s"), dcc[idx].nick, par);
  2962. tell_ignores(idx, par);
  2963. }
  2964. static void cmd_pls_user(struct userrec *u, int idx, char *par)
  2965. {
  2966. char *handle, *host;
  2967. putlog(LOG_CMDS, "*", STR("#%s# +user %s"), dcc[idx].nick, par);
  2968. if (!par[0]) {
  2969. dprintf(idx, STR("Usage: +user <handle> [hostmask]\n"));
  2970. return;
  2971. }
  2972. handle = newsplit(&par);
  2973. host = newsplit(&par);
  2974. if (strlen(handle) > HANDLEN)
  2975. handle[HANDLEN] = 0;
  2976. if (get_user_by_handle(userlist, handle))
  2977. dprintf(idx, STR("Someone already exists by that name.\n"));
  2978. else if (strchr(BADNICKCHARS, handle[0]) != NULL)
  2979. dprintf(idx, STR("You can't start a nick with '%c'.\n"), handle[0]);
  2980. else if (!egg_strcasecmp(handle, botnetnick))
  2981. dprintf(idx, STR("Hey! That's MY name!\n"));
  2982. else {
  2983. struct userrec *u2;
  2984. char tmp[50], s[16], s2[17];
  2985. userlist = adduser(userlist, handle, host, "-", USER_DEFAULT);
  2986. u2 = get_user_by_handle(userlist, handle);
  2987. sprintf(tmp, STR("%lu %s"), time(NULL), u->handle);
  2988. set_user(&USERENTRY_ADDED, u2, tmp);
  2989. dprintf(idx, STR("Added %s (%s) with no flags.\n"), handle, host);
  2990. while (par[0]) {
  2991. host=newsplit(&par);
  2992. set_user(&USERENTRY_HOSTS, u2, host);
  2993. dprintf(idx, STR("Added host %s to %s.\n"), host, handle);
  2994. }
  2995. make_rand_str(s, 15);
  2996. set_user(&USERENTRY_PASS, u2, s);
  2997. make_rand_str(s2, 16);
  2998. set_user(&USERENTRY_SECPASS, u2, s2);
  2999. dprintf(idx, STR("%s's initial password set to \002%s\002\n"), handle, s);
  3000. dprintf(idx, STR("%s's initial secpass set to \002%s\002\n"), handle, s2);
  3001. #ifdef HUB
  3002. write_userfile(idx);
  3003. #endif /* HUB */
  3004. }
  3005. }
  3006. static void cmd_mns_user(struct userrec *u, int idx, char *par)
  3007. {
  3008. int idx2;
  3009. char *handle;
  3010. struct userrec *u2;
  3011. module_entry *me;
  3012. putlog(LOG_CMDS, "*", STR("#%s# -user %s"), dcc[idx].nick, par);
  3013. if (!par[0]) {
  3014. dprintf(idx, STR("Usage: -user <hand>\n"));
  3015. return;
  3016. }
  3017. handle = newsplit(&par);
  3018. u2 = get_user_by_handle(userlist, handle);
  3019. if (!u2 || !u) {
  3020. dprintf(idx, STR("No such user!\n"));
  3021. return;
  3022. }
  3023. if (isowner(u2->handle)) {
  3024. dprintf(idx, STR("You can't remove a permanent bot owner!\n"));
  3025. return;
  3026. }
  3027. if ((u2->flags & USER_ADMIN) && !(isowner(u->handle))) {
  3028. dprintf(idx, STR("You can't remove an admin!\n"));
  3029. return;
  3030. }
  3031. if ((u2->flags & USER_OWNER) && !(u->flags & USER_OWNER)) {
  3032. dprintf(idx, STR("You can't remove a bot owner!\n"));
  3033. return;
  3034. }
  3035. if (u2->flags & USER_BOT) {
  3036. if ((bot_flags(u2) & BOT_SHARE) && !(u->flags & USER_OWNER)) {
  3037. dprintf(idx, STR("You can't remove share bots.\n"));
  3038. return;
  3039. }
  3040. for (idx2 = 0; idx2 < dcc_total; idx2++)
  3041. if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
  3042. !egg_strcasecmp(dcc[idx2].nick, handle))
  3043. break;
  3044. if (idx2 != dcc_total) {
  3045. dprintf(idx, STR("You can't remove a directly linked bot.\n"));
  3046. return;
  3047. }
  3048. }
  3049. if (!(u->flags & USER_MASTER) &&
  3050. !(u2->flags & USER_BOT)) {
  3051. dprintf(idx, STR("You can't remove users who aren't bots!\n"));
  3052. return;
  3053. }
  3054. if ((me = module_find("irc", 0, 0))) {
  3055. Function *func = me->funcs;
  3056. (func[IRC_CHECK_THIS_USER]) (handle, 1, NULL);
  3057. }
  3058. if (deluser(handle)) {
  3059. dprintf(idx, STR("Deleted %s.\n"), handle);
  3060. #ifdef HUB
  3061. write_userfile(idx);
  3062. #endif /* HUB */
  3063. } else
  3064. dprintf(idx, STR("Failed.\n"));
  3065. }
  3066. static void cmd_pls_host(struct userrec *u, int idx, char *par)
  3067. {
  3068. char *handle, *host;
  3069. struct userrec *u2;
  3070. struct list_type *q;
  3071. struct flag_record fr2 = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0},
  3072. fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  3073. module_entry *me;
  3074. putlog(LOG_CMDS, "*", STR("#%s# +host %s"), dcc[idx].nick, par);
  3075. if (!par[0]) {
  3076. dprintf(idx, STR("Usage: +host [handle] <newhostmask>\n"));
  3077. return;
  3078. }
  3079. handle = newsplit(&par);
  3080. if (par[0]) {
  3081. host = newsplit(&par);
  3082. u2 = get_user_by_handle(userlist, handle);
  3083. } else {
  3084. host = handle;
  3085. handle = dcc[idx].nick;
  3086. u2 = u;
  3087. }
  3088. if (!u2 || !u) {
  3089. dprintf(idx, STR("No such user.\n"));
  3090. return;
  3091. }
  3092. get_user_flagrec(u, &fr, NULL);
  3093. if (egg_strcasecmp(handle, dcc[idx].nick)) {
  3094. get_user_flagrec(u2, &fr2, NULL);
  3095. if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
  3096. dprintf(idx, STR("You can't add hostmasks to non-bots.\n"));
  3097. return;
  3098. }
  3099. if (!glob_owner(fr) && glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE)) {
  3100. dprintf(idx, STR("You can't add hostmasks to share bots.\n"));
  3101. return;
  3102. }
  3103. if (glob_admin(fr2) && !isowner(u->handle)) {
  3104. dprintf(idx, STR("You can't add hostmasks to an admin.\n"));
  3105. return;
  3106. }
  3107. if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
  3108. dprintf(idx, STR("You can't add hostmasks to a bot owner/master.\n"));
  3109. return;
  3110. }
  3111. if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
  3112. !glob_owner(fr) && !chan_owner(fr)) {
  3113. dprintf(idx, STR("You can't add hostmasks to a channel owner/master.\n"));
  3114. return;
  3115. }
  3116. if (!glob_master(fr) && !chan_master(fr)) {
  3117. dprintf(idx, STR("Permission denied.\n"));
  3118. return;
  3119. }
  3120. }
  3121. if (!chan_master(fr) && get_user_by_host(host)) {
  3122. dprintf(idx, STR("You cannot add a host matching another user!\n"));
  3123. return;
  3124. }
  3125. for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next)
  3126. if (!egg_strcasecmp(q->extra, host)) {
  3127. dprintf(idx, STR("That hostmask is already there.\n"));
  3128. return;
  3129. }
  3130. addhost_by_handle(handle, host);
  3131. update_mod(handle, dcc[idx].nick, "+host", host);
  3132. dprintf(idx, STR("Added '%s' to %s.\n"), host, handle);
  3133. if ((me = module_find("irc", 0, 0))) {
  3134. Function *func = me->funcs;
  3135. (func[IRC_CHECK_THIS_USER]) (handle, 0, NULL);
  3136. }
  3137. #ifdef HUB
  3138. write_userfile(idx);
  3139. #endif /* HUB */
  3140. }
  3141. static void cmd_mns_host(struct userrec *u, int idx, char *par)
  3142. {
  3143. char *handle, *host;
  3144. struct userrec *u2;
  3145. struct flag_record fr2 = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0},
  3146. fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  3147. module_entry *me;
  3148. putlog(LOG_CMDS, "*", STR("#%s# -host %s"), dcc[idx].nick, par);
  3149. if (!par[0]) {
  3150. dprintf(idx, STR("Usage: -host [handle] <hostmask>\n"));
  3151. return;
  3152. }
  3153. handle = newsplit(&par);
  3154. if (par[0]) {
  3155. host = newsplit(&par);
  3156. u2 = get_user_by_handle(userlist, handle);
  3157. } else {
  3158. host = handle;
  3159. handle = dcc[idx].nick;
  3160. u2 = u;
  3161. }
  3162. if (!u2 || !u) {
  3163. dprintf(idx, STR("No such user.\n"));
  3164. return;
  3165. }
  3166. get_user_flagrec(u, &fr, NULL);
  3167. get_user_flagrec(u2, &fr2, NULL);
  3168. /* check to see if user is +d or +k and don't let them remove hosts */
  3169. if (glob_deop(fr) || glob_kick(fr) || chan_deop(fr) || chan_kick (fr)) {
  3170. dprintf(idx, STR("You can't remove hostmasks while having the +d or +k flag.\n"));
  3171. return;
  3172. }
  3173. if (egg_strcasecmp(handle, dcc[idx].nick)) {
  3174. if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
  3175. dprintf(idx, STR("You can't remove hostmasks from non-bots.\n"));
  3176. return;
  3177. }
  3178. if (glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE) && !glob_owner(fr)) {
  3179. dprintf(idx, STR("You can't remove hostmasks from a share bot.\n"));
  3180. return;
  3181. }
  3182. if (glob_admin(fr2) && !isowner(u->handle)) {
  3183. dprintf(idx, STR("You can't remove hostmasks from an admin.\n"));
  3184. return;
  3185. }
  3186. if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
  3187. dprintf(idx, STR("You can't remove hostmasks from a bot owner/master.\n"));
  3188. return;
  3189. }
  3190. if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
  3191. !glob_owner(fr) && !chan_owner(fr)) {
  3192. dprintf(idx, STR("You can't remove hostmasks from a channel owner/master.\n"));
  3193. return;
  3194. }
  3195. if (!glob_master(fr) && !chan_master(fr)) {
  3196. dprintf(idx, STR("Permission denied.\n"));
  3197. return;
  3198. }
  3199. }
  3200. if (delhost_by_handle(handle, host)) {
  3201. dprintf(idx, STR("Removed '%s' from %s.\n"), host, handle);
  3202. update_mod(handle, dcc[idx].nick, "-host", host);
  3203. if ((me = module_find("irc", 0, 0))) {
  3204. Function *func = me->funcs;
  3205. (func[IRC_CHECK_THIS_USER]) (handle, 2, host);
  3206. }
  3207. #ifdef HUB
  3208. write_userfile(idx);
  3209. #endif /* HUB */
  3210. } else
  3211. dprintf(idx, STR("Failed.\n"));
  3212. }
  3213. /* netserver */
  3214. static void cmd_netserver(struct userrec * u, int idx, char * par) {
  3215. putlog(LOG_CMDS, "*", STR("#%s# netserver"), dcc[idx].nick);
  3216. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("cursrv"));
  3217. }
  3218. static void cmd_botserver(struct userrec * u, int idx, char * par) {
  3219. putlog(LOG_CMDS, "*", STR("#%s# botserver %s"), dcc[idx].nick, par);
  3220. if (!par || !par[0]) {
  3221. dprintf(idx, STR("Usage: botserver <bot>\n"));
  3222. return;
  3223. }
  3224. if (nextbot(par)<0) {
  3225. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3226. }
  3227. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("cursrv"));
  3228. }
  3229. void rcmd_cursrv(char * fbot, char * fhand, char * fidx) {
  3230. #ifdef LEAF
  3231. char tmp[2048], cursrvname[500];
  3232. int server_online = 0;
  3233. module_entry *me;
  3234. if ((me = module_find("server", 0, 0))) {
  3235. Function *func = me->funcs;
  3236. server_online = (*(int *)(func[25]));
  3237. sprintf(cursrvname, "%s", ((char *)(func[41])));
  3238. }
  3239. if (server_online)
  3240. sprintf(tmp, "Currently: %-40s Lag: %d", cursrvname, server_lag);
  3241. // sprintf(tmp, STR("%-20s %d)"), cursrvname, server_lag);
  3242. else
  3243. sprintf(tmp, "Currently: none");
  3244. // sprintf(tmp, STR("%-20s"), "none");
  3245. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3246. #endif /* LEAF */
  3247. }
  3248. /* netversion */
  3249. static void cmd_netversion(struct userrec * u, int idx, char * par) {
  3250. putlog(LOG_CMDS, "*", STR("#%s# netversion"), dcc[idx].nick);
  3251. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("ver"));
  3252. }
  3253. static void cmd_botversion(struct userrec * u, int idx, char * par) {
  3254. putlog(LOG_CMDS, "*", STR("#%s# botversion %s"), dcc[idx].nick, par);
  3255. if (!par || !par[0]) {
  3256. dprintf(idx, STR("Usage: botversion <bot>\n"));
  3257. return;
  3258. }
  3259. if (nextbot(par)<0) {
  3260. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3261. }
  3262. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("ver"));
  3263. }
  3264. void rcmd_ver(char * fbot, char * fhand, char * fidx) {
  3265. char tmp[2048];
  3266. #ifdef HAVE_UNAME
  3267. struct utsname un;
  3268. #endif /* HAVE_UNAME */
  3269. sprintf(tmp, STR("%s "), version);
  3270. #ifdef HAVE_UNAME
  3271. if (uname(&un) < 0) {
  3272. #endif /* HAVE_UNAME */
  3273. strcat(tmp, STR("(unknown OS)"));
  3274. #ifdef HAVE_UNAME
  3275. } else {
  3276. sprintf(tmp + strlen(tmp), STR("%s %s (%s)"), un.sysname, un.release, un.machine);
  3277. }
  3278. #endif /* HAVE_UNAME */
  3279. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3280. }
  3281. /* netnick, botnick */
  3282. static void cmd_netnick (struct userrec *u, int idx, char *par) {
  3283. putlog(LOG_CMDS, "*", STR("#%s# netnick"), dcc[idx].nick);
  3284. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("curnick"));
  3285. }
  3286. static void cmd_botnick(struct userrec * u, int idx, char * par) {
  3287. putlog(LOG_CMDS, "*", STR("#%s# botnick %s"), dcc[idx].nick, par);
  3288. if (!par || !par[0]) {
  3289. dprintf(idx, STR("Usage: botnick <bot>\n"));
  3290. return;
  3291. }
  3292. if (nextbot(par)<0) {
  3293. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3294. }
  3295. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("curnick"));
  3296. }
  3297. void rcmd_curnick(char * fbot, char * fhand, char * fidx) {
  3298. #ifdef LEAF
  3299. char tmp[1024];
  3300. int server_online = 0;
  3301. module_entry *me;
  3302. if ((me = module_find("server", 0, 0))) {
  3303. Function *func = me->funcs;
  3304. server_online = (*(int *)(func[25]));
  3305. }
  3306. tmp[0] = 0;
  3307. if (server_online)
  3308. sprintf(tmp, STR("Currently: %-20s "), botname);
  3309. if (strncmp(botname, origbotname, strlen(botname)))
  3310. sprintf(tmp, STR("%sWant: %s"), tmp, origbotname);
  3311. if (!server_online)
  3312. sprintf(tmp, STR("%s(not online)"), tmp);
  3313. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3314. #endif /* LEAF */
  3315. }
  3316. /* netmsg, botmsg */
  3317. static void cmd_botmsg(struct userrec * u, int idx, char * par) {
  3318. char * tnick, * tbot;
  3319. char tmp[1024];
  3320. putlog(LOG_CMDS, "*", STR("#%s# botmsg %s"), dcc[idx].nick, par);
  3321. tbot=newsplit(&par);
  3322. tnick=newsplit(&par);
  3323. if (!par[0]) {
  3324. dprintf(idx, STR("Usage: botmsg <bot> <nick|#channel> <message>\n"));
  3325. return;
  3326. }
  3327. if (nextbot(tbot)<0) {
  3328. dprintf(idx, STR("No such bot linked\n"));
  3329. return;
  3330. }
  3331. sprintf(tmp, STR("msg %s %s"), tnick, par);
  3332. botnet_send_cmd(botnetnick, tbot, u->handle, idx, tmp);
  3333. }
  3334. static void cmd_netmsg(struct userrec * u, int idx, char * par) {
  3335. char * tnick;
  3336. char tmp[1024];
  3337. putlog(LOG_CMDS, "*", STR("#%s# netmsg %s"), dcc[idx].nick, par);
  3338. tnick=newsplit(&par);
  3339. if (!par[0]) {
  3340. dprintf(idx, STR("Usage: netmsg <nick|#channel> <message>\n"));
  3341. return;
  3342. }
  3343. sprintf(tmp, STR("msg %s %s"), tnick, par);
  3344. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, tmp);
  3345. }
  3346. void rcmd_msg(char * tobot, char * frombot, char * fromhand, char * fromidx, char * par) {
  3347. #ifdef LEAF
  3348. char buf[1024], *nick;
  3349. nick=newsplit(&par);
  3350. dprintf(DP_SERVER, STR("PRIVMSG %s :%s\n"), nick, par);
  3351. if (!strcmp(tobot, botnetnick)) {
  3352. sprintf(buf, STR("Sent message to %s"), nick);
  3353. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, buf);
  3354. }
  3355. #endif /* LEAF */
  3356. }
  3357. #ifdef HUB
  3358. /* netlag */
  3359. static void cmd_netlag(struct userrec * u, int idx, char * par) {
  3360. struct timeval tv;
  3361. time_t tm;
  3362. char tmp[64];
  3363. putlog(LOG_CMDS, "*", STR("#%s# netlag"), dcc[idx].nick);
  3364. gettimeofday(&tv, NULL);
  3365. tm = (tv.tv_sec % 10000) * 100 + (tv.tv_usec * 100) / (1000000);
  3366. sprintf(tmp, STR("ping %lu"), tm);
  3367. dprintf(idx, STR("Sent ping to all linked bots\n"));
  3368. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, tmp);
  3369. }
  3370. #endif /* HUB */
  3371. void rcmd_ping(char * frombot, char *fromhand, char * fromidx, char * par) {
  3372. char tmp[64];
  3373. sprintf(tmp, STR("pong %s"), par);
  3374. botnet_send_cmd(botnetnick, frombot, fromhand, atoi(fromidx), tmp);
  3375. }
  3376. void rcmd_pong(char *frombot, char *fromhand, char *fromidx, char *par) {
  3377. int i=atoi(fromidx);
  3378. if ((i>=0) && (i<dcc_total) && (dcc[i].type==&DCC_CHAT) && (!strcmp(dcc[i].nick, fromhand))) {
  3379. struct timeval tv;
  3380. time_t tm;
  3381. gettimeofday(&tv, NULL);
  3382. tm = ((tv.tv_sec % 10000) * 100 + (tv.tv_usec * 100) / (1000000)) - atoi(par);
  3383. dprintf(i, STR("Pong from %s: %i.%i seconds\n"), frombot, (tm / 100), (tm % 100));
  3384. }
  3385. }
  3386. /* exec commands */
  3387. #ifdef HUB
  3388. static void cmd_netw(struct userrec * u, int idx, char * par) {
  3389. char tmp[128];
  3390. putlog(LOG_CMDS, "*", STR("#%s# netw"), dcc[idx].nick);
  3391. strcpy(tmp, STR("exec w"));
  3392. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, tmp);
  3393. }
  3394. static void cmd_netps(struct userrec * u, int idx, char * par) {
  3395. char buf[1024];
  3396. putlog(LOG_CMDS, "*", STR("#%s# netps %s"), dcc[idx].nick, par);
  3397. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  3398. putlog(LOG_WARN, "*", STR("%s attempted 'netps' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  3399. dprintf(idx, STR("No."));
  3400. return;
  3401. }
  3402. sprintf(buf, STR("exec ps %s"), par);
  3403. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3404. }
  3405. static void cmd_netlast(struct userrec * u, int idx, char * par) {
  3406. char buf[1024];
  3407. putlog(LOG_CMDS, "*", STR("#%s# netlast %s"), dcc[idx].nick, par);
  3408. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  3409. putlog(LOG_WARN, "*", STR("%s attempted 'netlast' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  3410. dprintf(idx, STR("No."));
  3411. return;
  3412. }
  3413. sprintf(buf, STR("exec last %s"), par);
  3414. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3415. }
  3416. #endif /* HUB */
  3417. void crontab_show(struct userrec * u, int idx) {
  3418. dprintf(idx, STR("Showing current crontab:\n"));
  3419. if (!exec_str(idx, STR("crontab -l | grep -v \"^#\"")))
  3420. dprintf(idx, STR("Exec failed"));
  3421. }
  3422. void crontab_del() {
  3423. char * tmpfile, *p, buf[2048];
  3424. tmpfile=nmalloc(strlen(binname)+100);
  3425. strcpy(tmpfile, binname);
  3426. if (!(p=strrchr(tmpfile, '/')))
  3427. return;
  3428. p++;
  3429. strcpy(p, STR(".ctb"));
  3430. sprintf(buf, STR("crontab -l | grep -v \"%s\" | grep -v \"^#\" | grep -v \"^\\$\" > %s"), binname, tmpfile);
  3431. if (shell_exec(buf, NULL, NULL, NULL)) {
  3432. sprintf(buf, STR("crontab %s"), tmpfile);
  3433. shell_exec(buf, NULL, NULL, NULL);
  3434. }
  3435. unlink(tmpfile);
  3436. }
  3437. static void cmd_crontab(struct userrec *u, int idx, char *par) {
  3438. char * code;
  3439. int i;
  3440. putlog(LOG_CMDS, "*", STR("#%s# crontab %s"), dcc[idx].nick, par);
  3441. if (!par[0]) {
  3442. dprintf(idx, STR("Usage: crontab <status|delete|show|new> [interval]\n"));
  3443. return;
  3444. }
  3445. code=newsplit(&par);
  3446. if (!strcmp(code, STR("status"))) {
  3447. i=crontab_exists();
  3448. if (!i)
  3449. dprintf(idx, STR("No crontab\n"));
  3450. else if (i==1)
  3451. dprintf(idx, STR("Crontabbed\n"));
  3452. else
  3453. dprintf(idx, STR("Error checking crontab status\n"));
  3454. } else if (!strcmp(code, STR("show"))) {
  3455. crontab_show(u, idx);
  3456. } else if (!strcmp(code, STR("delete"))) {
  3457. crontab_del();
  3458. i=crontab_exists();
  3459. if (!i)
  3460. dprintf(idx, STR("No crontab\n"));
  3461. else if (i==1)
  3462. dprintf(idx, STR("Crontabbed\n"));
  3463. else
  3464. dprintf(idx, STR("Error checking crontab status\n"));
  3465. } else if (!strcmp(code, STR("new"))) {
  3466. i=atoi(par);
  3467. if ((i<=0) || (i>60))
  3468. i=10;
  3469. crontab_create(i);
  3470. i=crontab_exists();
  3471. if (!i)
  3472. dprintf(idx, STR("No crontab\n"));
  3473. else if (i==1)
  3474. dprintf(idx, STR("Crontabbed\n"));
  3475. else
  3476. dprintf(idx, STR("Error checking crontab status\n"));
  3477. } else {
  3478. dprintf(idx, STR("Usage: crontab status|delete|show|new [interval]\n"));
  3479. }
  3480. }
  3481. #ifdef HUB
  3482. static void cmd_netcrontab(struct userrec * u, int idx, char * par) {
  3483. char buf[1024], *cmd;
  3484. putlog(LOG_CMDS, "*", STR("#%s# netcrontab %s"), dcc[idx].nick, par);
  3485. cmd=newsplit(&par);
  3486. if ((strcmp(cmd, STR("status")) && strcmp(cmd, STR("show")) && strcmp(cmd, STR("delete")) && strcmp(cmd, STR("new")))) {
  3487. dprintf(idx, STR("Usage: netcrontab <status|delete|show|new> [interval]\n"));
  3488. return;
  3489. }
  3490. egg_snprintf(buf, sizeof buf, STR("exec crontab %s %s"), cmd, par);
  3491. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3492. }
  3493. #endif /* HUB */
  3494. void rcmd_exec(char * frombot, char * fromhand, char * fromidx, char * par) {
  3495. char * cmd, scmd[512], *out, *err;
  3496. struct passwd *pw;
  3497. cmd=newsplit(&par);
  3498. scmd[0]=0;
  3499. if (!strcmp(cmd, "w")) {
  3500. strcpy(scmd, "w");
  3501. } else if (!strcmp(cmd, STR("last"))) {
  3502. char user[20];
  3503. if (par[0]) {
  3504. strncpyz(user, par, sizeof(user));
  3505. } else {
  3506. pw = getpwuid(geteuid());
  3507. if (!pw) return;
  3508. strncpyz(user, pw->pw_name, sizeof(user));
  3509. }
  3510. if (!user[0]) {
  3511. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Can't determine user id for process"));
  3512. return;
  3513. }
  3514. sprintf(scmd, STR("last %s"), user);
  3515. } else if (!strcmp(cmd, STR("ps"))) {
  3516. sprintf(scmd, STR("ps %s"), par);
  3517. } else if (!strcmp(cmd, STR("raw"))) {
  3518. sprintf(scmd, STR("%s"), par);
  3519. } else if (!strcmp(cmd, STR("kill"))) {
  3520. sprintf(scmd, STR("kill %s"), par);
  3521. } else if (!strcmp(cmd, STR("crontab"))) {
  3522. char * code=newsplit(&par);
  3523. scmd[0]=0;
  3524. if (!strcmp(code, STR("show"))) {
  3525. strcpy(scmd, STR("crontab -l | grep -v \"^#\""));
  3526. } else if (!strcmp(code, STR("delete"))) {
  3527. crontab_del();
  3528. } else if (!strcmp(code, STR("new"))) {
  3529. int i=atoi(par);
  3530. if ((i<=0) || (i>60))
  3531. i=10;
  3532. crontab_create(i);
  3533. }
  3534. if (!scmd[0]) {
  3535. char s[200];
  3536. int i;
  3537. i=crontab_exists();
  3538. if (!i)
  3539. sprintf(s, STR("No crontab"));
  3540. else if (i==1)
  3541. sprintf(s, STR("Crontabbed"));
  3542. else
  3543. sprintf(s, STR("Error checking crontab status"));
  3544. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, s);
  3545. }
  3546. }
  3547. if (!scmd[0])
  3548. return;
  3549. if (shell_exec(scmd, NULL, &out, &err)) {
  3550. if (out) {
  3551. char * p, * np;
  3552. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Result:"));
  3553. p=out;
  3554. while (p && p[0]) {
  3555. np=strchr(p, '\n');
  3556. if (np)
  3557. *np++=0;
  3558. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, p);
  3559. p=np;
  3560. }
  3561. nfree(out);
  3562. }
  3563. if (err) {
  3564. char * p, * np;
  3565. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Errors:"));
  3566. p=err;
  3567. while (p && p[0]) {
  3568. np=strchr(p, '\n');
  3569. if (np)
  3570. *np++=0;
  3571. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, p);
  3572. p=np;
  3573. }
  3574. nfree(err);
  3575. }
  3576. } else {
  3577. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("exec failed"));
  3578. }
  3579. }
  3580. static void cmd_botjump(struct userrec * u, int idx, char * par) {
  3581. char *tbot, buf[1024];
  3582. putlog(LOG_CMDS, "*", STR("#%s# botjump %s"), dcc[idx].nick, par);
  3583. tbot=newsplit(&par);
  3584. if (!tbot[0]) {
  3585. dprintf(idx, STR("Usage: botjump <bot> [server [port [pass]]]\n"));
  3586. return;
  3587. }
  3588. if (nextbot(tbot)<0) {
  3589. dprintf(idx, STR("No such linked bot\n"));
  3590. return;
  3591. }
  3592. sprintf(buf, STR("jump %s"), par);
  3593. botnet_send_cmd(botnetnick, tbot, dcc[idx].nick, idx, buf);
  3594. }
  3595. void rcmd_jump(char * frombot, char * fromhand, char * fromidx, char * par) {
  3596. #ifdef LEAF
  3597. char * other;
  3598. module_entry *me;
  3599. Function *func;
  3600. int port, default_port = 0;
  3601. if (!(me = module_find("server", 0, 0)) )
  3602. return;
  3603. func = me->funcs;
  3604. default_port = (*(int *)(func[24]));
  3605. if (par[0]) {
  3606. other = newsplit(&par);
  3607. port = atoi(newsplit(&par));
  3608. if (!port)
  3609. port = default_port;
  3610. strncpyz(((char *)(func[20])), other, 120); //newserver
  3611. (*(int *)(func[21])) = port; //newserverport
  3612. strncpyz(((char *)(func[22])), par, 120); //newserverpass
  3613. }
  3614. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Jumping..."));
  3615. (*(int *)(func[23])) = 0; //cycle_time
  3616. (func[SERVER_NUKESERVER]) ("jumping...");
  3617. #endif /* LEAF */
  3618. }
  3619. /* "Remotable" commands */
  3620. void gotremotecmd (char * forbot, char * frombot, char * fromhand, char * fromidx, char * cmd) {
  3621. char * par = cmd;
  3622. cmd=newsplit(&par);
  3623. if (!strcmp(cmd, STR("exec"))) {
  3624. rcmd_exec(frombot, fromhand, fromidx, par);
  3625. } else if (!strcmp(cmd, STR("curnick"))) {
  3626. rcmd_curnick(frombot, fromhand, fromidx);
  3627. } else if (!strcmp(cmd, STR("cursrv"))) {
  3628. rcmd_cursrv(frombot, fromhand, fromidx);
  3629. } else if (!strcmp(cmd, STR("jump"))) {
  3630. rcmd_jump(frombot, fromhand, fromidx, par);
  3631. } else if (!strcmp(cmd, STR("msg"))) {
  3632. rcmd_msg(forbot, frombot, fromhand, fromidx, par);
  3633. } else if (!strcmp(cmd, STR("ver"))) {
  3634. rcmd_ver(frombot, fromhand, fromidx);
  3635. } else if (!strcmp(cmd, STR("ping"))) {
  3636. rcmd_ping(frombot, fromhand, fromidx, par);
  3637. } else if (!strcmp(cmd, STR("pong"))) {
  3638. rcmd_pong(frombot, fromhand, fromidx, par);
  3639. } else if (!strcmp(cmd, STR("die"))) {
  3640. exit(0);
  3641. } else {
  3642. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Unrecognized remote command"));
  3643. }
  3644. }
  3645. void gotremotereply (char *frombot, char *tohand, char *toidx, char *ln) {
  3646. int idx = atoi(toidx);
  3647. if ((idx >= 0) && (idx < dcc_total) && (dcc[idx].type == &DCC_CHAT) && (!strcmp(dcc[idx].nick, tohand))) {
  3648. char *buf = nmalloc(strlen(frombot) + 2 + 1);
  3649. sprintf(buf, "(%s)", frombot);
  3650. dprintf(idx, STR("%-13s %s\n"), buf, ln);
  3651. nfree(buf);
  3652. }
  3653. }
  3654. static void cmd_traffic(struct userrec *u, int idx, char *par)
  3655. {
  3656. unsigned long itmp, itmp2;
  3657. dprintf(idx, STR("Traffic since last restart\n"));
  3658. dprintf(idx, "==========================\n");
  3659. if (otraffic_irc > 0 || itraffic_irc > 0 || otraffic_irc_today > 0 ||
  3660. itraffic_irc_today > 0) {
  3661. dprintf(idx, "IRC:\n");
  3662. dprintf(idx, " out: %s", btos(otraffic_irc + otraffic_irc_today));
  3663. dprintf(idx, " (%s today)\n", btos(otraffic_irc_today));
  3664. dprintf(idx, " in: %s", btos(itraffic_irc + itraffic_irc_today));
  3665. dprintf(idx, " (%s today)\n", btos(itraffic_irc_today));
  3666. }
  3667. if (otraffic_bn > 0 || itraffic_bn > 0 || otraffic_bn_today > 0 ||
  3668. itraffic_bn_today > 0) {
  3669. dprintf(idx, STR("Botnet:\n"));
  3670. dprintf(idx, " out: %s", btos(otraffic_bn + otraffic_bn_today));
  3671. dprintf(idx, " (%s today)\n", btos(otraffic_bn_today));
  3672. dprintf(idx, " in: %s", btos(itraffic_bn + itraffic_bn_today));
  3673. dprintf(idx, " (%s today)\n", btos(itraffic_bn_today));
  3674. }
  3675. if (otraffic_dcc > 0 || itraffic_dcc > 0 || otraffic_dcc_today > 0 ||
  3676. itraffic_dcc_today > 0) {
  3677. dprintf(idx, STR("Partyline:\n"));
  3678. itmp = otraffic_dcc + otraffic_dcc_today;
  3679. itmp2 = otraffic_dcc_today;
  3680. dprintf(idx, " out: %s", btos(itmp));
  3681. dprintf(idx, " (%s today)\n", btos(itmp2));
  3682. dprintf(idx, " in: %s", btos(itraffic_dcc + itraffic_dcc_today));
  3683. dprintf(idx, " (%s today)\n", btos(itraffic_dcc_today));
  3684. }
  3685. if (otraffic_trans > 0 || itraffic_trans > 0 || otraffic_trans_today > 0 ||
  3686. itraffic_trans_today > 0) {
  3687. dprintf(idx, STR("Transfer.mod:\n"));
  3688. dprintf(idx, " out: %s", btos(otraffic_trans + otraffic_trans_today));
  3689. dprintf(idx, " (%s today)\n", btos(otraffic_trans_today));
  3690. dprintf(idx, " in: %s", btos(itraffic_trans + itraffic_trans_today));
  3691. dprintf(idx, " (%s today)\n", btos(itraffic_trans_today));
  3692. }
  3693. if (otraffic_unknown > 0 || otraffic_unknown_today > 0) {
  3694. dprintf(idx, "Misc:\n");
  3695. dprintf(idx, " out: %s", btos(otraffic_unknown + otraffic_unknown_today));
  3696. dprintf(idx, " (%s today)\n", btos(otraffic_unknown_today));
  3697. dprintf(idx, " in: %s", btos(itraffic_unknown + itraffic_unknown_today));
  3698. dprintf(idx, " (%s today)\n", btos(itraffic_unknown_today));
  3699. }
  3700. dprintf(idx, "---\n");
  3701. dprintf(idx, "Total:\n");
  3702. itmp = otraffic_irc + otraffic_bn + otraffic_dcc + otraffic_trans
  3703. + otraffic_unknown + otraffic_irc_today + otraffic_bn_today
  3704. + otraffic_dcc_today + otraffic_trans_today + otraffic_unknown_today;
  3705. itmp2 = otraffic_irc_today + otraffic_bn_today + otraffic_dcc_today
  3706. + otraffic_trans_today + otraffic_unknown_today;
  3707. dprintf(idx, " out: %s", btos(itmp));
  3708. dprintf(idx, " (%s today)\n", btos(itmp2));
  3709. dprintf(idx, " in: %s", btos(itraffic_irc + itraffic_bn + itraffic_dcc
  3710. + itraffic_trans + itraffic_unknown + itraffic_irc_today
  3711. + itraffic_bn_today + itraffic_dcc_today + itraffic_trans_today
  3712. + itraffic_unknown_today));
  3713. dprintf(idx, " (%s today)\n", btos(itraffic_irc_today + itraffic_bn_today
  3714. + itraffic_dcc_today + itraffic_trans_today
  3715. + itraffic_unknown_today));
  3716. putlog(LOG_CMDS, "*", STR("#%s# traffic"), dcc[idx].nick);
  3717. }
  3718. static char traffictxt[20];
  3719. static char *btos(unsigned long bytes)
  3720. {
  3721. char unit[10];
  3722. float xbytes;
  3723. sprintf(unit, "Bytes");
  3724. xbytes = bytes;
  3725. if (xbytes > 1024.0) {
  3726. sprintf(unit, "KBytes");
  3727. xbytes = xbytes / 1024.0;
  3728. }
  3729. if (xbytes > 1024.0) {
  3730. sprintf(unit, "MBytes");
  3731. xbytes = xbytes / 1024.0;
  3732. }
  3733. if (xbytes > 1024.0) {
  3734. sprintf(unit, "GBytes");
  3735. xbytes = xbytes / 1024.0;
  3736. }
  3737. if (xbytes > 1024.0) {
  3738. sprintf(unit, "TBytes");
  3739. xbytes = xbytes / 1024.0;
  3740. }
  3741. if (bytes > 1024)
  3742. sprintf(traffictxt, "%.2f %s", xbytes, unit);
  3743. else
  3744. sprintf(traffictxt, "%lu Bytes", bytes);
  3745. return traffictxt;
  3746. }
  3747. static void cmd_whoami(struct userrec *u, int idx, char *par)
  3748. {
  3749. putlog(LOG_CMDS, "*", STR("#%s# whoami"), dcc[idx].nick);
  3750. dprintf(idx, "You are %s@%s.\n", dcc[idx].nick, botnetnick);
  3751. }
  3752. /* DCC CHAT COMMANDS
  3753. */
  3754. /* Function call should be:
  3755. * int cmd_whatever(idx,"parameters");
  3756. * As with msg commands, function is responsible for any logging.
  3757. */
  3758. cmd_t C_dcc[] =
  3759. {
  3760. {"+host", "m|m", (Function) cmd_pls_host, NULL},
  3761. {"+ignore", "m", (Function) cmd_pls_ignore, NULL},
  3762. {"+user", "m", (Function) cmd_pls_user, NULL},
  3763. #ifdef HUB
  3764. {"-bot", "a", (Function) cmd_mns_user, NULL},
  3765. #endif /* HUB */
  3766. {"-host", "", (Function) cmd_mns_host, NULL},
  3767. {"-ignore", "m", (Function) cmd_mns_ignore, NULL},
  3768. {"-user", "m", (Function) cmd_mns_user, NULL},
  3769. {"addlog", "mo|o", (Function) cmd_addlog, NULL},
  3770. /* {"putlog", "mo|o", (Function) cmd_addlog, NULL}, */
  3771. {"about", "", (Function) cmd_about, NULL},
  3772. {"away", "", (Function) cmd_away, NULL},
  3773. {"back", "", (Function) cmd_back, NULL},
  3774. #ifdef HUB
  3775. {"backup", "m|m", (Function) cmd_backup, NULL},
  3776. {"binds", "a", (Function) cmd_binds, NULL},
  3777. {"boot", "m", (Function) cmd_boot, NULL},
  3778. {"botconfig", "n", (Function) cmd_botconfig, NULL},
  3779. {"botinfo", "", (Function) cmd_botinfo, NULL},
  3780. {"bots", "m", (Function) cmd_bots, NULL},
  3781. {"downbots", "m", (Function) cmd_downbots, NULL},
  3782. {"bottree", "n", (Function) cmd_bottree, NULL},
  3783. {"chaddr", "a", (Function) cmd_chaddr, NULL},
  3784. #endif /* HUB */
  3785. {"chat", "", (Function) cmd_chat, NULL},
  3786. {"chattr", "m|m", (Function) cmd_chattr, NULL},
  3787. #ifdef HUB
  3788. {"chhandle", "m", (Function) cmd_chhandle, NULL},
  3789. {"chnick", "m", (Function) cmd_chhandle, NULL, 1},
  3790. {"chpass", "m", (Function) cmd_chpass, NULL},
  3791. {"chsecpass", "n", (Function) cmd_chsecpass, NULL},
  3792. #ifdef S_DCCPASS
  3793. {"cmdpass", "a", (Function) cmd_cmdpass, NULL},
  3794. #endif /* S_DCCPASS */
  3795. #endif /* HUB */
  3796. {"color", "", (Function) cmd_color, NULL},
  3797. {"comment", "m|m", (Function) cmd_comment, NULL},
  3798. #ifdef HUB
  3799. {"config", "n", (Function) cmd_config, NULL},
  3800. #endif /* HUB */
  3801. {"console", "-|-", (Function) cmd_console, NULL},
  3802. {"date", "", (Function) cmd_date, NULL},
  3803. #ifdef HUB
  3804. {"dccstat", "a", (Function) cmd_dccstat, NULL},
  3805. #endif /* HUB */
  3806. {"debug", "a", (Function) cmd_debug, NULL},
  3807. {"die", "n", (Function) cmd_die, NULL},
  3808. {"echo", "", (Function) cmd_echo, NULL},
  3809. {"fixcodes", "", (Function) cmd_fixcodes, NULL},
  3810. {"handle", "", (Function) cmd_handle, NULL},
  3811. {"nohelp", "-|-", (Function) cmd_nohelp, NULL, 1},
  3812. {"help", "-|-", (Function) cmd_help, NULL},
  3813. {"ignores", "m", (Function) cmd_ignores, NULL},
  3814. #ifdef HUB
  3815. {"link", "n", (Function) cmd_link, NULL},
  3816. #endif /* HUB */
  3817. {"match", "m|m", (Function) cmd_match, NULL},
  3818. {"me", "", (Function) cmd_me, NULL},
  3819. {"motd", "", (Function) cmd_motd, NULL},
  3820. #ifdef HUB
  3821. #ifdef S_TCLCMDS
  3822. {"nettcl", "a", (Function) cmd_nettcl, NULL},
  3823. #endif /* S_TCLCMDS */
  3824. {"newleaf", "n", (Function) cmd_newleaf, NULL},
  3825. #endif /* HUB */
  3826. {"newpass", "", (Function) cmd_newpass, NULL},
  3827. {"secpass", "", (Function) cmd_secpass, NULL},
  3828. {"nick", "", (Function) cmd_handle, NULL, 1},
  3829. {"page", "", (Function) cmd_page, NULL},
  3830. {"quit", "", (Function) NULL, NULL},
  3831. {"relay", "i", (Function) cmd_relay, NULL},
  3832. #ifdef HUB
  3833. {"reload", "m|m", (Function) cmd_reload, NULL},
  3834. #endif /* HUB */
  3835. {"restart", "m", (Function) cmd_restart, NULL},
  3836. #ifdef HUB
  3837. {"save", "m|m", (Function) cmd_save, NULL},
  3838. #endif /* HUB */
  3839. {"simul", "a", (Function) cmd_simul, NULL},
  3840. {"status", "m|m", (Function) cmd_status, NULL},
  3841. {"strip", "", (Function) cmd_strip, NULL},
  3842. {"su", "a", (Function) cmd_su, NULL},
  3843. #ifdef S_TCLCMDS
  3844. {"tcl", "a", (Function) cmd_tcl, NULL},
  3845. #endif /* S_TCLCMDS */
  3846. #ifdef HUB
  3847. {"trace", "n", (Function) cmd_trace, NULL},
  3848. #endif /* HUB */
  3849. {"traffic", "m", (Function) cmd_traffic, NULL},
  3850. {"unlink", "m", (Function) cmd_unlink, NULL},
  3851. {"update", "a", (Function) cmd_update, NULL},
  3852. #ifdef HUB
  3853. {"netcrontab", "a", (Function) cmd_netcrontab, NULL},
  3854. #endif /* HUB */
  3855. {"uptime", "m|m", (Function) cmd_uptime, NULL},
  3856. {"crontab", "a", (Function) cmd_crontab, NULL},
  3857. #ifdef HUB
  3858. {"vbottree", "n", (Function) cmd_vbottree, NULL},
  3859. {"who", "n", (Function) cmd_who, NULL},
  3860. #endif /* HUB */
  3861. {"whois", "", (Function) cmd_whois, NULL},
  3862. {"whom", "", (Function) cmd_whom, NULL},
  3863. {"whoami", "", (Function) cmd_whoami, NULL},
  3864. {"botjump", "m", (Function) cmd_botjump, NULL},
  3865. {"botmsg", "o", (Function) cmd_botmsg, NULL},
  3866. {"netmsg", "n", (Function) cmd_netmsg, NULL},
  3867. {"botnick", "m", (Function) cmd_botnick, NULL},
  3868. {"netnick", "m", (Function) cmd_netnick, NULL},
  3869. #ifdef HUB
  3870. {"netw", "n", (Function) cmd_netw, NULL},
  3871. {"netps", "n", (Function) cmd_netps, NULL},
  3872. {"netlast", "n", (Function) cmd_netlast, NULL},
  3873. {"netlag", "m", (Function) cmd_netlag, NULL},
  3874. #endif /* HUB */
  3875. {"botserver", "m", (Function) cmd_botserver, NULL},
  3876. {"netserver", "m", (Function) cmd_netserver, NULL},
  3877. {"botversion", "o", (Function) cmd_botversion, NULL},
  3878. {"netversion", "o", (Function) cmd_netversion, NULL},
  3879. {"userlist", "m", (Function) cmd_userlist, NULL},
  3880. {"ps", "n", (Function) cmd_ps, NULL},
  3881. {"last", "n", (Function) cmd_last, NULL},
  3882. {"exec", "a", (Function) cmd_exec, NULL},
  3883. {"w", "n", (Function) cmd_w, NULL},
  3884. {"channels", "", (Function) cmd_channels, NULL},
  3885. {"randstring", "", (Function) cmd_randstring, NULL},
  3886. #ifdef HUB
  3887. {"botcmd", "i", (Function) cmd_botcmd, NULL},
  3888. {"bc", "i", (Function) cmd_botcmd, NULL},
  3889. {"hublevel", "a", (Function) cmd_hublevel, NULL},
  3890. {"lagged", "m", (Function) cmd_lagged, NULL},
  3891. {"uplink", "a", (Function) cmd_uplink, NULL},
  3892. #endif /* HUB */
  3893. {NULL, NULL, NULL, NULL}
  3894. };