NLNET::CLoginCookie Class Reference

#include <login_cookie.h>


Detailed Description

Manage cookie during the authenticate procedure.

_UserAddr is the ipv4 address of the client in uint32 _UserKey is an uint32 generated by the login_service at each login password verification _UserId is an uint32 uniq for each account (an account could have more than one avatar)

Author:
Vianney Lecroart

Nevrax France

Date:
2001

Definition at line 49 of file login_cookie.h.

Public Member Functions

void clear ()
 CLoginCookie ()
 CLoginCookie (uint32 addr, uint32 id)
uint32 generateKey ()
uint32 getUserAddr () const
uint32 getUserId () const
uint32 getUserKey () const
bool isValid () const
void serial (NLMISC::IStream &s)
void set (uint32 ua, uint32 uk, uint32 ui)
void setFromString (const std::string &str)
std::string setToString ()
std::string toString () const

Private Attributes

uint32 _UserAddr
uint32 _UserId
uint32 _UserKey
bool _Valid

Friends

bool operator== (const CLoginCookie &c1, const CLoginCookie &c2)
 Comparison == operator.


Constructor & Destructor Documentation

NLNET::CLoginCookie::CLoginCookie uint32  addr,
uint32  id
 

Definition at line 47 of file login_cookie.cpp.

References _UserKey, addr, generateKey(), id, and uint32.

00047                                                   : _Valid(true), _UserAddr(addr), _UserId(id)
00048 {
00049         // generates the key for this cookie
00050         _UserKey = generateKey();
00051 }

NLNET::CLoginCookie::CLoginCookie  )  [inline]
 

Definition at line 54 of file login_cookie.h.

00054 : _Valid(false) { }


Member Function Documentation

void NLNET::CLoginCookie::clear void   )  [inline]
 

Definition at line 110 of file login_cookie.h.

00110 { _Valid = false; }

uint32 NLNET::CLoginCookie::generateKey  ) 
 

Todo:
ace: is the cookie enough to avoid hackers to predice keys?

Definition at line 55 of file login_cookie.cpp.

References r, t, and uint32.

Referenced by CLoginCookie().

00056 {
00057         uint32 t = time (NULL);
00058         srand (time(NULL));
00059         uint32 r = rand ();
00060         static uint32 n = 0;
00061         n++;
00062 
00063         // 12bits for the time (in second) => loop in 1 hour
00064         //  8bits for random => 256 case
00065         // 12bits for the inc number => can generate 4096 keys per second without any problem (if you generate more than this number, you could have 2 same keys)
00066         return (t&0xFFF)<<20 | (r&0xFF)<<12 | (n&0xFFF);
00067 
00068         // 12bits for the time (in second) => loop in 1 hour
00069         // 20bits for the inc number => can generate more than 1 million keys per second without any problem (never exceed on my computer)
00070 //      return (t&0xFFF)<<20 | (n&0xFFFFF);
00071 }

uint32 NLNET::CLoginCookie::getUserAddr  )  const [inline]
 

Definition at line 103 of file login_cookie.h.

References _UserAddr, nlassert, and uint32.

00103 { nlassert (_Valid); return _UserAddr; }

uint32 NLNET::CLoginCookie::getUserId  )  const [inline]
 

Definition at line 105 of file login_cookie.h.

References _UserId, nlassert, and uint32.

Referenced by NLNET::cbShardValidation().

00105 { nlassert (_Valid); return _UserId; }

uint32 NLNET::CLoginCookie::getUserKey  )  const [inline]
 

Definition at line 104 of file login_cookie.h.

References _UserKey, nlassert, and uint32.

00104 { nlassert (_Valid); return _UserKey; }

bool NLNET::CLoginCookie::isValid void   )  const [inline]
 

Definition at line 109 of file login_cookie.h.

00109 { return _Valid; }

void NLNET::CLoginCookie::serial NLMISC::IStream s  )  [inline]
 

Definition at line 56 of file login_cookie.h.

References _UserAddr, _UserId, _UserKey, nlwarning, and s.

