Files
AyeZeeBB c98c3f3207 Keep busy dedicated servers playable; hold stale skaters instead of rebuilding them
No protocol change: a server built from this still takes 1.1.4 players.

Server: what each player is sent
- A crowd limit: each player is sent at most crowd_budget poses a second
  (default 600, 0 for none; "crowd <n>|off"). Everyone at 5 a second at
  least, the nearest at the full rate, the next nearest at 10. Before,
  everyone within full-rate distance was sent at the full rate, which a
  crowd of 40 turned into more than a connection carries
- A skater's sound goes only to players within the full-rate distance,
  and in a crowd only from the nearest; it went to everyone
- A player who joins, or arrives after a map change, is shown the others
  about seven a second, nearest first, and none while what they were
  already sent is still on its way. Before, every outfit and every
  stream went at once (and to everyone at once after a map change)
- Whole pose and sound states every 8 seconds instead of 2, on the
  source's own clock, and slower pose rates sent on that clock too, so
  recipients share one patch and compression (DeltaCache) instead of one
  each. The settings survive a map change
- Object updates wait for a connection that is behind

Server: Steam connections
- send_rate (default 900 KB/s, "rate <KB/s>") is set as both Steam's
  minimum and maximum, for open connections and each new one. With only
  the maximum raised a connection stayed at Steam's 256 KB/s; set high,
  what was lost was resent until the connection was full of resends
  (about 1.1 MB/s reaches a player through the relays)
- A 4 MB send buffer, and a refused must-arrive message no longer ends
  the player's session at once: 15 seconds of refusals do (30 for object
  updates). A full queue used to drop everyone who was behind together

Server: seeing what is going on
- "net [player]": every connection's ping, delivery, queue and rate, the
  traffic by kind (poses, sound, voice, outfits, objects), who uploads
  most, and how busy the server's loop is
- A [network] line in the log every minute
- A leave or failed join says how it ended: closed by the player's game
  with Steam's reason, connection lost, or closed by the server and why
- The queue time no longer prints Steam's "unknown" as a number

Server: other
- Reserved slots: reserved_slots and reserved in ReSkateServer.json, and
  the "reserved" command; admins always have one
- The speed check flags a game at about 1.5x and over (was 1.06x), and
  tells only that player; for the admins it is in the log

Game
- A remote skater with no pose for a second stays where it was for up to
  eight seconds instead of being destroyed and rebuilt three seconds
  later. On a busy server one slow frame did that to many players at
  once, and the rebuilding made the next frames slower still
- Every waiting message is read each frame (at most 128 were)
- On an official server the role tags (Dev, Staff, Homie, Creator) show
  for every player, not only the few the game is connected to directly;
  community servers keep the old rule
- The server browser searches Steam at most every 15 seconds (45 after an
  empty answer) and keeps the last list for 15 minutes when Steam returns
  nothing, up from 2
- The game's own connections send at up to 900 KB/s
2026-10-07 14:43:45 -05:00

75 lines
3.5 KiB
C++

#pragma once
#include <algorithm>
#include <cstdint>
#include <deque>
namespace dingosdk::server {
// Game-speed check for one player: a speedhack (Cheat Engine and the like) speeds up the game's
// clock, which the player's pose timestamps come from, so the player's clock runs ahead of the
// server's. The gap between arrival and send time (network delay plus a fixed clock offset) then
// shrinks steadily instead of only jittering. Only its smallest value per block is used: delay
// spikes add to it, they never subtract, so lag cannot look like speed.
class SpeedCheck {
public:
static constexpr std::uint64_t block_us = 2000000; // one minimum per block
static constexpr std::uint64_t window_us = 20000000; // speed measured across this
static constexpr std::uint64_t gap_us = 2500000; // longer without poses (loading): start over
// Half as fast again and more is flagged. A little under 1.5, since a game at exactly 1.5x
// measures a hair either side of it; nothing but a speed hack comes near.
static constexpr double limit = 1.45;
static constexpr unsigned strikes_needed = 3; // consecutive fast measurements (one per block)
// One pose: the sender's timestamp and when it arrived, both in microseconds. Returns true
// when this sample completes a measurement (see speed()).
bool sample(std::uint64_t sent, std::uint64_t arrived) {
// A reordered or repeated pose says nothing new; a clock that jumped back (a restarted game)
// or a long pause (loading) starts over.
if (started_ && sent <= last_sent_ && last_sent_ - sent < gap_us && arrived >= last_arrived_) return false;
if (!started_ || sent < last_sent_ || arrived < last_arrived_ || arrived - last_arrived_ > gap_us) {
restart();
started_ = true;
}
last_sent_ = sent;
last_arrived_ = arrived;
const auto offset = static_cast<std::int64_t>(arrived) - static_cast<std::int64_t>(sent);
if (blocks_.empty() || arrived - blocks_.back().start >= block_us) {
const bool measured = measure();
blocks_.push_back({arrived, offset});
while (blocks_.size() > 1 && arrived - blocks_[1].start >= window_us) blocks_.pop_front();
return measured;
}
blocks_.back().min_offset = std::min(blocks_.back().min_offset, offset);
return false;
}
// The last measured speed (1 = real time) and whether it has been too fast for long enough.
double speed() const { return speed_; }
bool flagged() const { return strikes_ >= strikes_needed; }
void restart() {
blocks_.clear();
speed_ = 1.0;
strikes_ = 0;
started_ = false;
}
private:
struct Block { std::uint64_t start{}; std::int64_t min_offset{}; };
std::deque<Block> blocks_;
std::uint64_t last_sent_{}, last_arrived_{};
double speed_ = 1.0;
unsigned strikes_{};
bool started_{};
// The completed blocks span the window: compare the first block's minimum with the last one's.
bool measure() {
if (blocks_.size() < 2) return false;
const auto &first = blocks_.front(), &last = blocks_.back();
const auto span = last.start - first.start;
if (span + block_us < window_us) return false;
// Sent time advanced by (arrival span + how much the gap shrank).
speed_ = 1.0 + static_cast<double>(first.min_offset - last.min_offset) / static_cast<double>(span);
strikes_ = speed_ >= limit ? strikes_ + 1 : 0;
return true;
}
};
} // namespace dingosdk::server