mirror of
https://github.com/Dingo-Shenanigans/ReSkate.git
synced 2026-10-18 13:15:20 +02:00
Cap outfit packets and stop dropping recipients when a relay cannot be built. Add per-player relay limits for outfits, skater sound and voice, and a back-off for Steam IDs that keep failing to join. Throwdowns: only participants can write rows, turns and scores; a copy that fails to spawn no longer blocks the others. Throttle remote skater and skateboard re-creation, cap remote objects per session, and show developer and friend marks only for identities Steam vouches for. Route all connections through Steam's relays. Dedicated server: validate map changes, clean player names, keep vote cooldowns across reconnects, and cut ban labels on a character boundary.
54 lines
2.1 KiB
C++
54 lines
2.1 KiB
C++
#pragma once
|
|
#include <charconv>
|
|
#include <cstdint>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <utility>
|
|
|
|
// Parsing helpers for console lines, admin requests and chat commands.
|
|
namespace dingosdk::server {
|
|
inline std::string_view trim(std::string_view text) {
|
|
const auto first = text.find_first_not_of(" \t");
|
|
if (first == std::string_view::npos) return {};
|
|
return text.substr(first, text.find_last_not_of(" \t") - first + 1);
|
|
}
|
|
// The first word and the rest, both trimmed.
|
|
inline std::pair<std::string_view, std::string_view> split(std::string_view text) {
|
|
text = trim(text);
|
|
const auto space = text.find(' ');
|
|
if (space == std::string_view::npos) return {text, {}};
|
|
return {text.substr(0, space), trim(text.substr(space + 1))};
|
|
}
|
|
inline std::optional<std::uint64_t> number(std::string_view text) {
|
|
std::uint64_t value{};
|
|
const auto result = std::from_chars(text.data(), text.data() + text.size(), value);
|
|
if (result.ec != std::errc{} || result.ptr != text.data() + text.size()) return {};
|
|
return value;
|
|
}
|
|
inline std::optional<bool> on_off(std::string_view text) {
|
|
if (text == "on" || text == "true" || text == "yes") return true;
|
|
if (text == "off" || text == "false" || text == "no") return false;
|
|
return {};
|
|
}
|
|
inline std::string lower(std::string_view text) {
|
|
std::string result(text);
|
|
for (auto &c : result)
|
|
if (c >= 'A' && c <= 'Z') c = static_cast<char>(c + 32);
|
|
return result;
|
|
}
|
|
// Cuts text to at most `limit` bytes, never through a UTF-8 character.
|
|
inline void cut_text(std::string &text, std::size_t limit) {
|
|
if (text.size() <= limit) return;
|
|
auto cut = limit;
|
|
while (cut && (static_cast<unsigned char>(text[cut]) & 0xC0) == 0x80) --cut;
|
|
text.resize(cut);
|
|
}
|
|
// A command as the log shows it: the log is plain text, so a new password is left out.
|
|
inline std::string loggable(std::string_view command) {
|
|
const auto [verb, argument] = split(command);
|
|
if (lower(verb) != "password" || argument.empty() || argument == "off") return std::string(command);
|
|
return std::string(verb) + " <hidden>";
|
|
}
|
|
} // namespace dingosdk::server
|