MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / SetGameState

Method SetGameState

engine/Poseidon/Network/NetworkServerMission.cpp:1155–1340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1153 {
1154 LOG_ERROR(Network, "LoadWorldState: empty filename");
1155 return false;
1156 }
1157
1158 FILE* f = fopen(filename, "rb");
1159 if (!f)
1160 {
1161 LOG_ERROR(Network, "LoadWorldState: cannot open file '{}'", filename);
1162 return false;
1163 }
1164
1165 int32_t magic, version;
1166 if (fread(&magic, sizeof(magic), 1, f) != 1 || fread(&version, sizeof(version), 1, f) != 1)
1167 {
1168 LOG_ERROR(Network, "LoadWorldState: truncated file header");
1169 fclose(f);
1170 return false;
1171 }
1172
1173 if (magic != 0x4A495053 || version != 1)
1174 {
1175 LOG_ERROR(Network, "LoadWorldState: invalid file format");
1176 fclose(f);
1177 return false;
1178 }
1179
1180 int32_t timeElapsed, objectCount, jipCount;
1181 if (fread(&timeElapsed, sizeof(timeElapsed), 1, f) != 1 || fread(&objectCount, sizeof(objectCount), 1, f) != 1 ||
1182 fread(&jipCount, sizeof(jipCount), 1, f) != 1)
1183 {
1184 LOG_ERROR(Network, "LoadWorldState: truncated file data");
1185 fclose(f);
1186 return false;
1187 }
1188
1189 fclose(f);
1190
1191 // Adjust mission start time
1192 _missionHeader.start = GlobalTickCount() - timeElapsed;
1193
1194 LOG_INFO(Network, "LoadWorldState: loaded from '{}' ({} objects, {} JIP msgs, {}ms elapsed)", filename, objectCount,
1195 jipCount, timeElapsed);
1196 return true;
1197}
1198
1199void NetworkServer::SetGameState(NetworkGameState state)
1200{
1201 LOG_INFO(Network, "State: {} -> {}", NGSName(_state), NGSName(state));
1202 if (state != _state)
1203 {
1204 _stateEnteredTime = GlobalTickCount();
1205 }
1206 if (state == NGSPrepareRole && _state > NGSPrepareRole)
1207 {
1208 // cancel all messages - updates from last sessions, file transfers etc.
1209 _server->CancelAllMessages();
1210 // reset all camera information from previous session
1211 for (int i = 0; i < _players.Size(); i++)
1212 {

Callers

nothing calls this directly

Calls 13

NGSNameFunction · 0.85
GlobalTickCountFunction · 0.85
GetRankingLogFunction · 0.85
EncryptFunction · 0.85
CancelAllMessagesMethod · 0.80
SubstringMethod · 0.80
AddClassMethod · 0.80
strMethod · 0.80
pcountMethod · 0.80
SizeMethod · 0.45
GetLengthMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected