summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/charserverhandler.cpp17
-rw-r--r--src/net/charserverhandler.h4
-rw-r--r--src/net/loginhandler.cpp7
-rw-r--r--src/net/loginhandler.h7
-rw-r--r--src/net/network.cpp16
-rw-r--r--src/net/network.h5
6 files changed, 31 insertions, 25 deletions
diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp
index e7fe3955..015c9d94 100644
--- a/src/net/charserverhandler.cpp
+++ b/src/net/charserverhandler.cpp
@@ -30,6 +30,7 @@
#include "../game.h"
#include "../localplayer.h"
#include "../log.h"
+#include "../logindata.h"
#include "../main.h"
#include "../gui/ok_dialog.h"
@@ -119,11 +120,11 @@ void CharServerHandler::handleMessage(MessageIn *msg)
break;
case 0x0071:
- char_ID = msg->readInt32();
- map_path = msg->readString(16);
- map_address = msg->readInt32();
- map_port = msg->readInt16();
player_node = mCharInfo->getEntry();
+ msg->skip(4); // CharID, must be the same as player_node->charID
+ map_path = msg->readString(16);
+ mLoginData->hostname = iptostring(msg->readInt32());
+ mLoginData->port = msg->readInt16();
mCharInfo->unlock();
mCharInfo->select(0);
// Clear unselected players infos
@@ -136,10 +137,6 @@ void CharServerHandler::handleMessage(MessageIn *msg)
} while (mCharInfo->getPos());
state = CONNECTING_STATE;
-
- logger->log("CharSelect: Map: %s", map_path.c_str());
- logger->log("CharSelect: Server: %s:%i", iptostring(map_address),
- map_port);
break;
case 0x0081:
@@ -165,9 +162,9 @@ void CharServerHandler::handleMessage(MessageIn *msg)
LocalPlayer* CharServerHandler::readPlayerData(MessageIn *msg, int &slot)
{
- LocalPlayer *tempPlayer = new LocalPlayer(account_ID, 0, NULL);
+ LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL);
- tempPlayer->mLoginId = msg->readInt32();
+ tempPlayer->mCharId = msg->readInt32();
tempPlayer->totalWeight = 0;
tempPlayer->maxWeight = 0;
tempPlayer->lastAttackTime = 0;
diff --git a/src/net/charserverhandler.h b/src/net/charserverhandler.h
index 21178377..16d2c361 100644
--- a/src/net/charserverhandler.h
+++ b/src/net/charserverhandler.h
@@ -29,6 +29,7 @@
#include "../lockedarray.h"
class LocalPlayer;
+class LoginData;
class CharServerHandler : public MessageHandler
{
@@ -39,7 +40,10 @@ class CharServerHandler : public MessageHandler
void setCharInfo(LockedArray<LocalPlayer*> *charInfo) { mCharInfo = charInfo; };
+ void setLoginData(LoginData *loginData) { mLoginData = loginData; };
+
protected:
+ LoginData *mLoginData;
LockedArray<LocalPlayer*> *mCharInfo;
LocalPlayer* readPlayerData(MessageIn *msg, int &slot);
diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp
index fd525d99..aca08e6a 100644
--- a/src/net/loginhandler.cpp
+++ b/src/net/loginhandler.cpp
@@ -28,6 +28,7 @@
#include "protocol.h"
#include "../log.h"
+#include "../logindata.h"
#include "../main.h"
#include "../serverinfo.h"
@@ -54,9 +55,9 @@ void LoginHandler::handleMessage(MessageIn *msg)
n_server = (msg->getLength() - 47) / 32;
server_info = (SERVER_INFO**)malloc(sizeof(SERVER_INFO*) * n_server);
- session_ID1 = msg->readInt32();
- account_ID = msg->readInt32();
- session_ID2 = msg->readInt32();
+ mLoginData->session_ID1 = msg->readInt32();
+ mLoginData->account_ID = msg->readInt32();
+ mLoginData->session_ID2 = msg->readInt32();
msg->skip(30); // unknown
sex = msg->readInt8();
diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h
index 99ade7f1..52014559 100644
--- a/src/net/loginhandler.h
+++ b/src/net/loginhandler.h
@@ -26,12 +26,19 @@
#include "messagehandler.h"
+struct LoginData;
+
class LoginHandler : public MessageHandler
{
public:
LoginHandler();
void handleMessage(MessageIn *msg);
+
+ void setLoginData(LoginData *loginData) { mLoginData = loginData; };
+
+ protected:
+ LoginData *mLoginData;
};
#endif
diff --git a/src/net/network.cpp b/src/net/network.cpp
index f519a467..9e6f6621 100644
--- a/src/net/network.cpp
+++ b/src/net/network.cpp
@@ -91,7 +91,7 @@ int networkThread(void *data)
}
Network::Network():
- mAddress(0), mPort(0),
+ mAddress(), mPort(0),
mInBuffer(new char[BUFFER_SIZE]),
mOutBuffer(new char[BUFFER_SIZE]),
mInSize(0), mOutSize(0),
@@ -106,9 +106,6 @@ Network::~Network()
{
clearHandlers();
- if (mAddress)
- free(mAddress);
-
if (mState != IDLE && mState != ERROR)
disconnect();
@@ -118,7 +115,7 @@ Network::~Network()
delete mOutBuffer;
}
-bool Network::connect(const char *address, short port)
+bool Network::connect(const std::string &address, short port)
{
if (mState != IDLE && mState != ERROR)
{
@@ -126,17 +123,16 @@ bool Network::connect(const char *address, short port)
return false;
}
- if (!address)
+ if (address.empty())
{
logger->log("Empty address given to Network::connect()!");
mState = ERROR;
return false;
}
- if (mAddress)
- free(mAddress);
+ logger->log("Network::Connecting to %s:%i", address.c_str(), port);
- mAddress = strdup(address);
+ mAddress = address;
mPort = port;
// Reset to sane values
@@ -322,7 +318,7 @@ bool Network::realConnect()
{
IPaddress ipAddress;
- if (SDLNet_ResolveHost(&ipAddress, mAddress, mPort) == -1)
+ if (SDLNet_ResolveHost(&ipAddress, mAddress.c_str(), mPort) == -1)
{
logger->log("Error in SDLNet_ResolveHost(): %s", SDLNet_GetError());
mState = ERROR;
diff --git a/src/net/network.h b/src/net/network.h
index 75bde584..06abc445 100644
--- a/src/net/network.h
+++ b/src/net/network.h
@@ -27,6 +27,7 @@
#include <map>
#include <SDL_net.h>
#include <SDL_thread.h>
+#include <string>
class MessageHandler;
class MessageIn;
@@ -42,7 +43,7 @@ class Network
Network();
~Network();
- bool connect(const char *address, short port);
+ bool connect(const std::string &address, short port);
void disconnect();
void registerHandler(MessageHandler *handler);
@@ -75,7 +76,7 @@ class Network
TCPsocket mSocket;
- char *mAddress;
+ std::string mAddress;
short mPort;
char *mInBuffer, *mOutBuffer;