2005-01-07 04:10:31 +00:00
#if !defined(WITHOUT_NETWORKING)
2005-01-26 08:50:09 +00:00
#include "global.h"
2005-01-07 04:10:31 +00:00
#include "ScreenSMOnlineLogin.h"
2005-01-26 08:50:09 +00:00
#include "RageLog.h"
#include "ProfileManager.h"
2005-01-07 04:10:31 +00:00
#include "GameSoundManager.h"
2005-01-26 08:50:09 +00:00
#include "ThemeManager.h"
#include "PrefsManager.h"
#include "ScreenManager.h"
#include "ScreenTextEntry.h"
#include "ScreenPrompt.h"
2005-01-07 04:10:31 +00:00
#include "GameState.h"
2005-01-26 08:50:09 +00:00
#include "NetworkSyncManager.h"
#include "ScreenTextEntry.h"
2005-01-07 04:10:31 +00:00
2005-01-26 08:50:09 +00:00
REGISTER_SCREEN_CLASS ( ScreenSMOnlineLogin );
2005-01-07 04:10:31 +00:00
2005-03-28 08:01:36 +00:00
AutoScreenMessage ( SM_SMOnlinePack )
AutoScreenMessage ( SM_PasswordDone )
2005-02-11 07:50:26 +00:00
OptionRowDefinition g_ProfileLine [ 1 ] = {
OptionRowDefinition ( "Profile" , false )
2005-01-26 08:50:09 +00:00
};
2005-01-07 04:10:31 +00:00
2005-02-08 23:55:07 +00:00
ScreenSMOnlineLogin :: ScreenSMOnlineLogin ( CString sClassName ) : ScreenOptions ( sClassName )
{
2005-01-26 08:50:09 +00:00
LOG -> Trace ( "ScreenSMOnlineLogin::ScreenSMOnlineLogin()" );
2005-02-23 06:29:05 +00:00
}
void ScreenSMOnlineLogin :: Init ()
{
ScreenOptions :: Init ();
2005-01-07 04:10:31 +00:00
2005-07-06 06:11:56 +00:00
g_ProfileLine [ 0 ]. m_vsChoices . clear ();
PROFILEMAN -> GetLocalProfileNames ( g_ProfileLine [ 0 ]. m_vsChoices );
2005-01-07 04:10:31 +00:00
2005-07-06 06:11:56 +00:00
if ( ! g_ProfileLine [ 0 ]. m_vsChoices . size ())
2005-02-06 03:32:53 +00:00
{
2005-02-08 23:55:07 +00:00
SCREENMAN -> SystemMessage ( "You Must Define A Profile!" );
SCREENMAN -> SetNewScreen ( "ScreenProfileOptions" );
2005-01-07 04:10:31 +00:00
}
2005-02-08 23:55:07 +00:00
else
2005-02-06 03:32:53 +00:00
{
2005-03-10 18:03:19 +00:00
FOREACH_PlayerNumber ( pn )
g_ProfileLine [ 0 ]. m_vEnabledForPlayers . insert ( pn );
2005-02-24 13:48:14 +00:00
vector < OptionRowDefinition > vDefs ( & g_ProfileLine [ 0 ], & g_ProfileLine [ ARRAYSIZE ( g_ProfileLine )] );
vector < OptionRowHandler *> vHands ( vDefs . size (), NULL );
InitMenu ( INPUTMODE_SHARE_CURSOR , vDefs , vHands );
2005-02-08 23:55:07 +00:00
SOUND -> PlayMusic ( THEME -> GetPathS ( "ScreenMachineOptions" , "music" ));
2005-06-23 08:05:09 +00:00
OptionRow & row = * m_pRows . back ();
2005-02-19 19:17:28 +00:00
row . SetExitText ( "Login" );
2005-01-26 08:50:09 +00:00
}
2005-02-08 23:55:07 +00:00
}
2005-01-07 04:10:31 +00:00
2005-04-03 06:21:02 +00:00
void ScreenSMOnlineLogin :: ImportOptions ( int row , const vector < PlayerNumber > & vpns )
2005-02-08 23:55:07 +00:00
{
2005-02-24 01:17:39 +00:00
switch ( row )
2005-02-09 04:24:41 +00:00
{
2005-02-24 01:17:39 +00:00
case 0 :
{
vector < CString > vsProfiles ;
PROFILEMAN -> GetLocalProfileIDs ( vsProfiles );
CStringArray :: iterator iter ;
FOREACH_PlayerNumber ( pn )
{
2005-05-16 09:36:32 +00:00
iter = find ( vsProfiles . begin (), vsProfiles . end (), PREFSMAN -> GetDefaultLocalProfileID ( pn ). Get () );
2005-02-24 01:17:39 +00:00
if ( iter != vsProfiles . end () )
2005-06-23 08:05:09 +00:00
m_pRows [ 0 ] -> SetOneSelection (( PlayerNumber ) pn , iter - vsProfiles . begin ());
2005-02-24 01:17:39 +00:00
}
}
break ;
2005-02-09 04:24:41 +00:00
}
2005-02-08 23:55:07 +00:00
}
2005-01-26 08:50:09 +00:00
2005-04-03 06:21:02 +00:00
void ScreenSMOnlineLogin :: ExportOptions ( int row , const vector < PlayerNumber > & vpns )
2005-02-08 23:55:07 +00:00
{
2005-02-24 01:17:39 +00:00
switch ( row )
2005-02-09 04:24:41 +00:00
{
2005-02-24 01:17:39 +00:00
case 0 :
{
vector < CString > vsProfiles ;
PROFILEMAN -> GetLocalProfileIDs ( vsProfiles );
FOREACH_EnabledPlayer ( pn )
2005-06-23 08:05:09 +00:00
PREFSMAN -> GetDefaultLocalProfileID ( pn ). Set ( vsProfiles [ m_pRows [ 0 ] -> GetOneSelection ( pn )] );
2005-02-24 01:17:39 +00:00
}
break ;
2005-02-09 04:24:41 +00:00
}
2005-02-08 23:55:07 +00:00
}
2005-01-26 08:50:09 +00:00
2005-02-08 23:55:07 +00:00
void ScreenSMOnlineLogin :: HandleScreenMessage ( const ScreenMessage SM )
{
2005-03-23 08:48:38 +00:00
if ( SM == SM_PasswordDone )
2005-02-08 23:55:07 +00:00
{
2005-01-26 08:50:09 +00:00
if ( ! ScreenTextEntry :: s_bCancelledLast )
2005-02-08 23:55:07 +00:00
SendLogin ( ScreenTextEntry :: s_sLastAnswer );
2005-01-26 08:50:09 +00:00
else
2005-07-12 06:50:18 +00:00
SCREENMAN -> PostMessageToTopScreen ( SM_GoToPrevScreen , 0 );
2005-03-23 08:48:38 +00:00
}
else if ( SM == SM_SMOnlinePack )
{
2005-01-07 04:10:31 +00:00
int ResponceCode = NSMAN -> m_SMOnlinePacket . Read1 ();
2005-02-08 23:55:07 +00:00
if ( ResponceCode == 0 )
{
int Status = NSMAN -> m_SMOnlinePacket . Read1 ();
2005-03-23 08:48:38 +00:00
if ( Status == 0 )
{
NSMAN -> isSMOLoggedIn [ m_iPlayer ] = true ;
m_iPlayer ++ ;
if ( GAMESTATE -> IsPlayerEnabled (( PlayerNumber ) m_iPlayer ) && m_iPlayer < NUM_PLAYERS )
2005-07-03 04:45:34 +00:00
ScreenTextEntry :: Password ( SM_PasswordDone , "You are logging on as: \n " + GAMESTATE -> GetPlayerDisplayName (( PlayerNumber ) m_iPlayer ) + " \n\n Please enter your password." , NULL );
2005-02-08 23:55:07 +00:00
else
2005-07-12 06:50:18 +00:00
SCREENMAN -> PostMessageToTopScreen ( SM_GoToNextScreen , 0 );
2005-03-23 08:48:38 +00:00
}
else
{
CString Responce = NSMAN -> m_SMOnlinePacket . ReadNT ();
2005-07-03 04:45:34 +00:00
ScreenTextEntry :: Password ( SM_PasswordDone , Responce + " \n\n You are logging on as: \n " + GAMESTATE -> GetPlayerDisplayName (( PlayerNumber ) m_iPlayer ) + " \n\n Please enter your password." , NULL );
2005-03-23 08:48:38 +00:00
}
2005-01-07 04:10:31 +00:00
}
}
2005-07-12 06:33:01 +00:00
else if ( SM == SM_GoToNextScreen )
2005-07-12 06:33:00 +00:00
{
vector < PlayerNumber > v ;
v . push_back ( GAMESTATE -> m_MasterPlayerNumber );
for ( unsigned r = 0 ; r < m_pRows . size (); r ++ )
ExportOptions ( r , v );
PREFSMAN -> SaveGlobalPrefsToDisk ();
FOREACH_EnabledPlayer ( pn )
{
PROFILEMAN -> LoadLocalProfileFromMachine (( PlayerNumber ) pn );
}
if ( GAMESTATE -> IsPlayerEnabled (( PlayerNumber ) 0 ) && GAMESTATE -> IsPlayerEnabled (( PlayerNumber ) 1 ) &&
( GAMESTATE -> GetPlayerDisplayName (( PlayerNumber ) 0 ) == GAMESTATE -> GetPlayerDisplayName (( PlayerNumber ) 1 )))
{
SCREENMAN -> SystemMessage ( "Each Player Needs A Unique Profile!" );
SCREENMAN -> SetNewScreen ( "ScreenSMOnlineLogin" );
}
else
{
m_iPlayer = 0 ;
while ( ! GAMESTATE -> IsPlayerEnabled (( PlayerNumber ) m_iPlayer ))
++ m_iPlayer ;
ScreenTextEntry :: Password ( SM_PasswordDone , "You are logging on as: \n " + GAMESTATE -> GetPlayerDisplayName (( PlayerNumber ) m_iPlayer ) + " \n\n Please enter your password." , NULL );
}
return ;
}
else if ( SM == SM_GoToPrevScreen )
{
2005-07-12 06:50:18 +00:00
SCREENMAN -> PostMessageToTopScreen ( SM_GoToPrevScreen , 0 );
2005-07-12 06:33:00 +00:00
return ;
}
2005-02-08 23:55:07 +00:00
ScreenOptions :: HandleScreenMessage ( SM );
}
2005-01-07 04:10:31 +00:00
2005-02-08 23:55:07 +00:00
void ScreenSMOnlineLogin :: MenuStart ( PlayerNumber pn , const InputEventType type )
{
ScreenOptions :: MenuStart ( pn , type );
}
2005-01-07 04:10:31 +00:00
2005-02-08 23:55:07 +00:00
CString ScreenSMOnlineLogin :: GetSelectedProfileID ()
{
2005-01-26 08:50:09 +00:00
vector < CString > vsProfiles ;
PROFILEMAN -> GetLocalProfileIDs ( vsProfiles );
2005-01-07 04:10:31 +00:00
2005-06-23 08:05:09 +00:00
const OptionRow & row = * m_pRows [ GetCurrentRow ()];
2005-01-26 08:50:09 +00:00
const int Selection = row . GetOneSharedSelection ();
if ( ! Selection )
return "" ;
return vsProfiles [ Selection - 1 ];
2005-02-08 23:55:07 +00:00
}
2005-01-07 04:10:31 +00:00
2005-02-08 23:55:07 +00:00
void ScreenSMOnlineLogin :: SendLogin ( CString sPassword )
{
2005-01-26 08:50:09 +00:00
CString PlayerName = GAMESTATE -> GetPlayerDisplayName (( PlayerNumber ) m_iPlayer );
2005-01-07 04:10:31 +00:00
2005-05-08 04:42:33 +00:00
CString HashedName = NSMAN -> MD5Hex ( sPassword );
2005-01-07 04:10:31 +00:00
2005-05-08 04:42:33 +00:00
int authMethod = 0 ;
if ( NSMAN -> GetSMOnlineSalt () != 0 )
{
authMethod = 1 ;
HashedName = NSMAN -> MD5Hex ( HashedName + ssprintf ( "%d" , NSMAN -> GetSMOnlineSalt () ) );
}
2005-01-07 22:00:08 +00:00
2005-01-12 22:23:56 +00:00
NSMAN -> m_SMOnlinePacket . ClearPacket ();
2005-01-26 08:50:09 +00:00
NSMAN -> m_SMOnlinePacket . Write1 (( uint8_t ) 0 ); //Login command
NSMAN -> m_SMOnlinePacket . Write1 (( uint8_t ) m_iPlayer ); //Player
2005-05-08 04:42:33 +00:00
NSMAN -> m_SMOnlinePacket . Write1 (( uint8_t ) authMethod ); //MD5 hash style
2005-01-26 08:50:09 +00:00
NSMAN -> m_SMOnlinePacket . WriteNT ( PlayerName );
2005-01-07 04:10:31 +00:00
NSMAN -> m_SMOnlinePacket . WriteNT ( HashedName );
NSMAN -> SendSMOnline ( );
2005-02-08 23:55:07 +00:00
}
2005-01-07 04:10:31 +00:00
#endif
/*
2005-01-26 08:50:09 +00:00
* (c) 2004 Charles Lohr Adam Lowman
2005-01-07 04:10:31 +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.
2005-03-12 08:58:35 +00:00
*/