summaryrefslogtreecommitdiff
path: root/server/client.hpp
blob: 40ba1a538cb49d880df22827fee3b040c77bca2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once

#ifdef WIN32
#include <Windows.h>
#pragma comment(lib, "ws2_32.lib")
#else
#include <unistd.h>
#include <sys/types.h> 
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#endif

#include <cstdio>
#include <cstdlib>
#include <string>
#include <fstream>
#include <memory>

#include "util.hpp"

constexpr auto PORT_NUM = 6969;
constexpr auto BUFFER_SIZE = 255;

namespace server
{
	class c_client {
		SOCKET	  m_socket{ };
		in_addr	  m_address{ };
		ulong_t   m_hwid{ };

	public:
		c_client( SOCKET socket, in_addr& address ) : 
			m_socket( socket ),
			m_address( address ) { }

		~c_client( ) {
			closesocket( m_socket );
		}

		void decode_buffer( uint8_t* buf, size_t length ) {
			auto key = buf[ 0 ];
			for( size_t i{ 1 }; i < length; ++i )
				buf[ i ] ^= key;
		}

		auto get_ip( ) {
			return inet_ntoa( m_address );
		}

		std::vector< byte > receive_message( );
		bool send_message( byte* msg, size_t length );
		bool send_message( const char* );

		//handles messages, hwid etc
		void handle_buffer( byte* msg );
		virtual bool handle( );
	};
}