Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
WorldStateBuilder.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef SF_WORLDSTATE_BUILDER_H
7#define SF_WORLDSTATE_BUILDER_H
8
9#include "WorldPacket.h"
10#include "WorldSession.h"
11
12#include <map>
13
14// This builder had to be created because blizzard is swaping worldstate with value therefore a big rewrite would be needed everytime
16{
17public:
18 WorldStateBuilder(uint32 mapId, uint32 areaId, uint32 zoneId, std::map<uint32, uint32> wstateList = std::map<uint32, uint32>()) :
19 _mapId(mapId), _zoneId(zoneId), _areaId(areaId), _wstateList(wstateList) {}
20
22 {
23 WorldPacket data(SMSG_INIT_WORLD_STATES, 4 + 4 + 4 + 3 + (_wstateList.size() * (4 + 4)));
24 data << uint32(_mapId);
25 data << uint32(_areaId);
26 data << uint32(_zoneId);
27 data.WriteBits(_wstateList.size(), 21);
28 data.FlushBits();
29
30 for (std::map<uint32, uint32>::const_iterator iter = _wstateList.begin(); iter != _wstateList.end(); ++iter)
31 data << uint32(iter->second) << uint32(iter->first);
32
33 return data;
34 }
35
36 void SendPacket(WorldSession* session)
37 {
38 WorldPacket data = BuildPacket();
39 session->SendPacket(&data);
40 }
41
42 void AppendState(uint32 worldstate, uint32 value) { _wstateList.insert(std::make_pair(worldstate, value)); }
43
44private:
48 std::map<uint32, uint32> _wstateList;
49};
50#endif
std::uint32_t uint32
Definition Define.h:77
void WriteBits(T value, size_t bits)
Definition ByteBuffer.h:192
void FlushBits()
Definition ByteBuffer.h:154
Player session in the World.
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
void SendPacket(WorldSession *session)
void AppendState(uint32 worldstate, uint32 value)
std::map< uint32, uint32 > _wstateList
WorldPacket BuildPacket() const
WorldStateBuilder(uint32 mapId, uint32 areaId, uint32 zoneId, std::map< uint32, uint32 > wstateList=std::map< uint32, uint32 >())
@ SMSG_INIT_WORLD_STATES
Definition Opcodes.h:720