2013-11-21 14:49:30 +01:00
|
|
|
#ifndef NETWORK_DEPENDENCIES_PROTOCOLS_H
|
|
|
|
#define NETWORK_DEPENDENCIES_PROTOCOLS_H
|
|
|
|
|
2013-11-25 11:39:38 +01:00
|
|
|
//////////////////////////////////
|
|
|
|
// Created by Sam Svensson 2013 //
|
|
|
|
//////////////////////////////////
|
|
|
|
|
2013-11-21 14:49:30 +01:00
|
|
|
#include <string>
|
2013-11-21 13:40:52 +01:00
|
|
|
|
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Network
|
|
|
|
{
|
|
|
|
namespace Protocols
|
|
|
|
{
|
|
|
|
enum PackageType
|
|
|
|
{
|
2013-11-28 08:40:08 +01:00
|
|
|
PackageType_header,
|
|
|
|
PackageType_test,
|
|
|
|
PackageType_input,
|
|
|
|
PackageType_update_position
|
2013-11-21 13:40:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ProtocolHeader
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
int packageType;
|
|
|
|
int clientID;
|
|
|
|
|
2013-11-25 19:00:33 +01:00
|
|
|
ProtocolHeader() { this->packageType = package_type_header; }
|
|
|
|
virtual ~ProtocolHeader() { }
|
2013-11-21 13:40:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ProtocolTest : public ProtocolHeader
|
|
|
|
{
|
|
|
|
std::string textMessage;
|
2013-11-25 19:00:33 +01:00
|
|
|
unsigned int numOfFloats;
|
|
|
|
float *f;
|
|
|
|
|
2013-11-21 13:40:52 +01:00
|
|
|
ProtocolTest() { this->packageType = package_type_test; }
|
2013-11-25 19:00:33 +01:00
|
|
|
virtual ~ProtocolTest() { delete[] f; }
|
2013-11-21 13:40:52 +01:00
|
|
|
};
|
2013-11-22 11:40:55 +01:00
|
|
|
|
|
|
|
class ProtocolSet
|
2013-11-22 09:17:07 +01:00
|
|
|
{
|
2013-11-22 11:40:55 +01:00
|
|
|
public:
|
2013-11-25 19:00:33 +01:00
|
|
|
PackageType type;
|
2013-11-22 11:40:55 +01:00
|
|
|
union
|
|
|
|
{
|
|
|
|
ProtocolHeader* pHeader;
|
|
|
|
ProtocolTest *pTest;
|
|
|
|
|
|
|
|
}Protocol;
|
|
|
|
|
|
|
|
void Release()
|
2013-11-22 09:17:07 +01:00
|
|
|
{
|
2013-11-25 19:00:33 +01:00
|
|
|
switch(type)
|
2013-11-22 11:40:55 +01:00
|
|
|
{
|
|
|
|
case package_type_header:
|
|
|
|
if(Protocol.pHeader)
|
|
|
|
{
|
|
|
|
delete Protocol.pHeader;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case package_type_test:
|
|
|
|
if(Protocol.pTest)
|
|
|
|
{
|
|
|
|
delete Protocol.pTest;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-11-21 13:40:52 +01:00
|
|
|
}
|
|
|
|
}
|
2013-11-21 14:49:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|