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

3
}  // namespace EAthena