GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/gamehandler.cpp Lines: 1 38 2.6 %
Date: 2017-11-29 Branches: 0 34 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  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/tmwa/gamehandler.h"
24
25
#include "client.h"
26
27
#include "being/localplayer.h"
28
29
#include "net/ea/token.h"
30
31
#include "net/ea/gamerecv.h"
32
33
#include "net/tmwa/loginhandler.h"
34
#include "net/tmwa/messageout.h"
35
#include "net/tmwa/network.h"
36
#include "net/tmwa/protocolout.h"
37
38
#include "debug.h"
39
40
namespace TmwAthena
41
{
42
43
extern ServerInfo mapServer;
44
45
GameHandler::GameHandler() :
46
    Ea::GameHandler()
47
{
48
    gameHandler = this;
49
}
50
51
GameHandler::~GameHandler()
52
{
53
    gameHandler = nullptr;
54
}
55
56
void GameHandler::mapLoadedEvent() const
57
{
58
    createOutPacket(CMSG_MAP_LOADED);
59
}
60
61
void GameHandler::connect() const
62
{
63
    if (Network::mInstance == nullptr)
64
        return;
65
66
    BLOCK_START("GameHandler::connect")
67
    Network::mInstance->connect(mapServer);
68
    const Token &token = static_cast<LoginHandler*>(loginHandler)->getToken();
69
70
    if (client->getState() == State::CONNECT_GAME)
71
    {
72
        // Change the player's ID to the account ID to match what eAthena uses
73
        if (localPlayer != nullptr)
74
        {
75
            Ea::GameRecv::mCharID = localPlayer->getId();
76
            localPlayer->setId(token.account_ID);
77
        }
78
        else
79
        {
80
            Ea::GameRecv::mCharID = BeingId_zero;
81
        }
82
    }
83
84
    // Send login infos
85
    createOutPacket(CMSG_MAP_SERVER_CONNECT);
86
    outMsg.writeBeingId(token.account_ID, "account id");
87
    outMsg.writeBeingId(Ea::GameRecv::mCharID, "char id");
88
    outMsg.writeInt32(token.session_ID1, "session id1");
89
    outMsg.writeInt32(token.session_ID2, "session id2");
90
    outMsg.writeInt8(Being::genderToInt(token.sex), "gender");
91
92
/*
93
    if (localPlayer)
94
    {
95
        // Change the player's ID to the account ID to match what eAthena uses
96
        localPlayer->setId(token.account_ID);
97
    }
98
*/
99
    // We get 4 useless bytes before the real answer comes in (what are these?)
100
    Network::mInstance->skip(4);
101
    BLOCK_END("GameHandler::connect")
102
}
103
104
bool GameHandler::isConnected() const
105
{
106
    if (Network::mInstance == nullptr)
107
        return false;
108
    return Network::mInstance->isConnected();
109
}
110
111
void GameHandler::disconnect() const
112
{
113
    BLOCK_START("GameHandler::disconnect")
114
    if (Network::mInstance != nullptr)
115
        Network::mInstance->disconnect();
116
    BLOCK_END("GameHandler::disconnect")
117
}
118
119
void GameHandler::quit() const
120
{
121
    createOutPacket(CMSG_CLIENT_QUIT);
122
}
123
124
void GameHandler::ping(const int tick) const
125
{
126
    createOutPacket(CMSG_MAP_PING);
127
    outMsg.writeInt32(tick, "tick");
128
}
129
130
void GameHandler::disconnect2() const
131
{
132
    createOutPacket(CMSG_CLIENT_DISCONNECT);
133
}
134
135
4
}  // namespace TmwAthena