Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
debug_io_net.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
20// $File: //depot/GeneralsMD/Staging/code/Libraries/Source/debug/debug_io_net.cpp $
21// $Author: mhoffe $
22// $Revision: #1 $
23// $DateTime: 2003/07/03 11:55:26 $
24//
25// ©2003 Electronic Arts
26//
27// Debug I/O class net (Network destination via named pipe)
29#include "_pch.h"
30#include <new> // needed for placement new prototype
31
35
37{
38 if (m_pipe!=INVALID_HANDLE_VALUE)
39 CloseHandle(m_pipe);
40}
41
42int DebugIONet::Read(char *buf, int maxchar)
43{
44 if (m_pipe==INVALID_HANDLE_VALUE)
45 return 0;
46
47 DWORD mode=PIPE_READMODE_MESSAGE|PIPE_NOWAIT;
48 SetNamedPipeHandleState(m_pipe,&mode,NULL,NULL);
49
50 DWORD read;
51 if (!ReadFile(m_pipe,buf,maxchar-1,&read,NULL))
52 read=0;
53 mode=PIPE_READMODE_MESSAGE|PIPE_WAIT;
54 SetNamedPipeHandleState(m_pipe,&mode,NULL,NULL);
55
56 return read;
57}
58
59void DebugIONet::Write(StringType type, const char *src, const char *str)
60{
61 if (m_pipe==INVALID_HANDLE_VALUE)
62 return;
63
64 DWORD dummy;
65 WriteFile(m_pipe,&type,1,&dummy,NULL);
66
67 unsigned len;
68 len=src?strlen(src):0;
69 WriteFile(m_pipe,&len,4,&dummy,NULL);
70 if (len)
71 WriteFile(m_pipe,src,len,&dummy,NULL);
72
73 len=strlen(str);
74 WriteFile(m_pipe,&len,4,&dummy,NULL);
75 if (len)
76 WriteFile(m_pipe,str,len,&dummy,NULL);
77}
78
80{
81}
82
83void DebugIONet::Execute(class Debug& dbg, const char *cmd, bool structuredCmd,
84 unsigned argn, const char * const * argv)
85{
86 if (!cmd||!strcmp(cmd,"help"))
87 {
88 dbg << "net I/O help:\n"
89 " add [ <machine> ]\n"
90 " create net I/O (optionally specifying the machine to connect to)\n";
91 }
92 else if (!strcmp(cmd,"add"))
93 {
94 const char *machine=argn?argv[0]:".";
95
96 char buf[256];
97 wsprintf(buf,"\\\\%s\\pipe\\ea_debug_v1",machine);
98 m_pipe=CreateFile(buf,GENERIC_READ|GENERIC_WRITE,
99 0,NULL,OPEN_EXISTING,0,NULL);
100 if (m_pipe==INVALID_HANDLE_VALUE)
101 {
102 dbg << "Could not connect to given machine.\n";
103 return;
104 }
105
106 // we're reading messages
107 DWORD mode=PIPE_READMODE_MESSAGE;
108 SetNamedPipeHandleState(m_pipe,&mode,NULL,NULL);
109
110 // write welcome message
111 char comp[128];
112 mode=sizeof(comp);
113 GetComputerName(comp,&mode);
114 wsprintf(buf,"Client at %s\n",comp);
115 Write(Other,NULL,buf);
116 }
117}
118
119DebugIOInterface *DebugIONet::Create(void)
120{
121 return new (DebugAllocMemory(sizeof(DebugIONet))) DebugIONet();
122}
123
125{
126 this->~DebugIONet();
127 DebugFreeMemory(this);
128}
#define NULL
Definition BaseType.h:92
unsigned long DWORD
Definition bittype.h:57
Debug module main class (singleton).
Definition debug_debug.h:45
StringType
List of possible log string types.
Definition debug_io.h:67
@ Other
some other message
Definition debug_io.h:90
static DebugIOInterface * Create(void)
virtual void Write(StringType type, const char *src, const char *str)
Write out some characters differentiated by the log string type.
virtual void Delete(void)
Destroys the current I/O class instance.
virtual int Read(char *buf, int maxchar)
Retrieves up to the given number of characters from a command input source.
virtual ~DebugIONet()
virtual void Execute(class Debug &dbg, const char *cmd, bool structuredCmd, unsigned argn, const char *const *argv)
I/O class specific command.
virtual void EmergencyFlush(void)
Emergency shutdown function.
void * DebugAllocMemory(unsigned numBytes)
void DebugFreeMemory(void *ptr)