summaryrefslogtreecommitdiffstats
path: root/src/chat-server/chathandler.cpp
blob: 6413881621ebeb18a4a6ca8869bc95ceccbf85b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/*
 *  The Mana World Server
 *  Copyright 2004 The Mana World Development Team
 *
 *  This file is part of The Mana World.
 *
 *  The Mana World is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  The Mana World is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with The Mana World; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  $Id$
 */

#include <list>

#include "defines.h"
#include "account-server/characterdata.hpp"
#include "account-server/guild.hpp"
#include "account-server/guildmanager.hpp"
#include "account-server/serverhandler.hpp"
#include "chat-server/chatchannelmanager.hpp"
#include "chat-server/chathandler.hpp"
#include "net/connectionhandler.hpp"
#include "net/messagein.hpp"
#include "net/messageout.hpp"
#include "net/netcomputer.hpp"
#include "utils/logger.h"
#include "utils/stringfilter.h"
#include "utils/tokendispenser.hpp"


class ChatClient : public NetComputer
{
    public:
        /**
         * Constructor.
         */
        ChatClient(ENetPeer *peer);

        std::string characterName;
        AccountLevel accountLevel;
};

ChatClient::ChatClient(ENetPeer *peer):
    NetComputer(peer),
    accountLevel(AL_NORMAL)
{
}

struct ChatPendingLogin
{
    std::string character;
    AccountLevel level;
    int timeout;
};

typedef std::map< std::string, ChatPendingLogin > ChatPendingLogins;
static ChatPendingLogins pendingLogins;

typedef std::map< std::string, ChatClient * > ChatPendingClients;
static ChatPendingClients pendingClients;

void registerChatClient(std::string const &token, std::string const &name, int level)
{
    ChatPendingClients::iterator i = pendingClients.find(token);
    if (i != pendingClients.end())
    {
        ChatClient *computer = i->second;
        computer->characterName = name;
        computer->accountLevel = (AccountLevel) level;
        pendingClients.erase(i);
        MessageOut result;
        result.writeShort(CPMSG_CONNECT_RESPONSE);
        result.writeByte(ERRMSG_OK);
        computer->send(result);
    }
    else
    {
        ChatPendingLogin p;
        p.character = name;
        p.level = (AccountLevel) level;
        p.timeout = 300; // world ticks
        pendingLogins.insert(std::make_pair(token, p));
    }
}

bool
ChatHandler::startListen(enet_uint16 port)
{
    LOG_INFO("Chat handler started:");
    return ConnectionHandler::startListen(port);
}

void ChatHandler::removeOutdatedPending()
{
    ChatPendingLogins::iterator i = pendingLogins.begin(), next;
    while (i != pendingLogins.end())
    {
        next = i; ++next;
        if (--i->second.timeout <= 0) pendingLogins.erase(i);
        i = next;
    }
}

NetComputer *ChatHandler::computerConnected(ENetPeer *peer)
{
    return new ChatClient(peer);
}

void ChatHandler::computerDisconnected(NetComputer *computer)
{
    // Remove user from all channels
    chatChannelManager->removeUserFromAllChannels(((ChatClient*)computer)->characterName);
    ChatPendingClients::iterator i_end = pendingClients.end();
    for (ChatPendingClients::iterator i = pendingClients.begin();
            i != i_end; ++i)
    {
        if (i->second == computer)
        {
            pendingClients.erase(i);
            break;
        }
    }
    delete computer;
}

void ChatHandler::process(enet_uint32 timeout)
{
    ConnectionHandler::process(timeout);
    removeOutdatedPending();
}

