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

📄 chworld.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				string		strTarget;

				ChHtmlWnd::GetHTMLAttribute( strCommand, ATTR_TARGET, strTarget );

				if (IsTargetSelfOutput( strTarget ))
				{
					boolProcessed = DoJump( strValue, strCommand, false );
				}
				else
				{
					boolProcessed = false;
				}
				break;
			}

			case xcmd:
			{
				strValue += strCoord;
				DoXCmd( strValue );
				break;
			}

			default:
			{
				boolProcessed = false;
				break;
			}
		}
	}

	return boolProcessed;
}


bool ChWorldMainInfo::DoInline( const string& strArgs )
{
	bool		boolProcessed;
	ChInlineMsg	msg( strArgs );

	boolProcessed = DoHook( msg );

	if (!boolProcessed)
	{
		CommandType	command = invalid;
		string		strValue;

		if (ChHtmlWnd::GetHTMLAttribute( strArgs, ATTR_XCMD, strValue ))
		{
			command = xcmd;
		}
		else if (ChHtmlWnd::GetHTMLAttribute( strArgs, ATTR_XMODE, strValue ))
		{
			command = xmode;
		}

		switch( command )
		{
	#if 0
												// Inline xch_cmd disabled for now
			case xcmd:
			{
				DoXCmd( strValue );
				boolProcessed = true;
				break;
			}
	#endif

			case xmode:
			{
				boolProcessed = DoXMode( strValue );
				break;
			}

			default:
			{
				boolProcessed = false;
				break;
			}
		}
	}

	return boolProcessed;
}


bool ChWorldMainInfo::DoHint( const string& strArgs )
{
	string	strHint( strArgs );
	bool	boolProcessed;

	if (!strHint.IsEmpty())
	{
		boolProcessed = FormatHint( strHint );
	}
	else
	{
		strHint = "";
		boolProcessed = true;
	}

	if (boolProcessed)
	{
		#if defined( CH_MSW )
		{
			ChPersistentFrame*	pFrame = GetCore()->GetFrameWnd();

			ASSERT( pFrame );
			pFrame->SetMessageText( strHint );
		}
		#elif defined( CH_UNIX )
		{
			TRACE1( "Need code to display hint: %s", (const char*)strHint );
		}
		#else
		{
			#error Platform not defined!
		}
		#endif
	}

	return boolProcessed;
}


void ChWorldMainInfo::DoAlert()
{
	if (GetSoundID())
	{
		ChMsg	doAlert( CH_MSG_SOUND_ALERT );

		NotifySound( doAlert );
	}
}


#if !defined( CH_PUEBLO_PLUGIN )
void ChWorldMainInfo::DoQuickConnect()
{
	ChQuickConnect		quickConnectDlg;
	int					iResult;

	iResult = quickConnectDlg.DoModal();
	if (IDOK == iResult)
	{
		ChWorldInfo	info( quickConnectDlg.GetHost(), "",
							quickConnectDlg.GetHost(),
							quickConnectDlg.GetPort(), otherType,
							quickConnectDlg.GetLoginType(), "", "", "" );

		Connect( info );
	}
}
#endif


bool ChWorldMainInfo::Connect( const ChWorldInfo& info )
{
//	bool		boolSuccess;
	string		strStatusFmt;
	string		strStatus;
	ChCore*		pCore = GetCore();
											// Reset the 'Pueblo Enhanced' flag
	m_boolPuebloEnhancedFound = false;
	m_iConnectID++;							// Update the connect ID

	#if defined( CH_MSW )
	{										// Put up a status message

		LOADSTRING( IDS_STATUS_CONNECTING_FMT, strStatusFmt );
		strStatus.Format( strStatusFmt, (const char*)info.GetName() );

		pCore->DisplayStatus( strStatus );
	}
	#endif	// defined( CH_MSW )
											// Connect...
	if (0 == m_pWorldConn)
	{
		m_pWorldConn = new ChWorldConn( GetModuleID(), worldSocketHandler,
										this, (chparam)this );
	}
											// Display the 'connecting...' dlg
	DisplayConnectDlg( info );
											// Store the world information
	m_pWorldInfo = new ChWorldInfo( info );
											/* Let the world connection class
												know about the current world */

	GetWorldConnection()->SetWorldInfo( m_pWorldInfo );

	m_boolWaitingForHostName = true;
	GetWorldConnection()->AsyncGetHostByName( info.GetAddr(),
												worldSocketAsyncHandler,
												(chparam)this );
	return true;
}


