version 1.8, 2000/11/24 14:17:35 |
version 1.9, 2000/11/28 13:21:23 |
| |
/** | /** |
* login | * login |
*/ | */ |
CLogUserId login(NL3D::CScene * scene, | sint8 login(NL3D::CScene * scene, |
NL3D::CFontGenerator * fontGenerator, | NL3D::CFontGenerator * fontGenerator, |
uint w, uint h) | uint w, uint h, vector<string>& shards) |
{ | { |
CLoginInterface logscreen(scene, fontGenerator, w, h); | CLoginInterface logscreen(scene, fontGenerator, w, h); |
return logscreen.log(); | return logscreen.log(shards); |
} | } |
| |
| |
| |
/** | /** |
* connectToLS | |
*/ | |
bool connectToLS (CLogUserId &luid, vector<string>& 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 | * chooseLanguage |
*/ | */ |
sint chooseLanguage(NL3D::CScene * scene, | sint chooseLanguage(NL3D::CScene * scene, |
| |
{ | { |
LANGUAGE, | LANGUAGE, |
LOGIN, | LOGIN, |
CONNECT, | |
SHARD | SHARD |
}; | }; |
| |
| |
uint w = 800; | uint w = 800; |
uint h = 600; | uint h = 600; |
uint bpp = 32; | uint bpp = 32; |
bool windowed = true; | bool windowed = false;//true; |
NL3D::CScene scene; | NL3D::CScene scene; |
NL3D::CSceneUt::init3d(scene, w, h, bpp, windowed); | NL3D::CSceneUt::init3d(scene, w, h, bpp, windowed); |
| |
| |
// index of chard in the list | // index of chard in the list |
sint shardIndex; | sint shardIndex; |
| |
TState clientSate = LANGUAGE; | |
| TState clientState = LANGUAGE; |
bool quit = false; | bool quit = false; |
while(!quit) | while(!quit) |
{ | { |
switch(clientSate) | switch(clientState) |
{ | { |
// language choice | // language choice |
case LANGUAGE: | case LANGUAGE: |
| |
else | else |
{ | { |
CI18N::load(languageIndex); | CI18N::load(languageIndex); |
clientSate = LOGIN; | clientState = LOGIN; |
} | } |
} | } |
break; | break; |
| |
// get user's login and password | // get user's login and password |
case LOGIN: | case LOGIN: |
{ | { |
id = login(&scene, &fontGen, w, h); | if(login(&scene, &fontGen, w, h, shards)) |
if(id.Login.size()==0) // happens only if return back is asked | clientState = SHARD; |
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 | else |
clientSate = SHARD; | clientState = LANGUAGE; |
} | } |
break; | break; |
| |
| |
{ | { |
shardIndex = chooseShard(&scene, &fontGen, w, h, shards); | shardIndex = chooseShard(&scene, &fontGen, w, h, shards); |
if(shardIndex==-1) | if(shardIndex==-1) |
clientSate = LOGIN; | clientState = LOGIN; |
else | else |
quit = true; | quit = true; |
} | } |