void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
{
    ChatClient &computer = *static_cast< ChatClient * >(comp);
    MessageOut result;

    if (computer.characterName.empty())
    {
        if (message.getId() != PCMSG_CONNECT) return;
        std::string magic_token = message.readString(MAGIC_TOKEN_LENGTH);
        ChatPendingLogins::iterator i = pendingLogins.find(magic_token);
        if (i == pendingLogins.end())
        {
            ChatPendingClients::iterator i_end = pendingClients.end();
            for (ChatPendingClients::iterator i = pendingClients.begin();
                 i != i_end; ++i)
            {
                if (i->second == &computer) return;
            }
            pendingClients.insert(std::make_pair(magic_token, &computer));
            return;
        }

        computer.characterName = i->second.character;
        computer.accountLevel = i->second.level;
        pendingLogins.erase(i);
        result.writeShort(CPMSG_CONNECT_RESPONSE);
        result.writeByte(ERRMSG_OK);
        computer.send(result);
        sendGuildRejoin(computer);
        return;
    }

    switch (message.getId())
    {
        case PCMSG_CHAT:
            {
                // chat to people around area
                std::string text = message.readString();
                // If it's slang clean,
                if (stringFilter->filterContent(text))
                {
                    short channel = message.readShort();
                    LOG_DEBUG("Say: (Channel " << channel << "): " << text);
                    // Let's say that channel 0 is the default channel for now.
                    if (channel == 0)
                    {
                        // TODO: I think commands should be / only - BL
                        if (text.substr(0, 1) == "@" ||
                                text.substr(0, 1) == "#" ||
                                text.substr(0, 1) == "/" )
                        {
                            // The message is a command. Deal with it.
                            handleCommand(computer, text);
                        }
                    }
                    else
                    {
                        // We send the message to the players registered in the
                        // channel.
                        sayInChannel(computer, channel, text);
                    }
                }
                else
                {
                    warnPlayerAboutBadWords(computer);
                }
            }
            break;

        case PCMSG_ANNOUNCE:
            {
                std::string text = message.readString();
                // If it's slang's free.
                if (stringFilter->filterContent(text))
                {
                    // We send the message to all players in the default
                    // channel as it is an announce.
                    announce(computer, text);
                }
                else
                {
                    warnPlayerAboutBadWords(computer);
                }
            }
            break;

        case PCMSG_PRIVMSG:
            {
                std::string user = message.readString();
                std::string text = message.readString();
                if (stringFilter->filterContent(text))
                {
                    // We seek the player to whom the message is told
                    // and send it to her/him.
                    sayToPlayer(computer, user, text);
                }
                else
                {
                    warnPlayerAboutBadWords(computer);
                }
            } break;

        // Channels handling
        // =================
        case PCMSG_REGISTER_CHANNEL:
            {
                result.writeShort(CPMSG_REGISTER_CHANNEL_RESPONSE);
                // 0 public, 1 private
                char channelType = message.readByte();
                if (!channelType)
                {
                    if (computer.accountLevel != AL_ADMIN &&
                        computer.accountLevel != AL_GM)
                    {
                    //    Removed the need for admin/gm rights to create public channels
                    //    result.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
                    //    break;
                    }
                }
                std::string channelName = message.readString();
                std::string channelAnnouncement = message.readString();
                std::string channelPassword = message.readString();
                // Checking datas
                // Seeking double-quotes in strings
                if (channelName.empty() || channelName.length() > MAX_CHANNEL_NAME ||
                stringFilter->findDoubleQuotes(channelName))
                {
                        result.writeByte(ERRMSG_INVALID_ARGUMENT);
                        break;
                }
                if (channelAnnouncement.length() > MAX_CHANNEL_ANNOUNCEMENT ||
                    stringFilter->findDoubleQuotes(channelAnnouncement))
                {
                        result.writeByte(ERRMSG_INVALID_ARGUMENT);
                        break;
                }
                if (channelPassword.length() > MAX_CHANNEL_PASSWORD ||
                stringFilter->findDoubleQuotes(channelPassword))
                {
                        result.writeByte(ERRMSG_INVALID_ARGUMENT);
                        break;
                }

                if (guildManager->doesExist(channelName))
                {
                    result.writeByte(ERRMSG_INVALID_ARGUMENT);
                    break;
                }

                // If it's slang's free.
                if (stringFilter->filterContent(channelName) &&
                        stringFilter->filterContent(channelAnnouncement))
                {
                    // We attempt to create a new channel
                    short channelId;
                    if (channelType) {
                        channelId = chatChannelManager->registerPrivateChannel(
                                channelName,
                                channelAnnouncement,
                                channelPassword);
                    }
                    else
                    {
                        channelId = chatChannelManager->registerPublicChannel(
                                channelName,
                                channelAnnouncement,
                                channelPassword);
                    }

                    if (channelId != 0)
                    {
                        // We add the player as admin of this channel as he
                        // created it. The user registering a private channel
                        // is the only one to be able to update the password
                        // and the announcement in it and also to remove it.
                        chatChannelManager->addUserInChannel(
                                computer.characterName, channelId);

                        result.writeByte(ERRMSG_OK);
                        result.writeShort(channelId);
                        result.writeString(channelName);
                        break;
                    }
                    else
                    {
                        result.writeByte(ERRMSG_FAILURE);
                        break;
                    }
                }
                else
                {
                    warnPlayerAboutBadWords(computer);
                }
            }
            break;

        case PCMSG_UNREGISTER_CHANNEL:
            {
                result.writeShort(CPMSG_UNREGISTER_CHANNEL_RESPONSE);

                short channelId = message.readShort();
                std::string channelName = chatChannelManager->getChannelName(channelId);

                // Get character based on name.
                CharacterPtr character = serverHandler->getCharacter(computer.characterName);

                if (!chatChannelManager->channelExists(channelId))
                {
                    result.writeByte(ERRMSG_INVALID_ARGUMENT);
                }
                else if (channelId < (signed) MAX_PUBLIC_CHANNELS_RANGE)
                { // Public channel
                    if (computer.accountLevel == AL_ADMIN || computer.accountLevel == AL_GM)
                    {
                        warnUsersAboutPlayerEventInChat(
                                channelId, "", CHAT_EVENT_LEAVING_PLAYER);
                        if (chatChannelManager->removeChannel(channelId))
                            result.writeByte(ERRMSG_OK);
                        else
                            result.writeByte(ERRMSG_FAILURE);
                    }
                    else if (guildManager->doesExist(channelName))
                    {
                        Guild *guild = guildManager->findByName(channelName);
                        if (guild->checkLeader(character.get()))
                        {
                            chatChannelManager->removeChannel(channelId);
                            guildManager->removeGuild(guild->getId());
                            result.writeByte(ERRMSG_OK);
                        }
                    }
                    else
                    {
                        result.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
                    }
                }
                else
                { // Private channel
                    // We first see if the user is the admin (first user) of
                    // the channel
                    std::vector<std::string> const &userList =
                        chatChannelManager->getUserListInChannel(channelId);
                    std::vector<std::string>::const_iterator i = userList.begin();
                    // If it's actually the private channel's admin
                    if (*i == computer.characterName)
                    {
                        // Make every user quit the channel
                        warnUsersAboutPlayerEventInChat(
                                channelId, "", CHAT_EVENT_LEAVING_PLAYER);
                        if (chatChannelManager->removeChannel(channelId)) {
                            result.writeByte(ERRMSG_OK);
                        }
                        else
                        {
                            result.writeByte(ERRMSG_FAILURE);
                        }
                    }
                    else
                    {
                        result.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
                    }
                }
            } break;

        case PCMSG_ENTER_CHANNEL:
        {
            result.writeShort(CPMSG_ENTER_CHANNEL_RESPONSE);
            std::string channelName = message.readString();
            std::string givenPassword = message.readString();
            short channelId = chatChannelManager->getChannelId(channelName);
            if (channelId != 0 && chatChannelManager->channelExists(channelId))
            {
                std::string channelPassword = chatChannelManager->getChannelPassword(channelId);
                if (!channelPassword.empty())
                {
                    if (channelPassword != givenPassword)
                    {
                        result.writeByte(ERRMSG_INVALID_ARGUMENT);
                        break;
                    }
                }

                if (guildManager->doesExist(channelName))
                {
                    Guild *guild = guildManager->findByName(channelName);
                    if (!guild->checkInGuild(computer.characterName))
                    {
                        result.writeByte(ERRMSG_INVALID_ARGUMENT);
                        break;
                    }
                    sendUserJoined(channelId, computer.characterName);
                }
                if (chatChannelManager->addUserInChannel(computer.characterName, channelId))
                {
                    result.writeByte(ERRMSG_OK);
                    // The user entered the channel, now give him the channel
                    // id, the announcement string and the user list.
                    result.writeShort(channelId);
                    result.writeString(channelName);
                    result.writeString(chatChannelManager->getChannelAnnouncement(channelId));
                    std::vector< std::string > const &userList = 
                        chatChannelManager->getUserListInChannel(channelId);
                    for (std::vector< std::string >::const_iterator i = userList.begin(),
                         i_end = userList.end();
                         i != i_end; ++i) {
                        result.writeString(*i);
                    }
                    // Send an CPMSG_UPDATE_CHANNEL to warn other clients a user went
                    // in the channel.
                    warnUsersAboutPlayerEventInChat(channelId,
                                                    computer.characterName,
                                                    CHAT_EVENT_NEW_PLAYER);
                }
                else
                {
                    result.writeByte(ERRMSG_FAILURE);
                }
            }
            else
            {
                result.writeByte(ERRMSG_INVALID_ARGUMENT);
            }
        }
        break;

        case PCMSG_QUIT_CHANNEL:
        {
            result.writeShort(CPMSG_QUIT_CHANNEL_RESPONSE);
            short channelId = message.readShort();
            std::string channelName = chatChannelManager->getChannelName(channelId);

            if (channelId != 0 && chatChannelManager->channelExists(channelId))
            {
                if (chatChannelManager->removeUserFromChannel(computer.characterName, channelId))
                {
                    result.writeByte(ERRMSG_OK);
                    result.writeShort(channelId);
                    // Send an CPMSG_UPDATE_CHANNEL to warn other clients a
                    // user left the channel.
                    warnUsersAboutPlayerEventInChat(channelId,
                                                    computer.characterName,
                                                    CHAT_EVENT_LEAVING_PLAYER);
                    if (guildManager->doesExist(channelName))
                    {
                        // Send a user left message
                        sendUserLeft(channelId, computer.characterName);
                    }
                }
                else
                {
                    result.writeByte(ERRMSG_FAILURE);
                }
            }
            else
            {
                result.writeByte(ERRMSG_INVALID_ARGUMENT);
            }
        }
        break;

        case PCMSG_LIST_CHANNELS:
        {
            result.writeShort(CPMSG_LIST_CHANNELS_RESPONSE);

            std::list<std::string> publicChannels =
                chatChannelManager->getPublicChannelNames();
            std::list<std::string>::iterator i, i_end;

            for (i = publicChannels.begin(), i_end = publicChannels.end();
                    i != i_end; ++i)
            {
                short users = chatChannelManager->getNumberOfChannelUsers(*i);
                result.writeString(*i);
                result.writeShort(users);
            }
        }
        break;

        case PCMSG_LIST_CHANNELUSERS:
        {
            result.writeShort(CPMSG_LIST_CHANNELUSERS_RESPONSE);

            std::string channelName = message.readString();

            result.writeString(channelName);

            // Get user list
            std::vector<std::string> channelList;
            channelList = chatChannelManager->getUserListInChannel(
                                chatChannelManager->getChannelId(channelName));

            // Add a user at a time
            for (int i = 0; i < channelList.size(); ++i)
            {
                result.writeString(channelList[i]);
            }
        } break;

        case PCMSG_DISCONNECT:
        {
            result.writeShort(CPMSG_DISCONNECT_RESPONSE);
            result.writeByte(ERRMSG_OK);
            chatChannelManager->removeUserFromAllChannels(
                    computer.characterName);
        }
        break;

        default:
            LOG_WARN("ChatHandler::processMessage, Invalid message type"
                     << message.getId());
            result.writeShort(XXMSG_INVALID);
            break;
    }

    if (result.getLength() > 0)
        computer.send(result);
}