/*----------------------------------------------------------------------------
	ChWorldMainInfo::OnInitialStartup

	This method is called to initialize the ChWorld module, just after it
	is initialized.
----------------------------------------------------------------------------*/

void ChWorldMainInfo::OnInitialStartup()
{
	string			strWorldName;
	string			strWorldServer;
	chint16			sWorldPort;
	ChWorldType		type;
	ChLoginType		loginType;
	string			strUsername;
	string			strPassword;
	string			strHomePage;
	string			strBuffer;
											// Show the World module
	ShowModule( true );
											// Show the text output window
	GetTextOutput()->Show( true );

	EmptyURLList();

	#if !defined( CH_PUEBLO_PLUGIN )
	if (GetCmdLine().GetWorldServer( strWorldName, strWorldServer, sWorldPort, type,
								loginType, strUsername, strPassword ))
	{
		ChWorldInfo		info( strWorldName, "", strWorldServer, sWorldPort,
								type, loginType, strUsername, strPassword,
								strHomePage );

		if (info.IsValid())
		{
			Connect( info );
		}
	}
	else
	{
		DisplayWorldList();
	}
	#else
	if ( !GetCmdLine().GetHomePage().IsEmpty() )
	{

		DoJump( GetCmdLine().GetHomePage(), "", true, false, true );
	}
	else if (GetCmdLine().GetWorldServer( strWorldName, strWorldServer, sWorldPort, type,
								loginType, strUsername, strPassword ))
	{
		ChWorldInfo		info( strWorldName, "", strWorldServer, sWorldPort,
								type, loginType, strUsername, strPassword,
								strHomePage );

		if (info.IsValid())
		{
			Connect( info );
		}
	}
	#endif
}


void ChWorldMainInfo::OnPuebloEnhanced( const ChVersion& versEnhanced )
{
											/* Check to see if we've already
												seen a Pueblo Enhanced world
												this session */
	if (IsFirstPuebloEnhanced())
	{
		ChShowModuleMsg	showMsg;
		ChVersion		versionMD5( 1, 10 );
		string			strPuebloClientCmd;
		string			strClientVer;
		ChClientInfo	clientInfo( ChClientInfo::thisMachine );
		ChVersion		clientVer = clientInfo.GetClientVersion();

											/* Load the Sound and Graphics
												modules if they're not already
												loaded */
		if (0 == GetSoundID())
		{
			LoadSoundModule();
		}

		if (0 == GetGraphicsID())
		{
			LoadGraphicsModule();
		}

		m_boolPuebloEnhancedFound = true;
											// Show the ChSound module
		if (GetSoundID())
		{
			NotifySound( showMsg );
		}
											// Show the ChGraphx module
		if (GetGraphicsID())
		{
			NotifyGraphics( showMsg );
		}
											/* Format the command to tell the
												world that we're a Pueblo
												client */

		strClientVer = clientVer.Format( ChVersion::formatShort );

		if (versEnhanced < versionMD5)
		{
			strPuebloClientCmd = PUEBLO_ENHANCED_COMMAND " " + strClientVer;
		}
		else
		{
			string		strPuebloClientFmt;

			CreateMD5Checksum();
											/* Format the new-style command to
												tell the world we're a Pueblo
												client */

			LOADSTRING( IDS_PUEBLO_CLIENT_110_FMT, strPuebloClientFmt );
			strPuebloClientCmd.Format( strPuebloClientFmt,
										(const char*)strClientVer,
										(const char*)GetMD5() );

			if (versEnhanced > versionMD5)
			{
											/* Newest version... add the
												module parameters to the
												PUEBLOCLIENT command */

				if (!m_strPuebloClientParams.IsEmpty())
				{
					strPuebloClientCmd += " " + m_strPuebloClientParams;
				}
			}
		}

		GetWorldConnection()->SendWorldCommand( strPuebloClientCmd, false );

											/* Send a message to the server to
												tell it that this is a Pueblo
												Enhanced world */

		TrackUsage( ChWorldMainInfo::worldEnhanced );
	}
}


