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;
|
2014-01-29 15:01:14 +01:00
|
|
|
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;
|
2014-02-04 16:07:10 +01:00
|
|
|
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;
|
2014-02-04 16:07:10 +01:00
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-01-29 15:01:14 +01:00
|
|
|
bool Connect(ConnectionInfo& data);
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2013-12-11 21:45:43 +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();
|
2013-12-11 21:45:43 +01:00
|
|
|
|
2014-01-28 09:00:02 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2013-12-12 10:32:43 +01:00
|
|
|
void Send(CustomProtocolObject& protocol);
|
2013-12-11 21:45:43 +01:00
|
|
|
|
2014-01-28 09:00:02 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-02-04 16:07:10 +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;
|
2013-12-12 15:33:11 +01:00
|
|
|
|
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
|
|
|
|
*/
|
2014-02-04 16:07:10 +01:00
|
|
|
//virtual void NetworkCallback(Oyster::Network::CustomNetProtocol& p);
|
2014-01-29 10:18:01 +01:00
|
|
|
|
2014-01-29 15:01:14 +01:00
|
|
|
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);
|
|
|
|
|
2014-02-12 14:33:56 +01:00
|
|
|
ClientEventFunction OnRecieve;
|
2013-12-10 08:32:08 +01:00
|
|
|
struct PrivateData;
|
|
|
|
PrivateData* privateData;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|