diff --git a/.gitignore b/.gitignore index 485dee6..8e24b65 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +cmake-build-debug diff --git a/basin/src/anticheat.c b/basin/src/anticheat.c index 8dd168d..fe9f175 100644 --- a/basin/src/anticheat.c +++ b/basin/src/anticheat.c @@ -3,21 +3,36 @@ #include "profile.h" #include "anticheat.h" -int ac_lock = 0; -#define AC_BEGIN -#define AC_END(ret) return ret; +#define AC_BEGIN beginProfilerSection("player_anticheat"); +#define AC_END(ret) { endProfilerSection("player_anticheat"); return ret; } + +int ac_chat(struct player* player, char* msg) { + AC_BEGIN + for (char* p = msg; *p; p++) { + if (*p < 32 || *p == 127 || *p == '\u00A7') { + kickPlayer(player, "Invalid chat message"); + AC_END(1); + } + } + AC_END(0) +} int ac_tick(struct player* player, int onground) { AC_BEGIN + AC_END(0) } int ac_ticklook(struct player* player, float yaw, float pitch) { AC_BEGIN + if (!isfinite(yaw) || !isfinite(pitch)) + AC_END(1) AC_END(0) } int ac_tickpos(struct player* player, double x, double y, double z) { AC_BEGIN + if (!isfinite(x) || !isfinite(y) || !isfinite(z)) + AC_END(1) AC_END(0); } \ No newline at end of file diff --git a/basin/src/anticheat.h b/basin/src/anticheat.h index 6a3f210..3180417 100644 --- a/basin/src/anticheat.h +++ b/basin/src/anticheat.h @@ -1,6 +1,7 @@ #ifndef BASIN_ANTICHEAT_H_ #define BASIN_ANTICHEAT_H_ +int ac_chat(struct player* player, char* msg); int ac_tick(struct player* player, int onground); int ac_ticklook(struct player* player, float yaw, float pitch); int ac_tickpos(struct player* player, double x, double y, double z); diff --git a/basin/src/player.c b/basin/src/player.c index be9d91d..31f0f0d 100644 --- a/basin/src/player.c +++ b/basin/src/player.c @@ -71,11 +71,6 @@ struct player* newPlayer(struct entity* entity, char* name, struct uuid uuid, st struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); player->reachDistance = 6.f; - player->acstate.real_onGround = 1; - player->acstate.flightInfraction = 0; - player->acstate.ldy = 0.; - player->acstate.lastJump = 0; - player->acstate.offGroundTime = 0; player->spawnedIn = 0; player->llTick = 0; player->triggerRechunk = 0; @@ -157,6 +152,8 @@ void player_receive_packet(struct player* player, struct packet* inp) { } } else if (inp->id == PKT_PLAY_SERVER_CHATMESSAGE) { char* msg = inp->data.play_server.chatmessage.message; + if (ac_chat(player, msg)) + goto cont; if (startsWith(msg, "/")) { callCommand(player, msg + 1); } else { diff --git a/basin/src/player.h b/basin/src/player.h index 0c46e25..0d74906 100644 --- a/basin/src/player.h +++ b/basin/src/player.h @@ -11,11 +11,6 @@ #include "network.h" typedef struct _acstate { - uint8_t real_onGround; - uint8_t flightInfraction; - double ldy; - size_t lastJump; - uint32_t offGroundTime; } acstate_t; struct player {