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

📄 chworld.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	GetCore()->GetFrameWnd()->EnableWindow( false );
}


void ChWorldMainInfo::CloseConnectDlg()
{
	GetCore()->GetFrameWnd()->EnableWindow();

	if (m_pConnectingDlg)
	{										// Destroy the 'connecting...' dlg
		m_pConnectingDlg->ShowWindow( SW_HIDE );

		m_pConnectingDlg->DestroyWindow();
		delete m_pConnectingDlg;
		m_pConnectingDlg = 0;
	}

	GetCore()->GetFrameWnd()->ActivateFrame();
}


/*----------------------------------------------------------------------------
	ChWorldMainInfo private methods
----------------------------------------------------------------------------*/

void ChWorldMainInfo::RegisterDispatchers()
{
	chint16		sHandlerCount = sizeof( worldHandlers ) /
								sizeof( ChMsgHandlerDesc );

	m_worldDispatcher.AddHandler( worldHandlers, sHandlerCount );
}


#if !defined( CH_PUEBLO_PLUGIN )

void ChWorldMainInfo::CreateMenus()
{
	ChRMenuMgr*		pMgr  = GetCore()->GetMenuMgr();
	ChMenuItem*		pItem;
	string			strText;

	ASSERT( pMgr );

	LOADSTRING( IDS_MENU_WORLD, strText );

	m_pStdFileMenu = new ChFileMenu( pMgr, fileMenuHandler );
	m_pStdEditMenu = new ChEditMenu( pMgr, editMenuHandler );
	m_pStdViewMenu = new ChViewMenu( pMgr, viewMenuHandler );
	m_pWorldMenu = new ChMenu( pMgr, strText, worldMenuHandler );
	m_pStdWindowMenu = new ChWindowMenu( pMgr, windowMenuHandler );

	m_boolMenus = true;

	ASSERT( 0 != GetFileMenu() );
	ASSERT( 0 != GetEditMenu() );
	ASSERT( 0 != GetViewMenu() );
	ASSERT( 0 != GetWorldMenu() );
	ASSERT( 0 != GetWindowMenu() );
											// Add our items to the File menu
	LOADSTRING( IDS_MENU_WORLD_LOGGING, strText );
	pItem = GetFileMenu()->InsertItem( strText, OnWorldLoggingCommand );
	LOADSTRING( IDS_MENU_WORLD_LOGGING_TXT, strText );
	pItem->SetHelpText( strText );
	pItem->Enable( false );
	pItem->SetData( (chparam)this );

	GetFileMenu()->InsertSeparator();
											/* Add our menu hooks to the
												standard Edit menu */
	GetEditMenu()->GetCutItem()->
					SetHandler( OnStdEditCut )->SetData( (chparam)this );
	GetEditMenu()->GetCopyItem()->
					SetHandler( OnStdEditCopy )->SetData( (chparam)this );
	GetEditMenu()->GetPasteItem()->
					SetHandler( OnStdEditPaste )->SetData( (chparam)this );

											// Hook into 'View/Previous'
	LOADSTRING( IDS_MENU_VIEW_PREV, strText );
	pItem = GetViewMenu()->InsertItem( strText, OnViewPrevCommand );
	LOADSTRING( IDS_MENU_VIEW_PREV_TXT, strText );
	pItem->SetHelpText( strText );
	pItem->SetData( (chparam)this );
											// Add our items to the World menu

	LOADSTRING( IDS_MENU_QUICK_CONNECT, strText );
	pItem = GetWorldMenu()->InsertItem( strText, OnWorldQuickConnectCommand );
	LOADSTRING( IDS_MENU_QUICK_CONNECT_TXT, strText );
	pItem->SetHelpText( strText );
	pItem->Enable( false );
	pItem->SetData( (chparam)this );

	GetWorldMenu()->InsertSeparator();

	LOADSTRING( IDS_MENU_WORLD_LIST, strText );
	pItem = GetWorldMenu()->InsertItem( strText, OnWorldListCommand );
	LOADSTRING( IDS_MENU_WORLD_LIST_TXT, strText );
	pItem->SetHelpText( strText );
	pItem->SetData( (chparam)this );

	LOADSTRING( IDS_MENU_ADD, strText );
	pItem = GetWorldMenu()->InsertItem( strText, OnWorldAddCommand );
	LOADSTRING( IDS_MENU_ADD_TXT, strText );
	pItem->SetHelpText( strText );
	pItem->Enable( false );
	pItem->SetData( (chparam)this );

	LOADSTRING( IDS_MENU_CREATE_SHORTCUT, strText );
	pItem = GetWorldMenu()->InsertItem( strText,
										OnWorldCreateShortcutCommand );
	LOADSTRING( IDS_MENU_CREATE_SHORTCUT_TXT, strText );
	pItem->SetHelpText( strText );
	pItem->Enable( false );
	pItem->SetData( (chparam)this );

	GetWorldMenu()->InsertSeparator();

	LOADSTRING( IDS_MENU_WORLD_DISCON, strText );
	pItem = GetWorldMenu()->InsertItem( strText, OnWorldDisconnectCommand );
	LOADSTRING( IDS_MENU_WORLD_DISCON_TXT, strText );
	pItem->SetHelpText( strText );
	pItem->Enable( false );
	pItem->SetData( (chparam)this );
											/* Add our item to the standard
												Window menu */

	LOADSTRING( IDS_WND_MENU_INPUT, strText );
	pItem = GetWindowMenu()->InsertItem( strText, OnWindowInputCommand );
	LOADSTRING( IDS_WND_MENU_INPUT_TXT, strText );
	pItem->SetHelpText( strText );
	LOADSTRING( IDS_WND_MENU_INPUT_ACC, strText );
	pItem->SetAccelerator( strText[0], CH_ACC_CONTROL | CH_ACC_VIRTKEY );
	pItem->SetData( (chparam)this );
}


