Removed old callbacks

Implemented new callback methods
Made ReceiveData renamed to ReceiveMessages, returns void amd calls the callback methods
This commit is contained in:
xX-TheDoctor-Xx
2016-07-18 21:48:34 +01:00
parent a1249ab5e9
commit b42b26cada
15 changed files with 39 additions and 65 deletions

View File

@ -1,21 +0,0 @@
#ifndef CALLBACKS_HPP
#define CALLBACKS_HPP
#ifdef _MSC_VER
#pragma once
#endif
#include "Defs.hpp"
#include "Serializer.hpp"
/*Client Callbacks begin*/
void OnMessage(uint16 sender, uint16 tag, uint16 subject, void *data);
void OnDisconnect(uint16 id);
void OnConnect(uint16 id);
/*Client Callbacks end*/
#endif

View File

@ -184,13 +184,11 @@ enum VoidCode
enum DistributionType
{
All,
AllAndMe,
All = 1, // Others and Server
AllAndMe, // Other, Server and Ourselfs
Server,
Others,
ID,
Reply,
Custom,
};
#endif // DEFS_HPP

View File

@ -6,6 +6,7 @@
#include <string>
#include <vector>
#include <functional>
#ifdef _MSC_VER
#pragma once
@ -28,17 +29,23 @@ public:
VoidCode Connect();
NetworkBuffer ReceiveDataArray();
const NetworkMessage &ReceiveData();
void ReceiveMessages();
void SendMessage(const NetworkMessage &message);
std::function<void(uint16)> OnDisconnect;
std::function<void(uint16)> OnConnect;
std::function<void(uint16, uint16, uint16, void*)> OnMessage;
private:
const NetworkBuffer &ReceiveDataArray();
static void ReceiveData(TcpClient *client);
static void SendNetworkMessage(const NetworkMessage &message, TcpClient *client);
VoidCode Initialize(const std::string &ip, uint16 port = default_port);
std::string ip;
uint16 port = 0;
bool initialized = false;
bool receive = false;
#ifdef _MSC_VER
SOCKET tcp_socket = INVALID_SOCKET;

View File

@ -8,7 +8,6 @@
#include "Defs.hpp"
#include "Init.hpp"
#include "TcpClient.hpp"
#include "Callbacks.hpp"
#include "NetworkBuffer.hpp"
#include "NetworkMessage.hpp"