summaryrefslogtreecommitdiff
path: root/server/client.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'server/client.hpp')
-rw-r--r--server/client.hpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/server/client.hpp b/server/client.hpp
new file mode 100644
index 0000000..a3dcd78
--- /dev/null
+++ b/server/client.hpp
@@ -0,0 +1,58 @@
+#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 "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 );
+
+ //handles messages, hwid etc
+ void handle_buffer( byte* msg );
+ virtual bool handle( );
+ };
+} \ No newline at end of file