From 57a0415ba3de26e406a64bd4911ee123ed14b217 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 18 Nov 2017 03:55:17 +0200 Subject: [PATCH] [Server] Send level packets in Player's update() at the appropriate time Previously, trying to send a level packet after base info and character class packets in a script actually led to the level packet being sent first and then being overridden by the others, with the player ending up at level 1 on their client. --- apps/openmw-mp/NetActor.cpp | 5 +++-- apps/openmw-mp/NetActor.hpp | 2 +- apps/openmw-mp/Player.cpp | 13 +++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/openmw-mp/NetActor.cpp b/apps/openmw-mp/NetActor.cpp index e2da6c23e..dffc2fc85 100644 --- a/apps/openmw-mp/NetActor.cpp +++ b/apps/openmw-mp/NetActor.cpp @@ -19,11 +19,12 @@ NetActor::NetActor() : inventory(this), cellAPI(this) void NetActor::resetUpdateFlags() { + baseInfoChanged = false; + levelChanged = false; statsChanged = false; + positionChanged = false; skillsChanged = false; attributesChanged = false; - baseInfoChanged = false; - positionChanged = false; } std::tuple NetActor::getPosition() const diff --git a/apps/openmw-mp/NetActor.hpp b/apps/openmw-mp/NetActor.hpp index b9e637388..4b3afedd3 100644 --- a/apps/openmw-mp/NetActor.hpp +++ b/apps/openmw-mp/NetActor.hpp @@ -64,7 +64,7 @@ public: mwmp::BaseNetCreature *getNetCreature() { return netCreature; } protected: - bool statsChanged, attributesChanged, skillsChanged, baseInfoChanged, positionChanged; + bool baseInfoChanged, levelChanged, statsChanged, positionChanged, attributesChanged, skillsChanged; mwmp::BasePlayer *basePlayer; mwmp::BaseNetCreature *netCreature; diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index 03e1d5dbf..319cc7214 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -123,6 +123,14 @@ void Player::update() // The character class can override values from below on the client, so send it first cClass.update(); + if (levelChanged) + { + auto packet = plPCtrl->GetPacket(ID_PLAYER_LEVEL); + packet->setPlayer(basePlayer); + packet->Send(false); + packet->Send(true); + } + if (statsChanged) { auto packet = plPCtrl->GetPacket(ID_PLAYER_STATS_DYNAMIC); @@ -356,10 +364,7 @@ void Player::setIsMale(bool male) void Player::setLevel(int level) { creatureStats.mLevel = level; - auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_LEVEL); - packet->setPlayer(this); - packet->Send(false); - packet->Send(true); + levelChanged = true; } int Player::getLevel() const