Server sends character create & delete messages
This commit is contained in:
@@ -243,6 +243,14 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
HandleRegionContent(static_cast<RegionPacket*>(argPacket));
|
HandleRegionContent(static_cast<RegionPacket*>(argPacket));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//character management
|
||||||
|
case SerialPacketType::CHARACTER_CREATE:
|
||||||
|
HandleCharacterCreate(static_cast<CharacterPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
case SerialPacketType::CHARACTER_DELETE:
|
||||||
|
HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
|
||||||
//rejection messages
|
//rejection messages
|
||||||
case SerialPacketType::REGION_REJECTION:
|
case SerialPacketType::REGION_REJECTION:
|
||||||
case SerialPacketType::CHARACTER_REJECTION:
|
case SerialPacketType::CHARACTER_REJECTION:
|
||||||
@@ -377,3 +385,13 @@ void InWorld::UpdateMap() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InWorld::HandleCharacterCreate(CharacterPacket* const argPacket) {
|
||||||
|
//TODO: HandleCharacterCreate()
|
||||||
|
std::cout << "HandleCharacterCreate" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||||
|
//TODO: HandleCharacterDelete()
|
||||||
|
std::cout << "HandleCharacterDelete" << std::endl;
|
||||||
|
}
|
||||||
@@ -91,6 +91,10 @@ protected:
|
|||||||
void HandleRegionContent(RegionPacket* const);
|
void HandleRegionContent(RegionPacket* const);
|
||||||
void UpdateMap();
|
void UpdateMap();
|
||||||
|
|
||||||
|
//character management
|
||||||
|
void HandleCharacterCreate(CharacterPacket* const);
|
||||||
|
void HandleCharacterDelete(CharacterPacket* const);
|
||||||
|
|
||||||
//indexes
|
//indexes
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
|
|||||||
@@ -104,11 +104,7 @@ private:
|
|||||||
//utility methods
|
//utility methods
|
||||||
void PumpPacket(SerialPacket* const);
|
void PumpPacket(SerialPacket* const);
|
||||||
void PumpPacketProximity(SerialPacket* const, int roomIndex, int x, int y, int radius);
|
void PumpPacketProximity(SerialPacket* const, int roomIndex, int x, int y, int radius);
|
||||||
|
void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
|
||||||
//utility methods
|
|
||||||
// void CleanupLostConnection(int index);
|
|
||||||
// void PumpCharacterUnload(int uid);
|
|
||||||
// void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
|
|
||||||
|
|
||||||
//APIs and utilities
|
//APIs and utilities
|
||||||
sqlite3* database = nullptr;
|
sqlite3* database = nullptr;
|
||||||
|
|||||||
+16
-6
@@ -92,10 +92,11 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//send this character to the player
|
//pump this character to all clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
|
CopyCharacterToPacket(&newPacket, characterIndex);
|
||||||
newPacket.type = SerialPacketType::CHARACTER_CREATE;
|
newPacket.type = SerialPacketType::CHARACTER_CREATE;
|
||||||
//TODO: pump character load
|
PumpPacket(&newPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||||
@@ -135,7 +136,11 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
|
|||||||
//delete the character
|
//delete the character
|
||||||
characterMgr.Delete(characterIndex);
|
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) {
|
void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) {
|
||||||
@@ -161,10 +166,11 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//send this character to the player
|
//pump this character to all clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
|
CopyCharacterToPacket(&newPacket, characterIndex);
|
||||||
newPacket.type = SerialPacketType::CHARACTER_CREATE;
|
newPacket.type = SerialPacketType::CHARACTER_CREATE;
|
||||||
//TODO: pump character load
|
PumpPacket(&newPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) {
|
void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket) {
|
||||||
@@ -193,5 +199,9 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket)
|
|||||||
//unload the character
|
//unload the character
|
||||||
characterMgr.Unload(argPacket->characterIndex);
|
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));
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,13 @@ void ServerApplication::Proc() {
|
|||||||
//find and unload the characters associated with this account
|
//find and unload the characters associated with this account
|
||||||
characterMgr.UnloadIf([&](std::pair<const int, CharacterData> character) -> bool {
|
characterMgr.UnloadIf([&](std::pair<const int, CharacterData> character) -> bool {
|
||||||
if (character.second.GetOwner() == account.first) {
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -169,32 +169,5 @@ void ServerApplication::CleanupLostConnection(int clientIndex) {
|
|||||||
std::cout << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
|
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
|
//TODO: remove this terminate comment
|
||||||
//*/
|
//*/
|
||||||
@@ -51,3 +51,23 @@ void ServerApplication::PumpPacketProximity(SerialPacket* const argPacket, int r
|
|||||||
//send the packet to that client
|
//send the packet to that client
|
||||||
//NOTE: this is perhaps too complex; I write it if I need it
|
//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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user