Server sends character create & delete messages

This commit is contained in:
Kayne Ruse
2014-12-11 07:12:16 +11:00
parent dbd1289ced
commit 72f641bf63
7 changed files with 66 additions and 39 deletions
+1 -5
View File
@@ -104,11 +104,7 @@ private:
//utility methods
void PumpPacket(SerialPacket* const);
void PumpPacketProximity(SerialPacket* const, int roomIndex, int x, int y, int radius);
//utility methods
// void CleanupLostConnection(int index);
// void PumpCharacterUnload(int uid);
// void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
//APIs and utilities
sqlite3* database = nullptr;
+16 -6
View File
@@ -92,10 +92,11 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket)
return;
}
//send this character to the player
//pump this character to all clients
CharacterPacket newPacket;
CopyCharacterToPacket(&newPacket, characterIndex);
newPacket.type = SerialPacketType::CHARACTER_CREATE;
//TODO: pump character load
PumpPacket(&newPacket);
}
void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) {
@@ -135,7 +136,11 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
//delete the character
characterMgr.Delete(characterIndex);
//TODO: pump character unload
//pump character delete
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_DELETE;
newPacket.characterIndex = characterIndex;
PumpPacket(static_cast<SerialPacket*>(&newPacket));
}
void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) {
@@ -161,10 +166,11 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) {
return;
}
//send this character to the player
//pump this character to all clients
CharacterPacket newPacket;
CopyCharacterToPacket(&newPacket, characterIndex);
newPacket.type = SerialPacketType::CHARACTER_CREATE;
//TODO: pump character load
PumpPacket(&newPacket);
}
void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) {
@@ -193,5 +199,9 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket)
//unload the character
characterMgr.Unload(argPacket->characterIndex);
//TODO: pump character unload
//pump character delete
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_DELETE;
newPacket.characterIndex = argPacket->characterIndex;
PumpPacket(static_cast<SerialPacket*>(&newPacket));
}
+7 -1
View File
@@ -188,7 +188,13 @@ void ServerApplication::Proc() {
//find and unload the characters associated with this account
characterMgr.UnloadIf([&](std::pair<const int, CharacterData> character) -> bool {
if (character.second.GetOwner() == account.first) {
// PumpCharacterUnload(character.first);
//pump character delete
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_DELETE;
newPacket.characterIndex = character.first;
PumpPacket(static_cast<SerialPacket*>(&newPacket));
//unload this character
return true;
}
return false;
-27
View File
@@ -169,32 +169,5 @@ void ServerApplication::CleanupLostConnection(int clientIndex) {
std::cout << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
}
//SET: utility/delete
void ServerApplication::PumpCharacterUnload(int uid) {
//delete the client-side character(s)
//NOTE: This is a strange function
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_DELETE;
newPacket.characterIndex = uid;
PumpPacket(static_cast<SerialPacket*>(&newPacket));
}
//SET: utility/delete
void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
CharacterData* character = characterMgr.Get(characterIndex);
if (!character) {
throw(std::runtime_error("Failed to copy a character to a packet"));
}
//TODO: keep this up to date when the character changes
packet->characterIndex = characterIndex;
strncpy(packet->handle, character->GetHandle().c_str(), PACKET_STRING_SIZE);
strncpy(packet->avatar, character->GetAvatar().c_str(), PACKET_STRING_SIZE);
packet->accountIndex = character->GetOwner();
packet->roomIndex = character->GetRoomIndex();
packet->origin = character->GetOrigin();
packet->motion = character->GetMotion();
}
//TODO: remove this terminate comment
//*/
+20
View File
@@ -51,3 +51,23 @@ void ServerApplication::PumpPacketProximity(SerialPacket* const argPacket, int r
//send the packet to that client
//NOTE: this is perhaps too complex; I write it if I need it
}
//-------------------------
//common copy methods
//-------------------------
void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
CharacterData* character = characterMgr.Get(characterIndex);
if (!character) {
throw(std::runtime_error("Failed to copy a character to a packet"));
}
//NOTE: keep this up to date when the character changes
packet->characterIndex = characterIndex;
strncpy(packet->handle, character->GetHandle().c_str(), PACKET_STRING_SIZE);
strncpy(packet->avatar, character->GetAvatar().c_str(), PACKET_STRING_SIZE);
packet->accountIndex = character->GetOwner();
packet->roomIndex = character->GetRoomIndex();
packet->origin = character->GetOrigin();
packet->motion = character->GetMotion();
}