_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

Classes
netconnect.cpp File Reference
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>
#include <utility>
#include <random>
#include "game.h"
#include "online_service.h"
#include "stratagus.h"
#include "netconnect.h"
#include "interface.h"
#include "map.h"
#include "network.h"
#include "parameters.h"
#include "player.h"
#include "script.h"
#include "settings.h"
#include "version.h"
#include "video.h"
#include "mdns.h"

Classes

struct  NetworkState
 
class  CServer
 
class  CClient
 

netconnect.cpp - The network high level connection code.

#define CLIENT_LIVE_BEAT   60
 
#define CLIENT_IS_DEAD   300
 
CNetworkHost Hosts [PlayerMax]
 Network players. More...
 
int NetConnectRunning = 0
 Host, ports, and assigned player numbers of all players. More...
 
int NetConnectType = 0
 Network menu: Setup mode active. More...
 
int NetLocalHostsSlot
 Network menu: Setup mode active. More...
 
int NetLocalPlayerNumber
 Network menu: Slot # in Hosts array of local client. More...
 
int NetPlayers
 Player number of local client. More...
 
std::string NetworkMapName
 How many network players. More...
 
std::string NetworkMapFragmentName
 Name of the map received with ICMMap. More...
 
bool NoRandomPlacementMultiplayer = false
 Name of the map currently loading via ICMMapNeeded. More...
 
CServerSetup ServerSetupState
 Disable the random placement of players in muliplayer mode. More...
 
CServerSetup LocalSetupState
 Network menu: Multiplayer Server Menu selections state. More...
 
MDNS MdnsService
 
static CServer Server
 
static CClient Client
 
static const char * ncconstatenames []
 
static const char * icmsgsubtypenames []
 
template<typename T >
static void NetworkSendICMessage (CUDPSocket &socket, const CHost &host, const T &msg)
 
void NetworkSendICMessage (CUDPSocket &socket, const CHost &host, const CInitMessage_Header &msg)
 Menu Loop: Client: Send GoodBye to the server and detach. More...
 
template<typename T >
static void NetworkSendICMessage_Log (CUDPSocket &socket, const CHost &host, const T &msg)
 
static void NetworkSendICMessage_Log (CUDPSocket &socket, const CHost &host, const CInitMessage_Header &msg)
 
static bool IsLocalSetupInSync (const CServerSetup &state1, const CServerSetup &state2, int index)
 
static bool IsSafeMapName (const char *mapname)
 
static int CheckVersions (const CInitMessage_Hello &msg, CUDPSocket &socket, const CHost &host)
 
int NetworkParseSetupEvent (const unsigned char *buf, int size, const CHost &host)
 Setup network connect state machine for the server. More...
 
void NetworkProcessClientRequest ()
 Menu: Setup the server IP. More...
 
int GetNetworkState ()
 
int FindHostIndexBy (const CHost &host)
 Disable the random placement of players in muliplayer mode. More...
 
void NetworkProcessServerRequest ()
 Menu Loop: Send out client request messages. More...
 
void NetworkInitClientConnect ()
 
void NetworkServerStartGame ()
 
int NetworkSetupServerAddress (const std::string &serveraddr, int port)
 Parse a network connect event. More...
 
void NetworkDetachFromServer ()
 Menu Loop: Server: Mark clients state to send stateinfo message. More...
 
void NetworkInitServerConnect (int openslots)
 Setup network connect state machine for clients. More...
 
void NetworkServerResyncClients ()
 Menu Loop: Send out server request messages. More...
 
void NetworkGamePrepareGameSettings ()
 Server user has finally hit the start game button. More...
 
static int CclNoRandomPlacementMultiplayer (lua_State *l)
 
static int CclUsesRandomPlacementMultiplayer (lua_State *l)
 
static int CclNetworkDiscoverServers (lua_State *l)
 
void NetworkCclRegister ()
 

Macro Definition Documentation

◆ CLIENT_IS_DEAD

#define CLIENT_IS_DEAD   300

◆ CLIENT_LIVE_BEAT

#define CLIENT_LIVE_BEAT   60

Function Documentation

◆ CclNetworkDiscoverServers()

static int CclNetworkDiscoverServers ( lua_State *  l)
static

◆ CclNoRandomPlacementMultiplayer()

static int CclNoRandomPlacementMultiplayer ( lua_State *  l)
static

Controls Randomization of Player position in Multiplayer mode. Without arguments, disables randomization. Otherwise, sets the NoRandomization flag to the boolean argument value.

Parameters
lLua state.

◆ CclUsesRandomPlacementMultiplayer()

static int CclUsesRandomPlacementMultiplayer ( lua_State *  l)
static

Return if player positions in multiplayer mode are randomized.

Parameters
lLua state.

◆ CheckVersions()

static int CheckVersions ( const CInitMessage_Hello msg,
CUDPSocket socket,
const CHost host 
)
static

Check if the Stratagus version and Network Protocol match

Parameters
msgmessage received
hosthost which send the message
Returns
0 if the versions match, -1 otherwise

◆ FindHostIndexBy()

int FindHostIndexBy ( const CHost host)

Disable the random placement of players in muliplayer mode.

◆ GetNetworkState()

int GetNetworkState ( )

◆ IsLocalSetupInSync()

static bool IsLocalSetupInSync ( const CServerSetup state1,
const CServerSetup state2,
int  index 
)
static

◆ IsSafeMapName()

static bool IsSafeMapName ( const char *  mapname)
static

Check if the map name looks safe.

