#include <login_cookie.h>
_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)
Nevrax France
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. | |
|
||||||||||||
|
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 } |
|
|
Definition at line 54 of file login_cookie.h.
00054 : _Valid(false) { } |
|
|
Definition at line 110 of file login_cookie.h.
00110 { _Valid = false; }
|
|
|
Definition at line 55 of file login_cookie.cpp. 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 }
|
|
|
Definition at line 103 of file login_cookie.h. References _UserAddr, nlassert, and uint32.
|
|
|
Definition at line 105 of file login_cookie.h. References _UserId, nlassert, and uint32. Referenced by NLNET::cbShardValidation().
|
|
|
Definition at line 104 of file login_cookie.h. References _UserKey, nlassert, and uint32.
|
|
|
Definition at line 109 of file login_cookie.h.
00109 { return _Valid; }
|
|
|
Definition at line 56 of file login_cookie.h. References _UserAddr, _UserId, _UserKey, nlwarning, and s.
|
|
||||||||||||||||
|
Definition at line 107 of file login_cookie.h. References _UserAddr, _UserId, _UserKey, and uint32. Referenced by NLNET::cbShardValidation().
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
||||||||||||
|
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 }
|
|
|
Definition at line 121 of file login_cookie.h. Referenced by getUserAddr(), NLNET::operator==(), serial(), set(), setFromString(), setToString(), and toString(). |
|
|
Definition at line 123 of file login_cookie.h. Referenced by getUserId(), NLNET::operator==(), serial(), set(), setFromString(), setToString(), and toString(). |
|
|
Definition at line 122 of file login_cookie.h. Referenced by CLoginCookie(), getUserKey(), NLNET::operator==(), serial(), set(), setFromString(), setToString(), and toString(). |
|
|
Definition at line 119 of file login_cookie.h. Referenced by NLNET::operator==(). |
1.3.6