00001
00002
00003
00004
00005
00006
00007
00008
00009
00015 #ifndef __ACCOUNTS_H__
00016 #define __ACCOUNTS_H__
00017
00018 #include "nxwcommn.h"
00019 #include "set.h"
00020
00021 #define ADMIN_ACCOUNT 0
00022
00023
00024 enum AUTHENTICATE_RESULT {
00025 LOGIN_NOT_FOUND = -3,
00026 BAD_PASSWORD = -4,
00027 ACCOUNT_BANNED = -5,
00028 ACCOUNT_WIPE = -6,
00029 };
00030
00031
00032 typedef enum {
00033 LOG_OUT,
00034 LOG_ENTERING,
00035 LOG_INGAME,
00036 } ACCOUNT_STATE;
00037
00038
00039
00043 class cAccount {
00044 public:
00045 ACCOUNT number;
00046 std::string name;
00047 std::string pass;
00048 bool ban;
00049 bool ras;
00050 TIMERVAL tempblock;
00051 TIMERVAL blockeduntil;
00052 unsigned long lastlogin;
00053 unsigned long lastIp;
00054 ACCOUNT_STATE state;
00055 std::vector<SERIAL> pgs;
00056 SERIAL pc_online;
00057
00058 cAccount( ACCOUNT num = INVALID );
00059
00060 SERIAL getInWorld();
00061 void setEntering( );
00062 bool isEntering( );
00063 void setOnline( P_CHAR pc );
00064 void setOffline();
00065 void onLogin( NXWSOCKET socket );
00066 bool isOnline();
00067 void changePassword( std::string password);
00068 void getAllChars( NxwCharWrapper& sc );
00069 void addCharToAccount( P_CHAR pc );
00070 inline void setLastIp(UI32 ip)
00071 { lastIp=ip; };
00072 std::string getLastIp();
00073
00074 };
00075
00076 typedef map<ACCOUNT, cAccount> ACCOUNT_LIST;
00077 typedef map<std::string, ACCOUNT > ACCOUNT_LIST_BY_NAME;
00078
00079
00083 class cAccounts
00084 {
00085
00086 private:
00087 ACCOUNT_LIST acctlist;
00088 ACCOUNT_LIST_BY_NAME accbyname;
00089
00090 UI32 lastusedacctnum, unsavedaccounts;
00091
00092 public:
00093 UI32 lasttimecheck;
00094
00095 cAccounts( void );
00096 ~cAccounts( void );
00097
00098 private:
00099 UI32 saveratio;
00100 void safeInsert( cAccount& acc );
00101 void LoadAccount ( ACCOUNT acctnumb, FILE* F );
00102
00103 public:
00104 void SetSaveRatio ( int );
00105 void LoadAccounts();
00106 void SaveAccounts();
00107 void CheckAccountFile();
00108
00109 int Count();
00110
00111 SI32 Authenticate(std::string username, std::string password);
00112 bool AuthenticateRAS(std::string username, std::string password);
00113 ACCOUNT CreateAccount(std::string username, std::string password);
00114
00115 bool IsOnline( ACCOUNT acctnum );
00116 SERIAL GetInWorld( ACCOUNT acctnum );
00117
00118 void SetOnline( P_CHAR pc );
00119 void SetEntering( ACCOUNT acctnum );
00120 void SetOffline( ACCOUNT acctnum );
00121 void OnLogin( ACCOUNT acctnum, NXWSOCKET socket );
00122 SI32 verifyPassword(std::string username, std::string password);
00123 SI32 ChangePassword( ACCOUNT acctnum, std::string password);
00124 void AddCharToAccount( ACCOUNT acctnum, P_CHAR pc );
00125 void GetAllChars( ACCOUNT acctnum, NxwCharWrapper& sc );
00126 ACCOUNT GetAccountByName(std::string name);
00127 cAccount *GetAccount(ACCOUNT acctnumb);
00128 bool RemoveAccount( std::string name );
00129
00130 };
00131
00132 extern cAccounts* Accounts;
00133
00134
00135 #endif // __ACCOUNTS_H__