From 24ce24bbc10904d8c05f16d42ebdc9fdf14f37c7 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 8 Nov 2002 08:17:59 +0000 Subject: [PATCH] Network server mode accepts multiple connections --- stepmania/src/ScreenSandbox.cpp | 14 ++++-- stepmania/src/SongManager.cpp | 9 ++++ stepmania/src/SongManager.h | 2 + stepmania/src/StepMania.cpp | 81 ++++++++++++++++++++++++++++++--- stepmania/src/StepMania.dsw | 27 ----------- 5 files changed, 95 insertions(+), 38 deletions(-) diff --git a/stepmania/src/ScreenSandbox.cpp b/stepmania/src/ScreenSandbox.cpp index 76a1b821f8..e6601b82b0 100644 --- a/stepmania/src/ScreenSandbox.cpp +++ b/stepmania/src/ScreenSandbox.cpp @@ -16,13 +16,13 @@ #include "GameConstantsAndTypes.h" #include "PrefsManager.h" #include "Quad.h" +#include "RageNetwork.h" ScreenSandbox::ScreenSandbox() { m_text.LoadFromFont( THEME->GetPathTo("Fonts","normal") ); m_text.SetXY( CENTER_X, CENTER_Y ); - m_text.SetText( "Press Left to Become Server\nRight to become Client." ); this->AddChild( &m_text ); // m_Menu.Load( @@ -41,6 +41,13 @@ ScreenSandbox::ScreenSandbox() void ScreenSandbox::Update( float fDeltaTime ) { Screen::Update( fDeltaTime ); + + CArray aPackets; + NETWORK->Recv( aPackets ); + for( unsigned int i=0; iGetSongFilePath()) == 0 ) + return m_pSongs[i]; + + return NULL; +} diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index 773ad3dda9..effdaef438 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -62,6 +62,8 @@ public: * if successful, false if no song could be found. */ bool ChooseRandomSong(); + Song* GetSongFromPath( const CString &sSongPath ); + protected: void LoadStepManiaSongDir( CString sDir, void(*callback)() ); void LoadDWISongDir( CString sDir ); diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index d6c468f9b9..b08bb034ce 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -85,6 +85,14 @@ HANDLE g_hMutex; // Used to check if an instance of our app is already const DWORD g_dwWindowStyle = WS_POPUP|WS_CAPTION|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU; BOOL g_bIsActive = FALSE; // Whether the focus is on our app +// command line arguments +CString g_sSongPath = ""; +bool g_bBeClient = false; +bool g_bBeServer = false; +CString g_sServerIP = ""; +int g_iNumClients = 0; + +const int SM_PORT = 26573; // Quake port + "Ko" + "na" + "mitsu" //----------------------------------------------------------------------------- // Function prototypes @@ -139,11 +147,13 @@ void StructuredExceptionHandler(unsigned int uCode, } throw std::exception(msg); } -void SplitCommandLine(const char *lpCmdLine, CStringArray &aCmds) { +void SplitCommandLine(const char *lpCmdLine, CStringArray &aCmds) +{ const char *s = lpCmdLine; /* Split a string on whitespace, but never between quotes. */ - while(*s) { + while(*s) + { CString cmd; while( isspace(*s) ) s++; @@ -181,9 +191,41 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR CmdLine, int nCmdShow CStringArray Cmds; SplitCommandLine(CmdLine, Cmds); - for(unsigned i = 0; i < Cmds.size(); ++i) + for(unsigned i = 0; i < Cmds.size(); ) { - if(Cmds[i] == "--fsck") { crash(); exit( 0 ); } + if(Cmds[i] == "--fsck") + { + crash(); + exit( 0 ); + } + else if(Cmds[i] == "--song") + { + ++i; + g_sSongPath = Cmds[i]; + ++i; + } + else if(Cmds[i] == "--client") + { + ++i; + g_bBeClient = true; + } + else if(Cmds[i] == "--server") + { + ++i; + g_bBeServer = true; + } + else if(Cmds[i] == "--ip") + { + ++i; + g_sServerIP = Cmds[i]; + ++i; + } + else if(Cmds[i] == "--numclients") + { + ++i; + g_iNumClients = atoi(Cmds[i]); + ++i; + } } #ifndef _DEBUG @@ -742,8 +784,35 @@ HRESULT CreateObjects( HWND hWnd ) BringWindowToTop( hWnd ); SetForegroundWindow( hWnd ); - SCREENMAN->SetNewScreen( "ScreenTitleMenu" ); -// SCREENMAN->SetNewScreen( "ScreenSandbox" ); + if( g_bBeClient ) + { + // immediately try to connect to server + GAMESTATE->m_pCurSong = SONGMAN->GetSongFromPath( g_sSongPath ); + if( GAMESTATE->m_pCurSong == NULL ) + throw RageException( "The song '%s' is required to play this network game.", g_sSongPath ); + NETWORK->Init( false ); + if( !NETWORK->Connect( (const char*)g_sServerIP, SM_PORT ) ) + throw RageException( "Could not connect to server '%s'", g_sServerIP ); + SCREENMAN->SetNewScreen( "ScreenSandbox" ); + } + else if( g_bBeServer ) + { + // wait for clients to connect + GAMESTATE->m_pCurSong = SONGMAN->GetSongFromPath( g_sSongPath ); + if( GAMESTATE->m_pCurSong == NULL ) + throw RageException( "The song '%s' is required to play this network game.", g_sSongPath ); + NETWORK->Init( true ); + if( !NETWORK->Listen( SM_PORT ) ) + throw RageException( "Could not connect to server '%s'", g_sServerIP ); + SCREENMAN->SetNewScreen( "ScreenSandbox" ); + } + else + { + // normal game + SCREENMAN->SetNewScreen( "ScreenTitleMenu" ); +// SCREENMAN->SetNewScreen( "ScreenSandbox" ); + } + return S_OK; } diff --git a/stepmania/src/StepMania.dsw b/stepmania/src/StepMania.dsw index a387ec3711..72a285dc22 100644 --- a/stepmania/src/StepMania.dsw +++ b/stepmania/src/StepMania.dsw @@ -15,33 +15,6 @@ Package=<4> ############################################################################### -Project: "ZipArchive"=.\smpackage\ZipArchive\ZipArchive.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "smpackage"=.\smpackage\smpackage.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ - Begin Project Dependency - Project_Dep_Name ZipArchive - End Project Dependency -}}} - -############################################################################### - Global: Package=<5>