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