summaryrefslogtreecommitdiffstats
path: root/src/NetworkClient.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-08-03 17:03:59 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-08-03 17:03:59 +0200
commitf7decf41d8d0062901cd39c42a3669a80537c7df (patch)
treed3032265df11eee6e3eaf8b4b081524bef5e72b2 /src/NetworkClient.cpp
parent2017-07-29 (diff)
downloadAltCraft-f7decf41d8d0062901cd39c42a3669a80537c7df.tar
AltCraft-f7decf41d8d0062901cd39c42a3669a80537c7df.tar.gz
AltCraft-f7decf41d8d0062901cd39c42a3669a80537c7df.tar.bz2
AltCraft-f7decf41d8d0062901cd39c42a3669a80537c7df.tar.lz
AltCraft-f7decf41d8d0062901cd39c42a3669a80537c7df.tar.xz
AltCraft-f7decf41d8d0062901cd39c42a3669a80537c7df.tar.zst
AltCraft-f7decf41d8d0062901cd39c42a3669a80537c7df.zip
Diffstat (limited to '')
-rw-r--r--src/NetworkClient.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/NetworkClient.cpp b/src/NetworkClient.cpp
index 0b759e6..235251f 100644
--- a/src/NetworkClient.cpp
+++ b/src/NetworkClient.cpp
@@ -6,8 +6,8 @@ NetworkClient::NetworkClient(std::string address, unsigned short port, std::stri
PacketHandshake handshake;
handshake.protocolVersion = 335;
- handshake.serverAddress = "127.0.0.1";
- handshake.serverPort = 25565;
+ handshake.serverAddress = address;
+ handshake.serverPort = port;
handshake.nextState = 2;
network.SendPacket(handshake);
state = Login;
@@ -24,8 +24,7 @@ NetworkClient::NetworkClient(std::string address, unsigned short port, std::stri
state = Play;
isActive = true;
- std::thread thread(&NetworkClient::NetworkLoop, this);
- std::swap(networkThread, thread);
+ networkThread = std::thread(&NetworkClient::NetworkLoop, this);
}
NetworkClient::~NetworkClient() {
@@ -35,7 +34,7 @@ NetworkClient::~NetworkClient() {
std::shared_ptr<Packet> NetworkClient::ReceivePacket() {
if (toReceive.empty())
- return std::shared_ptr<Packet>(nullptr);
+ return std::shared_ptr < Packet > (nullptr);
toReceiveMutex.lock();
auto ret = toReceive.front();
toReceive.pop();
@@ -57,7 +56,7 @@ void NetworkClient::NetworkLoop() {
while (isActive) {
toSendMutex.lock();
while (!toSend.empty()) {
- if (toSend.front()!=nullptr)
+ if (toSend.front() != nullptr)
network.SendPacket(*toSend.front());
toSend.pop();
}
@@ -78,7 +77,7 @@ void NetworkClient::NetworkLoop() {
using namespace std::chrono_literals;
if (std::chrono::steady_clock::now() - timeOfLastKeepAlivePacket > 20s) {
auto disconnectPacket = std::make_shared<PacketDisconnectPlay>();
- disconnectPacket->Reason = "Timeout";
+ disconnectPacket->Reason = "Timeout: server not respond";
toReceiveMutex.lock();
toReceive.push(disconnectPacket);
toReceiveMutex.unlock();