📄 chworld.cpp
字号:
/*----------------------------------------------------------------------------
_ _ _
/\ | | | (_)
/ \ _ __ __| |_ __ ___ _ __ ___ ___ __| |_ __ _
/ /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
/ ____ \| | | | (_| | | | (_) | | | | | | __/ (_| | | (_| |
/_/ \_\_| |_|\__,_|_| \___/|_| |_| |_|\___|\__,_|_|\__,_|
The contents of this file are subject to the Andromedia Public
License Version 1.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.andromedia.com/APL/
Software distributed under the License is distributed on an
"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is Pueblo client code, released November 4, 1998.
The Initial Developer of the Original Code is Andromedia Incorporated.
Portions created by Andromedia are Copyright (C) 1998 Andromedia
Incorporated. All Rights Reserved.
Andromedia Incorporated 415.365.6700
818 Mission Street - 2nd Floor 415.365.6701 fax
San Francisco, CA 94103
Contributor(s):
--------------------------------------------------------------------------
Chaco team: Dan Greening, Glenn Crocker, Jim Doubek,
Coyote Lussier, Pritham Shetty.
Wrote and designed original codebase.
------------------------------------------------------------------------------
Defines the ChWorld module for the Pueblo system. This module is
used to connect to external worlds, either old-style MUDs or Pueblo-
enhanced virtual worlds.
----------------------------------------------------------------------------*/
// $Header: /home/cvs/chaco/modules/client/msw/ChWorld/ChWorld.cpp,v 2.228 1996/10/09 22:14:21 pritham Exp $
#include "headers.h"
#if !defined(CH_PUEBLO_PLUGIN)
#include "resource.h"
#else
#include "vwrres.h"
#endif
#ifdef CH_UNIX
#include <ChDispat.h>
#include <ChMsgTyp.h>
#include <ChReg.h>
#include <ChDialogs.h>
#include <ChTypes.h>
#include <ChGraphx.h>
#include "../../unix/ChWorld/UnixRes.h"
#include "ChWList.h"
#endif // CH_UNIX
#include <fstream.h>
#include <ctype.h>
#include <time.h>
#include <ChCore.h>
#include <ChMsgTyp.h>
#include <ChExcept.h>
#if !defined( CH_PUEBLO_PLUGIN )
#include <ChMenu.h>
#else
#include <ChHttp.h>
#endif
#include <ChHtmWnd.h>
/* Headers for modules referenced
by this module */
#include <ChSound.h>
#if defined( CH_MSW )
#include <ChGraphx.h>
#endif // defined( CH_MSW )
#include <ChWorld.h>
#include "World.h"
#include "ChWConn.h"
#include "ChTextInput.h"
#include "ChWorldStream.h"
#include "ChConnectDlg.h"
#if defined( CH_MSW )
#include "ChWListD.h"
#if !defined( CH_PUEBLO_PLUGIN )
#include "ChAbout.h"
#include "ChPrefsWorld.h"
#include "ChPrefsNotify.h"
#include "ChQuickConnect.h"
#endif
#endif // defined( CH_MSW )
/*----------------------------------------------------------------------------
Constants
----------------------------------------------------------------------------*/
#define PERSONAL_URL "personal:"
#define WORLD_LIST_URL "world-list:"
#define WORLD_LIST_EDIT_URL "world-list-edit:"
#define PERSONAL_URL_OLD "http://~"
#define MAILTO_URL_PREFIX "mailto:"
#define SAVE_DLG_FLAGS (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY)
#define SAVE_DLG_FILTER "Text Files (*.txt)|*.txt|"\
"HTML Files (*.htm)|*.htm|"\
"All Files (*.*)|*.*||"
#define SAVE_DLG_FILTER_LONG "Text Files (*.txt)|*.txt|"\
"HTML Files (*.htm;*.html)|*.htm;*.html|"\
"All Files (*.*)|*.*||"
#define SAVE_LOG_DIR "Logs"
/*----------------------------------------------------------------------------
Type definitions
----------------------------------------------------------------------------*/
typedef enum { invalid, xworld, href, xcmd, xmode } CommandType;
/*----------------------------------------------------------------------------
Utility functions
----------------------------------------------------------------------------*/
CH_INTERN_FUNC( CommandType )
GetCommand( const string& strCommand, string& strValue, bool boolInline );
CH_INTERN_FUNC( bool )
FormatHint( string& strHint );
inline bool IsTargetSelfOutput( const string& strTarget )
{
bool boolSelf = (strTarget.Compare( "_self" ) == 0);
return boolSelf;
}
/*----------------------------------------------------------------------------
Socket handler declaration
----------------------------------------------------------------------------*/
CH_DECLARE_SOCKET_HANDLER( worldSocketHandler )
CH_DECLARE_SOCKET_ASYNC_HANDLER( worldSocketAsyncHandler )
/*----------------------------------------------------------------------------
Handler declarations
----------------------------------------------------------------------------*/
CH_DECLARE_MESSAGE_HANDLER( defWorldHandler )
CH_DECLARE_MESSAGE_HANDLER( worldInitHandler )
CH_DECLARE_MESSAGE_HANDLER( worldShowModuleHandler )
CH_DECLARE_MESSAGE_HANDLER( worldLoadCompleteHandler )
CH_DECLARE_MESSAGE_HANDLER( worldLoadErrorHandler )
#if !defined( CH_PUEBLO_PLUGIN )
CH_DECLARE_MESSAGE_HANDLER( worldGetPageCountHandler )
CH_DECLARE_MESSAGE_HANDLER( worldGetPagesHandler )
CH_DECLARE_MESSAGE_HANDLER( worldGetPageDataHandler )
CH_DECLARE_MESSAGE_HANDLER( worldReleasePagesHandler )
#endif // #if !defined( CH_PUEBLO_PLUGIN )
CH_DECLARE_MESSAGE_HANDLER( worldCommandHandler )
CH_DECLARE_MESSAGE_HANDLER( worldInlineHandler )
CH_DECLARE_MESSAGE_HANDLER( worldHintHandler )
CH_DECLARE_MESSAGE_HANDLER( worldInvalidWorldHandler )
CH_DECLARE_MESSAGE_HANDLER( worldSendWorldCmdHandler )
static ChMsgHandlerDesc worldHandlers[] =
{ {CH_MSG_INIT, worldInitHandler},
{CH_MSG_SHOW_MODULE, worldShowModuleHandler},
{CH_MSG_LOAD_COMPLETE, worldLoadCompleteHandler},
{CH_MSG_LOAD_ERROR, worldLoadErrorHandler},
#if !defined( CH_PUEBLO_PLUGIN )
{CH_MSG_GET_PAGE_COUNT, worldGetPageCountHandler},
{CH_MSG_GET_PAGES, worldGetPagesHandler},
{CH_MSG_GET_PAGE_DATA, worldGetPageDataHandler},
{CH_MSG_RELEASE_PAGES, worldReleasePagesHandler},
#endif
{CH_MSG_CMD, worldCommandHandler},
{CH_MSG_INLINE, worldInlineHandler},
{CH_MSG_HINT, worldHintHandler},
{CH_MSG_INVALID_WORLD, worldInvalidWorldHandler},
{CH_MSG_SEND_WORLD_CMD, worldSendWorldCmdHandler} };
/*----------------------------------------------------------------------------
Chaco menu handlers
----------------------------------------------------------------------------*/
#if !defined( CH_PUEBLO_PLUGIN )
CH_DECLARE_MESSAGE_HANDLER( fileMenuHandler )
CH_DECLARE_MESSAGE_HANDLER( editMenuHandler )
CH_DECLARE_MESSAGE_HANDLER( OnStdEditCopy )
CH_DECLARE_MESSAGE_HANDLER( OnStdEditCut )
CH_DECLARE_MESSAGE_HANDLER( OnStdEditPaste )
CH_DECLARE_MESSAGE_HANDLER( viewMenuHandler )
CH_DECLARE_MESSAGE_HANDLER( OnViewPrevCommand )
CH_DECLARE_MESSAGE_HANDLER( worldMenuHandler )
CH_DECLARE_MESSAGE_HANDLER( OnWorldListCommand )
CH_DECLARE_MESSAGE_HANDLER( OnWorldAddCommand )
CH_DECLARE_MESSAGE_HANDLER( OnWorldCreateShortcutCommand )
CH_DECLARE_MESSAGE_HANDLER( OnWorldQuickConnectCommand )
CH_DECLARE_MESSAGE_HANDLER( OnWorldDisconnectCommand )
CH_DECLARE_MESSAGE_HANDLER( OnWorldLoggingCommand )
CH_DECLARE_MESSAGE_HANDLER( windowMenuHandler )
CH_DECLARE_MESSAGE_HANDLER( OnWindowInputCommand )
#endif // !defined( CH_PUEBLO_PLUGIN )
/*----------------------------------------------------------------------------
ChWorldTinTin class
----------------------------------------------------------------------------*/
ChWorldTinTin::ChWorldTinTin( ChWorldMainInfo* pMainInfo ) :
TinTin( pMainInfo )
{
}
void ChWorldTinTin::SendToWorld( const string& strOutput )
{
if (IsOnline())
{ /* This function doesn't apply
any tintin processing to the
string that it is sending */
GetMainInfo()->Send( strOutput );
}
}
void ChWorldTinTin::Display( const string& strOutput,
bool boolPreformatted ) const
{
if (IsOnline())
{ /* This function doesn't apply
any tintin processing to the
string that it is sending */
GetMainInfo()->Display( strOutput, boolPreformatted );
}
}
/*----------------------------------------------------------------------------
ChWorldMainInfo class
----------------------------------------------------------------------------*/
ChWorldMainInfo::ChWorldMainInfo( const ChModuleID& idModule, ChCore* pCore,
ChArgumentList* pList ) :
ChMainInfo( idModule, pCore ),
m_iConnectID( 0 ),
m_pTextInput( 0 ),
m_pTextOutput( 0 ),
m_pWorldConn( 0 ),
m_pTinTin( 0 ),
m_pWorldStreamMgr( 0 ),
m_worldDispatcher( pCore, idModule, defWorldHandler ),
m_boolPuebloEnhancedFound( false ),
m_focusTarget( focusNone ),
m_idSoundModule( 0 ),
m_idGraphicsModule( 0 ),
m_pWorldInfo( 0 ),
m_boolShown( false ),
m_echoState( echoOn ),
#if !defined( CH_PUEBLO_PLUGIN )
m_boolMenus( false ),
m_boolMenusInstalled( false ),
m_pStdFileMenu( 0 ),
m_pStdEditMenu( 0 ),
m_pStdViewMenu( 0 ),
m_pWorldMenu( 0 ),
m_pStdWindowMenu( 0 ),
#endif
m_boolPersonalList( false ),
m_boolDisplayChanged( true ),
m_boolLoadPending( false ),
m_pConnectingDlg( 0 ),
m_boolWaitingForHostName( false ),
m_worldCmdLine( pList )
{
// Create the TinTin object
m_pTinTin = new ChWorldTinTin( this );
// Create the stream manager
m_pWorldStreamMgr =
new ChWorldStreamManager( this, GetModuleID() );
ASSERT( m_pWorldStreamMgr );
// Read the registry settings
UpdatePreferences();
RegisterDispatchers();
// Create critical section object
InitializeCriticalSection( &m_critsecDisconnect );
}
ChWorldMainInfo::~ChWorldMainInfo()
{
#if !defined( CH_PUEBLO_PLUGIN )
DestroyMenus();
#endif
ShutdownWorld( true, true );
if (m_pWorldStreamMgr)
{ // Delete the stream manager
delete m_pWorldStreamMgr;
m_pWorldStreamMgr = 0;
}
// Free the URL history items
EmptyURLList();
// Delete the Text output object
if (m_pTextOutput)
{
delete m_pTextOutput;
m_pTextOutput = 0;
}
// Delete the Text input object
if (m_pTextInput)
{
delete m_pTextInput;
m_pTextInput = 0;
}
// Delete the TinTin object
if (m_pTinTin)
{
delete m_pTinTin;
m_pTinTin = 0;
}
UnloadSoundModule();
UnloadGraphicsModule();
// Destroy critical section objects
DeleteCriticalSection( &m_critsecDisconnect );
}
void ChWorldMainInfo::OnSecondTick( time_t timeCurr )
{
if (IsConnected())
{
GetTinTin()->OnSecondTick( timeCurr );
}
}
void ChWorldMainInfo::Initialize()
{ /* Create the text input and
output objects */
m_pTextInput = new ChTextInput( this );
m_pTextOutput = new ChTextOutput( this );
/* Load the sound module as
'optional' */
LoadSoundModule( true );
// Create the menus
#if !defined( CH_PUEBLO_PLUGIN )
CreateMenus();
#endif
// Perform startup processing
OnInitialStartup();
}
void ChWorldMainInfo::ShowModule( bool boolShow )
{
ChShowModuleMsg showMsg( boolShow );
if (boolShow && !IsShown())
{
#if !defined( CH_PUEBLO_PLUGIN )
InstallMenus();
#endif
SetShown( boolShow );
}
else if (!boolShow && IsShown())
{
#if !defined( CH_PUEBLO_PLUGIN )
UninstallMenus();
#endif
m_boolShown = false;
SetShown( boolShow );
}
// Hide or show the ChSound module
if (GetSoundID())
{
NotifySound( showMsg );
}
// Hide or show the ChGraphx module
if (GetGraphicsID())
{
NotifyGraphics( showMsg );
}
}
void ChWorldMainInfo::DisplayWorldList()
{
if (DisplayChanged())
{
SetDisplayChanged( false );
// Clear the text output window
GetTextOutput()->Clear();
if (m_urlList.IsEmpty())
{ // Display the personal list
DoJump( PERSONAL_URL, "", true, true, true );
}
else
{ // Display the last page viewed
string* pstrTail;
pstrTail = (string*)m_urlList.GetTail();
DoJump( *pstrTail, "", true, false );
}
}
}
void ChWorldMainInfo::Send( const string& strText, bool boolEcho )
{
GetWorldConnection()->SendWorldCommand( strText, boolEcho );
}
void ChWorldMainInfo::Send( const string& strDefaultCmd,
const string& strMD5,
const string& strOverrideCmd,
const string& strParams,
bool boolEcho )
{
string strCmd;
if (!strMD5.IsEmpty() && !strOverrideCmd.IsEmpty())
{
if (VerifyMD5( strMD5 ))
{
strCmd = strOverrideCmd;
}
}
if (strCmd.IsEmpty())
{
strCmd = strDefaultCmd;
}
strCmd += ' ' + strParams;
Send( strCmd, boolEcho );
}
void ChWorldMainInfo::Display( const string& strText, bool boolPreformatted )
{
string strTextOut( strText );
string strOut;
GetWorldConnection()->TurnHtmlOn( strOut );
if (boolPreformatted)
{
strOut += "<pre>";
}
strOut += "<b><font text=\"#000080\">";
/* Strip out HTML from the users'
text and append it to the
output buffer */
ChHtmlWnd::EscapeForHTML( strTextOut );
strOut += strTextOut;
if (boolPreformatted)
{
strOut += "</pre>";
}
strOut += "</font></b><br>";
GetWorldConnection()->TurnHtmlOff( strOut );
GetTextOutput()->Add( strOut, false );
}
bool ChWorldMainInfo::DoCommand( const string& strCommand, chint32 lX,
chint32 lY )
{
bool boolProcessed = true;
ChCmdMsg msg( strCommand, lX, lY );
boolProcessed = DoHook( msg );
if (!boolProcessed)
{
CommandType command;
string strValue;
string strCoord;
command = GetCommand( strCommand, strValue, false );
if ((lX >= 0) && (lY >= 0))
{ /* Append the coordinates to the
command */
char buffer[80];
sprintf( buffer, "?%ld,%ld", lX, lY );
strCoord = buffer;
}
switch( command )
{
case xworld:
{
ChWorldInfo info( strValue );
if (info.IsValid())
{
Connect( info );
}
break;
}
case href:
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -