$treeview $search $mathjax
Stratagus
2.2.6
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "stratagus.h"
#include "net_lowlevel.h"
#include "player.h"
#include "map.h"
#include "network.h"
#include "netconnect.h"
#include "interface.h"
#include "menus.h"
#include "settings.h"
#include "version.h"
netconnect.cpp - The network high level connection code. | |
#define | CLIENT_LIVE_BEAT 60 |
#define | CLIENT_IS_DEAD 300 |
std::string | NetworkArg |
int | NetPlayers |
Network command line argument. | |
char * | NetworkAddr = NULL |
How many network players. | |
int | NetworkPort = NetworkDefaultPort |
Local network address to use. | |
int | HostsCount |
Local network port to use. | |
CNetworkHost | Hosts [PlayerMax] |
Number of hosts. | |
int | NetConnectRunning |
Host and ports of all players. | |
NetworkState | NetStates [PlayerMax] |
Network menu: Setup mode active. | |
unsigned char | NetLocalState |
Network menu: Server: Client Host states. | |
int | NetLocalHostsSlot |
Network menu: Local Server/Client connect state;. | |
int | NetLocalPlayerNumber |
Network menu: Slot # in Hosts array of local client. | |
static int | NetStateMsgCnt |
Player number of local client. | |
static unsigned char | LastStateMsgType |
Number of consecutive msgs of same type sent. | |
static unsigned long | NetLastPacketSent |
Subtype of last InitConfig message sent. | |
static unsigned long | NetworkServerIP |
Tick the last network packet was sent. | |
std::string | NetworkMapName |
Network Client: IP of server to join. | |
static int | NetworkServerPort = NetworkDefaultPort |
Name of the map recieved with ICMMap. | |
CServerSetup | ServerSetupState |
Server network port to use. | |
CServerSetup | LocalSetupState |
Network menu: Multiplayer Server Menu selections state. | |
static int | NetworkSendICMessage (unsigned long host, int port, CInitMessage *msg) |
static void | NetworkSendRateLimitedClientMessage (CInitMessage *msg, unsigned long msecs) |
int | NetworkSetupServerAddress (const std::string &serveraddr) |
Parse a network connect event. | |
void | NetworkInitClientConnect () |
Assign Player slot, evaluate Setup state.. | |
void | NetworkExitClientConnect () |
Setup network connect state machine for clients. | |
void | NetworkDetachFromServer () |
Menu Loop: Server: Mark clients state to send stateinfo message. | |
void | NetworkInitServerConnect (int openslots) |
Terminate network connect state machine for clients. | |
void | NetworkExitServerConnect () |
Setup network connect state machine for the server. | |
void | NetworkServerResyncClients () |
Menu Loop: Send out server request messages. | |
void | NetworkServerStartGame () |
Network menu: Multiplayer Client Menu selections local state. | |
void | NetworkGamePrepareGameSettings () |
Server user has finally hit the start game button. | |
void | NetworkConnectSetupGame () |
void | NetClientCheckLocalState () |
Compare Local State <-> Server's state, force Update when changes. | |
void | NetworkProcessClientRequest () |
Menu: Setup the server IP. | |
static void | KickDeadClient (int c) |
void | NetworkProcessServerRequest () |
Menu Loop: Send out client request messages. | |
static void | ClientParseDetaching (const CInitMessage *msg) |
static void | ClientParseConnecting (const CInitMessage *msg) |
static bool | IsSafeMapName (const char *mapname) |
static void | ClientParseConnected (const CInitMessage *msg) |
static void | ClientParseMapInfo (const CInitMessage *msg) |
static void | ClientParseSynced (const CInitMessage *msg) |
static void | ClientParseAsync (const CInitMessage *msg) |
static void | ClientParseGoAhead (const CInitMessage *msg) |
static void | ClientParseStarted (const CInitMessage *msg) |
static void | ClientParseAreYouThere (const CInitMessage *) |
static void | ClientParseBadMap (const CInitMessage *) |
static void | ServerParseHello (int h, const CInitMessage *msg) |
static void | ServerParseResync (const int h) |
static void | ServerParseWaiting (const int h) |
static void | ServerParseMap (const int h) |
static void | ServerParseState (const int h, const CInitMessage *msg) |
static void | ServerParseGoodBye (const int h) |
static void | ServerParseSeeYou (const int h) |
static void | ServerParseIAmHere (const int h) |
static int | CheckVersions (const CInitMessage *msg) |
static void | NetworkParseMenuPacket (const CInitMessage *msg) |
int | NetworkParseSetupEvent (const unsigned char *buf, int size) |
Terminate network connect state machine for the server. |
#define CLIENT_IS_DEAD 300 |
#define CLIENT_LIVE_BEAT 60 |
static int CheckVersions | ( | const CInitMessage * | msg | ) | [static] |
Check if the Stratagus version and Network Protocol match
msg | message received |
static void ClientParseAreYouThere | ( | const CInitMessage * | ) | [static] |
Parse a network menu AreYouThere keepalive packet and reply IAmHere.
msg | message received |
static void ClientParseAsync | ( | const CInitMessage * | msg | ) | [static] |
Parse a network menu packet in client async state.
msg | message received |
static void ClientParseBadMap | ( | const CInitMessage * | ) | [static] |
Parse a network menu Bad Map reply from server.
msg | message received |
static void ClientParseConnected | ( | const CInitMessage * | msg | ) | [static] |
Parse a network menu packet in client connected state.
msg | message received |
static void ClientParseConnecting | ( | const CInitMessage * | msg | ) | [static] |
Parse a network menu packet in client connecting state.
msg | message received |
static void ClientParseDetaching | ( | const CInitMessage * | msg | ) | [static] |
Parse a network menu packet in client detaching state.
msg | message received |
static void ClientParseGoAhead | ( | const CInitMessage * | msg | ) | [static] |
Parse a network menu packet in client final goahead waiting state.
msg | message received |
static void ClientParseMapInfo | ( | const CInitMessage * | msg | ) | [static] |
Parse a network menu packet in client initial mapinfo state.
msg | message received |
static void ClientParseStarted | ( | const CInitMessage * | msg | ) | [static] |
Parse a network menu packet in client final started state
msg | message received |
static void ClientParseSynced | ( | const CInitMessage * | msg | ) | [static] |
Parse a network menu packet in client synced state.
msg | message received |
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.
static void KickDeadClient | ( | int | c | ) | [static] |
Kick a client that doesn't answer to our packets
c | The client (host slot) to kick |
void NetClientCheckLocalState | ( | ) |
Compare Local State <-> Server's state, force Update when changes.
Callback from netconnect loop in Client-Sync state: Compare local state with server's information and force update when changes have occured.
void NetworkConnectSetupGame | ( | ) |
Assign player slots and names in a network game..
void NetworkDetachFromServer | ( | ) |
Menu Loop: Server: Mark clients state to send stateinfo message.
Terminate and detach Network connect state machine for the client
void NetworkExitClientConnect | ( | ) |
Setup network connect state machine for clients.
Terminate Network connect state machine for clients
void NetworkExitServerConnect | ( | ) |
Setup network connect state machine for the server.
Terminate Network connect state machine for the server
void NetworkGamePrepareGameSettings | ( | void | ) |
Server user has finally hit the start game button.
Multiplayer network game final race an player type setup.
void NetworkInitClientConnect | ( | ) |
Assign Player slot, evaluate Setup state..
Setup Network connect state machine for clients
void NetworkInitServerConnect | ( | int | openslots | ) |
Terminate network connect state machine for clients.
Setup Network connect state machine for the server
static void NetworkParseMenuPacket | ( | const CInitMessage * | msg | ) | [static] |
Parse a Network menu packet.
msg | message received |
int NetworkParseSetupEvent | ( | const unsigned char * | buf, | |
int | size | |||
) |
Terminate network connect state machine for the server.
Parse a setup event. (Command type <= MessageInitEvent)
buf | Packet received | |
size | size of the received packet. |
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
static int NetworkSendICMessage | ( | unsigned long | host, | |
int | port, | |||
CInitMessage * | msg | |||
) | [static] |
Send an InitConfig message across the Network
host | Host to send to (network byte order). | |
port | Port of host to send to (network byte order). | |
msg | The message to send |
static void NetworkSendRateLimitedClientMessage | ( | CInitMessage * | msg, | |
unsigned long | msecs | |||
) | [static] |
Send a message to the server, but only if the last packet was a while ago
msg | The message to send | |
msecs | microseconds to delay |
void NetworkServerResyncClients | ( | ) |
Menu Loop: Send out server request messages.
Notify state change by menu user to connected clients
void NetworkServerStartGame | ( | ) |
Network menu: Multiplayer Client Menu selections local state.
Server user has finally hit the start game button
int NetworkSetupServerAddress | ( | const std::string & | serveraddr | ) |
Parse a network connect event.
Setup the IP-Address of the network server to connect to
serveraddr | the serveraddress the user has entered |
static void ServerParseGoodBye | ( | const int | h | ) | [static] |
Parse the disconnect request of a client by sending out good bye
h | slot number of host msg originates from |
static void ServerParseHello | ( | int | h, | |
const CInitMessage * | msg | |||
) | [static] |
Parse the initial 'Hello' message of new client that wants to join the game
h | slot number of host msg originates from | |
msg | message received |
static void ServerParseIAmHere | ( | const int | h | ) | [static] |
Parse the 'I am Here' reply to the servers' 'Are you there' msg
h | slot number of host msg originates from |
static void ServerParseMap | ( | const int | h | ) | [static] |
Parse client map info acknoledge message
h | slot number of host msg originates from |
static void ServerParseResync | ( | const int | h | ) | [static] |
Parse client resync request after client user has changed menu selection
h | slot number of host msg originates from |
static void ServerParseSeeYou | ( | const int | h | ) | [static] |
Parse the final see you msg of a disconnecting client
h | slot number of host msg originates from |
static void ServerParseState | ( | const int | h, | |
const CInitMessage * | msg | |||
) | [static] |
Parse locate state change notifiction or initial state info request of client
h | slot number of host msg originates from | |
msg | message received |
static void ServerParseWaiting | ( | const int | h | ) | [static] |
Parse client heart beat waiting message
h | slot number of host msg originates from |
CNetworkHost Hosts[PlayerMax] |
Number of hosts.
int HostsCount |
Local network port to use.
unsigned char LastStateMsgType [static] |
Number of consecutive msgs of same type sent.
Network menu: Multiplayer Server Menu selections state.
Host and ports of all players.
Host, port, and number of all players.
unsigned long NetLastPacketSent [static] |
Subtype of last InitConfig message sent.
Network menu: Local Server/Client connect state;.
Network menu: Local Server/Client connect state.
Network menu: Slot # in Hosts array of local client.
unsigned char NetLocalState |
Network menu: Server: Client Host states.
int NetPlayers |
Network command line argument.
int NetStateMsgCnt [static] |
Player number of local client.
NetworkState NetStates[PlayerMax] |
Network menu: Setup mode active.
char* NetworkAddr = NULL |
How many network players.
Network players.
std::string NetworkArg |
std::string NetworkMapName |
Network Client: IP of server to join.
int NetworkPort = NetworkDefaultPort |
Local network address to use.
unsigned long NetworkServerIP [static] |
Tick the last network packet was sent.
int NetworkServerPort = NetworkDefaultPort [static] |
Name of the map recieved with ICMMap.
FIXME ARI: The following is a kludge to have some way to override the default port on the server to connect to. Should be selectable by advanced network menus. For now just specify with the -P port command line arg...
Server network port to use.
Player number of local client.
Client and server selection state for Multiplayer clients