⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chworld.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		pItem->Enable();
	}
											// Set the frame title

	GetCore()->SetFrameTitle( pWorldInfo->GetName() );
 #endif

											/* Store the world name & type in
												the cmd line info */

	GetCmdLine().SetWorld( pWorldInfo->GetName(), &pWorldInfo->GetType() );

											// Reset the TinTin processor
	GetTinTin()->Reset();
											// Start on line time tracking
#if !defined( CH_PUEBLO_PLUGIN )
	LOADSTRING( IDS_ONLINE, strOnLine );
	GetCore()->UpdateSessionPane( strOnLine, true );
#endif

											// Init the ChWorldConn
	GetWorldConnection()->InitConnection();
											/* Send connect information to
												the server */
	TrackUsage( worldConnect );

#if !defined( CH_PUEBLO_PLUGIN )
											// Enable the 'add' command
	LOADSTRING( IDS_MENU_ADD, strText );
	if (pItem = GetWorldMenu()->FindItem( strText ))
	{
		pItem->Enable();
	}
#endif

	ASSERT( 0 != GetWorldInfo() );

	#if defined( CH_MSW )
	{										/* Put up the connection
												confirmation status message */

		LOADSTRING( IDS_STATUS_CONNECTED_FMT, strStatusFmt );
		strStatus.Format( strStatusFmt, (const char*)GetWorldInfo()->GetName() );

		GetCore()->DisplayStatus( strStatus );
	}
	#endif	// defined( CH_MSW )
											/* Gather information from each
												of our controlled modules
												about what they wish to add to
												the PUEBLOCLIENT command
												line... */
	SendConnectedMsg();
}


void ChWorldMainInfo::OnInvalidWorld( const string& strReason )
{
											// Shutdown the world
	ShutdownWorld( false );
											/* Display the reason for the
												disconnect */
	#if defined( CH_MSW )
	{
		GetCore()->GetFrameWnd()->MessageBox( (const char*)strReason,  0,
						MB_OK | MB_ICONINFORMATION );
	}
	#elif defined( CH_UNIX )
	{
		TRACE( "ChWorldMainInfo::OnInvalidWorld : Need message box" );
	}
	#else
	{
		#error "Undefined platform";
	}
	#endif
}


void ChWorldMainInfo::OnAsyncSocketAddress( int iError, chuint32 luAddress )
{
	m_boolWaitingForHostName = false;
											/* (The address is in host byte
												order) */
	if (0 == iError)
	{
		string		strFormat;
		string		strMessage;
		string		strName;

		ASSERT( GetWorldInfo() );
		strName = GetWorldInfo()->GetName();
		if (0 == strName.GetLength())
		{
			strName = GetWorldInfo()->GetHost();
		}
											// Format and change the message

		LOADSTRING( IDS_CONNECT_STATUS_MSG, strFormat );
		strMessage.Format( strFormat, (const char*)strName,
							GetWorldInfo()->GetPort() );

		if (m_pConnectingDlg)
		{
			m_pConnectingDlg->ChangeMessage( strMessage );
		}
											// Perform the async connection
		try
		{
			GetWorldConnection()->Connect( luAddress,
											GetWorldInfo()->GetPort() );
		}
		catch( ChSocketEx socketEx )
		{
			ShutdownWorld( false );
		}
	}
	else
	{
		string		strFormat;
		string		strErrMessage;

		switch( iError )
		{
			case WSAENETDOWN:
			{
				LOADSTRING( IDS_ERR_DNS_NETDOWN, strFormat );
				break;
			}

			case WSAHOST_NOT_FOUND:
			default:
			{
				LOADSTRING( IDS_ERR_DNS_LOOKUP, strFormat );
				break;
			}
		}

		if (!strFormat.IsEmpty())
		{
			strErrMessage.Format( strFormat,
									(const char*)GetWorldInfo()->GetHost() );
		}

		CloseConnectDlg();

		if (!strErrMessage.IsEmpty())
		{
			#if defined( CH_MSW )
			{
				GetCore()->GetFrameWnd()->
								MessageBox( strErrMessage, 0,
											MB_ICONEXCLAMATION | MB_OK );
			}
			#elif defined( CH_UNIX )
			{
				TRACE( strErrMessage );
			}
			#else
			{
				#error "Undefined platform";
			}
			#endif
		}

		ShutdownWorld( false );
	}
}


