Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOCD detection #360

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/progs.h
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,19 @@ typedef struct gedict_s
float fIllegalFPSWarnings;
// ILLEGALFPS]

// SOCD detectioin
float fStrafeChangeCount;
float fFramePerfectStrafeChangeCount;
int socdDetected;
int socdChecksCount;
float fLastSideMoveSpeed;
int matchStrafeChangeCount;
int matchPerfectStrafeCount;
int totalStrafeChangeCount;
int totalPerfectStrafeCount;
int nullStrafeCount;
// SOCD

float shownick_time; // used to force centerprint is off at desired time
clientType_t ct; // client type for client edicts
// { timing
Expand Down
64 changes: 64 additions & 0 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,18 @@ void ClientConnect()
SendIntermissionToClient();
}

// SOCD
self->socdChecksCount = 0;
self->socdDetected = 0;
self->fStrafeChangeCount = 0;
self->fFramePerfectStrafeChangeCount = 0;
self->fLastSideMoveSpeed = 0;
self->matchStrafeChangeCount = 0;
self->matchPerfectStrafeCount = 0;
self->totalStrafeChangeCount = 0;
self->totalPerfectStrafeCount = 0;
self->nullStrafeCount = 0;

// ILLEGALFPS[

// Zibbo's frametime checking code
Expand Down Expand Up @@ -3520,6 +3532,58 @@ void PlayerPreThink()
}
#endif

// SOCD detection
{
float fSideMoveSpeed = self->movement[1];

if ((fSideMoveSpeed != 0) && (((fSideMoveSpeed > 0) - (fSideMoveSpeed < 0)) != ((self->fLastSideMoveSpeed > 0) - (self->fLastSideMoveSpeed < 0))) && (self->nullStrafeCount < 4)) //strafechange
{
self->fStrafeChangeCount += 1;
self->totalStrafeChangeCount += 1;
if (match_in_progress)
self->matchStrafeChangeCount += 1;

if ((fSideMoveSpeed != 0) && (self->fLastSideMoveSpeed != 0))
{
self->fFramePerfectStrafeChangeCount += 1;
self->totalPerfectStrafeCount += 1;
if (match_in_progress)
self->matchPerfectStrafeCount += 1;
}

self->nullStrafeCount = 0;
}
else
{
if (0 == fSideMoveSpeed)
self->nullStrafeCount += 1;
else
self->nullStrafeCount = 0;
}

self->fLastSideMoveSpeed = fSideMoveSpeed;

if (self->fStrafeChangeCount >= 25)
{
if (self->fFramePerfectStrafeChangeCount / self->fStrafeChangeCount >= 0.75)
{
int k_allow_socd_warning = cvar("k_allow_socd_warning");

self->socdDetected += 1;
if ((!match_in_progress) && (!self->isBot) && k_allow_socd_warning && (self->ct == ctPlayer))
{
G_bprint(PRINT_HIGH,
"Warning! %s: Movement assistance detected. Please disable iDrive or keyboard strafe assistance features.\n",
self->netname);
}
}

self->socdChecksCount += 1;
self->fStrafeChangeCount = 0;
self->fFramePerfectStrafeChangeCount = 0;
}
}

// ILLEGALFPS[

self->fAverageFrameTime += g_globalvars.frametime;
Expand Down
30 changes: 28 additions & 2 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1875,12 +1875,12 @@
G_sprint(self, 2, "%s in progress\n", redtext("Team picking"));
}

if (floor(k_captains) == 1)

Check warning on line 1878 in src/commands.c

View workflow job for this annotation

GitHub Actions / verify-msvc

decimal digit terminates octal escape sequence [D:\a\ktx\ktx\builddir\qwprogs.vcxproj]
{
G_sprint(self, 2, "\2201\221 %s present\n", redtext("captain"));
}

if (floor(k_coaches) == 1)

Check warning on line 1883 in src/commands.c

View workflow job for this annotation

GitHub Actions / verify-msvc

