Skip to content

Commit

Permalink
Add lock team and force team all commands
Browse files Browse the repository at this point in the history
  • Loading branch information
TriForceX committed Nov 23, 2023
1 parent 992f143 commit a568389
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 8 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ The version control structure on this project is `<mayor>.<minor>.<patch>` where

---

## 0.19.2
- Fix some emotes bugs due missing checks
- Fix spectator getting stuck in doors
- Fix plugin version check behavior
- Fix some compiling warnings
- Fix emote player box size when using chairs
- Fix duel glow with custom duel distance
- Fix force usage using emote chairs
- Changed player movements cvar name
- Merge updates from mvsdk
- Add current date to server news message
- Add option to ignore emotes from other players
- Add option to disable spawn on dimension change
- Add reset option for some menu items
- Add lock team and force team all commands

## 0.19.1
- Fix jetpack idle effect on die and some tweaks
- Fix mvapi level bump ahead of jk2mv release
Expand Down
9 changes: 8 additions & 1 deletion code/game/g_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,13 @@ void SetTeam( gentity_t *ent, char *s ) {
return;
}

// Tr!Force: [General] Check locked teams
if (level.jkmodLocals.lockedTeam[team])
{
trap_SendServerCommand(ent - g_entities, va("print \"Team %s%s%s is locked.\n\"", TeamColorString(team), JKMod_TeamName(team, CASE_NORMAL), S_COLOR_WHITE));
return;
}

//
// decide if we will allow the change
//
Expand Down Expand Up @@ -953,7 +960,7 @@ void Cmd_ForceChanged_f( gentity_t *ent )

strcpy(fpChStr, buf);

trap_SendServerCommand( ent-g_entities, va("print \"%s%s\n\n\"", S_COLOR_GREEN, fpChStr) );
trap_SendServerCommand( ent-g_entities, va("print \"%s%s\n\"", S_COLOR_GREEN, fpChStr) ); // Workaround

