Ejemplo n.º 1
0
void CChat::DecorateName(CSString &sName, const CChatChanMember * pMember, bool fSystem) // static
{
	ADDTOCALLSTACK("CChat::DecorateName");
	CChatChannel * pChannel = nullptr;
	if (pMember)
		pChannel = pMember->GetChannel();
	// 0 = yellow
	// 1 = purple
	// 2 = blue
	// 3 = purple
	// 4 = white
	// 5 = green
	int iResult = 0;
	if (!pMember || !pChannel) // Must be a system command if these are invalid
	{
		if (fSystem)
			iResult = 5;
		else
			iResult = 4;
	}
	else if (pChannel->IsModerator(pMember->GetChatName()))
		iResult = 1;
	else if (!pChannel->HasVoice(pMember->GetChatName()))
		iResult = 2;

	if (!pMember || !pChannel)
		sName.Format("%i%s", iResult, "SYSTEM");
	else
		sName.Format("%i%s", iResult, static_cast<lpctstr>(pMember->GetChatName()));
}
Ejemplo n.º 2
0
bool CServerDef::r_WriteVal( lpctstr pszKey, CSString &sVal, CTextConsole * pSrc )
{
	ADDTOCALLSTACK("CServerDef::r_WriteVal");
	EXC_TRY("WriteVal");
	switch ( FindTableSorted( pszKey, sm_szLoadKeys, CountOf( sm_szLoadKeys )-1 ) )
	{
	case SC_ACCAPP:
		sVal.FormatVal( m_eAccApp );
		break;
	case SC_ACCAPPS:
		// enum string
		ASSERT( m_eAccApp >= 0 && m_eAccApp < ACCAPP_QTY );
		sVal = sm_AccAppTable[ m_eAccApp ];
		break;
	case SC_ADMINEMAIL:
		sVal = m_sEMail;
		break;
	case SC_AGE:
		// display the age in days.
		sVal.FormatLLVal( GetAgeHours()/24 );
		break;
	case SC_CLIENTVERSION:
		{
			char szVersion[ 128 ];
			sVal = m_ClientVersion.WriteClientVer( szVersion );
		}
		break;
	case SC_CREATE:
		sVal.FormatLLVal( -( g_World.GetTimeDiff(m_timeCreate) / TICK_PER_SEC ) );
		break;
	case SC_LANG:
		sVal = m_sLang;
		break;

	case SC_LASTVALIDDATE:
		if ( m_timeLastValid.IsTimeValid() )
			sVal.FormatLLVal( GetTimeSinceLastValid() / ( TICK_PER_SEC * 60 ) );
		else
			sVal = "NA";
		break;
	case SC_LASTVALIDTIME:
		// How many seconds ago.
		sVal.FormatLLVal( m_timeLastValid.IsTimeValid() ? ( GetTimeSinceLastValid() / TICK_PER_SEC ) : -1 );
		break;
	case SC_SERVIP:
		sVal = m_ip.GetAddrStr();
		break;
	case SC_NAME:
	case SC_SERVNAME:
		sVal = GetName();	// What the name should be. Fill in from ping.
		break;
	case SC_SERVPORT:
		sVal.FormatVal( m_ip.GetPort() );
		break;
	case SC_ACCOUNTS:
		sVal.FormatSTVal( StatGet( SERV_STAT_ACCOUNTS ) );
		break;
	case SC_CLIENTS:
		sVal.FormatSTVal( StatGet( SERV_STAT_CLIENTS ) );
		break;
	case SC_ITEMS:
		sVal.FormatSTVal( StatGet( SERV_STAT_ITEMS ) );
		break;
	case SC_MEM:
		sVal.FormatSTVal( StatGet( SERV_STAT_MEM ) );
		break;
	case SC_CHARS:
		sVal.FormatSTVal( StatGet( SERV_STAT_CHARS ) );
		break;
	case SC_TIMEZONE:
		sVal.FormatVal( m_TimeZone );
		break;
	case SC_URL:
		sVal = m_sURL;
		break;
	case SC_URLLINK:
		// try to make a link of it.
		if ( m_sURL.IsEmpty() )
		{
			sVal = GetName();
			break;
		}
		sVal.Format("<a href=\"http://%s\">%s</a>", static_cast<lpctstr>(m_sURL), GetName());
		break;
	case SC_VERSION:
		sVal = SPHERE_VERSION;
		break;
	default:
		{
			lpctstr pszArgs = strchr(pszKey, ' ');
			if (pszArgs != NULL)
				GETNONWHITESPACE(pszArgs);

			CScriptTriggerArgs Args( pszArgs ? pszArgs : "" );
			if ( r_Call( pszKey, pSrc, &Args, &sVal ) )
				return true;

			return CScriptObj::r_WriteVal( pszKey, sVal, pSrc );
		}
	}
	return true;
	EXC_CATCH;

	EXC_DEBUG_START;
	EXC_ADD_KEYRET(pSrc);
	EXC_DEBUG_END;
	return false;
}
Ejemplo n.º 3
0
bool CWebPageDef::ServPage( CClient * pClient, tchar * pszPage, CSTime * pdateIfModifiedSince )	// static
{
	ADDTOCALLSTACK("CWebPageDef::ServPage");
	// make sure this is a valid format for the request.

	tchar szPageName[_MAX_PATH];
	Str_GetBare( szPageName, pszPage, sizeof(szPageName), "!\"#$%&()*,:;<=>?[]^{|}-+'`" );

	int iError = 404;
	CWebPageDef * pWebPage = g_Cfg.FindWebPage(szPageName);
	if ( pWebPage )
	{
		iError = pWebPage->ServPageRequest(pClient, szPageName, pdateIfModifiedSince);
		if ( ! iError )
			return true;
	}

	// Is it a file in the Script directory ?
	if ( iError == 404 )
	{
		const CResourceID ridjunk( RES_UNKNOWN, 1 );
		CWebPageDef tmppage( ridjunk );
		if ( tmppage.SetSourceFile( szPageName, pClient ))
		{
			if ( !tmppage.ServPageRequest(pClient, szPageName, pdateIfModifiedSince) )
				return true;
		}
	}

	// Can't find it !?
	// just take the default page. or have a custom 404 page ?

	pClient->m_Targ_Text = pszPage;

	tchar	*pszTemp = Str_GetTemp();
	sprintf(pszTemp, SPHERE_FILE "%d.htm", iError);
	pWebPage = g_Cfg.FindWebPage(pszTemp);
	if ( pWebPage )
	{
		if ( ! pWebPage->ServPageRequest( pClient, pszPage, nullptr ))
			return true;
	}

	// Hmm we should do something !!!?
	// Try to give a reasonable default error msg.

	lpctstr pszErrText;
	switch (iError)
	{
		case 401: pszErrText = "Authorization Required"; break;
		case 403: pszErrText = "Forbidden"; break;
		case 404: pszErrText = "Object Not Found"; break;
		case 500: pszErrText = "Internal Server Error"; break;
		default: pszErrText = "Unknown Error"; break;
	}

	CSTime datetime = CSTime::GetCurrentTime();
	const char *sDate = datetime.FormatGmt(nullptr);
	CSString sMsgHead;
	CSString sText;

	sText.Format(
		"<html><head><title>Error %d</title>"
		"<meta name=robots content=noindex>"
		"</head><body>"
		"<h2>HTTP Error %d</h2><p><strong>%d %s</strong></p>"
		"<p>The " SPHERE_TITLE " server cannot deliver the file or script you asked for.</p>"
		"<p>Please contact the server's administrator if this problem persists.</p>"
		"</body></html>",
		iError,
		iError,
		iError,
		pszErrText);

	sMsgHead.Format(
		"HTTP/1.1 %d %s\r\n"
		"Date: %s\r\n"
		"Server: " SPHERE_TITLE " " SPHERE_VERSION_PREFIX SPHERE_VERSION "\r\n"
		"Content-Type: text/html\r\n"
		"Content-Length: %d\r\n"
		"Connection: close\r\n"
		"\r\n%s",
		iError, pszErrText,
		static_cast<lpctstr>(sDate),
		sText.GetLength(),
		static_cast<lpctstr>(sText));

	new PacketWeb(pClient, reinterpret_cast<const byte *>(sMsgHead.GetPtr()), sMsgHead.GetLength());
	return false;
}