ManaPlus
gamehandler.cpp
Go to the documentation of this file.
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 
47  Ea::GameHandler()
48 {
49  gameHandler = this;
50 }
51 
53 {
54  gameHandler = nullptr;
55 }
56 
58 {
59  createOutPacket(CMSG_MAP_LOADED);
60 }
61 
63 {
64  if (Network::mInstance == nullptr)
65  return;
66 
67  BLOCK_START("GameHandler::connect")
69  const Token &token = static_cast<LoginHandler*>(loginHandler)->getToken();
70 
72  {
73  // Change the player's ID to the account ID to match what eAthena uses
74  if (localPlayer != nullptr)
75  {
78  }
79  else
80  {
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?)
102  BLOCK_END("GameHandler::connect")
103 }
104 
106 {
107  if (Network::mInstance == nullptr)
108  return false;
110 }
111 
113 {
114  BLOCK_START("GameHandler::disconnect")
115  if (Network::mInstance != nullptr)
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 
132 {
133  createOutPacket(CMSG_CLIENT_DISCONNECT);
134 }
135 
137 {
138 }
139 
140 void GameHandler::ping2() const
141 {
142 }
143 
144 } // namespace TmwAthena
const BeingId BeingId_zero
Definition: beingid.h:30
void setId(const BeingId id)
Definition: actorsprite.h:67
BeingId getId() const
Definition: actorsprite.h:64
static uint8_t genderToInt(const GenderT sex) A_CONST
Definition: being.h:927
StateT getState() const
Definition: client.h:69
bool isConnected() const
Definition: network.h:61
bool connect(const ServerInfo &server)
Definition: network.cpp:101
void skip(const int len)
Definition: network.cpp:181
void disconnect()
Definition: network.cpp:139
void reqRemainTime() const
void mapLoadedEvent() const
Definition: gamehandler.cpp:57
void ping(const int tick) const
bool isConnected() const
void disconnect2() const
static Network * mInstance
Definition: network.h:54
Client * client
Definition: client.cpp:118
Net::GameHandler * gameHandler
Definition: net.cpp:91
LocalPlayer * localPlayer
Net::LoginHandler * loginHandler
Definition: net.cpp:90
#define createOutPacket(name)
Definition: messageout.h:37
BeingId mCharID
Definition: gamerecv.cpp:47
@ CONNECT_GAME
Definition: state.h:48
ServerInfo mapServer
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
Definition: token.h:31
int session_ID2
Definition: token.h:43
GenderT sex
Definition: token.h:44
BeingId account_ID
Definition: token.h:41
int session_ID1
Definition: token.h:42