Created PumpCharacterUnload
This commit is contained in:
@@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS UserAccounts (
|
|||||||
-- password varchar(100),
|
-- password varchar(100),
|
||||||
blacklisted BIT DEFAULT 0,
|
blacklisted BIT DEFAULT 0,
|
||||||
whitelisted BIT DEFAULT 1
|
whitelisted BIT DEFAULT 1
|
||||||
|
-- TODO: moderator
|
||||||
);
|
);
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|||||||
@@ -159,13 +159,14 @@ int ServerApplication::SaveUserAccount(int uid) {
|
|||||||
|
|
||||||
void ServerApplication::UnloadUserAccount(int uid) {
|
void ServerApplication::UnloadUserAccount(int uid) {
|
||||||
//save this user account, and then unload it
|
//save this user account, and then unload it
|
||||||
|
//NOTE: the associated characters are unloaded externally
|
||||||
SaveUserAccount(uid);
|
SaveUserAccount(uid);
|
||||||
accountMap.erase(uid);
|
accountMap.erase(uid);
|
||||||
//TODO: unload this account's characters?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::DeleteUserAccount(int uid) {
|
void ServerApplication::DeleteUserAccount(int uid) {
|
||||||
//delete a user account from the database, and remove it from memory
|
//delete a user account from the database, and remove it from memory
|
||||||
|
//NOTE: the associated characters are unloaded externally
|
||||||
sqlite3_stmt* statement = nullptr;
|
sqlite3_stmt* statement = nullptr;
|
||||||
|
|
||||||
//prep
|
//prep
|
||||||
@@ -185,8 +186,6 @@ void ServerApplication::DeleteUserAccount(int uid) {
|
|||||||
throw( std::runtime_error(std::string() + "Unknown SQL error when deleting an account: " + sqlite3_errmsg(database)) );
|
throw( std::runtime_error(std::string() + "Unknown SQL error when deleting an account: " + sqlite3_errmsg(database)) );
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: delete this account's characters?
|
|
||||||
|
|
||||||
//finish the routine
|
//finish the routine
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
accountMap.erase(uid);
|
accountMap.erase(uid);
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ private:
|
|||||||
|
|
||||||
//TODO: a function that only sends to characters in a certain proximity
|
//TODO: a function that only sends to characters in a certain proximity
|
||||||
void PumpPacket(SerialPacket);
|
void PumpPacket(SerialPacket);
|
||||||
|
void PumpCharacterUnload(int uid);
|
||||||
|
|
||||||
//Account management
|
//Account management
|
||||||
int CreateUserAccount(std::string username, int clientIndex);
|
int CreateUserAccount(std::string username, int clientIndex);
|
||||||
|
|||||||
@@ -113,21 +113,16 @@ void ServerApplication::HandleSynchronize(SerialPacket packet) {
|
|||||||
|
|
||||||
void ServerApplication::HandleDisconnect(SerialPacket packet) {
|
void ServerApplication::HandleDisconnect(SerialPacket packet) {
|
||||||
//TODO: authenticate who is disconnecting/kicking
|
//TODO: authenticate who is disconnecting/kicking
|
||||||
//TODO: define the difference between unloading and deleting a character
|
|
||||||
|
|
||||||
//forward to the specified client
|
//forward to the specified client
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
char buffer[PACKET_BUFFER_SIZE];
|
||||||
serialize(&packet, buffer);
|
serialize(&packet, buffer);
|
||||||
network.Send(&clientMap[accountMap[packet.clientInfo.accountIndex].clientIndex].address, buffer, PACKET_BUFFER_SIZE);
|
network.Send(&clientMap[accountMap[packet.clientInfo.accountIndex].clientIndex].address, buffer, PACKET_BUFFER_SIZE);
|
||||||
|
|
||||||
//delete the server- and client-side character(s)
|
//unload client and server-side characters
|
||||||
SerialPacket delPacket;
|
|
||||||
delPacket.meta.type = SerialPacket::Type::CHARACTER_DELETE;
|
|
||||||
|
|
||||||
for (std::map<int, CharacterData>::iterator it = characterMap.begin(); it != characterMap.end(); /* EMPTY */ ) {
|
for (std::map<int, CharacterData>::iterator it = characterMap.begin(); it != characterMap.end(); /* EMPTY */ ) {
|
||||||
if (it->second.owner == packet.clientInfo.accountIndex) {
|
if (it->second.owner == packet.clientInfo.accountIndex) {
|
||||||
delPacket.characterInfo.characterIndex = it->first;
|
PumpCharacterUnload(it->first);
|
||||||
PumpPacket(delPacket);
|
|
||||||
SaveCharacter(it->first);
|
SaveCharacter(it->first);
|
||||||
it = characterMap.erase(it); //efficient
|
it = characterMap.erase(it); //efficient
|
||||||
continue;
|
continue;
|
||||||
@@ -191,3 +186,11 @@ void ServerApplication::PumpPacket(SerialPacket packet) {
|
|||||||
network.Send(&it.second.address, buffer, PACKET_BUFFER_SIZE);
|
network.Send(&it.second.address, buffer, PACKET_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerApplication::PumpCharacterUnload(int uid) {
|
||||||
|
//delete the client-side character(s)
|
||||||
|
SerialPacket delPacket;
|
||||||
|
delPacket.meta.type = SerialPacket::Type::CHARACTER_DELETE;
|
||||||
|
delPacket.characterInfo.characterIndex = uid;
|
||||||
|
PumpPacket(delPacket);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user