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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: queries server for the command list, and then use QueryCommand() to see
// if the server supports this command.
//
// $NoKeywords: $
//=============================================================================
#include <ctype.h> // isspace() define
#include <string.h>
#include "CMDList.h"
#include "Iresponse.h"
#include "Socket.h"
#include "proto_oob.h"
#include "DialogGameInfo.h"
#include "inetapi.h"
#include "TokenLine.h"
#include "dialogkickplayer.h"
extern void v_strncpy(char *dest, const char *src, int bufsize);
typedef enum
{
NONE = 0,
INFO_REQUESTED,
INFO_RECEIVED
} RCONSTATUS;
typedef enum
{
FS,
PAK
} MAP_TYPES;
CCMDList::CCMDList(IResponse *target,serveritem_t &server, const char *rconPassword) {
memcpy(&m_Server, &server,sizeof(serveritem_t));
m_bGotCommands = false;
m_pResponseTarget=target;
v_strncpy(m_szRconPassword,rconPassword,100);
m_pRcon = new CRcon(this , server,rconPassword);
m_pRcon->SendRcon("cmdlist");
m_CMDList.RemoveAll();
}
CCMDList::~CCMDList() {
delete m_pRcon;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCMDList::RunFrame()
{
if(m_pRcon)
{
m_pRcon->RunFrame();
}
}
void CCMDList::ServerResponded()
{
char store[2048];
strcpy(store, m_pRcon->RconResponse());
char *cur=store;
char *next=NULL;
char *cmd=NULL;
bool cmd_end=false;
// response format:
//Command List
//--------------
//_unloadmodule
// ...
// writeip
//--------------
//125 Total Commands
//CmdList ? for syntax
while(cur!=NULL)
{
if(next!=NULL)
{
cur++;
}
next=strchr(cur,'\n');
if(next!=NULL)
{
*next='\0';
}
if( strncmp(cur,"Command List",12) && strncmp(cur,"-------------",13)
&& strncmp(cur,"Total Commands",14) && strncmp(cur,"CmdList ? for syntax",20) )
{
char *removeWhiteSpace=cur;
while(!isspace(*removeWhiteSpace) && removeWhiteSpace<next)
{
removeWhiteSpace++;
}
*removeWhiteSpace='\0';
cmd = new char[strlen(cur)];
if(cmd)
{
strcpy(cmd,cur);
m_CMDList.AddToTail(cmd);
}
}
else if ( ! strncmp(cur,"CmdList ? for syntax",20))
{
cmd_end=true;
}
cur=next;
}
if( cmd_end )
{
m_bGotCommands = true;
m_pResponseTarget->ServerResponded();
}
}
void CCMDList::ServerFailedToRespond()
{
//m_pResponseTarget->ServerFailedToRespond();
}
serveritem_t &CCMDList::GetServer()
{
return m_Server;
}
bool CCMDList::QueryCommand(char *cmd)
{
if(!m_bGotCommands)
return false;
for(int i=0;i<m_CMDList.Count();i++)
{
char *cmd_in = m_CMDList[i];
if(!stricmp(cmd,m_CMDList[i]))
break;
}
if(i!=m_CMDList.Count())
{
return true;
}
else
return false;
}
bool CCMDList::GotCommands()
{
return m_bGotCommands;
}
void CCMDList::SetPassword(const char *newPass)
{
m_pRcon->SetPassword(newPass);
m_bGotCommands = false;
m_CMDList.RemoveAll();
m_pRcon->SendRcon("cmdlist");
}
|