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