CUGL 3.0
Cornell University Game Library
|
#include <CUNetcodeConfig.h>
Public Member Functions | |
NetcodeConfig () | |
NetcodeConfig (const InetAddress &lobby) | |
NetcodeConfig (const InetAddress &lobby, const ICEAddress &iceServer) | |
NetcodeConfig (const std::shared_ptr< JsonValue > &prefs) | |
NetcodeConfig (const NetcodeConfig &src)=default | |
NetcodeConfig (NetcodeConfig &&src)=default | |
~NetcodeConfig () | |
NetcodeConfig & | operator= (const NetcodeConfig &src)=default |
NetcodeConfig & | operator= (NetcodeConfig &&src)=default |
NetcodeConfig & | set (const NetcodeConfig &src) |
NetcodeConfig & | set (const std::shared_ptr< NetcodeConfig > &src) |
NetcodeConfig & | set (const std::shared_ptr< JsonValue > &pref) |
Public Attributes | |
bool | secure |
InetAddress | lobby |
std::vector< ICEAddress > | iceServers |
bool | multiplex |
uint16_t | portRangeBegin |
uint16_t | portRangeEnd |
uint16_t | mtu |
size_t | bufferSize |
size_t | maxMessage |
uint16_t | maxPlayers |
std::string | uuidSeed |
uint8_t | apiVersion |
This class represents the configuration for our underlying Netcode.
Each NetcodeConnection
has a configuration that cannot be changed once connection is established. This configuration controls such things as the initial lobby server (what the game connects to find other players), the ICE servers (used for NAT traversal), and communication settings like the MTU (maximum transmission unit). All all of these, only the lobby is required. Provided that the lobby is on the same network as the players, the default values for all of the other settings are sufficient.
The lobby MUST be the address of a websocket running the CUGL game lobby. While our netcode uses standard Web RTC signaling protocols, a generic signaling server will not give us the room management that we need.
When specifying ICE servers, the standard setup is to either specify a STUN and a TURN server, or a STUN server only. Specifying no ICE servers mean that only local connections are supported.
This class is effectively a simple struct. All attributes are publicly available and we do not use the standard CUGL shared pointer architecture. Internet addresses are designed to be use on the stack, though you can combine them with shared pointers åif you wish.
cugl::netcode::NetcodeConfig::NetcodeConfig | ( | ) |
Creates a new configuration.
All values will be defaults. The lobby server will be set to 'localhost" at port 8000 (e.g. the Django port).
cugl::netcode::NetcodeConfig::NetcodeConfig | ( | const InetAddress & | lobby | ) |
Creates a new configuration with the given lobby server
All other values will be defaults. No ICE servers will be specified.
cugl::netcode::NetcodeConfig::NetcodeConfig | ( | const InetAddress & | lobby, |
const ICEAddress & | iceServer | ||
) |
Creates a new configuration with the given lobby and ICE server
All other values will be defaults. No ICE servers will be specified.
cugl::netcode::NetcodeConfig::NetcodeConfig | ( | const std::shared_ptr< JsonValue > & | prefs | ) |
Creates this configuration using a JSON entry.
The JSON value should be an object with at least one key – "lobby" – which is the JSON for an InetAddress
. All other keys are optional. They include:
"secure": A boolean indicating if the lobby uses SSL "ICE servers": A list of {@link ICEAddress} JSONs "multiplex": A boolean specifying whether to use UDP multiplexing "port range": A list pair of the ports to scan "MTU": An int representing the maximum transmission unit "buffer size": An int respresenting the size of the message buffer "max message": An int respresenting the maximum transmission size "max players": An int respresenting the maximum number of players "UUID seed": A string providing a potential UUID seed "API version": An int respresenting the API version
prefs | The configuration settings |
|
default |
Creates a copy of the configuration.
This copy constructor is provided so that internet addresses may be safely used on the stack, without the use of pointers.
src | The original configuration to copy |
|
default |
Creates a new configuration with the resources of the given one.
This move constructor is provided so that internet addresses may be used efficiently on the stack, without the use of pointers.
src | The original configuration contributing resources |
cugl::netcode::NetcodeConfig::~NetcodeConfig | ( | ) |
Deletes this configuration, disposing all resources
|
default |
Assigns this configuration to be a copy of the given configuration.
src | The configuration to copy |
|
default |
Assigns this configuration to have the resources of the given configuration.
src | The configuration to take resources from |
NetcodeConfig & cugl::netcode::NetcodeConfig::set | ( | const NetcodeConfig & | src | ) |
Assigns this configuration to be a copy of the given configuration.
src | The configuration to copy |
NetcodeConfig & cugl::netcode::NetcodeConfig::set | ( | const std::shared_ptr< JsonValue > & | pref | ) |
Assigns this configuration according to the given JSON object
The JSON value should be an object with at least one key – "lobby" – which is the JSON for an InetAddress
. All other keys are optional. They include:
"secure": A boolean indicating if the lobby uses SSL "ICE servers": A list of {@link ICEAddress} JSONs "multiplex": A boolean specifying whether to use UDP multiplexing "port range": A list pair of the ports to scan "MTU": An int representing the maximum transmission unit "buffer size": An int respresenting the size of the message buffer "max message": An int respresenting the maximum transmission size "max players": An int respresenting the maximum number of players "UUID seed": A string providing a potential UUID seed "API version": An int respresenting the API version
pref | The address settings |
NetcodeConfig & cugl::netcode::NetcodeConfig::set | ( | const std::shared_ptr< NetcodeConfig > & | src | ) |
Assigns this configuration to be a copy of the given configuration.
src | The configuration to copy |
uint8_t cugl::netcode::NetcodeConfig::apiVersion |
The API version number.
Clients with mismatched versions will be prevented from connecting to each other. Start this at 0 and increment it every time a backwards incompatible API change happens.
size_t cugl::netcode::NetcodeConfig::bufferSize |
The message buffer size (default 0 for automatic)
This value is the number of messages that can be received before a dispatcher must be called. This value is coupled to the maximum message size. If this value is small, then maximum message size may need to be increased to support data throughput.
std::vector<ICEAddress> cugl::netcode::NetcodeConfig::iceServers |
The collection of STUN/TURN servers to use (default None)
InetAddress cugl::netcode::NetcodeConfig::lobby |
The internet address for the lobby server
size_t cugl::netcode::NetcodeConfig::maxMessage |
The maximum message size (default 0 for automatic)
This value is the maximum size of a single message, which is one call to a dispatcher. It is coupled to the message buffer size. If this value is smalled, the buffer size may need to be increased to support data throughput.
uint16_t cugl::netcode::NetcodeConfig::maxPlayers |
The maximum number of players allowed (default 2)
uint16_t cugl::netcode::NetcodeConfig::mtu |
The maximum transmission unit (default 0 for automatic)
bool cugl::netcode::NetcodeConfig::multiplex |
Whether to multiplex connections over a single UDP port (default false)
uint16_t cugl::netcode::NetcodeConfig::portRangeBegin |
The starting port to scan for connections (default 1024)
uint16_t cugl::netcode::NetcodeConfig::portRangeEnd |
The final port to scan for connections (default 65535)
bool cugl::netcode::NetcodeConfig::secure |
Whether the lobby requires an SSL connection
std::string cugl::netcode::NetcodeConfig::uuidSeed |
The UUID seed (default "" for random)
If the seed is empty, each connection will generate a fresh Version 4 (random) UUID. In that case, the UUID will change for each session and/or connection to the game lobby.
To keep the UUID the same every session, provide this value with a nonempty string. In that case NetcodeConnection
will concatenate this with device information to produce a Version 5 UUID that is the same every time.
The device information is added to ensure that different devices have different UUIDs on the same seed. The device information used is the vendor id used by hashtool::system_uuid
. If no vendor id can be acquired, NetcodeConnection
rolls over to a Version 4 UUID.