1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:53:51 +00:00

[Server] Use static WorldEvent variable in Networking

This commit is contained in:
David Cernat 2017-01-29 10:24:12 +02:00
parent 08faad9f32
commit 2cecce6c72
2 changed files with 52 additions and 46 deletions

View file

@ -21,6 +21,8 @@ using namespace std;
Networking *Networking::sThis = 0; Networking *Networking::sThis = 0;
static WorldEvent *worldEvent;
Networking::Networking(RakNet::RakPeerInterface *peer) Networking::Networking(RakNet::RakPeerInterface *peer)
{ {
sThis = this; sThis = this;
@ -415,7 +417,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
return; return;
WorldPacket *myPacket = worldController->GetPacket(packet->data[0]); WorldPacket *myPacket = worldController->GetPacket(packet->data[0]);
WorldEvent *event = new WorldEvent(player->guid); worldEvent = new WorldEvent(player->guid);
mwmp::WorldObject worldObject; mwmp::WorldObject worldObject;
switch (packet->data[0]) switch (packet->data[0])
@ -426,18 +428,18 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_PLACE from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_PLACE from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
for (unsigned int i = 0; i < event->objectChanges.count; i++) for (unsigned int i = 0; i < worldEvent->objectChanges.count; i++)
{ {
worldObject = event->objectChanges.objects[i]; worldObject = worldEvent->objectChanges.objects[i];
Script::Call<Script::CallbackIdentity("OnObjectPlace")>( Script::Call<Script::CallbackIdentity("OnObjectPlace")>(
player->getId(), player->getId(),
worldObject.refId.c_str(), worldObject.refId.c_str(),
(int)worldObject.refNumIndex, (int)worldObject.refNumIndex,
event->cell.getDescription().c_str()); worldEvent->cell.getDescription().c_str());
} }
break; break;
@ -448,20 +450,20 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_DELETE from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_DELETE from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
ESM::CellRef cellRef; ESM::CellRef cellRef;
for (unsigned int i = 0; i < event->objectChanges.count; i++) for (unsigned int i = 0; i < worldEvent->objectChanges.count; i++)
{ {
worldObject = event->objectChanges.objects[i]; worldObject = worldEvent->objectChanges.objects[i];
Script::Call<Script::CallbackIdentity("OnObjectDelete")>( Script::Call<Script::CallbackIdentity("OnObjectDelete")>(
player->getId(), player->getId(),
worldObject.refId.c_str(), worldObject.refId.c_str(),
(int)worldObject.refNumIndex, (int)worldObject.refNumIndex,
event->cell.getDescription().c_str()); worldEvent->cell.getDescription().c_str());
} }
break; break;
@ -472,8 +474,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_LOCK from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_LOCK from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -483,8 +485,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_UNLOCK from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_UNLOCK from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -494,8 +496,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_SCALE from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_SCALE from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -505,8 +507,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_MOVE from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_MOVE from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -516,8 +518,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_ROTATE from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_ROTATE from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -527,8 +529,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_ANIM_PLAY from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_OBJECT_ANIM_PLAY from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -538,8 +540,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_CONTAINER_ADD from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_CONTAINER_ADD from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -549,8 +551,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_CONTAINER_REMOVE from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_CONTAINER_REMOVE from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -560,8 +562,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_DOOR_ACTIVATE from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_DOOR_ACTIVATE from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -571,8 +573,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_SHORT from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_SHORT from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -582,8 +584,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_FLOAT from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_LOCAL_FLOAT from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -593,8 +595,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_MEMBER_SHORT from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_MEMBER_SHORT from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -604,8 +606,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_GLOBAL_SHORT from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_GLOBAL_SHORT from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -615,8 +617,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_MUSIC_PLAY from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_MUSIC_PLAY from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -626,8 +628,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_VIDEO_PLAY from %s", LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_VIDEO_PLAY from %s",
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->Read(event); myPacket->Read(worldEvent);
myPacket->Send(event, true); myPacket->Send(worldEvent, true);
break; break;
} }
@ -718,8 +720,6 @@ void Networking::newPlayer(RakNet::RakNetGUID guid)
} }
void Networking::disconnectPlayer(RakNet::RakNetGUID guid) void Networking::disconnectPlayer(RakNet::RakNetGUID guid)
{ {
Player *player = Players::getPlayer(guid); Player *player = Players::getPlayer(guid);
@ -740,6 +740,11 @@ WorldPacketController *Networking::getWorldController() const
return worldController; return worldController;
} }
WorldEvent *Networking::getLastEvent()
{
return worldEvent;
}
const Networking &Networking::get() const Networking &Networking::get()
{ {
return *sThis; return *sThis;

View file

@ -36,6 +36,7 @@ namespace mwmp
PlayerPacketController *getPlayerController() const; PlayerPacketController *getPlayerController() const;
WorldPacketController *getWorldController() const; WorldPacketController *getWorldController() const;
WorldEvent *getLastEvent();
MasterClient *getMasterClient(); MasterClient *getMasterClient();
void InitQuery(std::string queryAddr, unsigned short queryPort, std::string serverAddr, unsigned short serverPort); void InitQuery(std::string queryAddr, unsigned short queryPort, std::string serverAddr, unsigned short serverPort);