void
ChatHandler::handleCommand(ChatClient &computer, std::string const &command)
{
    LOG_INFO("Chat: Received unhandled command: " << command);
    MessageOut result;
    result.writeShort(CPMSG_ERROR);
    result.writeByte(CHAT_UNHANDLED_COMMAND);
    computer.send(result);
}

void
ChatHandler::warnPlayerAboutBadWords(ChatClient &computer)
{
    // We could later count if the player is really often unpolite.
    MessageOut result;
    result.writeShort(CPMSG_ERROR);
    result.writeByte(CHAT_USING_BAD_WORDS); // The Channel
    computer.send(result);

    LOG_INFO(computer.characterName << " says bad words.");
}

void
ChatHandler::announce(ChatClient &computer, std::string const &text)
{
    MessageOut result;
    if (computer.accountLevel == AL_ADMIN ||
        computer.accountLevel == AL_GM )
    {
        LOG_INFO("ANNOUNCE: " << text);
        // Send it to all beings.
        result.writeShort(CPMSG_ANNOUNCEMENT);
        result.writeString(text);
        sendToEveryone(result);
    }
    else
    {
        result.writeShort(CPMSG_ERROR);
        result.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
        computer.send(result);
        LOG_INFO(computer.characterName <<
            " couldn't make an announcement due to insufficient rights.");
    }
}

