mirror of
https://github.com/Dingo-Shenanigans/ReSkate.git
synced 2026-10-23 17:35:57 +02:00
A dedicated server that rotates its maps can now ask players where to go next instead of taking the pool's next map. Server - maps.rotation_vote: when the timer runs out, a vote between three maps drawn at random from the pool, "Random map" and "Stay here". The most votes wins, a tie is drawn, and with no votes it is the pool's next map. It ends early once everyone has voted. - maps.rotation_vote_seconds (10-120, default 30) and maps.rotation_extend_minutes (0-240, default 15; 0 leaves "Stay here" out). - maps.rotation_announce: a card when the map has 10, 5 and 1 minutes left. - The vote's maps are drawn a minute ahead and sent to games (PacketKind::next_maps), so their pictures are ready when it opens. - /vote extend: a built-in vote that gives the map in play rotation_extend_minutes more. On by default (votes.extend_map), and only runs while the maps are on a timer. "extend" is now a reserved vote name. - Console: rotation vote on|off, rotation announce on|off, rotation stay <minutes>|off, rotation extend [minutes], votes extend ..., vote extend. Game - The vote opens as a popup in the middle of the screen: a tile per answer with its picture, name, share of the votes and count. It holds input as the map download card does, and works with a controller (D-pad, A, B), the keyboard and the mouse. - Pictures: a mod map's icon from its folder, or from Thunderstore when it is not installed; the game's own maps show their loading screen picture, cut to its middle square. "Random map", "Stay here" and a map without a picture are drawn as shapes. - Older servers and polls are unchanged: the vote is a poll, so it can still be answered with /1, /2... in chat. Protocol 50: games and servers both need this build.
62 lines
3.7 KiB
C++
62 lines
3.7 KiB
C++
#pragma once
|
|
#include "Engine/Game/Multiplayer/session_model.h"
|
|
#include <cstdint>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace dingosdk::multiplayer {
|
|
// Commands and tick execute on the game's client thread. model() is thread-safe.
|
|
std::string command(std::string_view action, std::string_view argument = {}, std::string_view password = {});
|
|
// A dedicated server's vote is running and this player may answer it (queue_command "vote" yes|no).
|
|
bool server_vote_open() noexcept;
|
|
// A dedicated server's poll is running and this player may answer it: how many answers it has
|
|
// (queue_command "vote" 1 to that many). 0: no poll.
|
|
unsigned server_poll_answers() noexcept;
|
|
// Private menu queue: passwords never pass through console history/logging.
|
|
bool queue_command(std::string_view action, std::string_view argument, std::string_view password);
|
|
// Called just before the host's validated native load is submitted, on the client thread.
|
|
void host_map_change(std::string_view destination);
|
|
enum class MapLoadResult { waiting, queued, failed, missing }; // missing: the map is not installed
|
|
// Runs on the client thread; only catalog-registered destinations may be queued.
|
|
using MapLoader = MapLoadResult (*)(std::string_view map, bool submitted, std::string &detail);
|
|
void tick(std::uintptr_t base, std::uintptr_t client, bool gameplay_ready, std::string_view map,
|
|
MapLoader loader = nullptr);
|
|
MultiplayerModel model();
|
|
std::string take_leave_notice(); // why the session just ended over a missing map, once; client thread
|
|
// The same map when the host said which Thunderstore package it is from, so it can be offered
|
|
// for download instead (Extension/Assets/map_download.h): the session does not end. It tells
|
|
// the host the map is being fetched, which is given much longer than a load, and goes on
|
|
// trying the map, so it loads as soon as it is installed. Once per map; client thread.
|
|
// The downloader ends the session (queue_command "stop") when the player says no or the map
|
|
// cannot be had. Should the session end meanwhile for another reason,
|
|
// queue_command("rejoin", "", "") goes back to it, with the password it was joined with.
|
|
struct MapNeed {
|
|
std::string package; // protocol.h: valid_map_package, never empty
|
|
std::string map; // its name for people
|
|
bool server{}; // a dedicated server's map, not a player's lobby
|
|
bool moved{}; // the session changed to this map with the player in it (else: joining)
|
|
// The version of it installed here, when that is another than the host's: the host's is
|
|
// fetched in its place. Empty: the map is not installed.
|
|
std::string have;
|
|
};
|
|
std::optional<MapNeed> take_map_need();
|
|
// Whether a session is waiting on a map being fetched right now. Thread-safe.
|
|
bool fetching_map() noexcept;
|
|
// How a host learns the package of the map it is on, to tell its guests: the level's asset in,
|
|
// the package (or nothing) out. Called on the client thread, often; it should be quick.
|
|
using MapPackageLookup = std::string (*)(std::string_view asset);
|
|
// The maps a dedicated server's vote for the next map will offer, as it said about a minute
|
|
// before the vote (protocol.h: next_maps): each one's name in the vote and its Thunderstore
|
|
// package (may be empty). None outside such a server, and after the map changed. Thread-safe;
|
|
// the serial changes whenever the list does.
|
|
struct NextMapWanted {
|
|
std::string name, package;
|
|
};
|
|
std::vector<NextMapWanted> next_maps();
|
|
unsigned next_maps_serial() noexcept;
|
|
void set_map_package_lookup(MapPackageLookup lookup) noexcept;
|
|
// The session's chat lines for the overlay. Thread-safe and cheap: callable every frame.
|
|
MultiplayerChat chat();
|
|
} // namespace dingosdk::multiplayer
|