Working on server side stuff

This commit is contained in:
Vladislav Khorev committed 2026-11-17 15:28:21 +06:00
1 parent a784da9fb4
commit 542fc191fa
12 files changed
+757 -64

No files matched your search

+18
View File
@@ -22,8 +22,14 @@ struct InitialStateMessage {
std::int64_t tickMs = kSimulationTickMs;
std::uint32_t inputDelayTicks = kDefaultInputDelayTicks;
std::string compatibilityFingerprint;
// 32 random bytes (64 hex chars) issued per connection; used with the app
// pepper to derive per-message HMAC keys.
std::string sessionSecret;
};
// Server-side limit on client messages; exceeding it gets the player kicked.
inline constexpr std::size_t kMaxCommandsPerSecond = 20;
struct DestinationInputMessage {
std::uint64_t clientSequence = 0;
Vec3fp target;
@@ -101,6 +107,18 @@ std::string makeCharacterActionInputMessage(
bool parseCharacterActionInputMessage(
const std::string& text, CharacterActionInputMessage& message,
std::string& error);
// Adds an HMAC-SHA256 "signature" to a client input envelope. The key is
// SHA-256(sessionSecret || appPepper || clientSequence); the signed text is
// "type|clientSequence|payload". Unsigned make*InputMessage output is what the
// parse* functions consume, so signing is layered on top.
std::string signInputMessage(
const std::string& unsignedMessage, const std::string& sessionSecretHex);
// Verifies the signature and extracts the clientSequence. Returns false (with
// an error) for a missing/invalid signature or malformed envelope.
bool verifyInputMessage(
const std::string& text, const std::string& sessionSecretHex,
std::uint64_t& clientSequence, std::string& error);
std::string makeTickMessage(const TickMessage& message);
bool parseTickMessage(
const std::string& text, TickMessage& message, std::string& error);