Otclient
14/8/2020
protocolcodes.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
* of this software and associated documentation files (the "Software"), to deal
6
* in the Software without restriction, including without limitation the rights
7
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
* copies of the Software, and to permit persons to whom the Software is
9
* furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
13
*
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
* THE SOFTWARE.
21
*/
22
23
#include "
protocolcodes.h
"
24
25
namespace
Proto
{
26
27
std::map<uint8, uint8>
messageModesMap
;
28
29
void
buildMessageModesMap
(
int
version) {
30
messageModesMap
.clear();
31
32
if
(version >= 1094) {
33
messageModesMap
[
Otc::MessageMana
] = 43;
34
}
35
36
if
(version >= 1055) {
// might be 1054
37
messageModesMap
[
Otc::MessageNone
] = 0;
38
messageModesMap
[
Otc::MessageSay
] = 1;
39
messageModesMap
[
Otc::MessageWhisper
] = 2;
40
messageModesMap
[
Otc::MessageYell
] = 3;
41
messageModesMap
[
Otc::MessagePrivateFrom
] = 4;
42
messageModesMap
[
Otc::MessagePrivateTo
] = 5;
43
messageModesMap
[
Otc::MessageChannelManagement
] = 6;
44
messageModesMap
[
Otc::MessageChannel
] = 7;
45
messageModesMap
[
Otc::MessageChannelHighlight
] = 8;
46
messageModesMap
[
Otc::MessageSpell
] = 9;
47
messageModesMap
[
Otc::MessageNpcFromStartBlock
] = 10;
48
messageModesMap
[
Otc::MessageNpcFrom
] = 11;
49
messageModesMap
[
Otc::MessageNpcTo
] = 12;
50
messageModesMap
[
Otc::MessageGamemasterBroadcast
] = 13;
51
messageModesMap
[
Otc::MessageGamemasterChannel
] = 14;
52
messageModesMap
[
Otc::MessageGamemasterPrivateFrom
] = 15;
53
messageModesMap
[
Otc::MessageGamemasterPrivateTo
] = 16;
54
messageModesMap
[
Otc::MessageLogin
] = 17;
55
messageModesMap
[
Otc::MessageWarning
] = 18;
// Admin
56
messageModesMap
[
Otc::MessageGame
] = 19;
57
messageModesMap
[
Otc::MessageGameHighlight
] = 20;
58
messageModesMap
[
Otc::MessageFailure
] = 21;
59
messageModesMap
[
Otc::MessageLook
] = 22;
60
messageModesMap
[
Otc::MessageDamageDealed
] = 23;
61
messageModesMap
[
Otc::MessageDamageReceived
] = 24;
62
messageModesMap
[
Otc::MessageHeal
] = 25;
63
messageModesMap
[
Otc::MessageExp
] = 26;
64
messageModesMap
[
Otc::MessageDamageOthers
] = 27;
65
messageModesMap
[
Otc::MessageHealOthers
] = 28;
66
messageModesMap
[
Otc::MessageExpOthers
] = 29;
67
messageModesMap
[
Otc::MessageStatus
] = 30;
68
messageModesMap
[
Otc::MessageLoot
] = 31;
69
messageModesMap
[
Otc::MessageTradeNpc
] = 32;
70
messageModesMap
[
Otc::MessageGuild
] = 33;
71
messageModesMap
[
Otc::MessagePartyManagement
] = 34;
72
messageModesMap
[
Otc::MessageParty
] = 35;
73
messageModesMap
[
Otc::MessageBarkLow
] = 36;
74
messageModesMap
[
Otc::MessageBarkLoud
] = 37;
75
messageModesMap
[
Otc::MessageReport
] = 38;
76
messageModesMap
[
Otc::MessageHotkeyUse
] = 39;
77
messageModesMap
[
Otc::MessageTutorialHint
] = 40;
78
messageModesMap
[
Otc::MessageThankyou
] = 41;
79
messageModesMap
[
Otc::MessageMarket
] = 42;
80
}
else
if
(version >= 1036) {
81
for
(
int
i =
Otc::MessageNone
; i <=
Otc::MessageBeyondLast
; ++i) {
82
if
(i >=
Otc::MessageNpcTo
)
83
messageModesMap
[i] = i + 1;
84
else
85
messageModesMap
[i] = i;
86
}
87
}
else
if
(version >= 900) {
88
for
(
int
i =
Otc::MessageNone
; i <=
Otc::MessageBeyondLast
; ++i)
89
messageModesMap
[i] = i;
90
}
else
if
(version >= 861) {
91
messageModesMap
[
Otc::MessageNone
] = 0;
92
messageModesMap
[
Otc::MessageSay
] = 1;
93
messageModesMap
[
Otc::MessageWhisper
] = 2;
94
messageModesMap
[
Otc::MessageYell
] = 3;
95
messageModesMap
[
Otc::MessageNpcTo
] = 4;
96
messageModesMap
[
Otc::MessageNpcFrom
] = 5;
97
messageModesMap
[
Otc::MessagePrivateFrom
] = 6;
98
messageModesMap
[
Otc::MessagePrivateTo
] = 6;
99
messageModesMap
[
Otc::MessageChannel
] = 7;
100
messageModesMap
[
Otc::MessageChannelManagement
] = 8;
101
messageModesMap
[
Otc::MessageGamemasterBroadcast
] = 9;
102
messageModesMap
[
Otc::MessageGamemasterChannel
] = 10;
103
messageModesMap
[
Otc::MessageGamemasterPrivateFrom
] = 11;
104
messageModesMap
[
Otc::MessageGamemasterPrivateTo
] = 11;
105
messageModesMap
[
Otc::MessageChannelHighlight
] = 12;
106
messageModesMap
[
Otc::MessageMonsterSay
] = 13;
107
messageModesMap
[
Otc::MessageMonsterYell
] = 14;
108
messageModesMap
[
Otc::MessageWarning
] = 15;
109
messageModesMap
[
Otc::MessageGame
] = 16;
110
messageModesMap
[
Otc::MessageLogin
] = 17;
111
messageModesMap
[
Otc::MessageStatus
] = 18;
112
messageModesMap
[
Otc::MessageLook
] = 19;
113
messageModesMap
[
Otc::MessageFailure
] = 20;
114
messageModesMap
[
Otc::MessageBlue
] = 21;
115
messageModesMap
[
Otc::MessageRed
] = 22;
116
}
else
if
(version >= 840) {
117
messageModesMap
[
Otc::MessageNone
] = 0;
118
messageModesMap
[
Otc::MessageSay
] = 1;
119
messageModesMap
[
Otc::MessageWhisper
] = 2;
120
messageModesMap
[
Otc::MessageYell
] = 3;
121
messageModesMap
[
Otc::MessageNpcTo
] = 4;
122
messageModesMap
[
Otc::MessageNpcFromStartBlock
] = 5;
123
messageModesMap
[
Otc::MessagePrivateFrom
] = 6;
124
messageModesMap
[
Otc::MessagePrivateTo
] = 6;
125
messageModesMap
[
Otc::MessageChannel
] = 7;
126
messageModesMap
[
Otc::MessageChannelManagement
] = 8;
127
messageModesMap
[
Otc::MessageRVRChannel
] = 9;
128
messageModesMap
[
Otc::MessageRVRAnswer
] = 10;
129
messageModesMap
[
Otc::MessageRVRContinue
] = 11;
130
messageModesMap
[
Otc::MessageGamemasterBroadcast
] = 12;
131
messageModesMap
[
Otc::MessageGamemasterChannel
] = 13;
132
messageModesMap
[
Otc::MessageGamemasterPrivateFrom
] = 14;
133
messageModesMap
[
Otc::MessageGamemasterPrivateTo
] = 14;
134
messageModesMap
[
Otc::MessageChannelHighlight
] = 15;
135
// 16, 17 ??
136
messageModesMap
[
Otc::MessageRed
] = 18;
137
messageModesMap
[
Otc::MessageMonsterSay
] = 19;
138
messageModesMap
[
Otc::MessageMonsterYell
] = 20;
139
messageModesMap
[
Otc::MessageWarning
] = 21;
140
messageModesMap
[
Otc::MessageGame
] = 22;
141
messageModesMap
[
Otc::MessageLogin
] = 23;
142
messageModesMap
[
Otc::MessageStatus
] = 24;
143
messageModesMap
[
Otc::MessageLook
] = 25;
144
messageModesMap
[
Otc::MessageFailure
] = 26;
145
messageModesMap
[
Otc::MessageBlue
] = 27;
146
}
else
if
(version >= 760) {
147
messageModesMap
[
Otc::MessageNone
] = 0;
148
messageModesMap
[
Otc::MessageSay
] = 1;
149
messageModesMap
[
Otc::MessageWhisper
] = 2;
150
messageModesMap
[
Otc::MessageYell
] = 3;
151
messageModesMap
[
Otc::MessagePrivateFrom
] = 4;
152
messageModesMap
[
Otc::MessagePrivateTo
] = 4;
153
messageModesMap
[
Otc::MessageChannel
] = 5;
154
messageModesMap
[
Otc::MessageRVRChannel
] = 6;
155
messageModesMap
[
Otc::MessageRVRAnswer
] = 7;
156
messageModesMap
[
Otc::MessageRVRContinue
] = 8;
157
messageModesMap
[
Otc::MessageGamemasterBroadcast
] = 9;
158
messageModesMap
[
Otc::MessageGamemasterChannel
] = 10;
159
messageModesMap
[
Otc::MessageGamemasterPrivateFrom
] = 11;
160
messageModesMap
[
Otc::MessageGamemasterPrivateTo
] = 11;
161
messageModesMap
[
Otc::MessageChannelHighlight
] = 12;
162
// 13, 14, 15 ??
163
messageModesMap
[
Otc::MessageMonsterSay
] = 16;
164
messageModesMap
[
Otc::MessageMonsterYell
] = 17;
165
messageModesMap
[
Otc::MessageWarning
] = 18;
166
messageModesMap
[
Otc::MessageGame
] = 19;
167
messageModesMap
[
Otc::MessageLogin
] = 20;
168
messageModesMap
[
Otc::MessageStatus
] = 21;
169
messageModesMap
[
Otc::MessageLook
] = 22;
170
messageModesMap
[
Otc::MessageFailure
] = 23;
171
messageModesMap
[
Otc::MessageBlue
] = 24;
172
messageModesMap
[
Otc::MessageRed
] = 25;
173
}
174
}
175
176
Otc::MessageMode
translateMessageModeFromServer
(
uint8
mode)
177
{
178
auto
it = std::find_if(
messageModesMap
.begin(),
messageModesMap
.end(), [=] (
const
std::pair<uint8, uint8>& p) { return p.second == mode; });
179
if
(it !=
messageModesMap
.end())
180
return
(
Otc::MessageMode
)it->first;
181
return
Otc::MessageInvalid
;
182
}
183
184
uint8
translateMessageModeToServer
(
Otc::MessageMode
mode)
185
{
186
if
(mode < 0 || mode >=
Otc::LastMessage
)
187
return
Otc::MessageInvalid
;
188
auto
it =
messageModesMap
.find(mode);
189
if
(it !=
messageModesMap
.end())
190
return
it->second;
191
return
Otc::MessageInvalid
;
192
}
193
194
}
protocolcodes.h
Otc::MessageBarkLow
@ MessageBarkLow
Definition:
const.h:321
Otc::MessageRVRChannel
@ MessageRVRChannel
Definition:
const.h:336
Otc::MessageParty
@ MessageParty
Definition:
const.h:320
Otc::MessageThankyou
@ MessageThankyou
Definition:
const.h:326
Otc::MessageRed
@ MessageRed
Definition:
const.h:334
Otc::MessagePrivateFrom
@ MessagePrivateFrom
Definition:
const.h:291
Otc::MessageWarning
@ MessageWarning
Definition:
const.h:304
Otc::MessageStatus
@ MessageStatus
Definition:
const.h:315
Otc::MessageRVRContinue
@ MessageRVRContinue
Definition:
const.h:338
Otc::MessageChannel
@ MessageChannel
Definition:
const.h:294
Otc::MessageLook
@ MessageLook
Definition:
const.h:307
Otc::MessageSay
@ MessageSay
Definition:
const.h:288
Otc::MessageHotkeyUse
@ MessageHotkeyUse
Definition:
const.h:324
Otc::MessageNpcFrom
@ MessageNpcFrom
Definition:
const.h:297
Otc::MessageMana
@ MessageMana
Definition:
const.h:328
Otc::MessageTutorialHint
@ MessageTutorialHint
Definition:
const.h:325
Otc::MessageGamemasterChannel
@ MessageGamemasterChannel
Definition:
const.h:300
Otc::MessageHeal
@ MessageHeal
Definition:
const.h:310
Otc::MessageGameHighlight
@ MessageGameHighlight
Definition:
const.h:339
Otc::MessageNpcTo
@ MessageNpcTo
Definition:
const.h:298
Proto::buildMessageModesMap
void buildMessageModesMap(int version)
Definition:
protocolcodes.cpp:29
Otc::MessageGamemasterPrivateFrom
@ MessageGamemasterPrivateFrom
Definition:
const.h:301
Otc::MessageYell
@ MessageYell
Definition:
const.h:290
Otc::MessageBeyondLast
@ MessageBeyondLast
Definition:
const.h:329
Otc::MessageInvalid
@ MessageInvalid
Definition:
const.h:342
Otc::MessageExp
@ MessageExp
Definition:
const.h:311
Proto::translateMessageModeFromServer
Otc::MessageMode translateMessageModeFromServer(uint8 mode)
Definition:
protocolcodes.cpp:176
Otc::MessageMode
MessageMode
Definition:
const.h:286
Otc::MessageBarkLoud
@ MessageBarkLoud
Definition:
const.h:322
Proto::translateMessageModeToServer
uint8 translateMessageModeToServer(Otc::MessageMode mode)
Definition:
protocolcodes.cpp:184
Otc::MessageNone
@ MessageNone
Definition:
const.h:287
Proto::messageModesMap
std::map< uint8, uint8 > messageModesMap
Definition:
protocolcodes.cpp:27
Otc::MessageGamemasterBroadcast
@ MessageGamemasterBroadcast
Definition:
const.h:299
Otc::MessageLoot
@ MessageLoot
Definition:
const.h:316
Otc::LastMessage
@ LastMessage
Definition:
const.h:341
Otc::MessageRVRAnswer
@ MessageRVRAnswer
Definition:
const.h:337
Otc::MessageExpOthers
@ MessageExpOthers
Definition:
const.h:314
Proto
Definition:
protocolcodes.cpp:25
Otc::MessageTradeNpc
@ MessageTradeNpc
Definition:
const.h:317
Otc::MessageGuild
@ MessageGuild
Definition:
const.h:318
Otc::MessageDamageOthers
@ MessageDamageOthers
Definition:
const.h:312
Otc::MessageChannelHighlight
@ MessageChannelHighlight
Definition:
const.h:295
Otc::MessageReport
@ MessageReport
Definition:
const.h:323
Otc::MessageDamageDealed
@ MessageDamageDealed
Definition:
const.h:308
Otc::MessageLogin
@ MessageLogin
Definition:
const.h:303
Otc::MessageGame
@ MessageGame
Definition:
const.h:305
Otc::MessageGamemasterPrivateTo
@ MessageGamemasterPrivateTo
Definition:
const.h:302
Otc::MessageBlue
@ MessageBlue
Definition:
const.h:335
Otc::MessageMonsterSay
@ MessageMonsterSay
Definition:
const.h:333
Otc::MessagePartyManagement
@ MessagePartyManagement
Definition:
const.h:319
Otc::MessageDamageReceived
@ MessageDamageReceived
Definition:
const.h:309
Otc::MessageWhisper
@ MessageWhisper
Definition:
const.h:289
Otc::MessageFailure
@ MessageFailure
Definition:
const.h:306
Otc::MessagePrivateTo
@ MessagePrivateTo
Definition:
const.h:292
Otc::MessageChannelManagement
@ MessageChannelManagement
Definition:
const.h:293
Otc::MessageNpcFromStartBlock
@ MessageNpcFromStartBlock
Definition:
const.h:340
Otc::MessageMonsterYell
@ MessageMonsterYell
Definition:
const.h:332
Otc::MessageMarket
@ MessageMarket
Definition:
const.h:327
uint8
uint8_t uint8
Definition:
types.h:37
Otc::MessageHealOthers
@ MessageHealOthers
Definition:
const.h:313
Otc::MessageSpell
@ MessageSpell
Definition:
const.h:296
src
client
protocolcodes.cpp
Generated by
1.8.17
For more information visit
https://forum.opentibia.dev/