#ifndef Network_H #define Network_H #ifdef WIN32 # ifdef _DEBUG # ifndef _LTMDB # define _CRTDBG_MAP_ALLOC # include # include # define DEBUG_CLIENTBLOCK new (_CLIENT_BLOCK, __FILE__, __LINE__) # define new DEBUG_CLIENTBLOCK # define _LTMDB # endif # endif # define _WINSOCK_DEPRECATED_NO_WARNINGS # include #else # include # include # include # include # include # include # include # define __declspec(x) # define __int64 long long # ifndef SOCKET # define SOCKET int # define SOCKADDR_IN sockaddr_in # define ADDR_ANY INADDR_ANY # define closesocket close # define PHOSTENT hostent* # endif #endif #include #include namespace Framework { class Text; } namespace Network { __declspec(dllexport) void Start(int maxClients); __declspec(dllexport) void getHostName(char* name, int bufferLen); __declspec(dllexport) char* getHostAddress(); __declspec(dllexport) void Exit(); class Connection { public: virtual bool send(const char* message, int len) = 0; // sends message virtual bool getMessage(char* message, int len) = 0; // receives message }; class EncryptedConnection : public Connection { public: virtual bool sendEncrypted(const char* message, int len) = 0; // sends message virtual bool getMessageEncrypted(char* message, int len) = 0; // receives message }; class NetworkReader : public Framework::StreamReader { private: Connection* connection; public: __declspec(dllexport) NetworkReader(Connection* v); __declspec(dllexport) virtual ~NetworkReader(); //! Reads from the resource //! \param bytes An array to be filled with bytes from the resource //! \param len How many bytes to read from the resource __declspec(dllexport) void read(char* bytes, int len) override; //! Reads the next line from the resource //! \return The read line as text with line break __declspec(dllexport) Framework::Text* readLine() override; //! Checks whether the resource has been fully read //! return 1 if the resource has been fully read. 0 otherwise __declspec(dllexport) bool isEnd() const override; }; class NetworkWriter : public Framework::StreamWriter { private: Connection* connection; public: __declspec(dllexport) NetworkWriter(Connection* v); __declspec(dllexport) virtual ~NetworkWriter(); //! Writes to the resource //! \param bytes An array containing the bytes to write to the resource //! \param len How many bytes to write to the resource __declspec(dllexport) void write(const char* bytes, int len) override; //! Checks whether the resource has been fully written //! return 1 if the resource has been fully written. 0 otherwise __declspec(dllexport) bool isEnd() const override; }; class EncryptedNetworkReader : public Framework::StreamReader { private: EncryptedConnection* connection; public: __declspec(dllexport) EncryptedNetworkReader(EncryptedConnection* v); //! Reads from the resource //! \param bytes An array to be filled with bytes from the resource //! \param len How many bytes to read from the resource __declspec(dllexport) void read(char* bytes, int len) override; //! Reads the next line from the resource //! \return The read line as text with line break __declspec(dllexport) Framework::Text* readLine() override; //! Checks whether the resource has been fully read //! return 1 if the resource has been fully read. 0 otherwise __declspec(dllexport) bool isEnd() const override; }; class EncryptedNetworkWriter : public Framework::StreamWriter { private: EncryptedConnection* connection; public: __declspec(dllexport) EncryptedNetworkWriter(EncryptedConnection* v); //! Writes to the resource //! \param bytes An array containing the bytes to write to the resource //! \param len How many bytes to write to the resource __declspec(dllexport) void write(const char* bytes, int len) override; //! Checks whether the resource has been fully written //! return 1 if the resource has been fully written. 0 otherwise __declspec(dllexport) bool isEnd() const override; }; } // namespace Network #endif