mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 21:29:19 +02:00
Networking used to be reachable only through the eu07.ini network.server / network.client entries, and init_modes() refused to start at all unless a scenery file was already known. That made it impossible to join a session without knowing (and typing) the host's scenario up front, even though SERVER_HELLO already carries the scenario name. - add --host [address:port] and --connect address:port to the command line (default port 7420, --host defaults to 0.0.0.0), plus --scenario/--vehicle aliases and -h/--help; the existing ini settings keep working - drop the init_modes() restriction: a client goes straight to the scenario loader and waits there for the handshake, a host without -s still gets the launcher and simply refuses joins until a scenario is up - the loader screen reports the network state instead of sitting on a blank progress bar - a client that did not ask for a vehicle with -v starts as an observer rather than failing to find the default EU07-424; the lobby of stage 2 will take over the choice - handshake carries build identification and the server answers an impossible join with SERVER_REJECT and a readable reason instead of dropping the socket silently; protocol version bumped to 3 - deserialize_message() no longer dereferences a null message on an unknown message type
93 lines
2.2 KiB
C++
93 lines
2.2 KiB
C++
#pragma once
|
|
#include "network/message.h"
|
|
#include "input/command.h"
|
|
#include <queue>
|
|
|
|
namespace network
|
|
{
|
|
struct message
|
|
{
|
|
enum type_e
|
|
{
|
|
CLIENT_HELLO = 0,
|
|
SERVER_HELLO,
|
|
FRAME_INFO,
|
|
REQUEST_COMMAND,
|
|
SERVER_REJECT,
|
|
TYPE_MAX
|
|
};
|
|
|
|
type_e type;
|
|
|
|
message(type_e t) : type(t) {}
|
|
virtual void serialize(std::ostream &stream) const {}
|
|
virtual void deserialize(std::istream &stream) {}
|
|
};
|
|
|
|
struct client_hello : public message
|
|
{
|
|
client_hello() : message(CLIENT_HELLO) {}
|
|
|
|
virtual void serialize(std::ostream &stream) const override;
|
|
virtual void deserialize(std::istream &stream) override;
|
|
|
|
int32_t version;
|
|
uint32_t start_packet;
|
|
// build identification of the connecting simulator, informational only
|
|
std::string app_version;
|
|
};
|
|
|
|
// sent by the server instead of SERVER_HELLO when the client cannot join;
|
|
// carries a human readable reason so the player learns what went wrong
|
|
struct server_reject : public message
|
|
{
|
|
server_reject() : message(SERVER_REJECT) {}
|
|
|
|
std::string reason;
|
|
|
|
virtual void serialize(std::ostream &stream) const override;
|
|
virtual void deserialize(std::istream &stream) override;
|
|
};
|
|
|
|
struct server_hello : public message
|
|
{
|
|
server_hello() : message(SERVER_HELLO) {}
|
|
|
|
uint32_t seed;
|
|
int64_t timestamp;
|
|
int64_t config;
|
|
std::string scenario;
|
|
// build identification of the server, informational only
|
|
std::string app_version;
|
|
|
|
virtual void serialize(std::ostream &stream) const override;
|
|
virtual void deserialize(std::istream &stream) override;
|
|
};
|
|
|
|
struct request_command : public message
|
|
{
|
|
request_command(type_e type) : message(type) {}
|
|
request_command() : message(REQUEST_COMMAND) {}
|
|
|
|
command_queue::commands_map commands;
|
|
|
|
virtual void serialize(std::ostream &stream) const override;
|
|
virtual void deserialize(std::istream &stream) override;
|
|
};
|
|
|
|
struct frame_info : public request_command
|
|
{
|
|
frame_info() : request_command(FRAME_INFO) {}
|
|
|
|
double render_dt;
|
|
double dt;
|
|
double sync;
|
|
|
|
virtual void serialize(std::ostream &stream) const override;
|
|
virtual void deserialize(std::istream &stream) override;
|
|
};
|
|
|
|
std::shared_ptr<message> deserialize_message(std::istream &stream);
|
|
void serialize_message(const message &msg, std::ostream &stream);
|
|
} // namespace network
|