void
ChatHandler::sayToPlayer(ChatClient &computer, std::string const &playerName,
                         std::string const &text)
{
    MessageOut result;
    LOG_DEBUG(computer.characterName << " says to " << playerName << ": "
              << text);
    // Send it to the being if the being exists
    result.writeShort(CPMSG_PRIVMSG);
    result.writeString(computer.characterName);
    result.writeString(text);
    for (NetComputers::iterator i = clients.begin(), i_end = clients.end();
         i != i_end; ++i) {
        if (static_cast< ChatClient * >(*i)->characterName == playerName)
        {
            (*i)->send(result);
            break;
        }
    }
}

void
ChatHandler::sayInChannel(ChatClient &computer, short channel,
                          std::string const &text)
{
    MessageOut result;
    LOG_DEBUG(computer.characterName << " says in channel " << channel << ": "
              << text);
    // Send it to all beings in channel
    result.writeShort(CPMSG_PUBMSG);
    result.writeShort(channel);
    result.writeString(computer.characterName);
    result.writeString(text);
    sendInChannel(channel, result);
}

void ChatHandler::warnUsersAboutPlayerEventInChat(short channelId,
                                                  std::string const &userName,
                                                  char eventId)
{
    MessageOut result;
    result.writeShort(CPMSG_CHANNEL_EVENT);
    result.writeShort(channelId);
    result.writeByte(eventId);
    result.writeString(userName);
    sendInChannel(channelId, result);
}

