Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / server_share / login_service_itf.h
blobef7eba0a84e443f10c44c1f0aecdc555a1db01f7
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 /////////////////////////////////////////////////////////////////
18 // WARNING : this is a generated file, don't change it !
19 /////////////////////////////////////////////////////////////////
21 #ifndef LOGIN_SERVICE_ITF
22 #define LOGIN_SERVICE_ITF
23 #include "nel/misc/types_nl.h"
24 #include <memory>
25 #include "nel/misc/hierarchical_timer.h"
26 #include "nel/misc/string_conversion.h"
27 #include "nel/net/message.h"
28 #include "nel/net/module.h"
29 #include "nel/net/module_builder_parts.h"
30 #include "nel/net/module_message.h"
31 #include "nel/net/module_gateway.h"
33 #include "game_share/callback_adaptor.h"
35 #include "nel/net/login_cookie.h"
37 namespace LS
41 class CLoginServiceWebItf
43 protected:
45 /// the callback server adaptor
46 CUniquePtr<ICallbackServerAdaptor> _CallbackServer;
48 void getCallbakArray(NLNET::TCallbackItem *&arrayPtr, uint32 &arraySize)
50 static NLNET::TCallbackItem callbackArray[] =
52 { "LG", CLoginServiceWebItf::cb_login },
53 { "LO", CLoginServiceWebItf::cb_logout },
57 arrayPtr = callbackArray;
58 arraySize = sizeofarray(callbackArray);
61 static void _cbConnection(NLNET::TSockId from, void *arg)
63 H_AUTO(CLoginServiceWeb__cbConnection);
64 CLoginServiceWebItf *_this = reinterpret_cast<CLoginServiceWebItf *>(arg);
66 _this->on_CLoginServiceWeb_Connection(from);
69 static void _cbDisconnection(NLNET::TSockId from, void *arg)
71 H_AUTO(CLoginServiceWeb__cbDisconnection);
72 CLoginServiceWebItf *_this = reinterpret_cast<CLoginServiceWebItf *>(arg);
74 _this->on_CLoginServiceWeb_Disconnection(from);
78 public:
79 /** Constructor, if you specify a replacement adaptor, then the object
80 * become owner of the adaptor (and it will be released with the
81 * interface).
83 CLoginServiceWebItf(ICallbackServerAdaptor *replacementAdaptor = NULL)
85 if (replacementAdaptor == NULL)
87 // use default callback server
88 _CallbackServer = CUniquePtr<ICallbackServerAdaptor>(new CNelCallbackServerAdaptor(this));
90 else
92 // use the replacement one
93 _CallbackServer = CUniquePtr<ICallbackServerAdaptor>(replacementAdaptor);
97 virtual ~CLoginServiceWebItf()
101 /// Open the interface socket in the specified port
102 void openItf(uint16 port)
104 NLNET::TCallbackItem *arrayPtr;
105 uint32 arraySize;
109 getCallbakArray(arrayPtr, arraySize);
110 _CallbackServer->addCallbackArray(arrayPtr, arraySize);
112 _CallbackServer->setConnectionCallback (_cbConnection, this);
113 _CallbackServer->setDisconnectionCallback (_cbDisconnection, this);
115 _CallbackServer->init(port);
118 /** Must be called evenly, update the network subclass to receive message
119 * and dispatch method invokation.
121 void update()
123 H_AUTO(CLoginServiceWeb_update);
127 _CallbackServer->update();
129 catch (...)
131 nlwarning("CLoginServiceWeb : Exception launch in callback server update");
135 // Return the cookie generated for this user session
136 // Eventualy, return an empty string as cookie in case of error
137 // resultCode : 0 - ok, login success
138 // 1 - invalid user
139 // 2 - user already online, must relog
140 // errorString contain a stringified description in case of error
142 void loginResult(NLNET::TSockId dest, uint32 userId, const std::string &cookie, uint32 resultCode, const std::string &errorString)
144 H_AUTO(loginResult_loginResult);
145 #ifdef NL_DEBUG
146 nldebug("CLoginServiceWeb::loginResult called");
147 #endif
148 NLNET::CMessage message("LGR");
149 nlWrite(message, serial, userId);
150 nlWrite(message, serial, const_cast < std::string& > (cookie));
151 nlWrite(message, serial, resultCode);
152 nlWrite(message, serial, const_cast < std::string& > (errorString));
154 _CallbackServer->send(message, dest);
156 // Return an error code for the logout attemp
157 // If return is not 0, then reason contains a debug string
158 // Return values : 0 - ok
159 // 1 - invalid user
160 // 2 - user already offline
162 void logoutResult(NLNET::TSockId dest, uint32 errorCode, const std::string &reason)
164 H_AUTO(logoutResult_logoutResult);
165 #ifdef NL_DEBUG
166 nldebug("CLoginServiceWeb::logoutResult called");
167 #endif
168 NLNET::CMessage message("LGOR");
169 nlWrite(message, serial, errorCode);
170 nlWrite(message, serial, const_cast < std::string& > (reason));
172 _CallbackServer->send(message, dest);
175 static void cb_login (NLNET::CMessage &message, NLNET::TSockId from, NLNET::CCallbackNetBase &netbase)
177 H_AUTO(login_on_login);
178 #ifdef NL_DEBUG
179 nldebug("CLoginServiceWeb::cb_login received from class '%s'", typeid(netbase).name());
180 #endif
181 ICallbackServerAdaptor *adaptor = static_cast< ICallbackServerAdaptor *>(netbase.getUserData());
183 CLoginServiceWebItf *callback = (CLoginServiceWebItf *)adaptor->getContainerClass();
185 if (callback == NULL)
186 return;
187 uint32 userId;
188 std::string ipAddress;
189 uint32 domainId;
190 nlRead(message, serial, userId);
191 nlRead(message, serial, ipAddress);
192 nlRead(message, serial, domainId);
195 #ifdef NL_DEBUG
196 nldebug("CLoginServiceWeb::cb_login : calling on_login");
197 #endif
200 callback->on_login(from, userId, ipAddress, domainId);
204 static void cb_logout (NLNET::CMessage &message, NLNET::TSockId from, NLNET::CCallbackNetBase &netbase)
206 H_AUTO(logout_on_logout);
207 #ifdef NL_DEBUG
208 nldebug("CLoginServiceWeb::cb_logout received from class '%s'", typeid(netbase).name());
209 #endif
210 ICallbackServerAdaptor *adaptor = static_cast< ICallbackServerAdaptor *>(netbase.getUserData());
212 CLoginServiceWebItf *callback = (CLoginServiceWebItf *)adaptor->getContainerClass();
214 if (callback == NULL)
215 return;
216 uint32 userId;
217 nlRead(message, serial, userId);
220 #ifdef NL_DEBUG
221 nldebug("CLoginServiceWeb::cb_logout : calling on_logout");
222 #endif
225 callback->on_logout(from, userId);
230 /// Connection callback : a new interface client connect
231 virtual void on_CLoginServiceWeb_Connection(NLNET::TSockId from) =0;
232 /// Disconnection callback : one of the interface client disconnect
233 virtual void on_CLoginServiceWeb_Disconnection(NLNET::TSockId from) =0;
236 // The web side as authentified an user
237 // and inform the LS that the user is now online
238 // and authentified for the indicated ring domain
239 // LS then generate a cookie that will be
240 // used to authenticate the user when it will
241 // conect to the front end later
242 virtual void on_login(NLNET::TSockId from, uint32 userId, const std::string &ipAddress, uint32 domainId) =0;
244 // The web side says that the user is no more actif (has logged out)
245 // If the user is not in game (status cs_online), then
246 // it's status is set to cs_offline and the cookie cleared
247 // Otherwise, the status is unchanged and the cookie is still valid.
248 virtual void on_logout(NLNET::TSockId from, uint32 userId) =0;
253 /** This is the client side of the interface
254 * Derive from this class to invoke method on the callback server
257 class CLoginServiceWebClientItf
259 protected:
261 /// the callback client adaptor
262 CUniquePtr < ICallbackClientAdaptor > _CallbackClient;
265 void getCallbakArray(NLNET::TCallbackItem *&arrayPtr, uint32 &arraySize)
268 static NLNET::TCallbackItem callbackArray[] =
270 { "LGR", CLoginServiceWebClientItf::cb_loginResult },
271 { "LGOR", CLoginServiceWebClientItf::cb_logoutResult },
275 arrayPtr = callbackArray;
276 arraySize = sizeofarray(callbackArray);
280 static void _cbDisconnection(NLNET::TSockId from, void *arg)
282 CLoginServiceWebClientItf *_this = reinterpret_cast<CLoginServiceWebClientItf *>(arg);
284 _this->on_CLoginServiceWebClient_Disconnection(from);
288 public:
289 /// Retreive the message name for a given callback name
290 static const std::string &getMessageName(const std::string &methodName)
292 static std::map<std::string, std::string> messageNames;
293 static bool initialized = false;
294 if (!initialized)
296 messageNames.insert(std::make_pair(std::string("on_loginResult"), std::string("LGR")));
297 messageNames.insert(std::make_pair(std::string("on_logoutResult"), std::string("LGOR")));
299 initialized = true;
302 std::map < std::string, std::string>::const_iterator it(messageNames.find(methodName));
303 if (it != messageNames.end())
304 return it->second;
307 static std::string emptyString;
309 return emptyString;
313 CLoginServiceWebClientItf(ICallbackClientAdaptor *adaptorReplacement = NULL)
315 if (adaptorReplacement == NULL)
317 // use the default Nel adaptor
318 _CallbackClient = CUniquePtr < ICallbackClientAdaptor >(new CNelCallbackClientAdaptor(this));
320 else
322 // use the replacement one
323 _CallbackClient = CUniquePtr < ICallbackClientAdaptor >(adaptorReplacement);
327 /// Connect the interface client to the callback server at the specified address and port
328 virtual void connectItf(NLNET::CInetAddress address)
330 NLNET::TCallbackItem *arrayPtr;
331 uint32 arraySize;
333 static bool callbackAdded = false;
334 if (!callbackAdded)
337 getCallbakArray(arrayPtr, arraySize);
338 _CallbackClient->addCallbackArray(arrayPtr, arraySize);
341 _CallbackClient->setDisconnectionCallback (_cbDisconnection, this);
343 _CallbackClient->connect(address);
346 /** Must be called evenly, update the network subclass to receive message
347 * and dispatch invokation returns.
349 virtual void update()
351 H_AUTO(CLoginServiceWeb_update);
355 _CallbackClient->update();
357 catch (...)
359 nlwarning("CLoginServiceWeb : Exception launch in callback client update");
363 // The web side as authentified an user
364 // and inform the LS that the user is now online
365 // and authentified for the indicated ring domain
366 // LS then generate a cookie that will be
367 // used to authenticate the user when it will
368 // conect to the front end later
370 void login(uint32 userId, const std::string &ipAddress, uint32 domainId)
372 #ifdef NL_DEBUG
373 nldebug("CLoginServiceWebClient::login called");
374 #endif
375 NLNET::CMessage message("LG");
376 nlWrite(message, serial, userId);
377 nlWrite(message, serial, const_cast < std::string& > (ipAddress));
378 nlWrite(message, serial, domainId);
380 _CallbackClient->send(message);
382 // The web side says that the user is no more actif (has logged out)
383 // If the user is not in game (status cs_online), then
384 // it's status is set to cs_offline and the cookie cleared
385 // Otherwise, the status is unchanged and the cookie is still valid.
387 void logout(uint32 userId)
389 #ifdef NL_DEBUG
390 nldebug("CLoginServiceWebClient::logout called");
391 #endif
392 NLNET::CMessage message("LO");
393 nlWrite(message, serial, userId);
395 _CallbackClient->send(message);
398 static void cb_loginResult (NLNET::CMessage &message, NLNET::TSockId from, NLNET::CCallbackNetBase &netbase)
400 #ifdef NL_DEBUG
401 nldebug("CLoginServiceWebClient::cb_loginResult received from class '%s'", typeid(netbase).name());
402 #endif
403 ICallbackClientAdaptor *adaptor = static_cast< ICallbackClientAdaptor *>(netbase.getUserData());
405 CLoginServiceWebClientItf *callback = (CLoginServiceWebClientItf *)adaptor->getContainerClass();
407 if (callback == NULL)
408 return;
409 uint32 userId;
410 std::string cookie;
411 uint32 resultCode;
412 std::string errorString;
413 nlRead(message, serial, userId);
414 nlRead(message, serial, cookie);
415 nlRead(message, serial, resultCode);
416 nlRead(message, serial, errorString);
419 #ifdef NL_DEBUG
420 nldebug("CLoginServiceWebClient::cb_loginResult : calling on_loginResult");
421 #endif
423 callback->on_loginResult(from, userId, cookie, resultCode, errorString);
426 static void cb_logoutResult (NLNET::CMessage &message, NLNET::TSockId from, NLNET::CCallbackNetBase &netbase)
428 #ifdef NL_DEBUG
429 nldebug("CLoginServiceWebClient::cb_logoutResult received from class '%s'", typeid(netbase).name());
430 #endif
431 ICallbackClientAdaptor *adaptor = static_cast< ICallbackClientAdaptor *>(netbase.getUserData());
433 CLoginServiceWebClientItf *callback = (CLoginServiceWebClientItf *)adaptor->getContainerClass();
435 if (callback == NULL)
436 return;
437 uint32 errorCode;
438 std::string reason;
439 nlRead(message, serial, errorCode);
440 nlRead(message, serial, reason);
443 #ifdef NL_DEBUG
444 nldebug("CLoginServiceWebClient::cb_logoutResult : calling on_logoutResult");
445 #endif
447 callback->on_logoutResult(from, errorCode, reason);
451 /// Disconnection callback : the connection to the server is lost
452 virtual void on_CLoginServiceWebClient_Disconnection(NLNET::TSockId from) =0;
455 // Return the cookie generated for this user session
456 // Eventualy, return an empty string as cookie in case of error
457 // resultCode : 0 - ok, login success
458 // 1 - invalid user
459 // 2 - user already online, must relog
460 // errorString contain a stringified description in case of error
461 virtual void on_loginResult(NLNET::TSockId from, uint32 userId, const std::string &cookie, uint32 resultCode, const std::string &errorString) =0;
463 // Return an error code for the logout attemp
464 // If return is not 0, then reason contains a debug string
465 // Return values : 0 - ok
466 // 1 - invalid user
467 // 2 - user already offline
468 virtual void on_logoutResult(NLNET::TSockId from, uint32 errorCode, const std::string &reason) =0;
474 #endif