Skip to content

Commit e95c0d2

Browse files
committed
Merge branch 'release' into develop
2 parents b87a346 + 78a6d7a commit e95c0d2

File tree

91 files changed

+1185
-797
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1185
-797
lines changed

rts/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ endif (TRACE_SYNC)
2424
SET(SYNCDEBUG FALSE CACHE BOOL "Enable sync debugger (needs SYNCCHECK=true)")
2525
if (SYNCDEBUG)
2626
ADD_DEFINITIONS(-DSYNCDEBUG)
27+
If (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG2" AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG3")
28+
Message(FATAL_ERROR "You need CMAKE_BUILD_TYPE set to either DEBUG2 or DEBUG3 for a SYNCDEBUG build")
29+
EndIf ()
30+
If (NOT SYNCCHECK)
31+
Message(FATAL_ERROR "You need SYNCCHECK=TRUE for a SYNCDEBUG build")
32+
EndIf ()
33+
If (NOT TRACE_SYNC)
34+
Message(WARNING "It is recommended to use TRACE_SYNC=TRUE for a SYNCDEBUG build")
35+
EndIf ()
2736
endif (SYNCDEBUG)
2837

2938
# Only used by GML build, but used in builds/GML and lib/gml

rts/ExternalAI/EngineOutHandler.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,17 @@ class CEngineOutHandler : public CObject {
134134
#define CATCH_AI_EXCEPTION \
135135
catch (const std::exception& e) { \
136136
CEngineOutHandler::HandleAIException(e.what()); \
137-
throw; \
137+
throw e; \
138138
} catch (const std::string& s) { \
139139
CEngineOutHandler::HandleAIException(s.c_str()); \
140-
throw; \
140+
throw s; \
141141
} catch (const char* s) { \
142142
CEngineOutHandler::HandleAIException(s); \
143-
throw; \
143+
throw s; \
144144
} catch (int err) { \
145145
const std::string s = IntToString(err); \
146146
CEngineOutHandler::HandleAIException(s.c_str()); \
147-
throw; \
147+
throw err; \
148148
} catch (...) { \
149149
CEngineOutHandler::HandleAIException("Unknown"); \
150150
throw; \

rts/ExternalAI/Interface/SSkirmishAICallback.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,18 +2075,23 @@ struct SSkirmishAICallback {
20752075

20762076
float (CALLING_CONV *WeaponDef_getIntensity)(int skirmishAIId, int weaponDefId);
20772077

2078+
/** @deprecated only relevant for visualization */
20782079
float (CALLING_CONV *WeaponDef_getThickness)(int skirmishAIId, int weaponDefId);
20792080

2081+
/** @deprecated only relevant for visualization */
20802082
float (CALLING_CONV *WeaponDef_getLaserFlareSize)(int skirmishAIId, int weaponDefId);
20812083

2084+
/** @deprecated only relevant for visualization */
20822085
float (CALLING_CONV *WeaponDef_getCoreThickness)(int skirmishAIId, int weaponDefId);
20832086

20842087
float (CALLING_CONV *WeaponDef_getDuration)(int skirmishAIId, int weaponDefId);
20852088

2089+
/** @deprecated only relevant for visualization */
20862090
int (CALLING_CONV *WeaponDef_getLodDistance)(int skirmishAIId, int weaponDefId);
20872091

20882092
float (CALLING_CONV *WeaponDef_getFalloffRate)(int skirmishAIId, int weaponDefId);
20892093

2094+
/** @deprecated only relevant for visualization */
20902095
int (CALLING_CONV *WeaponDef_getGraphicsType)(int skirmishAIId, int weaponDefId);
20912096

20922097
bool (CALLING_CONV *WeaponDef_isSoundTrigger)(int skirmishAIId, int weaponDefId);

rts/Game/Game.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ CGame::~CGame()
408408
SafeDelete(weaponDefHandler);
409409
SafeDelete(damageArrayHandler);
410410
SafeDelete(explGenHandler);
411-
SafeDelete(gCEG);
412411
SafeDelete(helper);
413412
SafeDelete((mapInfo = const_cast<CMapInfo*>(mapInfo)));
414413

@@ -534,7 +533,6 @@ void CGame::LoadSimulation(const std::string& mapName)
534533
qf = new CQuadField();
535534
damageArrayHandler = new CDamageArrayHandler();
536535
explGenHandler = new CExplosionGeneratorHandler();
537-
gCEG = new CCustomExplosionGenerator();
538536

539537
{
540538
//! FIXME: these five need to be loaded before featureHandler
@@ -1739,7 +1737,7 @@ void CGame::DumpState(int newMinFrameNum, int newMaxFrameNum, int newFramePeriod
17391737
file << "\t\t\t\toldUpdatePos: <" << oldUpdatePos.x << ", " << oldUpdatePos.y << ", " << oldUpdatePos.z << ">\n";
17401738
file << "\t\t\t\toldSlowUpPos: <" << oldSlowUpPos.x << ", " << oldSlowUpPos.y << ", " << oldSlowUpPos.z << ">\n";
17411739
file << "\t\t\t\tmaxSpeed: " << amt->maxSpeed << ", maxWantedSpeed: " << amt->maxWantedSpeed << "\n";
1742-
file << "\t\t\t\tpadStatus: " << amt->padStatus << ", progressState: " << amt->progressState << "\n";
1740+
file << "\t\t\t\tprogressState: " << amt->progressState << "\n";
17431741
#endif
17441742
}
17451743
#endif
@@ -2073,10 +2071,6 @@ void CGame::ReloadCOB(const string& msg, int player)
20732071
LOG("Reloaded cob script for %i units", count);
20742072
}
20752073

2076-
void CGame::ReloadCEGs(const std::string& tag) {
2077-
gCEG->RefreshCache(tag);
2078-
}
2079-
20802074

20812075

20822076
void CGame::SelectUnits(const string& line)

rts/Game/GameServer.cpp

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ CGameServer::CGameServer(const std::string& hostIP, int hostPort, const GameData
136136
internalSpeed = 1.0f;
137137
gamePausable = true;
138138
noHelperAIs = false;
139+
canReconnect = false;
139140
allowSpecDraw = true;
140141
cheating = false;
141142

@@ -264,7 +265,7 @@ CGameServer::~CGameServer()
264265
if (setup->useLuaGaia && (numTeams > 0)) {
265266
--numTeams;
266267
}
267-
demoRecorder->SetTime(serverFrameNum / 30, spring_tomsecs(spring_gettime()-serverStartTime)/1000);
268+
demoRecorder->SetTime(serverFrameNum / GAME_SPEED, spring_tomsecs(spring_gettime() - serverStartTime) / 1000);
268269
demoRecorder->InitializeStats(players.size(), numTeams);
269270

270271
// Pass the winners to the CDemoRecorder.
@@ -502,7 +503,7 @@ bool CGameServer::SendDemoData(int targetFrameNum)
502503
pckt >> spectator;
503504
pckt >> team;
504505
pckt >> name;
505-
AddAdditionalUser(name, "", true); // even though this is a demo, keep the players vector properly updated
506+
AddAdditionalUser(name, "", true,(bool)spectator,(int)team); // even though this is a demo, keep the players vector properly updated
506507
} catch (const netcode::UnpackPacketException& ex) {
507508
Message(str(format("Warning: Discarding invalid new player packet in demo: %s") %ex.what()));
508509
continue;
@@ -1171,7 +1172,8 @@ void CGameServer::ProcessPacket(const unsigned playerNum, boost::shared_ptr<cons
11711172
}
11721173
} break;
11731174

1174-
case NETMSG_LUAMSG:
1175+
1176+
case NETMSG_LUAMSG: {
11751177
try {
11761178
netcode::UnpackPacket pckt(packet, 3);
11771179
unsigned char playerNum;
@@ -1188,19 +1190,36 @@ void CGameServer::ProcessPacket(const unsigned playerNum, boost::shared_ptr<cons
11881190
} catch (const netcode::UnpackPacketException& ex) {
11891191
Message(str(format("Player %s sent invalid LuaMsg: %s") %players[a].name %ex.what()));
11901192
}
1191-
break;
1193+
} break;
1194+
11921195

11931196
case NETMSG_SYNCRESPONSE: {
11941197
#ifdef SYNCCHECK
1195-
const int frameNum = *(int*)&inbuf[1];
1198+
netcode::UnpackPacket pckt(packet, 1);
1199+
1200+
unsigned char playerNum; pckt >> playerNum;
1201+
int frameNum; pckt >> frameNum;
1202+
unsigned int checkSum; pckt >> checkSum;
1203+
1204+
assert(a == playerNum);
1205+
11961206
if (outstandingSyncFrames.find(frameNum) != outstandingSyncFrames.end())
1197-
players[a].syncResponse[frameNum] = *(unsigned*)&inbuf[5];
1198-
// update players' ping (if !defined(SYNCCHECK) this is done in NETMSG_KEYFRAME)
1207+
players[a].syncResponse[frameNum] = checkSum;
1208+
1209+
// update player's ping (if !defined(SYNCCHECK) this is done in NETMSG_KEYFRAME)
11991210
if (frameNum <= serverFrameNum && frameNum > players[a].lastFrameResponse)
12001211
players[a].lastFrameResponse = frameNum;
1212+
1213+
#ifndef NDEBUG
1214+
// send player <a>'s sync-response back to everybody
1215+
// (the only purpose of this is to allow a client to
1216+
// detect if it is desynced wrt. a demo-stream)
1217+
if ((frameNum % GAME_SPEED) == 0) {
1218+
Broadcast((CBaseNetProtocol::Get()).SendSyncResponse(playerNum, frameNum, checkSum));
1219+
}
12011220
#endif
1202-
}
1203-
break;
1221+
#endif
1222+
} break;
12041223

12051224
case NETMSG_SHARE:
12061225
if (inbuf[1] != a) {
@@ -2023,7 +2042,14 @@ void CGameServer::PushAction(const Action& action)
20232042
if (tokens.size() > 1) {
20242043
const std::string& name = tokens[0];
20252044
const std::string& password = tokens[1];
2026-
2045+
int team = 0;
2046+
bool spectator = true;
2047+
if ( tokens.size() > 2 ) {
2048+
spectator = (tokens[2] == "0") ? false : true;
2049+
}
2050+
if ( tokens.size() > 3 ) {
2051+
team = atoi(tokens[3].c_str());
2052+
}
20272053
GameParticipant gp;
20282054
gp.name = name;
20292055
// note: this must only compare by name
@@ -2040,11 +2066,15 @@ void CGameServer::PushAction(const Action& action)
20402066
participantIter->SetValue("password", password);
20412067
LOG("Changed player/spectator password: \"%s\" \"%s\"", name.c_str(), password.c_str());
20422068
} else {
2043-
AddAdditionalUser(name, password);
2044-
LOG("Added player/spectator password: \"%s\" \"%s\"", name.c_str(), password.c_str());
2069+
AddAdditionalUser(name, password, false, spectator, team);
2070+
std::string logstring = "Added ";
2071+
if ( spectator ) logstring = logstring + "spectator";
2072+
else logstring = logstring + "player";
2073+
logstring = logstring + " \"%s\" with password \"%s\", to team %d";
2074+
LOG(logstring.c_str(), name.c_str(), password.c_str(),team);
20452075
}
20462076
} else {
2047-
LOG_L(L_WARNING, "Failed to add player/spectator password. usage: /adduser <player-name> <password>");
2077+
LOG_L(L_WARNING, "Failed to add player/spectator password. usage: /adduser <player-name> <password> [spectator] [team]");
20482078
}
20492079
}
20502080
}
@@ -2243,13 +2273,13 @@ void CGameServer::KickPlayer(const int playerNum)
22432273
}
22442274

