From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- .../plain&hideattic=0&sortby=date/index.html | 265 +++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 cvs/cvsweb.cgi/~checkout~/code/client/Attic/client.cpp?rev=1.8&content-type=text/plain&hideattic=0&sortby=date/index.html (limited to 'cvs/cvsweb.cgi/~checkout~/code/client/Attic/client.cpp?rev=1.8&content-type=text/plain&hideattic=0&sortby=date/index.html') diff --git a/cvs/cvsweb.cgi/~checkout~/code/client/Attic/client.cpp?rev=1.8&content-type=text/plain&hideattic=0&sortby=date/index.html b/cvs/cvsweb.cgi/~checkout~/code/client/Attic/client.cpp?rev=1.8&content-type=text/plain&hideattic=0&sortby=date/index.html new file mode 100644 index 00000000..37604174 --- /dev/null +++ b/cvs/cvsweb.cgi/~checkout~/code/client/Attic/client.cpp?rev=1.8&content-type=text/plain&hideattic=0&sortby=date/index.html @@ -0,0 +1,265 @@ +/** \file client.cpp + * Client prototype + * + * $Id: client.cpp,v 1.8 2000/11/24 14:17:35 coutelas Exp $ + */ + +/* Copyright, 2000 Nevrax Ltd. + * + * This file is part of NEVRAX NEL. + * NEVRAX NEL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + + * NEVRAX NEL is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with NEVRAX NEL; see the file COPYING. If not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +#include "nel/misc/types_nl.h" +#include "nel/misc/debug.h" +#include "nel/misc/i18n.h" + +#include "nel/net/msg_socket.h" +#include "nel/net/naming_client.h" +#include "nel/net/unitime.h" + +#include "nel/3d/driver.h" + +#include "language_interface.h" +#include "login_interface.h" +#include "shards_list_interface.h" + +#include + +using namespace std; +using namespace NLNET; +using namespace NLMISC; +using namespace NL3D; + + +#ifdef NL_OS_WINDOWS +CFontGenerator fontGen("\\\\server\\code\\fonts\\arialuni.ttf"); +#else +CFontGenerator fontGen("arialuni.ttf"); +#endif + + +/** + * login + */ +CLogUserId login(NL3D::CScene * scene, + NL3D::CFontGenerator * fontGenerator, + uint w, uint h) +{ + CLoginInterface logscreen(scene, fontGenerator, w, h); + return logscreen.log(); +} + + + +/** + * connectToLS + */ +bool connectToLS (CLogUserId &luid, vector& shards) +{ + CInetAddress servaddr("vianneyl", 49999); + + CSocket server; + try + { + server.connect(servaddr); + } + catch(Exception) + { + return false; + } + + CMessage msgout(""); + msgout.setType(0); // we don't listen for incoming replies, therefore we must not use a type as string. 0 is the default action for CLogService : "LOG" + + string l = luid.Login.toString(), p = luid.Password.toString(); + msgout.serial(l); + msgout.serial(p); + + // send the message + server.send(msgout); + + // receive the answer + CMessage msgin("", true); + server.receive(msgin); + + uint8 ok; + msgin.serial (ok); + nlinfo ("res=%d", ok); + + if (ok) + { + uint32 nbshard, id; + msgin.serial (id); + msgin.serial (nbshard); + for (uint i = 0; i < nbshard; i++) + { + string shardip, shardname; + msgin.serial (shardip); + msgin.serial (shardname); + shards.push_back (shardip); + } + } + + server.close(); + + return ok==1; +} + + +/** + * chooseLanguage + */ +sint chooseLanguage(NL3D::CScene * scene, + NL3D::CFontGenerator * fontGenerator, + uint w, uint h) +{ + CLanguageInterface languageScreen(scene, fontGenerator, w, h); + return languageScreen.choose(); +} + + + +/** + * chooseShard + */ +sint chooseShard(NL3D::CScene * scene, + NL3D::CFontGenerator * fontGenerator, + uint w, uint h, + const std::vector& shards) +{ + CShardsListInterface shardListScreen(scene, fontGenerator, w, h, shards); + return shardListScreen.choose(); +} + + +enum TState +{ + LANGUAGE, + LOGIN, + CONNECT, + SHARD +}; + + +/****************************************************************\ + MAIN +\****************************************************************/ +void main() +{ + try + { + // init scene + uint w = 800; + uint h = 600; + uint bpp = 32; + bool windowed = true; + NL3D::CScene scene; + NL3D::CSceneUt::init3d(scene, w, h, bpp, windowed); + + // synchronize time with server + CUniTime::syncUniTimeFromService(); + + // user id (login & password) + CLogUserId id; + + //shard's name list + vector shards; + + // index of chard in the list + sint shardIndex; + + TState clientSate = LANGUAGE; + bool quit = false; + while(!quit) + { + switch(clientSate) + { + // language choice + case LANGUAGE: + { + sint languageIndex = chooseLanguage(&scene, &fontGen, w, h); + if(languageIndex==-1) + quit = true; + else + { + CI18N::load(languageIndex); + clientSate = LOGIN; + } + } + break; + + // get user's login and password + case LOGIN: + { + id = login(&scene, &fontGen, w, h); + if(id.Login.size()==0) // happens only if return back is asked + clientSate = LANGUAGE; + else + clientSate = CONNECT; + } + break; + + // connection + case CONNECT: + { + bool connected = connectToLS (id,shards); + if(!connected) + { + if(windowed) + { + IDriver::TMessageBoxId answer = + scene.getDriver()->systemMessageBox("Can't establish connection", + "user connection", IDriver::retryCancelType, IDriver::errorIcon); + if(answer==IDriver::cancelId) + clientSate = LOGIN; + else + clientSate = CONNECT; + } + else + clientSate = LOGIN; + } + else + clientSate = SHARD; + } + break; + + // shard choice + case SHARD: + { + shardIndex = chooseShard(&scene, &fontGen, w, h, shards); + if(shardIndex==-1) + clientSate = LOGIN; + else + quit = true; + } + break; + } + + if(quit) break; + } + + + // release scene + NL3D::CSceneUt::release3d(scene); + + } + catch(Exception &e) + { + nlerror ("main(): Exception trapped: %s", e.what ()); + } + +} -- cgit v1.2.1