Skip to content

Commit

Permalink
[Core/Packet] Split SMSG_WEATHER to MiscPackets (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
leelf00 authored Aug 26, 2024
1 parent 3c12a1c commit f2b1aae
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 17 deletions.
14 changes: 14 additions & 0 deletions src/server/game/Server/Packets/MiscPackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@

#include "MiscPackets.h"

WorldPackets::Misc::Weather::Weather() : ServerPacket(SMSG_WEATHER, 4 + 4 + 1) { }

WorldPackets::Misc::Weather::Weather(WeatherState weatherID, float intensity /*= 0.0f*/, bool abrupt /*= false*/)
: ServerPacket(SMSG_WEATHER, 4 + 4 + 1), Abrupt(abrupt), Intensity(intensity), WeatherID(weatherID) { }

WorldPacket const* WorldPackets::Misc::Weather::Write()
{
_worldPacket << uint32(WeatherID);
_worldPacket << float(Intensity);
_worldPacket << uint8(Abrupt);

return &_worldPacket;
}

WorldPacket const* WorldPackets::Misc::StartMirrorTimer::Write()
{
_worldPacket << MaxValue;
Expand Down
15 changes: 15 additions & 0 deletions src/server/game/Server/Packets/MiscPackets.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,25 @@
#include "Packet.h"
#include <array>

enum WeatherState : uint32;

namespace WorldPackets
{
namespace Misc
{
class TC_GAME_API Weather final : public ServerPacket
{
public:
Weather();
Weather(WeatherState weatherID, float intensity = 0.0f, bool abrupt = false);

WorldPacket const* Write() override;

bool Abrupt = false;
float Intensity = 0.0f;
WeatherState WeatherID = WeatherState(0);
};

class StartMirrorTimer final : public ServerPacket
{
public:
Expand Down
27 changes: 15 additions & 12 deletions src/server/game/Weather/Weather.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
* This file is part of the Legends of Azeroth Pandaria Project. See THANKS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
Expand All @@ -20,15 +20,16 @@
*/

#include "Weather.h"
#include "GameTime.h"
#include "WorldPacket.h"
#include "Player.h"
#include "World.h"
#include "Log.h"
#include "MiscPackets.h"
#include "ObjectMgr.h"
#include "Util.h"
#include "ScriptMgr.h"
#include "Opcodes.h"
#include "WorldSession.h"

/// Create the Weather object
Weather::Weather(uint32 zone, WeatherData const* weatherChances)
Expand Down Expand Up @@ -193,19 +194,19 @@ bool Weather::ReGenerate()

void Weather::SendWeatherUpdateToPlayer(Player* player)
{
WorldPacket data(SMSG_WEATHER, (4+4+4));
WorldPackets::Misc::Weather weather(GetWeatherState(), m_grade);
player->SendDirectMessage(weather.Write());
}

data << uint32(GetWeatherState()) << (float)m_grade << uint8(0);
player->GetSession()->SendPacket(&data);
void Weather::SendFineWeatherUpdateToPlayer(Player* player)
{
WorldPackets::Misc::Weather weather(WEATHER_STATE_FINE);
player->SendDirectMessage(weather.Write());
}

/// Send the new weather to all players in the zone
bool Weather::UpdateWeather()
{
Player* player = sWorld->FindPlayerInZone(m_zone);
if (!player)
return false;

///- Send the weather packet to all players in this zone
if (m_grade >= 1)
m_grade = 0.9999f;
Expand All @@ -214,9 +215,11 @@ bool Weather::UpdateWeather()

WeatherState state = GetWeatherState();

WorldPacket data(SMSG_WEATHER, (4+4+4));
data << uint32(state) << (float)m_grade << uint8(0);
player->SendMessageToSet(&data, true);
WorldPackets::Misc::Weather weather(state, m_grade);

//- Returns false if there were no players found to update
if (!sWorld->SendZoneMessage(m_zone, weather.Write()))
return false;

///- Log the event
char const* wthstr;
Expand Down
7 changes: 4 additions & 3 deletions src/server/game/Weather/Weather.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
* This file is part of the Legends of Azeroth Pandaria Project. See THANKS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
Expand Down Expand Up @@ -42,7 +42,7 @@ struct WeatherData
uint32 ScriptId;
};

enum WeatherState
enum WeatherState : uint32
{
WEATHER_STATE_FINE = 0,
WEATHER_STATE_FOG = 1, // Used in some instance encounters.
Expand All @@ -62,7 +62,7 @@ enum WeatherState
};

/// Weather for one zone
class Weather
class TC_GAME_API Weather
{
public:

Expand All @@ -74,6 +74,7 @@ class Weather
bool UpdateWeather();

void SendWeatherUpdateToPlayer(Player* player);
static void SendFineWeatherUpdateToPlayer(Player* player);
void SetWeather(WeatherType type, float grade);

/// For which zone is this weather?
Expand Down
7 changes: 6 additions & 1 deletion src/server/game/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2944,9 +2944,11 @@ void World::SendGlobalText(const char* text, WorldSession* self)
}

/// Send a packet to all players (or players selected team) in the zone (except self if mentioned)
void World::SendZoneMessage(uint32 zone, WorldPacket* packet, WorldSession* self, uint32 team)
bool World::SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self, uint32 team)
{
bool foundPlayerToSend = false;
SessionMap::const_iterator itr;

for (itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
{
if (itr->second &&
Expand All @@ -2957,8 +2959,11 @@ void World::SendZoneMessage(uint32 zone, WorldPacket* packet, WorldSession* self
(team == 0 || itr->second->GetPlayer()->GetTeam() == team))
{
itr->second->SendPacket(packet);
foundPlayerToSend = true;
}
}

return foundPlayerToSend;
}

/// Send a System Message to all players in the zone (except self if mentioned)
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/World/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ class TC_GAME_API World
void SendGlobalMessage(WorldPacket* packet, WorldSession* self = 0, uint32 team = 0);
void SendGlobalMessage(WorldPacket* packet, AccountTypes security, WorldSession* self = 0, uint32 team = 0);
void SendGlobalGMMessage(WorldPacket* packet, WorldSession* self = 0, uint32 team = 0);
void SendZoneMessage(uint32 zone, WorldPacket* packet, WorldSession* self = 0, uint32 team = 0);
bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, uint32 team = 0);
void SendZoneText(uint32 zone, const char *text, WorldSession* self = 0, uint32 team = 0);
void SendServerMessage(ServerMessageType type, const char *text = "", Player* player = NULL);

Expand Down

0 comments on commit f2b1aae

Please sign in to comment.