ent->client->ps.fd.forceDoInit = 1;
argCheck:
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_svcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Svcmd_ForceTeam_f
forceteam <player> <team>
===================
*/
void Svcmd_ForceTeam_f( void ) {
void BaseJK2_Svcmd_ForceTeam_f( void ) { // Tr!Force: [BaseJK2] Force team command function
gclient_t *cl;
char str[MAX_TOKEN_CHARS];

Expand Down
26 changes: 20 additions & 6 deletions jkmod/game/jk_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void JKMod_Cmd_HelpInfo(gentity_t *ent)
{
trap_SendServerCommand(ent - g_entities, va("print \""
"^5[^7 Admin ^5]^7\n"
"^7You can perform some console commands if you are logged as admin or by remote console\n"
"^7You can perform additional console commands if you are logged as admin or by remote console\n"
"^7For ^5rcon ^7commands you have to use the following sintax: ^2/rcon <command>\n"
"^5----------\n"
"^7Rcon commands:\n"
Expand All @@ -73,6 +73,8 @@ static void JKMod_Cmd_HelpInfo(gentity_t *ent)
"^3togglemod\n"
"^3teleport\n"
"^3forcedimension\n"
"^3forceteam\n"
"^3lockteam\n"
"^3whois\n"
"^3listdir\n"
"^5----------\n"
Expand Down Expand Up @@ -756,6 +758,15 @@ void JKMod_Cmd_WhoIs(gentity_t *ent)
{
int num;
const char *mapname = JKMod_GetCurrentMap();
team_t team;
char locked[MAX_STRING_CHARS] = { 0 };

for (team = 0; team < TEAM_NUM_TEAMS; team++)
{
if (level.jkmodLocals.lockedTeam[team]) Q_strcat(locked, sizeof(locked), va(" %s,", JKMod_TeamName(team, CASE_NORMAL)));
}

if (locked[0]) locked[strlen(locked) - 1] = '\0';

if (ent)
{
Expand All @@ -769,6 +780,8 @@ void JKMod_Cmd_WhoIs(gentity_t *ent)
"^7List of all players connected on the server\n"
"^7Client plugin status: ^2Valid^7, ^5Newer, ^3Older^7, ^1Invalid\n"
"^7\""));

if (locked[0]) trap_SendServerCommand(ent - g_entities, va("print \"Currently locked teams:%s\n\"", locked));

trap_SendServerCommand(ent - g_entities, va("print \""
"^5----------------------------------------------------------------------------------------------------------\n"
Expand All @@ -779,8 +792,9 @@ void JKMod_Cmd_WhoIs(gentity_t *ent)
else
{
G_Printf("Map: %s\n", mapname);
if (locked[0]) G_Printf("Locked Teams:%s\n", locked);
G_Printf("Num Name Type Dimension Plugin Game\n");
G_Printf("--- ---------------------------- ----- ------------ -------------- -----------\n");
G_Printf("--- ---------------------------- ----- ------------ --------------- ----------\n");
}

for (num = 0; num < level.maxclients; num++)
Expand Down Expand Up @@ -827,13 +841,13 @@ void JKMod_Cmd_WhoIs(gentity_t *ent)
if (ent)
{
if (JKMod_IgnoreClientCheck(2, ent->s.number, user->s.number)) {
Q_strcat(ignored, sizeof(ignored), va("Emote/", ignored));
Q_strcat(ignored, sizeof(ignored), "Emote/");
}
if (JKMod_IgnoreClientCheck(1, ent->s.number, user->s.number)) {
Q_strcat(ignored, sizeof(ignored), va("Duel/", ignored));
Q_strcat(ignored, sizeof(ignored), "Duel/");
}
if (JKMod_IgnoreClientCheck(0, ent->s.number, user->s.number)) {
Q_strcat(ignored, sizeof(ignored), va("Chat/", ignored));
Q_strcat(ignored, sizeof(ignored), "Chat/");
}
if (ignored[0] == '\0') strcpy(ignored, "None/");

Expand Down Expand Up @@ -879,7 +893,7 @@ void JKMod_Cmd_WhoIs(gentity_t *ent)
(int)ent->client->ps.origin[1],
(int)ent->client->ps.origin[2],
(int)ent->client->ps.viewangles[YAW]));
} else {
} else if (level.numConnectedClients) {
G_Printf("--- ---------------------------- ----- ------------ --------------- ----------\n");
}
}
Expand Down
31 changes: 31 additions & 0 deletions jkmod/game/jk_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,37 @@ void JKMod_DropPlayer(gentity_t *ent, char *reason)
trap_DropClient(clientNum, va("%s (Reason: ^3%s^7)", G_GetStripEdString("SVINGAME", "WAS_KICKED"), reason));
}

/*
=====================================================================
Team name list in different formats
=====================================================================
*/
const char *JKMod_TeamName(team_t team, int letterCase)
{
const char *teamName[CASE_MAX][TEAM_NUM_TEAMS] = {
{ // Normal
"Free",
"Red",
"Blue",
"Spectator",
},
{ // Upper
"FREE",
"RED",
"BLUE",
"SPECTATOR",
},
{ // Lower
"free",
"red",
"blue",
"spectator",
}
};

return teamName[letterCase][team];
}

/*
=====================================================================
Convert milliseconds to string
Expand Down
7 changes: 7 additions & 0 deletions jkmod/game/jk_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ typedef struct
unsigned dimensionBase; // Global base dimension
int jetpackFxActive; // Server jetpack active effect
int jetpackFxIdle; // Server jetpack idle effect
int lockedTeam[TEAM_NUM_TEAMS]; // Current locked team

} jkmod_locals_t;

Expand Down Expand Up @@ -315,6 +316,7 @@ Re-routed functions
#define G_CallSpawn JKMod_G_CallSpawn
#define trap_Trace JKMod_DimensionTrace
#define trap_SetBrushModel JKMod_SetBrushModel
#define Svcmd_ForceTeam_f JKMod_svCmd_forceTeam

/*
=====================================================================
Expand Down Expand Up @@ -433,6 +435,7 @@ void BaseJK2_G_UpdateCvars(void);
void BaseJK2_G_InitGame(int levelTime, int randomSeed, int restart);

// g_svcmds.c
void BaseJK2_Svcmd_ForceTeam_f(void);
qboolean BaseJK2_ConsoleCommand(void);

// jk_active.c
Expand Down Expand Up @@ -466,6 +469,7 @@ void JKMod_StringEscape(char *in, char *out, int outSize);
char *JKMod_SanitizeString(char *dest, char *source, int destSize);
int JKMod_DuplicatedNameCheck(gentity_t *ent, char *clientName);
void JKMod_DropPlayer(gentity_t *ent, char *reason);
const char *JKMod_TeamName(team_t team, int letterCase);
const char *JKMod_MsToString(const int ms);
const char *JKMod_MsToWord(const int ms, qboolean abbr);
int JKMod_GetClientNumber(char* name);
Expand Down Expand Up @@ -564,4 +568,7 @@ void JKMod_CheckValidMapItems(void);
void JKMod_SetBrushModel(gentity_t *ent, const char *name);
void JKMod_DoorFix(gentity_t* ent);

// jk_svcmds.c
void JKMod_svCmd_forceTeam(void);

#endif // __JK_LOCAL_H__
16 changes: 16 additions & 0 deletions jkmod/game/jk_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ typedef enum
GENERIC_CONVERTER = ( 1 << 2 ),
GENERIC_SERVERSIDE = ( 1 << 3 ),

/* Total */
GENERIC_MAX = 4

} jkmod_objects_t;

// Letter case style
typedef enum
{
/* List */
CASE_NORMAL,
CASE_UPPER,
CASE_LOWER,

/* Total */
CASE_MAX

} jkmod_letterCase_t;

#endif //__JK_PUBLIC_H__
103 changes: 103 additions & 0 deletions jkmod/game/jk_svcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,104 @@ static void JKMod_svCmd_listDir(void)
}
}

