Wrote PumpPacketProximity, it works

This commit is contained in:
Kayne Ruse
2015-01-13 01:01:46 +11:00
parent cd06ccc1a5
commit 74bf70c44d
3 changed files with 18 additions and 1 deletions
+1
View File
@@ -107,6 +107,7 @@ private:
//utility methods
void PumpPacket(SerialPacket* const);
void PumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position, int distance);
void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
//APIs and utilities
+1 -1
View File
@@ -300,5 +300,5 @@ void ServerApplication::HandleCharacterSetMotion(CharacterPacket* const argPacke
CharacterPacket newPacket;
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
newPacket.type = SerialPacketType::CHARACTER_SET_MOTION;
PumpPacket(&newPacket);
PumpPacketProximity(&newPacket, characterData->GetRoomIndex(), characterData->GetOrigin(), -1);
}
+16
View File
@@ -175,6 +175,22 @@ void ServerApplication::PumpPacket(SerialPacket* const argPacket) {
}
}
void ServerApplication::PumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position, int distance) {
RoomData* room = roomMgr.Get(roomIndex);
if (!room) {
throw(std::runtime_error("Failed to pump to a non-existant room"));
}
for (auto& character : *room->GetCharacterList()) {
if (distance == -1 || (character->GetOrigin() - position).Length() <= distance) {
AccountData* account = accountMgr.Get(character->GetOwner());
ClientData* client = clientMgr.Get(account->GetClientIndex());
network.SendTo(client->GetAddress(), argPacket);
}
}
}
void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
CharacterData* character = characterMgr.Get(characterIndex);
if (!character) {