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 * Login system example, client.
21 * This client connects to a front-end server using login system.
23 * Before running this client, the front end service sample must run,
24 * and also the NeL naming_service, time_service, login_service, welcome_service.
32 #include "nel/misc/types_nl.h"
33 #include "nel/misc/debug.h"
34 #include "nel/misc/config_file.h"
35 #include "nel/misc/bit_mem_stream.h"
37 // We're using the login client
38 #include "nel/net/login_client.h"
39 #include "nel/net/login_cookie.h"
41 #include "nel/net/udp_sock.h"
45 using namespace NLMISC
;
46 using namespace NLNET
;
51 void main (int argc
, char **argv
)
55 CConfigFile ConfigFile
;
57 ConfigFile
.load ("client.cfg");
59 string
LSHost(ConfigFile
.getVar("LSHost").asString());
63 fgets(buf
, 256, stdin
);
67 fgets(buf
, 256, stdin
);
72 Login
= ConfigFile
.getVar("Login").asString();
75 if (Password
.empty ())
77 Password
= ConfigFile
.getVar("Password").asString();
80 /* Try to connect to the login service and check the login, password and version of the client.
81 * return an empty string if all go well
83 result
= CLoginClient::authenticate(LSHost
+":49999", Login
, Password
, "sample");
85 if(!result
.empty()) nlerror ("*** Authenticate failed '%s' ***", result
.c_str());
87 // CLoginClient::ShardList contains all available shards
88 for (uint i
= 0; i
< CLoginClient::ShardList
.size (); i
++)
90 nlinfo("*** shard %d is: %s (%d) ***", i
, CLoginClient::ShardList
[i
].Name
.c_str (), CLoginClient::ShardList
[i
].Id
);
93 /* Try to connect to the last shard number in the list.
94 * return an empty string if all go well
97 string fs_ip
, login_cookie
;
98 result
= CLoginClient::wantToConnectToShard(CLoginClient::ShardList
[CLoginClient::ShardList
.size() - 1].Id
, fs_ip
, login_cookie
);
99 if (!result
.empty()) nlerror("*** Select shard failed '%s' ***", result
.c_str());
100 CLoginCookie cookie
; cookie
.setFromString(login_cookie
); // who's idea was it to send the cookie as a string...
102 CCallbackClient
*cnx
= new CCallbackClient();
103 result
= CLoginClient::connectToShard(cookie
, fs_ip
, *cnx
);
105 if (!result
.empty()) nlerror("*** Connection to the shard failed '%s' ***", result
.c_str());
107 nlinfo ("*** Connection granted! You are connected on the frond end ***");
109 while (cnx
->connected ())
115 if( cnx
->connected ())