summaryrefslogblamecommitdiffstats
path: root/src/Network.hpp
blob: f28f80839d1fb8030a768d03510b7451aaf4d8d1 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

            









                      

               

                                       
 



                                                                                                                  
 

                                                                                                         

                                                                     
#pragma once

#include <memory>
#include "Socket.hpp"
#include "Packet.hpp"

enum ConnectionState {
	Handshaking,
	Login,
	Play,
	Status,
};

class Network {
	Socket *socket = nullptr;
	StreamSocket *stream = nullptr;

	std::shared_ptr<Packet> ReceivePacketByPacketId(int packetId, ConnectionState state, StreamInput &stream);
public:
	Network(std::string address, unsigned short port);
	~Network();

	std::shared_ptr<Packet> ReceivePacket(ConnectionState state = Play, bool useCompression = false);
	void SendPacket(Packet &packet, int compressionThreshold = -1);
	std::shared_ptr<Packet> ParsePacketPlay(PacketNamePlayCB id);
};