1212// When a local game is started - a listen server - via calling StartGame() a server is created and then the client is
1313// connected to it via createAndConnectToLocalServer().
1414
15+ function Core_ClientServer::clearLoadStatus()
16+ {
17+ Core_ClientServer.moduleLoadedDone = 0;
18+ Core_ClientServer.moduleLoadedFailed = 0;
19+ }
20+ function Core_ClientServer::onLoadMap(%this)
21+ {
22+ %this.finishMapLoad();
23+ }
24+
25+ function Core_ClientServer::finishMapLoad(%this)
26+ {
27+ Core_ClientServer.GetEventManager().postEvent( "mapLoadComplete" );
28+ }
29+
30+ function Core_ClientServer::FailMapLoad(%this, %moduleName, %isFine)
31+ {
32+ Core_ClientServer.failedModuleName = %moduleName;
33+ Core_ClientServer.GetEventManager().postEvent( "mapLoadFail", %isFine );
34+ }
35+
36+ function Core_ClientServerListener::onMapLoadComplete(%this)
37+ {
38+ Core_ClientServer.moduleLoadedDone++;
39+ %numModsNeedingLoaded = 0;
40+ %modulesList = ModuleDatabase.findModules();
41+ for(%i=0; %i < getWordCount(%modulesList); %i++)
42+ {
43+ %module = getWord(%modulesList, %i);
44+ if (%module.ModuleId.isMethod("finishMapLoad"))
45+ %numModsNeedingLoaded++;
46+ }
47+ if (Core_ClientServer.moduleLoadedDone == %numModsNeedingLoaded)
48+ {
49+ loadMissionStage3();
50+ }
51+ }
52+
53+ function Core_ClientServerListener::onmapLoadFail(%this, %isFine)
54+ {
55+ if (%isFine)
56+ {
57+ %this.onMapLoadComplete();
58+ return;
59+ }
60+
61+ Core_ClientServer.moduleLoadedFailed++;
62+ if (Core_ClientServer.moduleLoadedFailed>1) return; // yeah, we know
63+
64+ $Server::LoadFailMsg = Core_ClientServer.failedModuleName @" failed to load mission specific data!";
65+ error($Server::LoadFailMsg);
66+ // Inform clients that are already connected
67+
68+ for (%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
69+ {
70+ %cl = ClientGroup.getObject( %clientIndex );
71+ %cl.onConnectionDropped($Server::LoadFailMsg);
72+ %cl.endMission();
73+ %cl.resetGhosting();
74+ %cl.clearPaths();
75+ }
76+ destroyServer();
77+ }
78+
1579function Core_ClientServer::onCreate( %this )
1680{
1781 echo("\n--------- Initializing Directory: scripts ---------");
@@ -33,6 +97,11 @@ function Core_ClientServer::onCreate( %this )
3397 {
3498 initClient();
3599 }
100+ %this.GetEventManager().registerEvent("mapLoadComplete");
101+ %this.GetEventManager().registerEvent("mapLoadFail");
102+ %this.listener = new ScriptMsgListener() {class = Core_ClientServerListener;};
103+ %this.GetEventManager().subscribe( %this.listener, "mapLoadComplete" );
104+ %this.GetEventManager().subscribe( %this.listener, "mapLoadFail" );
36105}
37106
38107function Core_ClientServer::onDestroy( %this )
0 commit comments