diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index b78c16642..637ed49ce 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -26,9 +26,12 @@ Networking::Networking(RakNet::RakPeerInterface *peer) this->peer = peer; players = Players::GetPlayers(); - controller = new PacketsController(peer); + playerController = new PlayerPacketController(peer); + worldController = new WorldPacketController(peer); - controller->SetStream(0, &bsOut); // set send stream + // Set send stream + playerController->SetStream(0, &bsOut); + worldController->SetStream(0, &bsOut); running = true; exitCode = 0; @@ -41,39 +44,18 @@ Networking::~Networking() Script::Call(false); sThis = 0; - delete controller; + delete playerController; LOG_QUIT(); } -void Networking::Update(RakNet::Packet *packet) +void Networking::ProcessPlayerPacket(RakNet::Packet *packet) { - Player *player = Players::GetPlayer(packet->guid); - RakNet::BitStream bsIn(&packet->data[1], packet->length, false); - - { - RakNet::RakNetGUID ignoredGUID; - bsIn.Read(ignoredGUID); - (void)ignoredGUID; - } - - controller->SetStream(&bsIn, 0); - - if (player == 0) - { - controller->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid); - Players::NewPlayer(packet->guid); - player = Players::GetPlayer(packet->guid); - controller->GetPacket(ID_USER_MYID)->Send(Players::GetPlayer(packet->guid), false); - return; - } - - PlayerPacket *myPacket = controller->GetPacket(packet->data[0]); + PlayerPacket *myPacket = playerController->GetPacket(packet->data[0]); if (packet->data[0] == ID_HANDSHAKE) { - DEBUG_PRINTF("ID_HANDSHAKE\n"); string passw = "SuperPassword"; myPacket->Read(player); @@ -118,7 +100,7 @@ void Networking::Update(RakNet::Packet *packet) if (!result) { - controller->GetPacket(ID_USER_DISCONNECTED)->Send(Players::GetPlayer(packet->guid), false); + playerController->GetPacket(ID_USER_DISCONNECTED)->Send(Players::GetPlayer(packet->guid), false); Players::DeletePlayer(packet->guid); return; } @@ -126,7 +108,7 @@ void Networking::Update(RakNet::Packet *packet) else if (packet->data[0] == ID_GAME_BASE_INFO) { LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_BASE_INFO about %s", - player->Npc()->mName.c_str()); + player->Npc()->mName.c_str()); myPacket->Read(player); myPacket->Send(player, true); @@ -145,264 +127,355 @@ void Networking::Update(RakNet::Packet *packet) { /*case ID_GAME_BASE_INFO: { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_BASE_INFO about %s", - player->Npc()->mName.c_str()); + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_BASE_INFO about %s", + player->Npc()->mName.c_str()); - myPacket->Read(player); - myPacket->Send(player, true); + myPacket->Read(player); + myPacket->Send(player, true); - break; + break; }*/ - case ID_GAME_POS: - { - //DEBUG_PRINTF("ID_GAME_POS \n"); - - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); - myPacket->Send(player, true); //send to other clients - } + case ID_GAME_POS: + { + //DEBUG_PRINTF("ID_GAME_POS \n"); - break; - } - case ID_GAME_CELL: + if (!player->CreatureStats()->mDead) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_CELL from %s", - player->Npc()->mName.c_str()); + myPacket->Read(player); + myPacket->Send(player, true); //send to other clients + } - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); + break; + } + case ID_GAME_CELL: + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_CELL from %s", + player->Npc()->mName.c_str()); - LOG_APPEND(Log::LOG_INFO, "- Moved to %s", - player->GetCell()->getDescription().c_str()); + if (!player->CreatureStats()->mDead) + { + myPacket->Read(player); - myPacket->Send(player, true); //send to other clients - Script::Call(player->GetID()); - } - else - { - LOG_APPEND(Log::LOG_INFO, "- Ignored because %s is dead", - player->Npc()->mName.c_str()); - } + LOG_APPEND(Log::LOG_INFO, "- Moved to %s", + player->GetCell()->getDescription().c_str()); - break; + myPacket->Send(player, true); //send to other clients + Script::Call(player->GetID()); } - case ID_GAME_ATTRIBUTE: + else { + LOG_APPEND(Log::LOG_INFO, "- Ignored because %s is dead", + player->Npc()->mName.c_str()); + } - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); - myPacket->Send(player, true); - - Script::Call(player->GetID()); - } + break; + } + case ID_GAME_ATTRIBUTE: + { - break; - } - case ID_GAME_SKILL: + if (!player->CreatureStats()->mDead) { + myPacket->Read(player); + myPacket->Send(player, true); - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); - myPacket->Send(player, true); + Script::Call(player->GetID()); + } - Script::Call(player->GetID()); - } + break; + } + case ID_GAME_SKILL: + { - break; - } - case ID_GAME_LEVEL: + if (!player->CreatureStats()->mDead) { + myPacket->Read(player); + myPacket->Send(player, true); - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); - myPacket->Send(player, true); + Script::Call(player->GetID()); + } - Script::Call(player->GetID()); - } + break; + } + case ID_GAME_LEVEL: + { - break; - } - case ID_GAME_EQUIPMENT: + if (!player->CreatureStats()->mDead) { - DEBUG_PRINTF("ID_GAME_EQUIPMENT\n"); - myPacket->Read(player); myPacket->Send(player, true); - Script::Call(player->GetID()); - - break; + Script::Call(player->GetID()); } - case ID_GAME_ATTACK: - { - DEBUG_PRINTF("ID_GAME_ATTACK\n"); + break; + } + case ID_GAME_EQUIPMENT: + { + DEBUG_PRINTF("ID_GAME_EQUIPMENT\n"); - if (!player->CreatureStats()->mDead) - { - myPacket->Read(player); + myPacket->Read(player); + myPacket->Send(player, true); + + Script::Call(player->GetID()); + + break; + } - Player *target = Players::GetPlayer(player->GetAttack()->target); + case ID_GAME_ATTACK: + { + DEBUG_PRINTF("ID_GAME_ATTACK\n"); - if (target == nullptr) - target = player; + if (!player->CreatureStats()->mDead) + { + myPacket->Read(player); - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player: %s attaked %s state: %d", player->Npc()->mName.c_str(), - target->Npc()->mName.c_str(), player->GetAttack()->pressed == 1); - if (player->GetAttack()->pressed == 0) + Player *target = Players::GetPlayer(player->GetAttack()->target); + + if (target == nullptr) + target = player; + + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player: %s attaked %s state: %d", player->Npc()->mName.c_str(), + target->Npc()->mName.c_str(), player->GetAttack()->pressed == 1); + if (player->GetAttack()->pressed == 0) + { + LOG_APPEND(Log::LOG_VERBOSE, "success: %d", player->GetAttack()->success == 1); + if (player->GetAttack()->success == 1) { - LOG_APPEND(Log::LOG_VERBOSE, "success: %d", player->GetAttack()->success == 1); - if (player->GetAttack()->success == 1) - { - LOG_APPEND(Log::LOG_VERBOSE, "damage: %d", player->GetAttack()->damage == 1); - player->setLastAttackerID(target->GetID()); - } + LOG_APPEND(Log::LOG_VERBOSE, "damage: %d", player->GetAttack()->damage == 1); + player->setLastAttackerID(target->GetID()); } - - myPacket->Send(player, true); - controller->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(player->GetAttack()->target); } - break; - } - case ID_GAME_DYNAMICSTATS: - { - DEBUG_PRINTF("ID_GAME_DYNAMICSTATS\n"); - myPacket->Read(player); myPacket->Send(player, true); - break; + playerController->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(player->GetAttack()->target); } + break; + } - case ID_GAME_DIE: - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_DIE from %s", - player->Npc()->mName.c_str()); + case ID_GAME_DYNAMICSTATS: + { + DEBUG_PRINTF("ID_GAME_DYNAMICSTATS\n"); + myPacket->Read(player); + myPacket->Send(player, true); + break; + } - Player *killer = Players::GetPlayer(player->getLastAttackerID()); + case ID_GAME_DIE: + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_DIE from %s", + player->Npc()->mName.c_str()); - short reason = 0; // unknown; + Player *killer = Players::GetPlayer(player->getLastAttackerID()); - if (!killer) - killer = player; - else if (killer->GetID() == player->GetID()) - reason = 2; //suicide - else - reason = 1; //killed + short reason = 0; // unknown; - player->resetLastAttacker(); + if (!killer) + killer = player; + else if (killer->GetID() == player->GetID()) + reason = 2; //suicide + else + reason = 1; //killed - player->CreatureStats()->mDead = true; - myPacket->Send(player, true); + player->resetLastAttacker(); - Script::Call(player->GetID(), reason, killer->GetID()); + player->CreatureStats()->mDead = true; + myPacket->Send(player, true); - break; - } + Script::Call(player->GetID(), reason, killer->GetID()); - case ID_GAME_RESURRECT: - { - DEBUG_PRINTF("ID_GAME_RESURRECT\n"); - //packetResurrect.Read(player); - player->CreatureStats()->mDead = false; - myPacket->Send(player, true); - controller->GetPacket(ID_GAME_POS)->RequestData(player->guid); - controller->GetPacket(ID_GAME_CELL)->RequestData(player->guid); + break; + } - Script::Call(player->GetID()); + case ID_GAME_RESURRECT: + { + DEBUG_PRINTF("ID_GAME_RESURRECT\n"); + //packetResurrect.Read(player); + player->CreatureStats()->mDead = false; + myPacket->Send(player, true); + playerController->GetPacket(ID_GAME_POS)->RequestData(player->guid); + playerController->GetPacket(ID_GAME_CELL)->RequestData(player->guid); - break; - } + Script::Call(player->GetID()); + + break; + } - case ID_GAME_DRAWSTATE: + case ID_GAME_DRAWSTATE: + { + DEBUG_PRINTF("ID_GAME_DRAWSTATE\n"); + myPacket->Read(player); + myPacket->Send(player, true); + break; + } + + case ID_CHAT_MESSAGE: + { + DEBUG_PRINTF("ID_CHAT_MESSAGE\n"); + myPacket->Read(player); + Script::CallBackReturn result = true; + Script::Call(result, player->GetID(), player->ChatMessage()->c_str()); + + if (result) { - DEBUG_PRINTF("ID_GAME_DRAWSTATE\n"); - myPacket->Read(player); + *player->ChatMessage() = player->Npc()->mName + " (" + std::to_string(player->GetID()) + "): " + + *player->ChatMessage() + "\n"; + myPacket->Send(player, false); myPacket->Send(player, true); - break; } + break; + } + case ID_GAME_CHARGEN: + { + DEBUG_PRINTF("ID_GAME_CHARGEN\n"); + myPacket->Read(player); - case ID_CHAT_MESSAGE: + if (player->CharGenStage()->current == player->CharGenStage()->end && player->CharGenStage()->current != 0) { - DEBUG_PRINTF("ID_CHAT_MESSAGE\n"); - myPacket->Read(player); - Script::CallBackReturn result = true; - Script::Call(result, player->GetID(), player->ChatMessage()->c_str()); - - if (result) - { - *player->ChatMessage() = player->Npc()->mName + " (" + std::to_string(player->GetID()) + "): " - + *player->ChatMessage() + "\n"; - myPacket->Send(player, false); - myPacket->Send(player, true); - } - break; + Script::Call(player->GetID()); + cout << "RACE: " << player->Npc()->mRace << endl; } - case ID_GAME_CHARGEN: - { - DEBUG_PRINTF("ID_GAME_CHARGEN\n"); - myPacket->Read(player); + break; + } - if (player->CharGenStage()->current == player->CharGenStage()->end && player->CharGenStage()->current != 0) - { - Script::Call(player->GetID()); - cout << "RACE: " << player->Npc()->mRace << endl; - } - break; - } + case ID_GUI_MESSAGEBOX: + { + DEBUG_PRINTF("ID_GUI_MESSAGEBOX\n"); + myPacket->Read(player); - case ID_GUI_MESSAGEBOX: - { - DEBUG_PRINTF("ID_GUI_MESSAGEBOX\n"); - myPacket->Read(player); + Script::Call(player->GetID(), (int)player->guiMessageBox.id, + player->guiMessageBox.data.c_str()); + break; + } - Script::Call(player->GetID(), (int)player->guiMessageBox.id, - player->guiMessageBox.data.c_str()); - break; - } + case ID_GAME_CHARCLASS: + { + DEBUG_PRINTF("ID_GAME_CHARCLASS\n"); + myPacket->Read(player); + break; + } - case ID_GAME_CHARCLASS: - { - DEBUG_PRINTF("ID_GAME_CHARCLASS\n"); - myPacket->Read(player); - break; - } - case ID_GAME_INVENTORY: - { - DEBUG_PRINTF("ID_GAME_INVENTORY\n"); - myPacket->Read(player); - break; - } + case ID_GAME_INVENTORY: + { + DEBUG_PRINTF("ID_GAME_INVENTORY\n"); + myPacket->Read(player); + break; + } - default: - printf("Message with identifier %i has arrived.\n", packet->data[0]); - break; + default: + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled PlayerPacket with identifier %i has arrived", + packet->data[0]); + break; + } +} + +void Networking::ProcessWorldPacket(RakNet::Packet *packet) +{ + Player *player = Players::GetPlayer(packet->guid); + + if (!player->isHandshaked() || player->LoadedState() != Player::POSTLOADED) + return; + + WorldPacket *myPacket = worldController->GetPacket(packet->data[0]); + WorldEvent *event = new WorldEvent(player->guid); + event->cellRef.blank(); + + switch (packet->data[0]) + { + + case ID_WORLD_OBJECT_PLACE: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_PLACE from %s", + player->Npc()->mName.c_str()); + + myPacket->Read(event); + myPacket->Send(event, true); + + break; + } + + case ID_WORLD_OBJECT_DELETE: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_DELETE from %s", + player->Npc()->mName.c_str()); + + myPacket->Read(event); + + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str()); + + myPacket->Send(event, true); + + break; + } + + default: + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled WorldPacket with identifier %i has arrived", + packet->data[0]); + break; + } + +} + +void Networking::Update(RakNet::Packet *packet) +{ + Player *player = Players::GetPlayer(packet->guid); + + RakNet::BitStream bsIn(&packet->data[1], packet->length, false); + + { + RakNet::RakNetGUID ignoredGUID; + bsIn.Read(ignoredGUID); + (void)ignoredGUID; + } + + if (player == 0) + { + playerController->SetStream(&bsIn, 0); + + playerController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid); + Players::NewPlayer(packet->guid); + player = Players::GetPlayer(packet->guid); + playerController->GetPacket(ID_USER_MYID)->Send(Players::GetPlayer(packet->guid), false); + return; + } + else if (playerController->ContainsPacket(packet->data[0])) + { + playerController->SetStream(&bsIn, 0); + ProcessPlayerPacket(packet); + } + else if (worldController->ContainsPacket(packet->data[0])) + { + worldController->SetStream(&bsIn, 0); + ProcessWorldPacket(packet); + } + else + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled Raknet packet with identifier %i has arrived", + packet->data[0]); } } void Networking::NewPlayer(RakNet::RakNetGUID guid) { - controller->GetPacket(ID_GAME_BASE_INFO)->RequestData(guid); - controller->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(guid); - controller->GetPacket(ID_GAME_POS)->RequestData(guid); - controller->GetPacket(ID_GAME_CELL)->RequestData(guid); - controller->GetPacket(ID_GAME_EQUIPMENT)->RequestData(guid); + playerController->GetPacket(ID_GAME_BASE_INFO)->RequestData(guid); + playerController->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(guid); + playerController->GetPacket(ID_GAME_POS)->RequestData(guid); + playerController->GetPacket(ID_GAME_CELL)->RequestData(guid); + playerController->GetPacket(ID_GAME_EQUIPMENT)->RequestData(guid); for (TPlayers::iterator pl = players->begin(); pl != players->end(); pl++) //sending other players to new player { if (pl->first == guid) continue; - controller->GetPacket(ID_GAME_BASE_INFO)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_DYNAMICSTATS)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_ATTRIBUTE)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_SKILL)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_POS)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_CELL)->Send(pl->second, guid); - controller->GetPacket(ID_GAME_EQUIPMENT)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_BASE_INFO)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_DYNAMICSTATS)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_ATTRIBUTE)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_SKILL)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_POS)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_CELL)->Send(pl->second, guid); + playerController->GetPacket(ID_GAME_EQUIPMENT)->Send(pl->second, guid); } } @@ -415,13 +488,18 @@ void Networking::DisconnectPlayer(RakNet::RakNetGUID guid) if (!player) return; Script::Call(player->GetID()); - controller->GetPacket(ID_USER_DISCONNECTED)->Send(player, true); + playerController->GetPacket(ID_USER_DISCONNECTED)->Send(player, true); Players::DeletePlayer(guid); } -PacketsController *Networking::GetController() const +PlayerPacketController *Networking::GetPlayerController() const +{ + return playerController; +} + +WorldPacketController *Networking::GetWorldController() const { - return controller; + return worldController; } const Networking &Networking::Get() @@ -454,31 +532,37 @@ int Networking::MainLoop() switch (packet->data[0]) { case ID_REMOTE_DISCONNECTION_NOTIFICATION: - printf("Another client has disconnected.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Client at %s has disconnected", + packet->systemAddress.ToString()); break; case ID_REMOTE_CONNECTION_LOST: - printf("Another client has lost connection.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Client at %s has lost connection", + packet->systemAddress.ToString()); break; case ID_REMOTE_NEW_INCOMING_CONNECTION: - printf("Another client has connected.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Client at %s has connected", + packet->systemAddress.ToString()); break; case ID_CONNECTION_REQUEST_ACCEPTED: // client to server { - printf("Our connection request has been accepted.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Our connection request has been accepted"); break; } case ID_NEW_INCOMING_CONNECTION: - printf("A connection is incoming.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "A connection is incoming from %s", + packet->systemAddress.ToString()); break; case ID_NO_FREE_INCOMING_CONNECTIONS: - printf("The server is full.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "The server is full"); break; case ID_DISCONNECTION_NOTIFICATION: - printf("A client has disconnected.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Client at %s has disconnected", + packet->systemAddress.ToString()); DisconnectPlayer(packet->guid); break; case ID_CONNECTION_LOST: - printf("A client has lost connection.\n"); + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Client at %s has lost connection", + packet->systemAddress.ToString()); DisconnectPlayer(packet->guid); break; default: diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 04399d69a..afba73f49 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -5,7 +5,8 @@ #ifndef OPENMW_NETWORKING_HPP #define OPENMW_NETWORKING_HPP -#include +#include +#include #include "Player.hpp" namespace mwmp @@ -19,7 +20,11 @@ namespace mwmp void NewPlayer(RakNet::RakNetGUID guid); void DisconnectPlayer(RakNet::RakNetGUID guid); void KickPlayer(RakNet::RakNetGUID guid); + + void ProcessPlayerPacket(RakNet::Packet *packet); + void ProcessWorldPacket(RakNet::Packet *packet); void Update(RakNet::Packet *packet); + unsigned short NumberOfConnections() const; unsigned int MaxConnections() const; @@ -27,7 +32,9 @@ namespace mwmp void StopServer(int code); - PacketsController *GetController() const; + PlayerPacketController *GetPlayerController() const; + WorldPacketController *GetWorldController() const; + static const Networking &Get(); static Networking *GetPtr(); @@ -37,7 +44,8 @@ namespace mwmp RakNet::BitStream bsOut; TPlayers *players; - PacketsController *controller; + PlayerPacketController *playerController; + WorldPacketController *worldController; bool running; int exitCode; diff --git a/apps/openmw-mp/Script/Functions/CharClass.cpp b/apps/openmw-mp/Script/Functions/CharClass.cpp index 5bb7cd81b..42dc6a911 100644 --- a/apps/openmw-mp/Script/Functions/CharClass.cpp +++ b/apps/openmw-mp/Script/Functions/CharClass.cpp @@ -15,7 +15,7 @@ void CharClassFunctions::SendClass(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CHARCLASS)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_CHARCLASS)->Send(player, false); } void CharClassFunctions::SetDefaultClass(unsigned short pid, const char *id) noexcept diff --git a/apps/openmw-mp/Script/Functions/Chat.cpp b/apps/openmw-mp/Script/Functions/Chat.cpp index f7b878aeb..07c0c3783 100644 --- a/apps/openmw-mp/Script/Functions/Chat.cpp +++ b/apps/openmw-mp/Script/Functions/Chat.cpp @@ -15,9 +15,9 @@ void ScriptFunctions::SendMessage(unsigned short pid, const char *message, bool DEBUG_PRINTF("System: %s", message); - mwmp::Networking::Get().GetController()->GetPacket(ID_CHAT_MESSAGE)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_CHAT_MESSAGE)->Send(player, false); if (broadcast) - mwmp::Networking::Get().GetController()->GetPacket(ID_CHAT_MESSAGE)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_CHAT_MESSAGE)->Send(player, true); } void ScriptFunctions::CleanChat(unsigned short pid) diff --git a/apps/openmw-mp/Script/Functions/GUI.cpp b/apps/openmw-mp/Script/Functions/GUI.cpp index f613883d9..3e7146ede 100644 --- a/apps/openmw-mp/Script/Functions/GUI.cpp +++ b/apps/openmw-mp/Script/Functions/GUI.cpp @@ -18,7 +18,7 @@ void GUIFunctions::_MessageBox(unsigned short pid, int id, const char *label) no player->guiMessageBox.label = label; player->guiMessageBox.type = Player::GUIMessageBox::MessageBox; - mwmp::Networking::Get().GetController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); } void GUIFunctions::CustomMessageBox(unsigned short pid, int id, const char *label, const char *buttons) noexcept @@ -31,7 +31,7 @@ void GUIFunctions::CustomMessageBox(unsigned short pid, int id, const char *labe player->guiMessageBox.buttons = buttons; player->guiMessageBox.type = Player::GUIMessageBox::CustomMessageBox; - mwmp::Networking::Get().GetController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); } void GUIFunctions::InputDialog(unsigned short pid, int id, const char *label) noexcept @@ -43,7 +43,7 @@ void GUIFunctions::InputDialog(unsigned short pid, int id, const char *label) no player->guiMessageBox.label = label; player->guiMessageBox.type = Player::GUIMessageBox::InputDialog; - mwmp::Networking::Get().GetController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); } void GUIFunctions::SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index 8b3a0ae44..50e581147 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -114,8 +114,8 @@ void ItemFunctions::SendEquipment(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_EQUIPMENT)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_EQUIPMENT)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_EQUIPMENT)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_EQUIPMENT)->Send(player, true); } void ItemFunctions::SendInventory(unsigned short pid) noexcept diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 7a7131f5d..018d18646 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -454,14 +454,14 @@ void StatsFunctions::SetCharGenStage(unsigned short pid, int start, int end) noe player->CharGenStage()->current = start; player->CharGenStage()->end = end; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CHARGEN)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_CHARGEN)->Send(player, false); } void StatsFunctions::Resurrect(unsigned short pid) { Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_RESURRECT)->RequestData(player->guid); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_RESURRECT)->RequestData(player->guid); } void StatsFunctions::SendBaseInfo(unsigned short pid) noexcept @@ -469,16 +469,16 @@ void StatsFunctions::SendBaseInfo(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_BASE_INFO)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_BASE_INFO)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_BASE_INFO)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_BASE_INFO)->Send(player, true); } void StatsFunctions::SendDynamicStats(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(player, true); } void StatsFunctions::SendAttributes(unsigned short pid) noexcept @@ -486,8 +486,8 @@ void StatsFunctions::SendAttributes(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_ATTRIBUTE)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_ATTRIBUTE)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_ATTRIBUTE)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_ATTRIBUTE)->Send(player, true); } void StatsFunctions::SendSkills(unsigned short pid) noexcept @@ -495,8 +495,8 @@ void StatsFunctions::SendSkills(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_SKILL)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_SKILL)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_SKILL)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_SKILL)->Send(player, true); } void StatsFunctions::SendLevel(unsigned short pid) noexcept @@ -504,6 +504,6 @@ void StatsFunctions::SendLevel(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_LEVEL)->Send(player, false); - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_LEVEL)->Send(player, true); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_LEVEL)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_LEVEL)->Send(player, true); } diff --git a/apps/openmw-mp/Script/Functions/Translocations.cpp b/apps/openmw-mp/Script/Functions/Translocations.cpp index 3c468650e..2fa2964bc 100644 --- a/apps/openmw-mp/Script/Functions/Translocations.cpp +++ b/apps/openmw-mp/Script/Functions/Translocations.cpp @@ -58,7 +58,7 @@ void TranslocationFunctions::SetPos(unsigned short pid, double x, double y, doub player->Position()->pos[1] = y; player->Position()->pos[2] = z; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_POS)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_POS)->Send(player, false); } void TranslocationFunctions::SetCell(unsigned short pid, const char *name) noexcept @@ -80,7 +80,7 @@ void TranslocationFunctions::SetCell(unsigned short pid, const char *name) noexc player->GetCell()->mName = name; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_CELL)->Send(player, false); } const char* TranslocationFunctions::GetCell(unsigned short pid) noexcept @@ -108,24 +108,24 @@ void TranslocationFunctions::SetExterior(unsigned short pid, int x, int y) noexc player->GetCell()->mData.mFlags &= ~ESM::Cell::Interior; } - player->GetCell()->mCellId.mIndex.mX = x; - player->GetCell()->mCellId.mIndex.mY = y; + player->GetCell()->mData.mX = x; + player->GetCell()->mData.mY = y; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_CELL)->Send(player, false); } int TranslocationFunctions::GetExteriorX(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player,0); - return player->GetCell()->mCellId.mIndex.mX; + return player->GetCell()->mData.mX; } int TranslocationFunctions::GetExteriorY(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player,0); - return player->GetCell()->mCellId.mIndex.mY; + return player->GetCell()->mData.mY; } bool TranslocationFunctions::IsInExterior(unsigned short pid) noexcept @@ -183,5 +183,5 @@ void TranslocationFunctions::SetAngle(unsigned short pid, double x, double y, do player->Position()->rot[1] = y; player->Position()->rot[2] = z; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_POS)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_POS)->Send(player, false); } diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index 15c22592f..a666fb1cc 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -17,7 +17,7 @@ void WorldFunctions::SetHour(unsigned short pid, double hour) noexcept player->month = -1; player->day = -1; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_TIME)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_TIME)->Send(player, false); } void WorldFunctions::SetMonth(unsigned short pid, int month) noexcept @@ -29,7 +29,7 @@ void WorldFunctions::SetMonth(unsigned short pid, int month) noexcept player->month = month; player->day = -1; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_TIME)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_TIME)->Send(player, false); } @@ -42,5 +42,5 @@ void WorldFunctions::SetDay(unsigned short pid, int day) noexcept player->month = -1; player->day = day; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_TIME)->Send(player, false); + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GAME_TIME)->Send(player, false); } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index d8f5e57a0..97c193a57 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -551,7 +551,7 @@ namespace MWClass void Npc::hit(const MWWorld::Ptr& ptr, float attackStrength, int type) const { - if(mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) + if (mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) return; MWBase::World *world = MWBase::Environment::get().getWorld(); @@ -594,16 +594,16 @@ namespace MWClass float hitchance = MWMechanics::getHitChance(ptr, victim, ptr.getClass().getSkill(ptr, weapskill)); - if(ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) + if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) { mwmp::Main::get().getLocalPlayer()->GetAttack()->success = true; - if(mwmp::Main::get().getNetworking()->isDedicatedPlayer(victim)) + if (mwmp::Main::get().getNetworking()->isDedicatedPlayer(victim)) mwmp::Main::get().getLocalPlayer()->GetAttack()->target =mwmp::Players::GetPlayer(victim)->guid; } if(Misc::Rng::roll0to99() >= hitchance) { - if(ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) + if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) { mwmp::Main::get().getLocalPlayer()->GetAttack()->success = false; mwmp::Main::get().getLocalPlayer()->sendAttack(0); @@ -843,7 +843,7 @@ namespace MWClass } - if(attacker == MWMechanics::getPlayer() && mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) + if (attacker == MWMechanics::getPlayer() && mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) { mwmp::Attack *_atk = mwmp::Main::get().getLocalPlayer()->GetAttack(); _atk->damage = damage; @@ -853,7 +853,7 @@ namespace MWClass mwmp::Main::get().getLocalPlayer()->sendAttack(0); // todo: make this sensitive to different weapon types } - if(ptr == MWMechanics::getPlayer()) + if (ptr == MWMechanics::getPlayer()) { mwmp::Main::get().getLocalPlayer()->updateDynamicStats(true); mwmp::Main::get().getLocalPlayer()->updatePosition(true); // fix position after getting damage; @@ -863,7 +863,7 @@ namespace MWClass boost::shared_ptr Npc::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const { - if(actor == MWMechanics::getPlayer() && mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) + if (actor == MWMechanics::getPlayer() && mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) return boost::shared_ptr(new MWWorld::FailedAction("Not implemented.")); // player got activated by another NPC if(ptr == MWMechanics::getPlayer()) diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index b5c8dc8bb..09f610d98 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -1,5 +1,9 @@ #include "hud.hpp" +#include +#include "../mwmp/Main.hpp" +#include "../mwworld/cellstore.hpp" + #include #include #include @@ -51,6 +55,18 @@ namespace MWGui if (setNewOwner) dropped.getCellRef().setOwner(""); + // Added by tes3mp + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->cell = *dropped.getCell()->getCell(); + event->cellRef.mRefID = dropped.getCellRef().getRefId(); + event->cellRef.mRefNum = dropped.getCellRef().getRefNum(); + event->cellRef.mPos = dropped.getCellRef().getPosition(); + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_PLACE)->Send(event); + + printf("Sending ID_WORLD_OBJECT_PLACE about %s\n%i\n", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex); + return dropped; } diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 5b6e762a0..5eb9adf87 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1039,7 +1039,7 @@ namespace MWMechanics mwmp::Main::get().getLocalPlayer()->prepareAttack(2, state); } - if(mwmp::Main::get().getNetworking()->isDedicatedPlayer(iter->first)) + if (mwmp::Main::get().getNetworking()->isDedicatedPlayer(iter->first)) iter->second->getCharacterController()->setAttackingOrSpell(mwmp::Main::get().getNetworking()->Attack(iter->first)); diff --git a/apps/openmw/mwmechanics/combat.cpp b/apps/openmw/mwmechanics/combat.cpp index 9a3282f47..ddc4af4cb 100644 --- a/apps/openmw/mwmechanics/combat.cpp +++ b/apps/openmw/mwmechanics/combat.cpp @@ -117,13 +117,13 @@ namespace MWMechanics bool isDedicated = mwmp::Main::get().getNetworking()->isDedicatedPlayer(blocker); - if(attacker == MWMechanics::getPlayer()) + if (attacker == MWMechanics::getPlayer()) mwmp::Main::get().getLocalPlayer()->GetAttack()->block = false; - if((!isDedicated && Misc::Rng::roll0to99() < x) || + if ((!isDedicated && Misc::Rng::roll0to99() < x) || (isDedicated && mwmp::Players::GetPlayer(blocker)->GetAttack()->block == 1)) { - if(attacker == MWMechanics::getPlayer()) + if (attacker == MWMechanics::getPlayer()) mwmp::Main::get().getLocalPlayer()->GetAttack()->block = true; // Reduce shield durability by incoming damage @@ -180,7 +180,7 @@ namespace MWMechanics void projectileHit(const MWWorld::Ptr &attacker, const MWWorld::Ptr &victim, MWWorld::Ptr weapon, const MWWorld::Ptr &projectile, const osg::Vec3f& hitPosition, float attackStrength) { - if(mwmp::Main::get().getNetworking()->isDedicatedPlayer(attacker)) + if (mwmp::Main::get().getNetworking()->isDedicatedPlayer(attacker)) return; MWBase::World *world = MWBase::Environment::get().getWorld(); const MWWorld::Store &gmst = world->getStore().get(); @@ -202,7 +202,7 @@ namespace MWMechanics int skillValue = attacker.getClass().getSkill(attacker, weapon.getClass().getEquipmentSkill(weapon)); - if(attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) + if (attacker == MWBase::Environment::get().getWorld()->getPlayerPtr()) mwmp::Main::get().getLocalPlayer()->GetAttack()->success = true; if (Misc::Rng::roll0to99() >= getHitChance(attacker, victim, skillValue)) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 9aee1d00f..a5c4176eb 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -799,13 +799,13 @@ namespace MWMechanics bool isDedicated = mwmp::Main::get().getNetworking()->isDedicatedPlayer(mCaster); - if(mCaster == getPlayer()) + if (mCaster == getPlayer()) { mwmp::Main::get().getLocalPlayer()->GetAttack()->success = true; mwmp::Main::get().getLocalPlayer()->GetAttack()->pressed = true; } - if(isDedicated) + if (isDedicated) { mwmp::Players::GetPlayer(mCaster)->GetAttack()->pressed = false; } @@ -821,7 +821,7 @@ namespace MWMechanics fail = true; } - if(mCaster == getPlayer()) + if (mCaster == getPlayer()) { mwmp::Main::get().getLocalPlayer()->sendAttack(1); mwmp::Main::get().getLocalPlayer()->GetAttack()->pressed = false; diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index c8bca3777..949ea88b2 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -439,7 +439,7 @@ void DedicatedPlayer::updateCell() MWWorld::CellStore *cellStore; if (cell.isExterior() == 1) - cellStore = world->getExterior(cell.mCellId.mIndex.mX, cell.mCellId.mIndex.mY); + cellStore = world->getExterior(cell.mData.mX, cell.mData.mY); else if (!cell.mName.empty()) cellStore = world->getInterior(cell.mName); // Go no further if cell data is invalid diff --git a/apps/openmw/mwmp/GUIChat.cpp b/apps/openmw/mwmp/GUIChat.cpp index c7baa6c0f..865277200 100644 --- a/apps/openmw/mwmp/GUIChat.cpp +++ b/apps/openmw/mwmp/GUIChat.cpp @@ -130,7 +130,7 @@ namespace mwmp *localPlayer->ChatMessage() = str; RakNet::BitStream bs; - networking->GetPacket(ID_CHAT_MESSAGE)->Packet(&bs, localPlayer, true); + networking->GetPlayerPacket(ID_CHAT_MESSAGE)->Packet(&bs, localPlayer, true); networking->SendData(&bs); } diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index 6dc5858d5..a52bb98af 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -126,7 +126,7 @@ void mwmp::GUIController::OnInputBoxDone(MWGui::WindowBase *parWindow) printf("GUIController::OnInputBoxDone: %s.\n",mInputBox->getTextInput().c_str()); Main::get().getLocalPlayer()->guiMessageBox.data = mInputBox->getTextInput(); - Main::get().getNetworking()->GetPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer()); + Main::get().getNetworking()->GetPlayerPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer()); MWBase::Environment::get().getWindowManager()->removeDialog(mInputBox); mInputBox = 0; @@ -168,7 +168,7 @@ void mwmp::GUIController::update(float dt) printf("Pressed: %d\n", pressedButton); calledMessageBox = false; Main::get().getLocalPlayer()->guiMessageBox.data = MyGUI::utility::toString(pressedButton); - Main::get().getNetworking()->GetPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer()); + Main::get().getNetworking()->GetPlayerPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer()); } } diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index f79dd399d..e42dc86ef 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -90,7 +90,7 @@ bool LocalPlayer::charGenThread() // todo: need fix (*BirthSign()) = world->getPlayer().getBirthSign(); LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_BASE_INFO to server with my CharGen info"); - GetNetworking()->GetPacket(ID_GAME_BASE_INFO)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_BASE_INFO)->Send(this); if (CharGenStage()->end != 1) { @@ -99,11 +99,11 @@ bool LocalPlayer::charGenThread() // todo: need fix updateSkills(true); updateLevel(true); sendClass(); - GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_CHARGEN)->Send(this); } CharGenStage()->end = 0; /*RakNet::BitStream bs; - GetNetworking()->GetPacket(ID_GAME_BASE_INFO)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket(ID_GAME_BASE_INFO)->Packet(&bs, this, true); GetNetworking()->SendData(&bs);*/ } @@ -128,7 +128,7 @@ bool LocalPlayer::charGenThread() // todo: need fix windowManager->pushGuiMode(MWGui::GM_Review); break; } - GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_CHARGEN)->Send(this); CharGenStage()->current++; return false; @@ -163,7 +163,7 @@ void LocalPlayer::updateDynamicStats(bool forceUpdate) timer = 0; - GetNetworking()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_DYNAMICSTATS)->Send(this); } } } @@ -185,7 +185,7 @@ void LocalPlayer::updateAttributes(bool forceUpdate) if (isUpdating || forceUpdate) { - GetNetworking()->GetPacket(ID_GAME_ATTRIBUTE)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_ATTRIBUTE)->Send(this); } } @@ -221,7 +221,7 @@ void LocalPlayer::updateSkills(bool forceUpdate) if (isUpdating || forceUpdate) { NpcStats()->mLevelProgress = ptrNpcStats.getLevelProgress(); - GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_SKILL)->Send(this); } } @@ -233,7 +233,7 @@ void LocalPlayer::updateLevel(bool forceUpdate) if (ptrNpcStats.getLevel() != CreatureStats()->mLevel || forceUpdate) { CreatureStats()->mLevel = ptrNpcStats.getLevel(); - GetNetworking()->GetPacket(ID_GAME_LEVEL)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_LEVEL)->Send(this); // Also update skills to refresh level progress and attribute bonuses // for next level up @@ -273,7 +273,7 @@ void LocalPlayer::updatePosition(bool forceUpdate) Dir()->pos[1] = move.mPosition[1]; Dir()->pos[2] = move.mPosition[2]; - GetNetworking()->GetPacket(ID_GAME_POS)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_POS)->Send(this); } else if (isJumping && world->isOnGround(player)) { @@ -285,7 +285,7 @@ void LocalPlayer::updatePosition(bool forceUpdate) { sentJumpEnd = true; (*Position()) = ptrPos; - GetNetworking()->GetPacket(ID_GAME_POS)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_POS)->Send(this); } } @@ -309,11 +309,11 @@ void LocalPlayer::updateCell(bool forceUpdate) } else if (ptrCell->isExterior()) { - if (ptrCell->mCellId.mIndex.mX != GetCell()->mCellId.mIndex.mX) + if (ptrCell->mData.mX != GetCell()->mData.mX) { shouldUpdate = true; } - else if (ptrCell->mCellId.mIndex.mY != GetCell()->mCellId.mIndex.mY) + else if (ptrCell->mData.mY != GetCell()->mData.mY) { shouldUpdate = true; } @@ -334,7 +334,7 @@ void LocalPlayer::updateCell(bool forceUpdate) updatePosition(true); RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_CELL)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_CELL)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); // Also update skill progress @@ -398,7 +398,7 @@ void LocalPlayer::updateEquipped(bool forceUpdate) { RakNet::BitStream bs; bs.ResetWritePointer(); - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_EQUIPMENT)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_EQUIPMENT)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); equipChanged = false; } @@ -508,7 +508,7 @@ void LocalPlayer::updateAttackState(bool forceUpdate) GetAttack()->refid = spell; /*RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); GetNetworking()->SendData(&bs);*/ } else if (state == MWMechanics::DrawState_Weapon) @@ -539,7 +539,7 @@ void LocalPlayer::updateDeadState(bool forceUpdate) { CreatureStats()->mDead = true; RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID)ID_GAME_DIE)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID)ID_GAME_DIE)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); isDead = true; } @@ -606,7 +606,7 @@ void LocalPlayer::updateDrawStateAndFlags(bool forceUpdate) mwmp::Main::get().getLocalPlayer()->updatePosition(true); // fix position after jump; RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_DRAWSTATE)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_DRAWSTATE)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); //timer = 0; } @@ -695,8 +695,8 @@ void LocalPlayer::setCell() world->getPlayer().setTeleported(true); - int x = GetCell()->mCellId.mIndex.mX; - int y = GetCell()->mCellId.mIndex.mY; + int x = GetCell()->mData.mX; + int y = GetCell()->mData.mY; if (GetCell()->isExterior()) { @@ -783,7 +783,7 @@ void LocalPlayer::sendClass() else charClass.mId = cls->mId; - GetNetworking()->GetPacket(ID_GAME_CHARCLASS)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_CHARCLASS)->Send(this); } void LocalPlayer::sendAttack(char type) @@ -801,7 +801,7 @@ void LocalPlayer::sendAttack(char type) GetAttack()->type = type; GetAttack()->pressed = false; RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); } @@ -832,6 +832,6 @@ void LocalPlayer::prepareAttack(char type, bool state) GetAttack()->attacker = guid; RakNet::BitStream bs; - GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); + GetNetworking()->GetPlayerPacket((RakNet::MessageID) ID_GAME_ATTACK)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); } diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index 20c11cb33..8c3ab61fe 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -189,8 +189,8 @@ void Main::UpdateWorld(float dt) const init = false; LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_BASE_INFO to server"); - mNetworking->GetPacket(ID_GAME_BASE_INFO)->Send(getLocalPlayer()); - mNetworking->GetPacket(ID_LOADED)->Send(getLocalPlayer()); + mNetworking->GetPlayerPacket(ID_GAME_BASE_INFO)->Send(getLocalPlayer()); + mNetworking->GetPlayerPacket(ID_LOADED)->Send(getLocalPlayer()); mLocalPlayer->updateDynamicStats(true); get().getGUIController()->setChatVisible(true); } diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index baa6c36dc..577fb982e 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -18,13 +18,14 @@ #include "../mwstate/statemanagerimp.hpp" #include #include +#include #include "DedicatedPlayer.hpp" #include "Main.hpp" using namespace std; using namespace mwmp; -Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), controller(peer) +Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), playerController(peer), worldController(peer) { RakNet::SocketDescriptor sd; @@ -32,7 +33,9 @@ Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), control RakNet::StartupResult b = peer->Startup(1,&sd, 1); RakAssert(b==RAKNET_STARTED); - controller.SetStream(0, &bsOut); + playerController.SetStream(0, &bsOut); + worldController.SetStream(0, &bsOut); + connected = 0; } @@ -163,13 +166,9 @@ void Networking::Connect(const std::string &ip, unsigned short port) } } -void Networking::ReceiveMessage(RakNet::Packet *packet) +void Networking::ProcessPlayerPacket(RakNet::Packet *packet) { RakNet::RakNetGUID id; - - if (packet->length < 2) - return; - RakNet::BitStream bsIn(&packet->data[1], packet->length, false); bsIn.Read(id); @@ -178,499 +177,583 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) if (id != myid) pl = Players::GetPlayer(id); - PlayerPacket *myPacket = controller.GetPacket(packet->data[0]); + PlayerPacket *myPacket = playerController.GetPacket(packet->data[0]); switch (packet->data[0]) { - case ID_HANDSHAKE: - { - (*getLocalPlayer()->GetPassw()) = "SuperPassword"; - myPacket->Send(getLocalPlayer(), serverAddr); - break; - } - case ID_GAME_BASE_INFO: + case ID_HANDSHAKE: + { + (*getLocalPlayer()->GetPassw()) = "SuperPassword"; + myPacket->Send(getLocalPlayer(), serverAddr); + break; + } + case ID_GAME_BASE_INFO: + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_GAME_BASE_INFO from server"); + + if (id == myid) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_GAME_BASE_INFO from server"); + LOG_APPEND(Log::LOG_INFO, "%s", "- Packet was about my id"); - if (id == myid) + if (packet->length == myPacket->headerSize()) { - LOG_APPEND(Log::LOG_INFO, "%s", "- Packet was about my id"); - - if (packet->length == myPacket->headerSize()) - { - LOG_APPEND(Log::LOG_INFO, "%s", "- Requesting info"); - myPacket->Send(getLocalPlayer(), serverAddr); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - LOG_APPEND(Log::LOG_INFO, "%s", "- Updating LocalPlayer"); - getLocalPlayer()->updateChar(); - } + LOG_APPEND(Log::LOG_INFO, "%s", "- Requesting info"); + myPacket->Send(getLocalPlayer(), serverAddr); } else { - LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl == 0 ? "new player" : pl->Npc()->mName.c_str()); - - if (pl == 0) - { - LOG_APPEND(Log::LOG_INFO, "%s", "- Exchanging data with new player"); - pl = Players::NewPlayer(id); - } - - myPacket->Packet(&bsIn, pl, false); - Players::CreatePlayer(id); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + LOG_APPEND(Log::LOG_INFO, "%s", "- Updating LocalPlayer"); + getLocalPlayer()->updateChar(); } - break; } - case ID_GAME_POS: + else { - if (id == myid) + LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl == 0 ? "new player" : pl->Npc()->mName.c_str()); + + if (pl == 0) { - if (packet->length != myPacket->headerSize()) - { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "ID_GAME_POS changed by server"); - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setPosition(); - } - else - getLocalPlayer()->updatePosition(true); + LOG_APPEND(Log::LOG_INFO, "%s", "- Exchanging data with new player"); + pl = Players::NewPlayer(id); } - else if (pl != 0) - myPacket->Packet(&bsIn, pl, false); - break; + + myPacket->Packet(&bsIn, pl, false); + Players::CreatePlayer(id); } - case ID_USER_MYID: + break; + } + case ID_GAME_POS: + { + if (id == myid) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_USER_MYID from server"); - myid = id; - getLocalPlayer()->guid = id; - break; + if (packet->length != myPacket->headerSize()) + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "ID_GAME_POS changed by server"); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setPosition(); + } + else + getLocalPlayer()->updatePosition(true); } - case ID_USER_DISCONNECTED: - { - if (id == myid) - MWBase::Environment::get().getStateManager()->requestQuit(); - else if (pl != 0) - Players::DisconnectPlayer(id); + else if (pl != 0) + myPacket->Packet(&bsIn, pl, false); + break; + } + case ID_USER_MYID: + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_USER_MYID from server"); + myid = id; + getLocalPlayer()->guid = id; + break; + } + case ID_USER_DISCONNECTED: + { + if (id == myid) + MWBase::Environment::get().getStateManager()->requestQuit(); + else if (pl != 0) + Players::DisconnectPlayer(id); - } - case ID_GAME_EQUIPMENT: + } + case ID_GAME_EQUIPMENT: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) { - if (packet->length == myPacket->headerSize()) - { - getLocalPlayer()->updateEquipped(true); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setInventory(); - } + getLocalPlayer()->updateEquipped(true); } - else if (pl != 0) + else { - myPacket->Packet(&bsIn, pl, false); - pl->UpdateInventory(); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setInventory(); } - break; } - case ID_GAME_ATTACK: + else if (pl != 0) + { + myPacket->Packet(&bsIn, pl, false); + pl->UpdateInventory(); + } + break; + } + case ID_GAME_ATTACK: + { + if (pl != 0) { - if (pl != 0) + myPacket->Packet(&bsIn, pl, false); + + //cout << "Player: " << pl->Npc()->mName << " pressed: " << (pl->GetAttack()->pressed == 1) << endl; + if (pl->GetAttack()->pressed == 0) { - myPacket->Packet(&bsIn, pl, false); + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Attack success: %s", + pl->GetAttack()->success ? "true" : "false"); - //cout << "Player: " << pl->Npc()->mName << " pressed: " << (pl->GetAttack()->pressed == 1) << endl; - if (pl->GetAttack()->pressed == 0) + if (pl->GetAttack()->success == 1) { - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Attack success: %s", - pl->GetAttack()->success ? "true" : "false"); - - if (pl->GetAttack()->success == 1) - { - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Damage: %f", - pl->GetAttack()->damage); - } + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Damage: %f", + pl->GetAttack()->damage); } + } - MWMechanics::CreatureStats &stats = pl->getPtr().getClass().getNpcStats(pl->getPtr()); - stats.getSpells().setSelectedSpell(pl->GetAttack()->refid); + MWMechanics::CreatureStats &stats = pl->getPtr().getClass().getNpcStats(pl->getPtr()); + stats.getSpells().setSelectedSpell(pl->GetAttack()->refid); - MWWorld::Ptr victim; - if (pl->GetAttack()->target == getLocalPlayer()->guid) - victim = MWBase::Environment::get().getWorld()->getPlayerPtr(); - else if (Players::GetPlayer(pl->GetAttack()->target) != 0) - victim = Players::GetPlayer(pl->GetAttack()->target)->getPtr(); + MWWorld::Ptr victim; + if (pl->GetAttack()->target == getLocalPlayer()->guid) + victim = MWBase::Environment::get().getWorld()->getPlayerPtr(); + else if (Players::GetPlayer(pl->GetAttack()->target) != 0) + victim = Players::GetPlayer(pl->GetAttack()->target)->getPtr(); - MWWorld::Ptr attacker; - attacker = pl->getPtr(); + MWWorld::Ptr attacker; + attacker = pl->getPtr(); - // Get the weapon used (if hand-to-hand, weapon = inv.end()) - if (*pl->DrawState() == 1) + // Get the weapon used (if hand-to-hand, weapon = inv.end()) + if (*pl->DrawState() == 1) + { + MWWorld::InventoryStore &inv = attacker.getClass().getInventoryStore(attacker); + MWWorld::ContainerStoreIterator weaponslot = inv.getSlot( + MWWorld::InventoryStore::Slot_CarriedRight); + MWWorld::Ptr weapon = ((weaponslot != inv.end()) ? *weaponslot : MWWorld::Ptr()); + if (!weapon.isEmpty() && weapon.getTypeName() != typeid(ESM::Weapon).name()) + weapon = MWWorld::Ptr(); + + if (victim.mRef != 0) { - MWWorld::InventoryStore &inv = attacker.getClass().getInventoryStore(attacker); - MWWorld::ContainerStoreIterator weaponslot = inv.getSlot( - MWWorld::InventoryStore::Slot_CarriedRight); - MWWorld::Ptr weapon = ((weaponslot != inv.end()) ? *weaponslot : MWWorld::Ptr()); - if (!weapon.isEmpty() && weapon.getTypeName() != typeid(ESM::Weapon).name()) - weapon = MWWorld::Ptr(); - - if (victim.mRef != 0) + bool healthdmg; + if (!weapon.isEmpty()) + healthdmg = true; + else { - bool healthdmg; - if (!weapon.isEmpty()) - healthdmg = true; - else - { - MWMechanics::CreatureStats &otherstats = victim.getClass().getCreatureStats(victim); - healthdmg = otherstats.isParalyzed() || otherstats.getKnockedDown(); - } - - if (!weapon.isEmpty()) - MWMechanics::blockMeleeAttack(attacker, victim, weapon, pl->GetAttack()->damage, 1); - pl->getPtr().getClass().onHit(victim, pl->GetAttack()->damage, healthdmg, weapon, attacker, osg::Vec3f(), - pl->GetAttack()->success); + MWMechanics::CreatureStats &otherstats = victim.getClass().getCreatureStats(victim); + healthdmg = otherstats.isParalyzed() || otherstats.getKnockedDown(); } - } - else - { - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "SpellId: %s", - pl->GetAttack()->refid.c_str()); + + if (!weapon.isEmpty()) + MWMechanics::blockMeleeAttack(attacker, victim, weapon, pl->GetAttack()->damage, 1); + pl->getPtr().getClass().onHit(victim, pl->GetAttack()->damage, healthdmg, weapon, attacker, osg::Vec3f(), + pl->GetAttack()->success); } } - break; + else + { + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "SpellId: %s", + pl->GetAttack()->refid.c_str()); + } } - case ID_GAME_DYNAMICSTATS: + break; + } + case ID_GAME_DYNAMICSTATS: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) { - if (packet->length == myPacket->headerSize()) - { - getLocalPlayer()->updateDynamicStats(true); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setDynamicStats(); - } + getLocalPlayer()->updateDynamicStats(true); } - else if (pl != 0) + else { - myPacket->Packet(&bsIn, pl, false); - - MWWorld::Ptr ptrPlayer = pl->getPtr(); - MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); - MWMechanics::DynamicStat value; - - for (int i = 0; i < 3; ++i) - { - value.readState(pl->CreatureStats()->mDynamic[i]); - ptrCreatureStats->setDynamic(i, value); - } + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setDynamicStats(); } - break; } - case ID_GAME_DIE: + else if (pl != 0) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_GAME_DIE from server"); - if (id == myid) - { - MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWMechanics::DynamicStat health = player.getClass().getCreatureStats(player).getHealth(); - health.setCurrent(0); - player.getClass().getCreatureStats(player).setHealth(health); - myPacket->Send(getLocalPlayer(), serverAddr); - } - else if (pl != 0) + myPacket->Packet(&bsIn, pl, false); + + MWWorld::Ptr ptrPlayer = pl->getPtr(); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); + MWMechanics::DynamicStat value; + + for (int i = 0; i < 3; ++i) { - LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl->Npc()->mName.c_str()); - MWMechanics::DynamicStat health; - pl->CreatureStats()->mDead = true; - health.readState(pl->CreatureStats()->mDynamic[0]); - health.setCurrent(0); - health.writeState(pl->CreatureStats()->mDynamic[0]); - pl->getPtr().getClass().getCreatureStats(pl->getPtr()).setHealth(health); + value.readState(pl->CreatureStats()->mDynamic[i]); + ptrCreatureStats->setDynamic(i, value); } - break; } - case ID_GAME_RESURRECT: + break; + } + case ID_GAME_DIE: + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Received ID_GAME_DIE from server"); + if (id == myid) { - if (id == myid) - { - MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - player.getClass().getCreatureStats(player).resurrect(); - ESM::Position pos; - MWBase::Environment::get().getWorld()->findInteriorPosition("Pelagiad, Fort Pelagiad", pos); - MWBase::Environment::get().getWorld()->changeToInteriorCell("Pelagiad, Fort Pelagiad", pos, true); - (*getLocalPlayer()->Position()) = pos; - (*getLocalPlayer()->GetCell()) = *player.getCell()->getCell(); - myPacket->Send(getLocalPlayer(), serverAddr); + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWMechanics::DynamicStat health = player.getClass().getCreatureStats(player).getHealth(); + health.setCurrent(0); + player.getClass().getCreatureStats(player).setHealth(health); + myPacket->Send(getLocalPlayer(), serverAddr); + } + else if (pl != 0) + { + LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", pl->Npc()->mName.c_str()); + MWMechanics::DynamicStat health; + pl->CreatureStats()->mDead = true; + health.readState(pl->CreatureStats()->mDynamic[0]); + health.setCurrent(0); + health.writeState(pl->CreatureStats()->mDynamic[0]); + pl->getPtr().getClass().getCreatureStats(pl->getPtr()).setHealth(health); + } + break; + } + case ID_GAME_RESURRECT: + { + if (id == myid) + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); + player.getClass().getCreatureStats(player).resurrect(); + ESM::Position pos; + MWBase::Environment::get().getWorld()->findInteriorPosition("Pelagiad, Fort Pelagiad", pos); + MWBase::Environment::get().getWorld()->changeToInteriorCell("Pelagiad, Fort Pelagiad", pos, true); + (*getLocalPlayer()->Position()) = pos; + (*getLocalPlayer()->GetCell()) = *player.getCell()->getCell(); + myPacket->Send(getLocalPlayer(), serverAddr); - getLocalPlayer()->updateDynamicStats(true); - controller.GetPacket(ID_GAME_DYNAMICSTATS)->Send(getLocalPlayer(), serverAddr); - } - else if (pl != 0) - { - pl->CreatureStats()->mDead = false; - if (pl->CreatureStats()->mDynamic[0].mMod < 1) - pl->CreatureStats()->mDynamic[0].mMod = 1; - pl->CreatureStats()->mDynamic[0].mCurrent = pl->CreatureStats()->mDynamic[0].mMod; + getLocalPlayer()->updateDynamicStats(true); + playerController.GetPacket(ID_GAME_DYNAMICSTATS)->Send(getLocalPlayer(), serverAddr); + } + else if (pl != 0) + { + pl->CreatureStats()->mDead = false; + if (pl->CreatureStats()->mDynamic[0].mMod < 1) + pl->CreatureStats()->mDynamic[0].mMod = 1; + pl->CreatureStats()->mDynamic[0].mCurrent = pl->CreatureStats()->mDynamic[0].mMod; - pl->getPtr().getClass().getCreatureStats(pl->getPtr()).resurrect(); + pl->getPtr().getClass().getCreatureStats(pl->getPtr()).resurrect(); - MWMechanics::DynamicStat health; - health.readState(pl->CreatureStats()->mDynamic[0]); - pl->getPtr().getClass().getCreatureStats(pl->getPtr()).setHealth(health); - } - break; + MWMechanics::DynamicStat health; + health.readState(pl->CreatureStats()->mDynamic[0]); + pl->getPtr().getClass().getCreatureStats(pl->getPtr()).setHealth(health); } - case ID_GAME_CELL: + break; + } + case ID_GAME_CELL: + { + if (id == myid) { - if (id == myid) - { - if (packet->length == myPacket->headerSize()) - getLocalPlayer()->updateCell(true); - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setCell(); - } - } - else if (pl != 0) + if (packet->length == myPacket->headerSize()) + getLocalPlayer()->updateCell(true); + else { - myPacket->Packet(&bsIn, pl, false); - pl->updateCell(); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setCell(); } - break; } - case ID_GAME_DRAWSTATE: + else if (pl != 0) { - if (id == myid) - getLocalPlayer()->updateDrawStateAndFlags(true); - else if (pl != 0) - { - myPacket->Packet(&bsIn, pl, false); - pl->UpdateDrawState(); - } - break; + myPacket->Packet(&bsIn, pl, false); + pl->updateCell(); } - case ID_CHAT_MESSAGE: + break; + } + case ID_GAME_DRAWSTATE: + { + if (id == myid) + getLocalPlayer()->updateDrawStateAndFlags(true); + else if (pl != 0) { - std::string message; - if (id == myid) - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - message = *getLocalPlayer()->ChatMessage(); - } - else if (pl != 0) - { - myPacket->Packet(&bsIn, pl, false); - message = *pl->ChatMessage(); - } - Main::get().getGUIController()->PrintChatMessage(message); + myPacket->Packet(&bsIn, pl, false); + pl->UpdateDrawState(); + } + break; + } + case ID_CHAT_MESSAGE: + { + std::string message; + if (id == myid) + { + myPacket->Packet(&bsIn, getLocalPlayer(), false); + message = *getLocalPlayer()->ChatMessage(); + } + else if (pl != 0) + { + myPacket->Packet(&bsIn, pl, false); + message = *pl->ChatMessage(); + } + Main::get().getGUIController()->PrintChatMessage(message); - break; + break; + } + case ID_GAME_CHARGEN: + { + if (id == myid) + { + myPacket->Packet(&bsIn, getLocalPlayer(), false); } - case ID_GAME_CHARGEN: + break; + } + case ID_GAME_ATTRIBUTE: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) + { + getLocalPlayer()->updateAttributes(true); + } + else { myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setAttributes(); } - break; } - case ID_GAME_ATTRIBUTE: + else if (pl != 0) { - if (id == myid) - { - if (packet->length == myPacket->headerSize()) - { - getLocalPlayer()->updateAttributes(true); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setAttributes(); - } - } - else if (pl != 0) - { - myPacket->Packet(&bsIn, pl, false); + myPacket->Packet(&bsIn, pl, false); - MWWorld::Ptr ptrPlayer = pl->getPtr(); - MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); - MWMechanics::AttributeValue attributeValue; + MWWorld::Ptr ptrPlayer = pl->getPtr(); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); + MWMechanics::AttributeValue attributeValue; - for (int i = 0; i < 8; ++i) - { - attributeValue.readState(pl->CreatureStats()->mAttributes[i]); - ptrCreatureStats->setAttribute(i, attributeValue); - } + for (int i = 0; i < 8; ++i) + { + attributeValue.readState(pl->CreatureStats()->mAttributes[i]); + ptrCreatureStats->setAttribute(i, attributeValue); } - break; } - case ID_GAME_SKILL: + break; + } + case ID_GAME_SKILL: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) { - if (packet->length == myPacket->headerSize()) - { - getLocalPlayer()->updateSkills(true); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setSkills(); - } + getLocalPlayer()->updateSkills(true); } - else if (pl != 0) + else { - myPacket->Packet(&bsIn, pl, false); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setSkills(); + } + } + else if (pl != 0) + { + myPacket->Packet(&bsIn, pl, false); - MWWorld::Ptr ptrPlayer = pl->getPtr(); - MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer); - MWMechanics::SkillValue skillValue; + MWWorld::Ptr ptrPlayer = pl->getPtr(); + MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer); + MWMechanics::SkillValue skillValue; - for (int i = 0; i < 27; ++i) - { - skillValue.readState(pl->NpcStats()->mSkills[i]); - ptrNpcStats->setSkill(i, skillValue); - } + for (int i = 0; i < 27; ++i) + { + skillValue.readState(pl->NpcStats()->mSkills[i]); + ptrNpcStats->setSkill(i, skillValue); } - break; } - case ID_GAME_LEVEL: + break; + } + case ID_GAME_LEVEL: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) { - if (packet->length == myPacket->headerSize()) - { - getLocalPlayer()->updateLevel(true); - } - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setLevel(); - } + getLocalPlayer()->updateLevel(true); } - else if (pl != 0) + else { - myPacket->Packet(&bsIn, pl, false); - - MWWorld::Ptr ptrPlayer = pl->getPtr(); - MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); - - ptrCreatureStats->setLevel(pl->CreatureStats()->mLevel); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setLevel(); } - break; } - case ID_GUI_MESSAGEBOX: + else if (pl != 0) { - if (id == myid) - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); + myPacket->Packet(&bsIn, pl, false); - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "ID_GUI_MESSAGEBOX, Type %d, MSG %s", - getLocalPlayer()->guiMessageBox.type, - getLocalPlayer()->guiMessageBox.label.c_str()); + MWWorld::Ptr ptrPlayer = pl->getPtr(); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); - if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::MessageBox) - Main::get().getGUIController()->ShowMessageBox(getLocalPlayer()->guiMessageBox); - else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::CustomMessageBox) - Main::get().getGUIController()->ShowCustomMessageBox(getLocalPlayer()->guiMessageBox); - else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::InputDialog) - Main::get().getGUIController()->ShowInputBox(getLocalPlayer()->guiMessageBox); - } - break; + ptrCreatureStats->setLevel(pl->CreatureStats()->mLevel); } - case ID_GAME_CHARCLASS: + break; + } + case ID_GUI_MESSAGEBOX: + { + if (id == myid) { - if (id == myid) - { - if (packet->length == myPacket->headerSize()) - getLocalPlayer()->sendClass(); - else - { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - getLocalPlayer()->setClass(); - } - } - break; + myPacket->Packet(&bsIn, getLocalPlayer(), false); + + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "ID_GUI_MESSAGEBOX, Type %d, MSG %s", + getLocalPlayer()->guiMessageBox.type, + getLocalPlayer()->guiMessageBox.label.c_str()); + + if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::MessageBox) + Main::get().getGUIController()->ShowMessageBox(getLocalPlayer()->guiMessageBox); + else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::CustomMessageBox) + Main::get().getGUIController()->ShowCustomMessageBox(getLocalPlayer()->guiMessageBox); + else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::InputDialog) + Main::get().getGUIController()->ShowInputBox(getLocalPlayer()->guiMessageBox); } - case ID_GAME_TIME: + break; + } + case ID_GAME_CHARCLASS: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) + getLocalPlayer()->sendClass(); + else { myPacket->Packet(&bsIn, getLocalPlayer(), false); - MWBase::World *world = MWBase::Environment::get().getWorld(); - if (getLocalPlayer()->hour != -1) - world->setHour(getLocalPlayer()->hour); - else if (getLocalPlayer()->day != -1) - world->setDay(getLocalPlayer()->day); - else if (getLocalPlayer()->month != -1) - world->setMonth(getLocalPlayer()->month); + getLocalPlayer()->setClass(); } } - case ID_GAME_INVENTORY: + case ID_GAME_INVENTORY: + { + if (id == myid) { - if (id == myid) + if (packet->length == myPacket->headerSize()) { - if (packet->length == myPacket->headerSize()) - { - printf("ID_GAME_INVENTORY update only\n"); - getLocalPlayer()->updateInventory(true); - GetPacket(ID_GAME_INVENTORY)->Send(getLocalPlayer()); - } - else + printf("ID_GAME_INVENTORY update only\n"); + getLocalPlayer()->updateInventory(true); + GetPacket(ID_GAME_INVENTORY)->Send(getLocalPlayer()); + } + else + { + myPacket->Packet(&bsIn, getLocalPlayer(), false); + MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWWorld::ContainerStore &conStore = ptr.getClass().getContainerStore(ptr); + if (getLocalPlayer()->inventory.action == Inventory::ADDITEM) { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::ContainerStore &conStore = ptr.getClass().getContainerStore(ptr); - if (getLocalPlayer()->inventory.action == Inventory::ADDITEM) + for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) { - for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) - { - mwmp::Item item = getLocalPlayer()->inventory.items[i]; - MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptr); - if(item.health != -1) - itemPtr.getCellRef().setCharge(item.health); - } + mwmp::Item item = getLocalPlayer()->inventory.items[i]; + MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptr); + if(item.health != -1) + itemPtr.getCellRef().setCharge(item.health); } - else if (getLocalPlayer()->inventory.action == Inventory::REMOVEITEM) + } + else if (getLocalPlayer()->inventory.action == Inventory::REMOVEITEM) + { + for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) { - for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) - { - mwmp::Item item = getLocalPlayer()->inventory.items[i]; - conStore.remove(item.refid, item.count, ptr); - } + mwmp::Item item = getLocalPlayer()->inventory.items[i]; + conStore.remove(item.refid, item.count, ptr); } - else // update + } + else // update + { + conStore.clear(); + for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) { - conStore.clear(); - for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) - { - mwmp::Item item = getLocalPlayer()->inventory.items[i]; - MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptr); - if(item.health != -1) - itemPtr.getCellRef().setCharge(item.health); - printf("%s %d %d\n", item.refid.c_str(), item.count, item.health); - } - getLocalPlayer()->setInventory(); // restore equipped items + mwmp::Item item = getLocalPlayer()->inventory.items[i]; + MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptr); + if(item.health != -1) + itemPtr.getCellRef().setCharge(item.health); + printf("%s %d %d\n", item.refid.c_str(), item.count, item.health); } + getLocalPlayer()->setInventory(); // restore equipped items } } - break; } - default: - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Custom message with identifier %i has arrived in initialization.", packet->data[0]); + break; + } + case ID_GAME_TIME: + { + if (id == myid) + { + myPacket->Packet(&bsIn, getLocalPlayer(), false); + MWBase::World *world = MWBase::Environment::get().getWorld(); + if (getLocalPlayer()->hour != -1) + world->setHour(getLocalPlayer()->hour); + else if (getLocalPlayer()->day != -1) + world->setDay(getLocalPlayer()->day); + else if (getLocalPlayer()->month != -1) + world->setMonth(getLocalPlayer()->month); + } + break; + } + default: + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Unhandled PlayerPacket with identifier %i has arrived", + packet->data[0]); } } -PlayerPacket *Networking::GetPacket(RakNet::MessageID id) +void Networking::ProcessWorldPacket(RakNet::Packet *packet) { - return controller.GetPacket(id); + RakNet::RakNetGUID id; + RakNet::BitStream bsIn(&packet->data[1], packet->length, false); + bsIn.Read(id); + + DedicatedPlayer *pl = 0; + static RakNet::RakNetGUID myid = getLocalPlayer()->guid; + if (id != myid) + pl = Players::GetPlayer(id); + + WorldPacket *myPacket = worldController.GetPacket(packet->data[0]); + WorldEvent *event = new WorldEvent(id); + myPacket->Packet(&bsIn, event, false); + + MWWorld::CellStore *ptrCellStore; + + if (event->cell.isExterior()) + { + ptrCellStore = MWBase::Environment::get().getWorld()->getExterior(event->cell.mData.mX, event->cell.mData.mY); + } + else + { + ptrCellStore = MWBase::Environment::get().getWorld()->getInterior(event->cell.mName); + } + + switch (packet->data[0]) + { + case ID_WORLD_OBJECT_PLACE: + { + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), event->cellRef.mRefID, 1); + + MWBase::Environment::get().getWorld()->placeObject(ref.getPtr(), ptrCellStore, event->cellRef.mPos); + + break; + } + case ID_WORLD_OBJECT_DELETE: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_DELETE"); + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %i, %i, %i, %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str()); + + MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + + if (ptrFound) + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", + ptrFound.getCellRef().getRefId().c_str(), + ptrFound.getCellRef().getRefNum()); + + MWBase::Environment::get().getWorld()->deleteObject(ptrFound); + } + + break; + } + default: + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Unhandled WorldPacket with identifier %i has arrived", + packet->data[0]); +>>>>>>> refs/remotes/origin/tes3mp-packetexpansion + } +} + +void Networking::ReceiveMessage(RakNet::Packet *packet) +{ + if (packet->length < 2) + return; + + if (playerController.ContainsPacket(packet->data[0])) + { + ProcessPlayerPacket(packet); + } + else if (worldController.ContainsPacket(packet->data[0])) + { + ProcessWorldPacket(packet); + } +} + +PlayerPacket *Networking::GetPlayerPacket(RakNet::MessageID id) +{ + return playerController.GetPacket(id); +} + +WorldPacket *Networking::GetWorldPacket(RakNet::MessageID id) +{ + return worldController.GetPacket(id); } LocalPlayer *Networking::getLocalPlayer() @@ -678,6 +761,11 @@ LocalPlayer *Networking::getLocalPlayer() return mwmp::Main::get().getLocalPlayer(); } +WorldEvent *Networking::createWorldEvent() +{ + return new WorldEvent(getLocalPlayer()->guid); +} + bool Networking::isDedicatedPlayer(const MWWorld::Ptr &ptr) { if (ptr.mRef == 0) diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index 430a6d849..9c03510f8 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -10,16 +10,17 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace mwmp { @@ -33,7 +34,9 @@ namespace mwmp void Connect(const std::string& ip, unsigned short port); void Update(); void SendData(RakNet::BitStream *bitStream); - PlayerPacket *GetPacket(RakNet::MessageID id); + + PlayerPacket *GetPlayerPacket(RakNet::MessageID id); + WorldPacket *GetWorldPacket(RakNet::MessageID id); bool isDedicatedPlayer(const MWWorld::Ptr &ptr); bool Attack(const MWWorld::Ptr &ptr); @@ -45,14 +48,19 @@ namespace mwmp bool isConnected(); + WorldEvent *createWorldEvent(); + private: bool connected; RakNet::RakPeerInterface *peer; RakNet::SystemAddress serverAddr; RakNet::BitStream bsOut; - PacketsController controller; + PlayerPacketController playerController; + WorldPacketController worldController; + void ProcessPlayerPacket(RakNet::Packet *packet); + void ProcessWorldPacket(RakNet::Packet *packet); void ReceiveMessage(RakNet::Packet *packet); LocalPlayer *getLocalPlayer(); }; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 1830be693..31a8126b0 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -2,6 +2,9 @@ #include +#include +#include "../mwmp/Main.hpp" + #include #include #include @@ -668,7 +671,16 @@ namespace MWScript runtime.pop(); if (parameter == 1) + { + // Added by tes3mp + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->cell = *ptr.getCell()->getCell(); + event->cellRef.mRefID = ptr.getCellRef().getRefId(); + event->cellRef.mRefNum = ptr.getCellRef().getRefNum(); + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_DELETE)->Send(event); + MWBase::Environment::get().getWorld()->deleteObject(ptr); + } else if (parameter == 0) MWBase::Environment::get().getWorld()->undeleteObject(ptr); else diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 4e6135764..d057ad071 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -1,5 +1,9 @@ #include "actiontake.hpp" +#include +#include "../mwmp/Main.hpp" +#include "../mwworld/cellstore.hpp" + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" @@ -17,6 +21,19 @@ namespace MWWorld MWBase::Environment::get().getMechanicsManager()->itemTaken( actor, getTarget(), MWWorld::Ptr(), getTarget().getRefData().getCount()); actor.getClass().getContainerStore (actor).add (getTarget(), getTarget().getRefData().getCount(), actor); + + // Added by tes3mp + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->cell = *getTarget().getCell()->getCell(); + event->cellRef.mRefID = getTarget().getCellRef().getRefId(); + event->cellRef.mRefNum = getTarget().getCellRef().getRefNum(); + mwmp::Main::get().getNetworking()->GetWorldPacket(ID_WORLD_OBJECT_DELETE)->Send(event); + + printf("Sending ID_WORLD_OBJECT_DELETE about\n- cellRef: %s, %i\n- cell: %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str()); + MWBase::Environment::get().getWorld()->deleteObject (getTarget()); } } diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index e5c9e779e..6be2075c4 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -168,6 +168,30 @@ namespace return true; } }; + + // Added by tes3mp + template + struct SearchByRefNumCustomVisitor + { + PtrType mFound; + ESM::RefNum mRefNumToFind; + + SearchByRefNumCustomVisitor(const ESM::RefNum& toFind) + : mFound(NULL) + , mRefNumToFind(toFind) + { + } + + bool operator()(const PtrType& ptr) + { + if (ptr.getCellRef().getRefNum() == mRefNumToFind) + { + mFound = ptr; + return false; + } + return true; + } + }; } namespace MWWorld @@ -433,6 +457,14 @@ namespace MWWorld return Ptr(); } + // Added by tes3mp + Ptr CellStore::searchByRefNum (ESM::RefNum refNum) + { + SearchByRefNumCustomVisitor searchVisitor(refNum); + forEach(searchVisitor); + return searchVisitor.mFound; + } + float CellStore::getWaterLevel() const { if (isExterior()) diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 1aee13132..45f4a6606 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -228,6 +228,9 @@ namespace MWWorld Ptr searchViaActorId (int id); ///< Will return an empty Ptr if cell is not loaded. + Ptr searchByRefNum (ESM::RefNum refNum); + ///< Added by tes3mp + float getWaterLevel() const; void setWaterLevel (float level); diff --git a/apps/openmw/mwworld/livecellref.hpp b/apps/openmw/mwworld/livecellref.hpp index f42e1611a..91495eed2 100644 --- a/apps/openmw/mwworld/livecellref.hpp +++ b/apps/openmw/mwworld/livecellref.hpp @@ -28,7 +28,7 @@ namespace MWWorld */ MWWorld::CellRef mRef; - /* Added by TES3MP to prevent dedicated players' references from automatically + /* Added by tes3mp to prevent dedicated players' references from automatically * and unpredictably moving across exterior cell boundaries on clients */ bool canChangeCell; diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 0edaa8c7f..6e95d857c 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -147,11 +147,17 @@ add_component_dir (version add_component_dir (openmw-mp Log - PacketsController - Packets/PlayerPacket Packets/PacketBaseInfo Packets/PacketPosition Packets/PacketEquipment Packets/PacketAttack - Packets/PacketDynamicStats Packets/PacketCell Packets/PacketDrawState Packets/PacketChatMessage - Packets/PacketCharGen Packets/PacketAttribute Packets/PacketSkill Packets/PacketLevel Packets/PacketHandshake - Packets/PacketGUIBoxes Packets/PacketClass Packets/PacketTime Packets/PacketInventory) + Controllers/PlayerPacketController Controllers/WorldPacketController + Packets/BasePacket Packets/Player/PlayerPacket Packets/World/WorldPacket + + Packets/Player/PacketBaseInfo Packets/Player/PacketPosition Packets/Player/PacketEquipment + Packets/Player/PacketAttack Packets/Player/PacketDynamicStats Packets/Player/PacketCell + Packets/Player/PacketDrawState Packets/Player/PacketChatMessage Packets/Player/PacketCharGen + Packets/Player/PacketAttribute Packets/Player/PacketSkill Packets/Player/PacketLevel + Packets/Player/PacketHandshake Packets/Player/PacketGUIBoxes Packets/Player/PacketClass + Packets/Player/PacketTime Packets/PacketInventory + + Packets/World/PacketObjectDelete Packets/World/PacketObjectPlace) add_component_dir (fallback fallback validate diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp new file mode 100644 index 000000000..0348f3500 --- /dev/null +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -0,0 +1,31 @@ +#ifndef OPENMW_WORLDEVENT_HPP +#define OPENMW_WORLDEVENT_HPP + +#include +#include +#include + +namespace mwmp +{ + class WorldEvent + { + public: + + WorldEvent(RakNet::RakNetGUID guid) : guid(guid) + { + + } + + WorldEvent() + { + + } + + RakNet::RakNetGUID guid; + + ESM::Cell cell; + ESM::CellRef cellRef; + }; +} + +#endif //OPENMW_WORLDEVENT_HPP diff --git a/components/openmw-mp/Controllers/PlayerPacketController.cpp b/components/openmw-mp/Controllers/PlayerPacketController.cpp new file mode 100644 index 000000000..ac146c479 --- /dev/null +++ b/components/openmw-mp/Controllers/PlayerPacketController.cpp @@ -0,0 +1,87 @@ +#include +#include +#include + +#include "../Packets/Player/PacketClass.hpp" +#include "../Packets/Player/PacketPosition.hpp" +#include "../Packets/Player/PacketBaseInfo.hpp" +#include "../Packets/Player/PacketEquipment.hpp" +#include "../Packets/Player/PacketAttack.hpp" +#include "../Packets/Player/PacketDynamicStats.hpp" +#include "../Packets/Player/PacketResurrect.hpp" +#include "../Packets/Player/PacketDie.hpp" +#include "../Packets/Player/PacketCell.hpp" +#include "../Packets/Player/PacketSendMyID.hpp" +#include "../Packets/Player/PacketDisconnect.hpp" +#include "../Packets/Player/PacketDrawState.hpp" +#include "../Packets/Player/PacketChatMessage.hpp" +#include "../Packets/Player/PacketCharGen.hpp" +#include "../Packets/Player/PacketAttribute.hpp" +#include "../Packets/Player/PacketSkill.hpp" +#include "../Packets/Player/PacketLevel.hpp" +#include "../Packets/Player/PacketHandshake.hpp" +#include "../Packets/Player/PacketGUIBoxes.hpp" +#include "../Packets/Player/PacketTime.hpp" +#include "../Packets/Player/PacketLoaded.hpp" +#include "../Packets/Player/PacketInventory.hpp" + +#include "PlayerPacketController.hpp" + +template +inline void AddPacket(mwmp::PlayerPacketController::packets_t *packets, RakNet::RakPeerInterface *peer) +{ + T *packet = new T(peer); + typedef mwmp::PlayerPacketController::packets_t::value_type value_t; + packets->insert(value_t(packet->GetPacketID(), value_t::second_type(packet))); +} + +mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *peer) +{ + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); + AddPacket(&packets, peer); +} + + +mwmp::PlayerPacket *mwmp::PlayerPacketController::GetPacket(RakNet::MessageID id) +{ + return packets[(unsigned char)id].get(); +} + +void mwmp::PlayerPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream) +{ + BOOST_FOREACH( packets_t::value_type &packet, packets ) + packet.second->SetStreams(inStream, outStream); +} + +bool mwmp::PlayerPacketController::ContainsPacket(RakNet::MessageID id) +{ + BOOST_FOREACH(packets_t::value_type &packet, packets) { + if (packet.first == id) + return true; + } + return false; +} diff --git a/components/openmw-mp/PacketsController.hpp b/components/openmw-mp/Controllers/PlayerPacketController.hpp similarity index 54% rename from components/openmw-mp/PacketsController.hpp rename to components/openmw-mp/Controllers/PlayerPacketController.hpp index f112743cf..fc2927c65 100644 --- a/components/openmw-mp/PacketsController.hpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.hpp @@ -1,29 +1,27 @@ -// -// Created by koncord on 15.01.16. -// - -#ifndef OPENMW_PACKETSCONTROLLER_HPP -#define OPENMW_PACKETSCONTROLLER_HPP +#ifndef OPENMW_PLAYERPACKETCONTROLLER_HPP +#define OPENMW_PLAYERPACKETCONTROLLER_HPP #include -#include "Packets/PlayerPacket.hpp" +#include "../Packets/Player/PlayerPacket.hpp" #include #include namespace mwmp { - class PacketsController + class PlayerPacketController { public: - PacketsController(RakNet::RakPeerInterface *peer); + PlayerPacketController(RakNet::RakPeerInterface *peer); PlayerPacket *GetPacket(RakNet::MessageID id); void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream); + bool ContainsPacket(RakNet::MessageID id); + typedef std::map > packets_t; private: packets_t packets; }; } -#endif //OPENMW_PACKETSCONTROLLER_HPP +#endif //OPENMW_PLAYERPACKETCONTROLLER_HPP diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp new file mode 100644 index 000000000..119c0b581 --- /dev/null +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +#include "../Packets/World/PacketObjectPlace.hpp" +#include "../Packets/World/PacketObjectDelete.hpp" + +#include "WorldPacketController.hpp" + +template +inline void AddPacket(mwmp::WorldPacketController::packets_t *packets, RakNet::RakPeerInterface *peer) +{ + T *packet = new T(peer); + typedef mwmp::WorldPacketController::packets_t::value_type value_t; + packets->insert(value_t(packet->GetPacketID(), value_t::second_type(packet))); +} + +mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *peer) +{ + AddPacket(&packets, peer); + AddPacket(&packets, peer); +} + + +mwmp::WorldPacket *mwmp::WorldPacketController::GetPacket(RakNet::MessageID id) +{ + return packets[(unsigned char)id].get(); +} + +void mwmp::WorldPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream) +{ + BOOST_FOREACH( packets_t::value_type &packet, packets ) + packet.second->SetStreams(inStream, outStream); +} + +bool mwmp::WorldPacketController::ContainsPacket(RakNet::MessageID id) +{ + BOOST_FOREACH(packets_t::value_type &packet, packets) { + if (packet.first == id) + return true; + } + return false; +} diff --git a/components/openmw-mp/Controllers/WorldPacketController.hpp b/components/openmw-mp/Controllers/WorldPacketController.hpp new file mode 100644 index 000000000..d96a8c886 --- /dev/null +++ b/components/openmw-mp/Controllers/WorldPacketController.hpp @@ -0,0 +1,27 @@ +#ifndef OPENMW_WORLDPACKETCONTROLLER_HPP +#define OPENMW_WORLDPACKETCONTROLLER_HPP + + +#include +#include "../Packets/World/WorldPacket.hpp" +#include +#include + +namespace mwmp +{ + class WorldPacketController + { + public: + WorldPacketController(RakNet::RakPeerInterface *peer); + WorldPacket *GetPacket(RakNet::MessageID id); + void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream); + + bool ContainsPacket(RakNet::MessageID id); + + typedef std::map > packets_t; + private: + packets_t packets; + }; +} + +#endif //OPENMW_WORLDPACKETCONTROLLER_HPP diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index 7611ef955..a53ed59c1 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -31,7 +31,10 @@ enum GameMessages ID_LOADED, ID_GUI_MESSAGEBOX, ID_GAME_TIME, - ID_GAME_INVENTORY + ID_GAME_INVENTORY, + + ID_WORLD_OBJECT_PLACE, + ID_WORLD_OBJECT_DELETE }; diff --git a/components/openmw-mp/Packets/BasePacket.cpp b/components/openmw-mp/Packets/BasePacket.cpp new file mode 100644 index 000000000..408b95c7e --- /dev/null +++ b/components/openmw-mp/Packets/BasePacket.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include "BasePacket.hpp" + +using namespace mwmp; + +BasePacket::BasePacket(RakNet::RakPeerInterface *peer) +{ + packetID = 0; + priority = HIGH_PRIORITY; + reliability = RELIABLE_ORDERED; + this->peer = peer; +} + +BasePacket::~BasePacket() +{ + +} + +void BasePacket::SetReadStream(RakNet::BitStream *bitStream) +{ + bsRead = bitStream; +} + +void BasePacket::SetSendStream(RakNet::BitStream *bitStream) +{ + bsSend = bitStream; +} + +void BasePacket::SetStreams(RakNet::BitStream *inStream, RakNet::BitStream *outStream) +{ + if (inStream != 0) + bsRead = inStream; + if (outStream != 0) + bsSend = outStream; +} \ No newline at end of file diff --git a/components/openmw-mp/Packets/PlayerPacket.hpp b/components/openmw-mp/Packets/BasePacket.hpp similarity index 76% rename from components/openmw-mp/Packets/PlayerPacket.hpp rename to components/openmw-mp/Packets/BasePacket.hpp index fe45f1e23..88b963734 100644 --- a/components/openmw-mp/Packets/PlayerPacket.hpp +++ b/components/openmw-mp/Packets/BasePacket.hpp @@ -1,5 +1,5 @@ -#ifndef OPENMW_PLAYERPACKET_HPP -#define OPENMW_PLAYERPACKET_HPP +#ifndef OPENMW_BASEPACKET_HPP +#define OPENMW_BASEPACKET_HPP #include #include @@ -10,20 +10,12 @@ namespace mwmp { - class PlayerPacket + class BasePacket { public: - PlayerPacket(RakNet::RakPeerInterface *peer); + BasePacket(RakNet::RakPeerInterface *peer); - ~PlayerPacket(); - - virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); - - virtual void Send(BasePlayer *player, bool toOtherPlayers = true); - virtual void Send(BasePlayer *player, RakNet::AddressOrGUID destination); - virtual void Read(BasePlayer *player); - - virtual void RequestData(RakNet::RakNetGUID player); + ~BasePacket(); void SetReadStream(RakNet::BitStream *bitStream); void SetSendStream(RakNet::BitStream *bitStream); @@ -90,16 +82,12 @@ namespace mwmp } protected: - BasePlayer *player; unsigned char packetID; PacketReliability reliability; PacketPriority priority; - - private: RakNet::BitStream *bsRead, *bsSend, *bs; RakNet::RakPeerInterface *peer; - }; } -#endif //OPENMW_PLAYERPACKET_HPP +#endif //OPENMW_BASEPACKET_HPP diff --git a/components/openmw-mp/Packets/PacketAttack.cpp b/components/openmw-mp/Packets/Player/PacketAttack.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketAttack.cpp rename to components/openmw-mp/Packets/Player/PacketAttack.cpp diff --git a/components/openmw-mp/Packets/PacketAttack.hpp b/components/openmw-mp/Packets/Player/PacketAttack.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketAttack.hpp rename to components/openmw-mp/Packets/Player/PacketAttack.hpp index cbc64bcca..415d5f78a 100644 --- a/components/openmw-mp/Packets/PacketAttack.hpp +++ b/components/openmw-mp/Packets/Player/PacketAttack.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETATTACK_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketAttribute.cpp b/components/openmw-mp/Packets/Player/PacketAttribute.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketAttribute.cpp rename to components/openmw-mp/Packets/Player/PacketAttribute.cpp diff --git a/components/openmw-mp/Packets/PacketAttribute.hpp b/components/openmw-mp/Packets/Player/PacketAttribute.hpp similarity index 87% rename from components/openmw-mp/Packets/PacketAttribute.hpp rename to components/openmw-mp/Packets/Player/PacketAttribute.hpp index 461587f23..4a60347da 100644 --- a/components/openmw-mp/Packets/PacketAttribute.hpp +++ b/components/openmw-mp/Packets/Player/PacketAttribute.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETATTRIBUTE_HPP #define OPENMW_PACKETATTRIBUTE_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketBaseInfo.cpp b/components/openmw-mp/Packets/Player/PacketBaseInfo.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketBaseInfo.cpp rename to components/openmw-mp/Packets/Player/PacketBaseInfo.cpp diff --git a/components/openmw-mp/Packets/PacketBaseInfo.hpp b/components/openmw-mp/Packets/Player/PacketBaseInfo.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketBaseInfo.hpp rename to components/openmw-mp/Packets/Player/PacketBaseInfo.hpp index 4b7e33896..91a6bee0f 100644 --- a/components/openmw-mp/Packets/PacketBaseInfo.hpp +++ b/components/openmw-mp/Packets/Player/PacketBaseInfo.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETBASEINFO_HPP #define OPENMW_PACKETBASEINFO_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketCell.cpp b/components/openmw-mp/Packets/Player/PacketCell.cpp similarity index 83% rename from components/openmw-mp/Packets/PacketCell.cpp rename to components/openmw-mp/Packets/Player/PacketCell.cpp index 991774382..67b3ed43f 100644 --- a/components/openmw-mp/Packets/PacketCell.cpp +++ b/components/openmw-mp/Packets/Player/PacketCell.cpp @@ -18,9 +18,7 @@ void mwmp::PacketCell::Packet(RakNet::BitStream *bs, mwmp::BasePlayer *player, b PlayerPacket::Packet(bs, player, send); RW(player->GetCell()->mData.mFlags, send); - - RW(player->GetCell()->mCellId.mIndex.mX, send); - RW(player->GetCell()->mCellId.mIndex.mY, send); - + RW(player->GetCell()->mData.mX, send); + RW(player->GetCell()->mData.mY, send); RW(player->GetCell()->mName, send); } diff --git a/components/openmw-mp/Packets/PacketCell.hpp b/components/openmw-mp/Packets/Player/PacketCell.hpp similarity index 84% rename from components/openmw-mp/Packets/PacketCell.hpp rename to components/openmw-mp/Packets/Player/PacketCell.hpp index 74ca1faab..b130202b4 100644 --- a/components/openmw-mp/Packets/PacketCell.hpp +++ b/components/openmw-mp/Packets/Player/PacketCell.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETCELL_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketCharGen.cpp b/components/openmw-mp/Packets/Player/PacketCharGen.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketCharGen.cpp rename to components/openmw-mp/Packets/Player/PacketCharGen.cpp diff --git a/components/openmw-mp/Packets/PacketCharGen.hpp b/components/openmw-mp/Packets/Player/PacketCharGen.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketCharGen.hpp rename to components/openmw-mp/Packets/Player/PacketCharGen.hpp index c9d51f9e1..7df1e43ff 100644 --- a/components/openmw-mp/Packets/PacketCharGen.hpp +++ b/components/openmw-mp/Packets/Player/PacketCharGen.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETCHARGEN_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketChatMessage.cpp b/components/openmw-mp/Packets/Player/PacketChatMessage.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketChatMessage.cpp rename to components/openmw-mp/Packets/Player/PacketChatMessage.cpp diff --git a/components/openmw-mp/Packets/PacketChatMessage.hpp b/components/openmw-mp/Packets/Player/PacketChatMessage.hpp similarity index 86% rename from components/openmw-mp/Packets/PacketChatMessage.hpp rename to components/openmw-mp/Packets/Player/PacketChatMessage.hpp index 0decedd65..c15dc1083 100644 --- a/components/openmw-mp/Packets/PacketChatMessage.hpp +++ b/components/openmw-mp/Packets/Player/PacketChatMessage.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETCHATMESSAGE_HPP #define OPENMW_PACKETCHATMESSAGE_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketClass.cpp b/components/openmw-mp/Packets/Player/PacketClass.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketClass.cpp rename to components/openmw-mp/Packets/Player/PacketClass.cpp diff --git a/components/openmw-mp/Packets/PacketClass.hpp b/components/openmw-mp/Packets/Player/PacketClass.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketClass.hpp rename to components/openmw-mp/Packets/Player/PacketClass.hpp index 6ae1dea8e..f8ce75dc5 100644 --- a/components/openmw-mp/Packets/PacketClass.hpp +++ b/components/openmw-mp/Packets/Player/PacketClass.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETCLASS_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketDie.hpp b/components/openmw-mp/Packets/Player/PacketDie.hpp similarity index 90% rename from components/openmw-mp/Packets/PacketDie.hpp rename to components/openmw-mp/Packets/Player/PacketDie.hpp index 15622465c..88dbac404 100644 --- a/components/openmw-mp/Packets/PacketDie.hpp +++ b/components/openmw-mp/Packets/Player/PacketDie.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETDIE_HPP -#include +#include #include namespace mwmp diff --git a/components/openmw-mp/Packets/PacketDisconnect.hpp b/components/openmw-mp/Packets/Player/PacketDisconnect.hpp similarity index 87% rename from components/openmw-mp/Packets/PacketDisconnect.hpp rename to components/openmw-mp/Packets/Player/PacketDisconnect.hpp index 154a31f32..39cdbcbc1 100644 --- a/components/openmw-mp/Packets/PacketDisconnect.hpp +++ b/components/openmw-mp/Packets/Player/PacketDisconnect.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETDISCONNECT_HPP #define OPENMW_PACKETDISCONNECT_HPP -#include +#include #include namespace mwmp diff --git a/components/openmw-mp/Packets/PacketDrawState.cpp b/components/openmw-mp/Packets/Player/PacketDrawState.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketDrawState.cpp rename to components/openmw-mp/Packets/Player/PacketDrawState.cpp diff --git a/components/openmw-mp/Packets/PacketDrawState.hpp b/components/openmw-mp/Packets/Player/PacketDrawState.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketDrawState.hpp rename to components/openmw-mp/Packets/Player/PacketDrawState.hpp index c1fb4b991..7aa20750c 100644 --- a/components/openmw-mp/Packets/PacketDrawState.hpp +++ b/components/openmw-mp/Packets/Player/PacketDrawState.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETDRAWSTATE_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketDynamicStats.cpp b/components/openmw-mp/Packets/Player/PacketDynamicStats.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketDynamicStats.cpp rename to components/openmw-mp/Packets/Player/PacketDynamicStats.cpp diff --git a/components/openmw-mp/Packets/PacketDynamicStats.hpp b/components/openmw-mp/Packets/Player/PacketDynamicStats.hpp similarity index 86% rename from components/openmw-mp/Packets/PacketDynamicStats.hpp rename to components/openmw-mp/Packets/Player/PacketDynamicStats.hpp index c4c8e8ff2..8c03445bc 100644 --- a/components/openmw-mp/Packets/PacketDynamicStats.hpp +++ b/components/openmw-mp/Packets/Player/PacketDynamicStats.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKAGEDYNAMICSTATS_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketEquipment.cpp b/components/openmw-mp/Packets/Player/PacketEquipment.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketEquipment.cpp rename to components/openmw-mp/Packets/Player/PacketEquipment.cpp diff --git a/components/openmw-mp/Packets/PacketEquipment.hpp b/components/openmw-mp/Packets/Player/PacketEquipment.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketEquipment.hpp rename to components/openmw-mp/Packets/Player/PacketEquipment.hpp index 5b677f555..d0134a577 100644 --- a/components/openmw-mp/Packets/PacketEquipment.hpp +++ b/components/openmw-mp/Packets/Player/PacketEquipment.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETEQUIPMENT_HPP #define OPENMW_PACKETEQUIPMENT_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketGUIBoxes.cpp b/components/openmw-mp/Packets/Player/PacketGUIBoxes.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketGUIBoxes.cpp rename to components/openmw-mp/Packets/Player/PacketGUIBoxes.cpp diff --git a/components/openmw-mp/Packets/PacketGUIBoxes.hpp b/components/openmw-mp/Packets/Player/PacketGUIBoxes.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketGUIBoxes.hpp rename to components/openmw-mp/Packets/Player/PacketGUIBoxes.hpp index ace0bf771..8d71257f9 100644 --- a/components/openmw-mp/Packets/PacketGUIBoxes.hpp +++ b/components/openmw-mp/Packets/Player/PacketGUIBoxes.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETGUIBOXES_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketHandshake.cpp b/components/openmw-mp/Packets/Player/PacketHandshake.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketHandshake.cpp rename to components/openmw-mp/Packets/Player/PacketHandshake.cpp diff --git a/components/openmw-mp/Packets/PacketHandshake.hpp b/components/openmw-mp/Packets/Player/PacketHandshake.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketHandshake.hpp rename to components/openmw-mp/Packets/Player/PacketHandshake.hpp index b5846d433..539be878b 100644 --- a/components/openmw-mp/Packets/PacketHandshake.hpp +++ b/components/openmw-mp/Packets/Player/PacketHandshake.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETHANDSHAKE_HPP #define OPENMW_PACKETHANDSHAKE_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketLevel.cpp b/components/openmw-mp/Packets/Player/PacketLevel.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketLevel.cpp rename to components/openmw-mp/Packets/Player/PacketLevel.cpp diff --git a/components/openmw-mp/Packets/PacketLevel.hpp b/components/openmw-mp/Packets/Player/PacketLevel.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketLevel.hpp rename to components/openmw-mp/Packets/Player/PacketLevel.hpp index aa61dcc10..8537e954d 100644 --- a/components/openmw-mp/Packets/PacketLevel.hpp +++ b/components/openmw-mp/Packets/Player/PacketLevel.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETLEVEL_HPP #define OPENMW_PACKETLEVEL_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketLoaded.hpp b/components/openmw-mp/Packets/Player/PacketLoaded.hpp similarity index 84% rename from components/openmw-mp/Packets/PacketLoaded.hpp rename to components/openmw-mp/Packets/Player/PacketLoaded.hpp index 35565150d..8f58a4938 100644 --- a/components/openmw-mp/Packets/PacketLoaded.hpp +++ b/components/openmw-mp/Packets/Player/PacketLoaded.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETLOADED_HPP #define OPENMW_PACKETLOADED_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketPosition.cpp b/components/openmw-mp/Packets/Player/PacketPosition.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketPosition.cpp rename to components/openmw-mp/Packets/Player/PacketPosition.cpp diff --git a/components/openmw-mp/Packets/PacketPosition.hpp b/components/openmw-mp/Packets/Player/PacketPosition.hpp similarity index 85% rename from components/openmw-mp/Packets/PacketPosition.hpp rename to components/openmw-mp/Packets/Player/PacketPosition.hpp index d15baa946..33c60a6a8 100644 --- a/components/openmw-mp/Packets/PacketPosition.hpp +++ b/components/openmw-mp/Packets/Player/PacketPosition.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETPOSITION_HPP #define OPENMW_PACKETPOSITION_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketResurrect.hpp b/components/openmw-mp/Packets/Player/PacketResurrect.hpp similarity index 90% rename from components/openmw-mp/Packets/PacketResurrect.hpp rename to components/openmw-mp/Packets/Player/PacketResurrect.hpp index 4588fbbfd..f24d81d62 100644 --- a/components/openmw-mp/Packets/PacketResurrect.hpp +++ b/components/openmw-mp/Packets/Player/PacketResurrect.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETRESURRECT_HPP -#include +#include #include namespace mwmp diff --git a/components/openmw-mp/Packets/PacketSendMyID.hpp b/components/openmw-mp/Packets/Player/PacketSendMyID.hpp similarity index 86% rename from components/openmw-mp/Packets/PacketSendMyID.hpp rename to components/openmw-mp/Packets/Player/PacketSendMyID.hpp index 32ddbe8c9..5e6fa802c 100644 --- a/components/openmw-mp/Packets/PacketSendMyID.hpp +++ b/components/openmw-mp/Packets/Player/PacketSendMyID.hpp @@ -5,7 +5,7 @@ #ifndef OPENMW_PACKETSENDMYID_HPP #define OPENMW_PACKETSENDMYID_HPP -#include +#include #include namespace mwmp diff --git a/components/openmw-mp/Packets/PacketSkill.cpp b/components/openmw-mp/Packets/Player/PacketSkill.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketSkill.cpp rename to components/openmw-mp/Packets/Player/PacketSkill.cpp diff --git a/components/openmw-mp/Packets/PacketSkill.hpp b/components/openmw-mp/Packets/Player/PacketSkill.hpp similarity index 87% rename from components/openmw-mp/Packets/PacketSkill.hpp rename to components/openmw-mp/Packets/Player/PacketSkill.hpp index 3f58db341..d7af6c56b 100644 --- a/components/openmw-mp/Packets/PacketSkill.hpp +++ b/components/openmw-mp/Packets/Player/PacketSkill.hpp @@ -6,7 +6,7 @@ #define OPENMW_PACKETSKILL_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PacketTime.cpp b/components/openmw-mp/Packets/Player/PacketTime.cpp similarity index 100% rename from components/openmw-mp/Packets/PacketTime.cpp rename to components/openmw-mp/Packets/Player/PacketTime.cpp diff --git a/components/openmw-mp/Packets/PacketTime.hpp b/components/openmw-mp/Packets/Player/PacketTime.hpp similarity index 84% rename from components/openmw-mp/Packets/PacketTime.hpp rename to components/openmw-mp/Packets/Player/PacketTime.hpp index bb7521ff8..69efa442b 100644 --- a/components/openmw-mp/Packets/PacketTime.hpp +++ b/components/openmw-mp/Packets/Player/PacketTime.hpp @@ -6,7 +6,7 @@ #define OPENMW_TIMEPACKET_HPP -#include +#include namespace mwmp { diff --git a/components/openmw-mp/Packets/PlayerPacket.cpp b/components/openmw-mp/Packets/Player/PlayerPacket.cpp similarity index 64% rename from components/openmw-mp/Packets/PlayerPacket.cpp rename to components/openmw-mp/Packets/Player/PlayerPacket.cpp index 08ef332af..338b7de27 100644 --- a/components/openmw-mp/Packets/PlayerPacket.cpp +++ b/components/openmw-mp/Packets/Player/PlayerPacket.cpp @@ -17,7 +17,7 @@ void PlayerPacket::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) } } -PlayerPacket::PlayerPacket(RakNet::RakPeerInterface *peer) +PlayerPacket::PlayerPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer) { packetID = 0; priority = HIGH_PRIORITY; @@ -49,28 +49,10 @@ void PlayerPacket::Read(BasePlayer *player) Packet(bsRead, player, false); } -void PlayerPacket::SetReadStream(RakNet::BitStream *bitStream) -{ - bsRead = bitStream; -} - -void PlayerPacket::SetSendStream(RakNet::BitStream *bitStream) -{ - bsSend = bitStream; -} - -void PlayerPacket::RequestData(RakNet::RakNetGUID player) +void PlayerPacket::RequestData(RakNet::RakNetGUID guid) { bsSend->ResetWritePointer(); bsSend->Write(packetID); - bsSend->Write(player); - peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, player, false); + bsSend->Write(guid); + peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, guid, false); } - -void PlayerPacket::SetStreams(RakNet::BitStream *inStream, RakNet::BitStream *outStream) -{ - if (inStream != 0) - bsRead = inStream; - if (outStream != 0) - bsSend = outStream; -} \ No newline at end of file diff --git a/components/openmw-mp/Packets/Player/PlayerPacket.hpp b/components/openmw-mp/Packets/Player/PlayerPacket.hpp new file mode 100644 index 000000000..8d4953183 --- /dev/null +++ b/components/openmw-mp/Packets/Player/PlayerPacket.hpp @@ -0,0 +1,46 @@ +#ifndef OPENMW_PLAYERPACKET_HPP +#define OPENMW_PLAYERPACKET_HPP + +#include +#include +#include +#include +#include + +#include + + +namespace mwmp +{ + class PlayerPacket : public BasePacket + { + public: + PlayerPacket(RakNet::RakPeerInterface *peer); + + ~PlayerPacket(); + + virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); + + virtual void Send(BasePlayer *player, bool toOtherPlayers = true); + virtual void Send(BasePlayer *player, RakNet::AddressOrGUID destination); + virtual void Read(BasePlayer *player); + + virtual void RequestData(RakNet::RakNetGUID guid); + + static size_t headerSize() + { + return (size_t)(1 + RakNet::RakNetGUID::size()); // packetID + RakNetGUID (uint64_t) + } + + unsigned char GetPacketID() + { + return packetID; + } + + protected: + BasePlayer *player; + + }; +} + +#endif //OPENMW_PLAYERPACKET_HPP diff --git a/components/openmw-mp/Packets/World/PacketObjectDelete.cpp b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp new file mode 100644 index 000000000..510f079c7 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectDelete.cpp @@ -0,0 +1,22 @@ +#include +#include "PacketObjectDelete.hpp" + +using namespace mwmp; + +PacketObjectDelete::PacketObjectDelete(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_WORLD_OBJECT_DELETE; +} + +void PacketObjectDelete::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(event->cellRef.mRefID, send); + RW(event->cellRef.mRefNum.mIndex, send); + + RW(event->cell.mData.mFlags, send); + RW(event->cell.mData.mX, send); + RW(event->cell.mData.mY, send); + RW(event->cell.mName, send); +} diff --git a/components/openmw-mp/Packets/World/PacketObjectDelete.hpp b/components/openmw-mp/Packets/World/PacketObjectDelete.hpp new file mode 100644 index 000000000..d3042bc67 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectDelete.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETOBJECTDELETE_HPP +#define OPENMW_PACKETOBJECTDELETE_HPP + +#include + +namespace mwmp +{ + class PacketObjectDelete : public WorldPacket + { + public: + PacketObjectDelete(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETOBJECTDELETE_HPP diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp new file mode 100644 index 000000000..d87907352 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp @@ -0,0 +1,23 @@ +#include +#include "PacketObjectPlace.hpp" + +using namespace mwmp; + +PacketObjectPlace::PacketObjectPlace(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_WORLD_OBJECT_PLACE; +} + +void PacketObjectPlace::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(event->cellRef.mRefID, send); + RW(event->cellRef.mRefNum.mIndex, send); + RW(event->cellRef.mPos, send); + + RW(event->cell.mData.mFlags, send); + RW(event->cell.mData.mX, send); + RW(event->cell.mData.mY, send); + RW(event->cell.mName, send); +} diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.hpp b/components/openmw-mp/Packets/World/PacketObjectPlace.hpp new file mode 100644 index 000000000..cea0263dd --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETOBJECTPLACE_HPP +#define OPENMW_PACKETOBJECTPLACE_HPP + +#include + +namespace mwmp +{ + class PacketObjectPlace : public WorldPacket + { + public: + PacketObjectPlace(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETOBJECTPLACE_HPP diff --git a/components/openmw-mp/Packets/World/WorldPacket.cpp b/components/openmw-mp/Packets/World/WorldPacket.cpp new file mode 100644 index 000000000..543c6c5d6 --- /dev/null +++ b/components/openmw-mp/Packets/World/WorldPacket.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include "WorldPacket.hpp" + +using namespace mwmp; + +void WorldPacket::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + this->event = event; + this->bs = bs; + + if (send) + { + bs->Write(packetID); + bs->Write(event->guid); + } +} + +WorldPacket::WorldPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer) +{ + packetID = 0; + priority = HIGH_PRIORITY; + reliability = RELIABLE_ORDERED; + this->peer = peer; +} + +WorldPacket::~WorldPacket() +{ + +} + +void WorldPacket::Send(WorldEvent *event, RakNet::AddressOrGUID destination) +{ + bsSend->ResetWritePointer(); + Packet(bsSend, event, true); + peer->Send(bsSend, priority, reliability, 0, destination, false); +} + +void WorldPacket::Send(WorldEvent *event, bool toOther) +{ + bsSend->ResetWritePointer(); + Packet(bsSend, event, true); + peer->Send(bsSend, priority, reliability, 0, event->guid, toOther); +} + +void WorldPacket::Read(WorldEvent *event) +{ + Packet(bsRead, event, false); +} + +void WorldPacket::RequestData(RakNet::RakNetGUID guid) +{ + bsSend->ResetWritePointer(); + bsSend->Write(packetID); + bsSend->Write(guid); + peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, guid, false); +} diff --git a/components/openmw-mp/Packets/World/WorldPacket.hpp b/components/openmw-mp/Packets/World/WorldPacket.hpp new file mode 100644 index 000000000..8ad187870 --- /dev/null +++ b/components/openmw-mp/Packets/World/WorldPacket.hpp @@ -0,0 +1,46 @@ +#ifndef OPENMW_WORLDPACKET_HPP +#define OPENMW_WORLDPACKET_HPP + +#include +#include +#include +#include +#include + +#include + + +namespace mwmp +{ + class WorldPacket : public BasePacket + { + public: + WorldPacket(RakNet::RakPeerInterface *peer); + + ~WorldPacket(); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + + virtual void Send(WorldEvent *event, bool toOtherPlayers = true); + virtual void Send(WorldEvent *event, RakNet::AddressOrGUID destination); + virtual void Read(WorldEvent *event); + + virtual void RequestData(RakNet::RakNetGUID guid); + + static size_t headerSize() + { + return (size_t)(1 + RakNet::RakNetGUID::size()); // packetID + RakNetGUID (uint64_t) + } + + unsigned char GetPacketID() + { + return packetID; + } + + protected: + WorldEvent *event; + + }; +} + +#endif //OPENMW_WORLDPACKET_HPP diff --git a/components/openmw-mp/PacketsController.cpp b/components/openmw-mp/PacketsController.cpp deleted file mode 100644 index 1b89bb5ad..000000000 --- a/components/openmw-mp/PacketsController.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// -// Created by koncord on 15.01.16. -// - -#include -#include -#include - -#include "Packets/PacketClass.hpp" -#include "Packets/PacketPosition.hpp" -#include "Packets/PacketBaseInfo.hpp" -#include "components/openmw-mp/Packets/PacketEquipment.hpp" -#include "Packets/PacketAttack.hpp" -#include "Packets/PacketDynamicStats.hpp" -#include "Packets/PacketResurrect.hpp" -#include "Packets/PacketDie.hpp" -#include "Packets/PacketCell.hpp" -#include "Packets/PacketSendMyID.hpp" -#include "Packets/PacketDisconnect.hpp" -#include "Packets/PacketDrawState.hpp" -#include "Packets/PacketChatMessage.hpp" -#include "Packets/PacketCharGen.hpp" -#include "Packets/PacketAttribute.hpp" -#include "Packets/PacketSkill.hpp" -#include "Packets/PacketLevel.hpp" -#include "Packets/PacketHandshake.hpp" -#include "Packets/PacketGUIBoxes.hpp" -#include "Packets/PacketTime.hpp" -#include "Packets/PacketLoaded.hpp" -#include "Packets/PacketInventory.hpp" - -#include "PacketsController.hpp" - -template -inline void AddPacket(mwmp::PacketsController::packets_t *packets, RakNet::RakPeerInterface *peer) -{ - T *packet = new T(peer); - typedef mwmp::PacketsController::packets_t::value_type value_t; - packets->insert(value_t(packet->GetPacketID(), value_t::second_type(packet))); -} - -mwmp::PacketsController::PacketsController(RakNet::RakPeerInterface *peer) -{ - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); - AddPacket(&packets, peer); -} - - -mwmp::PlayerPacket *mwmp::PacketsController::GetPacket(RakNet::MessageID id) -{ - return packets[(unsigned char)id].get(); -} - -void mwmp::PacketsController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream) -{ - BOOST_FOREACH( packets_t::value_type &packet, packets ) - packet.second->SetStreams(inStream, outStream); -} \ No newline at end of file