Files
itgmania212121/stepmania/src/ScreenSMOnlineLogin.cpp
T

241 lines
7.3 KiB
C++
Raw Normal View History

2005-01-26 08:50:09 +00:00
#include "global.h"
2006-08-13 20:22:43 +00:00
#if !defined(WITHOUT_NETWORKING)
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 "Profile.h"
2005-12-22 03:10:04 +00:00
#include "LocalizedString.h"
2006-01-17 21:23:26 +00:00
#include "OptionRowHandler.h"
2005-01-07 04:10:31 +00:00
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS(ScreenSMOnlineLogin);
2005-01-07 04:10:31 +00:00
AutoScreenMessage( SM_SMOnlinePack )
AutoScreenMessage( SM_PasswordDone )
AutoScreenMessage( SM_NoProfilesDefined )
2005-12-20 08:35:47 +00:00
static LocalizedString DEFINE_A_PROFILE( "ScreenSMOnlineLogin", "You must define a Profile." );
void ScreenSMOnlineLogin::Init()
{
ScreenOptions::Init();
2006-01-17 06:11:22 +00:00
m_iPlayer = 0;
2005-01-07 04:10:31 +00:00
2006-01-17 21:23:26 +00:00
vector<OptionRowHandler*> vHands;
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull();
pHand->m_Def.m_sName = "Profile";
pHand->m_Def.m_bOneChoiceForAllPlayers = false;
pHand->m_Def.m_bAllowThemeItems = false;
pHand->m_Def.m_vEnabledForPlayers.clear();
2006-01-17 21:23:26 +00:00
FOREACH_PlayerNumber( pn )
pHand->m_Def.m_vEnabledForPlayers.insert( pn );
PROFILEMAN->GetLocalProfileDisplayNames( pHand->m_Def.m_vsChoices );
if( pHand->m_Def.m_vsChoices.empty() )
2005-02-06 03:32:53 +00:00
{
//Give myself a message so that I can bail out later
PostScreenMessage(SM_NoProfilesDefined, 0);
SAFE_DELETE(pHand);
2005-01-07 04:10:31 +00:00
}
else
vHands.push_back( pHand );
2006-01-17 21:31:50 +00:00
InitMenu( vHands );
SOUND->PlayMusic( THEME->GetPathS("ScreenOptionsServiceChild", "music"));
2006-01-17 21:23:26 +00:00
OptionRow &row = *m_pRows.back();
row.SetExitText("Login");
2005-02-08 23:55:07 +00:00
}
2005-01-07 04:10:31 +00:00
2005-07-13 19:01:42 +00:00
void ScreenSMOnlineLogin::ImportOptions( int iRow, const vector<PlayerNumber> &vpns )
2005-02-08 23:55:07 +00:00
{
2005-07-13 19:01:42 +00:00
switch( iRow )
{
case 0:
{
2006-01-22 01:00:06 +00:00
vector<RString> vsProfiles;
PROFILEMAN->GetLocalProfileIDs( vsProfiles );
FOREACH_PlayerNumber( pn )
{
2006-01-22 01:00:06 +00:00
vector<RString>::iterator iter = find(vsProfiles.begin(), vsProfiles.end(), ProfileManager::m_sDefaultLocalProfileID[pn].Get() );
if( iter != vsProfiles.end() )
2005-06-23 08:05:09 +00:00
m_pRows[0]->SetOneSelection((PlayerNumber) pn, iter - vsProfiles.begin());
}
}
break;
}
2005-02-08 23:55:07 +00:00
}
2005-01-26 08:50:09 +00:00
2005-07-13 19:01:42 +00:00
void ScreenSMOnlineLogin::ExportOptions( int iRow, const vector<PlayerNumber> &vpns )
2005-02-08 23:55:07 +00:00
{
2005-07-13 19:01:42 +00:00
switch( iRow )
{
case 0:
{
2006-01-22 01:00:06 +00:00
vector<RString> vsProfiles;
PROFILEMAN->GetLocalProfileIDs( vsProfiles );
FOREACH_EnabledPlayer( pn )
ProfileManager::m_sDefaultLocalProfileID[pn].Set( vsProfiles[m_pRows[0]->GetOneSelection(pn)] );
}
break;
}
2005-02-08 23:55:07 +00:00
}
2005-01-26 08:50:09 +00:00
2005-12-21 12:55:20 +00:00
static LocalizedString UNIQUE_PROFILE ( "ScreenSMOnlineLogin", "Each player needs a unique Profile." );
static LocalizedString YOU_ARE_LOGGING_ON_AS ( "ScreenSMOnlineLogin", "You are logging on as:" );
static LocalizedString ENTER_YOUR_PASSWORD ( "ScreenSMOnlineLogin", "Enter your password." );
2005-02-08 23:55:07 +00:00
void ScreenSMOnlineLogin::HandleScreenMessage(const ScreenMessage SM)
{
2006-01-22 01:00:06 +00:00
RString sLoginQuestion;
2006-01-17 07:09:29 +00:00
if( GAMESTATE->IsPlayerEnabled((PlayerNumber) m_iPlayer) )
sLoginQuestion = YOU_ARE_LOGGING_ON_AS.GetValue() + "\n" + GAMESTATE->GetPlayerDisplayName((PlayerNumber) m_iPlayer) + "\n" + ENTER_YOUR_PASSWORD.GetValue();
2005-12-21 12:55:20 +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 );
}
else if( SM == SM_NoProfilesDefined )
{
SCREENMAN->SystemMessage(DEFINE_A_PROFILE);
SCREENMAN->SetNewScreen("ScreenOptionsManageProfiles");
}
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();
if(Status == 0)
{
NSMAN->isSMOLoggedIn[m_iPlayer] = true;
m_iPlayer++;
if( GAMESTATE->IsPlayerEnabled((PlayerNumber) m_iPlayer) && m_iPlayer < NUM_PLAYERS )
2005-12-21 12:55:20 +00:00
{
ScreenTextEntry::Password(SM_PasswordDone, sLoginQuestion, NULL );
}
2005-02-08 23:55:07 +00:00
else
2005-08-25 00:22:32 +00:00
{
SCREENMAN->SetNewScreen( THEME->GetMetric (m_sName,"NextScreen") );
m_iPlayer = 0;
2005-08-25 00:22:32 +00:00
}
}
else
{
2006-01-22 01:00:06 +00:00
RString Responce = NSMAN->m_SMOnlinePacket.ReadNT();
2005-12-21 12:55:20 +00:00
ScreenTextEntry::Password( SM_PasswordDone, Responce + "\n\n"+sLoginQuestion, NULL );
}
2005-01-07 04:10:31 +00:00
}
}
2005-07-12 06:33:01 +00:00
else if( SM == SM_GoToNextScreen )
{
vector<PlayerNumber> v;
v.push_back( GAMESTATE->m_MasterPlayerNumber );
for( unsigned r=0; r<m_pRows.size(); r++ )
ExportOptions( r, v );
2005-10-27 04:54:45 +00:00
PREFSMAN->SavePrefsToDisk();
FOREACH_EnabledPlayer(pn)
{
PROFILEMAN->LoadLocalProfileFromMachine((PlayerNumber) pn);
}
if(GAMESTATE->IsPlayerEnabled((PlayerNumber) 0) && GAMESTATE->IsPlayerEnabled((PlayerNumber) 1) &&
(GAMESTATE->GetPlayerDisplayName((PlayerNumber) 0) == GAMESTATE->GetPlayerDisplayName((PlayerNumber) 1)))
{
2005-12-20 08:35:47 +00:00
SCREENMAN->SystemMessage( UNIQUE_PROFILE );
SCREENMAN->SetNewScreen("ScreenSMOnlineLogin");
}
else
{
m_iPlayer=0;
while(!GAMESTATE->IsPlayerEnabled((PlayerNumber) m_iPlayer))
++m_iPlayer;
2005-12-21 12:55:20 +00:00
ScreenTextEntry::Password(SM_PasswordDone, sLoginQuestion, NULL );
}
return;
}
2005-02-08 23:55:07 +00:00
ScreenOptions::HandleScreenMessage(SM);
}
2005-01-07 04:10:31 +00:00
void ScreenSMOnlineLogin::MenuStart( const InputEventPlus &input )
2005-02-08 23:55:07 +00:00
{
ScreenOptions::MenuStart( input );
2005-02-08 23:55:07 +00:00
}
2005-01-07 04:10:31 +00:00
2006-01-22 01:00:06 +00:00
RString ScreenSMOnlineLogin::GetSelectedProfileID()
2005-02-08 23:55:07 +00:00
{
2006-01-22 01:00:06 +00:00
vector<RString> vsProfiles;
2005-01-26 08:50:09 +00:00
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 )
2006-01-22 01:00:06 +00:00
return RString();
2005-01-26 08:50:09 +00:00
return vsProfiles[ Selection-1 ];
2005-02-08 23:55:07 +00:00
}
2005-01-07 04:10:31 +00:00
2006-08-10 06:43:39 +00:00
void ScreenSMOnlineLogin::SendLogin( RString sPassword )
2005-02-08 23:55:07 +00:00
{
2006-08-10 06:43:39 +00:00
RString PlayerName = GAMESTATE->GetPlayerDisplayName( (PlayerNumber) m_iPlayer );
2005-01-07 04:10:31 +00:00
2006-01-22 01:00:06 +00:00
RString HashedName = NSMAN->MD5Hex( sPassword );
2005-01-07 04:10:31 +00:00
int authMethod = 0;
if ( NSMAN->GetSMOnlineSalt() != 0 )
{
authMethod = 1;
2006-08-10 06:43:39 +00:00
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();
2006-08-10 06:43:39 +00:00
NSMAN->m_SMOnlinePacket.Write1( (uint8_t)0 ); //Login command
NSMAN->m_SMOnlinePacket.Write1( (uint8_t)m_iPlayer ); //Player
NSMAN->m_SMOnlinePacket.Write1( (uint8_t)authMethod ); //MD5 hash style
NSMAN->m_SMOnlinePacket.WriteNT( PlayerName );
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-08-25 00:22:32 +00:00
* (c) 2004-2005 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
*/