decimal digit terminates octal escape sequence [D:\a\ktx\ktx\builddir\qwprogs.vcxproj]
{
G_sprint(self, 2, "\2201\221 %s present\n", redtext("coach"));
}
Expand Down Expand Up @@ -8089,6 +8089,7 @@
{
char arg_x[1024];
int i;
gedict_t* p;

if (match_in_progress)
{
Expand All @@ -8114,16 +8115,41 @@

if (!is_real_adm(self))
{
if (strneq(arg_x, "f_version") && strneq(arg_x, "f_modified") && strneq(arg_x, "f_server"))
if (strneq(arg_x, "f_version") && strneq(arg_x, "f_modified") && strneq(arg_x, "f_server") && strneq(arg_x, "f_movement"))
{
G_sprint(self, 2, "You are not allowed to check \020%s\021\n"
"available checks are: f_version, f_modified and f_server\n",
"available checks are: f_version, f_modified, f_server and f_movement\n",
arg_x);

return;
}
}

if (streq(arg_x, "f_movement"))
{
G_bprint(2, "%s is checking \020%s\021\n", self->netname, arg_x);

for (p = world; (p = find_client(p));)
{
if ((p->ct == ctPlayer) && (!p->isBot))
{
if (p->socdDetected > 0)
{
G_bprint(2, "%s: %s:%.1f%% (%d/%d). SOCD movement assistance detected!\n", p->netname, redtext("Perfect strafes"),
p->totalStrafeChangeCount > 0 ? 100.0 * p->totalPerfectStrafeCount / p->totalStrafeChangeCount : 0.0,
p->totalPerfectStrafeCount, p->totalStrafeChangeCount);
}
else
{
G_bprint(2, "%s: %s:%.1f%% (%d/%d)\n", p->netname, redtext("Perfect strafes"),
p->totalStrafeChangeCount > 0 ? 100.0 * p->totalPerfectStrafeCount / p->totalStrafeChangeCount : 0.0,
p->totalPerfectStrafeCount, p->totalStrafeChangeCount);
}
}
}
return;
}

for (i = 1; i <= MAX_CLIENTS; i++)
{
if (g_edicts[i].f_checkbuf)
Expand Down
10 changes: 10 additions & 0 deletions src/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,16 @@ void OnePlayerStats(gedict_t *p, int tp)
p->ps.vel_frames > 0 ? p->ps.velocity_sum / p->ps.vel_frames : 0.);
}

// movement
if (!p->isBot)
{
G_bprint(2, "%s: %s:%.1f%% (%d/%d) %s:%d/%d\n", redtext("Movement"), redtext("Perfect strafes"),
p->matchStrafeChangeCount > 0 ? 100.0 * p->matchPerfectStrafeCount / p->matchStrafeChangeCount : 0.0,
p->matchPerfectStrafeCount, p->matchStrafeChangeCount, redtext("SOCD detections"),
p->socdDetected, p->socdChecksCount);
}


// armors + megahealths
if (!lgc_enabled())
{
Expand Down
2 changes: 2 additions & 0 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
{
bodyque[i] = spawn();
bodyque[i]->classname = "bodyque";
bodyque[i - 1]->s.v.owner = EDICT_TO_PROG(bodyque[i]);

Check warning on line 56 in src/world.c

View workflow job for this annotation

GitHub Actions / verify-macos

implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
}

bodyque[MAX_BODYQUE - 1]->s.v.owner = EDICT_TO_PROG(bodyque[0]);

Check warning on line 59 in src/world.c

View workflow job for this annotation

GitHub Actions / verify-macos

implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
bodyque_head = 0;
}

Expand Down Expand Up @@ -144,7 +144,7 @@
e = spawn();

e->classname = "mapguard";
e->s.v.owner = EDICT_TO_PROG(world);

Check warning on line 147 in src/world.c

View workflow job for this annotation

GitHub Actions / verify-macos

implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
e->think = (func_t) CheckDefMap;
e->s.v.nextthink = g_globalvars.time + max(0.0001, timeout);
}
Expand Down Expand Up @@ -582,7 +582,7 @@

self = spawn();
setorigin(self, -912.6f, -898.9f, 248.0f); // oh, ktpro like
self->s.v.owner = EDICT_TO_PROG(world);

Check warning on line 585 in src/world.c

View workflow job for this annotation

GitHub Actions / verify-macos

implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
SP_item_artifact_super_damage();

self = swp; // restore self
Expand Down Expand Up @@ -1000,6 +1000,8 @@

RegisterCvar("k_teamoverlay"); // q3 like team overlay

RegisterCvar("k_allow_socd_warning"); // socd

// { SP
RegisterCvarEx("k_monster_spawn_time", "20");
// }
Expand Down
Loading