mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-21 04:56:01 +08:00
Update from SDK 2013
This commit is contained in:

committed by
Nicholas Hastings

parent
6d5c024820
commit
94b660e16e
22
utils/vmpi/testapps/MessageWatch/MessageRecvMgr.h
Normal file
22
utils/vmpi/testapps/MessageWatch/MessageRecvMgr.h
Normal file
@ -0,0 +1,22 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef MESSAGERECVMGR_H
|
||||
#define MESSAGERECVMGR_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
class IMessageRecvMgr
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // MESSAGERECVMGR_H
|
77
utils/vmpi/testapps/MessageWatch/MessageWatch.cpp
Normal file
77
utils/vmpi/testapps/MessageWatch/MessageWatch.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
// MessageWatch.cpp : Defines the class behaviors for the application.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "MessageWatch.h"
|
||||
#include "MessageWatchDlg.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMessageWatchApp
|
||||
|
||||
BEGIN_MESSAGE_MAP(CMessageWatchApp, CWinApp)
|
||||
//{{AFX_MSG_MAP(CMessageWatchApp)
|
||||
// NOTE - the ClassWizard will add and remove mapping macros here.
|
||||
// DO NOT EDIT what you see in these blocks of generated code!
|
||||
//}}AFX_MSG
|
||||
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMessageWatchApp construction
|
||||
|
||||
CMessageWatchApp::CMessageWatchApp()
|
||||
{
|
||||
// TODO: add construction code here,
|
||||
// Place all significant initialization in InitInstance
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// The one and only CMessageWatchApp object
|
||||
|
||||
CMessageWatchApp theApp;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMessageWatchApp initialization
|
||||
|
||||
BOOL CMessageWatchApp::InitInstance()
|
||||
{
|
||||
// Standard initialization
|
||||
// If you are not using these features and wish to reduce the size
|
||||
// of your final executable, you should remove from the following
|
||||
// the specific initialization routines you do not need.
|
||||
|
||||
#ifdef _AFXDLL
|
||||
Enable3dControls(); // Call this when using MFC in a shared DLL
|
||||
#else
|
||||
Enable3dControlsStatic(); // Call this when linking to MFC statically
|
||||
#endif
|
||||
|
||||
CMessageWatchDlg dlg;
|
||||
m_pMainWnd = &dlg;
|
||||
int nResponse = dlg.DoModal();
|
||||
if (nResponse == IDOK)
|
||||
{
|
||||
// TODO: Place code here to handle when the dialog is
|
||||
// dismissed with OK
|
||||
}
|
||||
else if (nResponse == IDCANCEL)
|
||||
{
|
||||
// TODO: Place code here to handle when the dialog is
|
||||
// dismissed with Cancel
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
56
utils/vmpi/testapps/MessageWatch/MessageWatch.h
Normal file
56
utils/vmpi/testapps/MessageWatch/MessageWatch.h
Normal file
@ -0,0 +1,56 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
// MessageWatch.h : main header file for the MESSAGEWATCH application
|
||||
//
|
||||
|
||||
#if !defined(AFX_MESSAGEWATCH_H__72A09EC9_2B19_4AC5_A281_5FAD41F6DFCA__INCLUDED_)
|
||||
#define AFX_MESSAGEWATCH_H__72A09EC9_2B19_4AC5_A281_5FAD41F6DFCA__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#ifndef __AFXWIN_H__
|
||||
#error include 'stdafx.h' before including this file for PCH
|
||||
#endif
|
||||
|
||||
#include "resource.h" // main symbols
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMessageWatchApp:
|
||||
// See MessageWatch.cpp for the implementation of this class
|
||||
//
|
||||
|
||||
class CMessageWatchApp : public CWinApp
|
||||
{
|
||||
public:
|
||||
CMessageWatchApp();
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CMessageWatchApp)
|
||||
public:
|
||||
virtual BOOL InitInstance();
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
|
||||
//{{AFX_MSG(CMessageWatchApp)
|
||||
// NOTE - the ClassWizard will add and remove member functions here.
|
||||
// DO NOT EDIT what you see in these blocks of generated code !
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_MESSAGEWATCH_H__72A09EC9_2B19_4AC5_A281_5FAD41F6DFCA__INCLUDED_)
|
194
utils/vmpi/testapps/MessageWatch/MessageWatch.rc
Normal file
194
utils/vmpi/testapps/MessageWatch/MessageWatch.rc
Normal file
@ -0,0 +1,194 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
|
||||
"#define _AFX_NO_OLE_RESOURCES\r\n"
|
||||
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
|
||||
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
|
||||
"\r\n"
|
||||
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
|
||||
"#ifdef _WIN32\r\n"
|
||||
"LANGUAGE 9, 1\r\n"
|
||||
"#pragma code_page(1252)\r\n"
|
||||
"#endif //_WIN32\r\n"
|
||||
"#include ""res\\MessageWatch.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
|
||||
"#include ""afxres.rc"" // Standard components\r\n"
|
||||
"#endif\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDR_MAINFRAME ICON DISCARDABLE "res\\MessageWatch.ico"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_MESSAGEWATCH_DIALOG DIALOGEX 0, 0, 232, 147
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_APPWINDOW
|
||||
CAPTION "MessageWatch"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
PUSHBUTTON "Quit",IDCANCEL,175,126,50,14
|
||||
LISTBOX IDC_MACHINES,7,7,218,114,LBS_SORT | LBS_NOINTEGRALHEIGHT |
|
||||
WS_VSCROLL | WS_TABSTOP
|
||||
PUSHBUTTON "&Show All",IDSHOWALL,7,126,50,14
|
||||
PUSHBUTTON "&Hide All",IDHIDEALL,91,126,50,14
|
||||
END
|
||||
|
||||
IDD_OUTPUT DIALOG DISCARDABLE 0, 0, 320, 225
|
||||
STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Output"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
EDITTEXT IDC_DEBUG_OUTPUT,7,7,306,211,ES_MULTILINE | ES_READONLY |
|
||||
WS_VSCROLL
|
||||
END
|
||||
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,1
|
||||
PRODUCTVERSION 1,0,0,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x1L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904B0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "\0"
|
||||
VALUE "FileDescription", "MessageWatch MFC Application\0"
|
||||
VALUE "FileVersion", "1, 0, 0, 1\0"
|
||||
VALUE "InternalName", "MessageWatch\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2002\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "MessageWatch.EXE\0"
|
||||
VALUE "ProductName", "MessageWatch Application\0"
|
||||
VALUE "ProductVersion", "1, 0, 0, 1\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO DISCARDABLE
|
||||
BEGIN
|
||||
IDD_MESSAGEWATCH_DIALOG, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 225
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 140
|
||||
END
|
||||
|
||||
IDD_OUTPUT, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 313
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 218
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
#define _AFX_NO_SPLITTER_RESOURCES
|
||||
#define _AFX_NO_OLE_RESOURCES
|
||||
#define _AFX_NO_TRACKER_RESOURCES
|
||||
#define _AFX_NO_PROPERTY_RESOURCES
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE 9, 1
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
#include "res\MessageWatch.rc2" // non-Microsoft Visual C++ edited resources
|
||||
#include "afxres.rc" // Standard components
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
324
utils/vmpi/testapps/MessageWatch/MessageWatchDlg.cpp
Normal file
324
utils/vmpi/testapps/MessageWatch/MessageWatchDlg.cpp
Normal file
@ -0,0 +1,324 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
// MessageWatchDlg.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "MessageWatch.h"
|
||||
#include "MessageWatchDlg.h"
|
||||
#include "messagemgr.h"
|
||||
#include "tier1/strtools.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
|
||||
#define WM_STARTIDLE (WM_USER + 565)
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------- //
|
||||
// CSender.
|
||||
// --------------------------------------------------------------------------- //
|
||||
|
||||
CSender::CSender()
|
||||
{
|
||||
m_pSocket = NULL;
|
||||
m_pConsoleWnd = NULL;
|
||||
}
|
||||
|
||||
CSender::~CSender()
|
||||
{
|
||||
if ( m_pSocket )
|
||||
m_pSocket->Release();
|
||||
|
||||
if ( m_pConsoleWnd )
|
||||
m_pConsoleWnd->Release();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMessageWatchDlg dialog
|
||||
|
||||
CMessageWatchDlg::CMessageWatchDlg(CWnd* pParent /*=NULL*/)
|
||||
: CDialog(CMessageWatchDlg::IDD, pParent)
|
||||
{
|
||||
//{{AFX_DATA_INIT(CMessageWatchDlg)
|
||||
// NOTE: the ClassWizard will add member initialization here
|
||||
//}}AFX_DATA_INIT
|
||||
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
|
||||
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
||||
|
||||
m_pListenSocket = NULL;
|
||||
}
|
||||
|
||||
CMessageWatchDlg::~CMessageWatchDlg()
|
||||
{
|
||||
// destroy the sender objects.
|
||||
|
||||
if ( m_pListenSocket )
|
||||
m_pListenSocket->Release();
|
||||
}
|
||||
|
||||
void CMessageWatchDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(CMessageWatchDlg)
|
||||
DDX_Control(pDX, IDC_MACHINES, m_Machines);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CMessageWatchDlg, CDialog)
|
||||
//{{AFX_MSG_MAP(CMessageWatchDlg)
|
||||
ON_MESSAGE(WM_STARTIDLE, OnStartIdle)
|
||||
ON_WM_PAINT()
|
||||
ON_WM_QUERYDRAGICON()
|
||||
ON_LBN_DBLCLK(IDC_MACHINES, OnDblclkMachines)
|
||||
ON_BN_CLICKED(IDSHOWALL, OnShowall)
|
||||
ON_BN_CLICKED(IDHIDEALL, OnHideall)
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMessageWatchDlg message handlers
|
||||
|
||||
BOOL CMessageWatchDlg::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
// Set the icon for this dialog. The framework does this automatically
|
||||
// when the application's main window is not a dialog
|
||||
SetIcon(m_hIcon, TRUE); // Set big icon
|
||||
SetIcon(m_hIcon, FALSE); // Set small icon
|
||||
|
||||
// Setup our listen socket and thread.
|
||||
m_pListenSocket = CreateIPSocket();
|
||||
m_pListenSocket->BindToAny( MSGMGR_BROADCAST_PORT );
|
||||
|
||||
m_cWinIdle.StartIdle( GetSafeHwnd(), WM_STARTIDLE, 0, 0, 100 );
|
||||
m_cWinIdle.NextIdle();
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
}
|
||||
|
||||
|
||||
LONG CMessageWatchDlg::OnStartIdle( UINT, LONG )
|
||||
{
|
||||
MSG msg;
|
||||
if (!PeekMessage(&msg, GetSafeHwnd(), 0,0, PM_NOREMOVE))
|
||||
OnIdle();
|
||||
m_cWinIdle.NextIdle();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void CMessageWatchDlg::OnIdle()
|
||||
{
|
||||
// Kill dead connections.
|
||||
int iNext;
|
||||
for ( int iSender=m_Senders.Head(); iSender != m_Senders.InvalidIndex(); iSender = iNext )
|
||||
{
|
||||
iNext = m_Senders.Next( iSender );
|
||||
|
||||
CSender *pSender = m_Senders[iSender];
|
||||
if ( pSender->m_pSocket && !pSender->m_pSocket->IsConnected() )
|
||||
{
|
||||
// Just release the socket so the text stays there.
|
||||
pSender->m_pSocket->Release();
|
||||
pSender->m_pSocket = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Look for new connections.
|
||||
while ( 1 )
|
||||
{
|
||||
CIPAddr ipFrom;
|
||||
char data[16];
|
||||
int len = m_pListenSocket->RecvFrom( data, sizeof( data ), &ipFrom );
|
||||
if ( len == -1 )
|
||||
break;
|
||||
|
||||
if ( data[0] == MSGMGR_PACKETID_ANNOUNCE_PRESENCE &&
|
||||
*((int*)&data[1]) == MSGMGR_VERSION )
|
||||
{
|
||||
int iPort = *((int*)&data[5]);
|
||||
|
||||
// See if we have a machine with this info yet.
|
||||
CIPAddr connectAddr = ipFrom;
|
||||
connectAddr.port = iPort;
|
||||
|
||||
// NOTE: we'll accept connections from machines we were connected to earlier but
|
||||
// lost the connection to.
|
||||
CSender *pSender = FindSenderByAddr( ipFrom.ip );
|
||||
if ( !pSender || !pSender->m_pSocket )
|
||||
{
|
||||
// 'nitiate the connection.
|
||||
ITCPSocket *pNew = CreateTCPSocket();
|
||||
if ( pNew->BindToAny( 0 ) && TCPSocket_Connect( pNew, &connectAddr, 1000 ) )
|
||||
{
|
||||
char nameStr[256];
|
||||
char title[512];
|
||||
if ( !ConvertIPAddrToString( &ipFrom, nameStr, sizeof( nameStr ) ) )
|
||||
Q_snprintf( nameStr, sizeof( nameStr ), "%d.%d.%d.%d", ipFrom.ip[0], ipFrom.ip[1], ipFrom.ip[2], ipFrom.ip[3] );
|
||||
|
||||
Q_snprintf( title, sizeof( title ), "%s:%d", nameStr, iPort );
|
||||
|
||||
// If the sender didn't exist yet, add a new one.
|
||||
if ( !pSender )
|
||||
{
|
||||
pSender = new CSender;
|
||||
|
||||
IConsoleWnd *pWnd = CreateConsoleWnd(
|
||||
AfxGetInstanceHandle(),
|
||||
IDD_OUTPUT,
|
||||
IDC_DEBUG_OUTPUT,
|
||||
false
|
||||
);
|
||||
|
||||
pSender->m_pConsoleWnd = pWnd;
|
||||
pWnd->SetTitle( title );
|
||||
|
||||
Q_strncpy( pSender->m_Name, title, sizeof( pSender->m_Name ) );
|
||||
m_Senders.AddToTail( pSender );
|
||||
m_Machines.AddString( pSender->m_Name );
|
||||
}
|
||||
|
||||
pSender->m_Addr = connectAddr;
|
||||
pSender->m_pSocket = pNew;
|
||||
}
|
||||
else
|
||||
{
|
||||
pNew->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Read input from our current connections.
|
||||
FOR_EACH_LL( m_Senders, i )
|
||||
{
|
||||
CSender *pSender = m_Senders[i];
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
if ( !pSender->m_pSocket )
|
||||
break;
|
||||
|
||||
CUtlVector<unsigned char> data;
|
||||
if ( !pSender->m_pSocket->Recv( data ) )
|
||||
break;
|
||||
|
||||
if ( data[0] == MSGMGR_PACKETID_MSG )
|
||||
{
|
||||
char *pMsg = (char*)&data[1];
|
||||
pSender->m_pConsoleWnd->PrintToConsole( pMsg );
|
||||
OutputDebugString( pMsg );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CMessageWatchDlg::OnDestroy()
|
||||
{
|
||||
// Stop the idling thread
|
||||
m_cWinIdle.EndIdle();
|
||||
CDialog::OnDestroy();
|
||||
}
|
||||
|
||||
|
||||
CSender* CMessageWatchDlg::FindSenderByAddr( const unsigned char ip[4] )
|
||||
{
|
||||
FOR_EACH_LL( m_Senders, i )
|
||||
{
|
||||
if ( memcmp( m_Senders[i]->m_Addr.ip, ip, 4 ) == 0 )
|
||||
return m_Senders[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
CSender* CMessageWatchDlg::FindSenderByName( const char *pName )
|
||||
{
|
||||
FOR_EACH_LL( m_Senders, i )
|
||||
{
|
||||
if ( stricmp( pName, m_Senders[i]->m_Name ) == 0 )
|
||||
return m_Senders[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// If you add a minimize button to your dialog, you will need the code below
|
||||
// to draw the icon. For MFC applications using the document/view model,
|
||||
// this is automatically done for you by the framework.
|
||||
|
||||
void CMessageWatchDlg::OnPaint()
|
||||
{
|
||||
if (IsIconic())
|
||||
{
|
||||
CPaintDC dc(this); // device context for painting
|
||||
|
||||
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
|
||||
|
||||
// Center icon in client rectangle
|
||||
int cxIcon = GetSystemMetrics(SM_CXICON);
|
||||
int cyIcon = GetSystemMetrics(SM_CYICON);
|
||||
CRect rect;
|
||||
GetClientRect(&rect);
|
||||
int x = (rect.Width() - cxIcon + 1) / 2;
|
||||
int y = (rect.Height() - cyIcon + 1) / 2;
|
||||
|
||||
// Draw the icon
|
||||
dc.DrawIcon(x, y, m_hIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
CDialog::OnPaint();
|
||||
}
|
||||
}
|
||||
|
||||
// The system calls this to obtain the cursor to display while the user drags
|
||||
// the minimized window.
|
||||
HCURSOR CMessageWatchDlg::OnQueryDragIcon()
|
||||
{
|
||||
return (HCURSOR) m_hIcon;
|
||||
}
|
||||
|
||||
void CMessageWatchDlg::OnDblclkMachines()
|
||||
{
|
||||
int index = m_Machines.GetCurSel();
|
||||
if ( index != LB_ERR )
|
||||
{
|
||||
CString str;
|
||||
m_Machines.GetText( index, str );
|
||||
|
||||
CSender *pSender = FindSenderByName( str );
|
||||
if ( pSender )
|
||||
pSender->m_pConsoleWnd->SetVisible( true );
|
||||
}
|
||||
}
|
||||
|
||||
void CMessageWatchDlg::OnShowall()
|
||||
{
|
||||
FOR_EACH_LL( m_Senders, i )
|
||||
{
|
||||
m_Senders[i]->m_pConsoleWnd->SetVisible( true );
|
||||
}
|
||||
}
|
||||
|
||||
void CMessageWatchDlg::OnHideall()
|
||||
{
|
||||
FOR_EACH_LL( m_Senders, i )
|
||||
{
|
||||
m_Senders[i]->m_pConsoleWnd->SetVisible( false );
|
||||
}
|
||||
}
|
100
utils/vmpi/testapps/MessageWatch/MessageWatchDlg.h
Normal file
100
utils/vmpi/testapps/MessageWatch/MessageWatchDlg.h
Normal file
@ -0,0 +1,100 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
// MessageWatchDlg.h : header file
|
||||
//
|
||||
|
||||
#if !defined(AFX_MESSAGEWATCHDLG_H__AB9CEAF4_0166_4CCA_9DEC_77C0918F78C4__INCLUDED_)
|
||||
#define AFX_MESSAGEWATCHDLG_H__AB9CEAF4_0166_4CCA_9DEC_77C0918F78C4__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
#include "iphelpers.h"
|
||||
#include "tcpsocket.h"
|
||||
#include "threadhelpers.h"
|
||||
#include "consolewnd.h"
|
||||
#include "win_idle.h"
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMessageWatchDlg dialog
|
||||
|
||||
class CSender
|
||||
{
|
||||
public:
|
||||
CSender();
|
||||
~CSender();
|
||||
|
||||
public:
|
||||
|
||||
CIPAddr m_Addr;
|
||||
ITCPSocket *m_pSocket;
|
||||
IConsoleWnd *m_pConsoleWnd;
|
||||
char m_Name[128];
|
||||
};
|
||||
|
||||
class CMessageWatchDlg : public CDialog
|
||||
{
|
||||
// Construction
|
||||
public:
|
||||
CMessageWatchDlg(CWnd* pParent = NULL); // standard constructor
|
||||
~CMessageWatchDlg();
|
||||
|
||||
|
||||
// Listen for broadcasts on this socket.
|
||||
ISocket *m_pListenSocket;
|
||||
|
||||
// Connections we've made.
|
||||
CUtlLinkedList<CSender*,int> m_Senders;
|
||||
|
||||
CCriticalSection m_SocketsCS;
|
||||
CWinIdle m_cWinIdle;
|
||||
|
||||
|
||||
CSender* FindSenderByAddr( const unsigned char ip[4] );
|
||||
CSender* FindSenderByName( const char *pName );
|
||||
|
||||
|
||||
// Dialog Data
|
||||
//{{AFX_DATA(CMessageWatchDlg)
|
||||
enum { IDD = IDD_MESSAGEWATCH_DIALOG };
|
||||
CListBox m_Machines;
|
||||
//}}AFX_DATA
|
||||
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CMessageWatchDlg)
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
protected:
|
||||
HICON m_hIcon;
|
||||
|
||||
void OnIdle();
|
||||
|
||||
// Generated message map functions
|
||||
//{{AFX_MSG(CMessageWatchDlg)
|
||||
afx_msg void OnDestroy();
|
||||
afx_msg LONG OnStartIdle(UINT, LONG);
|
||||
virtual BOOL OnInitDialog();
|
||||
afx_msg void OnPaint();
|
||||
afx_msg HCURSOR OnQueryDragIcon();
|
||||
afx_msg void OnDblclkMachines();
|
||||
afx_msg void OnShowall();
|
||||
afx_msg void OnHideall();
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_MESSAGEWATCHDLG_H__AB9CEAF4_0166_4CCA_9DEC_77C0918F78C4__INCLUDED_)
|
15
utils/vmpi/testapps/MessageWatch/StdAfx.cpp
Normal file
15
utils/vmpi/testapps/MessageWatch/StdAfx.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// MessageWatch.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
|
||||
|
33
utils/vmpi/testapps/MessageWatch/StdAfx.h
Normal file
33
utils/vmpi/testapps/MessageWatch/StdAfx.h
Normal file
@ -0,0 +1,33 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#if !defined(AFX_STDAFX_H__70653A1B_FB34_4AD9_861C_580071240D6F__INCLUDED_)
|
||||
#define AFX_STDAFX_H__70653A1B_FB34_4AD9_861C_580071240D6F__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
|
||||
|
||||
#include <afxwin.h> // MFC core and standard components
|
||||
#include <afxext.h> // MFC extensions
|
||||
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
|
||||
#ifndef _AFX_NO_AFXCMN_SUPPORT
|
||||
#include <afxcmn.h> // MFC support for Windows Common Controls
|
||||
#endif // _AFX_NO_AFXCMN_SUPPORT
|
||||
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_STDAFX_H__70653A1B_FB34_4AD9_861C_580071240D6F__INCLUDED_)
|
BIN
utils/vmpi/testapps/MessageWatch/res/MessageWatch.ico
Normal file
BIN
utils/vmpi/testapps/MessageWatch/res/MessageWatch.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
13
utils/vmpi/testapps/MessageWatch/res/MessageWatch.rc2
Normal file
13
utils/vmpi/testapps/MessageWatch/res/MessageWatch.rc2
Normal file
@ -0,0 +1,13 @@
|
||||
//
|
||||
// MESSAGEWATCH.RC2 - resources Microsoft Visual C++ does not edit directly
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#error this file is not editable by Microsoft Visual C++
|
||||
#endif //APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Add manually edited resources here...
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
29
utils/vmpi/testapps/MessageWatch/resource.h
Normal file
29
utils/vmpi/testapps/MessageWatch/resource.h
Normal file
@ -0,0 +1,29 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by MessageWatch.rc
|
||||
//
|
||||
#define IDSHOWALL 3
|
||||
#define IDHIDEALL 4
|
||||
#define IDD_MESSAGEWATCH_DIALOG 102
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDD_OUTPUT 129
|
||||
#define IDC_MACHINES 1000
|
||||
#define IDC_DEBUG_OUTPUT 1000
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 129
|
||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
123
utils/vmpi/testapps/MessageWatch/win_idle.cpp
Normal file
123
utils/vmpi/testapps/MessageWatch/win_idle.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
// Class for sending idle messages to a window
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "win_idle.h"
|
||||
|
||||
// Stub function to get into the object's main thread loop
|
||||
DWORD WINAPI CWinIdle::ThreadStub(LPVOID pIdle)
|
||||
{
|
||||
return ((CWinIdle *)pIdle)->RunIdle();
|
||||
}
|
||||
|
||||
CWinIdle::CWinIdle() :
|
||||
m_hIdleThread(NULL),
|
||||
m_hIdleEvent(NULL),
|
||||
m_hStopEvent(NULL),
|
||||
m_hWnd(0),
|
||||
m_uMsg(0),
|
||||
m_dwDelay(0)
|
||||
{
|
||||
}
|
||||
|
||||
CWinIdle::~CWinIdle()
|
||||
{
|
||||
if (m_hIdleThread)
|
||||
OutputDebugString("!!CWinIdle Warning!! Idle thread not shut down!\n");
|
||||
}
|
||||
|
||||
DWORD CWinIdle::RunIdle()
|
||||
{
|
||||
// Set up an event list
|
||||
HANDLE aEvents[2];
|
||||
|
||||
aEvents[0] = m_hStopEvent;
|
||||
aEvents[1] = m_hIdleEvent;
|
||||
|
||||
// Wait for a stop or idle event
|
||||
while (WaitForMultipleObjects(2, aEvents, FALSE, INFINITE) != WAIT_OBJECT_0)
|
||||
{
|
||||
// Send an idle message
|
||||
PostMessage(m_hWnd, m_uMsg, m_wParam, m_lParam);
|
||||
// Wait for a bit...
|
||||
Sleep(m_dwDelay);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL CWinIdle::StartIdle(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam, DWORD dwDelay)
|
||||
{
|
||||
// Make sure it's not already running
|
||||
if (m_hIdleThread)
|
||||
return FALSE;
|
||||
|
||||
// Make sure they send in a valid handle..
|
||||
if (!hWnd)
|
||||
return FALSE;
|
||||
|
||||
// Create the events
|
||||
m_hIdleEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
m_hStopEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
|
||||
// Make sure the events got created
|
||||
if ((!m_hIdleEvent) || (!m_hStopEvent))
|
||||
return FALSE;
|
||||
|
||||
// Create the thread
|
||||
DWORD dwThreadID;
|
||||
m_hIdleThread = CreateThread(NULL, 0, CWinIdle::ThreadStub, (void *)this, 0, &dwThreadID);
|
||||
|
||||
if (m_hIdleThread)
|
||||
{
|
||||
SetThreadPriority(m_hIdleThread, THREAD_PRIORITY_IDLE);
|
||||
|
||||
m_hWnd = hWnd;
|
||||
m_uMsg = uMessage;
|
||||
m_wParam = wParam;
|
||||
m_lParam = lParam;
|
||||
|
||||
m_dwDelay = dwDelay;
|
||||
}
|
||||
|
||||
return m_hIdleThread != 0;
|
||||
}
|
||||
|
||||
BOOL CWinIdle::EndIdle()
|
||||
{
|
||||
// Make sure it's running
|
||||
if (!m_hIdleThread)
|
||||
return FALSE;
|
||||
|
||||
// Stop the idle thread
|
||||
SetEvent(m_hStopEvent);
|
||||
WaitForSingleObject(m_hIdleThread, INFINITE);
|
||||
CloseHandle(m_hIdleThread);
|
||||
|
||||
// Get rid of the event objects
|
||||
CloseHandle(m_hIdleEvent);
|
||||
CloseHandle(m_hStopEvent);
|
||||
|
||||
// Set everything back to 0
|
||||
m_hIdleEvent = 0;
|
||||
m_hStopEvent = 0;
|
||||
m_hIdleThread = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CWinIdle::NextIdle()
|
||||
{
|
||||
// Make sure the thread's running
|
||||
if (!m_hIdleThread)
|
||||
return;
|
||||
|
||||
// Signal an idle message
|
||||
SetEvent(m_hIdleEvent);
|
||||
}
|
78
utils/vmpi/testapps/MessageWatch/win_idle.h
Normal file
78
utils/vmpi/testapps/MessageWatch/win_idle.h
Normal file
@ -0,0 +1,78 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
// WinIdle.h - Defines a class for sending idle messages to a window from a secondary thread
|
||||
|
||||
#ifndef __WINIDLE_H__
|
||||
#define __WINIDLE_H__
|
||||
|
||||
|
||||
class CWinIdle
|
||||
{
|
||||
protected:
|
||||
HANDLE m_hIdleEvent, m_hStopEvent;
|
||||
|
||||
HWND m_hWnd;
|
||||
UINT m_uMsg;
|
||||
WPARAM m_wParam;
|
||||
LPARAM m_lParam;
|
||||
|
||||
DWORD m_dwDelay;
|
||||
|
||||
HANDLE m_hIdleThread;
|
||||
|
||||
// The thread calling stub
|
||||
static DWORD WINAPI ThreadStub(LPVOID pIdle);
|
||||
// The actual idle loop
|
||||
virtual DWORD RunIdle();
|
||||
|
||||
public:
|
||||
CWinIdle();
|
||||
virtual ~CWinIdle();
|
||||
|
||||
inline DWORD GetDelay() {return m_dwDelay;}
|
||||
inline void SetDelay(DWORD delay) {m_dwDelay = delay;}
|
||||
|
||||
// Member access
|
||||
virtual HANDLE GetThreadHandle() const { return m_hIdleThread; };
|
||||
|
||||
// Start idling, and define the message and window to use
|
||||
// Returns TRUE on success
|
||||
virtual BOOL StartIdle(HWND hWnd, UINT uMessage, WPARAM wParam = 0, LPARAM lParam = 0, DWORD dwDelay = 0);
|
||||
// Stop idling
|
||||
// Returns TRUE on success
|
||||
virtual BOOL EndIdle();
|
||||
// Notify the idle process that the message was received.
|
||||
// Note : If this function is not called, the idle thread will not send any messages
|
||||
virtual void NextIdle();
|
||||
};
|
||||
|
||||
|
||||
// Used to slow down the idle thread while dialogs are up.
|
||||
class IdleChanger
|
||||
{
|
||||
public:
|
||||
IdleChanger(CWinIdle *pIdle, DWORD msDelay)
|
||||
{
|
||||
m_pIdle = pIdle;
|
||||
m_OldDelay = pIdle->GetDelay();
|
||||
pIdle->SetDelay(msDelay);
|
||||
}
|
||||
|
||||
~IdleChanger()
|
||||
{
|
||||
m_pIdle->SetDelay(m_OldDelay);
|
||||
}
|
||||
|
||||
CWinIdle *m_pIdle;
|
||||
DWORD m_OldDelay;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //__WINIDLE_H__
|
||||
|
Reference in New Issue
Block a user