Skip to content

Commit

Permalink
🛡️Modified stuff so that windows compiles correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Lygaen committed Jun 20, 2023
1 parent 578ba4e commit 5d39e87
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Client
{
private:
ClientSocket sock;
IStream *stream;
IMCStream *stream;
bool isRunning;
ClientState state;

Expand Down
4 changes: 0 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ int main()

std::signal(SIGINT, [](int signal)
{ Server::inst()->stop(); });
std::signal(SIGKILL, [](int signal)
{ Server::inst()->stop(); });
std::signal(SIGQUIT, [](int signal)
{ Server::inst()->stop(); });

server.start();
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/net/packet.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "packet.h"
#include <utils/logger.h>

void IPacket::send(IStream *stream)
void IPacket::send(IMCStream *stream)
{
MemoryStream m;
m.writeVarInt(id);
Expand Down
6 changes: 3 additions & 3 deletions src/net/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class IPacket
* children classes.
* @param stream the stream to write to
*/
virtual void write(IStream *stream) = 0;
virtual void write(IMCStream *stream) = 0;

/**
* @brief Construct a new IPacket object
Expand Down Expand Up @@ -70,7 +70,7 @@ class IPacket
* anywhere on any stream, unlike IPackert#write()
* @param stream the stream to read from
*/
virtual void read(IStream *stream) = 0;
virtual void read(IMCStream *stream) = 0;
/**
* @brief Sends a Packet in Minecraft format
*
Expand All @@ -80,7 +80,7 @@ class IPacket
* as to their structure.
* @param stream
*/
void send(IStream *stream);
void send(IMCStream *stream);
};

#endif // MINESERVER_PACKET_H
4 changes: 2 additions & 2 deletions src/net/packets/handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include <locale>
#include <utils/config.h>

void HandshakePacket::write(IStream *stream)
void HandshakePacket::write(IMCStream *stream)
{
// Does nothing
throw std::runtime_error("Handshake write should not be called !");
}

void HandshakePacket::read(IStream *stream)
void HandshakePacket::read(IMCStream *stream)
{
protocolVersion = stream->readVarInt();
serverAddress = stream->readString();
Expand Down
4 changes: 2 additions & 2 deletions src/net/packets/handshake.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HandshakePacket : public IPacket
* @param stream the stream to write to
* @deprecated Do not call this function
*/
void write(IStream *stream) override;
void write(IMCStream *stream) override;

public:
/**
Expand Down Expand Up @@ -82,7 +82,7 @@ class HandshakePacket : public IPacket
* Reads handshake data from the stream
* @param stream the stream to read from
*/
void read(IStream *stream) override;
void read(IMCStream *stream) override;
};

#endif // MINESERVER_HANDSHAKE_H
4 changes: 2 additions & 2 deletions src/net/packets/status/pingpong.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "pingpong.h"

void PingPongPacket::write(IStream *stream)
void PingPongPacket::write(IMCStream *stream)
{
stream->writeLong(payload);
}

void PingPongPacket::read(IStream *stream)
void PingPongPacket::read(IMCStream *stream)
{
payload = stream->readLong();
}
4 changes: 2 additions & 2 deletions src/net/packets/status/pingpong.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PingPongPacket : public IPacket
* Writes back the payload obtained
* @param stream the stream to write to
*/
void write(IStream *stream) override;
void write(IMCStream *stream) override;

public:
/**
Expand All @@ -51,7 +51,7 @@ class PingPongPacket : public IPacket
* Reads the payload from the client
* @param stream the stream to read from
*/
void read(IStream *stream) override;
void read(IMCStream *stream) override;
};

#endif // MINESERVER_PINGPONG_H
4 changes: 2 additions & 2 deletions src/net/packets/status/serverlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <utils/config.h>
#include <utils/logger.h>

void ServerListPacket::write(IStream *stream)
void ServerListPacket::write(IMCStream *stream)
{
rapidjson::Document document;
document.SetObject();
Expand Down Expand Up @@ -43,7 +43,7 @@ void ServerListPacket::write(IStream *stream)
stream->writeString(std::string(buffer.GetString(), buffer.GetSize()));
}

