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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: defines a RCon class used to send rcon commands to remote servers
//
// $NoKeywords: $
//=============================================================================
#include "mapslist.h"
#include "Iresponse.h"
#include "Socket.h"
#include "proto_oob.h"
#include "DialogGameInfo.h"
#include "inetapi.h"
#include "TokenLine.h"
#include "dialogkickplayer.h"
#include <string.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;
CMapsList::CMapsList(IResponse *target,serveritem_t &server, const char *rconPassword,const char *mod) {
memcpy(&m_Server, &server,sizeof(serveritem_t));
m_pResponseTarget=target;
if(strcmp(mod,"valve") )
{
v_strncpy(m_sMod,mod,64);
}
else
{
m_sMod[0]=0; // its the "valve" default mod, list all maps
}
m_bIsRefreshing=false;
m_bNewMapsList=false;
m_bRconFailed=false;
v_strncpy(m_szRconPassword,rconPassword,100);
m_pRcon = new CRcon(this , server,rconPassword);
}
CMapsList::~CMapsList() {
delete m_pRcon;
}
//-----------------------------------------------------------------------------
// Purpose: sends a status query packet to a single server
//-----------------------------------------------------------------------------
void CMapsList::SendQuery()
{
m_bIsRefreshing=true;
m_pRcon->SendRcon("maps *");
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMapsList::RunFrame()
{
if(m_pRcon)
{
m_pRcon->RunFrame();
}
}
void CMapsList::ServerResponded()
{
char store[2048];
strcpy(store, m_pRcon->RconResponse());
char *cur=store;
char *next=NULL;
int i=0,k=0;
bool checkDir=false;
// maps format:
// Dir: valve
//-------------
//(fs) rapidcore.bsp
//(fs) frenzy.bsp
//(fs) crossfire.bsp
//
//Dir: valve
//-------------
//(pak) boot_camp.bsp
//(pak) bounce.bsp
m_MapsList.RemoveAll();
char check[21];
_snprintf(check,21,"%s/",m_sMod);
if(strstr(store,check))
{ // if the name of the mod dir is in the return list its old style format
checkDir=true;
}
while(cur!=NULL)
{
cur++;
next=strchr(cur,'\n');
if(next!=NULL)
{
*next='\0';
}
if( strncmp(cur,"Dir:",4) && strncmp(cur,"-------------",13) )
{
TokenLine mapsLine;
mapsLine.SetLine(cur);
if(mapsLine.CountToken() >= 2 )
{
char tmpMap[100];
v_strncpy(tmpMap,mapsLine.GetToken(1),100); // type
char *end = strstr(tmpMap,".bsp"); // cull the .bsp
if(end != NULL)
{
*end='\0';
}
if(checkDir==true && strstr(tmpMap,m_sMod)==NULL )
// if the map name doesn't have the mod dir in it
// and its not running the "valve" mod continue
{
cur=next;
continue;
}
if ( strchr(tmpMap,'/') ) // remove the directory part of the map name
{
strcpy(tmpMap,strrchr(tmpMap,'/')+1);
}
for(k=0;k<m_MapsList.Count();k++) // now check it doesn't already exist inside the map list...
{
if(!strncmp(tmpMap,m_MapsList[k].name,strlen(tmpMap)) )
{
break;
}
}
if(k==m_MapsList.Count() // the map wasn't found
&& !(tmpMap[0]=='c' && (tmpMap[1]>='1' && tmpMap[1]<='5')) // a heuristic to remove single player maps
&& !(tmpMap[0]=='t' && tmpMap[1]=='0') ) // from the list
{
Maps_t map;
// this map wasn't found already
v_strncpy(map.name,tmpMap,strlen(tmpMap)+1);
if( !strcmp("(fs)",mapsLine.GetToken(0)) )
{ // name
map.type=FS;
}
else
{
map.type=PAK;
}
m_MapsList.AddToTail(map);
i++;
} // if k == Count
} // CountToken
} // if not a Dir: or "----------"
cur=next;
}
m_bNewMapsList=true;
m_bIsRefreshing=false;
// notify the UI of the new server info
m_pResponseTarget->ServerResponded();
}
void CMapsList::ServerFailedToRespond()
{
// rcon failed
//m_pResponseTarget->ServerFailedToRespond();
}
void CMapsList::Refresh()
{
SendQuery();
}
bool CMapsList::IsRefreshing()
{
return m_bIsRefreshing;
}
serveritem_t &CMapsList::GetServer()
{
return m_Server;
}
bool CMapsList::NewMapsList()
{
return m_bNewMapsList;
}
CUtlVector<Maps_t> *CMapsList::GetMapsList()
{
m_bNewMapsList=false;
return &m_MapsList;
}
void CMapsList::SetPassword(const char *newPass)
{
m_pRcon->SetPassword(newPass);
m_bRconFailed=false;
}
|