-
Notifications
You must be signed in to change notification settings - Fork 1k
/
protocolgame.h
340 lines (268 loc) · 12.5 KB
/
protocolgame.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
// Copyright 2022 The Forgotten Server Authors. All rights reserved.
// Use of this source code is governed by the GPL-2.0 License that can be found in the LICENSE file.
#ifndef FS_PROTOCOLGAME_H
#define FS_PROTOCOLGAME_H
#include "chat.h"
#include "creature.h"
#include "protocol.h"
#include "tasks.h"
class Container;
class Game;
class NetworkMessage;
class Player;
class ProtocolGame;
class Quest;
class Tile;
class TrackedQuest;
enum SessionEndTypes_t : uint8_t {
SESSION_END_LOGOUT = 0,
SESSION_END_UNKNOWN = 1, // unknown, no difference from logout
SESSION_END_FORCECLOSE = 2,
SESSION_END_UNKNOWN2 = 3, // unknown, no difference from logout
};
using ProtocolGame_ptr = std::shared_ptr<ProtocolGame>;
extern Game g_game;
struct TextMessage
{
MessageClasses type = MESSAGE_STATUS_DEFAULT;
std::string text;
Position position;
uint16_t channelId;
struct {
int32_t value = 0;
TextColor_t color;
} primary, secondary;
TextMessage() = default;
TextMessage(MessageClasses type, std::string text) : type(type), text(std::move(text)) {}
};
class ProtocolGame final : public Protocol
{
public:
// static protocol information
enum {server_sends_first = true};
enum {protocol_identifier = 0}; // Not required as we send first
enum {use_checksum = true};
static const char* protocol_name() {
return "gameworld protocol";
}
explicit ProtocolGame(Connection_ptr connection) : Protocol(connection) {}
void login(const std::string& name, uint32_t accountId, OperatingSystem_t operatingSystem);
void logout(bool displayEffect, bool forced);
uint16_t getVersion() const {
return version;
}
private:
ProtocolGame_ptr getThis() {
return std::static_pointer_cast<ProtocolGame>(shared_from_this());
}
void connect(uint32_t playerId, OperatingSystem_t operatingSystem);
void disconnectClient(const std::string& message) const;
void writeToOutputBuffer(const NetworkMessage& msg);
void release() override;
void checkCreatureAsKnown(uint32_t id, bool& known, uint32_t& removedKnown);
bool canSee(int32_t x, int32_t y, int32_t z) const;
bool canSee(const Creature*) const;
bool canSee(const Position& pos) const;
// we have all the parse methods
void parsePacket(NetworkMessage& msg) override;
void onRecvFirstMessage(NetworkMessage& msg) override;
void onConnect() override;
//Parse methods
void parseAutoWalk(NetworkMessage& msg);
void parseSetOutfit(NetworkMessage& msg);
void parseEditPodiumRequest(NetworkMessage& msg);
void parseSay(NetworkMessage& msg);
void parseLookAt(NetworkMessage& msg);
void parseLookInBattleList(NetworkMessage& msg);
void parseFightModes(NetworkMessage& msg);
void parseAttack(NetworkMessage& msg);
void parseFollow(NetworkMessage& msg);
void parseEquipObject(NetworkMessage& msg);
void parseBugReport(NetworkMessage& msg);
void parseDebugAssert(NetworkMessage& msg);
void parseRuleViolationReport(NetworkMessage& msg);
void parseThrow(NetworkMessage& msg);
void parseUseItemEx(NetworkMessage& msg);
void parseUseWithCreature(NetworkMessage& msg);
void parseUseItem(NetworkMessage& msg);
void parseCloseContainer(NetworkMessage& msg);
void parseUpArrowContainer(NetworkMessage& msg);
void parseUpdateContainer(NetworkMessage& msg);
void parseTextWindow(NetworkMessage& msg);
void parseHouseWindow(NetworkMessage& msg);
void parseWrapItem(NetworkMessage& msg);
void parseLookInShop(NetworkMessage& msg);
void parsePlayerPurchase(NetworkMessage& msg);
void parsePlayerSale(NetworkMessage& msg);
void parseQuestLine(NetworkMessage& msg);
void parseQuestTracker(NetworkMessage& msg);
void parseInviteToParty(NetworkMessage& msg);
void parseJoinParty(NetworkMessage& msg);
void parseRevokePartyInvite(NetworkMessage& msg);
void parsePassPartyLeadership(NetworkMessage& msg);
void parseEnableSharedPartyExperience(NetworkMessage& msg);
void parseToggleMount(NetworkMessage& msg);
void parseModalWindowAnswer(NetworkMessage& msg);
void parseBrowseField(NetworkMessage& msg);
void parseSeekInContainer(NetworkMessage& msg);
//trade methods
void parseRequestTrade(NetworkMessage& msg);
void parseLookInTrade(NetworkMessage& msg);
//market methods
void parseMarketLeave();
void parseMarketBrowse(NetworkMessage& msg);
void parseMarketCreateOffer(NetworkMessage& msg);
void parseMarketCancelOffer(NetworkMessage& msg);
void parseMarketAcceptOffer(NetworkMessage& msg);
//VIP methods
void parseAddVip(NetworkMessage& msg);
void parseRemoveVip(NetworkMessage& msg);
void parseEditVip(NetworkMessage& msg);
void parseRotateItem(NetworkMessage& msg);
//Channel tabs
void parseChannelInvite(NetworkMessage& msg);
void parseChannelExclude(NetworkMessage& msg);
void parseOpenChannel(NetworkMessage& msg);
void parseOpenPrivateChannel(NetworkMessage& msg);
void parseCloseChannel(NetworkMessage& msg);
//Send functions
void sendChannelMessage(const std::string& author, const std::string& text, SpeakClasses type, uint16_t channel);
void sendChannelEvent(uint16_t channelId, const std::string& playerName, ChannelEvent_t channelEvent);
void sendClosePrivate(uint16_t channelId);
void sendCreatePrivateChannel(uint16_t channelId, const std::string& channelName);
void sendChannelsDialog();
void sendChannel(uint16_t channelId, const std::string& channelName, const UsersMap* channelUsers, const InvitedMap* invitedUsers);
void sendOpenPrivateChannel(const std::string& receiver);
void sendToChannel(const Creature* creature, SpeakClasses type, const std::string& text, uint16_t channelId);
void sendPrivateMessage(const Player* speaker, SpeakClasses type, const std::string& text);
void sendIcons(uint32_t icons);
void sendFYIBox(const std::string& message);
void sendDistanceShoot(const Position& from, const Position& to, uint8_t type);
void sendMagicEffect(const Position& pos, uint8_t type);
void sendCreatureHealth(const Creature* creature);
void sendSkills();
void sendPing();
void sendPingBack();
void sendCreatureTurn(const Creature* creature, uint32_t stackPos);
void sendCreatureSay(const Creature* creature, SpeakClasses type, const std::string& text, const Position* pos = nullptr);
void sendQuestLog();
void sendQuestLine(const Quest* quest);
void sendQuestTracker();
void sendUpdateQuestTracker(const TrackedQuest& trackedQuest);
void sendCancelWalk();
void sendChangeSpeed(const Creature* creature, uint32_t speed);
void sendCancelTarget();
void sendCreatureOutfit(const Creature* creature, const Outfit_t& outfit);
void sendStats();
void sendExperienceTracker(int64_t rawExp, int64_t finalExp);
void sendClientFeatures();
void sendBasicData();
void sendTextMessage(const TextMessage& message);
void sendReLoginWindow(uint8_t unfairFightReduction);
void sendTutorial(uint8_t tutorialId);
void sendAddMarker(const Position& pos, uint8_t markType, const std::string& desc);
void sendCreatureWalkthrough(const Creature* creature, bool walkthrough);
void sendCreatureShield(const Creature* creature);
void sendCreatureSkull(const Creature* creature);
void sendShop(Npc* npc, const ShopInfoList& itemList);
void sendCloseShop();
void sendSaleItemList(const std::list<ShopInfo>& shop);
void sendResourceBalance(const ResourceTypes_t resourceType, uint64_t amount);
void sendStoreBalance();
void sendMarketEnter(uint32_t depotId);
void sendMarketLeave();
void sendMarketBrowseItem(uint16_t itemId, const MarketOfferList& buyOffers, const MarketOfferList& sellOffers);
void sendMarketAcceptOffer(const MarketOfferEx& offer);
void sendMarketBrowseOwnOffers(const MarketOfferList& buyOffers, const MarketOfferList& sellOffers);
void sendMarketCancelOffer(const MarketOfferEx& offer);
void sendMarketBrowseOwnHistory(const HistoryMarketOfferList& buyOffers, const HistoryMarketOfferList& sellOffers);
void sendTradeItemRequest(const std::string& traderName, const Item* item, bool ack);
void sendCloseTrade();
void sendTextWindow(uint32_t windowTextId, Item* item, uint16_t maxlen, bool canWrite);
void sendTextWindow(uint32_t windowTextId, uint32_t itemId, const std::string& text);
void sendHouseWindow(uint32_t windowTextId, const std::string& text);
void sendOutfitWindow();
void sendPodiumWindow(const Item* item);
void sendUpdatedVIPStatus(uint32_t guid, VipStatus_t newStatus);
void sendVIP(uint32_t guid, const std::string& name, const std::string& description, uint32_t icon, bool notify, VipStatus_t status);
void sendVIPEntries();
void sendItemClasses();
void sendPendingStateEntered();
void sendEnterWorld();
void sendFightModes();
void sendCreatureLight(const Creature* creature);
void sendWorldLight(LightInfo lightInfo);
void sendWorldTime();
void sendCreatureSquare(const Creature* creature, SquareColor_t color);
void sendSpellCooldown(uint8_t spellId, uint32_t time);
void sendSpellGroupCooldown(SpellGroup_t groupId, uint32_t time);
void sendUseItemCooldown(uint32_t time);
//tiles
void sendMapDescription(const Position& pos);
void sendAddTileItem(const Position& pos, uint32_t stackpos, const Item* item);
void sendUpdateTileItem(const Position& pos, uint32_t stackpos, const Item* item);
void sendRemoveTileThing(const Position& pos, uint32_t stackpos);
void sendUpdateTileCreature(const Position& pos, uint32_t stackpos, const Creature* creature);
void sendRemoveTileCreature(const Creature* creature, const Position& pos, uint32_t stackpos);
void sendUpdateTile(const Tile* tile, const Position& pos);
void sendAddCreature(const Creature* creature, const Position& pos, int32_t stackpos, MagicEffectClasses magicEffect = CONST_ME_NONE);
void sendMoveCreature(const Creature* creature, const Position& newPos, int32_t newStackPos,
const Position& oldPos, int32_t oldStackPos, bool teleport);
//containers
void sendAddContainerItem(uint8_t cid, uint16_t slot, const Item* item);
void sendUpdateContainerItem(uint8_t cid, uint16_t slot, const Item* item);
void sendRemoveContainerItem(uint8_t cid, uint16_t slot, const Item* lastItem);
void sendContainer(uint8_t cid, const Container* container, bool hasParent, uint16_t firstIndex);
void sendEmptyContainer(uint8_t cid);
void sendCloseContainer(uint8_t cid);
//inventory
void sendInventoryItem(slots_t slot, const Item* item);
void sendItems();
//messages
void sendModalWindow(const ModalWindow& modalWindow);
//session end
void sendSessionEnd(SessionEndTypes_t reason);
//Help functions
// translate a tile to client-readable format
void GetTileDescription(const Tile* tile, NetworkMessage& msg);
// translate a floor to client-readable format
void GetFloorDescription(NetworkMessage& msg, int32_t x, int32_t y, int32_t z,
int32_t width, int32_t height, int32_t offset, int32_t& skip);
// translate a map area to client-readable format
void GetMapDescription(int32_t x, int32_t y, int32_t z,
int32_t width, int32_t height, NetworkMessage& msg);
void AddCreature(NetworkMessage& msg, const Creature* creature, bool known, uint32_t remove);
void AddPlayerStats(NetworkMessage& msg);
void AddOutfit(NetworkMessage& msg, const Outfit_t& outfit);
void AddPlayerSkills(NetworkMessage& msg);
void AddWorldLight(NetworkMessage& msg, LightInfo lightInfo);
void AddCreatureLight(NetworkMessage& msg, const Creature* creature);
//tiles
static void RemoveTileThing(NetworkMessage& msg, const Position& pos, uint32_t stackpos);
static void RemoveTileCreature(NetworkMessage& msg, const Creature* creature, const Position& pos, uint32_t stackpos);
void MoveUpCreature(NetworkMessage& msg, const Creature* creature, const Position& newPos, const Position& oldPos);
void MoveDownCreature(NetworkMessage& msg, const Creature* creature, const Position& newPos, const Position& oldPos);
//shop
void AddShopItem(NetworkMessage& msg, const ShopInfo& item);
//otclient
void parseExtendedOpcode(NetworkMessage& msg);
friend class Player;
// Helpers so we don't need to bind every time
template <typename Callable>
void addGameTask(Callable&& function) {
g_dispatcher.addTask(createTask(std::forward<Callable>(function)));
}
template <typename Callable>
void addGameTaskTimed(uint32_t delay, Callable&& function) {
g_dispatcher.addTask(createTask(delay, std::forward<Callable>(function)));
}
std::unordered_set<uint32_t> knownCreatureSet;
Player* player = nullptr;
uint32_t eventConnect = 0;
uint32_t challengeTimestamp = 0;
uint16_t version = CLIENT_VERSION_MIN;
uint8_t challengeRandom = 0;
bool debugAssertSent = false;
bool acceptPackets = false;
};
#endif // FS_PROTOCOLGAME_H