Created PumpCharacterUnload

This commit is contained in:
Kayne Ruse
2014-05-13 02:51:50 +10:00
parent eeb2400e79
commit 68475eee0f
4 changed files with 14 additions and 10 deletions
+2 -3
View File
@@ -159,13 +159,14 @@ int ServerApplication::SaveUserAccount(int uid) {
void ServerApplication::UnloadUserAccount(int uid) {
//save this user account, and then unload it
//NOTE: the associated characters are unloaded externally
SaveUserAccount(uid);
accountMap.erase(uid);
//TODO: unload this account's characters?
}
void ServerApplication::DeleteUserAccount(int uid) {
//delete a user account from the database, and remove it from memory
//NOTE: the associated characters are unloaded externally
sqlite3_stmt* statement = nullptr;
//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)) );
}
//TODO: delete this account's characters?
//finish the routine
sqlite3_finalize(statement);
accountMap.erase(uid);
+1
View File
@@ -75,6 +75,7 @@ private:
//TODO: a function that only sends to characters in a certain proximity
void PumpPacket(SerialPacket);
void PumpCharacterUnload(int uid);
//Account management
int CreateUserAccount(std::string username, int clientIndex);
+10 -7
View File
@@ -113,21 +113,16 @@ void ServerApplication::HandleSynchronize(SerialPacket packet) {
void ServerApplication::HandleDisconnect(SerialPacket packet) {
//TODO: authenticate who is disconnecting/kicking
//TODO: define the difference between unloading and deleting a character
//forward to the specified client
char buffer[PACKET_BUFFER_SIZE];
serialize(&packet, buffer);
network.Send(&clientMap[accountMap[packet.clientInfo.accountIndex].clientIndex].address, buffer, PACKET_BUFFER_SIZE);
//delete the server- and client-side character(s)
SerialPacket delPacket;
delPacket.meta.type = SerialPacket::Type::CHARACTER_DELETE;
//unload client and server-side characters
for (std::map<int, CharacterData>::iterator it = characterMap.begin(); it != characterMap.end(); /* EMPTY */ ) {
if (it->second.owner == packet.clientInfo.accountIndex) {
delPacket.characterInfo.characterIndex = it->first;
PumpPacket(delPacket);
PumpCharacterUnload(it->first);
SaveCharacter(it->first);
it = characterMap.erase(it); //efficient
continue;
@@ -191,3 +186,11 @@ void ServerApplication::PumpPacket(SerialPacket packet) {
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);
}