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

Classes
network.cpp File Reference
#include "online_service.h"
#include "stratagus.h"
#include <stddef.h>
#include <list>
#include "network.h"
#include "actions.h"
#include "commands.h"
#include "interface.h"
#include "map.h"
#include "net_lowlevel.h"
#include "net_message.h"
#include "netconnect.h"
#include "parameters.h"
#include "player.h"
#include "replay.h"
#include "sound.h"
#include "translate.h"
#include "unit.h"
#include "unit_manager.h"
#include "unittype.h"
#include "video.h"
#include <deque>

Classes

class  CNetworkCommandQueue
 Save game. More...
 

network.cpp - The network.

bool NetworkInSync = true
 Network file descriptor. More...
 
CUDPSocket NetworkFildes
 Network is in sync. More...
 
static unsigned long NetworkLastFrame [PlayerMax]
 Network file descriptor. More...
 
static unsigned long NetworkLastCycle [PlayerMax]
 Last frame received packet. More...
 
static unsigned int NetworkSyncSeeds [256]
 Last cycle received packet. More...
 
static unsigned int NetworkSyncHashs [256]
 Network sync seeds. More...
 
static CNetworkCommandQueue NetworkIn [256][PlayerMax][MaxNetworkCommands]
 Network sync hashs. More...
 
static std::deque< CNetworkCommandQueueCommandsIn
 Per-player network packet input queue. More...
 
static std::deque< CNetworkCommandQueueMsgCommandsIn
 Network command input queue. More...
 
static int PlayerQuit [PlayerMax]
 Network message input queue. More...
 
int SaveGame (const std::string &filename)
 Load saved game. More...
 
static void NetworkBroadcast (const CNetworkPacket &packet, int numcommands, int player=255)
 Player quit. More...
 
static void NetworkSendPacket (const CNetworkCommandQueue(&ncq)[MaxNetworkCommands])
 
void InitNetwork1 ()
 
void ExitNetwork1 ()
 Initialise network. More...
 
void NetworkOnStartGame ()
 Cleanup network (port) More...
 
void NetworkSendCommand (int command, const CUnit &unit, int x, int y, const CUnit *dest, const CUnitType *type, int status)
 Send network command. More...
 
void NetworkSendExtendedCommand (int command, int arg1, int arg2, int arg3, int arg4, int status)
 Send extended network command. More...
 
void NetworkSendSelection (CUnit **units, int count)
 Send Selections to Team. More...
 
void NetworkSendChatMessage (const std::string &msg)
 Get all network commands. More...
 
static void NetworkRemovePlayer (int player)
 
static bool IsNetworkCommandReady (int hostIndex, unsigned long gameNetCycle)
 
static bool IsNetworkCommandReady (unsigned long gameNetCycle)
 
static void ParseResendCommand (const CNetworkPacket &packet)
 
static bool IsAValidCommand_Command (const CNetworkPacket &packet, int index, const int player)
 
static bool IsAValidCommand_Dismiss (const CNetworkPacket &packet, int index, const int player)
 
static bool IsAValidCommand (const CNetworkPacket &packet, int index, const int player)
 
static void NetworkParseInGameEvent (const unsigned char *buf, int len, const CHost &host)
 
void NetworkEvent ()
 Initialise network data for ingame communication. More...
 
void NetworkQuitGame ()
 Hold in sync. More...
 
static void NetworkExecCommand_Sync (const CNetworkCommandQueue &ncq)
 
static void NetworkExecCommand_Selection (const CNetworkCommandQueue &ncq)
 
static void NetworkExecCommand_Chat (const CNetworkCommandQueue &ncq)
 
static void NetworkExecCommand_Quit (const CNetworkCommandQueue &ncq)
 
static void NetworkExecCommand_ExtendedCommand (const CNetworkCommandQueue &ncq)
 
static void NetworkExecCommand_Command (const CNetworkCommandQueue &ncq)
 
static void NetworkExecCommand (const CNetworkCommandQueue &ncq)
 
static void NetworkSendCommands (unsigned long gameNetCycle)
 
static void NetworkExecCommands (unsigned long gameNetCycle)
 
void NetworkCommands ()
 Recover network. More...
 
static void CheckPlayerThatTimeOut (int hostIndex)
 
static void NetworkResendCommands ()
 
void NetworkRecover ()
 Quit game: warn other users. More...
 

Function Documentation

◆ CheckPlayerThatTimeOut()

static void CheckPlayerThatTimeOut ( int  hostIndex)
static

◆ ExitNetwork1()

void ExitNetwork1 ( )

Initialise network.

Cleanup network.

◆ InitNetwork1()

void InitNetwork1 ( )

Initialize network port.

◆ IsAValidCommand()

static bool IsAValidCommand ( const CNetworkPacket packet,
int  index,
const int  player 
)
static

◆ IsAValidCommand_Command()

static bool IsAValidCommand_Command ( const CNetworkPacket packet,
int  index,
const int  player 
)
static

◆ IsAValidCommand_Dismiss()

static bool IsAValidCommand_Dismiss ( const CNetworkPacket packet,
int  index,
const int  player 
)
static

◆ IsNetworkCommandReady() [1/2]

static bool IsNetworkCommandReady ( int  hostIndex,
unsigned long  gameNetCycle 
)
static

◆ IsNetworkCommandReady() [2/2]

static bool IsNetworkCommandReady ( unsigned long  gameNetCycle)
static

◆ NetworkBroadcast()

static void NetworkBroadcast ( const CNetworkPacket packet,
int  numcommands,
int  player = 255 
)
static

