Exemplo n.º 1
0
DWORD RequestProc (DWORD dwNichts)
{
	int		*pBuffer;
	DWORD	dwRet;
	HANDLE	heventWait[2];
	int		iBeginLine, iEndLine;
	
	heventWait[0] = heventParentSend;
	heventWait[1] = heventDone;

	while (1)
	{
		dwRet = WaitForMultipleObjects (2, heventWait, false, INFINITE);

	// heventDone fired, so we're exiting.
		if (dwRet == WAIT_OBJECT_0 + 1)	
			break;

		pBuffer = (int *) GetMappedBuffer (hfileBuffer);
		
	// hfileBuffer is invalid.  Just leave.
		if (!pBuffer)
		{
			Con_Print("Invalid hfileBuffer\n");
			break;
		}

		switch (pBuffer[0])
		{
			case CCOM_WRITE_TEXT:
			// Param1 : Text
				pBuffer[0] = WriteText ((LPCTSTR) (pBuffer + 1));
				break;

			case CCOM_GET_TEXT:
			// Param1 : Begin line
			// Param2 : End line
				iBeginLine = pBuffer[1];
				iEndLine = pBuffer[2];
				pBuffer[0] = ReadText ((LPTSTR) (pBuffer + 1), iBeginLine, 
									   iEndLine);
				break;

			case CCOM_GET_SCR_LINES:
			// No params
				pBuffer[0] = GetScreenBufferLines (&pBuffer[1]);
				break;

			case CCOM_SET_SCR_LINES:
			// Param1 : Number of lines
				pBuffer[0] = SetScreenBufferLines (pBuffer[1]);
				break;
		}

		ReleaseMappedBuffer (pBuffer);
		SetEvent (heventChildSend);
	}

	return 0;
}
Exemplo n.º 2
0
/*
==============
OnBtnExecute

User wants to issue commands
==============
*/
void CServerCtrlDlg::OnBtnExecute( void ) 
{
	if ( !m_hSend || !m_hMappedFile )
		return;

	// Get commands
	CEdit *pEdit = (CEdit *)GetDlgItem( IDC_EDIT_COMMANDS );
	if ( pEdit )
	{
		CString cmds;
		pEdit->GetWindowText( cmds );

		// Get buffer
		char *sz = (char *)GetMappedBuffer( m_hMappedFile );
		if ( sz )
		{
			// Write command int32 token
			*(int *)&sz[ 0 ] = ENGINE_ISSUE_COMMANDS;

			// Write rest of line, including a return character ( necessary? )
			sprintf( sz + sizeof( int ), "%s\n", (char *)(LPCSTR)cmds );

			// Release the buffer
			ReleaseMappedBuffer( sz );

			// Store off what we are expecting in return buffer
			m_nPendingRequest = ENGINE_ISSUE_COMMANDS;

			// Signal HLDS to check for requests
			SetEvent( m_hSend );
		}
	}
}
Exemplo n.º 3
0
/*
==============
RefreshText

==============
*/
void CServerCtrlDlg::RefreshText( void )
{
	if ( !m_hSend || !m_hMappedFile )
		return;

	int i = 0;
	char *sz = (char *)GetMappedBuffer( m_hMappedFile );
	if ( sz )
	{
		// Command token
		*(int *)&sz[ i ] = ENGINE_RETRIEVE_CONSOLE_CONTENTS;
		i += sizeof( int );

		// Start at line 0
		*(int *)&sz[ i ] = 0;
		i += sizeof( int );

		// End at line 23 ( assumes 24 line console )
		*(int *)&sz[ i ] = 23;
		i += sizeof( int );

		// Done creating commands
		ReleaseMappedBuffer( sz );

		// Store off pending state info
		m_nPendingRequest = ENGINE_RETRIEVE_CONSOLE_CONTENTS;
		m_nPendingLines = 23 - 0 + 1;

		// Signal HLDS that we have written commands to the buffer
		SetEvent( m_hSend );
	}
}
Exemplo n.º 4
0
static unsigned _stdcall RequestProc( void *arg )
{
	int *pBuffer;
	DWORD dwRet;
	HANDLE heventWait[2];
	int iBeginLine, iEndLine;

	heventWait[0] = heventParentSend;
	heventWait[1] = heventDone;

	for(;; )
	{
		dwRet = WaitForMultipleObjects( 2, heventWait, FALSE, INFINITE );

		// heventDone fired, so we're exiting.
		if( dwRet == WAIT_OBJECT_0 + 1 )
			break;

		pBuffer = (int *) GetMappedBuffer( hfileBuffer );

		// hfileBuffer is invalid.  Just leave.
		if( !pBuffer )
		{
			printf( "Invalid hfileBuffer\n" );
			break;
		}

		switch( pBuffer[0] )
		{
		case CCOM_WRITE_TEXT:
			// Param1 : Text
			pBuffer[0] = WriteText( (LPCTSTR) ( pBuffer + 1 ) );
			break;

		case CCOM_GET_TEXT:
			// Param1 : Begin line
			// Param2 : End line
			iBeginLine = pBuffer[1];
			iEndLine = pBuffer[2];
			pBuffer[0] = ReadText( (LPTSTR) ( pBuffer + 1 ), iBeginLine,
			                      iEndLine );
			break;

		case CCOM_GET_SCR_LINES:
			// No params
			pBuffer[0] = GetScreenBufferLines( &pBuffer[1] );
			break;

		case CCOM_SET_SCR_LINES:
			// Param1 : Number of lines
			pBuffer[0] = SetScreenBufferLines( pBuffer[1] );
			break;
		}

		ReleaseMappedBuffer( pBuffer );
		SetEvent( heventChildSend );
	}

	_endthreadex( 0 );
	arg = NULL; // wsw : aiwa : shut up compiler
	return 0;
}
Exemplo n.º 5
0
/*
=====================
ProcessMappedResponse

The engine has signaled the receive event, see what the results of the command we issued are.
=====================
*/
int CServerCtrlDlg::ProcessMappedResponse( void )
{
	char *psz;
	int *pBuffer;
	int i;
	char line[ 1024 ];
	char szwindow[ 4096 ];
	CEdit *pEdit;

	pBuffer = (int *)GetMappedBuffer ( m_hMappedFile );
	
	// buffer is invalid.  Just leave.
	if ( !pBuffer )
	{
		return 0;
	}

	// Will be non-zero upon success
	if ( pBuffer[0] )
	{
		switch ( m_nPendingRequest )
		{
		case ENGINE_RETRIEVE_CONSOLE_CONTENTS:
			// Write text lines to console area
			pEdit = (CEdit *)GetDlgItem( IDC_EDIT_CONSOLE );
			if ( pEdit )
			{
				szwindow[ 0 ] = '\0';
				
				for ( i = 0; i < m_nPendingLines; i++ )
				{
					// Skip first int32 result code
					// Lines are assumed to be 80 characters wide
					psz = (char *)( pBuffer + 1 ) + 80 * i;
					strncpy( line, psz, 80 );
					line[ 79 ] = '\0';

					strcat( szwindow, line );
					if ( i != ( m_nPendingLines ) - 1 )
					{
						strcat( szwindow, "\r\n" );
					}
				}

				// Send to display control
				pEdit->SetWindowText( szwindow );
			}
			break;

		default:
			break;
		}
	}

	// Reset results stuff
	m_nPendingRequest	= 0;
	m_nPendingLines		= 0;

	// Free up buffer pointer
	ReleaseMappedBuffer( pBuffer );

	return 1;
}