1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
19 * multi shard example, front-end server.
21 * The goal of the example is to enable you to run 2 differents shards
22 * on the same computer with a login system.
24 * The naming service, admin executor service, login service, welcome service must be running.
28 // We're using the NeL Service framework and layer 5.
29 #include "nel/misc/config_file.h"
31 #include "nel/net/callback_server.h"
32 #include "nel/net/service.h"
33 #include "nel/net/login_server.h"
36 using namespace NLNET
;
37 using namespace NLMISC
;
40 * Connection callback for a client
42 void onConnectionClient (TSockId from
, const CLoginCookie
&cookie
)
44 nlinfo ("The client with uniq Id %d is connected", cookie
.getUserId ());
46 // store the user id in appId
47 from
->setAppId (cookie
.getUserId ());
52 * Disonnection callback for a client
54 void onDisconnectClient (TSockId from
, void *arg
)
56 nlinfo ("A client with uniq Id %d has disconnected", from
->appId ());
58 // tell the login system that this client is disconnected
59 CLoginServer::clientDisconnected ((uint32
) from
->appId ());
63 * CFrontEndService, based on IService
65 class CFrontEndService
: public IService
68 /// The server on which the clients connect
69 CCallbackServer _FEServer
;
78 // create a special connection for client (using TCP on port 37373)
79 uint16 fesPort
= 37373;
82 fesPort
= IService::ConfigFile
.getVar("FESPort").asInt();
84 catch ( EUnknownVar
& )
87 _FEServer
.init(fesPort
);
89 // connect and identify this front end to the login system
90 CLoginServer::init (_FEServer
, onConnectionClient
);
93 _FEServer
.setDisconnectionCallback(onDisconnectClient
, NULL
);
104 * Declare a service with the class CFrontEndService, the names "FS" (short) and "frontend_service" (long).
105 * The port is dynamicaly find and there s no callback array.
107 NLNET_SERVICE_MAIN (CFrontEndService
, "FS", "frontend_service", 0, EmptyCallbackArray
, "", "")