____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

network.cpp File Reference

The network. More...

#include "stratagus.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <list>
#include "net_lowlevel.h"
#include "unit.h"
#include "unit_manager.h"
#include "unittype.h"
#include "map.h"
#include "actions.h"
#include "player.h"
#include "network.h"
#include "netconnect.h"
#include "commands.h"
#include "replay.h"
#include "interface.h"
#include "results.h"
#include "sound.h"

Go to the source code of this file.

Classes

class  CNetworkCommandQueue

Defines

#define MAX_NCQS   100

Functions

static void NetworkBroadcast (const CNetworkPacket *packet, int numcommands)
static void NetworkSendPacket (const CNetworkCommandQueue *ncq)
void InitNetwork1 (void)
 Initialise network part 1 (ports).
void ExitNetwork1 (void)
 Cleanup network part 1 (ports).
void InitNetwork2 (void)
 Initialise network part 2.
static CNetworkCommandQueueAllocNCQ (void)
static void FreeNCQ (CNetworkCommandQueue *ncq)
void NetworkSendCommand (int command, const CUnit *unit, int x, int y, const CUnit *dest, const CUnitType *type, int status)
 Send extended network command.
void NetworkSendExtendedCommand (int command, int arg1, int arg2, int arg3, int arg4, int status)
 Send Selections to Team.
void NetworkSendSelection (CUnit **units, int count)
static void NetworkProcessSelection (CNetworkPacket *packet, int player)
static void NetworkRemovePlayer (int player)
void NetworkEvent (void)
 Handle network events.
void NetworkQuit (void)
 Quit game.
void NetworkChatMessage (const std::string &msg)
 Send network command.
static void ParseNetworkCommand (const CNetworkCommandQueue *ncq)
static void NetworkResendCommands (void)
static void NetworkSendCommands (void)
static void NetworkExecCommands (void)
static void NetworkSyncCommands (void)
void NetworkCommands (void)
 Get all network commands.
void NetworkRecover (void)
 Recover network.

Variables

int NetworkNumInterfaces
 Network number of interfaces.
Socket NetworkFildes = (Socket)-1
 Network file descriptor.
int NetworkInSync = 1
 Network is in sync.
int NetworkUpdates = 5
 Network update each # game cycles.
int NetworkLag = 10
 Network lag in # game cycles.
unsigned long NetworkStatus [PlayerMax]
 Network status.
unsigned long NetworkLastFrame [PlayerMax]
 Last frame received packet.
int NetworkTimeout = 45
 Number of seconds until player times out.
static char NetMsgBuf [PlayerMax][128]
 Chat message buffers.
static int NetMsgBufLen [PlayerMax]
 Stored chat message length.
static unsigned long NetworkDelay
 Delay counter for recover.
static int NetworkSyncSeeds [256]
 Network sync seeds.
static int NetworkSyncHashs [256]
 Network sync hashs.
static CNetworkCommandQueue NetworkIn [256][PlayerMax][MaxNetworkCommands]
 Per-player network packet input queue.
std::list< CNetworkCommandQueue * > CommandsIn
 Network command input queue.
std::list< CNetworkCommandQueue * > MsgCommandsIn
 Network message input queue.
static int PlayerQuit [PlayerMax]
 Player quit.
static CNetworkCommandQueue NCQs [MAX_NCQS]
 CNetworkCommandQueues.
static int NumNCQs
 Number of NCQs in use.


Detailed Description

The network.

Definition in file network.cpp.


Define Documentation

#define MAX_NCQS   100

Definition at line 293 of file network.cpp.

Referenced by AllocNCQ().


Function Documentation

static CNetworkCommandQueue* AllocNCQ ( void   )  [static]

void ExitNetwork1 ( void   ) 

Cleanup network part 1 (ports).

Cleanup network part 1. (to be called _AFTER_ part 2 :)

Definition at line 573 of file network.cpp.

References _C_, DebugPrint, HostsCount, IsNetworkGame, NetCloseUDP(), NetExit(), NetPlayers, NetworkFildes, and NetworkInSync.

Referenced by ApplyReplaySettings(), Exit(), InitNetwork1(), and tolua_stratagus_ExitNetwork100().

static void FreeNCQ ( CNetworkCommandQueue ncq  )  [static]

Free a CNetworkCommandQueue

Parameters:
ncq CNetworkCommandQueue to free

Definition at line 648 of file network.cpp.

References NumNCQs.

Referenced by NetworkSendCommands().