void ChWorldMainInfo::OnConnectComplete( int iErrorCode )
{
	string		strErrMessage;

	GetCore()->DisplayStatus( "" );

	CloseConnectDlg();

	ASSERT( 0 != GetWorldInfo() );

	if (0 == iErrorCode)
	{
		ASSERT( 0 != GetWorldInfo() );

		OnWorldConnect();
	}
	else
	{
		string		strName( GetWorldInfo()->GetName() );
		bool		boolShutdownWorld = true;

		if (m_boolWaitingForHostName)
		{
			m_boolWaitingForHostName = false;
		}
		else
		{									/* We are in the connect phase, connect
												 will throw an exception on failure 
												 and we will shutdown the world when 
												 we catch the exception.*/
			boolShutdownWorld = false;
		}

		if (strName.IsEmpty())
		{
			strName = GetWorldInfo()->GetHost();
		}

		switch ( iErrorCode )
		{
			case WSAEDISCON:
			{								/* Cancel the blocking request and
												terminate the connection */
				m_pWorldConn->cancelblocking();
				break;
			}
			case WSAEINTR :
			{
				break;
			}
			case WSAEADDRNOTAVAIL:
			{
				string		strFormat;

				LOADSTRING( IDS_HOST_NAME_ERROR, strFormat );
				strErrMessage.Format( strFormat, (const char*)strName );
				break;
			}

			case WSAECONNREFUSED:
			case WSAETIMEDOUT:
			default:
			{
				string		strFormat;

				LOADSTRING( IDS_CONNECT_ERROR, strFormat );
				strErrMessage.Format( strFormat, (const char*)strName );
				break;
			}
		}

		#if defined( CH_MSW )
		{
			if (!strErrMessage.IsEmpty())
			{
				GetCore()->Trace( strErrMessage, ChCore::traceErrors );
				GetCore()->GetFrameWnd()->MessageBox( strErrMessage );
			}
		}
		#endif	// defined( CH_MSW )

		if (boolShutdownWorld)
		{
			ShutdownWorld( false );
		}
	}
}


bool ChWorldMainInfo::DoJump( const string& strURL, const string& strHTML,
								bool boolForceLoad, bool boolAddToHistory,
								bool boolCritical )
{
	bool	boolProcessed;

	if (boolAddToHistory)
	{										// Save the URL in the list
		AddURLToList( strURL );
	}
											// Load the page
	if ((0 == strURL.Compare( PERSONAL_URL )) ||
		(0 == strURL.Compare( PERSONAL_URL_OLD )))
	{
		m_boolLoadPending = false;
		boolProcessed = true;

		GetPersonalWorldList();
	}
	else if (0 == strURL.Compare( WORLD_LIST_EDIT_URL ))
	{
		m_boolLoadPending = false;
		boolProcessed = true;

		EditPersonalWorldList();
	}
	else
	{
		string	strWorkingURL( strURL );

		if (0 == strWorkingURL.Compare( WORLD_LIST_URL ))
		{
			strWorkingURL = GetHomePage();
			boolForceLoad = true;
		}

		if (boolForceLoad)
		{
			SetPersonalList( false );
			m_boolLoadPending = true;
			GetTextOutput()->Clear();

			ChURLParts urlParts;

			urlParts.GetURLParts( strWorkingURL, GetCurrentURL() );

			GetTextOutput()->LoadTextOutURL( urlParts.GetURL() );

			boolProcessed = true;
		}
		else
		{
			m_boolLoadPending = false;

			boolProcessed = false;
		}
	}

	return boolProcessed;
}


/*----------------------------------------------------------------------------

	FUNCTION	||	ChWorldMainInfo::DoXCmd

	strCommand	||	Arguments to the 'xch_cmd=' HTML attribute.

------------------------------------------------------------------------------

	This method will process inline HTML for the 'xch_cmd=' attribute.

----------------------------------------------------------------------------*/

void ChWorldMainInfo::DoXCmd( const string& strCommand )
{
	if (!strCommand.IsEmpty())
	{
											/* Run this command by TinTin to
												figure out if it is a direction
												for the path */

		GetTinTin()->CheckInsertPath( strCommand );

											// Now send it directly to the world

		GetWorldConnection()->SendWorldCommand( strCommand, false );
	}
}


/*----------------------------------------------------------------------------

	FUNCTION	||	ChWorldMainInfo::DoXMode

	strArgs		||	Arguments to the 'xmode=' HTML attribute.

------------------------------------------------------------------------------

	This method will process the xmode inline command.  The valid values are
	either 'HTML' or 'TEXT'.

----------------------------------------------------------------------------*/

bool ChWorldMainInfo::DoXMode( string& strArgs )
{
	bool	boolProcessed = true;

	strArgs.MakeLower();

	if (strArgs == ATTR_XMODE_HTML)
	{
		GetWorldConnection()->SetMode( modeHtml );
	}
	else if (strArgs == ATTR_XMODE_PURE_HTML)
	{
		GetWorldConnection()->SetMode( modePureHtml );
	}
	else if (strArgs == ATTR_XMODE_TEXT)
	{
		GetWorldConnection()->SetMode( modeText );
	}
	else
	{
		boolProcessed = false;
	}

	return boolProcessed;
}


