Skip to content

Commit

Permalink
Jan 9th
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaKeks committed Feb 8, 2025
1 parent 8dd0ef5 commit b810c27
Show file tree
Hide file tree
Showing 64 changed files with 4,012 additions and 510 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-dev-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v4
- uses: jidicula/[email protected]
with:
clang-format-version: '16'
clang-format-version: '18'
check-path: ${{ matrix.path['check'] }}
exclude-regex: ${{ matrix.path['exclude'] }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-push-and-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v4
- uses: jidicula/[email protected]
with:
clang-format-version: '16'
clang-format-version: '18'
check-path: ${{ matrix.path['check'] }}
exclude-regex: ${{ matrix.path['exclude'] }}

Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
[submodule "vendor/sql_mm"]
path = vendor/sql_mm
url = https://github.com/zer0k-z/sql_mm.git
[submodule "vendor/ixwebsocket"]
path = vendor/ixwebsocket
url = https://github.com/machinezone/IXWebSocket
[submodule "vendor/json"]
path = vendor/json
url = https://github.com/nlohmann/json
13 changes: 12 additions & 1 deletion AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ for sdk_target in MMSPlugin.sdk_targets:
os.path.join(builder.sourcePath, 'hl2sdk-cs2', 'public', 'entity2'),
os.path.join(builder.sourcePath, 'hl2sdk-cs2', 'game', 'server'),
os.path.join(builder.sourcePath, 'vendor', 'funchook', 'include'),
os.path.join(builder.sourcePath, 'vendor', 'ixwebsocket'),
]

PROTOS = [
Expand Down Expand Up @@ -85,6 +86,7 @@ for sdk_target in MMSPlugin.sdk_targets:
os.path.join(builder.sourcePath, 'src', 'utils', 'schema.cpp'),
os.path.join(builder.sourcePath, 'src', 'utils', 'simplecmds.cpp'),
os.path.join(builder.sourcePath, 'src', 'utils', 'ctimer.cpp'),
os.path.join(builder.sourcePath, 'src', 'utils', 'http.cpp'),

os.path.join(builder.sourcePath, 'src', 'player', 'player_manager.cpp'),
os.path.join(builder.sourcePath, 'src', 'player', 'player.cpp'),
Expand Down Expand Up @@ -124,6 +126,9 @@ for sdk_target in MMSPlugin.sdk_targets:
os.path.join(builder.sourcePath, 'src', 'kz', 'db', 'setup_styles.cpp'),

os.path.join(builder.sourcePath, 'src', 'kz', 'global', 'kz_global.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'global', 'commands.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'global', 'enforcer.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'global', 'api', 'maps.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'hud', 'kz_hud.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'mappingapi', 'kz_mappingapi.cpp'),

Expand All @@ -148,7 +153,7 @@ for sdk_target in MMSPlugin.sdk_targets:
os.path.join(builder.sourcePath, 'src', 'kz', 'telemetry', 'kz_telemetry.cpp'),

os.path.join(builder.sourcePath, 'src', 'kz', 'timer', 'kz_timer.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'timer', 'announce_queue.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'timer', 'announce.cpp'),

os.path.join(builder.sourcePath, 'src', 'kz', 'timer', 'queries', 'base_request.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'timer', 'queries', 'course_top.cpp'),
Expand All @@ -162,6 +167,12 @@ for sdk_target in MMSPlugin.sdk_targets:
os.path.join(builder.sourcePath, 'src', 'kz', 'trigger', 'mapping_api.cpp'),
]

ws_dir = os.path.join(builder.sourcePath, 'vendor', 'ixwebsocket', 'ixwebsocket')

for file in os.listdir(ws_dir):
if file.endswith('.cpp'):
binary.sources.append(os.path.join(ws_dir, file))

binary.custom = [builder.tools.Protoc(protoc = sdk_target.protoc, sources = PROTOS)]

# Mode binaries
Expand Down
3 changes: 3 additions & 0 deletions cfg/cs2kz-server-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@
//"timeout" "60"
//"port" "3306"
}

"apiUrl" "https://api.cs2kz.org"
"apiKey" ""
}
2 changes: 2 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "vendor/tinyformat.h"

#include "entity2/entitysystem.h"
#include "tier0/dbg.h"

#define MAXPLAYERS 64

#define ENGINE_FIXED_TICK_INTERVAL 0.015625f
Expand Down
2 changes: 2 additions & 0 deletions src/cs2kz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "kz/option/kz_option.h"
#include "kz/language/kz_language.h"
#include "kz/mappingapi/kz_mappingapi.h"
#include "kz/global/kz_global.h"

#include "version.h"

Expand Down Expand Up @@ -90,6 +91,7 @@ bool KZPlugin::Unload(char *error, size_t maxlen)
g_pKZStyleManager->Cleanup();
g_pPlayerManager->Cleanup();
KZDatabaseService::Cleanup();
KZGlobalService::Cleanup();
return true;
}

Expand Down
9 changes: 6 additions & 3 deletions src/cs2kz.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#pragma once

#include <string_view>

#include "common.h"

class KZPlugin;
extern KZPlugin g_KZPlugin;

class KZPlugin : public ISmmPlugin, public IMetamodListener
{
public:
Expand Down Expand Up @@ -34,10 +39,8 @@ class KZPlugin : public ISmmPlugin, public IMetamodListener
char md5[33];

public:
const char *GetMD5()
std::string_view GetMD5()
{
return md5;
}
};

extern KZPlugin g_KZPlugin;
73 changes: 73 additions & 0 deletions src/kz/anticheat/kz_anticheat.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,75 @@
#include "../kz.h"
#include "kz_anticheat.h"
#include "kz/language/kz_language.h"
#include "kz/timer/kz_timer.h"
#include "utils/ctimer.h"

#include <vendor/ClientCvarValue/public/iclientcvarvalue.h>

extern IClientCvarValue *g_pClientCvarValue;

#define INTEGRITY_CHECK_MIN_INTERVAL 1.0f
#define INTEGRITY_CHECK_MAX_INTERVAL 5.0f
#define KICK_DELAY 5.0f
#define MINIMUM_FPS_MAX 64.0f
#define MAXIMUM_M_YAW 0.3f

static_function f64 KickPlayerInvalidSettings(CPlayerUserId userID)
{
KZPlayer *player = g_pKZPlayerManager->ToPlayer(userID);
if (player)
{
player->Kick("Invalid player settings");
}
return 0.0f;
}

static_function void ValidateCvar(CPlayerSlot nSlot, ECvarValueStatus eStatus, const char *pszCvarName, const char *pszCvarValue)
{
if (eStatus != ECvarValueStatus::ValueIntact)
{
return;
}
KZPlayer *player = g_pKZPlayerManager->ToPlayer(nSlot);
if (KZ_STREQI(pszCvarName, "m_yaw"))
{
if (atof(pszCvarValue) > MAXIMUM_M_YAW)
{
player->languageService->PrintChat(true, false, "Kick Player m_yaw");
player->languageService->PrintConsole(false, false, "Kick Player m_yaw (Console)");
player->anticheatService->MarkHasInvalidCvars();
player->timerService->TimerStop();
StartTimer<CPlayerUserId>(KickPlayerInvalidSettings, player->GetClient()->GetUserID(), KICK_DELAY, true, true);
}
}
else if (KZ_STREQI(pszCvarName, "fps_max"))
{
if (atof(pszCvarValue) != 0.0f && atof(pszCvarValue) < MINIMUM_FPS_MAX)
{
player->languageService->PrintChat(true, false, "Kick Player fps_max");
player->languageService->PrintConsole(false, false, "Kick Player fps_max (Console)");
player->anticheatService->MarkHasInvalidCvars();
player->timerService->TimerStop();
StartTimer<CPlayerUserId>(KickPlayerInvalidSettings, player->GetClient()->GetUserID(), KICK_DELAY, true, true);
}
}
}

static_function f64 CheckClientCvars(CPlayerUserId userID)
{
KZPlayer *player = g_pKZPlayerManager->ToPlayer(userID);
if (!player || !g_pClientCvarValue || !player->anticheatService->ShouldCheckClientCvars())
{
return 0.0f;
}
g_pClientCvarValue->QueryCvarValue(player->GetPlayerSlot(), "m_yaw", ValidateCvar);
g_pClientCvarValue->QueryCvarValue(player->GetPlayerSlot(), "fps_max", ValidateCvar);
return RandomFloat(INTEGRITY_CHECK_MIN_INTERVAL, INTEGRITY_CHECK_MAX_INTERVAL);
}

void KZAnticheatService::OnPlayerFullyConnect()
{
this->hasValidCvars = true;
StartTimer<CPlayerUserId>(CheckClientCvars, this->player->GetClient()->GetUserID(),
RandomFloat(INTEGRITY_CHECK_MIN_INTERVAL, INTEGRITY_CHECK_MAX_INTERVAL), true, true);
}
18 changes: 18 additions & 0 deletions src/kz/anticheat/kz_anticheat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,22 @@ class KZBaseService;

