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

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes
netconnect.cpp File Reference
#include "stratagus.h"
#include "netconnect.h"
#include "interface.h"
#include "map.h"
#include "master.h"
#include "network.h"
#include "parameters.h"
#include "player.h"
#include "script.h"
#include "settings.h"
#include "version.h"
#include "video.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
 
int HostsCount
 Network players. More...
 
CNetworkHost Hosts [PlayerMax]
 Number of hosts. More...
 
int NetConnectRunning = 0
 Host and ports 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...
 
static int NoRandomPlacementMultiplayer = 0
 Name of the map received with ICMMap. More...
 
CServerSetup ServerSetupState
 Disable the random placement of players in muliplayer mode. More...
 
CServerSetup LocalSetupState
 Network menu: Multiplayer Server Menu selections state. More...
 
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)
 
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)
 Network menu: Multiplayer Client Menu selections local state. 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)
 
void NetworkCclRegister ()
 

Macro Definition Documentation

#define CLIENT_IS_DEAD   300
#define CLIENT_LIVE_BEAT   60

Function Documentation

static int CclNoRandomPlacementMultiplayer ( lua_State *  l)
static

Removes Randomization of Player position in Multiplayer mode

Parameters
lLua state.
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
int FindHostIndexBy ( const CHost host)

Network menu: Multiplayer Client Menu selections local state.

int GetNetworkState ( )
static bool IsLocalSetupInSync ( const CServerSetup state1,
const CServerSetup state2,
int  index 
)
static
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.
void NetworkCclRegister ( )
void NetworkDetachFromServer ( )

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

Terminate and detach Network connect state machine for the client

void NetworkGamePrepareGameSettings ( void  )

Server user has finally hit the start game button.

Multiplayer network game final race and player type setup.

void NetworkInitClientConnect ( )

Setup Network connect state machine for clients

void NetworkInitServerConnect ( int  openslots)

Setup network connect state machine for clients.

Setup Network connect state machine for the server

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
void NetworkProcessClientRequest ( )

Menu: Setup the server IP.

Client Menu Loop: Send out client request messages

void NetworkProcessServerRequest ( )

Menu Loop: Send out client request messages.

Server Menu Loop: Send out server request messages

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
void NetworkSendICMessage ( CUDPSocket socket,
const CHost host,
const CInitMessage_Header msg 
)
template<typename T >
static void NetworkSendICMessage_Log ( CUDPSocket socket,
const CHost host,
const T &  msg 
)
static
static void NetworkSendICMessage_Log ( CUDPSocket socket,
const CHost host,
const CInitMessage_Header msg 
)
static
void NetworkServerResyncClients ( )

Menu Loop: Send out server request messages.

Notify state change by menu user to connected clients

void NetworkServerStartGame ( )

Server user has finally hit the start game button

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

CClient Client
static

Number of hosts.

int HostsCount

Network players.

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

Network menu: Multiplayer Server Menu selections state.

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",
}
int NetConnectRunning = 0

Host and ports of all players.

Host, port, and number of all players.

int NetConnectType = 0

Network menu: Setup mode active.

int NetLocalHostsSlot

Network menu: Setup mode active.

int NetLocalPlayerNumber

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

int NetPlayers

Player number of local client.

std::string NetworkMapName

How many network players.

int NoRandomPlacementMultiplayer = 0
static

Name of the map received with ICMMap.

CServer Server
static
CServerSetup ServerSetupState

Disable the random placement of players in muliplayer mode.

Player number of local client.

(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.