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) {
34  }
35 
36  if(version >= 1055) { // might be 1054
55  messageModesMap[Otc::MessageWarning] = 18; // Admin
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) {
116  } else if(version >= 840) {
135  // 16, 17 ??
146  } else if(version >= 760) {
162  // 13, 14, 15 ??
173  }
174 }
175 
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 
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