void ChWorldMainInfo::InstallMenus()
{
	ASSERT( 0 != GetFileMenu() );
	ASSERT( 0 != GetEditMenu() );
	ASSERT( 0 != GetViewMenu() );
	ASSERT( 0 != GetWorldMenu() );
	ASSERT( 0 != GetWindowMenu() );

	GetFileMenu()->Install( CH_MODULE_WORLD );
	GetEditMenu()->Install( CH_MODULE_WORLD );
	GetViewMenu()->Install( CH_MODULE_WORLD );
	GetWorldMenu()->Install( CH_MODULE_WORLD );
	GetWindowMenu()->Install( CH_MODULE_WORLD );

	m_boolMenusInstalled = true;
}


void ChWorldMainInfo::UninstallMenus()
{
	ASSERT( 0 != GetFileMenu() );
	ASSERT( 0 != GetEditMenu() );
	ASSERT( 0 != GetViewMenu() );
	ASSERT( 0 != GetWorldMenu() );
	ASSERT( 0 != GetWindowMenu() );

	GetFileMenu()->Uninstall();
	GetEditMenu()->Uninstall();
	GetViewMenu()->Uninstall();
	GetWorldMenu()->Uninstall();
	GetWindowMenu()->Uninstall();

	m_boolMenusInstalled = false;
}


void ChWorldMainInfo::DestroyMenus()
{
	ASSERT( 0 != GetFileMenu() );
	ASSERT( 0 != GetEditMenu() );
	ASSERT( 0 != GetViewMenu() );
	ASSERT( 0 != GetWorldMenu() );
	ASSERT( 0 != GetWindowMenu() );
											// Delete all of the menu objects
	delete m_pStdFileMenu;
	m_pStdFileMenu = 0;

	delete m_pStdEditMenu;
	m_pStdEditMenu = 0;

	delete m_pStdViewMenu;
	m_pStdViewMenu = 0;

	delete m_pWorldMenu;
	m_pWorldMenu = 0;

	delete m_pStdWindowMenu;
	m_pStdWindowMenu = 0;

	m_boolMenus = false;
}

#endif // !defined( CH_PUEBLO_PLUGIN )


void ChWorldMainInfo::Disconnect()
{
	m_iConnectID++;							// Update the connect ID

	if (0 != m_pWorldConn)
	{
		delete m_pWorldConn;
		m_pWorldConn = 0;
	}

	if (0 != GetWorldInfo())
	{
		delete m_pWorldInfo;
		m_pWorldInfo = 0;
	}

	if (GetTextOutput()->IsLogging())
	{										// Turn off logging if it's on
		GetTextOutput()->ToggleLogging();
	}
}


