g_cmds.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. /*
  2. Copyright (C) 1997-2001 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 "g_local.h"
  16. #include "m_player.h"
  17. char *ClientTeam (edict_t *ent)
  18. {
  19. char *p;
  20. static char value[512];
  21. value[0] = 0;
  22. if (!ent->client)
  23. return value;
  24. strcpy(value, Info_ValueForKey (ent->client->pers.userinfo, "skin"));
  25. p = strchr(value, '/');
  26. if (!p)
  27. return value;
  28. if ((int)(dmflags->value) & DF_MODELTEAMS)
  29. {
  30. *p = 0;
  31. return value;
  32. }
  33. // if ((int)(dmflags->value) & DF_SKINTEAMS)
  34. return ++p;
  35. }
  36. qboolean OnSameTeam (edict_t *ent1, edict_t *ent2)
  37. {
  38. char ent1Team [512];
  39. char ent2Team [512];
  40. if (!((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
  41. return false;
  42. strcpy (ent1Team, ClientTeam (ent1));
  43. strcpy (ent2Team, ClientTeam (ent2));
  44. if (strcmp(ent1Team, ent2Team) == 0)
  45. return true;
  46. return false;
  47. }
  48. void SelectNextItem (edict_t *ent, int itflags)
  49. {
  50. gclient_t *cl;
  51. int i, index;
  52. gitem_t *it;
  53. cl = ent->client;
  54. if (cl->chase_target) {
  55. ChaseNext(ent);
  56. return;
  57. }
  58. // scan for the next valid one
  59. for (i=1 ; i<=MAX_ITEMS ; i++)
  60. {
  61. index = (cl->pers.selected_item + i)%MAX_ITEMS;
  62. if (!cl->pers.inventory[index])
  63. continue;
  64. it = &itemlist[index];
  65. if (!it->use)
  66. continue;
  67. if (!(it->flags & itflags))
  68. continue;
  69. cl->pers.selected_item = index;
  70. return;
  71. }
  72. cl->pers.selected_item = -1;
  73. }
  74. void SelectPrevItem (edict_t *ent, int itflags)
  75. {
  76. gclient_t *cl;
  77. int i, index;
  78. gitem_t *it;
  79. cl = ent->client;
  80. if (cl->chase_target) {
  81. ChasePrev(ent);
  82. return;
  83. }
  84. // scan for the next valid one
  85. for (i=1 ; i<=MAX_ITEMS ; i++)
  86. {
  87. index = (cl->pers.selected_item + MAX_ITEMS - i)%MAX_ITEMS;
  88. if (!cl->pers.inventory[index])
  89. continue;
  90. it = &itemlist[index];
  91. if (!it->use)
  92. continue;
  93. if (!(it->flags & itflags))
  94. continue;
  95. cl->pers.selected_item = index;
  96. return;
  97. }
  98. cl->pers.selected_item = -1;
  99. }
  100. void ValidateSelectedItem (edict_t *ent)
  101. {
  102. gclient_t *cl;
  103. cl = ent->client;
  104. if (cl->pers.inventory[cl->pers.selected_item])
  105. return; // valid
  106. SelectNextItem (ent, -1);
  107. }
  108. //=================================================================================
  109. /*
  110. ==================
  111. Cmd_Give_f
  112. Give items to a client
  113. ==================
  114. */
  115. void Cmd_Give_f (edict_t *ent)
  116. {
  117. char *name;
  118. gitem_t *it;
  119. int index;
  120. int i;
  121. qboolean give_all;
  122. edict_t *it_ent;
  123. if (deathmatch->value && !sv_cheats->value)
  124. {
  125. gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
  126. return;
  127. }
  128. name = gi.args();
  129. if (Q_stricmp(name, "all") == 0)
  130. give_all = true;
  131. else
  132. give_all = false;
  133. if (give_all || Q_stricmp(gi.argv(1), "health") == 0)
  134. {
  135. if (gi.argc() == 3)
  136. ent->health = atoi(gi.argv(2));
  137. else
  138. ent->health = ent->max_health;
  139. if (!give_all)
  140. return;
  141. }
  142. if (give_all || Q_stricmp(name, "weapons") == 0)
  143. {
  144. for (i=0 ; i<game.num_items ; i++)
  145. {
  146. it = itemlist + i;
  147. if (!it->pickup)
  148. continue;
  149. if (!(it->flags & IT_WEAPON))
  150. continue;
  151. ent->client->pers.inventory[i] += 1;
  152. }
  153. if (!give_all)
  154. return;
  155. }
  156. if (give_all || Q_stricmp(name, "ammo") == 0)
  157. {
  158. for (i=0 ; i<game.num_items ; i++)
  159. {
  160. it = itemlist + i;
  161. if (!it->pickup)
  162. continue;
  163. if (!(it->flags & IT_AMMO))
  164. continue;
  165. Add_Ammo (ent, it, 1000);
  166. }
  167. if (!give_all)
  168. return;
  169. }
  170. if (give_all || Q_stricmp(name, "armor") == 0)
  171. {
  172. gitem_armor_t *info;
  173. it = FindItem("Jacket Armor");
  174. ent->client->pers.inventory[ITEM_INDEX(it)] = 0;
  175. it = FindItem("Combat Armor");
  176. ent->client->pers.inventory[ITEM_INDEX(it)] = 0;
  177. it = FindItem("Body Armor");
  178. info = (gitem_armor_t *)it->info;
  179. ent->client->pers.inventory[ITEM_INDEX(it)] = info->max_count;
  180. if (!give_all)
  181. return;
  182. }
  183. if (give_all || Q_stricmp(name, "Power Shield") == 0)
  184. {
  185. it = FindItem("Power Shield");
  186. it_ent = G_Spawn();
  187. it_ent->classname = it->classname;
  188. SpawnItem (it_ent, it);
  189. Touch_Item (it_ent, ent, NULL, NULL);
  190. if (it_ent->inuse)
  191. G_FreeEdict(it_ent);
  192. if (!give_all)
  193. return;
  194. }
  195. if (give_all)
  196. {
  197. for (i=0 ; i<game.num_items ; i++)
  198. {
  199. it = itemlist + i;
  200. if (!it->pickup)
  201. continue;
  202. if (it->flags & (IT_ARMOR|IT_WEAPON|IT_AMMO))
  203. continue;
  204. ent->client->pers.inventory[i] = 1;
  205. }
  206. return;
  207. }
  208. it = FindItem (name);
  209. if (!it)
  210. {
  211. name = gi.argv(1);
  212. it = FindItem (name);
  213. if (!it)
  214. {
  215. gi.cprintf (ent, PRINT_HIGH, "unknown item\n");
  216. return;
  217. }
  218. }
  219. if (!it->pickup)
  220. {
  221. gi.cprintf (ent, PRINT_HIGH, "non-pickup item\n");
  222. return;
  223. }
  224. index = ITEM_INDEX(it);
  225. if (it->flags & IT_AMMO)
  226. {
  227. if (gi.argc() == 3)
  228. ent->client->pers.inventory[index] = atoi(gi.argv(2));
  229. else
  230. ent->client->pers.inventory[index] += it->quantity;
  231. }
  232. else
  233. {
  234. it_ent = G_Spawn();
  235. it_ent->classname = it->classname;
  236. SpawnItem (it_ent, it);
  237. Touch_Item (it_ent, ent, NULL, NULL);
  238. if (it_ent->inuse)
  239. G_FreeEdict(it_ent);
  240. }
  241. }
  242. /*
  243. ==================
  244. Cmd_God_f
  245. Sets client to godmode
  246. argv(0) god
  247. ==================
  248. */
  249. void Cmd_God_f (edict_t *ent)
  250. {
  251. char *msg;
  252. if (deathmatch->value && !sv_cheats->value)
  253. {
  254. gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
  255. return;
  256. }
  257. ent->flags ^= FL_GODMODE;
  258. if (!(ent->flags & FL_GODMODE) )
  259. msg = "godmode OFF\n";
  260. else
  261. msg = "godmode ON\n";
  262. gi.cprintf (ent, PRINT_HIGH, msg);
  263. }
  264. /*
  265. ==================
  266. Cmd_Notarget_f
  267. Sets client to notarget
  268. argv(0) notarget
  269. ==================
  270. */
  271. void Cmd_Notarget_f (edict_t *ent)
  272. {
  273. char *msg;
  274. if (deathmatch->value && !sv_cheats->value)
  275. {
  276. gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
  277. return;
  278. }
  279. ent->flags ^= FL_NOTARGET;
  280. if (!(ent->flags & FL_NOTARGET) )
  281. msg = "notarget OFF\n";
  282. else
  283. msg = "notarget ON\n";
  284. gi.cprintf (ent, PRINT_HIGH, msg);
  285. }
  286. /*
  287. ==================
  288. Cmd_Noclip_f
  289. argv(0) noclip
  290. ==================
  291. */
  292. void Cmd_Noclip_f (edict_t *ent)
  293. {
  294. char *msg;
  295. if (deathmatch->value && !sv_cheats->value)
  296. {
  297. gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
  298. return;
  299. }
  300. if (ent->movetype == MOVETYPE_NOCLIP)
  301. {
  302. ent->movetype = MOVETYPE_WALK;
  303. msg = "noclip OFF\n";
  304. }
  305. else
  306. {
  307. ent->movetype = MOVETYPE_NOCLIP;
  308. msg = "noclip ON\n";
  309. }
  310. gi.cprintf (ent, PRINT_HIGH, msg);
  311. }
  312. /*
  313. ==================
  314. Cmd_Use_f
  315. Use an inventory item
  316. ==================
  317. */
  318. void Cmd_Use_f (edict_t *ent)
  319. {
  320. int index;
  321. gitem_t *it;
  322. char *s;
  323. s = gi.args();
  324. it = FindItem (s);
  325. if (!it)
  326. {
  327. gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);
  328. return;
  329. }
  330. if (!it->use)
  331. {
  332. gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");
  333. return;
  334. }
  335. index = ITEM_INDEX(it);
  336. if (!ent->client->pers.inventory[index])
  337. {
  338. gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);
  339. return;
  340. }
  341. it->use (ent, it);
  342. }
  343. /*
  344. ==================
  345. Cmd_Drop_f
  346. Drop an inventory item
  347. ==================
  348. */
  349. void Cmd_Drop_f (edict_t *ent)
  350. {
  351. int index;
  352. gitem_t *it;
  353. char *s;
  354. s = gi.args();
  355. it = FindItem (s);
  356. if (!it)
  357. {
  358. gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);
  359. return;
  360. }
  361. if (!it->drop)
  362. {
  363. gi.cprintf (ent, PRINT_HIGH, "Item is not dropable.\n");
  364. return;
  365. }
  366. index = ITEM_INDEX(it);
  367. if (!ent->client->pers.inventory[index])
  368. {
  369. gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);
  370. return;
  371. }
  372. it->drop (ent, it);
  373. }
  374. /*
  375. =================
  376. Cmd_Inven_f
  377. =================
  378. */
  379. void Cmd_Inven_f (edict_t *ent)
  380. {
  381. int i;
  382. gclient_t *cl;
  383. cl = ent->client;
  384. cl->showscores = false;
  385. cl->showhelp = false;
  386. if (cl->showinventory)
  387. {
  388. cl->showinventory = false;
  389. return;
  390. }
  391. cl->showinventory = true;
  392. gi.WriteByte (svc_inventory);
  393. for (i=0 ; i<MAX_ITEMS ; i++)
  394. {
  395. gi.WriteShort (cl->pers.inventory[i]);
  396. }
  397. gi.unicast (ent, true);
  398. }
  399. /*
  400. =================
  401. Cmd_InvUse_f
  402. =================
  403. */
  404. void Cmd_InvUse_f (edict_t *ent)
  405. {
  406. gitem_t *it;
  407. ValidateSelectedItem (ent);
  408. if (ent->client->pers.selected_item == -1)
  409. {
  410. gi.cprintf (ent, PRINT_HIGH, "No item to use.\n");
  411. return;
  412. }
  413. it = &itemlist[ent->client->pers.selected_item];
  414. if (!it->use)
  415. {
  416. gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");
  417. return;
  418. }
  419. it->use (ent, it);
  420. }
  421. /*
  422. =================
  423. Cmd_WeapPrev_f
  424. =================
  425. */
  426. void Cmd_WeapPrev_f (edict_t *ent)
  427. {
  428. gclient_t *cl;
  429. int i, index;
  430. gitem_t *it;
  431. int selected_weapon;
  432. cl = ent->client;
  433. if (!cl->pers.weapon)
  434. return;
  435. selected_weapon = ITEM_INDEX(cl->pers.weapon);
  436. // scan for the next valid one
  437. for (i=1 ; i<=MAX_ITEMS ; i++)
  438. {
  439. index = (selected_weapon + i)%MAX_ITEMS;
  440. if (!cl->pers.inventory[index])
  441. continue;
  442. it = &itemlist[index];
  443. if (!it->use)
  444. continue;
  445. if (! (it->flags & IT_WEAPON) )
  446. continue;
  447. it->use (ent, it);
  448. if (cl->pers.weapon == it)
  449. return; // successful
  450. }
  451. }
  452. /*
  453. =================
  454. Cmd_WeapNext_f
  455. =================
  456. */
  457. void Cmd_WeapNext_f (edict_t *ent)
  458. {
  459. gclient_t *cl;
  460. int i, index;
  461. gitem_t *it;
  462. int selected_weapon;
  463. cl = ent->client;
  464. if (!cl->pers.weapon)
  465. return;
  466. selected_weapon = ITEM_INDEX(cl->pers.weapon);
  467. // scan for the next valid one
  468. for (i=1 ; i<=MAX_ITEMS ; i++)
  469. {
  470. index = (selected_weapon + MAX_ITEMS - i)%MAX_ITEMS;
  471. if (!cl->pers.inventory[index])
  472. continue;
  473. it = &itemlist[index];
  474. if (!it->use)
  475. continue;
  476. if (! (it->flags & IT_WEAPON) )
  477. continue;
  478. it->use (ent, it);
  479. if (cl->pers.weapon == it)
  480. return; // successful
  481. }
  482. }
  483. /*
  484. =================
  485. Cmd_WeapLast_f
  486. =================
  487. */
  488. void Cmd_WeapLast_f (edict_t *ent)
  489. {
  490. gclient_t *cl;
  491. int index;
  492. gitem_t *it;
  493. cl = ent->client;
  494. if (!cl->pers.weapon || !cl->pers.lastweapon)
  495. return;
  496. index = ITEM_INDEX(cl->pers.lastweapon);
  497. if (!cl->pers.inventory[index])
  498. return;
  499. it = &itemlist[index];
  500. if (!it->use)
  501. return;
  502. if (! (it->flags & IT_WEAPON) )
  503. return;
  504. it->use (ent, it);
  505. }
  506. /*
  507. =================
  508. Cmd_InvDrop_f
  509. =================
  510. */
  511. void Cmd_InvDrop_f (edict_t *ent)
  512. {
  513. gitem_t *it;
  514. ValidateSelectedItem (ent);
  515. if (ent->client->pers.selected_item == -1)
  516. {
  517. gi.cprintf (ent, PRINT_HIGH, "No item to drop.\n");
  518. return;
  519. }
  520. it = &itemlist[ent->client->pers.selected_item];
  521. if (!it->drop)
  522. {
  523. gi.cprintf (ent, PRINT_HIGH, "Item is not dropable.\n");
  524. return;
  525. }
  526. it->drop (ent, it);
  527. }
  528. /*
  529. =================
  530. Cmd_Kill_f
  531. =================
  532. */
  533. void Cmd_Kill_f (edict_t *ent)
  534. {
  535. if((level.time - ent->client->respawn_time) < 5)
  536. return;
  537. ent->flags &= ~FL_GODMODE;
  538. ent->health = 0;
  539. meansOfDeath = MOD_SUICIDE;
  540. player_die (ent, ent, ent, 100000, vec3_origin);
  541. }
  542. /*
  543. =================
  544. Cmd_PutAway_f
  545. =================
  546. */
  547. void Cmd_PutAway_f (edict_t *ent)
  548. {
  549. ent->client->showscores = false;
  550. ent->client->showhelp = false;
  551. ent->client->showinventory = false;
  552. }
  553. int PlayerSort (void const *a, void const *b)
  554. {
  555. int anum, bnum;
  556. anum = *(int *)a;
  557. bnum = *(int *)b;
  558. anum = game.clients[anum].ps.stats[STAT_FRAGS];
  559. bnum = game.clients[bnum].ps.stats[STAT_FRAGS];
  560. if (anum < bnum)
  561. return -1;
  562. if (anum > bnum)
  563. return 1;
  564. return 0;
  565. }
  566. /*
  567. =================
  568. Cmd_Players_f
  569. =================
  570. */
  571. void Cmd_Players_f (edict_t *ent)
  572. {
  573. int i;
  574. int count;
  575. char small[64];
  576. char large[1280];
  577. int index[256];
  578. count = 0;
  579. for (i = 0 ; i < maxclients->value ; i++)
  580. if (game.clients[i].pers.connected)
  581. {
  582. index[count] = i;
  583. count++;
  584. }
  585. // sort by frags
  586. qsort (index, count, sizeof(index[0]), PlayerSort);
  587. // print information
  588. large[0] = 0;
  589. for (i = 0 ; i < count ; i++)
  590. {
  591. Com_sprintf (small, sizeof(small), "%3i %s\n",
  592. game.clients[index[i]].ps.stats[STAT_FRAGS],
  593. game.clients[index[i]].pers.netname);
  594. if (strlen (small) + strlen(large) > sizeof(large) - 100 )
  595. { // can't print all of them in one packet
  596. strcat (large, "...\n");
  597. break;
  598. }
  599. strcat (large, small);
  600. }
  601. gi.cprintf (ent, PRINT_HIGH, "%s\n%i players\n", large, count);
  602. }
  603. /*
  604. =================
  605. Cmd_Wave_f
  606. =================
  607. */
  608. void Cmd_Wave_f (edict_t *ent)
  609. {
  610. int i;
  611. i = atoi (gi.argv(1));
  612. // can't wave when ducked
  613. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  614. return;
  615. if (ent->client->anim_priority > ANIM_WAVE)
  616. return;
  617. ent->client->anim_priority = ANIM_WAVE;
  618. switch (i)
  619. {
  620. case 0:
  621. gi.cprintf (ent, PRINT_HIGH, "flipoff\n");
  622. ent->s.frame = FRAME_flip01-1;
  623. ent->client->anim_end = FRAME_flip12;
  624. break;
  625. case 1:
  626. gi.cprintf (ent, PRINT_HIGH, "salute\n");
  627. ent->s.frame = FRAME_salute01-1;
  628. ent->client->anim_end = FRAME_salute11;
  629. break;
  630. case 2:
  631. gi.cprintf (ent, PRINT_HIGH, "taunt\n");
  632. ent->s.frame = FRAME_taunt01-1;
  633. ent->client->anim_end = FRAME_taunt17;
  634. break;
  635. case 3:
  636. gi.cprintf (ent, PRINT_HIGH, "wave\n");
  637. ent->s.frame = FRAME_wave01-1;
  638. ent->client->anim_end = FRAME_wave11;
  639. break;
  640. case 4:
  641. default:
  642. gi.cprintf (ent, PRINT_HIGH, "point\n");
  643. ent->s.frame = FRAME_point01-1;
  644. ent->client->anim_end = FRAME_point12;
  645. break;
  646. }
  647. }
  648. /*
  649. ==================
  650. Cmd_Say_f
  651. ==================
  652. */
  653. void Cmd_Say_f (edict_t *ent, qboolean team, qboolean arg0)
  654. {
  655. int i, j;
  656. edict_t *other;
  657. char *p;
  658. char text[2048];
  659. gclient_t *cl;
  660. if (gi.argc () < 2 && !arg0)
  661. return;
  662. if (!((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
  663. team = false;
  664. if (team)
  665. Com_sprintf (text, sizeof(text), "(%s): ", ent->client->pers.netname);
  666. else
  667. Com_sprintf (text, sizeof(text), "%s: ", ent->client->pers.netname);
  668. if (arg0)
  669. {
  670. strcat (text, gi.argv(0));
  671. strcat (text, " ");
  672. strcat (text, gi.args());
  673. }
  674. else
  675. {
  676. p = gi.args();
  677. if (*p == '"')
  678. {
  679. p++;
  680. p[strlen(p)-1] = 0;
  681. }
  682. strcat(text, p);
  683. }
  684. // don't let text be too long for malicious reasons
  685. if (strlen(text) > 150)
  686. text[150] = 0;
  687. strcat(text, "\n");
  688. if (flood_msgs->value) {
  689. cl = ent->client;
  690. if (level.time < cl->flood_locktill) {
  691. gi.cprintf(ent, PRINT_HIGH, "You can't talk for %d more seconds\n",
  692. (int)(cl->flood_locktill - level.time));
  693. return;
  694. }
  695. i = cl->flood_whenhead - flood_msgs->value + 1;
  696. if (i < 0)
  697. i = (sizeof(cl->flood_when)/sizeof(cl->flood_when[0])) + i;
  698. if (cl->flood_when[i] &&
  699. level.time - cl->flood_when[i] < flood_persecond->value) {
  700. cl->flood_locktill = level.time + flood_waitdelay->value;
  701. gi.cprintf(ent, PRINT_CHAT, "Flood protection: You can't talk for %d seconds.\n",
  702. (int)flood_waitdelay->value);
  703. return;
  704. }
  705. cl->flood_whenhead = (cl->flood_whenhead + 1) %
  706. (sizeof(cl->flood_when)/sizeof(cl->flood_when[0]));
  707. cl->flood_when[cl->flood_whenhead] = level.time;
  708. }
  709. if (dedicated->value)
  710. gi.cprintf(NULL, PRINT_CHAT, "%s", text);
  711. for (j = 1; j <= game.maxclients; j++)
  712. {
  713. other = &g_edicts[j];
  714. if (!other->inuse)
  715. continue;
  716. if (!other->client)
  717. continue;
  718. if (team)
  719. {
  720. if (!OnSameTeam(ent, other))
  721. continue;
  722. }
  723. gi.cprintf(other, PRINT_CHAT, "%s", text);
  724. }
  725. }
  726. void Cmd_PlayerList_f(edict_t *ent)
  727. {
  728. int i;
  729. char st[80];
  730. char text[1400];
  731. edict_t *e2;
  732. // connect time, ping, score, name
  733. *text = 0;
  734. for (i = 0, e2 = g_edicts + 1; i < maxclients->value; i++, e2++) {
  735. if (!e2->inuse)
  736. continue;
  737. sprintf(st, "%02d:%02d %4d %3d %s%s\n",
  738. (level.framenum - e2->client->resp.enterframe) / 600,
  739. ((level.framenum - e2->client->resp.enterframe) % 600)/10,
  740. e2->client->ping,
  741. e2->client->resp.score,
  742. e2->client->pers.netname,
  743. e2->client->resp.spectator ? " (spectator)" : "");
  744. if (strlen(text) + strlen(st) > sizeof(text) - 50) {
  745. sprintf(text+strlen(text), "And more...\n");
  746. gi.cprintf(ent, PRINT_HIGH, "%s", text);
  747. return;
  748. }
  749. strcat(text, st);
  750. }
  751. gi.cprintf(ent, PRINT_HIGH, "%s", text);
  752. }
  753. /*
  754. =================
  755. ClientCommand
  756. =================
  757. */
  758. void ClientCommand (edict_t *ent)
  759. {
  760. char *cmd;
  761. if (!ent->client)
  762. return; // not fully in game yet
  763. cmd = gi.argv(0);
  764. if (Q_stricmp (cmd, "players") == 0)
  765. {
  766. Cmd_Players_f (ent);
  767. return;
  768. }
  769. if (Q_stricmp (cmd, "say") == 0)
  770. {
  771. Cmd_Say_f (ent, false, false);
  772. return;
  773. }
  774. if (Q_stricmp (cmd, "say_team") == 0)
  775. {
  776. Cmd_Say_f (ent, true, false);
  777. return;
  778. }
  779. if (Q_stricmp (cmd, "score") == 0)
  780. {
  781. Cmd_Score_f (ent);
  782. return;
  783. }
  784. if (Q_stricmp (cmd, "help") == 0)
  785. {
  786. Cmd_Help_f (ent);
  787. return;
  788. }
  789. if (level.intermissiontime)
  790. return;
  791. if (Q_stricmp (cmd, "use") == 0)
  792. Cmd_Use_f (ent);
  793. else if (Q_stricmp (cmd, "drop") == 0)
  794. Cmd_Drop_f (ent);
  795. else if (Q_stricmp (cmd, "give") == 0)
  796. Cmd_Give_f (ent);
  797. else if (Q_stricmp (cmd, "god") == 0)
  798. Cmd_God_f (ent);
  799. else if (Q_stricmp (cmd, "notarget") == 0)
  800. Cmd_Notarget_f (ent);
  801. else if (Q_stricmp (cmd, "noclip") == 0)
  802. Cmd_Noclip_f (ent);
  803. else if (Q_stricmp (cmd, "inven") == 0)
  804. Cmd_Inven_f (ent);
  805. else if (Q_stricmp (cmd, "invnext") == 0)
  806. SelectNextItem (ent, -1);
  807. else if (Q_stricmp (cmd, "invprev") == 0)
  808. SelectPrevItem (ent, -1);
  809. else if (Q_stricmp (cmd, "invnextw") == 0)
  810. SelectNextItem (ent, IT_WEAPON);
  811. else if (Q_stricmp (cmd, "invprevw") == 0)
  812. SelectPrevItem (ent, IT_WEAPON);
  813. else if (Q_stricmp (cmd, "invnextp") == 0)
  814. SelectNextItem (ent, IT_POWERUP);
  815. else if (Q_stricmp (cmd, "invprevp") == 0)
  816. SelectPrevItem (ent, IT_POWERUP);
  817. else if (Q_stricmp (cmd, "invuse") == 0)
  818. Cmd_InvUse_f (ent);
  819. else if (Q_stricmp (cmd, "invdrop") == 0)
  820. Cmd_InvDrop_f (ent);
  821. else if (Q_stricmp (cmd, "weapprev") == 0)
  822. Cmd_WeapPrev_f (ent);
  823. else if (Q_stricmp (cmd, "weapnext") == 0)
  824. Cmd_WeapNext_f (ent);
  825. else if (Q_stricmp (cmd, "weaplast") == 0)
  826. Cmd_WeapLast_f (ent);
  827. else if (Q_stricmp (cmd, "kill") == 0)
  828. Cmd_Kill_f (ent);
  829. else if (Q_stricmp (cmd, "putaway") == 0)
  830. Cmd_PutAway_f (ent);
  831. else if (Q_stricmp (cmd, "wave") == 0)
  832. Cmd_Wave_f (ent);
  833. else if (Q_stricmp(cmd, "playerlist") == 0)
  834. Cmd_PlayerList_f(ent);
  835. else // anything that doesn't match a command will be a chat
  836. Cmd_Say_f (ent, false, true);
  837. }