void ServerListPacket::read(IStream *stream)
void ServerListPacket::read(IMCStream *stream)
{
/* Nothing wrong if you call it but just unecessary bloat */
}
4 changes: 2 additions & 2 deletions src/net/packets/status/serverlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ServerListPacket : public IPacket
* Writes server list data to stream
* @param stream the stream to write to
*/
void write(IStream *stream) override;
void write(IMCStream *stream) override;

public:
/**
Expand All @@ -45,7 +45,7 @@ class ServerListPacket : public IPacket
* @param stream the stream to read from
* @deprecated No need to call it, it does nothing
*/
void read(IStream *stream) override;
void read(IMCStream *stream) override;
};

#endif // MINESERVER_SERVERLIST_H
60 changes: 30 additions & 30 deletions src/net/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>

bool IStream::readBoolean()
bool IMCStream::readBoolean()
{
std::byte b[sizeof(bool)];
read(b, 0, sizeof(bool));
return *reinterpret_cast<bool *>(b);
}

void IStream::writeBoolean(bool b)
void IMCStream::writeBoolean(bool b)
{
write(reinterpret_cast<std::byte *>(&b), 0, sizeof(bool));
}

std::int8_t IStream::readByte()
std::int8_t IMCStream::readByte()
{
std::byte b[sizeof(std::int8_t)];
read(b, 0, sizeof(std::int8_t));
return *reinterpret_cast<std::int8_t *>(b);
}

void IStream::writeByte(std::int8_t b)
void IMCStream::writeByte(std::int8_t b)
{
write(reinterpret_cast<std::byte *>(&b), 0, sizeof(std::int8_t));
}

std::uint8_t IStream::readUnsignedByte()
std::uint8_t IMCStream::readUnsignedByte()
{
std::int8_t b = readByte();
return *reinterpret_cast<std::uint8_t *>(&b);
}

void IStream::writeUnsignedByte(std::uint8_t b)
void IMCStream::writeUnsignedByte(std::uint8_t b)
{
writeByte(*reinterpret_cast<std::int8_t *>(&b));
}

std::int16_t IStream::readShort()
std::int16_t IMCStream::readShort()
{
std::byte b[sizeof(std::int16_t)];
read(b, 0, sizeof(std::int16_t));
Expand All @@ -58,7 +58,7 @@ std::int16_t IStream::readShort()
return *reinterpret_cast<std::int16_t *>(b);
}

void IStream::writeShort(std::int16_t s)
void IMCStream::writeShort(std::int16_t s)
{
if constexpr (std::endian::native == std::endian::little)
{
Expand All @@ -78,18 +78,18 @@ void IStream::writeShort(std::int16_t s)
}
}

std::uint16_t IStream::readUnsignedShort()
std::uint16_t IMCStream::readUnsignedShort()
{
std::int16_t b = readShort();
return *reinterpret_cast<std::uint16_t *>(&b);
}

void IStream::writeUnsignedShort(std::uint16_t s)
void IMCStream::writeUnsignedShort(std::uint16_t s)
{
writeShort(*reinterpret_cast<std::int16_t *>(&s));
}

std::int32_t IStream::readInt()
std::int32_t IMCStream::readInt()
{
std::byte b[sizeof(std::int32_t)];
read(b, 0, sizeof(std::int32_t));
Expand All @@ -107,7 +107,7 @@ std::int32_t IStream::readInt()
}
}

void IStream::writeInt(std::int32_t i)
void IMCStream::writeInt(std::int32_t i)
{
if constexpr (std::endian::native == std::endian::little)
{
Expand All @@ -121,7 +121,7 @@ void IStream::writeInt(std::int32_t i)
}
}

std::int64_t IStream::readLong()
std::int64_t IMCStream::readLong()
{
std::byte b[sizeof(std::int64_t)];
read(b, 0, sizeof(std::int64_t));
Expand All @@ -139,7 +139,7 @@ std::int64_t IStream::readLong()
}
}

