Rename client Networking's GetPacket method into GetPlayerPacket

This commit is contained in:
David Cernat 2016-10-19 22:49:35 +03:00
parent e27d1857ef
commit f218613231
6 changed files with 42 additions and 31 deletions

View file

@ -129,7 +129,7 @@ namespace mwmp
*localPlayer->ChatMessage() = str; *localPlayer->ChatMessage() = str;
RakNet::BitStream bs; RakNet::BitStream bs;
networking->GetPacket(ID_CHAT_MESSAGE)->Packet(&bs, localPlayer, true); networking->GetPlayerPacket(ID_CHAT_MESSAGE)->Packet(&bs, localPlayer, true);
networking->SendData(&bs); networking->SendData(&bs);
} }

View file

@ -109,7 +109,7 @@ void mwmp::GUIController::OnInputBoxDone(MWGui::WindowBase *parWindow)
printf("GUIController::OnInputBoxDone: %s.\n",mInputBox->getTextInput().c_str()); printf("GUIController::OnInputBoxDone: %s.\n",mInputBox->getTextInput().c_str());
Main::get().getLocalPlayer()->guiMessageBox.data = mInputBox->getTextInput(); 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); MWBase::Environment::get().getWindowManager()->removeDialog(mInputBox);
mInputBox = 0; mInputBox = 0;
@ -155,7 +155,7 @@ void mwmp::GUIController::update(float dt)
printf("Pressed: %d\n", pressedButton); printf("Pressed: %d\n", pressedButton);
calledMessageBox = false; calledMessageBox = false;
Main::get().getLocalPlayer()->guiMessageBox.data = MyGUI::utility::toString(pressedButton); 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());
} }
} }

View file

@ -89,7 +89,7 @@ bool LocalPlayer::charGenThread() // todo: need fix
(*BirthSign()) = world->getPlayer().getBirthSign(); (*BirthSign()) = world->getPlayer().getBirthSign();
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_BASE_INFO to server with my CharGen info"); 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) if (CharGenStage()->end != 1)
{ {
@ -98,11 +98,11 @@ bool LocalPlayer::charGenThread() // todo: need fix
updateSkills(true); updateSkills(true);
updateLevel(true); updateLevel(true);
sendClass(); sendClass();
GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this); GetNetworking()->GetPlayerPacket(ID_GAME_CHARGEN)->Send(this);
} }
CharGenStage()->end = 0; CharGenStage()->end = 0;
/*RakNet::BitStream bs; /*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);*/ GetNetworking()->SendData(&bs);*/
} }
@ -127,7 +127,7 @@ bool LocalPlayer::charGenThread() // todo: need fix
windowManager->pushGuiMode(MWGui::GM_Review); windowManager->pushGuiMode(MWGui::GM_Review);
break; break;
} }
GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this); GetNetworking()->GetPlayerPacket(ID_GAME_CHARGEN)->Send(this);
CharGenStage()->current++; CharGenStage()->current++;
return false; return false;
@ -162,7 +162,7 @@ void LocalPlayer::updateDynamicStats(bool forceUpdate)
timer = 0; 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) 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) if (isUpdating || forceUpdate)
{ {
NpcStats()->mLevelProgress = ptrNpcStats.getLevelProgress(); 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) if (ptrNpcStats.getLevel() != CreatureStats()->mLevel || forceUpdate)
{ {
CreatureStats()->mLevel = ptrNpcStats.getLevel(); 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 // Also update skills to refresh level progress and attribute bonuses
// for next level up // for next level up
@ -272,7 +272,7 @@ void LocalPlayer::updatePosition(bool forceUpdate)
Dir()->pos[1] = move.mPosition[1]; Dir()->pos[1] = move.mPosition[1];
Dir()->pos[2] = move.mPosition[2]; 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)) else if (isJumping && world->isOnGround(player))
{ {
@ -284,7 +284,7 @@ void LocalPlayer::updatePosition(bool forceUpdate)
{ {
sentJumpEnd = true; sentJumpEnd = true;
(*Position()) = ptrPos; (*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); updatePosition(true);
RakNet::BitStream bs; 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); GetNetworking()->SendData(&bs);
// Also update skill progress // Also update skill progress
@ -396,7 +396,7 @@ void LocalPlayer::updateInventory(bool forceUpdate)
{ {
RakNet::BitStream bs; RakNet::BitStream bs;
bs.ResetWritePointer(); 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); GetNetworking()->SendData(&bs);
invChanged = false; invChanged = false;
} }
@ -426,7 +426,7 @@ void LocalPlayer::updateAttackState(bool forceUpdate)
GetAttack()->refid = spell; GetAttack()->refid = spell;
/*RakNet::BitStream bs; /*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);*/ GetNetworking()->SendData(&bs);*/
} }
else if (state == MWMechanics::DrawState_Weapon) else if (state == MWMechanics::DrawState_Weapon)
@ -457,7 +457,7 @@ void LocalPlayer::updateDeadState(bool forceUpdate)
{ {
CreatureStats()->mDead = true; CreatureStats()->mDead = true;
RakNet::BitStream bs; 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); GetNetworking()->SendData(&bs);
isDead = true; isDead = true;
} }
@ -524,7 +524,7 @@ void LocalPlayer::updateDrawStateAndFlags(bool forceUpdate)
mwmp::Main::get().getLocalPlayer()->updatePosition(true); // fix position after jump; mwmp::Main::get().getLocalPlayer()->updatePosition(true); // fix position after jump;
RakNet::BitStream bs; 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); GetNetworking()->SendData(&bs);
//timer = 0; //timer = 0;
} }
@ -695,7 +695,7 @@ void LocalPlayer::sendClass()
else else
charClass.mId = cls->mId; charClass.mId = cls->mId;
GetNetworking()->GetPacket(ID_GAME_CHARCLASS)->Send(this); GetNetworking()->GetPlayerPacket(ID_GAME_CHARCLASS)->Send(this);
} }
void LocalPlayer::sendAttack(char type) void LocalPlayer::sendAttack(char type)
@ -713,7 +713,7 @@ void LocalPlayer::sendAttack(char type)
GetAttack()->type = type; GetAttack()->type = type;
GetAttack()->pressed = false; GetAttack()->pressed = false;
RakNet::BitStream bs; 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); GetNetworking()->SendData(&bs);
} }
@ -744,6 +744,6 @@ void LocalPlayer::prepareAttack(char type, bool state)
GetAttack()->attacker = guid; GetAttack()->attacker = guid;
RakNet::BitStream bs; 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); GetNetworking()->SendData(&bs);
} }

