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  *
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 {
58  createOutPacket(CMSG_MAP_LOADED);
59 }
60 
62 {
63  if (Network::mInstance == nullptr)
64  return;
65 
66  BLOCK_START("GameHandler::connect")
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
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?)
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 {
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 
131 {
132  createOutPacket(CMSG_CLIENT_DISCONNECT);
133 }
134 
136 {
137 }
138 
139 void GameHandler::ping2() const
140 {
141 }
142 
143 } // namespace TmwAthena
Ea::Network::disconnect
void disconnect()
Definition: network.cpp:138
TmwAthena::GameHandler::mapLoadedEvent
void mapLoadedEvent() const
Definition: gamehandler.cpp:56
TmwAthena::GameHandler::reqRemainTime
void reqRemainTime() const
Definition: gamehandler.cpp:135
TmwAthena::GameHandler
Definition: gamehandler.h:31
Token::session_ID1
int session_ID1
Definition: token.h:41
TmwAthena::Network::mInstance
static Network * mInstance
Definition: network.h:53
gamerecv.h
gamehandler.h
Token
Definition: token.h:29
ActorSprite::getId
BeingId getId() const
Definition: actorsprite.h:63
Ea::GameRecv::mCharID
BeingId mCharID
Definition: gamerecv.cpp:46
TmwAthena::GameHandler::ping2
void ping2() const
Definition: gamehandler.cpp:139
Token::account_ID
BeingId account_ID
Definition: token.h:40
Ea::Network::connect
bool connect(const ServerInfo &server)
Definition: network.cpp:100
Client::getState
StateT getState() const
Definition: client.h:68
TmwAthena
Definition: achievementhandler.cpp:25
TmwAthena::GameHandler::disconnect
void disconnect() const
Definition: gamehandler.cpp:111
TmwAthena::GameHandler::~GameHandler
~GameHandler()
Definition: gamehandler.cpp:51
TmwAthena::GameHandler::isConnected
bool isConnected() const
Definition: gamehandler.cpp:104
TmwAthena::mapServer
ServerInfo mapServer
Definition: charserverrecv.cpp:58
localplayer.h
State::CONNECT_GAME
@ CONNECT_GAME
Definition: state.h:47
localPlayer
LocalPlayer * localPlayer
Definition: localplayer.cpp:108
TmwAthena::GameHandler::GameHandler
GameHandler()
Definition: gamehandler.cpp:45
Being::genderToInt
static uint8_t genderToInt(const GenderT sex) A_CONST
Definition: being.h:926
TmwAthena::GameHandler::quit
void quit() const
Definition: gamehandler.cpp:119
protocolout.h
Token::sex
GenderT sex
Definition: token.h:43
loginhandler.h
TmwAthena::GameHandler::connect
void connect() const
Definition: gamehandler.cpp:61
loginHandler
Net::LoginHandler * loginHandler
Definition: net.cpp:89
Ea::Network::isConnected
bool isConnected() const
Definition: network.h:60
network.h
gameHandler
Net::GameHandler * gameHandler
Definition: net.cpp:90
TmwAthena::LoginHandler
Definition: loginhandler.h:31
createOutPacket
#define createOutPacket(name)
Definition: messageout.h:36
messageout.h
ActorSprite::setId
void setId(const BeingId id)
Definition: actorsprite.h:66
Token::session_ID2
int session_ID2
Definition: token.h:42
Ea
Definition: adminhandler.cpp:30
Ea::Network::skip
void skip(const int len)
Definition: network.cpp:180
client
Client * client
Definition: client.cpp:117
BLOCK_START
#define BLOCK_START(name)
Definition: perfomance.h:78
BLOCK_END
#define BLOCK_END(name)
Definition: perfomance.h:79
BeingId_zero
const BeingId BeingId_zero
Definition: beingid.h:29
TmwAthena::GameHandler::disconnect2
void disconnect2() const
Definition: gamehandler.cpp:130
ServerInfo
Definition: serverinfo.h:36
token.h
client.h
debug.h
TmwAthena::GameHandler::ping
void ping(const int tick) const
Definition: gamehandler.cpp:124