Danbias/Code/Network/NetworkAPI/NetworkClient.h

155 lines
2.9 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;
EventData(){}
EventData(Oyster::Network::CustomNetProtocol& o)
{
protocol = o;
}
const EventData& operator=(EventData& o)
{
protocol = o.protocol;
return *this;
}
const EventData& operator=(Oyster::Network::CustomNetProtocol& o)
{
protocol = o; return *this;
}
2014-01-28 09:00:02 +01:00
} data;
ClientEventArgs(){}
ClientEventArgs(ClientEventArgs& o)
{
type = o.type;
data = o.data;
}
const ClientEventArgs& operator=(ClientEventArgs& o)
{
type = o.type;
data = o.data;
return *this;
}
2014-01-28 09:00:02 +01:00
};
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
/**
*
*/
bool Connect(unsigned short port, std::wstring serverIP);
/**Tries to connect with the same port and ip it earlier used for Connect.
*
*/
bool Reconnect();
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-02-12 09:02:44 +01:00
/**
*
*/
void SetMessagePump( ClientEventFunction func );
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);
2014-02-18 08:55:38 +01:00
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);
2014-02-12 14:33:56 +01:00
ClientEventFunction OnRecieve;
2013-12-10 08:32:08 +01:00
struct PrivateData;
PrivateData* privateData;
};
}
}
}
#endif