00057         {
00058                 // verify that we initialized the cookie before writing it
00059                 if (!s.isReading() && !_Valid) nlwarning ("LC: serialize a non valid cookie");
00060 
00061                 s.serial (_UserAddr);
00062                 s.serial (_UserKey);
00063                 s.serial (_UserId);
00064 
00065                 if (s.isReading()) _Valid = true;
00066         }

void NLNET::CLoginCookie::set uint32  ua,
uint32  uk,
uint32  ui
[inline]
 

Definition at line 107 of file login_cookie.h.

References _UserAddr, _UserId, _UserKey, and uint32.

Referenced by NLNET::cbShardValidation().

00107 { _Valid = true; _UserAddr = ua; _UserKey = uk; _UserId = ui; }

void NLNET::CLoginCookie::setFromString const std::string &  str  )  [inline]
 

Definition at line 83 of file login_cookie.h.

References _UserAddr, _UserId, _UserKey, nlinfo, and toString().

00084         {
00085                 sscanf(str.c_str(), "%08X|%08X|%08X", &_UserAddr, &_UserKey, &_UserId);
00086 
00087                 if(str.empty () || (_UserAddr==0 && _UserKey==0 && _UserId==0))
00088                         _Valid = 0;
00089                 else
00090                         _Valid = 1;
00091 
00092                 nlinfo ("LC: setFromString %s -> %s, isValid: %d", str.c_str (), toString().c_str (), _Valid);
00093         }

std::string NLNET::CLoginCookie::setToString  )  [inline]
 

Definition at line 68 of file login_cookie.h.

References _UserAddr, _UserId, _UserKey, nlinfo, NLMISC::smprintf(), and toString().

00069         {
00070                 if (_Valid)
00071                 {
00072                         char cstr[8*3+2+1];
00073                         NLMISC::smprintf(cstr, 8*3+2+1, "%08X|%08X|%08X", _UserAddr, _UserKey, _UserId);
00074                         nlinfo ("LC: setToString %s -> %s", toString().c_str (), cstr);
00075                         return cstr;
00076                 }
00077                 else
00078                 {
00079                         return "0|0|0";
00080                 }
00081         }

std::string NLNET::CLoginCookie::toString  )  const [inline]
 

Definition at line 95 of file login_cookie.h.

References _UserAddr, _UserId, _UserKey, and NLMISC::toString().

Referenced by NLNET::cbShardValidation(), NLNET::cbWSChooseShard(), setFromString(), and setToString().

00096         {
00097                 if (_Valid)
00098                         return "'" + NLMISC::toString("%08X", (unsigned int)_UserAddr) + "|" + NLMISC::toString("%08X", (unsigned int)_UserKey) + "|" + NLMISC::toString("%08X", (unsigned int)_UserId) + "'";
00099                 else
00100                         return "<InvalidCookie>";
00101         }


Friends And Related Function Documentation

bool operator== const CLoginCookie c1,
const CLoginCookie c2
[friend]
 

Comparison == operator.

Definition at line 40 of file login_cookie.cpp.

00041 {
00042         nlassert (c1._Valid && c2._Valid);
00043 
00044         return c1._UserAddr==c2._UserAddr && c1._UserKey==c2._UserKey && c1._UserId==c2._UserId;
00045 }


Field Documentation

uint32 NLNET::CLoginCookie::_UserAddr [private]
 

Definition at line 121 of file login_cookie.h.

Referenced by getUserAddr(), NLNET::operator==(), serial(), set(), setFromString(), setToString(), and toString().

uint32 NLNET::CLoginCookie::_UserId [private]
 

Definition at line 123 of file login_cookie.h.

Referenced by getUserId(), NLNET::operator==(), serial(), set(), setFromString(), setToString(), and toString().

uint32 NLNET::CLoginCookie::_UserKey [private]
 

Definition at line 122 of file login_cookie.h.

Referenced by CLoginCookie(), getUserKey(), NLNET::operator==(), serial(), set(), setFromString(), setToString(), and toString().

bool NLNET::CLoginCookie::_Valid [private]
 

Definition at line 119 of file login_cookie.h.

Referenced by NLNET::operator==().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:58:34 2004 for NeL by doxygen 1.3.6