From a44506d6130da7ab06c59a4e297773c64ea519d4 Mon Sep 17 00:00:00 2001 From: Charles Lohr Date: Wed, 30 Nov 2005 00:37:47 +0000 Subject: [PATCH] Support UDP discovery broadcast packets (so we can list servers) --- stepmania/src/NetworkSyncServer.cpp | 17 ++++++++++++++++- stepmania/src/NetworkSyncServer.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/stepmania/src/NetworkSyncServer.cpp b/stepmania/src/NetworkSyncServer.cpp index 4b9bcb6324..436dd13094 100644 --- a/stepmania/src/NetworkSyncServer.cpp +++ b/stepmania/src/NetworkSyncServer.cpp @@ -47,6 +47,8 @@ bool StepManiaLanServer::ServerStart() if (server.bind(8765)) if (server.listen()) { + broadcast.create( IPPROTO_UDP ); + broadcast.connect( "255.255.255.255", 8765 ); stop = false; statsTime = time(NULL); return true; @@ -84,6 +86,7 @@ void StepManiaLanServer::ServerUpdate() UpdateClients(); if (time(NULL) > statsTime) { + BroadcastInfo(); SendStatsToClients(); statsTime = time(NULL); } @@ -993,10 +996,22 @@ void StepManiaLanServer::CheckLowerJudge(const unsigned int clientNum) Client[clientNum]->lowerJudge = true; } } + +void StepManiaLanServer::BroadcastInfo() +{ + PacketFunctions Binfo; + Binfo.ClearPacket(); + Binfo.WriteNT( servername ); + Binfo.Write2( 8765 ); + Binfo.Write2( Client.size() ); + + broadcast.SendPack( (char*)&Binfo.Data, Binfo.Position ); +} + #endif /* - * (c) 2003-2004 Joshua Allen + * (c) 2003-2005 Joshua Allen, Charles Lohr * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a diff --git a/stepmania/src/NetworkSyncServer.h b/stepmania/src/NetworkSyncServer.h index c3d6e618f4..af2acc6707 100644 --- a/stepmania/src/NetworkSyncServer.h +++ b/stepmania/src/NetworkSyncServer.h @@ -93,6 +93,7 @@ private: PacketFunctions Reply; vector Client; EzSockets server; + EzSockets broadcast; int ClientHost; vector playersPtr; time_t statsTime; @@ -136,6 +137,7 @@ private: void Disconnect(const unsigned int clientNum); void ClientsSongSelectStart(); void ResetLastSongInfo(); + void BroadcastInfo(); #endif };