void IStream::writeLong(std::int64_t l)
void IMCStream::writeLong(std::int64_t l)
{
if constexpr (std::endian::native == std::endian::little)
{
Expand All @@ -153,44 +153,44 @@ void IStream::writeLong(std::int64_t l)
}
}

float IStream::readFloat()
float IMCStream::readFloat()
{
std::int32_t i = readInt();
return *reinterpret_cast<float *>(&i);
}

void IStream::writeFloat(float f)
void IMCStream::writeFloat(float f)
{
writeInt(*reinterpret_cast<std::int32_t *>(&f));
}

double IStream::readDouble()
double IMCStream::readDouble()
{
static_assert(sizeof(double) == sizeof(std::int64_t));
std::int64_t i = readLong();
return *reinterpret_cast<double *>(&i);
}

void IStream::writeDouble(double d)
void IMCStream::writeDouble(double d)
{
writeLong(*reinterpret_cast<std::int64_t *>(&d));
}

std::string IStream::readString()
std::string IMCStream::readString()
{
std::int32_t len = readVarInt();
std::int8_t b[len];
read(reinterpret_cast<std::byte *>(b), 0, len);
return std::string(reinterpret_cast<const char *>(b), len);
}

void IStream::writeString(const std::string &s)
void IMCStream::writeString(const std::string &s)
{
writeVarInt(s.size());
write(reinterpret_cast<std::byte *>(const_cast<char *>(s.data())), 0, s.size());
}

ChatMessage IStream::readChat()
ChatMessage IMCStream::readChat()
{
ChatMessage m;

Expand All @@ -203,7 +203,7 @@ ChatMessage IStream::readChat()
return m;
}

void IStream::writeChat(const ChatMessage &c)
void IMCStream::writeChat(const ChatMessage &c)
{
rapidjson::Document doc(rapidjson::kObjectType);
c.save(doc, doc.GetAllocator());
Expand All @@ -219,7 +219,7 @@ void IStream::writeChat(const ChatMessage &c)

#define SEGMENT_BITS 0x7F
#define CONTINUE_BIT 0x80
std::int32_t IStream::readVarInt()
std::int32_t IMCStream::readVarInt()
{
std::int32_t value = 0;
int position = 0;
Expand All @@ -242,7 +242,7 @@ std::int32_t IStream::readVarInt()
return value;
}

void IStream::writeVarInt(std::int32_t i)
void IMCStream::writeVarInt(std::int32_t i)
{
while (true)
{
Expand All @@ -258,7 +258,7 @@ void IStream::writeVarInt(std::int32_t i)
}
}

std::int64_t IStream::readVarLong()
std::int64_t IMCStream::readVarLong()
{
std::int64_t value = 0;
int position = 0;
Expand All @@ -281,7 +281,7 @@ std::int64_t IStream::readVarLong()
return value;
}

void IStream::writeVarLong(std::int64_t l)
void IMCStream::writeVarLong(std::int64_t l)
{
while (true)
{
Expand Down Expand Up @@ -348,9 +348,9 @@ void NetSocketStream::flush()
/* Not implemented */
}

CipherStream::CipherStream(IStream *baseStream, std::byte *key, std::byte *iv) : baseStream(baseStream),
encipher(crypto::CipherState::ENCRYPT, key, iv),
decipher(crypto::CipherState::DECRYPT, key, iv)
CipherStream::CipherStream(IMCStream *baseStream, std::byte *key, std::byte *iv) : baseStream(baseStream),
encipher(crypto::CipherState::ENCRYPT, key, iv),
decipher(crypto::CipherState::DECRYPT, key, iv)

{
}
Expand Down Expand Up @@ -384,7 +384,7 @@ void CipherStream::flush()
baseStream->flush();
}

ZLibStream::ZLibStream(IStream *baseStream, int level) : baseStream(baseStream), comp(level)
ZLibStream::ZLibStream(IMCStream *baseStream, int level) : baseStream(baseStream), comp(level)
{
}

Expand Down
Loading

0 comments on commit 5d39e87

Please sign in to comment.