void InitNetwork1 ( void   ) 

void InitNetwork2 ( void   ) 

static void NetworkBroadcast ( const CNetworkPacket packet,
int  numcommands 
) [static]

Send message to all clients.

Parameters:
packet Packet to send.
numcommands Number of commands.

Definition at line 445 of file network.cpp.

References Hosts, HostsCount, NetSendUDP(), NetworkFildes, CNetworkPacket::Serialize(), and CNetworkPacket::Size().

Referenced by NetworkEvent(), NetworkRecover(), NetworkResendCommands(), and NetworkSendPacket().

void NetworkChatMessage ( const std::string &  msg  ) 

Send network command.

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

Parameters:
msg Text message to send.

Definition at line 1121 of file network.cpp.

References AllocNCQ(), CNetworkCommandQueue::Data, CPlayer::Index, IsNetworkGame, MessageChat, MessageChatTerm, MsgCommandsIn, CNetworkChat::Player, CNetworkChat::Text, ThisPlayer, and CNetworkCommandQueue::Type.

Referenced by InputKey().

void NetworkCommands ( void   ) 

Get all network commands.

Handle network commands.

Definition at line 1360 of file network.cpp.

References GameCycle, IsNetworkGame, NetworkExecCommands(), NetworkSendCommands(), NetworkSyncCommands(), and NetworkUpdates.

Referenced by GameMainLoop().

void NetworkEvent ( void   ) 

static void NetworkExecCommands ( void   )  [static]

static void NetworkProcessSelection ( CNetworkPacket packet,
int  player 
) [static]

void NetworkQuit ( void   ) 

void NetworkRecover ( void   ) 

static void NetworkRemovePlayer ( int  player  )  [static]

Remove a player from the game.

Parameters:
player Player number

Definition at line 868 of file network.cpp.

References Hosts, HostsCount, MaxNetworkCommands, and CNetworkCommandQueue::Time.

Referenced by ParseNetworkCommand().

