g_cmds.c 19 KB

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