aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Server/Packets/HotfixPackets.cpp
blob: ca3c0628fbf46294013b2f53c1df94a6396da105 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * This file is part of the TrinityCore Project. See AUTHORS 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
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "HotfixPackets.h"
#include "PacketOperators.h"
#include "PacketUtilities.h"

namespace WorldPackets::Hotfix
{
ByteBuffer& operator>>(ByteBuffer& data, DB2Manager::HotfixId& hotfixId)
{
    data >> hotfixId.PushID;
    data >> hotfixId.UniqueID;

    return data;
}

ByteBuffer& operator<<(ByteBuffer& data, DB2Manager::HotfixId const& hotfixId)
{
    data << int32(hotfixId.PushID);
    data << uint32(hotfixId.UniqueID);

    return data;
}

ByteBuffer& operator>>(ByteBuffer& data, DB2Manager::HotfixRecord& hotfixRecord)
{
    data >> hotfixRecord.ID;
    data >> hotfixRecord.TableHash;
    data >> hotfixRecord.RecordID;

    return data;
}

ByteBuffer& operator<<(ByteBuffer& data, DB2Manager::HotfixRecord const& hotfixRecord)
{
    data << hotfixRecord.ID;
    data << uint32(hotfixRecord.TableHash);
    data << int32(hotfixRecord.RecordID);

    return data;
}

void DBQueryBulk::Read()
{
    _worldPacket >> TableHash;
    _worldPacket >> BitsSize<13>(Queries);

    for (DBQueryRecord& record : Queries)
        _worldPacket >> record.RecordID;
}

WorldPacket const* DBReply::Write()
{
    _worldPacket << uint32(TableHash);
    _worldPacket << uint32(RecordID);
    _worldPacket << uint32(Timestamp);
    _worldPacket << Bits<3>(Status);
    _worldPacket << Size<uint32>(Data);
    _worldPacket.append(Data);

    return &_worldPacket;
}

WorldPacket const* AvailableHotfixes::Write()
{
    _worldPacket.reserve(4 + 4 + sizeof(DB2Manager::HotfixId) * Hotfixes.size());

    _worldPacket << int32(VirtualRealmAddress);
    _worldPacket << Size<uint32>(Hotfixes);
    for (DB2Manager::HotfixId const& hotfixId : Hotfixes)
        _worldPacket << hotfixId;

    return &_worldPacket;
}

void HotfixRequest::Read()
{
    _worldPacket >> ClientBuild;
    _worldPacket >> DataBuild;

    uint32 hotfixCount = _worldPacket.read<uint32>();
    if (hotfixCount > sDB2Manager.GetHotfixCount())
        OnInvalidArraySize(hotfixCount, sDB2Manager.GetHotfixCount());

    Hotfixes.resize(hotfixCount);
    for (int32& hotfixId : Hotfixes)
        _worldPacket >> hotfixId;
}

ByteBuffer& operator<<(ByteBuffer& data, HotfixConnect::HotfixData const& hotfixData)
{
    data << hotfixData.Record;
    data << uint32(hotfixData.Size);
    data << Bits<3>(hotfixData.Record.HotfixStatus);
    data.FlushBits();

    return data;
}

WorldPacket const* HotfixConnect::Write()
{
    _worldPacket << Size<uint32>(Hotfixes);
    for (HotfixData const& hotfix : Hotfixes)
        _worldPacket << hotfix;

    _worldPacket << Size<uint32>(HotfixContent);
    _worldPacket.append(HotfixContent);

    return &_worldPacket;
}
}