1
0

cmds.c 124 KB

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