2004-06-02 22:39:45 +00:00
|
|
|
#include "global.h"
|
2004-09-10 23:21:56 +00:00
|
|
|
|
|
|
|
|
#if !defined(WITHOUT_NETWORKING)
|
2004-06-02 22:39:45 +00:00
|
|
|
#include "NetworkSyncManager.h"
|
|
|
|
|
#include "ScreenNetworkOptions.h"
|
|
|
|
|
#include "RageLog.h"
|
2004-07-08 00:10:34 +00:00
|
|
|
#include "GameSoundManager.h"
|
2004-06-02 22:39:45 +00:00
|
|
|
#include "ThemeManager.h"
|
|
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#include "ScreenManager.h"
|
|
|
|
|
#include "ScreenTextEntry.h"
|
|
|
|
|
#include "ScreenPrompt.h"
|
2004-08-28 22:12:56 +00:00
|
|
|
#include "NetworkSyncServer.h"
|
2004-10-25 12:40:05 +00:00
|
|
|
|
2004-06-02 22:39:45 +00:00
|
|
|
enum {
|
|
|
|
|
PO_CONNECTION,
|
2004-08-28 22:12:56 +00:00
|
|
|
PO_SERVER,
|
2005-08-15 02:10:57 +00:00
|
|
|
PO_SCOREBOARD,
|
2004-06-02 22:39:45 +00:00
|
|
|
NUM_NETWORK_OPTIONS_LINES
|
|
|
|
|
};
|
|
|
|
|
|
2004-08-28 22:12:56 +00:00
|
|
|
enum {
|
|
|
|
|
NO_STOP_SERVER=0,
|
|
|
|
|
NO_START_SERVER
|
|
|
|
|
};
|
|
|
|
|
|
2005-08-15 02:10:57 +00:00
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
NO_SCOREBOARD_OFF=0,
|
|
|
|
|
NO_SCOREBOARD_ON
|
|
|
|
|
};
|
|
|
|
|
|
2005-02-11 07:50:26 +00:00
|
|
|
OptionRowDefinition g_NetworkOptionsLines[NUM_NETWORK_OPTIONS_LINES] = {
|
|
|
|
|
OptionRowDefinition( "Connection", true, "PRESS START" ),
|
2005-08-15 02:10:57 +00:00
|
|
|
OptionRowDefinition( "Server", true, "PRESS START" ),
|
|
|
|
|
OptionRowDefinition( "Scoreboard", true, "PRESS START" )
|
2004-06-02 22:39:45 +00:00
|
|
|
};
|
|
|
|
|
|
2005-03-28 08:01:36 +00:00
|
|
|
AutoScreenMessage( SM_DoneConnecting )
|
|
|
|
|
AutoScreenMessage( SM_ServerNameEnter )
|
2004-06-02 22:39:45 +00:00
|
|
|
|
2005-05-19 01:26:41 +00:00
|
|
|
static Preference<CString> g_sLastServer( "LastConnectedServer", "" );
|
2004-12-07 01:47:32 +00:00
|
|
|
|
2004-11-26 17:28:47 +00:00
|
|
|
REGISTER_SCREEN_CLASS( ScreenNetworkOptions );
|
2004-06-02 22:39:45 +00:00
|
|
|
ScreenNetworkOptions::ScreenNetworkOptions( CString sClassName ) : ScreenOptions( sClassName )
|
|
|
|
|
{
|
|
|
|
|
LOG->Trace( "ScreenNetworkOptions::ScreenNetworkOptions()" );
|
|
|
|
|
|
2004-10-19 06:15:42 +00:00
|
|
|
m_sClassName = sClassName;
|
2005-02-23 06:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenNetworkOptions::Init()
|
|
|
|
|
{
|
|
|
|
|
ScreenOptions::Init();
|
2004-10-19 06:15:42 +00:00
|
|
|
|
2005-07-06 06:11:56 +00:00
|
|
|
g_NetworkOptionsLines[PO_CONNECTION].m_vsChoices.clear();
|
2004-10-19 06:15:42 +00:00
|
|
|
if ( NSMAN->useSMserver )
|
2005-07-06 06:11:56 +00:00
|
|
|
g_NetworkOptionsLines[PO_CONNECTION].m_vsChoices.push_back("Disconnect from "+NSMAN->GetServerName());
|
2004-10-19 06:15:42 +00:00
|
|
|
else
|
2005-07-06 06:11:56 +00:00
|
|
|
g_NetworkOptionsLines[PO_CONNECTION].m_vsChoices.push_back("Connect...");
|
2004-08-28 22:12:56 +00:00
|
|
|
|
2005-07-06 06:11:56 +00:00
|
|
|
g_NetworkOptionsLines[PO_SERVER].m_vsChoices.clear();
|
|
|
|
|
g_NetworkOptionsLines[PO_SERVER].m_vsChoices.push_back("Stop");
|
|
|
|
|
g_NetworkOptionsLines[PO_SERVER].m_vsChoices.push_back("Start...");
|
2005-08-15 02:10:57 +00:00
|
|
|
|
|
|
|
|
g_NetworkOptionsLines[PO_SCOREBOARD].m_vsChoices.clear();
|
|
|
|
|
g_NetworkOptionsLines[PO_SCOREBOARD].m_vsChoices.push_back("Off");
|
|
|
|
|
g_NetworkOptionsLines[PO_SCOREBOARD].m_vsChoices.push_back("On");
|
2004-08-28 22:12:56 +00:00
|
|
|
|
2005-03-10 18:03:19 +00:00
|
|
|
//Enable all lines for all players
|
|
|
|
|
for ( unsigned int i = 0; i < NUM_NETWORK_OPTIONS_LINES; i++ )
|
|
|
|
|
FOREACH_PlayerNumber( pn )
|
|
|
|
|
g_NetworkOptionsLines[i].m_vEnabledForPlayers.insert( pn );
|
|
|
|
|
|
2005-02-24 13:48:14 +00:00
|
|
|
vector<OptionRowDefinition> vDefs( &g_NetworkOptionsLines[0], &g_NetworkOptionsLines[ARRAYSIZE(g_NetworkOptionsLines)] );
|
|
|
|
|
vector<OptionRowHandler*> vHands( vDefs.size(), NULL );
|
|
|
|
|
|
2005-07-15 03:28:09 +00:00
|
|
|
InitMenu( vDefs, vHands );
|
2004-06-02 22:39:45 +00:00
|
|
|
|
2005-08-15 02:10:57 +00:00
|
|
|
m_pRows[PO_SCOREBOARD]->SetOneSharedSelection(PREFSMAN->m_bEnableScoreboard);
|
|
|
|
|
|
2005-02-06 03:32:53 +00:00
|
|
|
SOUND->PlayMusic( THEME->GetPathS("ScreenMachineOptions","music") );
|
2004-06-02 22:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScreenNetworkOptions::HandleScreenMessage( const ScreenMessage SM )
|
|
|
|
|
{
|
2005-03-23 08:48:38 +00:00
|
|
|
if( SM == SM_DoneConnecting )
|
2004-06-02 22:39:45 +00:00
|
|
|
{
|
|
|
|
|
if( !ScreenTextEntry::s_bCancelledLast )
|
|
|
|
|
{
|
|
|
|
|
CString sNewName = ScreenTextEntry::s_sLastAnswer;
|
|
|
|
|
NSMAN->PostStartUp(sNewName);
|
|
|
|
|
NSMAN->DisplayStartupStatus();
|
2004-10-19 06:15:42 +00:00
|
|
|
UpdateConnectStatus( );
|
2005-05-06 20:41:05 +00:00
|
|
|
g_sLastServer.Set( ScreenTextEntry::s_sLastAnswer );
|
2004-06-02 22:39:45 +00:00
|
|
|
}
|
2005-03-23 08:48:38 +00:00
|
|
|
}
|
|
|
|
|
else if( SM == SM_ServerNameEnter )
|
|
|
|
|
{
|
2004-08-28 22:12:56 +00:00
|
|
|
if( !ScreenTextEntry::s_bCancelledLast )
|
|
|
|
|
{
|
|
|
|
|
if ( NSMAN->LANserver == NULL)
|
|
|
|
|
NSMAN->LANserver = new StepManiaLanServer;
|
|
|
|
|
NSMAN->LANserver->servername = ScreenTextEntry::s_sLastAnswer;
|
|
|
|
|
if (NSMAN->LANserver->ServerStart())
|
|
|
|
|
{
|
|
|
|
|
NSMAN->isLanServer = true;
|
|
|
|
|
SCREENMAN->SystemMessage( "Server Started." );
|
|
|
|
|
}
|
|
|
|
|
else
|
2004-09-06 18:20:16 +00:00
|
|
|
SCREENMAN->SystemMessage( "Server failed: " + NSMAN->LANserver->lastError + ssprintf(" Code:%d",NSMAN->LANserver->lastErrorCode) );
|
2004-08-28 22:12:56 +00:00
|
|
|
}
|
2004-06-02 22:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScreenOptions::HandleScreenMessage( SM );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-09-23 00:44:52 +00:00
|
|
|
void ScreenNetworkOptions::MenuStart( const InputEventPlus &input )
|
2004-06-02 22:39:45 +00:00
|
|
|
{
|
2004-10-19 06:15:42 +00:00
|
|
|
#if defined( WITHOUT_NETWORKING )
|
|
|
|
|
#else
|
2004-06-02 22:39:45 +00:00
|
|
|
switch( GetCurrentRow() )
|
|
|
|
|
{
|
|
|
|
|
case PO_CONNECTION:
|
2004-10-19 06:15:42 +00:00
|
|
|
if ( !NSMAN->useSMserver )
|
2004-10-25 12:40:05 +00:00
|
|
|
{
|
2005-07-03 04:45:34 +00:00
|
|
|
ScreenTextEntry::TextEntry( SM_DoneConnecting, "Enter a Network Address\n127.0.0.1 to connect to yourself", g_sLastServer, 128 );
|
2004-10-25 12:40:05 +00:00
|
|
|
}
|
2005-03-22 20:15:24 +00:00
|
|
|
else
|
|
|
|
|
{
|
2004-06-02 22:39:45 +00:00
|
|
|
NSMAN->CloseConnection();
|
|
|
|
|
SCREENMAN->SystemMessage("Disconnected from server.");
|
2004-10-19 06:15:42 +00:00
|
|
|
UpdateConnectStatus( );
|
2004-06-02 22:39:45 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2004-08-28 22:12:56 +00:00
|
|
|
case PO_SERVER:
|
2005-06-23 08:05:09 +00:00
|
|
|
switch( m_pRows[GetCurrentRow()]->GetOneSharedSelection() )
|
2004-08-28 22:12:56 +00:00
|
|
|
{
|
|
|
|
|
case NO_START_SERVER:
|
2004-09-06 21:28:56 +00:00
|
|
|
if (!NSMAN->isLanServer)
|
2004-11-18 09:09:29 +00:00
|
|
|
{
|
2005-07-03 04:45:34 +00:00
|
|
|
ScreenTextEntry::TextEntry( SM_ServerNameEnter, "Enter a server name...", "", 0);
|
2004-11-18 09:09:29 +00:00
|
|
|
}
|
2004-08-28 22:12:56 +00:00
|
|
|
break;
|
|
|
|
|
case NO_STOP_SERVER:
|
|
|
|
|
if ( NSMAN->LANserver != NULL )
|
|
|
|
|
NSMAN->LANserver->ServerStop();
|
2004-08-29 00:47:06 +00:00
|
|
|
SCREENMAN->SystemMessage( "Server Stopped." );
|
|
|
|
|
NSMAN->isLanServer = false;
|
2004-08-28 22:12:56 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2005-08-15 02:10:57 +00:00
|
|
|
case PO_SCOREBOARD:
|
|
|
|
|
if (m_pRows[PO_SCOREBOARD]->GetOneSharedSelection() == NO_SCOREBOARD_ON)
|
|
|
|
|
PREFSMAN->m_bEnableScoreboard.Set(true);
|
|
|
|
|
else
|
|
|
|
|
PREFSMAN->m_bEnableScoreboard.Set(false);
|
|
|
|
|
break;
|
2004-06-02 22:39:45 +00:00
|
|
|
default:
|
2005-09-23 00:44:52 +00:00
|
|
|
ScreenOptions::MenuStart( input );
|
2004-06-02 22:39:45 +00:00
|
|
|
}
|
2004-10-19 06:15:42 +00:00
|
|
|
#endif
|
2004-06-02 22:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
2005-07-13 19:01:42 +00:00
|
|
|
void ScreenNetworkOptions::ImportOptions( int iRow, const vector<PlayerNumber> &vpns ) { }
|
|
|
|
|
void ScreenNetworkOptions::ExportOptions( int iRow, const vector<PlayerNumber> &vpns ) { }
|
2004-06-02 22:39:45 +00:00
|
|
|
|
2004-10-19 06:15:42 +00:00
|
|
|
void ScreenNetworkOptions::UpdateConnectStatus( )
|
2004-06-02 22:39:45 +00:00
|
|
|
{
|
2004-10-19 06:15:42 +00:00
|
|
|
SCREENMAN->SetNewScreen( m_sClassName );
|
2004-06-08 05:22:33 +00:00
|
|
|
}
|
2004-09-10 23:21:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
2004-06-08 05:22:33 +00:00
|
|
|
/*
|
2005-08-15 02:10:57 +00:00
|
|
|
* (c) 2004 Charles Lohr, Josh Allen
|
2004-06-08 05:22:33 +00:00
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|