diff --git a/skymp5-server/cpp/addon/property_bindings/AppearanceBinding.cpp b/skymp5-server/cpp/addon/property_bindings/AppearanceBinding.cpp index a54c78466e..35f644eec2 100644 --- a/skymp5-server/cpp/addon/property_bindings/AppearanceBinding.cpp +++ b/skymp5-server/cpp/addon/property_bindings/AppearanceBinding.cpp @@ -1,5 +1,6 @@ #include "AppearanceBinding.h" #include "NapiHelper.h" +#include "UpdateAppearanceMessage.h" Napi::Value AppearanceBinding::Get(Napi::Env env, ScampServer& scampServer, uint32_t formId) @@ -34,19 +35,13 @@ void AppearanceBinding::Set(Napi::Env env, ScampServer& scampServer, auto appearance = actor.GetAppearance(); - std::string msg; - msg += Networking::MinPacketId; - msg += nlohmann::json{ - { "data", - appearance ? nlohmann::json::parse(appearance->ToJson()) - : nlohmann::json{} }, - { "idx", actor.GetIdx() }, - { "t", MsgType::UpdateAppearance } - }.dump(); + UpdateAppearanceMessage message; + message.appearance = appearance ? *appearance : std::nullopt; + message.idx = actor.GetIdx(); for (auto listener : actor.GetActorListeners()) { - // TODO: change to SendToUser - listener->SendToUserDeferred(msg.data(), msg.size(), true, - kChannelAppearance, false); + // TODO: change to SendToUser, probably was deferred only for ability to + // send text packets + listener->SendToUserDeferred(message, true, kChannelAppearance, false); } } diff --git a/skymp5-server/cpp/mp_common/NetworkingInterface.h b/skymp5-server/cpp/mp_common/NetworkingInterface.h index bc2dd4488e..e40c1c88e6 100644 --- a/skymp5-server/cpp/mp_common/NetworkingInterface.h +++ b/skymp5-server/cpp/mp_common/NetworkingInterface.h @@ -60,28 +60,4 @@ class IServer : public ISendTarget virtual std::string GetIp(UserId userId) const = 0; }; - -template -inline void Format(const FormatCallback& cb, const char* format, Ts... args) -{ - auto textSize = (size_t)snprintf(nullptr, 0, format, args...); - - const auto n = textSize + sizeof('\0') + sizeof(MinPacketId); - std::vector buf(n); - - buf[0] = MinPacketId; - auto len = (size_t)snprintf(buf.data() + 1, n - 1, format, args...); - - cb(reinterpret_cast(buf.data()), len + 1); -} - -template -inline void SendFormatted(Networking::ISendTarget* sendTarget, - Networking::UserId userId, const char* format, - Ts... args) -{ - Format([&](Networking::PacketData data, - size_t length) { sendTarget->Send(userId, data, length, true); }, - format, args...); -} } diff --git a/skymp5-server/cpp/server_guest_lib/MpActor.cpp b/skymp5-server/cpp/server_guest_lib/MpActor.cpp index efee1f380f..2097e295bf 100644 --- a/skymp5-server/cpp/server_guest_lib/MpActor.cpp +++ b/skymp5-server/cpp/server_guest_lib/MpActor.cpp @@ -400,13 +400,12 @@ void MpActor::SendToUser(const IMessageBase& message, bool reliable) } } -void MpActor::SendToUserDeferred(const void* data, size_t size, bool reliable, +void MpActor::SendToUserDeferred(const IMessageBase& message, bool reliable, int deferredChannelId, bool overwritePreviousChannelMessages) { if (callbacks->sendToUserDeferred) { - callbacks->sendToUserDeferred(this, data, size, reliable, - deferredChannelId, + callbacks->sendToUserDeferred(this, data, reliable, deferredChannelId, overwritePreviousChannelMessages); } else { throw std::runtime_error("sendToUserDeferred is nullptr"); diff --git a/skymp5-server/cpp/server_guest_lib/MpActor.h b/skymp5-server/cpp/server_guest_lib/MpActor.h index 775f0a9468..3a33eb4183 100644 --- a/skymp5-server/cpp/server_guest_lib/MpActor.h +++ b/skymp5-server/cpp/server_guest_lib/MpActor.h @@ -68,7 +68,7 @@ class MpActor : public MpObjectReference void Disable() override; void SendToUser(const IMessageBase& message, bool reliable); - void SendToUserDeferred(const void* data, size_t size, bool reliable, + void SendToUserDeferred(const IMessageBase& message, bool reliable, int deferredChannelId, bool overwritePreviousChannelMessages);