Otclient 1.0  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  {
31  messageModesMap.clear();
32 
33  if(version >= 1094) {
35  }
36 
37  if(version >= 1055) { // might be 1054
56  messageModesMap[Otc::MessageWarning] = 18; // Admin
81  } else if(version >= 1036) {
82  for(int i = Otc::MessageNone; i <= Otc::MessageBeyondLast; ++i) {
83  if(i >= Otc::MessageNpcTo)
84  messageModesMap[i] = i + 1;
85  else
86  messageModesMap[i] = i;
87  }
88  } else if(version >= 900) {
89  for(int i = Otc::MessageNone; i <= Otc::MessageBeyondLast; ++i)
90  messageModesMap[i] = i;
91  } else if(version >= 861) {
117  } else if(version >= 840) {
136  // 16, 17 ??
147  } else if(version >= 760) {
163  // 13, 14, 15 ??
174  }
175  }
176 
178  {
179  auto it = std::find_if(messageModesMap.begin(), messageModesMap.end(), [=](const std::pair<uint8, uint8>& p) { return p.second == mode; });
180  if(it != messageModesMap.end())
181  return static_cast<Otc::MessageMode>(it->first);
182  return Otc::MessageInvalid;
183  }
184 
186  {
187  if(mode < 0 || mode >= Otc::LastMessage)
188  return Otc::MessageInvalid;
189  const auto it = messageModesMap.find(mode);
190  if(it != messageModesMap.end())
191  return it->second;
192  return Otc::MessageInvalid;
193  }
194 
195 }
protocolcodes.h
Otc::MessageBarkLow
@ MessageBarkLow
Definition: const.h:343
Otc::MessageRVRChannel
@ MessageRVRChannel
Definition: const.h:358
Otc::MessageParty
@ MessageParty
Definition: const.h:342
Otc::MessageThankyou
@ MessageThankyou
Definition: const.h:348
Otc::MessageRed
@ MessageRed
Definition: const.h:356
Otc::MessagePrivateFrom
@ MessagePrivateFrom
Definition: const.h:313
Otc::MessageWarning
@ MessageWarning
Definition: const.h:326
Otc::MessageStatus
@ MessageStatus
Definition: const.h:337
Otc::MessageRVRContinue
@ MessageRVRContinue
Definition: const.h:360
Otc::MessageChannel
@ MessageChannel
Definition: const.h:316
Otc::MessageLook
@ MessageLook
Definition: const.h:329
Otc::MessageSay
@ MessageSay
Definition: const.h:310
Otc::MessageHotkeyUse
@ MessageHotkeyUse
Definition: const.h:346
Otc::MessageNpcFrom
@ MessageNpcFrom
Definition: const.h:319
Otc::MessageMana
@ MessageMana
Definition: const.h:350
Otc::MessageTutorialHint
@ MessageTutorialHint
Definition: const.h:347
Otc::MessageGamemasterChannel
@ MessageGamemasterChannel
Definition: const.h:322
Otc::MessageHeal
@ MessageHeal
Definition: const.h:332
Otc::MessageGameHighlight
@ MessageGameHighlight
Definition: const.h:361
Otc::MessageNpcTo
@ MessageNpcTo
Definition: const.h:320
Proto::buildMessageModesMap
void buildMessageModesMap(int version)
Definition: protocolcodes.cpp:29
Otc::MessageGamemasterPrivateFrom
@ MessageGamemasterPrivateFrom
Definition: const.h:323
Otc::MessageYell
@ MessageYell
Definition: const.h:312
Otc::MessageBeyondLast
@ MessageBeyondLast
Definition: const.h:351
Otc::MessageInvalid
@ MessageInvalid
Definition: const.h:364
Otc::MessageExp
@ MessageExp
Definition: const.h:333
Proto::translateMessageModeFromServer
Otc::MessageMode translateMessageModeFromServer(uint8 mode)
Definition: protocolcodes.cpp:177
Otc::MessageMode
MessageMode
Definition: const.h:308
Otc::MessageBarkLoud
@ MessageBarkLoud
Definition: const.h:344
Proto::translateMessageModeToServer
uint8 translateMessageModeToServer(Otc::MessageMode mode)
Definition: protocolcodes.cpp:185
Otc::MessageNone
@ MessageNone
Definition: const.h:309
Proto::messageModesMap
std::map< uint8, uint8 > messageModesMap
Definition: protocolcodes.cpp:27
Otc::MessageGamemasterBroadcast
@ MessageGamemasterBroadcast
Definition: const.h:321
Otc::MessageLoot
@ MessageLoot
Definition: const.h:338
Otc::LastMessage
@ LastMessage
Definition: const.h:363
Otc::MessageRVRAnswer
@ MessageRVRAnswer
Definition: const.h:359
Otc::MessageExpOthers
@ MessageExpOthers
Definition: const.h:336
Proto
Definition: protocolcodes.cpp:25
Otc::MessageTradeNpc
@ MessageTradeNpc
Definition: const.h:339
Otc::MessageGuild
@ MessageGuild
Definition: const.h:340
Otc::MessageDamageOthers
@ MessageDamageOthers
Definition: const.h:334
Otc::MessageChannelHighlight
@ MessageChannelHighlight
Definition: const.h:317
Otc::MessageReport
@ MessageReport
Definition: const.h:345
Otc::MessageDamageDealed
@ MessageDamageDealed
Definition: const.h:330
Otc::MessageLogin
@ MessageLogin
Definition: const.h:325
Otc::MessageGame
@ MessageGame
Definition: const.h:327
Otc::MessageGamemasterPrivateTo
@ MessageGamemasterPrivateTo
Definition: const.h:324
Otc::MessageBlue
@ MessageBlue
Definition: const.h:357
Otc::MessageMonsterSay
@ MessageMonsterSay
Definition: const.h:355
Otc::MessagePartyManagement
@ MessagePartyManagement
Definition: const.h:341
Otc::MessageDamageReceived
@ MessageDamageReceived
Definition: const.h:331
Otc::MessageWhisper
@ MessageWhisper
Definition: const.h:311
Otc::MessageFailure
@ MessageFailure
Definition: const.h:328
Otc::MessagePrivateTo
@ MessagePrivateTo
Definition: const.h:314
Otc::MessageChannelManagement
@ MessageChannelManagement
Definition: const.h:315
Otc::MessageNpcFromStartBlock
@ MessageNpcFromStartBlock
Definition: const.h:362
Otc::MessageMonsterYell
@ MessageMonsterYell
Definition: const.h:354
Otc::MessageMarket
@ MessageMarket
Definition: const.h:349
uint8
uint8_t uint8
Definition: types.h:37
Otc::MessageHealOthers
@ MessageHealOthers
Definition: const.h:335
Otc::MessageSpell
@ MessageSpell
Definition: const.h:318