sv_ccmds.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "qwsvdef.h"
  16. qboolean sv_allow_cheats;
  17. int fp_messages=4, fp_persecond=4, fp_secondsdead=10;
  18. char fp_msg[255] = { 0 };
  19. extern cvar_t cl_warncmd;
  20. extern redirect_t sv_redirected;
  21. /*
  22. ===============================================================================
  23. OPERATOR CONSOLE ONLY COMMANDS
  24. These commands can only be entered from stdin or by a remote operator datagram
  25. ===============================================================================
  26. */
  27. /*
  28. ====================
  29. SV_SetMaster_f
  30. Make a master server current
  31. ====================
  32. */
  33. void SV_SetMaster_f (void)
  34. {
  35. char data[2];
  36. int i;
  37. memset (&master_adr, 0, sizeof(master_adr));
  38. for (i=1 ; i<Cmd_Argc() ; i++)
  39. {
  40. if (!strcmp(Cmd_Argv(i), "none") || !NET_StringToAdr (Cmd_Argv(i), &master_adr[i-1]))
  41. {
  42. Con_Printf ("Setting nomaster mode.\n");
  43. return;
  44. }
  45. if (master_adr[i-1].port == 0)
  46. master_adr[i-1].port = BigShort (27000);
  47. Con_Printf ("Master server at %s\n", NET_AdrToString (master_adr[i-1]));
  48. Con_Printf ("Sending a ping.\n");
  49. data[0] = A2A_PING;
  50. data[1] = 0;
  51. NET_SendPacket (2, data, master_adr[i-1]);
  52. }
  53. svs.last_heartbeat = -99999;
  54. }
  55. /*
  56. ==================
  57. SV_Quit_f
  58. ==================
  59. */
  60. void SV_Quit_f (void)
  61. {
  62. SV_FinalMessage ("server shutdown\n");
  63. Con_Printf ("Shutting down.\n");
  64. SV_Shutdown ();
  65. Sys_Quit ();
  66. }
  67. /*
  68. ============
  69. SV_Logfile_f
  70. ============
  71. */
  72. void SV_Logfile_f (void)
  73. {
  74. char name[MAX_OSPATH];
  75. if (sv_logfile)
  76. {
  77. Con_Printf ("File logging off.\n");
  78. fclose (sv_logfile);
  79. sv_logfile = NULL;
  80. return;
  81. }
  82. sprintf (name, "%s/qconsole.log", com_gamedir);
  83. Con_Printf ("Logging text to %s.\n", name);
  84. sv_logfile = fopen (name, "w");
  85. if (!sv_logfile)
  86. Con_Printf ("failed.\n");
  87. }
  88. /*
  89. ============
  90. SV_Fraglogfile_f
  91. ============
  92. */
  93. void SV_Fraglogfile_f (void)
  94. {
  95. char name[MAX_OSPATH];
  96. int i;
  97. if (sv_fraglogfile)
  98. {
  99. Con_Printf ("Frag file logging off.\n");
  100. fclose (sv_fraglogfile);
  101. sv_fraglogfile = NULL;
  102. return;
  103. }
  104. // find an unused name
  105. for (i=0 ; i<1000 ; i++)
  106. {
  107. sprintf (name, "%s/frag_%i.log", com_gamedir, i);
  108. sv_fraglogfile = fopen (name, "r");
  109. if (!sv_fraglogfile)
  110. { // can't read it, so create this one
  111. sv_fraglogfile = fopen (name, "w");
  112. if (!sv_fraglogfile)
  113. i=1000; // give error
  114. break;
  115. }
  116. fclose (sv_fraglogfile);
  117. }
  118. if (i==1000)
  119. {
  120. Con_Printf ("Can't open any logfiles.\n");
  121. sv_fraglogfile = NULL;
  122. return;
  123. }
  124. Con_Printf ("Logging frags to %s.\n", name);
  125. }
  126. /*
  127. ==================
  128. SV_SetPlayer
  129. Sets host_client and sv_player to the player with idnum Cmd_Argv(1)
  130. ==================
  131. */
  132. qboolean SV_SetPlayer (void)
  133. {
  134. client_t *cl;
  135. int i;
  136. int idnum;
  137. idnum = atoi(Cmd_Argv(1));
  138. for (i=0,cl=svs.clients ; i<MAX_CLIENTS ; i++,cl++)
  139. {
  140. if (!cl->state)
  141. continue;
  142. if (cl->userid == idnum)
  143. {
  144. host_client = cl;
  145. sv_player = host_client->edict;
  146. return true;
  147. }
  148. }
  149. Con_Printf ("Userid %i is not on the server\n", idnum);
  150. return false;
  151. }
  152. /*
  153. ==================
  154. SV_God_f
  155. Sets client to godmode
  156. ==================
  157. */
  158. void SV_God_f (void)
  159. {
  160. if (!sv_allow_cheats)
  161. {
  162. Con_Printf ("You must run the server with -cheats to enable this command.\n");
  163. return;
  164. }
  165. if (!SV_SetPlayer ())
  166. return;
  167. sv_player->v.flags = (int)sv_player->v.flags ^ FL_GODMODE;
  168. if (!((int)sv_player->v.flags & FL_GODMODE) )
  169. SV_ClientPrintf (host_client, PRINT_HIGH, "godmode OFF\n");
  170. else
  171. SV_ClientPrintf (host_client, PRINT_HIGH, "godmode ON\n");
  172. }
  173. void SV_Noclip_f (void)
  174. {
  175. if (!sv_allow_cheats)
  176. {
  177. Con_Printf ("You must run the server with -cheats to enable this command.\n");
  178. return;
  179. }
  180. if (!SV_SetPlayer ())
  181. return;
  182. if (sv_player->v.movetype != MOVETYPE_NOCLIP)
  183. {
  184. sv_player->v.movetype = MOVETYPE_NOCLIP;
  185. SV_ClientPrintf (host_client, PRINT_HIGH, "noclip ON\n");
  186. }
  187. else
  188. {
  189. sv_player->v.movetype = MOVETYPE_WALK;
  190. SV_ClientPrintf (host_client, PRINT_HIGH, "noclip OFF\n");
  191. }
  192. }
  193. /*
  194. ==================
  195. SV_Give_f
  196. ==================
  197. */
  198. void SV_Give_f (void)
  199. {
  200. char *t;
  201. int v;
  202. if (!sv_allow_cheats)
  203. {
  204. Con_Printf ("You must run the server with -cheats to enable this command.\n");
  205. return;
  206. }
  207. if (!SV_SetPlayer ())
  208. return;
  209. t = Cmd_Argv(2);
  210. v = atoi (Cmd_Argv(3));
  211. switch (t[0])
  212. {
  213. case '2':
  214. case '3':
  215. case '4':
  216. case '5':
  217. case '6':
  218. case '7':
  219. case '8':
  220. case '9':
  221. sv_player->v.items = (int)sv_player->v.items | IT_SHOTGUN<< (t[0] - '2');
  222. break;
  223. case 's':
  224. sv_player->v.ammo_shells = v;
  225. break;
  226. case 'n':
  227. sv_player->v.ammo_nails = v;
  228. break;
  229. case 'r':
  230. sv_player->v.ammo_rockets = v;
  231. break;
  232. case 'h':
  233. sv_player->v.health = v;
  234. break;
  235. case 'c':
  236. sv_player->v.ammo_cells = v;
  237. break;
  238. }
  239. }
  240. /*
  241. ======================
  242. SV_Map_f
  243. handle a
  244. map <mapname>
  245. command from the console or progs.
  246. ======================
  247. */
  248. void SV_Map_f (void)
  249. {
  250. char level[MAX_QPATH];
  251. char expanded[MAX_QPATH];
  252. FILE *f;
  253. if (Cmd_Argc() != 2)
  254. {
  255. Con_Printf ("map <levelname> : continue game on a new level\n");
  256. return;
  257. }
  258. strcpy (level, Cmd_Argv(1));
  259. #if 0
  260. if (!strcmp (level, "e1m8"))
  261. { // QuakeWorld can't go to e1m8
  262. SV_BroadcastPrintf (PRINT_HIGH, "can't go to low grav level in QuakeWorld...\n");
  263. strcpy (level, "e1m5");
  264. }
  265. #endif
  266. // check to make sure the level exists
  267. sprintf (expanded, "maps/%s.bsp", level);
  268. COM_FOpenFile (expanded, &f);
  269. if (!f)
  270. {
  271. Con_Printf ("Can't find %s\n", expanded);
  272. return;
  273. }
  274. fclose (f);
  275. SV_BroadcastCommand ("changing\n");
  276. SV_SendMessagesToAll ();
  277. SV_SpawnServer (level);
  278. SV_BroadcastCommand ("reconnect\n");
  279. }
  280. /*
  281. ==================
  282. SV_Kick_f
  283. Kick a user off of the server
  284. ==================
  285. */
  286. void SV_Kick_f (void)
  287. {
  288. int i;
  289. client_t *cl;
  290. int uid;
  291. uid = atoi(Cmd_Argv(1));
  292. for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++)
  293. {
  294. if (!cl->state)
  295. continue;
  296. if (cl->userid == uid)
  297. {
  298. SV_BroadcastPrintf (PRINT_HIGH, "%s was kicked\n", cl->name);
  299. // print directly, because the dropped client won't get the
  300. // SV_BroadcastPrintf message
  301. SV_ClientPrintf (cl, PRINT_HIGH, "You were kicked from the game\n");
  302. SV_DropClient (cl);
  303. return;
  304. }
  305. }
  306. Con_Printf ("Couldn't find user number %i\n", uid);
  307. }
  308. /*
  309. ================
  310. SV_Status_f
  311. ================
  312. */
  313. void SV_Status_f (void)
  314. {
  315. int i, j, l;
  316. client_t *cl;
  317. float cpu, avg, pak;
  318. char *s;
  319. cpu = (svs.stats.latched_active+svs.stats.latched_idle);
  320. if (cpu)
  321. cpu = 100*svs.stats.latched_active/cpu;
  322. avg = 1000*svs.stats.latched_active / STATFRAMES;
  323. pak = (float)svs.stats.latched_packets/ STATFRAMES;
  324. Con_Printf ("net address : %s\n",NET_AdrToString (net_local_adr));
  325. Con_Printf ("cpu utilization : %3i%%\n",(int)cpu);
  326. Con_Printf ("avg response time: %i ms\n",(int)avg);
  327. Con_Printf ("packets/frame : %5.2f (%d)\n", pak, num_prstr);
  328. // min fps lat drp
  329. if (sv_redirected != RD_NONE) {
  330. // most remote clients are 40 columns
  331. // 0123456789012345678901234567890123456789
  332. Con_Printf ("name userid frags\n");
  333. Con_Printf (" address rate ping drop\n");
  334. Con_Printf (" ---------------- ---- ---- -----\n");
  335. for (i=0,cl=svs.clients ; i<MAX_CLIENTS ; i++,cl++)
  336. {
  337. if (!cl->state)
  338. continue;
  339. Con_Printf ("%-16.16s ", cl->name);
  340. Con_Printf ("%6i %5i", cl->userid, (int)cl->edict->v.frags);
  341. if (cl->spectator)
  342. Con_Printf(" (s)\n");
  343. else
  344. Con_Printf("\n");
  345. s = NET_BaseAdrToString ( cl->netchan.remote_address);
  346. Con_Printf (" %-16.16s", s);
  347. if (cl->state == cs_connected)
  348. {
  349. Con_Printf ("CONNECTING\n");
  350. continue;
  351. }
  352. if (cl->state == cs_zombie)
  353. {
  354. Con_Printf ("ZOMBIE\n");
  355. continue;
  356. }
  357. Con_Printf ("%4i %4i %5.2f\n"
  358. , (int)(1000*cl->netchan.frame_rate)
  359. , (int)SV_CalcPing (cl)
  360. , 100.0*cl->netchan.drop_count / cl->netchan.incoming_sequence);
  361. }
  362. } else {
  363. Con_Printf ("frags userid address name rate ping drop qport\n");
  364. Con_Printf ("----- ------ --------------- --------------- ---- ---- ----- -----\n");
  365. for (i=0,cl=svs.clients ; i<MAX_CLIENTS ; i++,cl++)
  366. {
  367. if (!cl->state)
  368. continue;
  369. Con_Printf ("%5i %6i ", (int)cl->edict->v.frags, cl->userid);
  370. s = NET_BaseAdrToString ( cl->netchan.remote_address);
  371. Con_Printf ("%s", s);
  372. l = 16 - strlen(s);
  373. for (j=0 ; j<l ; j++)
  374. Con_Printf (" ");
  375. Con_Printf ("%s", cl->name);
  376. l = 16 - strlen(cl->name);
  377. for (j=0 ; j<l ; j++)
  378. Con_Printf (" ");
  379. if (cl->state == cs_connected)
  380. {
  381. Con_Printf ("CONNECTING\n");
  382. continue;
  383. }
  384. if (cl->state == cs_zombie)
  385. {
  386. Con_Printf ("ZOMBIE\n");
  387. continue;
  388. }
  389. Con_Printf ("%4i %4i %3.1f %4i"
  390. , (int)(1000*cl->netchan.frame_rate)
  391. , (int)SV_CalcPing (cl)
  392. , 100.0*cl->netchan.drop_count / cl->netchan.incoming_sequence
  393. , cl->netchan.qport);
  394. if (cl->spectator)
  395. Con_Printf(" (s)\n");
  396. else
  397. Con_Printf("\n");
  398. }
  399. }
  400. Con_Printf ("\n");
  401. }
  402. /*
  403. ==================
  404. SV_ConSay_f
  405. ==================
  406. */
  407. void SV_ConSay_f(void)
  408. {
  409. client_t *client;
  410. int j;
  411. char *p;
  412. char text[1024];
  413. if (Cmd_Argc () < 2)
  414. return;
  415. Q_strcpy (text, "console: ");
  416. p = Cmd_Args();
  417. if (*p == '"')
  418. {
  419. p++;
  420. p[Q_strlen(p)-1] = 0;
  421. }
  422. Q_strcat(text, p);
  423. for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++)
  424. {
  425. if (client->state != cs_spawned)
  426. continue;
  427. SV_ClientPrintf(client, PRINT_CHAT, "%s\n", text);
  428. }
  429. }
  430. /*
  431. ==================
  432. SV_Heartbeat_f
  433. ==================
  434. */
  435. void SV_Heartbeat_f (void)
  436. {
  437. svs.last_heartbeat = -9999;
  438. }
  439. void SV_SendServerInfoChange(char *key, char *value)
  440. {
  441. if (!sv.state)
  442. return;
  443. MSG_WriteByte (&sv.reliable_datagram, svc_serverinfo);
  444. MSG_WriteString (&sv.reliable_datagram, key);
  445. MSG_WriteString (&sv.reliable_datagram, value);
  446. }
  447. /*
  448. ===========
  449. SV_Serverinfo_f
  450. Examine or change the serverinfo string
  451. ===========
  452. */
  453. char *CopyString(char *s);
  454. void SV_Serverinfo_f (void)
  455. {
  456. cvar_t *var;
  457. if (Cmd_Argc() == 1)
  458. {
  459. Con_Printf ("Server info settings:\n");
  460. Info_Print (svs.info);
  461. return;
  462. }
  463. if (Cmd_Argc() != 3)
  464. {
  465. Con_Printf ("usage: serverinfo [ <key> <value> ]\n");
  466. return;
  467. }
  468. if (Cmd_Argv(1)[0] == '*')
  469. {
  470. Con_Printf ("Star variables cannot be changed.\n");
  471. return;
  472. }
  473. Info_SetValueForKey (svs.info, Cmd_Argv(1), Cmd_Argv(2), MAX_SERVERINFO_STRING);
  474. // if this is a cvar, change it too
  475. var = Cvar_FindVar (Cmd_Argv(1));
  476. if (var)
  477. {
  478. Z_Free (var->string); // free the old value string
  479. var->string = CopyString (Cmd_Argv(2));
  480. var->value = Q_atof (var->string);
  481. }
  482. SV_SendServerInfoChange(Cmd_Argv(1), Cmd_Argv(2));
  483. }
  484. /*
  485. ===========
  486. SV_Serverinfo_f
  487. Examine or change the serverinfo string
  488. ===========
  489. */
  490. char *CopyString(char *s);
  491. void SV_Localinfo_f (void)
  492. {
  493. if (Cmd_Argc() == 1)
  494. {
  495. Con_Printf ("Local info settings:\n");
  496. Info_Print (localinfo);
  497. return;
  498. }
  499. if (Cmd_Argc() != 3)
  500. {
  501. Con_Printf ("usage: localinfo [ <key> <value> ]\n");
  502. return;
  503. }
  504. if (Cmd_Argv(1)[0] == '*')
  505. {
  506. Con_Printf ("Star variables cannot be changed.\n");
  507. return;
  508. }
  509. Info_SetValueForKey (localinfo, Cmd_Argv(1), Cmd_Argv(2), MAX_LOCALINFO_STRING);
  510. }
  511. /*
  512. ===========
  513. SV_User_f
  514. Examine a users info strings
  515. ===========
  516. */
  517. void SV_User_f (void)
  518. {
  519. if (Cmd_Argc() != 2)
  520. {
  521. Con_Printf ("Usage: info <userid>\n");
  522. return;
  523. }
  524. if (!SV_SetPlayer ())
  525. return;
  526. Info_Print (host_client->userinfo);
  527. }
  528. /*
  529. ================
  530. SV_Gamedir
  531. Sets the fake *gamedir to a different directory.
  532. ================
  533. */
  534. void SV_Gamedir (void)
  535. {
  536. char *dir;
  537. if (Cmd_Argc() == 1)
  538. {
  539. Con_Printf ("Current *gamedir: %s\n", Info_ValueForKey (svs.info, "*gamedir"));
  540. return;
  541. }
  542. if (Cmd_Argc() != 2)
  543. {
  544. Con_Printf ("Usage: sv_gamedir <newgamedir>\n");
  545. return;
  546. }
  547. dir = Cmd_Argv(1);
  548. if (strstr(dir, "..") || strstr(dir, "/")
  549. || strstr(dir, "\\") || strstr(dir, ":") )
  550. {
  551. Con_Printf ("*Gamedir should be a single filename, not a path\n");
  552. return;
  553. }
  554. Info_SetValueForStarKey (svs.info, "*gamedir", dir, MAX_SERVERINFO_STRING);
  555. }
  556. /*
  557. ================
  558. SV_Floodport_f
  559. Sets the gamedir and path to a different directory.
  560. ================
  561. */
  562. void SV_Floodprot_f (void)
  563. {
  564. int arg1, arg2, arg3;
  565. if (Cmd_Argc() == 1)
  566. {
  567. if (fp_messages) {
  568. Con_Printf ("Current floodprot settings: \nAfter %d msgs per %d seconds, silence for %d seconds\n",
  569. fp_messages, fp_persecond, fp_secondsdead);
  570. return;
  571. } else
  572. Con_Printf ("No floodprots enabled.\n");
  573. }
  574. if (Cmd_Argc() != 4)
  575. {
  576. Con_Printf ("Usage: floodprot <# of messages> <per # of seconds> <seconds to silence>\n");
  577. Con_Printf ("Use floodprotmsg to set a custom message to say to the flooder.\n");
  578. return;
  579. }
  580. arg1 = atoi(Cmd_Argv(1));
  581. arg2 = atoi(Cmd_Argv(2));
  582. arg3 = atoi(Cmd_Argv(3));
  583. if (arg1<=0 || arg2 <= 0 || arg3<=0) {
  584. Con_Printf ("All values must be positive numbers\n");
  585. return;
  586. }
  587. if (arg1 > 10) {
  588. Con_Printf ("Can only track up to 10 messages.\n");
  589. return;
  590. }
  591. fp_messages = arg1;
  592. fp_persecond = arg2;
  593. fp_secondsdead = arg3;
  594. }
  595. void SV_Floodprotmsg_f (void)
  596. {
  597. if (Cmd_Argc() == 1) {
  598. Con_Printf("Current msg: %s\n", fp_msg);
  599. return;
  600. } else if (Cmd_Argc() != 2) {
  601. Con_Printf("Usage: floodprotmsg \"<message>\"\n");
  602. return;
  603. }
  604. sprintf(fp_msg, "%s", Cmd_Argv(1));
  605. }
  606. /*
  607. ================
  608. SV_Gamedir_f
  609. Sets the gamedir and path to a different directory.
  610. ================
  611. */
  612. char gamedirfile[MAX_OSPATH];
  613. void SV_Gamedir_f (void)
  614. {
  615. char *dir;
  616. if (Cmd_Argc() == 1)
  617. {
  618. Con_Printf ("Current gamedir: %s\n", com_gamedir);
  619. return;
  620. }
  621. if (Cmd_Argc() != 2)
  622. {
  623. Con_Printf ("Usage: gamedir <newdir>\n");
  624. return;
  625. }
  626. dir = Cmd_Argv(1);
  627. if (strstr(dir, "..") || strstr(dir, "/")
  628. || strstr(dir, "\\") || strstr(dir, ":") )
  629. {
  630. Con_Printf ("Gamedir should be a single filename, not a path\n");
  631. return;
  632. }
  633. COM_Gamedir (dir);
  634. Info_SetValueForStarKey (svs.info, "*gamedir", dir, MAX_SERVERINFO_STRING);
  635. }
  636. /*
  637. ================
  638. SV_Snap
  639. ================
  640. */
  641. void SV_Snap (int uid)
  642. {
  643. client_t *cl;
  644. char pcxname[80];
  645. char checkname[MAX_OSPATH];
  646. int i;
  647. for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++)
  648. {
  649. if (!cl->state)
  650. continue;
  651. if (cl->userid == uid)
  652. break;
  653. }
  654. if (i >= MAX_CLIENTS) {
  655. Con_Printf ("userid not found\n");
  656. return;
  657. }
  658. sprintf(pcxname, "%d-00.pcx", uid);
  659. sprintf(checkname, "%s/snap", gamedirfile);
  660. Sys_mkdir(gamedirfile);
  661. Sys_mkdir(checkname);
  662. for (i=0 ; i<=99 ; i++)
  663. {
  664. pcxname[strlen(pcxname) - 6] = i/10 + '0';
  665. pcxname[strlen(pcxname) - 5] = i%10 + '0';
  666. sprintf (checkname, "%s/snap/%s", gamedirfile, pcxname);
  667. if (Sys_FileTime(checkname) == -1)
  668. break; // file doesn't exist
  669. }
  670. if (i==100)
  671. {
  672. Con_Printf ("Snap: Couldn't create a file, clean some out.\n");
  673. return;
  674. }
  675. strcpy(cl->uploadfn, checkname);
  676. memcpy(&cl->snap_from, &net_from, sizeof(net_from));
  677. if (sv_redirected != RD_NONE)
  678. cl->remote_snap = true;
  679. else
  680. cl->remote_snap = false;
  681. ClientReliableWrite_Begin (cl, svc_stufftext, 24);
  682. ClientReliableWrite_String (cl, "cmd snap");
  683. Con_Printf ("Requesting snap from user %d...\n", uid);
  684. }
  685. /*
  686. ================
  687. SV_Snap_f
  688. ================
  689. */
  690. void SV_Snap_f (void)
  691. {
  692. int uid;
  693. if (Cmd_Argc() != 2)
  694. {
  695. Con_Printf ("Usage: snap <userid>\n");
  696. return;
  697. }
  698. uid = atoi(Cmd_Argv(1));
  699. SV_Snap(uid);
  700. }
  701. /*
  702. ================
  703. SV_Snap
  704. ================
  705. */
  706. void SV_SnapAll_f (void)
  707. {
  708. client_t *cl;
  709. int i;
  710. for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++)
  711. {
  712. if (cl->state < cs_connected || cl->spectator)
  713. continue;
  714. SV_Snap(cl->userid);
  715. }
  716. }
  717. /*
  718. ==================
  719. SV_InitOperatorCommands
  720. ==================
  721. */
  722. void SV_InitOperatorCommands (void)
  723. {
  724. if (COM_CheckParm ("-cheats"))
  725. {
  726. sv_allow_cheats = true;
  727. Info_SetValueForStarKey (svs.info, "*cheats", "ON", MAX_SERVERINFO_STRING);
  728. }
  729. Cmd_AddCommand ("logfile", SV_Logfile_f);
  730. Cmd_AddCommand ("fraglogfile", SV_Fraglogfile_f);
  731. Cmd_AddCommand ("snap", SV_Snap_f);
  732. Cmd_AddCommand ("snapall", SV_SnapAll_f);
  733. Cmd_AddCommand ("kick", SV_Kick_f);
  734. Cmd_AddCommand ("status", SV_Status_f);
  735. Cmd_AddCommand ("map", SV_Map_f);
  736. Cmd_AddCommand ("setmaster", SV_SetMaster_f);
  737. Cmd_AddCommand ("say", SV_ConSay_f);
  738. Cmd_AddCommand ("heartbeat", SV_Heartbeat_f);
  739. Cmd_AddCommand ("quit", SV_Quit_f);
  740. Cmd_AddCommand ("god", SV_God_f);
  741. Cmd_AddCommand ("give", SV_Give_f);
  742. Cmd_AddCommand ("noclip", SV_Noclip_f);
  743. Cmd_AddCommand ("serverinfo", SV_Serverinfo_f);
  744. Cmd_AddCommand ("localinfo", SV_Localinfo_f);
  745. Cmd_AddCommand ("user", SV_User_f);
  746. Cmd_AddCommand ("gamedir", SV_Gamedir_f);
  747. Cmd_AddCommand ("sv_gamedir", SV_Gamedir);
  748. Cmd_AddCommand ("floodprot", SV_Floodprot_f);
  749. Cmd_AddCommand ("floodprotmsg", SV_Floodprotmsg_f);
  750. cl_warncmd.value = 1;
  751. }