class KZAnticheatService : public KZBaseService
{
public:
using KZBaseService::KZBaseService;

private:
bool hasValidCvars = true;

public:
bool ShouldCheckClientCvars()
{
return hasValidCvars;
}

void MarkHasInvalidCvars()
{
hasValidCvars = false;
}

void OnPlayerFullyConnect();
};
18 changes: 15 additions & 3 deletions src/kz/course/kz_course.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const KZCourse *KZ::course::GetCourseByCourseID(i32 id)
return nullptr;
}

const KZCourse *KZ::course::GetCourseByLocalCourseID(i32 id)
const KZCourse *KZ::course::GetCourseByLocalCourseID(u32 id)
{
FOR_EACH_VEC(courseList, i)
{
Expand All @@ -78,6 +78,18 @@ const KZCourse *KZ::course::GetCourseByLocalCourseID(i32 id)
return nullptr;
}

const KZCourse *KZ::course::GetCourseByGlobalCourseID(u32 id)
{
FOR_EACH_VEC(courseList, i)
{
if (courseList[i].globalDatabaseID == id)
{
return &courseList[i];
}
}
return nullptr;
}

const KZCourse *KZ::course::GetCourse(const char *courseName, bool caseSensitive)
{
FOR_EACH_VEC(courseList, i)
Expand Down Expand Up @@ -133,11 +145,11 @@ bool KZ::course::UpdateCourseLocalID(const char *courseName, u32 databaseID)
return false;
}

bool KZ::course::UpdateCourseGlobalID(const char *courseName, i32 courseID, u32 globalID)
bool KZ::course::UpdateCourseGlobalID(const char *courseName, u32 globalID)
{
FOR_EACH_VEC(courseList, i)
{
if (courseList[i].HasMatchingIdentifiers(courseID, courseName))
if (courseList[i].GetName() == courseName)
{
courseList[i].globalDatabaseID = globalID;
return true;
Expand Down
10 changes: 7 additions & 3 deletions src/kz/course/kz_course.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct PBData
struct
{
f64 pbTime {};
f64 points {};
CUtlVectorFixed<f64, KZ_MAX_SPLIT_ZONES> pbSplitZoneTimes;
CUtlVectorFixed<f64, KZ_MAX_CHECKPOINT_ZONES> pbCpZoneTimes;
CUtlVectorFixed<f64, KZ_MAX_STAGE_ZONES> pbStageZoneTimes;
Expand Down Expand Up @@ -111,7 +112,10 @@ namespace KZ
const KZCourse *GetCourseByCourseID(i32 id);

// Get a course's information given its local course id.
const KZCourse *GetCourseByLocalCourseID(i32 id);
const KZCourse *GetCourseByLocalCourseID(u32 id);

// Get a course's information given its global course id.
const KZCourse *GetCourseByGlobalCourseID(u32 id);

// Get a course's information given its name.
const KZCourse *GetCourse(const char *courseName, bool caseSensitive = true);
Expand All @@ -129,8 +133,8 @@ namespace KZ
bool UpdateCourseLocalID(const char *courseName, u32 databaseID);

// Update the course's global ID given its map-defined name and ID.
bool UpdateCourseGlobalID(const char *courseName, i32 courseID, u32 globalID);
bool UpdateCourseGlobalID(const char *courseName, u32 globalID);

void RegisterCommands();
} // namespace course
}; // namespace KZ
}; // namespace KZ
3 changes: 2 additions & 1 deletion src/kz/db/kz_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class KZDatabaseService : public KZBaseService
static void InsertAndUpdateStyleIDs(CUtlString styleName, CUtlString shortName);

// Times
static void SaveTime(u32 id, KZPlayer *player, CUtlString courseName, f64 time, u64 teleportsUsed, CUtlString metadata);
static void SaveTime(u64 steamID, u32 courseID, i32 modeID, f64 time, u64 teleportsUsed, u64 styleIDs, std::string_view metadata,
TransactionSuccessCallbackFunc onSuccess, TransactionFailureCallbackFunc onFailure);
static void QueryAllPBs(u64 steamID64, CUtlString mapName, TransactionSuccessCallbackFunc onSuccess, TransactionFailureCallbackFunc onFailure);
static void QueryPB(u64 steamID64, CUtlString mapName, CUtlString courseName, u32 modeID, TransactionSuccessCallbackFunc onSuccess,
TransactionFailureCallbackFunc onFailure);
Expand Down
Loading

0 comments on commit b810c27

Please sign in to comment.