Пример #1
0
    void
WriteStatusMessage(const char *message, ...)
{
    va_list args;
    va_start(args, message);
    const size_t bufferSize = 10240;
    char buffer[bufferSize];
    vsnprintf(buffer, bufferSize - 1, message, args);
    buffer[bufferSize - 1] = '\0';  // vsnprintf spec is vague on whether it null terminates a full buffer, so better safe than sorry
    WriteMessageToFile(stdout, buffer);
	if (NULL != CommandPipe) {
	  WriteToNamedPipe(CommandPipe, buffer);
	}
}
Пример #2
0
void MapScreenMessage( UINT16 usColor, UINT8 ubPriority, STR16 pStringA, ... )
{
  // this function sets up the string into several single line structures
	 
	ScrollStringStPtr pStringSt;
	UINT32 uiFont = MAP_SCREEN_MESSAGE_FONT;
	UINT16 usPosition=0;
	UINT16 usCount=0;
	UINT16 usStringLength=0;
	UINT16 usCurrentSPosition=0;
	UINT16 usCurrentLookup=0;
	//wchar_t *pString;
	BOOLEAN fLastLine=FALSE;
  va_list argptr;
  wchar_t	DestString[512], DestStringA[ 512 ];
	//wchar_t *pStringBuffer;
  BOOLEAN fMultiLine=FALSE;
  WRAPPED_STRING *pStringWrapper=NULL;
  WRAPPED_STRING *pStringWrapperHead=NULL;
  BOOLEAN fNewString = FALSE;
	UINT16	usLineWidthIfWordIsWiderThenWidth;

	if( fDisableJustForIan == TRUE )
	{
		if( ubPriority == MSG_BETAVERSION )
		{
			return;
		}
		else if( ubPriority == MSG_TESTVERSION )
		{
			return;
		}
		else if ( ubPriority == MSG_DEBUG )
		{
			return;
		}
	}

	if( ubPriority == MSG_BETAVERSION )
	{
		usColor = BETAVERSION_COLOR;
		#ifndef JA2BETAVERSION
			#ifndef JA2TESTVERSION
				return;
			#endif
		#endif

		WriteMessageToFile( DestString );
	}

	if( ubPriority == MSG_TESTVERSION )
	{
		usColor = TESTVERSION_COLOR;

		#ifndef JA2TESTVERSION
			 return;
		#endif
		WriteMessageToFile( DestString );
	}
	// OK, check if we are ani imeediate feedback message, if so, do something else!
	if ( ubPriority == MSG_UI_FEEDBACK )
	{
		va_start(argptr, pStringA);       	// Set up variable argument pointer
		vswprintf(DestString, pStringA, argptr);	// process gprintf string (get output str)
		va_end(argptr);

		BeginUIMessage( DestString );
		return;
	}

	if ( ubPriority == MSG_SKULL_UI_FEEDBACK )
	{
		va_start(argptr, pStringA);       	// Set up variable argument pointer
		vswprintf(DestString, pStringA, argptr);	// process gprintf string (get output str)
		va_end(argptr);

		InternalBeginUIMessage( TRUE, DestString );
		return;
	}

	// check if error
	if ( ubPriority == MSG_ERROR )
	{
		va_start(argptr, pStringA);       	// Set up variable argument pointer
		vswprintf(DestString, pStringA, argptr);	// process gprintf string (get output str)
		va_end(argptr);

		swprintf( DestStringA, L"DEBUG: %s", DestString );

		BeginUIMessage( DestStringA );
		WriteMessageToFile( DestStringA );

		return;
	}


		// OK, check if we are an immediate MAP feedback message, if so, do something else!
	if ( ( ubPriority == MSG_MAP_UI_POSITION_UPPER  ) ||
			 ( ubPriority == MSG_MAP_UI_POSITION_MIDDLE ) ||
			 ( ubPriority == MSG_MAP_UI_POSITION_LOWER  ) )
	{
		va_start(argptr, pStringA);       	// Set up variable argument pointer
		vswprintf(DestString, pStringA, argptr);	// process gprintf string (get output str)
		va_end(argptr);

		BeginMapUIMessage( ubPriority, DestString );
		return;
	}


	if ( fFirstTimeInMessageSystem )
	{
		// Init display array!
		memset( gpDisplayList, 0, sizeof( gpDisplayList ) );
		fFirstTimeInMessageSystem = FALSE;
		//if(!(InitializeMutex(SCROLL_MESSAGE_MUTEX,"ScrollMessageMutex" )))
		//	return;
	}

	
	pStringSt=pStringS;
	while(GetNextString(pStringSt))
		    pStringSt=GetNextString(pStringSt);

	va_start(argptr, pStringA);       	// Set up variable argument pointer
	vswprintf(DestString, pStringA, argptr);	// process gprintf string (get output str)
	va_end(argptr);

	if ( ubPriority == MSG_DEBUG )
	{
		#ifndef _DEBUG
			return;
		#endif
		#ifdef JA2DEMO
			return;
		#endif
		usColor = DEBUG_COLOR;
		wcscpy( DestStringA, DestString );
		swprintf( DestString, L"Debug: %s", DestStringA );
	}

	if ( ubPriority == MSG_DIALOG )
	{
		usColor = DIALOGUE_COLOR;
	}

	if ( ubPriority == MSG_INTERFACE )
	{
		usColor = INTERFACE_COLOR;
	}

	pStringWrapperHead=LineWrap(uiFont, MAP_LINE_WIDTH, &usLineWidthIfWordIsWiderThenWidth, DestString);
  pStringWrapper=pStringWrapperHead;
	if(!pStringWrapper)
    return;
	
	fNewString = TRUE;

	while(pStringWrapper->pNextWrappedString!=NULL)
	{
		AddStringToMapScreenMessageList(pStringWrapper->sString, usColor, uiFont, fNewString, ubPriority );
		fNewString = FALSE;

		pStringWrapper=pStringWrapper->pNextWrappedString;
	}

  AddStringToMapScreenMessageList(pStringWrapper->sString, usColor, uiFont, fNewString, ubPriority );


	// clear up list of wrapped strings
	ClearWrappedStrings( pStringWrapperHead );

	// play new message beep
	//PlayNewMessageSound( );

	MoveToEndOfMapScreenMessageList( );

	//LeaveMutex(SCROLL_MESSAGE_MUTEX, __LINE__, __FILE__);
}
Пример #3
0
// new tactical and mapscreen message system
void TacticalScreenMsg( UINT16 usColor, UINT8 ubPriority, STR16 pStringA, ... )
{
  // this function sets up the string into several single line structures
	
	ScrollStringStPtr pStringSt;
	UINT32 uiFont = TINYFONT1;
	UINT16 usPosition=0;
	UINT16 usCount=0;
	UINT16 usStringLength=0;
	UINT16 usCurrentSPosition=0;
	UINT16 usCurrentLookup=0;
	//wchar_t *pString;
	BOOLEAN fLastLine=FALSE;
  va_list argptr;

  wchar_t	DestString[512], DestStringA[ 512 ];
	//wchar_t *pStringBuffer;
  BOOLEAN fMultiLine=FALSE;
  ScrollStringStPtr pTempStringSt=NULL;
  WRAPPED_STRING *pStringWrapper=NULL;
  WRAPPED_STRING *pStringWrapperHead=NULL;
  BOOLEAN fNewString = FALSE;
	UINT16	usLineWidthIfWordIsWiderThenWidth=0;


	if( giTimeCompressMode > TIME_COMPRESS_X1 )
	{
		return;
	}

	if( fDisableJustForIan == TRUE && ubPriority != MSG_ERROR && ubPriority != MSG_INTERFACE )
	{
		return;
	}

	if( ubPriority == MSG_BETAVERSION )
	{
		usColor = BETAVERSION_COLOR;
		#ifndef JA2BETAVERSION
			#ifndef JA2TESTVERSION
				return;
			#endif
		#endif
		WriteMessageToFile( DestString );

	}

	if( ubPriority == MSG_TESTVERSION )
	{
		usColor = TESTVERSION_COLOR;

		#ifndef JA2TESTVERSION
			 return;
		#endif

		WriteMessageToFile( DestString );

	}


	if ( fFirstTimeInMessageSystem )
	{
		// Init display array!
		memset( gpDisplayList, 0, sizeof( gpDisplayList ) );
		fFirstTimeInMessageSystem = FALSE;
		//if(!(InitializeMutex(SCROLL_MESSAGE_MUTEX,"ScrollMessageMutex" )))
		//	return;
	}

	
	pStringSt=pStringS;
	while(GetNextString(pStringSt))
		    pStringSt=GetNextString(pStringSt);

	va_start(argptr, pStringA);       	// Set up variable argument pointer
	vswprintf(DestString, pStringA, argptr);	// process gprintf string (get output str)
	va_end(argptr);

	if ( ubPriority == MSG_DEBUG )
	{
		#ifndef _DEBUG
			return;
		#endif
		#ifdef JA2DEMO
			return;
		#endif
		usColor = DEBUG_COLOR;
		wcscpy( DestStringA, DestString );
		swprintf( DestString, L"Debug: %s", DestStringA );
		WriteMessageToFile( DestStringA );
	}

	if ( ubPriority == MSG_DIALOG )
	{
		usColor = DIALOGUE_COLOR;
	}

	if ( ubPriority == MSG_INTERFACE )
	{
		usColor = INTERFACE_COLOR;
	}



	pStringWrapperHead=LineWrap(uiFont, LINE_WIDTH, &usLineWidthIfWordIsWiderThenWidth, DestString);
  pStringWrapper=pStringWrapperHead;
	if(!pStringWrapper)
    return;
	
	fNewString = TRUE;
	while(pStringWrapper->pNextWrappedString!=NULL)
	{
	 if(!pStringSt)
	 {
    pStringSt=AddString(pStringWrapper->sString, usColor, uiFont, fNewString, ubPriority );
		fNewString = FALSE;
		pStringSt->pNext=NULL;
		pStringSt->pPrev=NULL;
    pStringS=pStringSt;
	 }
	 else
	 {
	  pTempStringSt=AddString(pStringWrapper->sString, usColor, uiFont, fNewString, ubPriority);
    fNewString = FALSE;
		pTempStringSt->pPrev=pStringSt;
	  pStringSt->pNext=pTempStringSt;
	  pStringSt=pTempStringSt;
	  pTempStringSt->pNext=NULL;
	 }
   pStringWrapper=pStringWrapper->pNextWrappedString;
	}
  pTempStringSt=AddString(pStringWrapper->sString, usColor, uiFont, fNewString, ubPriority );
	if(pStringSt)
	{
	 pStringSt->pNext=pTempStringSt;
	 pTempStringSt->pPrev=pStringSt;
	 pStringSt=pTempStringSt;
	 pStringSt->pNext=NULL;
	}
  else
	{
		pStringSt=pTempStringSt;
		pStringSt->pNext=NULL;
		pStringSt->pPrev=NULL;
    pStringS=pStringSt;
	}
	
	// clear up list of wrapped strings
	ClearWrappedStrings( pStringWrapperHead );

 //LeaveMutex(SCROLL_MESSAGE_MUTEX, __LINE__, __FILE__);
 return;
} 
Пример #4
0
//--------------------------------------------------------------------------------------------------------------//
void CTracer::TraceMessage(MessageTypeEnum Type, LPCTSTR szSource, LPCTSTR pszMessage, ...)
{
	TCHAR szDate[64];
	if (0 == ::GetDateFormat(
		LOCALE_USER_DEFAULT, 
		DATE_SHORTDATE, 
		NULL, 
		NULL, 
		szDate, 
		sizeof(szDate)/sizeof(TCHAR)))
	{
		szDate[0] = _T('?');
		szDate[1] = _T('\0');
	}

	TCHAR szTime[32];
	if (0 == ::GetTimeFormat(
		LOCALE_USER_DEFAULT,
		LOCALE_NOUSEROVERRIDE,
		NULL,
		NULL,
		szTime,
		sizeof(szTime)/sizeof(TCHAR)))
	{
		szTime[0] = _T('?');
		szTime[1] = _T('\0');
	}

	TCHAR cType;
	switch (Type)
	{
		case enMtInformation:
			cType = _T('I');
			break;

		case enMtWarning:
			cType = _T('W');
			break;

		case enMtError:
			cType = _T('E');
			break;

		default:
			cType = _T('?');
	}

	va_list arglist;
	va_start(arglist, pszMessage);
			
	TCHAR szMessage[4096];
	_vsntprintf_s(szMessage,sizeof(szMessage), 4096, pszMessage, arglist);

	
	TCHAR szOutputLine[4096];
	::wsprintf(
		szOutputLine, 
		_T("[%#04X] %s %s %c %s %s"), 
		::GetCurrentThreadId(),
		szDate,
		szTime,
		cType,
		szMessage, szSource!=NULL?szSource:_T(""));

	if (m_Destination & enMdWindow)
	{
		HWND hWnd = GetWindowHandle();
		sMessage Msg;
		Msg.szMessage = szMessage;
		Msg.szSource = szSource;
		if (hWnd) ::SendMessage(hWnd, GetMessageId(), Type, reinterpret_cast<LPARAM>(&Msg));
	}

	::lstrcat(szOutputLine, _T("\n"));
	
	if (m_Destination & enMdDebug) 
		::OutputDebugString(szOutputLine);
	if (m_Destination & enMdFile) 
		WriteMessageToFile(szOutputLine);
}
Пример #5
0
	void WriteMessageToFile(const std::string &out_file_name,
		MLB::SocketIo::PacketFormat packet_format) const
	{
		MLB::SocketIo::PacketFileWriter out_file(out_file_name, packet_format);
		WriteMessageToFile(out_file);
	}