You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

95 lines
2.7 KiB

/**
* @file multi.h
*
* Interface of functions for keeping multiplayer games in sync.
*/
#pragma once
#include <cstdint>
#include <span>
#include <string>
#include <string_view>
#include <vector>
#include "dvlnet/leaveinfo.hpp"
#include "msg.h"
#include "utils/attributes.h"
namespace devilution {
using net::leaveinfo_t;
// Defined in player.h, forward declared here to allow for functions which operate in the context of a player.
struct Player;
// must be unsigned to generate unsigned comparisons with pnum
#define MAX_PLRS 4
struct GameData {
int32_t size;
uint8_t reserved[4];
uint32_t programid;
uint8_t versionMajor;
uint8_t versionMinor;
uint8_t versionPatch;
_difficulty nDifficulty;
uint8_t nTickRate;
uint8_t bRunInTown;
uint8_t bTheoQuest;
uint8_t bCowQuest;
uint8_t bFriendlyFire;
uint8_t fullQuests;
/** Used to initialise the seed table for dungeon levels so players in multiplayer games generate the same layout */
uint32_t gameSeed[4];
/** FNV-1a hash of active mod list for multiplayer compatibility check */
uint32_t modHash;
void swapLE();
};
/* @brief Contains info of running public game (for game list browsing) */
struct GameInfo {
std::string name;
GameData gameData;
std::vector<std::string> players;
std::optional<int> latency;
std::optional<bool> peerIsRelayed;
};
extern bool gbSomebodyWonGameKludge;
extern uint16_t sgwPackPlrOffsetTbl[MAX_PLRS];
extern uint8_t gbActivePlayers;
extern bool gbGameDestroyed;
extern DVL_API_FOR_TEST GameData sgGameInitInfo;
extern bool gbSelectProvider;
extern DVL_API_FOR_TEST bool gbIsMultiplayer;
extern std::string GameName;
extern std::string GamePassword;
extern bool PublicGame;
extern uint8_t gbDeltaSender;
extern uint32_t player_state[MAX_PLRS];
extern bool IsLoopback;
DVL_API_FOR_TEST std::string DescribeLeaveReason(leaveinfo_t leaveReason);
std::string FormatGameSeed(const uint32_t gameSeed[4]);
uint32_t ComputeModListHash(std::span<const std::string_view> mods);
void InitGameInfo();
void NetSendLoPri(uint8_t playerId, const std::byte *data, size_t size);
void NetSendHiPri(uint8_t playerId, const std::byte *data, size_t size);
void multi_send_msg_packet(uint32_t pmask, const std::byte *data, size_t size);
void multi_msg_countdown();
void multi_player_left(uint8_t pnum, leaveinfo_t reason);
void multi_net_ping();
/**
* @return Always true for singleplayer
*/
bool multi_handle_delta();
void ProcessGameMessagePackets();
void multi_send_zero_packet(uint8_t pnum, _cmd_id bCmd, const std::byte *data, size_t size);
void NetClose();
bool NetInit(bool bSinglePlayer);
void recv_plrinfo(Player &player, const TCmdPlrInfoHdr &header, bool recv);
} // namespace devilution