void ChWorldMainInfo::AddURLToList( const string& strURL )
{
	string		strAbsURL;
	string*		pstrCopy;

	if (0 == strURL.Compare( WORLD_LIST_EDIT_URL ))
	{
											/* Don't add actions to the URL
												list */
		return;
	}
	else if ((0 == strURL.Compare( PERSONAL_URL )) ||
				(0 == strURL.Compare( WORLD_LIST_URL )) ||
				(0 == strURL.Compare( PERSONAL_URL_OLD )))
	{
		strAbsURL = strURL;
	}
	else
	{
		ChURLParts	parts;
		string		strPrevURL;
		const char*	pstrPrevURL;

		if (m_urlList.IsEmpty())
		{
			pstrPrevURL = 0;
		}
		else
		{
			strPrevURL = *(string*)m_urlList.GetTail();

			if ((0 == strPrevURL.Compare( PERSONAL_URL )) ||
				(0 == strPrevURL.Compare( PERSONAL_URL_OLD )))
			{
											// No previous relative URL
				pstrPrevURL = 0;
			}
			else if (0 == strPrevURL.Compare( WORLD_LIST_URL ))
			{
											/* The relative URL is from the
												home page */
				strPrevURL = GetHomePage();
				pstrPrevURL = strPrevURL;
			}
			else
			{
				pstrPrevURL = strPrevURL;
			}
		}
											// Calculate the absolute URL
		parts.GetURLParts( strURL, pstrPrevURL );
		strAbsURL = parts.GetURL();
	}

	ASSERT( !strAbsURL.IsEmpty() );

	pstrCopy = new string( strAbsURL );
	m_urlList.AddTail( (chparam)pstrCopy );
}

void ChWorldMainInfo::EmptyURLList()
{
	while (!m_urlList.IsEmpty())
	{
		string*		pstrTail;

		pstrTail = (string*)m_urlList.GetTail();
		m_urlList.RemoveTail();
											// Free the item
		delete pstrTail;
	}
}


void ChWorldMainInfo::LoadSoundModule( bool boolOptional )
{
	WorldLoadInfo*	pInfo;

	pInfo = new WorldLoadInfo( CH_MODULE_SOUND );
	LoadClientModule( CH_MODULE_SOUND, CH_MODULE_SOUND_BASE,
						GetModuleID(), (chparam)pInfo, boolOptional );
}


void ChWorldMainInfo::UnloadSoundModule()
{
	if (m_idSoundModule)
	{
		UnloadClientModule( m_idSoundModule );
		m_idSoundModule = 0;
	}
}


void ChWorldMainInfo::LoadGraphicsModule( bool boolOptional )
{
	WorldLoadInfo*	pInfo;

	pInfo = new WorldLoadInfo( CH_MODULE_GRAPHICS_PANE );
	ASSERT( pInfo );

	LoadClientModule( CH_MODULE_GRAPHICS_PANE, CH_MODULE_GRAPHICS_BASE,
						GetModuleID(), (chparam)pInfo, boolOptional );
}


void ChWorldMainInfo::UnloadGraphicsModule()
{
	if (GetGraphicsID())
	{										// Unhook the graphics module

		ChUninstallHookMsg	unhookCmdMsg( GetModuleID(), CH_MSG_CMD );
		ChUninstallHookMsg	unhookHintMsg( GetModuleID(), CH_MSG_HINT );
		ChUninstallHookMsg	unhookInlineMsg( GetModuleID(), CH_MSG_INLINE );

		NotifyGraphics( unhookCmdMsg );
		NotifyGraphics( unhookHintMsg );
		NotifyGraphics( unhookInlineMsg );
	}

	if (m_idGraphicsModule)
	{
		UnloadClientModule( m_idGraphicsModule );
	}
}


void ChWorldMainInfo::SendConnectedMsg()
{
	ChConnectedMsg		connectedMsg;

	m_strPuebloClientParams = "";

	if (GetSoundID())
	{
		NotifySound( connectedMsg );

		if (!m_strPuebloClientParams.IsEmpty())
		{
			m_strPuebloClientParams += ' ';
		}
		m_strPuebloClientParams += connectedMsg.GetPuebloClientParams();
		connectedMsg.ClearPuebloClientParams();
	}

	if (GetGraphicsID())
	{
		NotifyGraphics( connectedMsg );

		if (!m_strPuebloClientParams.IsEmpty())
		{
			m_strPuebloClientParams += ' ';
		}
		m_strPuebloClientParams += connectedMsg.GetPuebloClientParams();
		connectedMsg.ClearPuebloClientParams();
	}
}


