Files
itgmania212121/stepmania/src/ScreenNetworkOptions.cpp
T

187 lines
5.3 KiB
C++
Raw Normal View History

#include "global.h"
2004-09-10 23:21:56 +00:00
#if !defined(WITHOUT_NETWORKING)
#include "NetworkSyncManager.h"
#include "ScreenNetworkOptions.h"
#include "RageLog.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
#include "ThemeManager.h"
#include "PrefsManager.h"
#include "ScreenManager.h"
#include "ScreenTextEntry.h"
#include "ScreenPrompt.h"
#include "NetworkSyncServer.h"
#include "VirtualKeyboard.h"
2004-10-25 12:40:05 +00:00
enum {
PO_CONNECTION,
PO_SERVER,
NUM_NETWORK_OPTIONS_LINES
};
enum {
NO_STOP_SERVER=0,
NO_START_SERVER
};
2005-02-11 07:50:26 +00:00
OptionRowDefinition g_NetworkOptionsLines[NUM_NETWORK_OPTIONS_LINES] = {
OptionRowDefinition( "Connection", true, "PRESS START" ),
OptionRowDefinition( "Server", true, "PRESS START" )
};
const ScreenMessage SM_DoneConnecting = ScreenMessage(SM_User+1);
const ScreenMessage SM_ServerNameEnter = ScreenMessage(SM_User+2);
static Preference<CString> g_sLastServer( Options, "LastConnectedServer", "" );
2004-11-26 17:28:47 +00:00
REGISTER_SCREEN_CLASS( ScreenNetworkOptions );
ScreenNetworkOptions::ScreenNetworkOptions( CString sClassName ) : ScreenOptions( sClassName )
{
LOG->Trace( "ScreenNetworkOptions::ScreenNetworkOptions()" );
2004-10-19 06:15:42 +00:00
m_sClassName = sClassName;
}
void ScreenNetworkOptions::Init()
{
ScreenOptions::Init();
2004-10-19 06:15:42 +00:00
g_NetworkOptionsLines[PO_CONNECTION].choices.clear();
2004-10-19 06:15:42 +00:00
if ( NSMAN->useSMserver )
g_NetworkOptionsLines[PO_CONNECTION].choices.push_back("Disconnect from "+NSMAN->GetServerName());
else
g_NetworkOptionsLines[PO_CONNECTION].choices.push_back("Connect...");
g_NetworkOptionsLines[PO_SERVER].choices.clear();
g_NetworkOptionsLines[PO_SERVER].choices.push_back("Stop");
g_NetworkOptionsLines[PO_SERVER].choices.push_back("Start...");
2005-01-03 22:20:39 +00:00
InitMenu(
INPUTMODE_SHARE_CURSOR,
g_NetworkOptionsLines,
NUM_NETWORK_OPTIONS_LINES );
2005-02-06 03:32:53 +00:00
SOUND->PlayMusic( THEME->GetPathS("ScreenMachineOptions","music") );
}
2004-12-05 11:59:39 +00:00
void ScreenNetworkOptions::GoToPrevScreen()
{
SCREENMAN->SetNewScreen( "ScreenOptionsMenu" );
}
2004-12-05 11:59:39 +00:00
void ScreenNetworkOptions::GoToNextScreen()
{
2004-12-05 11:59:39 +00:00
GoToPrevScreen();
}
void ScreenNetworkOptions::HandleScreenMessage( const ScreenMessage SM )
{
switch( SM )
{
case SM_DoneConnecting:
if( !ScreenTextEntry::s_bCancelledLast )
{
CString sNewName = ScreenTextEntry::s_sLastAnswer;
NSMAN->PostStartUp(sNewName);
NSMAN->DisplayStartupStatus();
2004-10-19 06:15:42 +00:00
UpdateConnectStatus( );
g_sLastServer = ScreenTextEntry::s_sLastAnswer;
}
break;
case SM_ServerNameEnter:
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) );
}
}
ScreenOptions::HandleScreenMessage( SM );
}
void ScreenNetworkOptions::MenuStart( PlayerNumber pn, const InputEventType type )
{
2004-10-19 06:15:42 +00:00
#if defined( WITHOUT_NETWORKING )
#else
switch( GetCurrentRow() )
{
case PO_CONNECTION:
2004-10-19 06:15:42 +00:00
if ( !NSMAN->useSMserver )
2004-10-25 12:40:05 +00:00
{
VIRTUALKB.Reset(VKMODE_IP);
SCREENMAN->TextEntry( SM_DoneConnecting, "Enter a Network Address\n127.0.0.1 to connect to yourself", g_sLastServer );
2004-10-25 12:40:05 +00:00
}
2004-10-19 06:15:42 +00:00
else {
NSMAN->CloseConnection();
SCREENMAN->SystemMessage("Disconnected from server.");
2004-10-19 06:15:42 +00:00
UpdateConnectStatus( );
}
break;
case PO_SERVER:
switch (m_Rows[GetCurrentRow()]->GetOneSharedSelection())
{
case NO_START_SERVER:
2004-09-06 21:28:56 +00:00
if (!NSMAN->isLanServer)
2004-11-18 09:09:29 +00:00
{
VIRTUALKB.Reset(VKMODE_PROFILE);
SCREENMAN->TextEntry( SM_ServerNameEnter, "Enter a server name...", "", NULL );
2004-11-18 09:09:29 +00:00
}
break;
case NO_STOP_SERVER:
if ( NSMAN->LANserver != NULL )
NSMAN->LANserver->ServerStop();
SCREENMAN->SystemMessage( "Server Stopped." );
NSMAN->isLanServer = false;
break;
}
break;
default:
ScreenOptions::MenuStart( pn, type );
}
2004-10-19 06:15:42 +00:00
#endif
}
void ScreenNetworkOptions::ImportOptions( int row ) { }
void ScreenNetworkOptions::ExportOptions( int row ) { }
2004-10-19 06:15:42 +00:00
void ScreenNetworkOptions::UpdateConnectStatus( )
{
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
/*
* (c) 2004 Charles Lohr
* 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.
*/