Danbias/Code/Network/NetworkAPI/NetworkClient.h

119 lines
2.2 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;
struct ConnectionInfo;
2014-01-28 09:00:02 +01:00
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(ConnectionInfo& data);
2014-01-28 09:00:02 +01:00
/**
*
*/
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);
virtual std::string GetIpAddress();
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