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-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/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 
46  Ea::GameHandler()
47 {
48  gameHandler = this;
49 }
50 
52 {
53  gameHandler = nullptr;
54 }
55 
57 {
59 }
60 
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 
71  {
72  // Change the player's ID to the account ID to match what eAthena uses
73  if (localPlayer != nullptr)
74  {
77  }
78  else
79  {
81  }
82  }
83 
84  // Send login infos
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?)
101  BLOCK_END("GameHandler::connect")
102 }
103 
105 {
106  if (Network::mInstance == nullptr)
107  return false;
109 }
110 
112 {
113  BLOCK_START("GameHandler::disconnect")
114  if (Network::mInstance != nullptr)
116  BLOCK_END("GameHandler::disconnect")
117 }
118 
119 void GameHandler::quit() const
120 {
122 }
123 
124 void GameHandler::ping(const int tick) const
125 {
127  outMsg.writeInt32(tick, "tick");
128 }
129 
131 {
133 }
134 
135 } // namespace TmwAthena
int CMSG_MAP_PING
Definition: protocolout.cpp:39
static Network * mInstance
Definition: network.h:53
bool isConnected() const
Definition: network.h:60
BeingId getId() const
Definition: actorsprite.h:63
void disconnect2() const
ServerInfo mapServer
#define BLOCK_START(name)
Definition: perfomance.h:78
bool isConnected() const
void mapLoadedEvent() const
Definition: gamehandler.cpp:56
#define BLOCK_END(name)
Definition: perfomance.h:79
Client * client
Definition: client.cpp:117
Definition: token.h:29
GenderT sex
Definition: token.h:43
static uint8_t genderToInt(const GenderT sex) A_CONST
Definition: being.h:926
Net::LoginHandler * loginHandler
Definition: net.cpp:87
bool connect(const ServerInfo &server)
Definition: network.cpp:100
LocalPlayer * localPlayer
void disconnect()
Definition: network.cpp:138
void setId(const BeingId id)
Definition: actorsprite.h:66
int CMSG_CLIENT_DISCONNECT
int CMSG_MAP_LOADED
Definition: protocolout.cpp:40
BeingId account_ID
Definition: token.h:40
#define createOutPacket(name)
Definition: messageout.h:36
void skip(const int len)
Definition: network.cpp:180
int CMSG_MAP_SERVER_CONNECT
Definition: protocolout.cpp:38
int CMSG_CLIENT_QUIT
Definition: protocolout.cpp:41
StateT getState() const
Definition: client.h:68
void ping(const int tick) const
const BeingId BeingId_zero
Definition: beingid.h:29
BeingId mCharID
Definition: gamerecv.cpp:46
Net::GameHandler * gameHandler
Definition: net.cpp:88
int session_ID1
Definition: token.h:41
int session_ID2
Definition: token.h:42