____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
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"
#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 CNetworkCommandQueue * | AllocNCQ (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. | |
Definition in file network.cpp.
| #define MAX_NCQS 100 |
| static CNetworkCommandQueue* AllocNCQ | ( | void | ) | [static] |
Allocate a CNetworkCommandQueue
Definition at line 635 of file network.cpp.
References Assert, CNetworkCommandQueue::Clear(), MAX_NCQS, and NumNCQs.
Referenced by NetworkChatMessage(), NetworkSendCommand(), and NetworkSendExtendedCommand().
| 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
| ncq | CNetworkCommandQueue to free |
Definition at line 648 of file network.cpp.
References NumNCQs.
Referenced by NetworkSendCommands().
| void InitNetwork1 | ( | void | ) |
Initialise network part 1 (ports).
Initialize network part 1.
Definition at line 498 of file network.cpp.
References _C_, CommandsIn, DebugPrint, ExitNetwork1(), MsgCommandsIn, NetExit(), NetInit(), NetLastPort, NetLocalAddrs, NetMsgBufLen, NetOpenUDP(), NetResolveHost(), NetSocketAddr(), NetworkFildes, NetworkInSync, NetworkLag, NetworkNumInterfaces, NetworkPort, NetworkUpdates, NIPQUAD, NumNCQs, and PlayerMax.
Referenced by tolua_stratagus_InitNetwork100().
| void InitNetwork2 | ( | void | ) |
Initialise network part 2.
Initialize network part 2.
Definition at line 599 of file network.cpp.
References _C_, DebugPrint, Hosts, HostsCount, MaxNetworkCommands, MessageSync, NetworkConnectSetupGame(), NetworkLag, NetworkLastFrame, NetworkStatus, NetworkSyncHashs, NetworkSyncSeeds, NetworkUpdates, PlayerQuit, CNetworkHost::PlyNr, CNetworkCommandQueue::Time, and CNetworkCommandQueue::Type.
Referenced by CreateGame().
| static void NetworkBroadcast | ( | const CNetworkPacket * | packet, | |
| int | numcommands | |||
| ) | [static] |
Send message to all clients.
| 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)
| 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 | ) |
Handle network events.
Called if message for the network is ready. (by WaitEventsOneFrame)
Definition at line 895 of file network.cpp.
References _, _C_, CNetworkPacket::Command, CNetworkPacketHeader::Cycle, CNetworkCommandQueue::Data, DebugPrint, CNetworkPacket::Deserialize(), FrameCounter, GameCycle, CNetworkPacket::Header, Hosts, HostsCount, CPlayer::Index, IsNetworkGame, CPlayer::IsTeamed(), MaxNetworkCommands, MessageChat, MessageChatTerm, MessageCommandDismiss, MessageExtendedCommand, MessageNone, MessageQuit, MessageQuitAck, MessageResend, MessageSelection, MessageSync, NetConnectRunning, NetLastHost, NetLastPort, NetRecvUDP(), NetworkBroadcast(), NetworkFildes, NetworkInSync, NetworkLastFrame, NetworkParseSetupEvent(), NetworkProcessSelection(), NetworkSendPacket(), NetworkStatus, NetworkUpdates, NIPQUAD, NumPlayers, PlayerQuit, Players, CNetworkHost::PlyNr, SetMessage(), ThisPlayer, CNetworkCommandQueue::Time, CNetworkCommandQueue::Type, CNetworkPacketHeader::Type, CNetworkCommand::Unit, UnitSlotFree, UnitSlots, and CNetworkCommand::X.
Referenced by CEditor::Init(), InitCallbacks(), InitGameCallbacks(), initGuichan(), and PlayMovie().
| static void NetworkExecCommands | ( | void | ) | [static] |
Network excecute commands.
Definition at line 1303 of file network.cpp.
References _C_, Assert, DebugPrint, GameCycle, MaxNetworkCommands, MessageNone, NumPlayers, ParseNetworkCommand(), CNetworkCommandQueue::Time, and CNetworkCommandQueue::Type.
Referenced by NetworkCommands().
| static void NetworkProcessSelection | ( | CNetworkPacket * | packet, | |
| int | player | |||
| ) | [static] |
Process Received Unit Selection
| packet | Network Packet to Process | |
| player | Player number |
Definition at line 835 of file network.cpp.
References _network_selection_header_::Add, Assert, ChangeTeamSelectedUnits(), CNetworkPacket::Command, CNetworkPacket::Header, MessageSelection, _network_selection_header_::NumberSent, Players, _network_selection_header_::Remove, _network_selection_header_::Type, CNetworkSelection::Unit, UnitMax, and Units.
Referenced by NetworkEvent().
| void NetworkQuit | ( | void | ) |
Quit game.
Quit the game.
Definition at line 1098 of file network.cpp.
References CNetworkCommandQueue::Data, GameCycle, CPlayer::Index, MaxNetworkCommands, MessageNone, MessageQuit, NetworkLag, NetworkSendPacket(), NetworkUpdates, ThisPlayer, CNetworkCommandQueue::Time, CNetworkCommandQueue::Type, and CNetworkCommand::X.
Referenced by Exit(), and GameMainLoop().
| void NetworkRecover | ( | void | ) |
Recover network.
Recover network.
Definition at line 1376 of file network.cpp.
References _, CNetworkPacketHeader::Cycle, CNetworkCommandQueue::Data, FrameCounter, FRAMES_PER_SECOND, GameCycle, CNetworkPacket::Header, Hosts, HostsCount, MessageNone, MessageQuit, NetworkBroadcast(), NetworkDelay, NetworkInSync, NetworkLastFrame, NetworkResendCommands(), NetworkSyncCommands(), NetworkTimeout, NetworkUpdates, PlayerQuit, CNetworkHost::PlyNr, SetMessage(), CNetworkCommandQueue::Time, CNetworkPacketHeader::Type, CNetworkCommandQueue::Type, VideoSyncSpeed, and CNetworkCommand::X.
Referenced by GameMainLoop().
| static void NetworkRemovePlayer | ( | int | player | ) | [static] |
Remove a player from the game.
| 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.
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.
| 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. |
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] |
Network send commands.
Definition at line 1244 of file network.cpp.
References _C_, CNetworkCommandQueue::Clear(), CommandsIn, CNetworkCommandQueue::Data, DebugPrint, CUnit::Destroyed, FreeNCQ(), GameCycle, CPlayer::Index, MaxNetworkCommands, MessageExtendedCommand, MessageNone, MessageSync, MsgCommandsIn, NetworkLag, NetworkSendPacket(), NetworkSyncHashs, NetworkSyncSeeds, SyncHash, SyncRandSeed, ThisPlayer, CNetworkCommandQueue::Time, CNetworkCommandQueue::Type, CNetworkCommand::Unit, UnitSlots, CNetworkCommand::X, and CNetworkCommand::Y.
Referenced by NetworkCommands().
| 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.
| 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.
| 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 | |||
| ) |
Sends my selections to teammates
| units | Units to send | |
| count | Number of units to send |
Definition at line 758 of file network.cpp.
References _network_selection_header_::Add, CNetworkPacket::Command, CNetworkPacket::Header, Hosts, HostsCount, MaxNetworkCommands, MessageNone, MessageSelection, NetSendUDP(), NetworkFildes, _network_selection_header_::NumberSent, PlayerMax, Players, _network_selection_header_::Remove, CNetworkPacket::Serialize(), CNetworkSelection::Size(), CNetworkPacketHeader::Size(), CPlayer::Team, ThisPlayer, CNetworkPacketHeader::Type, _network_selection_header_::Type, CNetworkSelection::Unit, and UnitNumber.
Referenced by ChangeSelectedUnits(), SelectUnitsByType(), ToggleUnitsByType(), and UiUnselectAll().
| 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] |
Parse a network command.
| ncq | Network command from queue |
Definition at line 1155 of file network.cpp.
References _, _C_, CNetworkExtendedCommand::Arg1, CNetworkExtendedCommand::Arg2, CNetworkExtendedCommand::Arg3, CNetworkExtendedCommand::Arg4, Assert, GameSound::ChatMessage, CommandLog(), CommandQuit(), CNetworkCommandQueue::Data, DebugPrint, CNetworkCommand::Dest, CNetworkExtendedCommand::ExtendedType, FlushCommands, GameCycle, GameSounds, MaxSampleVolume, MessageChat, MessageChatTerm, MessageExtendedCommand, MessageNone, MessageQuit, MessageSync, NetMsgBuf, NetMsgBufLen, NetworkRemovePlayer(), NetworkSyncHashs, NetworkSyncSeeds, NoUnitP, ParseCommand(), ParseExtendedCommand(), CNetworkChat::Player, PlayGameSound(), SetMessage(), SoundConfig::Sound, CNetworkChat::Text, CNetworkCommandQueue::Type, CNetworkCommand::Unit, CNetworkCommand::X, and CNetworkCommand::Y.
Referenced by NetworkExecCommands().
| std::list<CNetworkCommandQueue *> CommandsIn |
Network command input queue.
Definition at line 277 of file network.cpp.
Referenced by InitNetwork1(), NetworkSendCommand(), NetworkSendCommands(), and NetworkSendExtendedCommand().
| std::list<CNetworkCommandQueue *> MsgCommandsIn |
Network message input queue.
Definition at line 278 of file network.cpp.
Referenced by InitNetwork1(), NetworkChatMessage(), and NetworkSendCommands().
CNetworkCommandQueue NCQs[MAX_NCQS] [static] |
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().
| Socket NetworkFildes = (Socket)-1 |
Network file descriptor.
Definition at line 259 of file network.cpp.
Referenced by ExitNetwork1(), InitNetwork1(), NetworkBroadcast(), NetworkEvent(), NetworkSendICMessage(), NetworkSendSelection(), NetworkServerStartGame(), and WaitEventsOneFrame().
CNetworkCommandQueue NetworkIn[256][PlayerMax][MaxNetworkCommands] [static] |
| 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 |
Network update each # game cycles.
Definition at line 261 of file network.cpp.
Referenced by ClientParseConnecting(), InitNetwork1(), InitNetwork2(), main(), NetworkCommands(), NetworkEvent(), NetworkQuit(), NetworkRecover(), NetworkResendCommands(), NetworkSendICMessage(), and NetworkSyncCommands().
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().
1.5.6