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