void ChatHandler::sendInChannel(short channelId, MessageOut &msg)
{
    std::vector< std::string > const &users =
            chatChannelManager->getUserListInChannel(channelId);
    for (NetComputers::iterator i = clients.begin(), i_end = clients.end();
         i != i_end; ++i)
    {
        // If the being is in the channel, send it
        std::vector< std::string >::const_iterator j_end = users.end(),
            j = std::find(users.begin(), j_end, static_cast< ChatClient * >(*i)->characterName);
        if (j != j_end)
        {
            (*i)->send(msg);
        }
    }
}

void ChatHandler::sendGuildEnterChannel(const MessageOut &msg, const std::string &name)
{
    for (NetComputers::iterator i = clients.begin(), i_end = clients.end();
         i != i_end; ++i) {
        if (static_cast< ChatClient * >(*i)->characterName == name)
        {
            (*i)->send(msg);
            break;
        }
    }
}

void ChatHandler::sendGuildInvite(const std::string &invitedName, const std::string &inviterName,
                                  const std::string &guildName)
{
    MessageOut msg(CPMSG_GUILD_INVITED);
    msg.writeString(inviterName);
    msg.writeString(guildName);
    for (NetComputers::iterator i = clients.begin(), i_end = clients.end();
         i != i_end; ++i) {
        if (static_cast< ChatClient * >(*i)->characterName == invitedName)
        {
            (*i)->send(msg);
            break;
        }
    }
}

void ChatHandler::sendGuildRejoin(ChatClient &computer)
{
    // Get character based on name.
    CharacterPtr character = serverHandler->getCharacter(computer.characterName);

    // Get list of guilds and check what rights they have.
    std::vector<std::string> guilds = character->getGuilds();
    for(unsigned int i = 0; i != guilds.size(); ++i)
    {
        Guild *guild = guildManager->findByName(guilds[i]);
        short leader = 0;
        if(!guild)
        {
            return;
        }
        if(guild->checkLeader(character.get()))
        {
            leader = 1;
        }
        MessageOut msg(CPMSG_GUILD_REJOIN);
        msg.writeString(guild->getName());
        msg.writeShort(guild->getId());
        msg.writeShort(leader);
        computer.send(msg);
        serverHandler->enterChannel(guild->getName(), character.get());
    }
}

void ChatHandler::sendUserJoined(short channelId, const std::string &name)
{
    MessageOut msg(CPMSG_USERJOINED);
    msg.writeShort(channelId);
    msg.writeString(name);
    sendInChannel(channelId, msg);
}

void ChatHandler::sendUserLeft(short channelId, const std::string &name)
{
    MessageOut msg(CPMSG_USERLEFT);
    msg.writeShort(channelId);
    msg.writeString(name);
    sendInChannel(channelId, msg);
}