Allow for broadcast reception, so users can see all currently running SMLAN servers on a network easily. This code may be very active in the next few days depending on bugs we find.

This commit is contained in:
Charles Lohr
2005-11-30 04:04:21 +00:00
parent cf46864b1a
commit bc1b00e437
5 changed files with 89 additions and 2 deletions
+53 -1
View File
@@ -27,6 +27,7 @@ void NetworkSyncManager::SendChat(const CString& message) { }
void NetworkSyncManager::SelectUserSong() { } void NetworkSyncManager::SelectUserSong() { }
CString NetworkSyncManager::MD5Hex( const CString &sInput ) { return CString(); } CString NetworkSyncManager::MD5Hex( const CString &sInput ) { return CString(); }
int NetworkSyncManager::GetSMOnlineSalt() { return 0; } int NetworkSyncManager::GetSMOnlineSalt() { return 0; }
void NetworkSyncManager::GetListOfLANServers( vector<NetServerInfo>& AllServers ) { }
#else #else
#include "ezsockets.h" #include "ezsockets.h"
#include "ProfileManager.h" #include "ProfileManager.h"
@@ -58,6 +59,7 @@ int NetworkSyncManager::GetSMOnlineSalt()
NetworkSyncManager::NetworkSyncManager( LoadingWindow *ld ) NetworkSyncManager::NetworkSyncManager( LoadingWindow *ld )
{ {
LANserver = NULL; //So we know if it has been created yet LANserver = NULL; //So we know if it has been created yet
BroadcastReception = NULL;
if( GetCommandlineArgument( "runserver" )) if( GetCommandlineArgument( "runserver" ))
{ {
@@ -91,7 +93,13 @@ NetworkSyncManager::~NetworkSyncManager ()
//Close Connection to server nicely. //Close Connection to server nicely.
if (useSMserver) if (useSMserver)
NetPlayerClient->close(); NetPlayerClient->close();
delete NetPlayerClient; SAFE_DELETE( NetPlayerClient );
if ( BroadcastReception )
{
BroadcastReception->close();
SAFE_DELETE( BroadcastReception );
}
if( isLanServer ) if( isLanServer )
{ {
@@ -236,6 +244,10 @@ void NetworkSyncManager::StartUp()
else if( GetCommandlineArgument( "listen" ) ) else if( GetCommandlineArgument( "listen" ) )
PostStartUp("LISTEN"); PostStartUp("LISTEN");
BroadcastReception = new EzSockets;
BroadcastReception->create( IPPROTO_UDP );
BroadcastReception->bind( 8765 );
BroadcastReception->blocking = false;
} }
@@ -517,6 +529,41 @@ void NetworkSyncManager::Update(float fDeltaTime)
if (useSMserver) if (useSMserver)
ProcessInput(); ProcessInput();
PacketFunctions BroadIn;
if ( BroadcastReception->ReadPack( (char*)&BroadIn.Data, 1020 ) )
{
NetServerInfo ThisServer;
BroadIn.Position = 0;
if ( BroadIn.Read1() == 141 )
{
ThisServer.Name = BroadIn.ReadNT();
int port = BroadIn.Read2();
BroadIn.Read2(); //Num players connected.
unsigned long addy = ntohl(BroadcastReception->fromAddr.sin_addr.S_un.S_addr);
ThisServer.Address = ssprintf( "%d.%d.%d.%d:%d",
(addy<<0)>>24, (addy<<8)>>24, (addy<<16)>>24, (addy<<24)>>24, port );
//It's fairly safe to assume that users will not be on networks with more than
//30 or 40 servers. Until this point, maps would be slower than vectors.
//So I am going to use a vector to store all of the servers.
//
//In this situation, I will traverse the vector to find the element that
//contains the corresponding server.
unsigned int i;
for ( i = 0; i < m_vAllLANServers.size(); i++ )
{
if ( m_vAllLANServers[i].Address == ThisServer.Address )
{
m_vAllLANServers[i].Name = ThisServer.Name;
break;
}
}
if ( i >= m_vAllLANServers.size() )
m_vAllLANServers.push_back( ThisServer );
}
}
} }
void NetworkSyncManager::ProcessInput() void NetworkSyncManager::ProcessInput()
@@ -866,6 +913,11 @@ CString NetworkSyncManager::MD5Hex( const CString &sInput )
return HashedName; return HashedName;
} }
void NetworkSyncManager::GetListOfLANServers( vector<NetServerInfo>& AllServers )
{
AllServers = m_vAllLANServers;
}
static bool ConnectToServer( const CString &t ) static bool ConnectToServer( const CString &t )
{ {
NSMAN->PostStartUp( t ); NSMAN->PostStartUp( t );
+11
View File
@@ -52,6 +52,12 @@ enum NSScoreBoardColumn
}; };
#define FOREACH_NSScoreBoardColumn( sc ) FOREACH_ENUM( NSScoreBoardColumn, NUM_NSSB_CATEGORIES, sc ) #define FOREACH_NSScoreBoardColumn( sc ) FOREACH_ENUM( NSScoreBoardColumn, NUM_NSSB_CATEGORIES, sc )
struct NetServerInfo
{
CString Name;
CString Address;
};
class EzSockets; class EzSockets;
class StepManiaLanServer; class StepManiaLanServer;
@@ -147,6 +153,8 @@ public:
int GetSMOnlineSalt(); int GetSMOnlineSalt();
CString MD5Hex( const CString &sInput ); CString MD5Hex( const CString &sInput );
void GetListOfLANServers( vector< NetServerInfo > & AllServers );
private: private:
#if !defined(WITHOUT_NETWORKING) #if !defined(WITHOUT_NETWORKING)
@@ -170,6 +178,9 @@ private:
CString m_ServerName; CString m_ServerName;
EzSockets *NetPlayerClient; EzSockets *NetPlayerClient;
EzSockets *BroadcastReception;
vector< NetServerInfo > m_vAllLANServers;
int m_ServerVersion; //ServerVersion int m_ServerVersion; //ServerVersion
+1
View File
@@ -1001,6 +1001,7 @@ void StepManiaLanServer::BroadcastInfo()
{ {
PacketFunctions Binfo; PacketFunctions Binfo;
Binfo.ClearPacket(); Binfo.ClearPacket();
Binfo.Write1( 141 ); //Code 13 + 128
Binfo.WriteNT( servername ); Binfo.WriteNT( servername );
Binfo.Write2( 8765 ); Binfo.Write2( 8765 );
Binfo.Write2( Client.size() ); Binfo.Write2( Client.size() );
+23 -1
View File
@@ -16,6 +16,7 @@ enum {
PO_CONNECTION, PO_CONNECTION,
PO_SERVER, PO_SERVER,
PO_SCOREBOARD, PO_SCOREBOARD,
PO_SERVERS,
NUM_NETWORK_OPTIONS_LINES NUM_NETWORK_OPTIONS_LINES
}; };
@@ -33,7 +34,8 @@ enum
OptionRowDefinition g_NetworkOptionsLines[NUM_NETWORK_OPTIONS_LINES] = { OptionRowDefinition g_NetworkOptionsLines[NUM_NETWORK_OPTIONS_LINES] = {
OptionRowDefinition( "Connection", true, "PRESS START" ), OptionRowDefinition( "Connection", true, "PRESS START" ),
OptionRowDefinition( "Server", true, "PRESS START" ), OptionRowDefinition( "Server", true, "PRESS START" ),
OptionRowDefinition( "Scoreboard", true, "PRESS START" ) OptionRowDefinition( "Scoreboard", true, "PRESS START" ),
OptionRowDefinition( "Servers", true, "PRESS START" )
}; };
AutoScreenMessage( SM_DoneConnecting ) AutoScreenMessage( SM_DoneConnecting )
@@ -65,6 +67,17 @@ void ScreenNetworkOptions::Init()
g_NetworkOptionsLines[PO_SCOREBOARD].m_vsChoices.push_back("Off"); g_NetworkOptionsLines[PO_SCOREBOARD].m_vsChoices.push_back("Off");
g_NetworkOptionsLines[PO_SCOREBOARD].m_vsChoices.push_back("On"); g_NetworkOptionsLines[PO_SCOREBOARD].m_vsChoices.push_back("On");
//Get info on all received servers from NSMAN.
g_NetworkOptionsLines[PO_SERVERS].m_vsChoices.clear();
g_NetworkOptionsLines[PO_SERVERS].m_bAllowThemeItems = false;
NSMAN->GetListOfLANServers( AllServers );
if ( AllServers.size() == 0 )
g_NetworkOptionsLines[PO_SERVERS].m_vsChoices.push_back( "-none-" );
for ( unsigned int j = 0; j < AllServers.size(); j++ )
g_NetworkOptionsLines[PO_SERVERS].m_vsChoices.push_back( AllServers[j].Name );
//Enable all lines for all players //Enable all lines for all players
for ( unsigned int i = 0; i < NUM_NETWORK_OPTIONS_LINES; i++ ) for ( unsigned int i = 0; i < NUM_NETWORK_OPTIONS_LINES; i++ )
FOREACH_PlayerNumber( pn ) FOREACH_PlayerNumber( pn )
@@ -154,6 +167,15 @@ void ScreenNetworkOptions::MenuStart( const InputEventPlus &input )
else else
PREFSMAN->m_bEnableScoreboard.Set(false); PREFSMAN->m_bEnableScoreboard.Set(false);
break; break;
case PO_SERVERS:
if ( AllServers.size() != 0 )
{
string sNewName = AllServers[m_pRows[GetCurrentRow()]->GetOneSharedSelection()].Address;
NSMAN->PostStartUp(sNewName);
NSMAN->DisplayStartupStatus();
UpdateConnectStatus( );
}
break;
default: default:
ScreenOptions::MenuStart( input ); ScreenOptions::MenuStart( input );
} }
+1
View File
@@ -16,6 +16,7 @@ public:
private: private:
void ImportOptions( int iRow, const vector<PlayerNumber> &vpns ); void ImportOptions( int iRow, const vector<PlayerNumber> &vpns );
void ExportOptions( int iRow, const vector<PlayerNumber> &vpns ); void ExportOptions( int iRow, const vector<PlayerNumber> &vpns );
vector<NetServerInfo> AllServers;
void UpdateConnectStatus(); void UpdateConnectStatus();
}; };