From f218613231349387f839608f1169f6905bee0805 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 22:49:35 +0300 Subject: [PATCH] Rename client Networking's GetPacket method into GetPlayerPacket --- apps/openmw/mwmp/GUIChat.cpp | 2 +- apps/openmw/mwmp/GUIController.cpp | 4 ++-- apps/openmw/mwmp/LocalPlayer.cpp | 36 +++++++++++++++--------------- apps/openmw/mwmp/Main.cpp | 4 ++-- apps/openmw/mwmp/Networking.cpp | 19 +++++++++++----- apps/openmw/mwmp/Networking.hpp | 8 +++++-- 6 files changed, 42 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwmp/GUIChat.cpp b/apps/openmw/mwmp/GUIChat.cpp index 1e83fd21d..fda7012a3 100644 --- a/apps/openmw/mwmp/GUIChat.cpp +++ b/apps/openmw/mwmp/GUIChat.cpp @@ -129,7 +129,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 087f22d8d..dbc20aa89 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -109,7 +109,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; @@ -155,7 +155,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 ccb0b74d7..5fe974e42 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -89,7 +89,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) { @@ -98,11 +98,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);*/ } @@ -127,7 +127,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; @@ -162,7 +162,7 @@ void LocalPlayer::updateDynamicStats(bool forceUpdate) timer = 0; - GetNetworking()->GetPacket(ID_GAME_DYNAMICSTATS)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_DYNAMICSTATS)->Send(this); } } } @@ -184,7 +184,7 @@ void LocalPlayer::updateAttributes(bool forceUpdate) if (isUpdating || forceUpdate) { - GetNetworking()->GetPacket(ID_GAME_ATTRIBUTE)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_ATTRIBUTE)->Send(this); } } @@ -220,7 +220,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); } } @@ -232,7 +232,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 @@ -272,7 +272,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)) { @@ -284,7 +284,7 @@ void LocalPlayer::updatePosition(bool forceUpdate) { sentJumpEnd = true; (*Position()) = ptrPos; - GetNetworking()->GetPacket(ID_GAME_POS)->Send(this); + GetNetworking()->GetPlayerPacket(ID_GAME_POS)->Send(this); } } @@ -333,7 +333,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 @@ -396,7 +396,7 @@ void LocalPlayer::updateInventory(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); invChanged = false; } @@ -426,7 +426,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) @@ -457,7 +457,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; } @@ -524,7 +524,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,7 +695,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) @@ -713,7 +713,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); } @@ -744,6 +744,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 d14945545..46e9ab7c0 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -24,7 +24,7 @@ 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 +32,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; } @@ -178,7 +180,7 @@ 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]) { @@ -409,7 +411,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) myPacket->Send(getLocalPlayer(), serverAddr); getLocalPlayer()->updateDynamicStats(true); - controller.GetPacket(ID_GAME_DYNAMICSTATS)->Send(getLocalPlayer(), serverAddr); + playerController.GetPacket(ID_GAME_DYNAMICSTATS)->Send(getLocalPlayer(), serverAddr); } else if (pl != 0) { @@ -618,9 +620,14 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) } } -PlayerPacket *Networking::GetPacket(RakNet::MessageID id) +PlayerPacket *Networking::GetPlayerPacket(RakNet::MessageID id) { - return controller.GetPacket(id); + return playerController.GetPacket(id); +} + +WorldPacket *Networking::GetWorldPacket(RakNet::MessageID id) +{ + return worldController.GetPacket(id); } LocalPlayer *Networking::getLocalPlayer() diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index f9b06794c..fff9703b2 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -20,6 +20,7 @@ #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); @@ -51,7 +54,8 @@ namespace mwmp RakNet::SystemAddress serverAddr; RakNet::BitStream bsOut; - PlayerPacketController controller; + PlayerPacketController playerController; + WorldPacketController worldController; void ReceiveMessage(RakNet::Packet *packet); LocalPlayer *getLocalPlayer();