static void NetworkResendCommands ( void   )  [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.

Definition at line 1222 of file network.cpp.

References CNetworkPacketHeader::Cycle, GameCycle, CNetworkPacket::Header, MessageNone, MessageResend, NetworkBroadcast(), NetworkUpdates, and CNetworkPacketHeader::Type.

Referenced by NetworkRecover().

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

Send extended network command.

Prepare send of command message.

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

Parameters:
command Command (Move,Attack,...).
unit Unit that receive the command.
x optional X map position.
y optional y map position.
dest optional destination unit.
type optional unit-type argument.
status Append command or flush old commands.
Warning:
Destination and unit-type shares the same network slot.

Definition at line 672 of file network.cpp.

References AllocNCQ(), Assert, CommandsIn, CNetworkCommandQueue::Data, CNetworkCommand::Dest, GameCycle, CUnitType::Slot, CUnit::Slot, CNetworkCommandQueue::Time, CNetworkCommandQueue::Type, CNetworkCommand::Unit, CNetworkCommand::X, and CNetworkCommand::Y.

Referenced by SendCommandAttack(), SendCommandAttackGround(), SendCommandAutoRepair(), SendCommandAutoSpellCast(), SendCommandBoard(), SendCommandBuildBuilding(), SendCommandCancelTraining(), SendCommandDismiss(), SendCommandFollow(), SendCommandMove(), SendCommandPatrol(), SendCommandRepair(), SendCommandResource(), SendCommandSpellCast(), SendCommandStandGround(), SendCommandStopUnit(), SendCommandTrainUnit(), and SendCommandUnload().

static void NetworkSendCommands ( void   )  [static]

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

Send Selections to Team.

Prepare send of extended command message.

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

Parameters:
command Command (Move,Attack,...).
arg1 optional argument #1
arg2 optional argument #2
arg3 optional argument #3
arg4 optional argument #4
status Append command or flush old commands.

Definition at line 729 of file network.cpp.

References AllocNCQ(), CNetworkExtendedCommand::Arg1, CNetworkExtendedCommand::Arg2, CNetworkExtendedCommand::Arg3, CNetworkExtendedCommand::Arg4, CommandsIn, CNetworkCommandQueue::Data, CNetworkExtendedCommand::ExtendedType, GameCycle, MessageExtendedCommand, CNetworkCommandQueue::Time, and CNetworkCommandQueue::Type.

Referenced by SendCommandDiplomacy(), and SendCommandSharedVision().

static void NetworkSendPacket ( const CNetworkCommandQueue ncq  )  [static]

Network send packet. Build it from queue and broadcast.

Parameters:
ncq Outgoing network queue start.

Definition at line 463 of file network.cpp.

References CNetworkPacket::Command, CNetworkPacketHeader::Cycle, CNetworkCommandQueue::Data, CNetworkPacket::Header, MaxNetworkCommands, MessageNone, NetworkBroadcast(), CNetworkCommandQueue::Time, CNetworkPacketHeader::Type, and CNetworkCommandQueue::Type.

Referenced by NetworkEvent(), NetworkQuit(), and NetworkSendCommands().

void NetworkSendSelection ( CUnit **  units,
int  count 
)

static void NetworkSyncCommands ( void   )  [static]

Network synchronize commands.

Definition at line 1336 of file network.cpp.

References FrameCounter, GameCycle, Hosts, HostsCount, NetworkDelay, NetworkInSync, NetworkUpdates, and CNetworkHost::PlyNr.

Referenced by NetworkCommands(), and NetworkRecover().

static void ParseNetworkCommand ( const CNetworkCommandQueue ncq  )  [static]


Variable Documentation

Network command input queue.

Definition at line 277 of file network.cpp.

Referenced by InitNetwork1(), NetworkSendCommand(), NetworkSendCommands(), and NetworkSendExtendedCommand().

Network message input queue.

Definition at line 278 of file network.cpp.

Referenced by InitNetwork1(), NetworkChatMessage(), and NetworkSendCommands().

CNetworkCommandQueue NCQs[MAX_NCQS] [static]

CNetworkCommandQueues.

Definition at line 294 of file network.cpp.

char NetMsgBuf[PlayerMax][128] [static]

Chat message buffers.

Definition at line 267 of file network.cpp.

Referenced by ParseNetworkCommand().

int NetMsgBufLen[PlayerMax] [static]

Stored chat message length.

Definition at line 268 of file network.cpp.

Referenced by InitNetwork1(), and ParseNetworkCommand().

unsigned long NetworkDelay [static]

Delay counter for recover.

Definition at line 273 of file network.cpp.

Referenced by NetworkRecover(), and NetworkSyncCommands().

CNetworkCommandQueue NetworkIn[256][PlayerMax][MaxNetworkCommands] [static]

Per-player network packet input queue.

Definition at line 276 of file network.cpp.

int NetworkInSync = 1

Network is in sync.

Definition at line 260 of file network.cpp.

Referenced by ExitNetwork1(), GameMainLoop(), InitNetwork1(), NetworkEvent(), NetworkRecover(), and NetworkSyncCommands().

int NetworkLag = 10

Network lag in # game cycles.

Network lag (# game cycles).

Definition at line 262 of file network.cpp.

Referenced by ClientParseConnecting(), InitNetwork1(), InitNetwork2(), main(), NetworkQuit(), NetworkSendCommands(), and NetworkSendICMessage().

unsigned long NetworkLastFrame[PlayerMax]

Last frame received packet.

Definition at line 264 of file network.cpp.

Referenced by InitNetwork2(), NetworkEvent(), and NetworkRecover().

Network number of interfaces.

Definition at line 258 of file network.cpp.

Referenced by InitNetwork1().

unsigned long NetworkStatus[PlayerMax]

Network status.

Definition at line 263 of file network.cpp.

Referenced by InitNetwork2(), and NetworkEvent().

int NetworkSyncHashs[256] [static]

Network sync hashs.

Definition at line 275 of file network.cpp.

Referenced by InitNetwork2(), NetworkSendCommands(), and ParseNetworkCommand().

int NetworkSyncSeeds[256] [static]

Network sync seeds.

Definition at line 274 of file network.cpp.

Referenced by InitNetwork2(), NetworkSendCommands(), and ParseNetworkCommand().

int NetworkTimeout = 45

Number of seconds until player times out.

Definition at line 265 of file network.cpp.

Referenced by NetworkRecover().

int NetworkUpdates = 5

int NumNCQs [static]

Number of NCQs in use.

Definition at line 295 of file network.cpp.

Referenced by AllocNCQ(), FreeNCQ(), and InitNetwork1().

int PlayerQuit[PlayerMax] [static]

Player quit.

Definition at line 291 of file network.cpp.

Referenced by InitNetwork2(), NetworkEvent(), and NetworkRecover().


Generated on Sat Feb 21 00:28:18 2009 for Bos Wars by  doxygen 1.5.6