1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "r2_modules/dms.h"
25 #include "r2_modules/ai_wrapper.h"
26 #include "r2_modules/server_animation_module.h"
27 #include "r2_modules/server_edition_module.h"
29 #include "r2_share/r2_ligo_config.h"
31 #include "nel/net/unified_network.h"
32 #include "nel/net/module_manager.h"
33 #include "nel/ligo/primitive.h"
34 #include "nel/ligo/ligo_config.h"
35 #include "nel/misc/entity_id.h"
37 #include "game_share/tick_event_handler.h"
38 #include "game_share/ryzom_version.h"
39 //#include "game_share/module_security.h"
40 #include "game_share/ryzom_entity_id.h"
41 #include "game_share/chat_group.h"
42 #include "game_share/singleton_registry.h"
44 using namespace NLNET
;
45 using namespace NLMISC
;
49 // force admin module to link in
50 extern void admin_modules_forceLink();
53 admin_modules_forceLink();
60 NLLIGO::CLigoConfig
* LigoConfigPtr
;
61 CR2LigoConfig R2LigoConfig
;
66 void CDynamicScenarioService::forwardToStringManagerModule (CMessage
&msgin
)
69 CChatGroup::TGroupType groupType
= CChatGroup::universe
;
71 TSessionId scenarioId
;
72 msgin
.serial(senderId
);
73 msgin
.serialEnum(groupType
);
76 msgin
.serial(scenarioId
);
77 _Dms
->translateAndForwardRequested(senderId
,groupType
,id_
,scenarioId
);
81 static void cbForwardToStringManagerModule(CMessage
&msgin
, const std::string
&serviceName
, TServiceId sid
)
83 nldebug("forwardToStringManagerModule");
84 CDynamicScenarioService::instance().forwardToStringManagerModule(msgin
);
86 static void cbForwardToStringManagerModuleWithArg(CMessage
&msgin
, const std::string
&serviceName
, TServiceId sid
)
88 nldebug("forwardToStringManagerModuleWithArg");
89 IServerAnimationModule
*imodule
= CDynamicMapService::getInstance()->getAnimationModule();
90 CServerAnimationModule
* module
= safe_cast
<CServerAnimationModule
*>(imodule
);
92 module
->onProcessModuleMessage(0,msgin
);
95 void CDynamicScenarioService::forwardIncarnChat(TChanID id
,TDataSetRow senderId
,ucstring sentence
)
97 _Dms
->forwardIncarnChat(id
,senderId
,sentence
);
98 nldebug("Forwarding dyn chat \"%s\" to dms",sentence
.c_str());
101 static void cbDynChatForward(CMessage
&msgin
, const std::string
&serviceName
, TServiceId sid
)
107 std::string sentence
;
108 CChatGroup::TGroupType groupType
= CChatGroup::say
;
110 msgin
.serial(sender
);
111 msgin
.serial(ucsentence
);
112 sentence
= ucsentence
.toString();
113 CDynamicScenarioService::instance().forwardIncarnChat(id
,sender
,sentence
);
114 nldebug("forwarding dyn chat \"%s\"",sentence
.c_str());
117 static void cbSessionAck(CMessage
&msgin
, const std::string
&serviceName
, TServiceId sid
)
119 CDynamicMapService
* dms
= CDynamicMapService::getInstance();
120 IServerAnimationModule
*imodule
= dms
->getAnimationModule();
121 CServerAnimationModule
* module
= safe_cast
<CServerAnimationModule
*>(imodule
);
122 module
->onProcessModuleMessage(0, msgin
);
125 static void cbDssStartAct(CMessage
&msgin
, const std::string
&serviceName
, TServiceId sid
)
127 CDynamicScenarioService
& service
= CDynamicScenarioService::instance();
128 CDynamicMapService
* dms
= CDynamicMapService::getInstance();
129 IServerAnimationModule
* imodule
= dms
->getAnimationModule();
130 CServerAnimationModule
* module
= safe_cast
<CServerAnimationModule
*>(imodule
);
131 TSessionId sessionId
;
135 msgin
.serial(sessionId
);
137 module
->scheduleStartAct(sessionId
, actId
);
140 static void cbExecCommandResult(CMessage
&msgin
, const std::string
&serviceName
, TServiceId sid
)
142 // treat the rely message sent back from a service whom we asked to execute a command
143 NLMISC::InfoLog
->displayNL("EXEC_COMMAND_RESULT' Received from: %3d: %s",sid
.toString().c_str(),serviceName
.c_str());
145 // retrieve the text from the input message
149 // divide the text into lines because NeL doesn't like long texts
150 CVectorSString lines
;
151 txt
.splitLines(lines
);
153 // display the lines of text
154 for (uint32 i
=0;i
<lines
.size();++i
)
156 NLMISC::InfoLog
->displayNL("%s",lines
[i
].c_str());
160 static void cbBotDespawnNotification(NLNET::CMessage
&msgin
, const std::string
&serviceName
, TServiceId sid
)
163 CEntityId creatureId
;
165 msgin
.serial(creatureId
);
166 CDynamicMapService
* dms
= CDynamicMapService::getInstance();
167 IServerAnimationModule
* imodule
= dms
->getAnimationModule();
168 CServerAnimationModule
* module
= safe_cast
<CServerAnimationModule
*>(imodule
);
170 module
->onBotDespawnNotification(creatureId
);
174 TUnifiedCallbackItem CbArray
[]=
176 {"translateAndForward", cbForwardToStringManagerModule
},
177 {"DYN_CHAT:FORWARD", cbDynChatForward
},
178 {"DSS_START_ACT", cbDssStartAct
},
179 {"translateAndForwardArg", cbForwardToStringManagerModuleWithArg
},
180 {"SESSION_ACK", cbSessionAck
},
181 {"EXEC_COMMAND_RESULT", cbExecCommandResult
},
182 {"BOT_DESPAWN_NOTIFICATION", cbBotDespawnNotification
},
183 {"BOT_DEATH_NOTIFICATION", cbBotDespawnNotification
},
187 void cbServiceUp(const std::string
&serviceName
, TServiceId serviceId
, void *)
189 nlinfo( "DSS: %s Service up", serviceName
.c_str() );
190 if( serviceName
== "AIS" )
192 nlinfo( "DSS: AI server up" );
193 CDynamicMapService
*dms
= CDynamicMapService::getInstance();
196 IServerAnimationModule
*imodule
= dms
->getAnimationModule();
197 CServerAnimationModule
* module
= safe_cast
<CServerAnimationModule
*>(imodule
);
200 nlinfo( "DSS: notifying ServerAnimModule that AI server is up" );
201 module
->onServiceUp( serviceName
, serviceId
);
206 IServerEditionModule
*imodule
= dms
->getEditionModule();
207 CServerEditionModule
* module
= safe_cast
<CServerEditionModule
*>(imodule
);
210 nlinfo( "DSS: notifying ServerEditionModule that '%s' server is up", serviceName
.c_str() );
211 module
->onServiceUp( serviceName
, serviceId
);
218 if( serviceName
== "BS" )
220 nlinfo( "DSS: %s server up", serviceName
.c_str() );
221 CDynamicMapService
*dms
= CDynamicMapService::getInstance();
224 IServerEditionModule
*imodule
= dms
->getEditionModule();
225 CServerEditionModule
* module
= safe_cast
<CServerEditionModule
*>(imodule
);
228 nlinfo( "DSS: notifying ServerEditionModule that '%s' server is up", serviceName
.c_str() );
229 module
->onServiceUp( serviceName
, serviceId
);
235 void cbServiceDown(const std::string
&serviceName
, TServiceId serviceId
, void *)
237 nlinfo( "DSS: %s Service down", serviceName
.c_str() );
238 if( serviceName
== "AIS" )
240 nlinfo( "DSS: AI server down" );
241 CDynamicMapService
* dms
= CDynamicMapService::getInstance();
246 IServerEditionModule
*imodule
= dms
->getEditionModule();
247 CServerEditionModule
* module
= safe_cast
<CServerEditionModule
*>(imodule
);
250 nlinfo( "DSS: notifying ServerEditionModule that '%s' server is down", serviceName
.c_str() );
251 module
->onServiceDown( serviceName
, serviceId
);
255 IServerAnimationModule
*imodule
= dms
->getAnimationModule();
256 CServerAnimationModule
* module
= safe_cast
<CServerAnimationModule
*>(imodule
);
259 nlinfo( "DSS: notifying ServerAnimModule that AI server is down" );
260 // module->onServiceDown( serviceName, serviceId );
265 if( serviceName
== "BS" )
267 nlinfo( "DSS: %s server up", serviceName
.c_str() );
268 CDynamicMapService
*dms
= CDynamicMapService::getInstance();
271 IServerEditionModule
*imodule
= dms
->getEditionModule();
272 CServerEditionModule
* module
= safe_cast
<CServerEditionModule
*>(imodule
);
275 nlinfo( "DSS: notifying ServerEditionModule that '%s' server is down", serviceName
.c_str() );
276 // module->onServiceDown( serviceName, serviceId );
282 void CDynamicScenarioService::init()
286 // initialize callbacks for service up / down
287 CUnifiedNetwork::getInstance()->setServiceUpCallback("*", cbServiceUp
, NULL
);
288 CUnifiedNetwork::getInstance()->setServiceDownCallback( "*", cbServiceDown
, NULL
);
290 CSingletonRegistry::getInstance()->init();
292 // preset the shard ID
293 if (ConfigFile
.getVarPtr("ShardId") != NULL
)
295 anticipateShardId(ConfigFile
.getVarPtr("ShardId")->asInt());
299 nlwarning("No variable ShardId in config file, this could result in miss registered DSS into SU because of late WS shard id message");
302 CAiWrapper::setInstance(new CAiWrapperServer
);
304 setVersion (RYZOM_VERSION
);
305 LigoConfigPtr
=&R2LigoConfig
;
307 if (!R2LigoConfig
.readPrimitiveClass ("world_editor_classes.xml", false))
309 // Should be in R:\leveldesign\world_editor_files
310 nlerror ("Can't load ligo primitive config file world_editor_classes.xml");
312 R2LigoConfig
.updateDynamicAliasBitCount(16);
314 // have ligo library register its own class types for its class factory
320 // setup the update systems
321 setUpdateTimeout(100);
324 IModuleManager
&mm
= IModuleManager::getInstance();
325 IModule
* serverGw
= mm
.createModule("StandardGateway", "serverGw", "");
326 nlassert(serverGw
!= NULL
);
328 NLNET::IModuleSocket
*socketServerGw
= mm
.getModuleSocket("serverGw");
329 nlassert(socketServerGw
!= NULL
);
330 _Dms
= new CDynamicMapService(ConfigFile
, socketServerGw
);
333 // open the server gw with a layer 3 transport
334 CCommandRegistry::getInstance().execute("serverGw.transportAdd L5Transport l5", *InfoLog
);
335 CCommandRegistry::getInstance().execute("serverGw.transportCmd l5(open)", *InfoLog
);
342 bool CDynamicScenarioService::update()
344 CSingletonRegistry::getInstance()->serviceUpdate();
348 void CDynamicScenarioService::release()
355 IModuleManager
&mm
= IModuleManager::getInstance();
356 IModule
* clientGw
= mm
.getLocalModule("serverGw");
357 nlassert(clientGw
!= NULL
);
358 mm
.deleteModule(clientGw
);
360 CSingletonRegistry::getInstance()->release();
366 NLNET_SERVICE_MAIN( CDynamicScenarioService
, "DSS", "dynamic_scenario_service", 0, CbArray
, "", "" );