22452275

2246-
void CGameServer::AddAdditionalUser(const std::string& name, const std::string& passwd, bool fromDemo)
2276+
void CGameServer::AddAdditionalUser(const std::string& name, const std::string& passwd, bool fromDemo, bool spectator, int team)
22472277
{
22482278
GameParticipant buf;
22492279
buf.isFromDemo = fromDemo;
22502280
buf.name = name;
2251-
buf.spectator = true;
2252-
buf.team = 0;
2281+
buf.spectator = spectator;
2282+
buf.team = team;
22532283
buf.isMidgameJoin = true;
22542284
if (passwd.size() > 0)
22552285
buf.SetValue("password",passwd);
@@ -2461,4 +2491,3 @@ void CGameServer::AddToPacketCache(boost::shared_ptr<const netcode::RawPacket> &
24612491
}
24622492
packetCache.back().push_back(pckt);
24632493
}
2464-

rts/Game/GameServer.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class CGameServer
204204
float minUserSpeed;
205205

206206
bool noHelperAIs;
207+
bool canReconnect;
207208
bool allowSpecDraw;
208209
bool allowAdditionalPlayers;
209210
bool whiteListAdditionalPlayers;
@@ -220,7 +221,7 @@ class CGameServer
220221
void InternalSpeedChange(float newSpeed);
221222
void UserSpeedChange(float newSpeed, int player);
222223

