Sending strings in broadcast message.

This commit is contained in:
Pontus Fransson 2014-02-23 20:40:29 +01:00
parent d64f3d7a20
commit be1c3e2af0
3 changed files with 26 additions and 10 deletions

View File

@ -190,7 +190,11 @@ const GameClientState::NetEvent& LanMenuState::DataRecieved( const NetEvent &mes
{
Protocol_Broadcast_Test decoded(data);
int test = decoded.test;
unsigned short port = decoded.port;
std::string ip = decoded.ip;
std::string name = decoded.name;
printf("Broadcast message: %d: %s: %s\n", port, ip.c_str(), name.c_str());
this->privData->connectIP->AppendText(L"Hej");
}
break;

View File

@ -75,29 +75,41 @@ namespace GameLogic
//#define protocol_Broadcast_Test 102
struct Protocol_Broadcast_Test :public Oyster::Network::CustomProtocolObject
{
int test;
unsigned short port;
std::string ip;
std::string name;
Protocol_Broadcast_Test()
{
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[0].value.netShort = protocol_Broadcast_Test;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->test = 0;
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;
}
Protocol_Broadcast_Test(int test)
Protocol_Broadcast_Test(unsigned short port, std::string ip, std::string name)
{
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[0].value.netShort = protocol_Broadcast_Test;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->test = test;
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;
}
Protocol_Broadcast_Test(Oyster::Network::CustomNetProtocol& p)
{
this->test = p[1].value.netInt;
this->port = p[1].value.netUShort;
this->ip.assign(p[2].value.netCharPtr);
this->name.assign(p[3].value.netCharPtr);
}
Oyster::Network::CustomNetProtocol GetProtocol() override
{
this->protocol[1].value = this->test;
this->protocol[1].value = this->port;
this->protocol.Set(2, ip);
this->protocol.Set(3, name);
return protocol;
}

View File

@ -50,7 +50,7 @@ DanBiasServerReturn GameServerAPI::ServerInitiate(const ServerInitDesc& desc)
opt.mainOptions.listenPort = desc.listenPort;
opt.mainOptions.ownerSession = &lobby;
GameLogic::Protocol_Broadcast_Test broadcastMessage(2);
GameLogic::Protocol_Broadcast_Test broadcastMessage(opt.mainOptions.listenPort, "127.0.0.1", "ServerName");
opt.broadcastOptions.broadcast = true;
opt.broadcastOptions.broadcastInterval = 1.0f;