Skip to content

Commit

Permalink
Merge pull request #13 from walliski/kicker-race-condition
Browse files Browse the repository at this point in the history
Kicker plugin improvements (and version 1.2.4)
  • Loading branch information
walliski authored Oct 14, 2021
2 parents 3640d20 + 5213d84 commit ee42bbc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ Overrides

## Changelog

* **1.2.4** 14.10.2021
- Handle race condition in Kicker plugin.
Properly check that both admin and score have been loaded before checking if the player should be kicked. Should
solve issues where clients with reserved slot gets kicked because their admin rights are not loaded at the time the
score is loaded and the kicker triggers.
- Use correct skillgroup in kick message in Kicker
Previously the message would say "Needed:" and then the players skillgroup. Now it will say both the players
skillgroup, and the one that is actually needed.

* **1.2.3** 07.03.2021
- Calculate score with low priority in initial setup.
Separates the player insertion and initial score load, so that we can do the important stuff with high prio, and the
Expand Down
4 changes: 2 additions & 2 deletions addons/sourcemod/scripting/include/myranks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#endif
#define _myrank_included_

#define MYRANK_VERSION "1.2.3"
#define MYRANK_VERSION "1.2.4"

#define MYRANK_SG_NAME_MAXLENGTH 24
#define MYRANK_SG_PERCENTAGE_MAXLENGTH 8
Expand Down Expand Up @@ -75,4 +75,4 @@ forward void Myrank_OnMaxScoreChange(int newScore, int mode);
* @param mode In which mode the score changed
*/

forward void Myrank_OnScoreChange(int client, int newScore, int mode);
forward void Myrank_OnInitialScoreLoad(int client, int newScore, int mode);
52 changes: 49 additions & 3 deletions addons/sourcemod/scripting/myranks-kicker.sp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public Plugin myinfo =
ConVar gCV_myrank_minimum_allowed_skillgroup;
ConVar gCV_myrank_minimum_allowed_score;

bool gB_AdminLoaded[MAXPLAYERS + 1] = {false, ...};
bool gB_ScoreLoaded[MAXPLAYERS + 1] = {false, ...};

public void OnPluginStart()
{
LoadTranslations("myranks-kicker.phrases");
Expand All @@ -38,22 +41,65 @@ void CreateConVars()
AutoExecConfig_CleanFile();
}

public void OnClientConnected(int client)
{
if (IsFakeClient(client))
{
return;
}

gB_AdminLoaded[client] = false;
gB_ScoreLoaded[client] = false;
}

public void OnClientPostAdminCheck(int client)
{
if (IsFakeClient(client))
{
return;
}

gB_AdminLoaded[client] = true;
KickIfNotAllowed(client);
}

public void Myrank_OnInitialScoreLoad(int client, int newScore, int mode)
{
if (mode != GOKZ_GetDefaultMode() || CheckCommandAccess(client, "myrank_kicker_immunity", ADMFLAG_RESERVATION)) {
if (mode != GOKZ_GetDefaultMode()) {
return;
}

gB_ScoreLoaded[client] = true;
KickIfNotAllowed(client);
}

public void KickIfNotAllowed(int client)
{
// We need both admin rights and score loaded to proceed.
if (!gB_AdminLoaded[client] || !gB_ScoreLoaded[client]) {
return;
}

// Abort if player is immune.
if (CheckCommandAccess(client, "myrank_kicker_immunity", ADMFLAG_RESERVATION)) {
return;
}

int mode = GOKZ_GetDefaultMode();
int newScore = Myrank_GetScore(client, mode);

if (newScore < gCV_myrank_minimum_allowed_score.IntValue) {
KickClient(client, "%t", "Score Kick", gC_ModeNamesShort[mode], gCV_myrank_minimum_allowed_score.IntValue);
}

int skillGroup = Myrank_GetSkillGroup(newScore, mode);

char skillGroupName[MYRANK_SG_NAME_MAXLENGTH];
char neededSkillGroupName[MYRANK_SG_NAME_MAXLENGTH];
Myrank_GetSkillGroupName(skillGroup, skillGroupName);
Myrank_GetSkillGroupName(gCV_myrank_minimum_allowed_skillgroup.IntValue, neededSkillGroupName);

if (skillGroup < gCV_myrank_minimum_allowed_skillgroup.IntValue) {
KickClient(client, "%t", "Skillgroup Kick", gC_ModeNamesShort[mode], skillGroupName);
KickClient(client, "%t", "Skillgroup Kick", gC_ModeNamesShort[mode], skillGroupName, neededSkillGroupName);
}
}
}
4 changes: 2 additions & 2 deletions addons/sourcemod/translations/myranks-kicker.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"Skillgroup Kick"
{
// You are not high enough skillgroup in mode: KZT. Needed: Skilled+
"#format" "{1:s},{2:s}"
"en" "You are not high enough skillgroup in mode: {1}. Needed: {2}"
"#format" "{1:s},{2:s},{3:s}"
"en" "You are not high enough skillgroup in mode: {1}. Your skillgroup: {2}. Needed: {3}"
}
}

0 comments on commit ee42bbc

Please sign in to comment.