void ChWorldMainInfo::TrackUsage( int iType )
{

	string 				strFormat;
	ChWorldHTTPReq* 	pReq = 0;


	switch( iType )
	{
		case worldConnect :
		{
			LOADSTRING( IDS_ONCONNECT_URL, strFormat  );
			pReq = new ChWorldConnectHTTPReq( GetConnectID() );
			break;
		}
		case worldDisconnect :
		{
			LOADSTRING( IDS_ONDISCONNECT_URL, strFormat  );
			pReq = new ChWorldDisconnectHTTPReq( GetConnectID() );
			break;
		}
		case worldEnhanced :
		{
			LOADSTRING( IDS_PUEBLOENHANCED_URL, strFormat  );
			pReq = new ChWorldEnhancedHTTPReq( GetConnectID(),
					GetTextOutput()->GetOutputWnd()->GetSafeHwnd() );
			break;
		}
	}

	if ( pReq )
	{


		string 				strURL, strData, strClientVersion;

		// format time in RFC 870 format
		time_t currTime;
		time( &currTime );
		struct tm* pTheTime = gmtime( &currTime );
		if (pTheTime )
		{
			string strTime;

			if (strftime(strTime.GetBuffer( 256 ), 256, "%A, %d-%b-%y %H:%M:%S GMT", pTheTime ))
			{
				strTime.ReleaseBuffer();
				ChUtil::HtmlAddNameValuePair( strData, "Time", strTime );
			}
			else
			{
				strTime.ReleaseBuffer();
			}
		}

		ASSERT( GetWorldInfo() );

		ChUtil::HtmlAddNameValuePair( strData, "Host", GetWorldInfo()->GetHost() );
		ChUtil::HtmlAddNameValuePair( strData, "Port", GetWorldInfo()->GetPort() );

											// Current client version

		strClientVersion = GetCore()->GetClientInfo()->
							GetClientVersion().Format( ChVersion::formatShort );
		strURL.Format( strFormat, LPCSTR(strClientVersion) );

		GetCore()->PostURL( strURL, strData, strData.GetLength(),
								0, GetStream(),
								(chparam)pReq  );
	}
}


void ChWorldMainInfo::CreateMD5Checksum()
{
	chuint32		luTime = 0;
	chuint32		luTicks = 0;
	chuint32		luAddress = 0;
	char			cTemp[65];
	const char*		pstrTemp = cTemp;
	string			strMD5;
	char			cLocalHostName[255];
	string			strWorldName = GetWorldInfo()->GetName();
	const char*		pstrWorldName;

	luTime = time(0);
	if (0 == gethostname( cLocalHostName, sizeof( cLocalHostName ) ))
	{
		hostent*	pLocalHost;

		pLocalHost = gethostbyname( cLocalHostName );
		if (pLocalHost)
		{
			LPIN_ADDR	pAddress = (LPIN_ADDR)(pLocalHost->h_addr_list[0]);

			luAddress = pAddress->s_addr;
		}
	}

	luTicks = GetTickCount();
											/* Make sure strWorldName has enough
												characters to cast... */

	strWorldName += "xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxX";
	pstrWorldName = strWorldName;
											/* XOR the world name through the
												values */
	luTime ^= (chuint32)pstrWorldName;
	pstrWorldName += 4;
	luAddress ^= (chuint32)pstrWorldName;
	pstrWorldName += 4;
	luTicks ^= (chuint32)pstrWorldName;
	pstrWorldName += 4;

	strMD5.Format( "%010lx%011lx%011lx", luTime, luAddress, luTicks );
	SetMD5( strMD5 );
}


/*----------------------------------------------------------------------------
	Chaco module library entry point
----------------------------------------------------------------------------*/

#if defined( CH_MSW ) && defined( CH_ARCH_16 )
CH_EXTERN_LIBRARY( void )
InitChWorldDLL();
#endif

#ifdef __linux__
CH_IMPLEMENT_MAIN_HANDLER( ChMainEntryWorld )
#else
#if defined( CH_PUEBLO_PLUGIN )
STDAPI_(int) 				
ChMainEntryWorld( ChMsg &msg, ChCore *pCore, ChMainInfo *pMainInfo, 
								ChModuleID idModule, const string *pstrModule, 
								ChArgumentList *pArgList )
#else
ChMain
#endif
#endif
{
	chparam		retVal = 0;

	switch( msg.GetMessage() )
	{
		case CH_MSG_INIT:
		{
			ChInitMsg	*pMsg = (ChInitMsg *)&msg;
			string		strLoadParam;
			ChModuleID	idServerModule;

			#if defined( CH_MSW ) && defined( CH_ARCH_16 )
			{
											// Initialize MFC
				InitChWorldDLL();
			}
			#endif	// defined( CH_MSW ) && defined( CH_ARCH_16 )

			pMsg->GetParams( idModule, strLoadParam, idServerModule );

			if (*pstrModule == CH_MODULE_WORLD)
			{
				ChWorldMainInfo	*pMainInfo;

				pMainInfo = new ChWorldMainInfo( idModule, pCore, pArgList );

				retVal = (chparam)pMainInfo;
			}

			break;
		

⌨️ 快捷键说明

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