summaryrefslogtreecommitdiff
path: root/server/client.hpp
blob: fad499f874336635f64d7e4484fb8adefef87676 (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
61
62
63
64
65
66
67
#pragma once

#ifdef WIN
#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 <thread>


#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 );
		}

		void kill( );

		//std::vector< byte > receive_message( );
		std::string get_msg( );
		bool send_msg( byte* msg, size_t length );
		bool send_msg( const char* );

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