A map name looks safe when there are no special characters and no .. or // sequences. This way only real valid maps from the map directory will be loaded.

Returns
true if the map name looks safe.

◆ NetworkCclRegister()

void NetworkCclRegister ( )

◆ NetworkDetachFromServer()

void NetworkDetachFromServer ( )

Menu Loop: Server: Mark clients state to send stateinfo message.

Terminate and detach Network connect state machine for the client

◆ NetworkGamePrepareGameSettings()

void NetworkGamePrepareGameSettings ( )

Server user has finally hit the start game button.

Multiplayer network game final copy of server settings to game settings.

◆ NetworkInitClientConnect()

void NetworkInitClientConnect ( )

Setup Network connect state machine for clients

◆ NetworkInitServerConnect()

void NetworkInitServerConnect ( int  openslots)

Setup network connect state machine for clients.

Setup Network connect state machine for the server

◆ NetworkParseSetupEvent()

int NetworkParseSetupEvent ( const unsigned char *  buf,
int  size,
const CHost host 
)

Setup network connect state machine for the server.

Parse a setup event. (Command type <= MessageInitEvent)

Parameters
bufPacket received
sizesize of the received packet.
hosthost which send the message
Returns
1 if packet is an InitConfig message, 0 otherwise

◆ NetworkProcessClientRequest()

void NetworkProcessClientRequest ( )

Menu: Setup the server IP.

Client Menu Loop: Send out client request messages

◆ NetworkProcessServerRequest()

void NetworkProcessServerRequest ( )

Menu Loop: Send out client request messages.

Server Menu Loop: Send out server request messages

◆ NetworkSendICMessage() [1/2]

void NetworkSendICMessage ( CUDPSocket socket,
const CHost host,
const CInitMessage_Header msg 
)

Menu Loop: Client: Send GoodBye to the server and detach.

◆ NetworkSendICMessage() [2/2]

template<typename T >
static void NetworkSendICMessage ( CUDPSocket socket,
const CHost host,
const T &  msg 
)
static

Send an InitConfig message across the Network

Parameters
hostHost to send to (network byte order).
portPort of host to send to (network byte order).
msgThe message to send

◆ NetworkSendICMessage_Log() [1/2]

static void NetworkSendICMessage_Log ( CUDPSocket socket,
const CHost host,
const CInitMessage_Header msg 
)
static

◆ NetworkSendICMessage_Log() [2/2]

template<typename T >
static void NetworkSendICMessage_Log ( CUDPSocket socket,
const CHost host,
const T &  msg 
)
static

◆ NetworkServerResyncClients()

void NetworkServerResyncClients ( )

Menu Loop: Send out server request messages.

Notify state change by menu user to connected clients

◆ NetworkServerStartGame()

void NetworkServerStartGame ( )

Server user has finally hit the start game button. (This is run on the server)

◆ NetworkSetupServerAddress()

int NetworkSetupServerAddress ( const std::string &  serveraddr,
int  port 
)

Parse a network connect event.

Setup the IP-Address of the network server to connect to

Parameters
serveraddrthe serveraddress the user has entered
Returns
True, if error; otherwise false.

Variable Documentation

◆ Client

CClient Client
static

◆ Hosts

Network players.

◆ icmsgsubtypenames

const char* icmsgsubtypenames[]
static
Initial value:
= {
"Hello",
"Config",
"EngineMismatch",
"ProtocolMismatch",
"EngineConfMismatch",
"MapUidMismatch",
"GameFull",
"Welcome",
"Waiting",
"Map",
"State",
"Resync",
"ServerQuit",
"GoodBye",
"SeeYou",
"Go",
"AreYouThere",
"IAmHere",
"MapNeeded",
}

◆ LocalSetupState

CServerSetup LocalSetupState

Network menu: Multiplayer Server Menu selections state.

◆ MdnsService

MDNS MdnsService

◆ ncconstatenames

const char* ncconstatenames[]
static
Initial value:
= {
"ccs_unused",
"ccs_connecting",
"ccs_connected",
"ccs_mapinfo",
"ccs_badmap",
"ccs_synced",
"ccs_async",
"ccs_changed",
"ccs_detaching",
"ccs_disconnected",
"ccs_unreachable",
"ccs_usercanceled",
"ccs_nofreeslots",
"ccs_serverquits",
"ccs_goahead",
"ccs_started",
"ccs_incompatibleengine",
"ccs_incompatibleluafiles",
"ccs_needmap",
}

◆ NetConnectRunning

int NetConnectRunning = 0

Host, ports, and assigned player numbers of all players.

Host, port, and number of all players.

◆ NetConnectType

int NetConnectType = 0

Network menu: Setup mode active.

◆ NetLocalHostsSlot

int NetLocalHostsSlot

Network menu: Setup mode active.

◆ NetLocalPlayerNumber

int NetLocalPlayerNumber

Network menu: Slot # in Hosts array of local client.

◆ NetPlayers

int NetPlayers

Player number of local client.

◆ NetworkMapFragmentName

std::string NetworkMapFragmentName

Name of the map received with ICMMap.

◆ NetworkMapName

std::string NetworkMapName

How many network players.

Player number of local client.

◆ NoRandomPlacementMultiplayer

bool NoRandomPlacementMultiplayer = false

Name of the map currently loading via ICMMapNeeded.

Network menu: Multiplayer Client Menu selections local state.

◆ Server

CServer Server
static

◆ ServerSetupState

CServerSetup ServerSetupState

Disable the random placement of players in muliplayer mode.

Name of the map currently loading via ICMMapNeeded.

(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.