$treeview $search $mathjax
Stratagus
2.2.7
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
00001 // _________ __ __ 00002 // / _____// |_____________ _/ |______ ____ __ __ ______ 00003 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 00004 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | 00005 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 00006 // \/ \/ \//_____/ \/ 00007 // ______________________ ______________________ 00008 // T H E W A R B E G I N S 00009 // Stratagus - A free fantasy real time strategy game engine 00010 // 00012 // 00013 // (c) Copyright 1998-2007 by Lutz Sammer, Russell Smith, and Jimmy Salmon 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; only version 2 of the License. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 00029 #ifndef __NETWORK_H__ 00030 #define __NETWORK_H__ 00031 00033 00034 /*---------------------------------------------------------------------------- 00035 -- Includes 00036 ----------------------------------------------------------------------------*/ 00037 00038 #include <stdint.h> 00039 #include "net_lowlevel.h" 00040 00041 /*---------------------------------------------------------------------------- 00042 -- Defines 00043 ----------------------------------------------------------------------------*/ 00044 00045 #define MaxNetworkCommands 9 00046 00047 #define IsNetworkGame() (NetworkFildes != (Socket)-1) 00048 00049 /*---------------------------------------------------------------------------- 00050 -- Declarations 00051 ----------------------------------------------------------------------------*/ 00052 00053 class CUnit; 00054 class CUnitType; 00055 00061 enum _message_type_ { 00062 MessageNone, 00063 MessageInitHello, 00064 MessageInitReply, 00065 MessageInitConfig, 00066 00067 MessageSync, 00068 MessageSelection, 00069 MessageQuit, 00070 MessageQuitAck, 00071 MessageResend, 00072 00073 MessageChat, 00074 MessageChatTerm, 00075 00076 MessageCommandStop, 00077 MessageCommandStand, 00078 MessageCommandFollow, 00079 MessageCommandMove, 00080 MessageCommandRepair, 00081 MessageCommandAutoRepair, 00082 MessageCommandAttack, 00083 MessageCommandGround, 00084 MessageCommandPatrol, 00085 MessageCommandBoard, 00086 MessageCommandUnload, 00087 MessageCommandBuild, 00088 MessageCommandDismiss, 00089 MessageCommandResourceLoc, 00090 MessageCommandResource, 00091 MessageCommandReturn, 00092 MessageCommandTrain, 00093 MessageCommandCancelTrain, 00094 MessageCommandUpgrade, 00095 MessageCommandCancelUpgrade, 00096 MessageCommandResearch, 00097 MessageCommandCancelResearch, 00098 00099 MessageExtendedCommand, 00100 00101 // ATTN: __MUST__ be last due to spellid encoding!!! 00102 MessageCommandSpellCast 00103 }; 00104 00108 enum _extended_message_type_ { 00109 ExtendedMessageDiplomacy, 00110 ExtendedMessageSharedVision 00111 }; 00112 00116 class CNetworkCommand 00117 { 00118 public: 00119 CNetworkCommand() : Unit(0), X(0), Y(0), Dest(0) {} 00120 void Clear() { this->Unit = this->X = this->Y = this->Dest = 0; } 00121 00122 void Serialize(unsigned char *p) const; 00123 void Deserialize(const unsigned char *p); 00124 static size_t Size() { return 2 + 2 + 2 + 2; } 00125 00126 uint16_t Unit; 00127 uint16_t X; 00128 uint16_t Y; 00129 uint16_t Dest; 00130 }; 00131 00135 class CNetworkExtendedCommand 00136 { 00137 public: 00138 CNetworkExtendedCommand() : ExtendedType(0), Arg1(0), Arg2(0), Arg3(0), Arg4(0) {} 00139 00140 void Serialize(unsigned char *p) const; 00141 void Deserialize(const unsigned char *p); 00142 static size_t Size() { return 1 + 1 + 2 + 2 + 2; } 00143 00144 uint8_t ExtendedType; 00145 uint8_t Arg1; 00146 uint16_t Arg2; 00147 uint16_t Arg3; 00148 uint16_t Arg4; 00149 }; 00150 00154 class CNetworkChat 00155 { 00156 public: 00157 CNetworkChat() { 00158 Player = 0; 00159 memset(Text, 0, sizeof(Text)); 00160 } 00161 00162 void Serialize(unsigned char *p) const ; 00163 void Deserialize(const unsigned char *p); 00164 static size_t Size() { return 1 + 7; } 00165 00166 uint8_t Player; 00167 char Text[7]; 00168 }; 00169 00173 typedef struct _network_selection_header_ { 00174 unsigned NumberSent : 6; 00175 unsigned Add : 1; 00176 unsigned Remove : 1; 00177 unsigned char Type[MaxNetworkCommands]; 00178 } NetworkSelectionHeader; 00179 00183 class CNetworkSelection 00184 { 00185 public: 00186 CNetworkSelection() { 00187 memset(Unit, 0, sizeof(Unit)); 00188 } 00189 00190 void Serialize(unsigned char *p) const; 00191 void Deserialize(const unsigned char *p); 00192 static size_t Size() { return 2 * 4; } 00193 00194 uint16_t Unit[4]; 00195 }; 00196 00202 class CNetworkPacketHeader 00203 { 00204 public: 00205 CNetworkPacketHeader() { 00206 Cycle = 0; 00207 memset(Type, 0, sizeof(Type)); 00208 } 00209 00210 void Serialize(unsigned char *p) const; 00211 void Deserialize(const unsigned char *p); 00212 static size_t Size() { return 1 + 1 * MaxNetworkCommands; } 00213 00214 uint8_t Cycle; 00215 uint8_t Type[MaxNetworkCommands]; 00216 }; 00217 00223 class CNetworkPacket 00224 { 00225 public: 00226 unsigned char *Serialize(int numcommands) const; 00227 int Deserialize(const unsigned char *p, unsigned int len); 00228 static size_t Size(int numcommands) { 00229 return CNetworkPacketHeader::Size() + numcommands * CNetworkCommand::Size(); 00230 } 00231 00232 CNetworkPacketHeader Header; 00233 CNetworkCommand Command[MaxNetworkCommands]; 00234 }; 00235 00236 /*---------------------------------------------------------------------------- 00237 -- Variables 00238 ----------------------------------------------------------------------------*/ 00239 00240 extern int NetworkNumInterfaces; 00241 extern Socket NetworkFildes; 00242 extern int NetworkInSync; 00243 extern int NetworkUpdates; 00244 extern int NetworkLag; 00245 extern unsigned long NetworkStatus[PlayerMax]; 00246 00247 /*---------------------------------------------------------------------------- 00248 -- Functions 00249 ----------------------------------------------------------------------------*/ 00250 00251 extern void InitNetwork1(); 00252 extern void InitNetwork2(); 00253 extern void ExitNetwork1(); 00254 extern void NetworkEvent(); 00255 extern void NetworkSync(); 00256 extern void NetworkQuit(); 00257 extern void NetworkRecover(); 00258 extern void NetworkCommands(); 00259 extern void NetworkChatMessage(const std::string &msg); 00260 00261 extern void NetworkSendCommand(int command, const CUnit &unit, int x, 00262 int y, const CUnit *dest, const CUnitType *type, int status); 00264 extern void NetworkSendExtendedCommand(int command, int arg1, int arg2, 00265 int arg3, int arg4, int status); 00267 extern void NetworkSendSelection(CUnit **units, int count); 00268 00269 extern void NetworkCclRegister(); 00270 00272 00273 #endif // !__NETWORK_H__