void ChWorldMainInfo::DoAutoLogin()
{
	ChWorldInfo*	pWorldInfo = GetWorldInfo();

	if (pWorldInfo)
	{
		ChWorldType		type = pWorldInfo->GetType();
		string			strUsername;
		string			strPassword;

		strUsername = pWorldInfo->GetUsername();
		strPassword = pWorldInfo->GetPassword();

		if (type.IsValidType() && strUsername.GetLength())
		{
			if (connectLogin == pWorldInfo->GetLoginType())
			{
											/* Login consists of the form
												'connect username password' */
				if (strPassword.GetLength())
				{
					string		strLoginFormat;
					string		strLogin;
											// Format the login string

					LOADSTRING( IDS_MUSH_LOGIN_FORMAT, strLoginFormat );
					strLogin.Format( strLoginFormat, (const char*)strUsername,
										(const char*)strPassword );

											// Send the login string

					GetWorldConnection()->SendWorldCommand( strLogin, false );
				}
			}
			else
			{								/* Login is on two separate lines.
												First send the username. */

				GetWorldConnection()->SendWorldCommand( strUsername,
															false );

				if (strPassword.GetLength())
				{							// Next send the password

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

			GetTextInput()->SetLoginRecognized();
		}
	}
}


void ChWorldMainInfo::ShutdownWorld( bool boolShutdownMessage,
										bool boolEntirely )
{
	EnterCriticalSection( &m_critsecDisconnect );

	if (IsConnected())
	{
		string		strOffline;
		string		strText;
		string		strDisconnectMsg;
	
		#if !defined( CH_PUEBLO_PLUGIN )
				ChMenuItem*	pItem;
		#endif
		
		#if !defined( CH_PUEBLO_PLUGIN )
											// Clear the frame title
		GetCore()->SetFrameTitle( "" );
											// Clear world info
		GetCmdLine().SetWorld( "" );

		LOADSTRING( IDS_OFFLINE, strOffline );
		GetCore()->UpdateSessionPane( strOffline, false );
		
		#endif //  !defined( CH_PUEBLO_PLUGIN )


		if (boolShutdownMessage && m_boolPauseOnDisconnect && IsShown())
		{
			ChWorldInfo*	pWorldInfo = GetWorldInfo();
			string			strFormat;
			string			strName;

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

			LOADSTRING( IDS_FMT_DISCONNECT_MSG, strFormat );
			strDisconnectMsg.Format( (const char*)strFormat,
										(const char*)strName );
		}
											/* Hide the graphics window if
												it is shown */
		if (GetGraphicsID())
		{
			ChShowModuleMsg		hideMsg( false );
			ChResetMsg			resetMsg;

			NotifyGraphics( hideMsg );
			NotifyGraphics( resetMsg );
		}
											// Stop any sounds that are playing
		if (GetSoundID())
		{
			ChMediaStopMsg	stopMsg;

			NotifySound( stopMsg );
		}

		if (GetWorldConnection()->IsConnected() && GetWorldInfo())
		{
											// Send a statistics event
			TrackUsage( worldDisconnect );
		}

		GetTextOutput()->GetOutputWnd()->UpdateWindow();

		if (!strDisconnectMsg.IsEmpty())
		{									// Display the disconnect message
			GetCore()->GetFrameWnd()->
							MessageBox( strDisconnectMsg, "Pueblo",
										MB_OK | MB_ICONINFORMATION );
		}
											// Disconnect from the world
		Disconnect();
											/* Set focus back to the text
												output window */
		GetTextOutput()->SetFocus();
											// Reset the Text Output window
		if (GetTextOutput())
		{
			GetTextOutput()->Reset();
		}
											/* Hide and unhook the 'text in'
												module */
		GetTextInput()->Show( false );

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

			LOADSTRING( IDS_MENU_WORLD_DISCON, strText );
			if (pItem = GetWorldMenu()->FindItem( strText ))
			{
				pItem->Enable( false );
			}
		}
#endif
											// Clear the status message
		GetCore()->DisplayStatus( "" );

#if !defined( CH_PUEBLO_PLUGIN )

		if (!boolEntirely)
		{									/* Clear the page history and
												restart the world manager */
			DisplayWorldList();
		}
#else
		if ( !boolEntirely )
		{
			if ( !GetCmdLine().GetOnDisconnectURL().IsEmpty() )
			{
				GetCore()->GetHTTPConn()->GetURL( 
						GetCmdLine().GetOnDisconnectURL(), 
						TEXT( "_current" ),	0 );

			}
			else if ( !GetCmdLine().GetHomePage().IsEmpty() )
			{

												// Clear the text output window
					GetTextOutput()->Clear();

					DoJump( GetCmdLine().GetHomePage(), "", true, false, true );
			}
			else 
			{

				DisplayWorldList();
			}
		}

#endif
	}

	ASSERT( !IsConnected() );

	LeaveCriticalSection( &m_critsecDisconnect );
}


void ChWorldMainInfo::AddCurrentWorld()
{

⌨️ 快捷键说明

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