Network server mode accepts multiple connections

This commit is contained in:
Chris Danford
2002-11-08 08:17:59 +00:00
parent 6dcd870c1b
commit 24ce24bbc1
5 changed files with 95 additions and 38 deletions
+9 -5
View File
@@ -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<Packet,Packet> aPackets;
NETWORK->Recv( aPackets );
for( unsigned int i=0; i<aPackets.size(); i++ )
{
m_text.SetText( "Message received." );
}
}
void ScreenSandbox::DrawPrimitives()
@@ -59,10 +66,7 @@ void ScreenSandbox::Input( const DeviceInput& DeviceI, const InputEventType type
switch( DeviceI.button )
{
case DIK_LEFT:
m_text.SetText( "You are the server." );
break;
case DIK_RIGHT:
m_text.SetText( "You are the client." );
m_text.SetText( "Message sent." );
break;
case DIK_T:
break;
+9
View File
@@ -635,3 +635,12 @@ bool SongManager::ChooseRandomSong()
return false;
}
Song* SongManager::GetSongFromPath( const CString &sSongPath )
{
for( unsigned int i=0; i<m_pSongs.size(); i++ )
if( sSongPath.CompareNoCase(m_pSongs[i]->GetSongFilePath()) == 0 )
return m_pSongs[i];
return NULL;
}
+2
View File
@@ -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 );
+75 -6
View File
@@ -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;
}
-27
View File
@@ -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>