-
Notifications
You must be signed in to change notification settings - Fork 2
/
DiagWindows.cpp
105 lines (85 loc) · 3.16 KB
/
DiagWindows.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include "tinyxml.h"
//#include "sockets.h"
//! \file
//! \brief These functions are deprecated and should not be used
const int iPortDebugConsole = 22155;
SOCKET DiagConsoleSocket;
char SendBuffer1[2048];
char SendBuffer2[2048];
bool bInitialized = false;
bool bAttemptedToConnectToDebugConsole = false;
SOCKET DiagSocketsConnectToServer( unsigned long IPAddress, int iPort )
{
SOCKET m_socket = SOCKET_ERROR;
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( m_socket == INVALID_SOCKET )
{
// debug( "Error at socket(): %ld\n", WSAGetLastError() );
// WSACleanup();
return SOCKET_ERROR;
// exit(1);
}
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = IPAddress;
clientService.sin_port = htons( iPort );
if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR)
{
//debug( "Failed to connect.\n" );
// WSACleanup();
// exit(1);
return SOCKET_ERROR;
}
return m_socket;
}
void DebugInit()
{
DiagConsoleSocket = DiagSocketsConnectToServer( inet_addr( "127.0.0.1" ), iPortDebugConsole );
if( DiagConsoleSocket != SOCKET_ERROR )
{
bInitialized = true;
}
bAttemptedToConnectToDebugConsole = true;
}
//! This function is deprecated and should not be used
// This should probably
// dump to a file or something in the future. (or maybe send out sockets messages
// to a console)
void debug( char *sMessage, ... )
{
// MessageBox(NULL, "debug function start", "Debug message",MB_OK | MB_ICONINFORMATION);
if( !bInitialized && !bAttemptedToConnectToDebugConsole )
{
// MessageBox(NULL, "init", "Debug message",MB_OK | MB_ICONINFORMATION);
DebugInit();
}
if( bInitialized )
{
va_list args;
va_start( args, sMessage );
// MessageBox(NULL, "vsprintf", "Debug message",MB_OK | MB_ICONINFORMATION);
vsprintf( SendBuffer1, sMessage, args );
// MessageBox(NULL, "sprintf", "Debug message",MB_OK | MB_ICONINFORMATION);
sprintf( SendBuffer2, "<debug message=\"%.2047s\"/>\n", SendBuffer1 );
// MessageBox(NULL, "send", "Debug message",MB_OK | MB_ICONINFORMATION);
int bytessent = send( DiagConsoleSocket, SendBuffer2, strlen( SendBuffer2 ), 0 );
if( bytessent == SOCKET_ERROR )
{
bInitialized = false;
}
// MessageBox(NULL, "debug function done", "Debug message",MB_OK | MB_ICONINFORMATION);
}
}
//! This function is deprecated and should not be used
void SignalCriticalError( char *sMessage, ... )
{
MessageBox(NULL, "crit function start", "Debug message",MB_OK | MB_ICONINFORMATION);
va_list args;
va_start( args, sMessage );
vsprintf( SendBuffer1, sMessage, args );
MessageBox(NULL, SendBuffer1, "Critical error",MB_OK | MB_ICONINFORMATION);
MessageBox(NULL, "crit function done", "Debug message",MB_OK | MB_ICONINFORMATION);
}