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.
34 #include "nel/misc/types_nl.h"
35 #include "nel/misc/debug.h"
36 #include "nel/misc/config_file.h"
37 #include "nel/misc/bit_mem_stream.h"
38 #include "nel/misc/path.h"
40 #include "nel/net/callback_client.h"
49 using namespace NLMISC
;
50 using namespace NLNET
;
53 // Do not display what you are typing
67 string CurrentEditString
;
69 // ***************************************************************************
70 void serverSentChat (CMessage
&msgin
, TSockId from
, CCallbackNetBase
&netbase
)
72 // Called when the server sent a CHAT message
75 printf("%s\n", text
.c_str());
78 // ***************************************************************************
79 // All messages handled by this server
81 TCallbackItem CallbackArray
[NB_CB
] =
83 { "CHAT", serverSentChat
}
89 int main (int argc
, char **argv
)
91 NLMISC::CApplicationContext applicationContext
;
93 CCallbackClient
*Client
;
95 NLMISC::CPath::addSearchPath(CHAT_DIR
);
97 // Read the host where to connect in the client.cfg file
98 CConfigFile ConfigFile
;
99 ConfigFile
.load (NLMISC::CPath::lookup("client.cfg"));
100 string
LSHost(ConfigFile
.getVar("LSHost").asString());
102 // Init and Connect the client to the server located on port 3333
103 Client
= new CCallbackClient();
104 Client
->addCallbackArray (CallbackArray
, NB_CB
);
106 printf("Please wait connecting...\n");
109 CInetAddress
addr(LSHost
+":3333");
110 Client
->connect(addr
);
112 catch(const ESocket
&e
)
114 printf("%s\n", e
.what());
118 if (!Client
->connected())
120 printf("Connection Error\n");
123 printf("Connected.\n");
139 else if (c
== KEY_ENTER
)
143 msg
.serial (CurrentEditString
);
145 CurrentEditString
= "";
149 CurrentEditString
+= c
;
154 while (Client
->connected());