summaryrefslogtreecommitdiffstats
path: root/src/NetworkClient.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-10-17 20:33:13 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-01-13 03:39:32 +0100
commita6e0c9ce9b6c468d0e622ffb5c05eba664ea4f47 (patch)
tree160309441fbe58921d9483e8d12e8d2e57955b97 /src/NetworkClient.cpp
parent2017-10-15 (diff)
downloadAltCraft-a6e0c9ce9b6c468d0e622ffb5c05eba664ea4f47.tar
AltCraft-a6e0c9ce9b6c468d0e622ffb5c05eba664ea4f47.tar.gz
AltCraft-a6e0c9ce9b6c468d0e622ffb5c05eba664ea4f47.tar.bz2
AltCraft-a6e0c9ce9b6c468d0e622ffb5c05eba664ea4f47.tar.lz
AltCraft-a6e0c9ce9b6c468d0e622ffb5c05eba664ea4f47.tar.xz
AltCraft-a6e0c9ce9b6c468d0e622ffb5c05eba664ea4f47.tar.zst
AltCraft-a6e0c9ce9b6c468d0e622ffb5c05eba664ea4f47.zip
Diffstat (limited to '')
-rw-r--r--src/NetworkClient.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/NetworkClient.cpp b/src/NetworkClient.cpp
index 36c6912..38cb947 100644
--- a/src/NetworkClient.cpp
+++ b/src/NetworkClient.cpp
@@ -1,7 +1,11 @@
#include "NetworkClient.hpp"
-NetworkClient::NetworkClient(std::string address, unsigned short port, std::string username)
- : network(address, port) {
+#include <easylogging++.h>
+
+#include "Network.hpp"
+
+NetworkClient::NetworkClient(std::string address, unsigned short port, std::string username) {
+ network = std::make_unique<Network>(address, port);
state = Handshaking;
PacketHandshake handshake;
@@ -9,18 +13,18 @@ NetworkClient::NetworkClient(std::string address, unsigned short port, std::stri
handshake.serverAddress = address;
handshake.serverPort = port;
handshake.nextState = 2;
- network.SendPacket(handshake);
+ network->SendPacket(handshake);
state = Login;
PacketLoginStart loginStart;
loginStart.Username = username;
- network.SendPacket(loginStart);
+ network->SendPacket(loginStart);
- auto packet = network.ReceivePacket(Login);
+ auto packet = network->ReceivePacket(Login);
while (!packet)
- packet = network.ReceivePacket(Login);
+ packet = network->ReceivePacket(Login);
if (packet->GetPacketId() == PacketNameLoginCB::SetCompression) {
auto compPacket = std::static_pointer_cast<PacketSetCompression>(packet);
@@ -28,7 +32,7 @@ NetworkClient::NetworkClient(std::string address, unsigned short port, std::stri
compressionThreshold = compPacket->Threshold;
packet.reset();
while (!packet)
- packet = network.ReceivePacket(Login, compressionThreshold >= 0);
+ packet = network->ReceivePacket(Login, compressionThreshold >= 0);
}
auto response = std::static_pointer_cast<PacketLoginSuccess>(packet);
@@ -60,11 +64,11 @@ void NetworkClient::SendPacket(std::shared_ptr<Packet> packet) {
void NetworkClient::UpdatePacket() {
while (!toSend.empty()) {
if (toSend.front() != nullptr)
- network.SendPacket(*toSend.front(), compressionThreshold);
+ network->SendPacket(*toSend.front(), compressionThreshold);
toSend.pop();
}
- auto packet = network.ReceivePacket(state, compressionThreshold >= 0);
+ auto packet = network->ReceivePacket(state, compressionThreshold >= 0);
if (packet.get() != nullptr) {
if (packet->GetPacketId() != PacketNamePlayCB::KeepAliveCB) {
toReceive.push(packet);
@@ -73,7 +77,7 @@ void NetworkClient::UpdatePacket() {
timeOfLastKeepAlivePacket = std::chrono::steady_clock::now();
auto packetKeepAlive = std::static_pointer_cast<PacketKeepAliveCB>(packet);
auto packetKeepAliveSB = std::make_shared<PacketKeepAliveSB>(packetKeepAlive->KeepAliveId);
- network.SendPacket(*packetKeepAliveSB, compressionThreshold);
+ network->SendPacket(*packetKeepAliveSB, compressionThreshold);
}
}
using namespace std::chrono_literals;