void ChWorldMainInfo::NotifyCore( ChMsg& msg ) const
{
	GetCore()->DispatchMsg( CH_CORE_MODULE_ID, msg );
}

void ChWorldMainInfo::NotifySound( ChMsg& msg ) const
{
	if ( m_idSoundModule )
	{
		GetCore()->DispatchMsg( m_idSoundModule, msg );
	}
}
void ChWorldMainInfo::NotifyGraphics( ChMsg& msg )  const
{
	if ( m_idGraphicsModule )
	{
		GetCore()->DispatchMsg( m_idGraphicsModule, msg );
	}
}

void ChWorldMainInfo::SetSoundID( const ChModuleID& idModule )
{
	m_idSoundModule = idModule;

	if (GetSoundID())
	{
		ChShowModuleMsg		showMsg;
											// Show the ChSound module
		NotifySound( showMsg );
	}
}


void ChWorldMainInfo::SetGraphicsID( const ChModuleID& idModule )
{
	m_idGraphicsModule = idModule;

	if (GetGraphicsID())
	{
		ChShowModuleMsg		showMsg;
		ChInstallHookMsg	hookCmdMsg( GetModuleID(), CH_MSG_CMD );
		ChInstallHookMsg	hookHintMsg( GetModuleID(), CH_MSG_HINT );
		ChInstallHookMsg	hookInlineMsg( GetModuleID(), CH_MSG_INLINE );

											// Show the ChGraphx module
		NotifyGraphics( showMsg );
											/* Hook the graphics module
												so we get hot spot
												notifications */
		NotifyGraphics( hookCmdMsg );
		NotifyGraphics( hookHintMsg );
		NotifyGraphics( hookInlineMsg );
	}
}


#if !defined( CH_PUEBLO_PLUGIN )
bool ChWorldMainInfo::CheckEditMenuItem( EditMenuItem item )
{
	bool	boolEnable = true;

	switch( GetFocusTarget() )
	{
		case focusTextInput:
		{
			boolEnable = GetTextInput()->CheckEditMenuItem( item );
			break;
		}

		case focusTextOutput:
		{
			boolEnable = GetTextOutput()->CheckEditMenuItem( item );
			break;
		}

		case focusNone:
		default:
		{
			boolEnable = false;
			break;
		}
	}

	return boolEnable;
}


void ChWorldMainInfo::DoEditMenuItem( EditMenuItem item )
{
	switch( GetFocusTarget() )
	{
		case focusTextInput:
		{
			GetTextInput()->DoEditMenuItem( item );
			break;
		}

		case focusTextOutput:
		{
			GetTextOutput()->DoEditMenuItem( item );
			break;
		}

		case focusNone:
		default:
		{
			break;
		}
	}
}

#endif //  !defined( CH_PUEBLO_PLUGIN )


void ChWorldMainInfo::AddChacoListJump()
{
	string		strText;
	string		strTemp;
	string		strFormat;
	string		strAppPath;
	string		strAppPathURL;

	strText = "<hr><dl>";
											// Get the file:// path of the dir
	ChUtil::GetAppDirectory( strAppPath );
	strAppPath += "img\\";

	ChURLParts::MapHostFileToURL( strAppPath, strAppPathURL );

											// Add the options

	LOADSTRING( IDS_PERSONAL_LIST_JUMP1, strFormat );
	strTemp.Format( strFormat, (const char*)strAppPathURL );
	strText += strTemp;

	LOADSTRING( IDS_PERSONAL_LIST_JUMP2, strFormat );
	strTemp.Format( strFormat, (const char*)strAppPathURL );
	strText += strTemp;

	strText += "</dl><hr>";

	GetTextOutput()->Add( strText );
}


void ChWorldMainInfo::DisplayConnectDlg( const ChWorldInfo& info )
{
	string		strMessage;
	string		strFormat;
	string		strName( info.GetName() );

	if (strName.IsEmpty())
	{
		strName = info.GetHost();
	}

	LOADSTRING( IDS_LOOKUP_STATUS_MSG, strFormat );
	strMessage.Format( strFormat, (const char*)strName );

	m_pConnectingDlg = new ChConnectingDlg( this );
	ASSERT( m_pConnectingDlg );

	m_pConnectingDlg->Create( strMessage );
	m_pConnectingDlg->CenterWindow( GetCore()->GetFrameWnd() );
	m_pConnectingDlg->ShowAfterASec();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -