// EQ2Emulator: Everquest II Server Emulator - Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net) - GPL License #pragma once #include #include #include #include #include #include #include "packet_headers.hpp" #include "../common/linked_list.hpp" #include "../common/packet/packet_struct.hpp" using namespace std; /** * LoginAccount class manages user account data and associated character profiles * Handles authentication, character management, and account operations */ class LoginAccount { public: // Default constructor - initializes account with default values LoginAccount(); // Parameterized constructor - creates account with specified ID, name, and password LoginAccount(int32 id, const char* in_name, const char* in_pass); // Destructor - cleans up all character profiles and allocated memory ~LoginAccount(); // Saves account data to persistent storage bool SaveAccount(LoginAccount* acct); // Vector containing all character profiles associated with this account vector charlist; // Sets the account name from C-string input void setName(const char* in_name) { strcpy(name, in_name); } // Sets the account password from C-string input void setPassword(const char* in_pass) { strcpy(password, in_pass); } // Sets the authentication status for this account void setAuthenticated(bool in_auth) { authenticated = in_auth; } // Sets the unique account identifier void setAccountID(int32 id) { account_id = id; } // Adds a character profile to the account's character list void addCharacter(CharSelectProfile* profile) { charlist.push_back(profile); } // Removes character by PacketStruct profile reference void removeCharacter(PacketStruct* profile); // Removes character by name with version-specific handling void removeCharacter(char* name, int16 version); // Serializes character data into provided buffer for network transmission void serializeCharacter(uchar* buffer, CharSelectProfile* profile); // Removes and deallocates all character profiles from the account void flushCharacters(); // Retrieves character profile by name, returns nullptr if not found CharSelectProfile* getCharacter(char* name); // Returns the unique account identifier int32 getLoginAccountID() { return account_id; } // Returns pointer to account name string char* getLoginName() { return name; } // Returns pointer to account password string char* getLoginPassword() { return password; } // Returns current authentication status bool getLoginAuthenticated() { return authenticated; } private: int32 account_id; // Unique identifier for this account char name[32]; // Account name (limited to 31 characters + null terminator) char password[32]; // Account password (limited to 31 characters + null terminator) bool authenticated; // Current authentication state }; // Default constructor implementation - initializes account with default values inline LoginAccount::LoginAccount() { account_id = 0; memset(name, 0, sizeof(name)); memset(password, 0, sizeof(password)); authenticated = false; } // Parameterized constructor implementation - sets up account with provided credentials inline LoginAccount::LoginAccount(int32 id, const char* in_name, const char* in_pass) { account_id = id; strcpy(name, in_name); strcpy(password, in_pass); authenticated = false; } // Destructor implementation - properly cleans up all character profiles inline LoginAccount::~LoginAccount() { for(auto iter = charlist.begin(); iter != charlist.end(); iter++) { delete(*iter); // Clean up character profile memory } } // Removes and deallocates all character profiles from memory inline void LoginAccount::flushCharacters() { for(auto iter = charlist.begin(); iter != charlist.end(); iter++) { delete(*iter); // Clean up each character profile } charlist.clear(); // Clear the vector } // Searches for and returns character profile by name inline CharSelectProfile* LoginAccount::getCharacter(char* name) { CharSelectProfile* profile = nullptr; EQ2_16BitString temp; // Iterate through character list to find matching name for(auto char_iterator = charlist.begin(); char_iterator != charlist.end(); char_iterator++) { profile = *char_iterator; temp = profile->packet->getType_EQ2_16BitString_ByName("name"); if(strcmp(temp.data.c_str(), name) == 0) return profile; // Return matching profile } return nullptr; // Character not found } // Removes character from account by name with client version handling inline void LoginAccount::removeCharacter(char* name, int16 version) { CharSelectProfile* profile = nullptr; EQ2_16BitString temp; // Search for character with matching name for(auto iter = charlist.begin(); iter != charlist.end(); iter++) { profile = *iter; temp = profile->packet->getType_EQ2_16BitString_ByName("name"); if(strcmp(temp.data.c_str(), name) == 0) { if(version <= 561) { profile->deleted = true; // Workaround for character select crash on legacy clients } else { delete(*iter); // Clean up memory charlist.erase(iter); // Remove from vector } return; } } }