223-
void AddAdditionalUser( const std::string& name, const std::string& passwd, bool fromDemo = false );
224+
void AddAdditionalUser( const std::string& name, const std::string& passwd, bool fromDemo = false, bool spectator = true, int team = 0);
224225

225226
bool hasLocalClient;
226227
unsigned localClientNumber;
@@ -239,7 +240,6 @@ class CGameServer
239240

240241
mutable Threading::RecursiveMutex gameServerMutex;
241242

242-
bool canReconnect;
243243
volatile bool gameHasStarted;
244244
volatile bool generatedGameID;
245245

@@ -250,4 +250,3 @@ class CGameServer
250250
extern CGameServer* gameServer;
251251

252252
#endif // _GAME_SERVER_H
253-

rts/Game/NetCommands.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,10 @@ void CGame::ClientReadNet()
362362
SimFrame();
363363
// both NETMSG_SYNCRESPONSE and NETMSG_NEWFRAME are used for ping calculation by server
364364
#ifdef SYNCCHECK
365-
net->Send(CBaseNetProtocol::Get().SendSyncResponse(gs->frameNum, CSyncChecker::GetChecksum()));
366-
if ((gs->frameNum & 4095) == 0) {// reset checksum every ~2.5 minute gametime
365+
net->Send(CBaseNetProtocol::Get().SendSyncResponse(gu->myPlayerNum, gs->frameNum, CSyncChecker::GetChecksum()));
366+
367+
if ((gs->frameNum & 4095) == 0) {
368+
// reset checksum every 4096 frames =~ 2.5 minutes
367369
CSyncChecker::NewFrame();
368370
}
369371
#endif
@@ -375,6 +377,36 @@ void CGame::ClientReadNet()
375377
break;
376378
}
377379

380+
case NETMSG_SYNCRESPONSE: {
381+
#if (defined(SYNCCHECK) && !defined(NDEBUG))
382+
// NOTE:
383+
// this packet is also sent during live games,
384+
// during which we should just ignore it (the
385+
// server does sync-checking for us)
386+
netcode::UnpackPacket pckt(packet, 1);
387+
388+
unsigned char playerNum; pckt >> playerNum;
389+
int frameNum; pckt >> frameNum;
390+
unsigned int checkSum; pckt >> checkSum;
391+
392+
const unsigned int ourCheckSum = CSyncChecker::GetChecksum();
393+
const char* fmtStr =
394+
"[DESYNC_WARNING] checksum %x from player %d (%s)"
395+
" does not match our checksum %x for frame-number %d";
396+
const CPlayer* player = playerHandler->Player(playerNum);
397+
398+
// check if our checksum for this frame matches what
399+
// player <playerNum> sent to the server at the same
400+
// frame in the original game (in case of a demo)
401+
if (playerNum == gu->myPlayerNum) { return; }
402+
if (gs->frameNum != frameNum) { return; }
403+
if (checkSum == ourCheckSum) { return; }
404+
405+
LOG_L(L_ERROR, fmtStr, checkSum, playerNum, player->name.c_str(), ourCheckSum, gs->frameNum);
406+
#endif
407+
} break;
408+
409+
378410
case NETMSG_COMMAND: {
379411
try {
380412
netcode::UnpackPacket pckt(packet, 1);
@@ -1041,10 +1073,13 @@ void CGame::ClientReadNet()
10411073
player.team = team;
10421074
player.playerNum = playerNum;
10431075
// add the new player
1076+
// TODO NETMSG_CREATE_NEWPLAYER perhaps add a lua hook; hook should be able to reassign the player to a team and/or create a new team/allyteam
10441077
playerHandler->AddPlayer(player);
10451078
eventHandler.PlayerAdded(player.playerNum);
10461079
LOG("Added new player: %s", name.c_str());
1047-
// TODO NETMSG_CREATE_NEWPLAYER perhaps add a lua hook; hook should be able to reassign the player to a team and/or create a new team/allyteam
1080+
if (!player.spectator) {
1081+
eventHandler.TeamChanged(player.team);
1082+
}
10481083
AddTraffic(-1, packetCode, dataLength);
10491084
} catch (const netcode::UnpackPacketException& ex) {
10501085
LOG_L(L_ERROR, "Got invalid New player message: %s", ex.what());
@@ -1071,4 +1106,3 @@ void CGame::ClientReadNet()
10711106
}
10721107
}
10731108
}
1074-