/*
=====================================================================
Lock team function
=====================================================================
*/
static void JKMod_svCmd_lockTeam(void)
{
team_t team = TEAM_NUM_TEAMS;
char arg1[MAX_STRING_CHARS];

if (trap_Argc() < 2)
{
G_Printf("Usage: lockteam <team>\nNotes: Use the command again to unlock\n");
}
else
{
trap_Argv(1, arg1, sizeof(arg1));

if (!Q_stricmp(arg1, "spectator") || !Q_stricmp(arg1, "s")) {
team = TEAM_SPECTATOR;
}
else if (!Q_stricmp(arg1, "free") || !Q_stricmp(arg1, "f")) {
team = TEAM_FREE;
}
else if (!Q_stricmp(arg1, "red") || !Q_stricmp(arg1, "r")) {
team = TEAM_RED;
}
else if (!Q_stricmp(arg1, "blue") || !Q_stricmp(arg1, "b")) {
team = TEAM_BLUE;
}

if (team != TEAM_NUM_TEAMS) {
int i;
gentity_t* ent;
qboolean check = level.jkmodLocals.lockedTeam[team];

level.jkmodLocals.lockedTeam[team] = check ? qfalse : qtrue;
trap_SendServerCommand(-1, va("print \"Server: %s team %s\n\"", (check ? "Unlocked" : "Locked"), JKMod_TeamName(team, CASE_UPPER)));

for (i = 0, ent = g_entities; i < MAX_CLIENTS; ++i, ++ent)
{
if (ent && ent->client && ent->client->pers.connected != CON_DISCONNECTED)
{
trap_SendServerCommand(-1, va("cp \"Team %s%s%s has been %s\"", TeamColorString(team), JKMod_TeamName(team, CASE_NORMAL), S_COLOR_WHITE, (check ? "unlocked" : "locked")));
}
}
} else {
G_Printf("Invalid team!\n");
}
}
}

/*
=====================================================================
Force team function
=====================================================================
*/
void JKMod_svCmd_forceTeam(void)
{
int i;
char arg1[MAX_STRING_CHARS];
char arg2[MAX_STRING_CHARS];

if (trap_Argc() < 3)
{
G_Printf("Usage: forceteam <player|number|all> <team>\n");
}
else
{
trap_Argv(1, arg1, sizeof(arg1));
trap_Argv(2, arg2, sizeof(arg2));

if (!Q_stricmp(arg1, "all"))
{
gentity_t* ent;

for (i = 0, ent = g_entities; i < MAX_CLIENTS; ++i, ++ent)
{
if (ent && ent->client && ent->client->pers.connected != CON_DISCONNECTED)
{
SetTeam(ent, arg2);
}
}
}
else
{
int target = JKMod_CheckValidClient(NULL, arg1);

if (target != -1)
{
gentity_t* ent = &g_entities[target];

SetTeam(ent, arg2);
}
}
}
}

/*
=====================================================================
Console command function
Expand Down Expand Up @@ -691,6 +789,11 @@ qboolean JKMod_ConsoleCommand(void)
JKMod_svCmd_listDir();
return qtrue;
}
if (!Q_stricmp(cmd, "lockteam"))
{
JKMod_svCmd_lockTeam();
return qtrue;
}
if (!Q_stricmp(cmd, "checkcvars") && jkcvar_gameTypeConfig.integer && !level.jkmodLocals.cvarTempUnlock)
{
level.jkmodLocals.cvarTempUnlock = 1;
Expand Down

0 comments on commit a568389

Please sign in to comment.