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 */
Cmd_Use_f(edict_t * ent)377 void Cmd_Use_f (edict_t *ent)
378 {
379 	int			index;
380 	gitem_t		*it;
381 	char		*s;
382 
383 	s = gi.args();
384 	it = FindItem (s);
385 	if (!it)
386 	{
387 		gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);
388 		return;
389 	}
390 	if (!it->use)
391 	{
392 		gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");
393 		return;
394 	}
395 	index = ITEM_INDEX(it);
396 	if (!ent->client->pers.inventory[index])
397 	{
398 		gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);
399 		return;
400 	}
401 
402 	it->use (ent, it);
403 }
404 
405 
406 /*
407 ==================
408 Cmd_Drop_f
409 
410 Drop an inventory item
411 ==================
412 */
Cmd_Drop_f(edict_t * ent)413 void Cmd_Drop_f (edict_t *ent)
414 {
415 	int			index;
416 	gitem_t		*it;
417 	char		*s;
418 
419 	s = gi.args();
420 	it = FindItem (s);
421 	if (!it)
422 	{
423 		gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);
424 		return;
425 	}
426 	if (!it->drop)
427 	{
428 		gi.cprintf (ent, PRINT_HIGH, "Item is not dropable.\n");
429 		return;
430 	}
431 	index = ITEM_INDEX(it);
432 	if (!ent->client->pers.inventory[index])
433 	{
434 		gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);
435 		return;
436 	}
437 
438 	it->drop (ent, it);
439 }
440 
441 
442 /*
443 =================
444 Cmd_Inven_f
445 =================
446 */
Cmd_Inven_f(edict_t * ent)447 void Cmd_Inven_f (edict_t *ent)
448 {
449 	int			i;
450 	gclient_t	*cl;
451 
452 	cl = ent->client;
453 
454 	cl->showscores = false;
455 	cl->showhelp = false;
456 
457 	if (cl->showinventory)
458 	{
459 		cl->showinventory = false;
460 		return;
461 	}
462 
463 	cl->showinventory = true;
464 
465 	gi.WriteByte (svc_inventory);
466 	for (i=0 ; i<MAX_ITEMS ; i++)
467 	{
468 		gi.WriteShort (cl->pers.inventory[i]);
469 	}
470 	gi.unicast (ent, true);
471 }
472 
473 /*
474 =================
475 Cmd_InvUse_f
476 =================
477 */
Cmd_InvUse_f(edict_t * ent)478 void Cmd_InvUse_f (edict_t *ent)
479 {
480 	gitem_t		*it;
481 
482 	ValidateSelectedItem (ent);
483 
484 	if (ent->client->pers.selected_item == -1)
485 	{
486 		gi.cprintf (ent, PRINT_HIGH, "No item to use.\n");
487 		return;
488 	}
489 
490 	it = &itemlist[ent->client->pers.selected_item];
491 	if (!it->use)
492 	{
493 		gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");
494 		return;
495 	}
496 	it->use (ent, it);
497 }
498 
499 /*
500 =================
501 Cmd_WeapPrev_f
502 =================
503 */
Cmd_WeapPrev_f(edict_t * ent)504 void Cmd_WeapPrev_f (edict_t *ent)
505 {
506 	gclient_t	*cl;
507 	int			i, index;
508 	gitem_t		*it;
509 	int			selected_weapon;
510 
511 	cl = ent->client;
512 
513 	if (!cl->pers.weapon)
514 		return;
515 
516 	selected_weapon = ITEM_INDEX(cl->pers.weapon);
517 
518 	// scan  for the next valid one
519 	for (i=1 ; i<=MAX_ITEMS ; i++)
520 	{
521 		index = (selected_weapon + i)%MAX_ITEMS;
522 		if (!cl->pers.inventory[index])
523 			continue;
524 		it = &itemlist[index];
525 		if (!it->use)
526 			continue;
527 		if (! (it->flags & IT_WEAPON) )
528 			continue;
529 		it->use (ent, it);
530 		if (cl->pers.weapon == it)
531 			return;	// successful
532 	}
533 }
534 
535 /*
536 =================
537 Cmd_WeapNext_f
538 =================
539 */
Cmd_WeapNext_f(edict_t * ent)540 void Cmd_WeapNext_f (edict_t *ent)
541 {
542 	gclient_t	*cl;
543 	int			i, index;
544 	gitem_t		*it;
545 	int			selected_weapon;
546 
547 	cl = ent->client;
548 
549 	if (!cl->pers.weapon)
550 		return;
551 
552 	selected_weapon = ITEM_INDEX(cl->pers.weapon);
553 
554 	// scan  for the next valid one
555 	for (i=1 ; i<=MAX_ITEMS ; i++)
556 	{
557 		index = (selected_weapon + MAX_ITEMS - i)%MAX_ITEMS;
558 		if (!cl->pers.inventory[index])
559 			continue;
560 		it = &itemlist[index];
561 		if (!it->use)
562 			continue;
563 		if (! (it->flags & IT_WEAPON) )
564 			continue;
565 		it->use (ent, it);
566 		if (cl->pers.weapon == it)
567 			return;	// successful
568 	}
569 }
570 
571 /*
572 =================
573 Cmd_WeapLast_f
574 =================
575 */
Cmd_WeapLast_f(edict_t * ent)576 void Cmd_WeapLast_f (edict_t *ent)
577 {
578 	gclient_t	*cl;
579 	int			index;
580 	gitem_t		*it;
581 
582 	cl = ent->client;
583 
584 	if (!cl->pers.weapon || !cl->pers.lastweapon)
585 		return;
586 
587 	index = ITEM_INDEX(cl->pers.lastweapon);
588 	if (!cl->pers.inventory[index])
589 		return;
590 	it = &itemlist[index];
591 	if (!it->use)
592 		return;
593 	if (! (it->flags & IT_WEAPON) )
594 		return;
595 	it->use (ent, it);
596 }
597 
598 /*
599 =================
600 Cmd_InvDrop_f
601 =================
602 */
Cmd_InvDrop_f(edict_t * ent)603 void Cmd_InvDrop_f (edict_t *ent)
604 {
605 	gitem_t		*it;
606 
607 	ValidateSelectedItem (ent);
608 
609 	if (ent->client->pers.selected_item == -1)
610 	{
611 		gi.cprintf (ent, PRINT_HIGH, "No item to drop.\n");
612 		return;
613 	}
614 
615 	it = &itemlist[ent->client->pers.selected_item];
616 	if (!it->drop)
617 	{
618 		gi.cprintf (ent, PRINT_HIGH, "Item is not dropable.\n");
619 		return;
620 	}
621 	it->drop (ent, it);
622 }
623 
624 /*
625 =================
626 Cmd_Kill_f
627 =================
628 */
Cmd_Kill_f(edict_t * ent)629 void Cmd_Kill_f (edict_t *ent)
630 {
631 	if((level.time - ent->client->respawn_time) < 5)
632 		return;
633 	ent->flags &= ~FL_GODMODE;
634 	ent->health = 0;
635 	meansOfDeath = MOD_SUICIDE;
636 	player_die (ent, ent, ent, 100000, vec3_origin);
637 }
638 
639 /*
640 =================
641 Cmd_PutAway_f
642 =================
643 */
Cmd_PutAway_f(edict_t * ent)644 void Cmd_PutAway_f (edict_t *ent)
645 {
646 	ent->client->showscores = false;
647 	ent->client->showhelp = false;
648 	ent->client->showinventory = false;
649 }
650 
651 
PlayerSort(void const * a,void const * b)652 int PlayerSort (void const *a, void const *b)
653 {
654 	int		anum, bnum;
655 
656 	anum = *(int *)a;
657 	bnum = *(int *)b;
658 
659 	anum = game.clients[anum].ps.stats[STAT_FRAGS];
660 	bnum = game.clients[bnum].ps.stats[STAT_FRAGS];
661 
662 	if (anum < bnum)
663 		return -1;
664 	if (anum > bnum)
665 		return 1;
666 	return 0;
667 }
668 
669 /*
670 =================
671 Cmd_Players_f
672 =================
673 */
Cmd_Players_f(edict_t * ent)674 void Cmd_Players_f (edict_t *ent)
675 {
676 	int		i;
677 	int		count;
678 	char	small[64];
679 	char	large[1280];
680 	int		index[256];
681 
682 	count = 0;
683 	for (i = 0 ; i < maxclients->value ; i++)
684 		if (game.clients[i].pers.connected)
685 		{
686 			index[count] = i;
687 			count++;
688 		}
689 
690 	// sort by frags
691 	qsort (index, count, sizeof(index[0]), PlayerSort);
692 
693 	// print information
694 	large[0] = 0;
695 
696 	for (i = 0 ; i < count ; i++)
697 	{
698 		Com_sprintf (small, sizeof(small), "%3i %s\n",
699 			game.clients[index[i]].ps.stats[STAT_FRAGS],
700 			game.clients[index[i]].pers.netname);
701 		if (strlen (small) + strlen(large) > sizeof(large) - 100 )
702 		{	// can't print all of them in one packet
703 			strcat (large, "...\n");
704 			break;
705 		}
706 		strcat (large, small);
707 	}
708 
709 	gi.cprintf (ent, PRINT_HIGH, "%s\n%i players\n", large, count);
710 }
711 
712 /*
713 =================
714 Cmd_Wave_f
715 =================
716 */
Cmd_Wave_f(edict_t * ent)717 void Cmd_Wave_f (edict_t *ent)
718 {
719 	int		i;
720 
721 	i = atoi (gi.argv(1));
722 
723 	// can't wave when ducked
724 	if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
725 		return;
726 
727 	if (ent->client->anim_priority > ANIM_WAVE)
728 		return;
729 
730 	ent->client->anim_priority = ANIM_WAVE;
731 
732 	switch (i)
733 	{
734 	case 0:
735 		gi.cprintf (ent, PRINT_HIGH, "flipoff\n");
736 		ent->s.frame = FRAME_flip01-1;
737 		ent->client->anim_end = FRAME_flip12;
738 		break;
739 	case 1:
740 		gi.cprintf (ent, PRINT_HIGH, "salute\n");
741 		ent->s.frame = FRAME_salute01-1;
742 		ent->client->anim_end = FRAME_salute11;
743 		break;
744 	case 2:
745 		gi.cprintf (ent, PRINT_HIGH, "taunt\n");
746 		ent->s.frame = FRAME_taunt01-1;
747 		ent->client->anim_end = FRAME_taunt17;
748 		break;
749 	case 3:
750 		gi.cprintf (ent, PRINT_HIGH, "wave\n");
751 		ent->s.frame = FRAME_wave01-1;
752 		ent->client->anim_end = FRAME_wave11;
753 		break;
754 	case 4:
755 	default:
756 		gi.cprintf (ent, PRINT_HIGH, "point\n");
757 		ent->s.frame = FRAME_point01-1;
758 		ent->client->anim_end = FRAME_point12;
759 		break;
760 	}
761 }
762 
763 /*
764 ==================
765 Cmd_Say_f
766 ==================
767 */
Cmd_Say_f(edict_t * ent,qboolean team,qboolean arg0)768 void Cmd_Say_f (edict_t *ent, qboolean team, qboolean arg0)
769 {
770 	int		i, j;
771 	edict_t	*other;
772 	char	*p;
773 	char	text[2048];
774 	gclient_t *cl;
775 
776 	if (gi.argc () < 2 && !arg0)
777 		return;
778 
779 	if (!((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
780 		team = false;
781 
782 	if (team)
783 		Com_sprintf (text, sizeof(text), "(%s): ", ent->client->pers.netname);
784 	else
785 		Com_sprintf (text, sizeof(text), "%s: ", ent->client->pers.netname);
786 
787 	if (arg0)
788 	{
789 		strcat (text, gi.argv(0));
790 		strcat (text, " ");
791 		strcat (text, gi.args());
792 	}
793 	else
794 	{
795 		p = gi.args();
796 
797 		if (*p == '"')
798 		{
799 			p++;
800 			p[strlen(p)-1] = 0;
801 		}
802 		strcat(text, p);
803 	}
804 
805 	// don't let text be too long for malicious reasons
806 	if (strlen(text) > 150)
807 		text[150] = 0;
808 
809 	strcat(text, "\n");
810 
811 	if (flood_msgs->value) {
812 		cl = ent->client;
813 
814         if (level.time < cl->flood_locktill) {
815 			gi.cprintf(ent, PRINT_HIGH, "You can't talk for %d more seconds\n",
816 				(int)(cl->flood_locktill - level.time));
817             return;
818         }
819         i = cl->flood_whenhead - flood_msgs->value + 1;
820         if (i < 0)
821             i = (sizeof(cl->flood_when)/sizeof(cl->flood_when[0])) + i;
822 		if (cl->flood_when[i] &&
823 			level.time - cl->flood_when[i] < flood_persecond->value) {
824 			cl->flood_locktill = level.time + flood_waitdelay->value;
825 			gi.cprintf(ent, PRINT_CHAT, "Flood protection:  You can't talk for %d seconds.\n",
826 				(int)flood_waitdelay->value);
827             return;
828         }
829 		cl->flood_whenhead = (cl->flood_whenhead + 1) %
830 			(sizeof(cl->flood_when)/sizeof(cl->flood_when[0]));
831 		cl->flood_when[cl->flood_whenhead] = level.time;
832 	}
833 
834 	if (dedicated->value)
835 		gi.cprintf(NULL, PRINT_CHAT, "%s", text);
836 
837 	for (j = 1; j <= game.maxclients; j++)
838 	{
839 		other = &g_edicts[j];
840 		if (!other->inuse)
841 			continue;
842 		if (!other->client)
843 			continue;
844 		if (team)
845 		{
846 			if (!OnSameTeam(ent, other))
847 				continue;
848 		}
849 		gi.cprintf(other, PRINT_CHAT, "%s", text);
850 	}
851 }
852 
Cmd_PlayerList_f(edict_t * ent)853 void Cmd_PlayerList_f(edict_t *ent)
854 {
855 	int i;
856 	char st[80];
857 	char text[1400];
858 	edict_t *e2;
859 
860 	// connect time, ping, score, name
861 	*text = 0;
862 	for (i = 0, e2 = g_edicts + 1; i < maxclients->value; i++, e2++) {
863 		if (!e2->inuse)
864 			continue;
865 
866 		Com_sprintf(st, sizeof(st), "%02d:%02d %4d %3d %s%s\n",
867 			(level.framenum - e2->client->resp.enterframe) / 600,
868 			((level.framenum - e2->client->resp.enterframe) % 600)/10,
869 			e2->client->ping,
870 			e2->client->resp.score,
871 			e2->client->pers.netname,
872 			e2->client->resp.spectator ? " (spectator)" : "");
873 		if (strlen(text) + strlen(st) > sizeof(text) - 50) {
874 			sprintf(text+strlen(text), "And more...\n");
875 			gi.cprintf(ent, PRINT_HIGH, "%s", text);
876 			return;
877 		}
878 		strcat(text, st);
879 	}
880 	gi.cprintf(ent, PRINT_HIGH, "%s", text);
881 }
882 
883 
884 /*
885 =================
886 ClientCommand
887 =================
888 */
ClientCommand(edict_t * ent)889 void ClientCommand (edict_t *ent)
890 {
891 	char	*cmd;
892 
893 	if (!ent->client)
894 		return;		// not fully in game yet
895 
896 	cmd = gi.argv(0);
897 
898 	if (Q_stricmp (cmd, "players") == 0)
899 	{
900 		Cmd_Players_f (ent);
901 		return;
902 	}
903 	if (Q_stricmp (cmd, "say") == 0)
904 	{
905 		Cmd_Say_f (ent, false, false);
906 		return;
907 	}
908 	if (Q_stricmp (cmd, "say_team") == 0)
909 	{
910 		Cmd_Say_f (ent, true, false);
911 		return;
912 	}
913 	if (Q_stricmp (cmd, "score") == 0)
914 	{
915 		Cmd_Score_f (ent);
916 		return;
917 	}
918 	if (Q_stricmp (cmd, "help") == 0)
919 	{
920 		Cmd_Help_f (ent);
921 		return;
922 	}
923 
924 	if (level.intermissiontime)
925 		return;
926 
927 	if (Q_stricmp (cmd, "use") == 0)
928 		Cmd_Use_f (ent);
929 	else if (Q_stricmp (cmd, "drop") == 0)
930 		Cmd_Drop_f (ent);
931 	else if (Q_stricmp (cmd, "give") == 0)
932 		Cmd_Give_f (ent);
933 	else if (Q_stricmp (cmd, "god") == 0)
934 		Cmd_God_f (ent);
935 	else if (Q_stricmp (cmd, "notarget") == 0)
936 		Cmd_Notarget_f (ent);
937 	else if (Q_stricmp (cmd, "noclip") == 0)
938 		Cmd_Noclip_f (ent);
939 	else if (Q_stricmp (cmd, "inven") == 0)
940 		Cmd_Inven_f (ent);
941 	else if (Q_stricmp (cmd, "invnext") == 0)
942 		SelectNextItem (ent, -1);
943 	else if (Q_stricmp (cmd, "invprev") == 0)
944 		SelectPrevItem (ent, -1);
945 	else if (Q_stricmp (cmd, "invnextw") == 0)
946 		SelectNextItem (ent, IT_WEAPON);
947 	else if (Q_stricmp (cmd, "invprevw") == 0)
948 		SelectPrevItem (ent, IT_WEAPON);
949 	else if (Q_stricmp (cmd, "invnextp") == 0)
950 		SelectNextItem (ent, IT_POWERUP);
951 	else if (Q_stricmp (cmd, "invprevp") == 0)
952 		SelectPrevItem (ent, IT_POWERUP);
953 	else if (Q_stricmp (cmd, "invuse") == 0)
954 		Cmd_InvUse_f (ent);
955 	else if (Q_stricmp (cmd, "invdrop") == 0)
956 		Cmd_InvDrop_f (ent);
957 	else if (Q_stricmp (cmd, "weapprev") == 0)
958 		Cmd_WeapPrev_f (ent);
959 	else if (Q_stricmp (cmd, "weapnext") == 0)
960 		Cmd_WeapNext_f (ent);
961 	else if (Q_stricmp (cmd, "weaplast") == 0)
962 		Cmd_WeapLast_f (ent);
963 	else if (Q_stricmp (cmd, "kill") == 0)
964 		Cmd_Kill_f (ent);
965 	else if (Q_stricmp (cmd, "putaway") == 0)
966 		Cmd_PutAway_f (ent);
967 	else if (Q_stricmp (cmd, "wave") == 0)
968 		Cmd_Wave_f (ent);
969 	else if (Q_stricmp(cmd, "playerlist") == 0)
970 		Cmd_PlayerList_f(ent);
971 	else	// anything that doesn't match a command will be a chat
972 		Cmd_Say_f (ent, false, true);
973 }
974