Player quit.

Send message to all clients.

Parameters
packetPacket to send.
numcommandsNumber of commands.

◆ NetworkCommands()

void NetworkCommands ( )

Recover network.

Handle network commands.

◆ NetworkEvent()

void NetworkEvent ( )

Initialise network data for ingame communication.

Called if message for the network is ready. (by WaitEventsOneFrame)

◆ NetworkExecCommand()

static void NetworkExecCommand ( const CNetworkCommandQueue ncq)
static

Execute a network command.

Parameters
ncqNetwork command from queue

◆ NetworkExecCommand_Chat()

static void NetworkExecCommand_Chat ( const CNetworkCommandQueue ncq)
static

◆ NetworkExecCommand_Command()

static void NetworkExecCommand_Command ( const CNetworkCommandQueue ncq)
static

◆ NetworkExecCommand_ExtendedCommand()

static void NetworkExecCommand_ExtendedCommand ( const CNetworkCommandQueue ncq)
static

◆ NetworkExecCommand_Quit()

static void NetworkExecCommand_Quit ( const CNetworkCommandQueue ncq)
static

◆ NetworkExecCommand_Selection()

static void NetworkExecCommand_Selection ( const CNetworkCommandQueue ncq)
static

◆ NetworkExecCommand_Sync()

static void NetworkExecCommand_Sync ( const CNetworkCommandQueue ncq)
static

◆ NetworkExecCommands()

static void NetworkExecCommands ( unsigned long  gameNetCycle)
static

Network execute commands.

◆ NetworkOnStartGame()

void NetworkOnStartGame ( )

Cleanup network (port)

Game will start now. (This function runs on all clients.)

◆ NetworkParseInGameEvent()

static void NetworkParseInGameEvent ( const unsigned char *  buf,
int  len,
const CHost host 
)
static

◆ NetworkQuitGame()

void NetworkQuitGame ( )

Hold in sync.

Quit the game.

◆ NetworkRecover()

void NetworkRecover ( )

Quit game: warn other users.

Recover network.

◆ NetworkRemovePlayer()

static void NetworkRemovePlayer ( int  player)
static

Remove a player from the game.

Parameters
playerPlayer number

◆ NetworkResendCommands()

static void NetworkResendCommands ( )
static

Network resend commands, we have a missing packet send to all clients what packet we are missing.

Todo:
We need only send to the clients, that have not delivered the packet.

◆ NetworkSendChatMessage()

void NetworkSendChatMessage ( const std::string &  msg)

Get all network commands.

Send chat message. (Message is sent with low priority)

Parameters
msgText message to send.

◆ NetworkSendCommand()

void NetworkSendCommand ( int  command,
const CUnit unit,
int  x,
int  y,
const CUnit dest,
const CUnitType type,
int  status 
)

Send network command.

Prepare send of command message.

Convert arguments into network format and place it into output queue.

Parameters
commandCommand (Move,Attack,...).
unitUnit that receive the command.
xoptional X map position.
yoptional y map position.
destoptional destination unit.
typeoptional unit-type argument.
statusAppend command or flush old commands.
Warning
Destination and unit-type shares the same network slot.

◆ NetworkSendCommands()

static void NetworkSendCommands ( unsigned long  gameNetCycle)
static

Network send commands.

◆ NetworkSendExtendedCommand()

void NetworkSendExtendedCommand ( int  command,
int  arg1,
int  arg2,
int  arg3,
int  arg4,
int  status 
)

Send extended network command.

Prepare send of extended command message.

Convert arguments into network format and place it into output queue.

Parameters
commandCommand (Move,Attack,...).
arg1optional argument #1
arg2optional argument #2
arg3optional argument #3
arg4optional argument #4
statusAppend command or flush old commands.

◆ NetworkSendPacket()

static void NetworkSendPacket ( const CNetworkCommandQueue(&)  ncq[MaxNetworkCommands])
static

Network send packet. Build it from queue and broadcast.

Parameters
ncqOutgoing network queue start.

◆ NetworkSendSelection()

void NetworkSendSelection ( CUnit **  units,
int  count 
)

Send Selections to Team.

Sends my selections to teammates

Parameters
unitsUnits to send
countNumber of units to send

◆ ParseResendCommand()

static void ParseResendCommand ( const CNetworkPacket packet)
static

◆ SaveGame()

int SaveGame ( const std::string &  filename)

Load saved game.

Save a game to file.

Parameters
filenameFile name to be stored.
Returns
-1 if saving failed, 0 if all OK
Note
Later we want to store in a more compact binary format.

Variable Documentation

◆ CommandsIn

std::deque<CNetworkCommandQueue> CommandsIn
static

Per-player network packet input queue.

◆ MsgCommandsIn

std::deque<CNetworkCommandQueue> MsgCommandsIn
static

Network command input queue.

◆ NetworkFildes

CUDPSocket NetworkFildes

Network is in sync.

◆ NetworkIn

Network sync hashs.

◆ NetworkInSync

bool NetworkInSync = true

Network file descriptor.

◆ NetworkLastCycle

unsigned long NetworkLastCycle[PlayerMax]
static

Last frame received packet.

◆ NetworkLastFrame

unsigned long NetworkLastFrame[PlayerMax]
static

Network file descriptor.

◆ NetworkSyncHashs

unsigned int NetworkSyncHashs[256]
static

Network sync seeds.

◆ NetworkSyncSeeds

unsigned int NetworkSyncSeeds[256]
static

Last cycle received packet.

◆ PlayerQuit

int PlayerQuit[PlayerMax]
static

Network message input queue.

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