Danbias/Code/Network/NetworkAPI/NetworkClient.h

116 lines
2.1 KiB
C
Raw Normal View History

2013-12-10 08:32:08 +01:00
#ifndef NETWORK_API_NETWORK_CLIENT_H
#define NETWORK_API_NETWORK_CLIENT_H
2014-01-28 09:00:02 +01:00
//////////////////////////////////////
// Created by Pontus Fransson 2013 //
// Modified by Dennis Andersen 2014 //
//////////////////////////////////////
2013-12-10 08:32:08 +01:00
2014-01-28 09:00:02 +01:00
#include "CustomNetProtocol.h"
#include "NetworkServerEventStruct.h"
#include "NetworkAPI_Preprocessor.h"
2013-12-10 08:32:08 +01:00
namespace Oyster
{
namespace Network
{
2014-01-28 09:00:02 +01:00
class NetworkSession;
2013-12-10 08:32:08 +01:00
extern "C"
{
2014-01-28 09:00:02 +01:00
class NET_API_EXPORT NetworkClient
2013-12-10 08:32:08 +01:00
{
2014-01-28 09:00:02 +01:00
public:
struct ClientEventArgs
{
enum EventType
{
EventType_ProtocolFailedToRecieve, // No data
EventType_ProtocolFailedToSend, // Data in data.protocol
EventType_ProtocolRecieved, // Data in data.protocol
EventType_Disconnect, // No data
} type;
union EventData
{
struct { Oyster::Network::CustomNetProtocol protocol; };
void * nothing;
} data;
};
typedef void(*ClientEventFunction)(NetEvent<NetworkClient*, ClientEventArgs> e);
2013-12-10 08:32:08 +01:00
public:
NetworkClient();
virtual ~NetworkClient();
2014-01-28 09:00:02 +01:00
bool operator ==(const NetworkClient& obj);
bool operator ==(const int& ID);
/**
*
*/
2014-01-29 10:18:01 +01:00
void Update();
2014-01-28 09:00:02 +01:00
/**
*
*/
bool Connect(int socket);
/**
*
*/
bool Connect(unsigned short port, const char serverIP[]);
2013-12-10 08:32:08 +01:00
2014-01-28 09:00:02 +01:00
/**
*
*/
void Disconnect();
2014-01-28 09:00:02 +01:00
/**
*
*/
void Send(CustomProtocolObject& protocol);
2014-01-28 09:00:02 +01:00
/**
*
*/
void Send(CustomNetProtocol* protocol);
2013-12-10 08:32:08 +01:00
2014-01-28 09:00:02 +01:00
/**
*
*/
void SetOwner(NetworkSession* owner);
2013-12-16 09:00:11 +01:00
2014-01-28 09:00:02 +01:00
/**
*
*/
bool IsConnected();
/**
*
*/
2014-01-07 10:26:09 +01:00
int GetID() const;
2014-01-29 10:18:01 +01:00
/**
*
*/
virtual void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
/** ! Deprecate !
* Do not use this furthermore, instead use void DataRecieved(NetEvent<NetworkClient*, ClientEventArgs> e);
* @see DataRecieved
*/
virtual void NetworkCallback(Oyster::Network::CustomNetProtocol& p);
2013-12-10 08:32:08 +01:00
private:
2014-01-29 10:18:01 +01:00
NetworkClient(const NetworkClient& obj);
NetworkClient& operator =(const NetworkClient& obj);
2013-12-10 08:32:08 +01:00
struct PrivateData;
PrivateData* privateData;
};
}
}
}
#endif