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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Implementation of CLogEventArgument
//
// $Workfile: $
// $Date: $
//
//------------------------------------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//
#pragma warning (disable:4786)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "argument.h"
#include "memdbg.h"
using namespace std;
//------------------------------------------------------------------------------------------------------
// Function: CLogEventArgument::CLogEventArgument
// Purpose: Constructor that builds the object out of the passed in string of text
// Input: text - text representing the argument
//------------------------------------------------------------------------------------------------------
CLogEventArgument::CLogEventArgument(const char* text)
{
init(text);
}
//------------------------------------------------------------------------------------------------------
// Function: CLogEventArgument::CLogEventArgument
// Purpose: Default constructor
//------------------------------------------------------------------------------------------------------
CLogEventArgument::CLogEventArgument()
:m_ArgText(NULL),m_Valid(false)
{}
//------------------------------------------------------------------------------------------------------
// Function: CLogEventArgument::init
// Purpose: initializes the argument
// Input: text - the text representing the argument
//------------------------------------------------------------------------------------------------------
void CLogEventArgument::init(const char* text)
{
int len=strlen(text);
m_ArgText=new TRACKED char[len+1];
strcpy(m_ArgText,text);
m_Valid=true;
}
char* findStartOfSvrID(char* cs)
{
char* read=&cs[strlen(cs)-1];
while (read != cs)
{
if (*read=='<' && *(read+1) != 'W') // if we've found a svrID
break;
read--;
}
return read;
}
//------------------------------------------------------------------------------------------------------
// Function: CLogEventArgument::asPlayerGetID
// Purpose: treats the argument as a player name, and returns the player ID.
// Note: PlayerName args have this form: "name<pid><WON:wonid>"
// Output: the ID of the player represented by this argument
//------------------------------------------------------------------------------------------------------
int CLogEventArgument::asPlayerGetSvrPID() const
{
char* read=findStartOfSvrID(m_ArgText);
if (read==m_ArgText)
return -1;
int retval=-1;
sscanf(read,"<%i>",&retval);
return retval;
}
/*
PID CLogEventArgument::asPlayerGetPID() const
{
char* openPID=NULL;
int svrPID=INVALID_PID;
if (openPID=strchr(m_ArgText,'<'))
{
openPID++;
sscanf(openPID,"%i",&svrPID);
}
unsigned long wonID;
if (openPID=strstr(m_ArgText,"<WON:"))
{
openPID+=5;
sscanf(openPID,"%li",&wonID);
}
return PID(svrPID,wonID);
}
*/
//------------------------------------------------------------------------------------------------------
// Function: CLogEventArgument::asPlayerGetName
// Purpose: treats the argument as a player name, and copies/returns the player name.
// Note: PlayerName args have this form: "name<pid><WONID:wonid>"
// Input: copybuf - the buffer to copy the name into
// Output: char* the pointer to the buffer that the name was copied into
//------------------------------------------------------------------------------------------------------
char* CLogEventArgument::asPlayerGetName(char* copybuf) const
{
char* eon=findStartOfSvrID(m_ArgText);
bool noPID=(eon==m_ArgText);
char old=*eon;
if (!noPID)
*eon=0;
strcpy(copybuf,m_ArgText);
if (!noPID)
*eon=old;
return copybuf;
}
//------------------------------------------------------------------------------------------------------
// Function: CLogEventArgument::asPlayerGetName
// Purpose: an alternate form of the above function that returns the playername
// as a C++ string, rather than buffercopying it around
// Output: string: the player's name
//------------------------------------------------------------------------------------------------------
string CLogEventArgument::asPlayerGetName() const
{
char* eon=findStartOfSvrID(m_ArgText);
bool noPID=(eon==m_ArgText);
char old=*eon;
if (!noPID)
*eon=0;
string s(m_ArgText);
if (!noPID)
*eon=old;
return s;
}
//------------------------------------------------------------------------------------------------------
// Function: CLogEventArgument::asPlayerGetWONID
// Purpose: treats the argument as a player name, and returns the player's wonid
// Note: PlayerName args have this form: "name<pid><WON:wonid>"
// Output: int: the WONID of the player
//------------------------------------------------------------------------------------------------------
unsigned long CLogEventArgument::asPlayerGetWONID() const
{
char* openPID=NULL;
unsigned long retval=INVALID_WONID;
if (openPID=strstr(m_ArgText,"<WON:"))
{
openPID+=5; //move past the <WON: string
sscanf(openPID,"%lu",&retval);
}
return retval;
}
unsigned long CLogEventArgument::asPlayerGetPID() const
{
int svrPID=asPlayerGetSvrPID();
if (pidMap[svrPID]==0 || pidMap[svrPID]==-1)
pidMap[svrPID]=svrPID;
return pidMap[svrPID];
}
//------------------------------------------------------------------------------------------------------
// Function: CLogEventArgument::getFloatValue
// Purpose: treats the argument as a floating point value, and returns it
// Output: double
//------------------------------------------------------------------------------------------------------
double CLogEventArgument::getFloatValue() const
{
return atof(m_ArgText);
}
//------------------------------------------------------------------------------------------------------
// Function: CLogEventArgument::getStringValue
// Purpose: treats the argument as a string and returns a pointer to the argument
// text itself. note the pointer is const, so the argument can't be modified by
// the caller (unless they perform some nefarious casting on the returned pointer)
// Output: const char*
//------------------------------------------------------------------------------------------------------
const char* CLogEventArgument::getStringValue() const
{
return m_ArgText;
}
//------------------------------------------------------------------------------------------------------
// Function: CLogEventArgument::getStringValue
// Purpose: an alternate form of the above that copies the string into a caller
// supplied buffer then returns a pointer to that buffer
// Input: copybuf - the buffer into which the string is to be copied
// Output: char* the pointer to the buffer that the caller passed in
//------------------------------------------------------------------------------------------------------
char* CLogEventArgument::getStringValue(char* copybuf) const
{
strcpy(copybuf,m_ArgText);
return copybuf;
}
|