-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
165 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#if defined _bs_console_command_included | ||
#endinput | ||
#endif | ||
#define _bs_console_command_included | ||
|
||
#define TEAM_ARG_MAX_SIZE 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#if defined _bs_console_variable_included | ||
#endinput | ||
#endif | ||
#define _bs_console_variable_included | ||
|
||
#define NOTIFICATIONS_JOIN_ATTEMPT (1 << 0) | ||
#define NOTIFICATIONS_ROUND_END (1 << 1) | ||
#define NOTIFICATIONS_TIMER (1 << 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#if defined _bs_message_included | ||
#endinput | ||
#endif | ||
#define _bs_message_included | ||
|
||
#define PREFIX_COLORED "{green}[Block spectators] " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#if defined _bs_use_case_included | ||
#endinput | ||
#endif | ||
#define _bs_use_case_included | ||
|
||
#define ENTITY_NOT_FOUND -1 | ||
#define TEAM_SPECTATOR 1 | ||
#define ROUND_TIMER_EXISTS_DEFAULT_VALUE true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public Action CommandListener_JoinTeam(int client, const char[] command, int argc) { | ||
char teamStr[TEAM_ARG_MAX_SIZE]; | ||
|
||
GetCmdArg(1, teamStr, sizeof(teamStr)); | ||
|
||
int team = StringToInt(teamStr); | ||
|
||
if (UseCase_IsSpectatorsBlocked() && team == TEAM_SPECTATOR) { | ||
MessagePrint_SpectatorsIsBlocked(client); | ||
|
||
return Plugin_Stop; | ||
} | ||
|
||
return Plugin_Continue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
static ConVar g_pluginEnabled = null; | ||
static ConVar g_notificationsMode = null; | ||
static ConVar g_blockTimeOffset = null; | ||
|
||
void Variable_Create() { | ||
g_pluginEnabled = CreateConVar("sm_blockspectators", "1", "Enable (1) or disable (0) spectators team blocking"); | ||
g_notificationsMode = CreateConVar("sm_blockspectators_notifications_mode", "7", "None (0), Join attempt (1), Round end (2), Timer (4)"); | ||
g_blockTimeOffset = CreateConVar("sm_blockspectators_time_offset", "0", "Time offset (in seconds) until the end of the round"); | ||
} | ||
|
||
bool Variable_IsPluginEnabled() { | ||
return g_pluginEnabled.IntValue == 1; | ||
} | ||
|
||
bool Variable_IsNotificationFlagEnabled(int flag) { | ||
return (g_notificationsMode.IntValue & flag) == flag; | ||
} | ||
|
||
float Variable_GetBlockTimeOffset() { | ||
return g_blockTimeOffset.FloatValue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
void MessagePrint_SpectatorsWasBlocked(int notificationFlag) { | ||
bool isNotificationEnalbed = Variable_IsNotificationFlagEnabled(notificationFlag); | ||
|
||
if (isNotificationEnalbed) { | ||
CPrintToChatAll("%s%t", PREFIX_COLORED, "Spectators team was blocked"); | ||
} | ||
} | ||
|
||
void MessagePrint_SpectatorsIsBlocked(int client) { | ||
bool isNotificationEnalbed = Variable_IsNotificationFlagEnabled(NOTIFICATIONS_JOIN_ATTEMPT); | ||
|
||
if (isNotificationEnalbed) { | ||
CPrintToChat(client, "%s%t", PREFIX_COLORED, "Spectators team is blocked"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
static Handle g_blockTimer = null; | ||
static float g_blockTimerEndTime = 0.0; | ||
static bool g_isSpectatorsBlocked = false; | ||
static bool g_isRoundTimerExists = ROUND_TIMER_EXISTS_DEFAULT_VALUE; | ||
|
||
bool UseCase_IsSpectatorsBlocked() { | ||
return g_isSpectatorsBlocked; | ||
} | ||
|
||
void UseCase_SetRoundTimerExists(bool exists) { | ||
g_isRoundTimerExists = exists; | ||
} | ||
|
||
void UseCase_BlockSpectatorsWithoutTimer() { | ||
if (!g_isRoundTimerExists) { | ||
UseCase_BlockSpectators(NOTIFICATIONS_ROUND_END); | ||
} | ||
} | ||
|
||
void UseCase_BlockSpectators(int notificationFlag) { | ||
g_isSpectatorsBlocked = true; | ||
MessagePrint_SpectatorsWasBlocked(notificationFlag); | ||
} | ||
|
||
void UseCase_UnblockSpectators() { | ||
delete g_blockTimer; | ||
g_isSpectatorsBlocked = false; | ||
} | ||
|
||
void UseCase_CreateBlockTimer() { | ||
if (!Variable_IsPluginEnabled()) { | ||
return; | ||
} | ||
|
||
int timerEntity = FindEntityByClassname(ENTITY_NOT_FOUND, "dod_round_timer"); | ||
|
||
if (timerEntity == ENTITY_NOT_FOUND) { | ||
g_isRoundTimerExists = false; | ||
|
||
return; | ||
} | ||
|
||
float timeRemanining = GetEntPropFloat(timerEntity, Prop_Send, "m_flTimeRemaining"); | ||
float timerDelay = timeRemanining - Variable_GetBlockTimeOffset() - 1.0; | ||
|
||
if (timerDelay < 0.0) { | ||
timerDelay = 0.0; | ||
} | ||
|
||
g_blockTimer = CreateTimer(timerDelay, Timer_BlockSpectators); | ||
g_blockTimerEndTime = GetGameTime() + timerDelay; | ||
} | ||
|
||
void UseCase_ExtendBlockTimer(int secondsAdded) { | ||
delete g_blockTimer; | ||
|
||
float timerSecondsLeft = g_blockTimerEndTime - GetGameTime(); | ||
float timerDelay = timerSecondsLeft + secondsAdded; | ||
|
||
g_blockTimer = CreateTimer(timerDelay, Timer_BlockSpectators); | ||
g_blockTimerEndTime = GetGameTime() + timerDelay; | ||
} | ||
|
||
public Action Timer_BlockSpectators(Handle timer) { | ||
g_blockTimer = null; | ||
UseCase_BlockSpectators(NOTIFICATIONS_TIMER); | ||
|
||
return Plugin_Continue; | ||
} |