GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/chatrecv.cpp Lines: 2 394 0.5 %
Date: 2021-03-17 Branches: 2 381 0.5 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2019  The ManaPlus Developers
6
 *  Copyright (C) 2019-2021  Andrei Karas
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#include "net/eathena/chatrecv.h"
25
26
#include "actormanager.h"
27
#include "notifymanager.h"
28
29
#include "being/localplayer.h"
30
#include "being/playerinfo.h"
31
#include "being/playerrelation.h"
32
#include "being/playerrelations.h"
33
34
#include "const/gui/chat.h"
35
36
#include "enums/resources/notifytypes.h"
37
38
#include "gui/windows/chatwindow.h"
39
40
#include "gui/widgets/tabs/chat/chattab.h"
41
42
#include "net/messagein.h"
43
44
#include "net/ea/chatrecv.h"
45
46
#include "net/eathena/mercenaryrecv.h"
47
48
#include "resources/chatobject.h"
49
#include "utils/gettext.h"
50
#include "utils/stringutils.h"
51
52
#include "debug.h"
53
54
extern int packetVersion;
55
56
namespace EAthena
57
{
58
59
namespace ChatRecv
60
{
61
1
    std::string mChatRoom;
62
}  // namespace ChatRecv
63
64
void ChatRecv::processIgnoreNickAck(Net::MessageIn &msg)
65
{
66
    const int type = msg.readUInt8("type");
67
    const int flag = msg.readUInt8("flag");
68
    switch (type)
69
    {
70
        case 0:
71
            switch (flag)
72
            {
73
                case 0:
74
                    NotifyManager::notify(NotifyTypes::IGNORE_PLAYER_SUCCESS);
75
                    break;
76
                case 1:
77
                    NotifyManager::notify(NotifyTypes::IGNORE_PLAYER_FAILURE);
78
                    break;
79
                case 2:
80
                    NotifyManager::notify(NotifyTypes::IGNORE_PLAYER_TOO_MANY);
81
                    break;
82
                default:
83
                    NotifyManager::notify(NotifyTypes::IGNORE_PLAYER_UNKNOWN);
84
                    break;
85
            }
86
            break;
87
        case 1:
88
            switch (flag)
89
            {
90
                case 0:
91
                    NotifyManager::notify(
92
                        NotifyTypes::UNIGNORE_PLAYER_SUCCESS);
93
                    break;
94
                case 1:
95
                    NotifyManager::notify(
96
                        NotifyTypes::UNIGNORE_PLAYER_FAILURE);
97
                    break;
98
                default:
99
                    NotifyManager::notify(
100
                        NotifyTypes::UNIGNORE_PLAYER_UNKNOWN);
101
                    break;
102
            }
103
            break;
104
105
        default:
106
            NotifyManager::notify(NotifyTypes::IGNORE_PLAYER_TYPE_UNKNOWN);
107
            break;
108
    }
109
}
110
111
void ChatRecv::processChat(Net::MessageIn &msg)
112
{
113
    BLOCK_START("ChatRecv::processChat")
114
    const int chatMsgLength = msg.readInt16("len") - 4;
115
    if (chatMsgLength <= 0)
116
    {
117
        BLOCK_END("ChatRecv::processChat")
118
        return;
119
    }
120
121
    processChatContinue(msg.readRawString(chatMsgLength, "message"),
122
        ChatMsgType::BY_PLAYER);
123
}
124
125
void ChatRecv::processFormatMessage(Net::MessageIn &msg)
126
{
127
    const int msgId = msg.readInt16("msg id");
128
    // +++ here need load message from configuration file
129
    std::string chatMsg;
130
    if (msgId >= 1266 && msgId <= 1269)
131
    {
132
        MercenaryRecv::handleMercenaryMessage(msgId - 1266);
133
        return;
134
    }
135
    switch (msgId)
136
    {
137
        case 1334:
138
            // TRANSLATORS: error message
139
            chatMsg = _("Can't cast skill in this area.");
140
            break;
141
        case 1335:
142
            // TRANSLATORS: error message
143
            chatMsg = _("Can't use item in this area.");
144
            break;
145
        case 1773:
146
            // TRANSLATORS: error message
147
            chatMsg = _("Can't equip. Wrong level.");
148
            break;
149
        case 1774:
150
            // TRANSLATORS: error message
151
            chatMsg = _("Can't use. Wrong level.");
152
            break;
153
        case 1923:
154
            // TRANSLATORS: error message
155
            chatMsg = _("Work in progress.");  // busy with npc
156
            break;
157
        default:
158
            chatMsg = strprintf("Message #%d", msgId);
159
            break;
160
    }
161
    processChatContinue(chatMsg, ChatMsgType::BY_SERVER);
162
}
163
164
void ChatRecv::processFormatMessageNumber(Net::MessageIn &msg)
165
{
166
    const int msgId = msg.readInt16("msg id");
167
    const int value = msg.readInt32("value");
168
    if (msgId == 1862)
169
    {
170
        NotifyManager::notify(NotifyTypes::USE_ITEM_WAIT, value);
171
        return;
172
    }
173
    // +++ here need load message from configuration file
174
    const std::string chatMsg = strprintf(
175
        "Message #%d, value: %d", msgId, value);
176
    processChatContinue(chatMsg, ChatMsgType::BY_SERVER);
177
}
178
179
void ChatRecv::processFormatColor(Net::MessageIn &msg)
180
{
181
    const int msgId = msg.readInt16("msg id");
182
    msg.readInt32("color");
183
    // +++ here need load message from configuration file
184
    const std::string chatMsg = strprintf(
185
        "Message #%d", msgId);
186
    processChatContinue(chatMsg, ChatMsgType::BY_SERVER);
187
}
188
189
void ChatRecv::processFormatMessageString(Net::MessageIn &msg)
190
{
191
    const int strLen = msg.readInt16("len") - 6;
192
    const int msgId = msg.readInt16("msg id");
193
    const std::string message = msg.readString(strLen, "value");
194
    // +++ here need load message from configuration file
195
    const std::string chatMsg = strprintf(
196
        "Message #%d, value: %s", msgId, message.c_str());
197
    processChatContinue(chatMsg, ChatMsgType::BY_SERVER);
198
}
199
200
void ChatRecv::processFormatMessageStringColor(Net::MessageIn &msg)
201
{
202
    const int strLen = msg.readInt16("len") - 10;
203
    const int msgId = msg.readInt16("msg id");
204
    if (packetVersion >= 20160406)
205
        msg.readInt32("color");
206
    const std::string message = msg.readString(strLen, "value");
207
    // +++ here need load message from configuration file
208
    const std::string chatMsg = strprintf(
209
        "Message #%d, value: %s", msgId, message.c_str());
210
    processChatContinue(chatMsg, ChatMsgType::BY_SERVER);
211
}
212
213
void ChatRecv::processFormatMessageSkill(Net::MessageIn &msg)
214
{
215
    const int skillId = msg.readInt16("skill id");
216
    const int msgId = msg.readInt32("msg id");
217
    // +++ here need load message from configuration file
218
    const std::string chatMsg = strprintf(
219
        "Message #%d, skill: %d", msgId, skillId);
220
    processChatContinue(chatMsg, ChatMsgType::BY_SERVER);
221
}
222
223
void ChatRecv::processColorChat(Net::MessageIn &msg)
224
{
225
    BLOCK_START("ChatRecv::processChat")
226
    int chatMsgLength = msg.readInt16("len") - 4;
227
    msg.readInt32("unused");
228
    msg.readInt32("chat color");
229
    chatMsgLength -= 8;
230
    if (chatMsgLength <= 0)
231
    {
232
        BLOCK_END("ChatRecv::processChat")
233
        return;
234
    }
235
236
    std::string message = msg.readRawString(chatMsgLength, "message");
237
    std::string msg2 = message;
238
    if (findCutFirst(msg2, "You're now in the '#") && findCutLast(msg2, "'"))
239
    {
240
        const size_t idx = msg2.find("' channel for '");
241
        if (idx != std::string::npos && (chatWindow != nullptr))
242
        {
243
            chatWindow->addChannelTab(std::string("#").append(
244
                msg2.substr(0, idx)), false);
245
            return;
246
        }
247
    }
248
    else
249
    {
250
        const std::string nick = Ea::ChatRecv::getLastWhisperNick();
251
        if (nick.size() > 1 && nick[0] == '#')
252
        {
253
            if (message == strprintf("[ %s ] %s : \302\202\302",
254
                nick.c_str(), localPlayer->getName().c_str()))
255
            {
256
                Ea::ChatRecv::mSentWhispers.pop();
257
            }
258
        }
259
    }
260
    processChatContinue(message, ChatMsgType::BY_UNKNOWN);
261
}
262
263
std::string ChatRecv::extractChannelFromMessage(std::string &chatMsg)
264
{
265
    std::string msg = chatMsg;
266
    std::string channel(GENERAL_CHANNEL);
267
    if (findCutFirst(msg, "[ #"))
268
    {   // found channel message
269
        const size_t idx = msg.find(" ] ");
270
        if (idx != std::string::npos)
271
        {
272
            channel = std::string("#").append(msg.substr(0, idx));
273
            chatMsg = msg.substr(idx + 3);
274
        }
275
    }
276
    return channel;
277
}
278
279
void ChatRecv::processChatContinue(std::string chatMsg,
280
                                   const ChatMsgTypeT own)
281
{
282
    const std::string channel = extractChannelFromMessage(chatMsg);
283
    bool allow(true);
284
    if (chatWindow != nullptr)
285
    {
286
        allow = chatWindow->resortChatLog(chatMsg,
287
            own,
288
            channel,
289
            IgnoreRecord_false,
290
            TryRemoveColors_true);
291
    }
292
293
    const size_t pos = chatMsg.find(" : ", 0);
294
    if (pos != std::string::npos)
295
        chatMsg.erase(0, pos + 3);
296
297
    trim(chatMsg);
298
299
    if (localPlayer != nullptr)
300
    {
301
        if (((chatWindow != nullptr) || Ea::ChatRecv::mShowMotd) && allow)
302
            localPlayer->setSpeech(chatMsg);
303
    }
304
    BLOCK_END("ChatRecv::processChat")
305
}
306
307
void ChatRecv::processGmChat(Net::MessageIn &msg)
308
{
309
    BLOCK_START("ChatRecv::processChat")
310
    const int chatMsgLength = msg.readInt16("len") - 4;
311
    if (chatMsgLength <= 0)
312
    {
313
        BLOCK_END("ChatRecv::processChat")
314
        return;
315
    }
316
317
    std::string chatMsg = msg.readRawString(chatMsgLength, "message");
318
    // remove non persistend "colors" from server.
319
    if (!findCutFirst(chatMsg, "ssss"))
320
        findCutFirst(chatMsg, "eulb");
321
322
    if (chatWindow != nullptr)
323
        chatWindow->addGlobalMessage(chatMsg);
324
    BLOCK_END("ChatRecv::processChat")
325
}
326
327
void ChatRecv::processGmChat2(Net::MessageIn &msg)
328
{
329
    const int chatMsgLength = msg.readInt16("len") - 16;
330
    msg.readInt32("font color");
331
    msg.readInt16("font type");
332
    msg.readInt16("font size");
333
    msg.readInt16("font align");
334
    msg.readInt16("font y");
335
    if (chatWindow != nullptr)
336
    {
337
        const std::string chatMsg = msg.readRawString(chatMsgLength,
338
            "message");
339
        chatWindow->addGlobalMessage(chatMsg);
340
    }
341
    else
342
    {
343
        msg.readRawString(chatMsgLength, "message");
344
    }
345
}
346
347
void ChatRecv::processWhisper(Net::MessageIn &msg)
348
{
349
    BLOCK_START("ChatRecv::processWhisper")
350
    int packetLen = 28;
351
    if (msg.getVersion() >= 20091104)
352
        packetLen += 4;
353
    const int chatMsgLength = msg.readInt16("len") - packetLen;
354
    std::string nick = msg.readString(24, "nick");
355
    if (msg.getVersion() >= 20091104)
356
        msg.readInt32("admin flag");
357
358
    if (chatMsgLength <= 0)
359
    {
360
        BLOCK_END("ChatRecv::processWhisper")
361
        return;
362
    }
363
364
    processWhisperContinue(nick, msg.readString(chatMsgLength, "message"));
365
}
366
367
void ChatRecv::processWhisperResponse(Net::MessageIn &msg)
368
{
369
    BLOCK_START("ChatRecv::processWhisperResponse")
370
371
    const uint8_t type = msg.readUInt8("response");
372
    if (msg.getVersion() >= 20131223)
373
        msg.readBeingId("being id");
374
    if (type == 1 && (chatWindow != nullptr))
375
    {
376
        const std::string nick = Ea::ChatRecv::getLastWhisperNick();
377
        if (nick.size() > 1 && nick[0] == '#')
378
        {
379
            chatWindow->channelChatLog(nick,
380
                // TRANSLATORS: chat message
381
                strprintf(_("Message could not be sent, channel "
382
                "%s is not exists."), nick.c_str()),
383
                ChatMsgType::BY_SERVER,
384
                IgnoreRecord_false,
385
                TryRemoveColors_false);
386
            if (!Ea::ChatRecv::mSentWhispers.empty())
387
                Ea::ChatRecv::mSentWhispers.pop();
388
            return;
389
        }
390
    }
391
    Ea::ChatRecv::processWhisperResponseContinue(msg, type);
392
}
393
394
void ChatRecv::processChatIgnoreList(Net::MessageIn &msg)
395
{
396
    UNIMPLEMENTEDPACKET;
397
    // +++ need put it in some object or window
398
    const int count = (msg.readInt16("len") - 4) / 24;
399
    for (int f = 0; f < count; f ++)
400
        msg.readString(24, "nick");
401
}
402
403
void ChatRecv::processChatDisplay(Net::MessageIn &msg)
404
{
405
    if (actorManager == nullptr)
406
        return;
407
    const int len = msg.readInt16("len") - 17;
408
    ChatObject *const obj = new ChatObject;
409
    obj->ownerId = msg.readBeingId("owner account id");
410
    obj->chatId = msg.readInt32("chat id");
411
    obj->maxUsers = msg.readInt16("max users");
412
    obj->currentUsers = msg.readInt16("current users");
413
    obj->type = msg.readUInt8("type");
414
    obj->title = msg.readString(len, "title");
415
    obj->update();
416
417
    Being *const dstBeing = actorManager->findBeing(obj->ownerId);
418
    if (dstBeing != nullptr)
419
        dstBeing->setChat(obj);
420
}
421
422
void ChatRecv::processChatRoomJoinAck(Net::MessageIn &msg)
423
{
424
    const int count = (msg.readInt16("len") - 8) / 28;
425
    const int id = msg.readInt32("chat id");
426
427
    // +++ ignore chat members for now
428
    for (int f = 0; f < count; f ++)
429
    {
430
        msg.readInt32("role");
431
        msg.readString(24, "name");
432
    }
433
434
    const ChatObject *const oldChat = ChatObject::findById(id);
435
436
    if (oldChat != nullptr)
437
        PlayerInfo::setRoomName(oldChat->title);
438
    else
439
        PlayerInfo::setRoomName(std::string());
440
    chatWindow->joinRoom(true);
441
    ChatObject *const obj = new ChatObject;
442
    if (oldChat != nullptr)
443
    {
444
        obj->ownerId = oldChat->ownerId;
445
        obj->chatId = oldChat->chatId;
446
        obj->maxUsers = oldChat->maxUsers;
447
        obj->currentUsers = oldChat->currentUsers;
448
        obj->type = oldChat->type;
449
        obj->title = oldChat->title;
450
//        obj->update();
451
    }
452
    localPlayer->setChat(obj);
453
}
454
455
void ChatRecv::processChatRoomLeave(Net::MessageIn &msg)
456
{
457
    if (actorManager == nullptr)
458
        return;
459
    msg.readInt16("users");
460
    const std::string name = msg.readString(24, "name");
461
    const int status = msg.readUInt8("flag");  // 0 - left, 1 - kicked
462
    switch (status)
463
    {
464
        case 0:
465
            NotifyManager::notify(NotifyTypes::ROOM_LEAVE, name);
466
            break;
467
        case 1:
468
            NotifyManager::notify(NotifyTypes::ROOM_KICKED, name);
469
            break;
470
        default:
471
            UNIMPLEMENTEDPACKETFIELD(status);
472
            break;
473
    }
474
    if ((localPlayer != nullptr) && name == localPlayer->getName())
475
    {
476
        if (chatWindow != nullptr)
477
            chatWindow->joinRoom(false);
478
        PlayerInfo::setRoomName(std::string());
479
        if (localPlayer != nullptr)
480
            localPlayer->setChat(nullptr);
481
    }
482
    else
483
    {
484
        Being *const being = actorManager->findBeingByName(
485
            name, ActorType::Player);
486
        if (being != nullptr)
487
            being->setChat(nullptr);
488
    }
489
}
490
491
void ChatRecv::processJoinChannel(Net::MessageIn &msg)
492
{
493
    if (chatWindow == nullptr)
494
        return;
495
496
    const std::string channel = msg.readString(24, "channel name");
497
    const int flag = msg.readUInt8("flag");
498
499
    if (channel.size() < 2)
500
        return;
501
    switch (flag)
502
    {
503
        case 0:
504
        default:
505
            chatWindow->channelChatLog(channel,
506
                // TRANSLATORS: chat message
507
                strprintf(_("Can't open channel. Channel "
508
                "%s is not exists."), channel.c_str()),
509
                ChatMsgType::BY_SERVER,
510
                IgnoreRecord_false,
511
                TryRemoveColors_false);
512
            break;
513
514
        case 1:
515
        case 2:
516
            chatWindow->addChannelTab(std::string("#").append(
517
                channel.substr(1)), false);
518
            break;
519
    }
520
}
521
522
void ChatRecv::processWhisperContinue(const std::string &nick,
523
                                      std::string chatMsg)
524
{
525
    // ignoring future whisper messages
526
    if (chatMsg.find("\302\202G") == 0 || chatMsg.find("\302\202A") == 0)
527
    {
528
        BLOCK_END("ChatRecv::processWhisper")
529
        return;
530
    }
531
    // remove first unicode space if this is may be whisper command.
532
    if (chatMsg.find("\302\202!") == 0)
533
        chatMsg = chatMsg.substr(2);
534
535
    if (nick != "Server")
536
    {
537
        if (playerRelations.hasPermission(nick, PlayerRelation::WHISPER))
538
        {
539
            chatWindow->addWhisper(nick,
540
                chatMsg,
541
                ChatMsgType::BY_OTHER);
542
        }
543
    }
544
    else if (localChatTab != nullptr)
545
    {
546
        localChatTab->chatLog(chatMsg,
547
            ChatMsgType::BY_SERVER,
548
            IgnoreRecord_false,
549
            TryRemoveColors_true);
550
    }
551
    BLOCK_END("ChatRecv::processWhisper")
552
}
553
554
void ChatRecv::processBeingChat(Net::MessageIn &msg)
555
{
556
    if (actorManager == nullptr)
557
        return;
558
559
    BLOCK_START("ChatRecv::processBeingChat")
560
    const int chatMsgLength = msg.readInt16("len") - 8;
561
    Being *const being = actorManager->findBeing(msg.readBeingId("being id"));
562
563
    if (chatMsgLength <= 0)
564
    {
565
        BLOCK_END("ChatRecv::processBeingChat")
566
        return;
567
    }
568
569
    std::string chatMsg = msg.readRawString(chatMsgLength, "message");
570
571
    if ((being != nullptr) && being->getType() == ActorType::Player)
572
        being->setTalkTime();
573
574
    const size_t pos = chatMsg.find(" : ", 0);
575
    std::string sender_name = ((pos == std::string::npos)
576
        ? "" : chatMsg.substr(0, pos));
577
578
    if ((being != nullptr) && sender_name != being->getName()
579
        && being->getType() == ActorType::Player)
580
    {
581
        if (!being->getName().empty())
582
            sender_name = being->getName();
583
    }
584
    else
585
    {
586
        chatMsg.erase(0, pos + 3);
587
    }
588
589
    trim(chatMsg);
590
591
    bool allow(true);
592
    // We use getIgnorePlayer instead of ignoringPlayer here
593
    // because ignorePlayer' side effects are triggered
594
    // right below for Being::IGNORE_SPEECH_FLOAT.
595
    if ((playerRelations.checkPermissionSilently(sender_name,
596
        PlayerRelation::SPEECH_LOG) != 0U) && (chatWindow != nullptr))
597
    {
598
        allow = chatWindow->resortChatLog(
599
            removeColors(sender_name).append(" : ").append(chatMsg),
600
            ChatMsgType::BY_OTHER,
601
            GENERAL_CHANNEL,
602
            IgnoreRecord_false,
603
            TryRemoveColors_true);
604
    }
605
606
    if (allow &&
607
        being != nullptr &&
608
        playerRelations.hasPermission(sender_name,
609
        PlayerRelation::SPEECH_FLOAT))
610
    {
611
        being->setSpeech(chatMsg);
612
    }
613
    BLOCK_END("ChatRecv::processBeingChat")
614
}
615
616
void ChatRecv::processChatRoomCreateAck(Net::MessageIn &msg)
617
{
618
    const int result = msg.readUInt8("flag");
619
    switch (result)
620
    {
621
        case 0:
622
        {
623
            PlayerInfo::setRoomName(mChatRoom);
624
            chatWindow->joinRoom(true);
625
            ChatObject *const obj = new ChatObject;
626
            obj->ownerId = localPlayer->getId();
627
            obj->chatId = 0;
628
            obj->maxUsers = 1000;
629
            obj->currentUsers = 1;
630
            obj->type = 1;
631
            obj->title = mChatRoom;
632
            obj->update();
633
            localPlayer->setChat(obj);
634
            break;
635
        }
636
        case 1:
637
            NotifyManager::notify(NotifyTypes::ROOM_LIMIT_EXCEEDED);
638
            break;
639
        case 2:
640
            NotifyManager::notify(NotifyTypes::ROOM_ALREADY_EXISTS);
641
            break;
642
        default:
643
            UNIMPLEMENTEDPACKETFIELD(result);
644
            break;
645
    }
646
    mChatRoom.clear();
647
}
648
649
void ChatRecv::processChatRoomDestroy(Net::MessageIn &msg)
650
{
651
    const int chatId = msg.readInt32("chat id");
652
    if (actorManager == nullptr)
653
        return;
654
    actorManager->removeRoom(chatId);
655
}
656
657
void ChatRecv::processChatRoomJoinFailed(Net::MessageIn &msg)
658
{
659
    const int result = msg.readUInt8("flag");
660
    switch (result)
661
    {
662
        case 0:
663
            NotifyManager::notify(NotifyTypes::ROOM_ERROR_FULL);
664
            break;
665
        case 1:
666
            NotifyManager::notify(NotifyTypes::ROOM_ERROR_WRONG_PASSWORD);
667
            break;
668
        case 2:
669
            NotifyManager::notify(NotifyTypes::ROOM_ERROR_KICKED);
670
            break;
671
        case 3:
672
            break;
673
        case 4:
674
            NotifyManager::notify(NotifyTypes::ROOM_ERROR_ZENY);
675
            break;
676
        case 5:
677
            NotifyManager::notify(NotifyTypes::ROOM_ERROR_LOW_LEVEL);
678
            break;
679
        case 6:
680
            NotifyManager::notify(NotifyTypes::ROOM_ERROR_HIGH_LEVEL);
681
            break;
682
        case 7:
683
            NotifyManager::notify(NotifyTypes::ROOM_ERROR_RACE);
684
            break;
685
        default:
686
            UNIMPLEMENTEDPACKETFIELD(result);
687
            break;
688
    }
689
}
690
691
void ChatRecv::processChatRoomAddMember(Net::MessageIn &msg)
692
{
693
    msg.readInt16("users");
694
    const std::string name = msg.readString(24, "name");
695
    if (localChatTab == nullptr)
696
        return;
697
    NotifyManager::notify(NotifyTypes::ROOM_JOINED, name);
698
}
699
700
void ChatRecv::processChatRoomSettings(Net::MessageIn &msg)
701
{
702
    const int sz = msg.readInt16("len") - 17;
703
    const BeingId ownerId = msg.readBeingId("owner id");
704
    const int chatId = msg.readInt32("chat id");
705
    const uint16_t limit = msg.readInt16("limit");
706
    msg.readInt16("users");
707
    const uint8_t type = msg.readUInt8("type");
708
    const std::string &title = msg.readString(sz, "title");
709
    ChatObject *const chat = localPlayer->getChat();
710
    if ((chat != nullptr) && chat->chatId == chatId)
711
    {
712
        chat->ownerId = ownerId;
713
        chat->maxUsers = limit;
714
        chat->type = type;
715
        if (chat->title != title)
716
        {
717
            chat->title = title;
718
            if (actorManager != nullptr)
719
                actorManager->updateRoom(chat);
720
            if (chatWindow != nullptr)
721
                chatWindow->joinRoom(true);
722
        }
723
    }
724
}
725
726
void ChatRecv::processChatRoomRoleChange(Net::MessageIn &msg)
727
{
728
    const int role = msg.readInt32("role");
729
    const std::string name = msg.readString(24, "name");
730
    switch (role)
731
    {
732
        case 0:
733
            NotifyManager::notify(NotifyTypes::ROOM_ROLE_OWNER, name);
734
            break;
735
        case 1:
736
            // dont show normal role
737
            break;
738
        default:
739
            UNIMPLEMENTEDPACKETFIELD(role);
740
            break;
741
    }
742
}
743
744
void ChatRecv::processMVPItem(Net::MessageIn &msg)
745
{
746
    UNIMPLEMENTEDPACKET;
747
    msg.readItemId("item id");
748
}
749
750
void ChatRecv::processMVPExp(Net::MessageIn &msg)
751
{
752
    UNIMPLEMENTEDPACKET;
753
    msg.readInt32("exp");
754
}
755
756
void ChatRecv::processMVPNoItem(Net::MessageIn &msg)
757
{
758
    UNIMPLEMENTEDPACKET;
759
}
760
761
void ChatRecv::processMannerMessage(Net::MessageIn &msg)
762
{
763
    const int result = msg.readInt32("type");
764
    switch (result)
765
    {
766
        case 0:
767
            NotifyManager::notify(NotifyTypes::MANNER_CHANGED);
768
            break;
769
        case 5:
770
            break;
771
        default:
772
            UNIMPLEMENTEDPACKETFIELD(result);
773
            break;
774
    }
775
}
776
777
void ChatRecv::processChatSilence(Net::MessageIn &msg)
778
{
779
    const int result = msg.readUInt8("type");
780
    const std::string name = msg.readString(24, "gm name");
781
782
    switch (result)
783
    {
784
        case 0:
785
            NotifyManager::notify(NotifyTypes::MANNER_POSITIVE_POINTS, name);
786
            break;
787
        case 1:
788
            NotifyManager::notify(NotifyTypes::MANNER_NEGATIVE_POINTS, name);
789
            break;
790
        default:
791
            UNIMPLEMENTEDPACKETFIELD(result);
792
            break;
793
    }
794
}
795
796
void ChatRecv::processChatTalkieBox(Net::MessageIn &msg)
797
{
798
    msg.readBeingId("being id");
799
    const std::string message = msg.readString(80, "message");
800
    localChatTab->chatLog(message,
801
        ChatMsgType::BY_SERVER,
802
        IgnoreRecord_false,
803
        TryRemoveColors_true);
804
}
805
806
void ChatRecv::processBattleChatMessage(Net::MessageIn &msg)
807
{
808
    UNIMPLEMENTEDPACKET;
809
    const int sz = msg.readInt16("len") - 24 - 8;
810
    msg.readBeingId("account id");
811
    msg.readString(24, "nick");
812
    msg.readString(sz, "message");
813
}
814
815
void ChatRecv::processScriptMessage(Net::MessageIn &msg)
816
{
817
    const int sz = msg.readInt16("len") - 8;
818
    msg.readBeingId("being id");
819
    const std::string message = msg.readString(sz, "message");
820
    localChatTab->chatLog(message,
821
        ChatMsgType::BY_SERVER,
822
        IgnoreRecord_false,
823
        TryRemoveColors_true);
824
}
825
826
void ChatRecv::processServiceMessageColor(Net::MessageIn &msg)
827
{
828
    const int sz = msg.readInt16("len") - 8;
829
    msg.readInt32("color");
830
    const std::string message = msg.readString(sz, "message");
831
    localChatTab->chatLog(message,
832
        ChatMsgType::BY_SERVER,
833
        IgnoreRecord_false,
834
        TryRemoveColors_true);
835
}
836
837

3
}  // namespace EAthena