Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / samples / net / multi_shards / client.cpp
blob6841177b4f72498258e972c189a7f452b3486c03
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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/>.
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.
28 // We're using std
29 #include <string>
31 // We're using NeL
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"
44 using namespace std;
45 using namespace NLMISC;
46 using namespace NLNET;
49 * main
51 void main (int argc, char **argv)
53 string result;
55 CConfigFile ConfigFile;
57 ConfigFile.load ("client.cfg");
59 string LSHost(ConfigFile.getVar("LSHost").asString());
61 char buf[256];
62 printf("Login: ");
63 fgets(buf, 256, stdin);
64 string Login(buf);
66 printf("Password: ");
67 fgets(buf, 256, stdin);
68 string Password(buf);
70 if (Login.empty ())
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 ())
111 cnx->update ();
112 nlSleep(10);
115 if( cnx->connected ())
116 cnx->disconnect ();
118 delete cnx;