# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

login_client.cpp

Go to the documentation of this file.
00001 
00009 /* Copyright, 2000 Nevrax Ltd.
00010  *
00011  * This file is part of NEVRAX NEL.
00012  * NEVRAX NEL is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2, or (at your option)
00015  * any later version.
00016 
00017  * NEVRAX NEL is distributed in the hope that it will be useful, but
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00020  * General Public License for more details.
00021 
00022  * You should have received a copy of the GNU General Public License
00023  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00024  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00025  * MA 02111-1307, USA.
00026  */
00027 
00028 #include "stdnet.h"
00029 
00030 #include "nel/misc/system_info.h"
00031 
00032 #include "nel/net/callback_client.h"
00033 
00034 #include "nel/net/login_cookie.h"
00035 #include "nel/net/login_client.h"
00036 
00037 #include "nel/net/udp_sock.h"
00038 
00039 using namespace std;
00040 using namespace NLMISC;
00041 
00042 namespace NLNET {
00043 
00044 
00045 // Callback for answer of the request shard
00046 bool ShardValidate;
00047 string ShardValidateReason;
00048 void cbShardValidate (CMessage &msgin, TSockId from, CCallbackNetBase &netbase)
00049 {
00050         //
00051         // S14: receive "SV" message from FES
00052         //
00053 
00054         msgin.serial (ShardValidateReason);
00055         ShardValidate = true;
00056 }
00057 
00058 static TCallbackItem FESCallbackArray[] =
00059 {
00060         { "SV", cbShardValidate },
00061 };
00062 
00063 string CLoginClient::connectToShard (CLoginCookie &lc, const std::string &addr, CCallbackClient &cnx)
00064 {
00065         nlassert (!cnx.connected());
00066         
00067         try
00068         {
00069                 //
00070                 // S12: connect to the FES and send "SV" message to the FES
00071                 //
00072                 cnx.connect (CInetAddress(addr));
00073                 cnx.addCallbackArray (FESCallbackArray, sizeof(FESCallbackArray)/sizeof(FESCallbackArray[0]));
00074 
00075                 cnx.displayAllMyAssociations ();
00076 
00077                 // send the cookie
00078                 CMessage msgout2 (cnx.getSIDA (), "SV");
00079                 msgout2.serial (lc);
00080                 cnx.send (msgout2);
00081 
00082                 // wait the answer of the connection
00083                 ShardValidate = false;
00084                 while (cnx.connected() && !ShardValidate)
00085                 {
00086                         cnx.update ();
00087                         nlSleep(10);
00088                 }
00089                 
00090                 // have we received the answer?
00091                 if (!ShardValidate) return "FES disconnect me";
00092         }
00093         catch (ESocket &e)
00094         {
00095                 return string("FES refused the connection (") + e.what () + ")";
00096         }
00097 
00098         return ShardValidateReason;
00099 }
00100 
00101 string CLoginClient::connectToShard (const std::string &addr, CUdpSock &cnx)
00102 {
00103         nlassert (!cnx.connected());
00104         
00105         try
00106         {
00107                 //
00108                 // S12: connect to the FES. Note: In UDP mode, it's the user that have to send the cookie to the front end
00109                 //
00110                 cnx.connect (CInetAddress(addr));
00111         }
00112         catch (ESocket &e)
00113         {
00114                 return string("FES refused the connection (") + e.what () + ")";
00115         }
00116 
00117         return ShardValidateReason;
00118 }
00119 
00120 string CLoginClient::connectToShard (const std::string &addr, CUdpSimSock &cnx)
00121 {
00122         nlassert (!cnx.connected());
00123         
00124         try
00125         {
00126                 //
00127                 // S12: connect to the FES. Note: In UDP mode, it's the user that have to send the cookie to the front end
00128                 //
00129                 cnx.connect (CInetAddress(addr));
00130         }
00131         catch (ESocket &e)
00132         {
00133                 return string("FES refused the connection (") + e.what () + ")";
00134         }
00135 
00136         return ShardValidateReason;
00137 }
00138 
00139 } // NLNET