Added a bunch of undefs to Defs.hpp
Hanshake now has distribution_mode Removed all the undef SendMessage and redefenitions, we are undefing it in Defs.hpp and we are now defing it back Added SendHanshake GetMaxConnections SetMaxConnections and shutdown_internal methods in TcpServer.hpp and changed AcceptConnection parameter to uint16 Removed process_all_data method in VoidNetClient.hpp Placed some functions that are OS independent in main cpp files to prevent the DRY concept Fixed receive_data_array method in TcpClientWindows.cpp VoidNetClientAPI::SendMessage now checks if tags dont have the CONNECT or DISCONNECT value because thats reserved to the server
This commit is contained in:
@ -5,11 +5,60 @@
|
||||
#pragma once
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _WINSOCKAPI_
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
|
||||
#undef GetBinaryType
|
||||
#undef GetShortPathName
|
||||
#undef GetLongPathName
|
||||
#undef GetEnvironmentStrings
|
||||
#undef SetEnvironmentStrings
|
||||
#undef FreeEnvironmentStrings
|
||||
#undef FormatMessage
|
||||
#undef EncryptFile
|
||||
#undef DecryptFile
|
||||
#undef CreateMutex
|
||||
#undef OpenMutex
|
||||
#undef CreateEvent
|
||||
#undef OpenEvent
|
||||
#undef CreateSemaphore
|
||||
#undef OpenSemaphore
|
||||
#undef LoadLibrary
|
||||
#undef GetModuleFileName
|
||||
#undef CreateProcess
|
||||
#undef GetCommandLine
|
||||
#undef GetEnvironmentVariable
|
||||
#undef SetEnvironmentVariable
|
||||
#undef ExpandEnvironmentStrings
|
||||
#undef OutputDebugString
|
||||
#undef FindResource
|
||||
#undef UpdateResource
|
||||
#undef FindAtom
|
||||
#undef AddAtom
|
||||
#undef GetSystemDirectory
|
||||
#undef GetTempPath
|
||||
#undef GetTempFileName
|
||||
#undef SetCurrentDirectory
|
||||
#undef GetCurrentDirectory
|
||||
#undef CreateDirectory
|
||||
#undef RemoveDirectory
|
||||
#undef CreateFile
|
||||
#undef DeleteFile
|
||||
#undef SearchPath
|
||||
#undef CopyFile
|
||||
#undef MoveFile
|
||||
#undef ReplaceFile
|
||||
#undef GetComputerName
|
||||
#undef SetComputerName
|
||||
#undef GetUserName
|
||||
#undef LogonUser
|
||||
#undef GetVersion
|
||||
#undef GetObject
|
||||
#undef SendMessage
|
||||
|
||||
typedef signed char int8, sbyte;
|
||||
typedef unsigned char uint8, byte;
|
||||
typedef signed short int16;
|
||||
@ -173,7 +222,7 @@ const uint16 default_server_port = 61250;
|
||||
enum DistributionType
|
||||
{
|
||||
All = 1, // Others and Server
|
||||
AllAndMe, // Other, Server and Ourselfs
|
||||
AllAndMe, // Other, Server and the user sending the message
|
||||
Server,
|
||||
Others,
|
||||
ID,
|
||||
@ -181,7 +230,7 @@ enum DistributionType
|
||||
|
||||
enum ConnectionCode
|
||||
{
|
||||
Accept = 0,
|
||||
Accept,
|
||||
Reject
|
||||
};
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
struct Handshake
|
||||
{
|
||||
Handshake();
|
||||
Handshake(uint16 id, byte con_code);
|
||||
Handshake(uint16 id, byte con_code, byte distribution_mode);
|
||||
~Handshake();
|
||||
|
||||
static const std::vector<byte> &EncodeHandshake(const Handshake &handshake);
|
||||
@ -20,6 +20,7 @@ struct Handshake
|
||||
|
||||
uint16 id;
|
||||
byte con_code;
|
||||
byte distribution_mode;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -15,7 +15,7 @@ struct NetworkBuffer
|
||||
NetworkBuffer();
|
||||
~NetworkBuffer();
|
||||
|
||||
std::vector<byte> header; // size must always be 8
|
||||
std::vector<byte> header; // size must always be sizeof(int32)
|
||||
std::vector<byte> body;
|
||||
|
||||
bool valid = false;
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#undef SendMessage
|
||||
#endif
|
||||
|
||||
class TcpClient
|
||||
@ -73,12 +72,4 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef UNICODE
|
||||
#define SendMessage SendMessageW
|
||||
#else
|
||||
#define SendMessage SendMessageA
|
||||
#endif // !UNICODE
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -10,10 +10,6 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#undef SendMessage
|
||||
#endif
|
||||
|
||||
class TcpServer
|
||||
{
|
||||
public:
|
||||
@ -27,22 +23,29 @@ public:
|
||||
void AddToClientsList(TcpClient &client);
|
||||
bool StartServer(bool accept_connections); // if accept_connections is false the user must call the funcion AcceptConnections()
|
||||
void AcceptConnections();
|
||||
|
||||
void SendMessage(const NetworkMessage &message);
|
||||
void SendHandshake(const Handshake &handshake);
|
||||
|
||||
void RejectConnection(TcpClient &client);
|
||||
void AcceptConnection(TcpClient &client);
|
||||
void AcceptConnection(uint16 client);
|
||||
|
||||
void CloseSocket(TcpClient &client);
|
||||
void CloseSocket(uint16 id);
|
||||
|
||||
uint16 GetMaxConnections();
|
||||
void SetMaxConnections(uint16 value);
|
||||
|
||||
const TcpClient &GetClientByID(uint16 id);
|
||||
|
||||
std::function<void(const NetworkMessage &message)> OnMessage;
|
||||
std::function<void(const NetworkMessage &message)> OnMessage; // this is going to be used for plugins
|
||||
|
||||
private:
|
||||
static void process_client_messages(TcpServer *server, TcpClient &client);
|
||||
static void process_message(TcpServer *server, const NetworkMessage &message);
|
||||
static void accept_connections(TcpServer *server);
|
||||
|
||||
void shutdown_internal();
|
||||
|
||||
bool initialize(uint16 port = default_server_port);
|
||||
|
||||
bool initialized = false;
|
||||
@ -59,12 +62,4 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef UNICODE
|
||||
#define SendMessage SendMessageW
|
||||
#else
|
||||
#define SendMessage SendMessageA
|
||||
#endif // !UNICODE
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -14,8 +14,6 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#undef SendMessage
|
||||
|
||||
struct VoidNetClientAPI
|
||||
{
|
||||
static bool Connect(const std::string &ip, uint16 port = default_client_port);
|
||||
@ -32,17 +30,9 @@ struct VoidNetClientAPI
|
||||
static void Receive();
|
||||
|
||||
private:
|
||||
static void process_all_data();
|
||||
|
||||
static TcpClient client;
|
||||
static uint16 id;
|
||||
static bool receive;
|
||||
};
|
||||
|
||||
#ifdef UNICODE
|
||||
#define SendMessage SendMessageW
|
||||
#else
|
||||
#define SendMessage SendMessageA
|
||||
#endif // !UNICODE
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user