From be1c3e2af099d49c4e239a1d8ff25f50a2333ac4 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Sun, 23 Feb 2014 20:40:29 +0100 Subject: [PATCH] Sending strings in broadcast message. --- .../GameClientState/LanMenuState.cpp | 6 +++- Code/Game/GameProtocols/GeneralProtocols.h | 28 +++++++++++++------ .../GameServer/Implementation/GameServer.cpp | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 05ba435c..0eaa4d95 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -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; diff --git a/Code/Game/GameProtocols/GeneralProtocols.h b/Code/Game/GameProtocols/GeneralProtocols.h index 5e46aa10..cb58f3f8 100644 --- a/Code/Game/GameProtocols/GeneralProtocols.h +++ b/Code/Game/GameProtocols/GeneralProtocols.h @@ -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; } diff --git a/Code/Game/GameServer/Implementation/GameServer.cpp b/Code/Game/GameServer/Implementation/GameServer.cpp index 2c2eb20d..a4545a80 100644 --- a/Code/Game/GameServer/Implementation/GameServer.cpp +++ b/Code/Game/GameServer/Implementation/GameServer.cpp @@ -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;