Danbias/Code/Game/GameProtocols/GeneralProtocols.h

121 lines
3.5 KiB
C
Raw Normal View History

#ifndef GAMELOGIC_GENERAL_PROTOCOLS_H
#define GAMELOGIC_GENERAL_PROTOCOLS_H
2013-12-18 15:28:47 +01:00
#include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h"
namespace GameLogic
{
2013-12-20 09:42:02 +01:00
struct Protocol_General_Status :public Oyster::Network::CustomProtocolObject
2013-12-18 15:28:47 +01:00
{
enum States
{
States_ready,
States_idle,
States_disconected,
States_leave
2013-12-18 15:28:47 +01:00
};
States status;
2013-12-20 09:42:02 +01:00
Protocol_General_Status()
2013-12-18 15:28:47 +01:00
{
this->protocol[0].value = protocol_General_Status;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
2013-12-18 15:28:47 +01:00
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
}
2014-01-07 10:26:09 +01:00
Protocol_General_Status(States state)
2013-12-20 09:42:02 +01:00
{
this->protocol[0].value = protocol_General_Status;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
2014-01-07 10:26:09 +01:00
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
this->status = state;
}
Protocol_General_Status(Oyster::Network::CustomNetProtocol& p)
{
status = (States)this->protocol[1].value.netShort;
2013-12-20 09:42:02 +01:00
}
2014-01-31 22:52:52 +01:00
Oyster::Network::CustomNetProtocol GetProtocol() override
2013-12-20 09:42:02 +01:00
{
2014-01-07 10:26:09 +01:00
this->protocol[1].value = status;
2013-12-20 09:42:02 +01:00
2014-01-31 22:52:52 +01:00
return protocol;
2013-12-20 09:42:02 +01:00
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_General_Text :public Oyster::Network::CustomProtocolObject
{
std::string text; //The text to send
int destination; //The destination if any (Ie a whisper to a player)
2013-12-20 09:42:02 +01:00
Protocol_General_Text()
: destination(-1) {}
Protocol_General_Text(Oyster::Network::CustomNetProtocol& p)
2013-12-20 09:42:02 +01:00
{
destination = p.Get(1).value.netInt;
text = p.Get(2).value.netCharPtr;
2013-12-20 09:42:02 +01:00
}
2014-01-31 22:52:52 +01:00
Oyster::Network::CustomNetProtocol GetProtocol() override
2013-12-20 09:42:02 +01:00
{
this->protocol.Set(0, protocol_General_Text, Oyster::Network::NetAttributeType_Short);
this->protocol.Set(1, destination, Oyster::Network::NetAttributeType_Int);
this->protocol.Set(2, text);
2014-01-31 22:52:52 +01:00
return protocol;
2013-12-20 09:42:02 +01:00
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
2014-02-23 18:38:20 +01:00
//#define protocol_Broadcast_Test 102
struct Protocol_Broadcast_Test :public Oyster::Network::CustomProtocolObject
{
2014-02-23 20:40:29 +01:00
unsigned short port;
std::string ip;
std::string name;
2014-02-23 18:38:20 +01:00
Protocol_Broadcast_Test()
{
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[0].value.netShort = protocol_Broadcast_Test;
2014-02-23 20:40:29 +01:00
this->protocol[1].type = Oyster::Network::NetAttributeType_UnsignedShort;
this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray;
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
this->port = 0;
2014-02-23 18:38:20 +01:00
}
2014-02-23 20:40:29 +01:00
Protocol_Broadcast_Test(unsigned short port, std::string ip, std::string name)
2014-02-23 18:38:20 +01:00
{
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[0].value.netShort = protocol_Broadcast_Test;
2014-02-23 20:40:29 +01:00
this->protocol[1].type = Oyster::Network::NetAttributeType_UnsignedShort;
this->port = port;
this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray;
this->ip = ip;
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
this->name = name;
2014-02-23 18:38:20 +01:00
}
Protocol_Broadcast_Test(Oyster::Network::CustomNetProtocol& p)
{
2014-02-23 20:40:29 +01:00
this->port = p[1].value.netUShort;
this->ip.assign(p[2].value.netCharPtr);
this->name.assign(p[3].value.netCharPtr);
2014-02-23 18:38:20 +01:00
}
Oyster::Network::CustomNetProtocol GetProtocol() override
{
2014-02-23 20:40:29 +01:00
this->protocol[1].value = this->port;
this->protocol.Set(2, ip);
this->protocol.Set(3, name);
2014-02-23 18:38:20 +01:00
return protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
2013-12-18 15:28:47 +01:00
}
#endif //!GAMELOGIC_CONTROL_PROTOCOLS_H