View file

@ -189,8 +189,8 @@ void Main::UpdateWorld(float dt) const
init = false; init = false;
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_BASE_INFO to server"); LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s", "Sending ID_GAME_BASE_INFO to server");
mNetworking->GetPacket(ID_GAME_BASE_INFO)->Send(getLocalPlayer()); mNetworking->GetPlayerPacket(ID_GAME_BASE_INFO)->Send(getLocalPlayer());
mNetworking->GetPacket(ID_LOADED)->Send(getLocalPlayer()); mNetworking->GetPlayerPacket(ID_LOADED)->Send(getLocalPlayer());
mLocalPlayer->updateDynamicStats(true); mLocalPlayer->updateDynamicStats(true);
get().getGUIController()->setChatVisible(true); get().getGUIController()->setChatVisible(true);
} }

View file

@ -24,7 +24,7 @@
using namespace std; using namespace std;
using namespace mwmp; using namespace mwmp;
Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), controller(peer) Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), playerController(peer), worldController(peer)
{ {
RakNet::SocketDescriptor sd; RakNet::SocketDescriptor sd;
@ -32,7 +32,9 @@ Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), control
RakNet::StartupResult b = peer->Startup(1,&sd, 1); RakNet::StartupResult b = peer->Startup(1,&sd, 1);
RakAssert(b==RAKNET_STARTED); RakAssert(b==RAKNET_STARTED);
controller.SetStream(0, &bsOut); playerController.SetStream(0, &bsOut);
worldController.SetStream(0, &bsOut);
connected = 0; connected = 0;
} }
@ -178,7 +180,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
if (id != myid) if (id != myid)
pl = Players::GetPlayer(id); pl = Players::GetPlayer(id);
PlayerPacket *myPacket = controller.GetPacket(packet->data[0]); PlayerPacket *myPacket = playerController.GetPacket(packet->data[0]);
switch (packet->data[0]) switch (packet->data[0])
{ {
@ -409,7 +411,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
myPacket->Send(getLocalPlayer(), serverAddr); myPacket->Send(getLocalPlayer(), serverAddr);
getLocalPlayer()->updateDynamicStats(true); getLocalPlayer()->updateDynamicStats(true);
controller.GetPacket(ID_GAME_DYNAMICSTATS)->Send(getLocalPlayer(), serverAddr); playerController.GetPacket(ID_GAME_DYNAMICSTATS)->Send(getLocalPlayer(), serverAddr);
} }
else if (pl != 0) 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() LocalPlayer *Networking::getLocalPlayer()

View file

@ -20,6 +20,7 @@
#include <components/openmw-mp/Packets/Player/PacketCell.hpp> #include <components/openmw-mp/Packets/Player/PacketCell.hpp>
#include <components/openmw-mp/Packets/Player/PacketDrawState.hpp> #include <components/openmw-mp/Packets/Player/PacketDrawState.hpp>
#include <components/openmw-mp/Controllers/PlayerPacketController.hpp> #include <components/openmw-mp/Controllers/PlayerPacketController.hpp>
#include <components/openmw-mp/Controllers/WorldPacketController.hpp>
namespace mwmp namespace mwmp
{ {
@ -33,7 +34,9 @@ namespace mwmp
void Connect(const std::string& ip, unsigned short port); void Connect(const std::string& ip, unsigned short port);
void Update(); void Update();
void SendData(RakNet::BitStream *bitStream); 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 isDedicatedPlayer(const MWWorld::Ptr &ptr);
bool Attack(const MWWorld::Ptr &ptr); bool Attack(const MWWorld::Ptr &ptr);
@ -51,7 +54,8 @@ namespace mwmp
RakNet::SystemAddress serverAddr; RakNet::SystemAddress serverAddr;
RakNet::BitStream bsOut; RakNet::BitStream bsOut;
PlayerPacketController controller; PlayerPacketController playerController;
WorldPacketController worldController;
void ReceiveMessage(RakNet::Packet *packet); void ReceiveMessage(RakNet::Packet *packet);
LocalPlayer *getLocalPlayer(); LocalPlayer *getLocalPlayer();