summaryrefslogtreecommitdiffstats
path: root/src/Network.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-01-27 13:01:35 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-01-27 15:06:36 +0100
commita2345d1f45870eb00a2a3d5d6fd21a386efcade3 (patch)
tree895dbf8f78d5b0117fb0daaab43423775ac4c304 /src/Network.cpp
parentMerge pull request #31 from uis246/pluginSystem (diff)
downloadAltCraft-a2345d1f45870eb00a2a3d5d6fd21a386efcade3.tar
AltCraft-a2345d1f45870eb00a2a3d5d6fd21a386efcade3.tar.gz
AltCraft-a2345d1f45870eb00a2a3d5d6fd21a386efcade3.tar.bz2
AltCraft-a2345d1f45870eb00a2a3d5d6fd21a386efcade3.tar.lz
AltCraft-a2345d1f45870eb00a2a3d5d6fd21a386efcade3.tar.xz
AltCraft-a2345d1f45870eb00a2a3d5d6fd21a386efcade3.tar.zst
AltCraft-a2345d1f45870eb00a2a3d5d6fd21a386efcade3.zip
Diffstat (limited to '')
-rw-r--r--src/Network.cpp20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/Network.cpp b/src/Network.cpp
index c8be740..431a5b1 100644
--- a/src/Network.cpp
+++ b/src/Network.cpp
@@ -7,24 +7,16 @@
Network::Network(std::string address, unsigned short port) {
try {
- socket = new Socket(address, port);
+ socket = std::make_unique<Socket>(address, port);
+ stream = std::make_unique<StreamSocket>(socket.get());
} catch (std::exception &e) {
LOG(WARNING) << "Connection failed: " << e.what();
throw;
- }
-
- try {
- stream = new StreamSocket(socket);
- } catch (std::exception &e) {
- LOG(WARNING) << "Stream creation failed: " << e.what();
- }
-
-
+ }
}
Network::~Network() {
- delete stream;
- delete socket;
+
}
std::shared_ptr<Packet> Network::ReceivePacket(ConnectionState state, bool useCompression) {
@@ -94,7 +86,7 @@ void Network::SendPacket(Packet &packet, int compressionThreshold) {
stream->WriteVarInt(packetSize.GetCountedSize());
stream->WriteVarInt(0);
stream->WriteVarInt(packet.GetPacketId());
- packet.ToStream(stream);
+ packet.ToStream(stream.get());
} else {
throw std::runtime_error("Compressing send data not supported");
}
@@ -105,7 +97,7 @@ void Network::SendPacket(Packet &packet, int compressionThreshold) {
packet.ToStream(&packetSize);
stream->WriteVarInt(packetSize.GetCountedSize());
stream->WriteVarInt(packet.GetPacketId());
- packet.ToStream(stream);
+ packet.ToStream(stream.get());
}
}