rts/Game/PreGame.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,21 @@ void CPreGame::GameDataReceived(boost::shared_ptr<const netcode::RawPacket> pack
443443
LOG("Using map: %s", gameSetup->mapName.c_str());
444444

445445
vfsHandler->AddArchiveWithDeps(gameSetup->mapName, false);
446-
archiveScanner->CheckArchive(gameSetup->mapName, gameData->GetMapChecksum());
446+
try {
447+
archiveScanner->CheckArchive(gameSetup->mapName, gameData->GetMapChecksum());
448+
} catch (const content_error& ex) {
449+
LOG_L(L_WARNING, "Incompatible map-checksum: %s", ex.what());
450+
}
447451

448452
LOG("Using game: %s", gameSetup->modName.c_str());
449453
vfsHandler->AddArchiveWithDeps(gameSetup->modName, false);
450454
modArchive = archiveScanner->ArchiveFromName(gameSetup->modName);
451455
LOG("Using game archive: %s", modArchive.c_str());
452-
archiveScanner->CheckArchive(modArchive, gameData->GetModChecksum());
456+
try {
457+
archiveScanner->CheckArchive(modArchive, gameData->GetModChecksum());
458+
} catch (const content_error& ex) {
459+
LOG_L(L_WARNING, "Incompatible game-checksum: %s", ex.what());
460+
}
453461

454462
if (net && net->GetDemoRecorder()) {
455463
net->GetDemoRecorder()->SetName(gameSetup->mapName, gameSetup->modName);

rts/Game/SelectedUnitsAI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void CSelectedUnitsAI::GiveCommandNet(Command &c, int player)
165165
CalculateGroupData(player, !!(c.options & SHIFT_KEY));
166166

167167
// use the vector from the middle of group to new pos as forward dir
168-
const float3 pos(c.GetParam(0), c.GetParam(1), c.GetParam(3));
168+
const float3 pos(c.GetParam(0), c.GetParam(1), c.GetParam(2));
169169
float3 frontdir = pos - centerCoor;
170170
frontdir.y = 0.0f;
171171
frontdir.ANormalize();

rts/Game/SyncedGameCommands.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Lua/LuaRules.h"
2020
#include "Sim/Misc/GlobalSynced.h"
2121
#include "Sim/Misc/TeamHandler.h"
22+
#include "Sim/Projectiles/ExplosionGenerator.h"
2223
#include "Sim/Units/UnitDefHandler.h"
2324
#include "Sim/Units/UnitHandler.h"
2425
#include "Sim/Units/UnitLoader.h"
@@ -180,11 +181,11 @@ class ReloadCobActionExecutor : public ISyncedActionExecutor {
180181

181182
class ReloadCegsActionExecutor : public ISyncedActionExecutor {
182183
public:
183-
ReloadCegsActionExecutor() : ISyncedActionExecutor("ReloadCegs",
184-
"Reloads Ceg scripts", true) {}
184+
ReloadCegsActionExecutor() : ISyncedActionExecutor("ReloadCEGs",
185+
"Reloads CEG scripts", true) {}
185186

186187
void Execute(const SyncedAction& action) const {
187-
game->ReloadCEGs(action.GetArgs());
188+
explGenHandler->ReloadGenerators(action.GetArgs());
188189
}
189190
};
190191

0 commit comments

Comments
 (0)