-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodServerLogLine.cs
More file actions
executable file
·164 lines (139 loc) · 4.82 KB
/
Copy pathCodServerLogLine.cs
File metadata and controls
executable file
·164 lines (139 loc) · 4.82 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace BlopsAutoKicker
{
internal enum LogLineType
{
Join = 0,
Quit,
Kill_Damage,
Say,
Init,
Shutdown,
Blank
}
/// <summary>
/// Represents all the data that could come from a single line
/// </summary>
///
internal class CodServerLogLine
{
internal const string RulesTrigger = "!rules";
internal LogLineType LineType { get; private set; }
internal string PlayerName { get; private set; }
internal string PlayerId { get; private set; }
internal string Weapon { get; private set; }
internal bool RulesRequest { get; private set; }
internal bool IsMelee { get; private set; }
internal double TimeStamp { get; private set; }
static Regex regex = new Regex(@"(\d+):(\d+) (.*)$",RegexOptions.Compiled);
private CodServerLogLine()
{
}
internal static CodServerLogLine ParseLine(string line)
{
CodServerLogLine csl = new CodServerLogLine();
var m = regex.Match(line);
if (!m.Success)
{
return null;
}
double d;
if (!Double.TryParse(String.Concat(m.Groups[1].Value, ".", m.Groups[2].Value), out d))
{
// couldn't parse the time stamp
return null;
}
csl.TimeStamp = d;
var data = m.Groups[3].Value.Split(';');
//handle special cases for broken lines, init and shutdown
if (data.Count() == 1)
{
if (data[0].Contains("InitGame:"))
{
csl.LineType = LogLineType.Init;
return csl;
}
else if (data[0].Contains("ShutdownGame:"))
{
csl.LineType = LogLineType.Shutdown;
return csl;
}
return null;
}
var command = data[0];
switch (command)
{
case "J":
if (data.Length < 4)
{
csl.LineType = LogLineType.Blank;
break;
}
csl.LineType = LogLineType.Join;
csl.PlayerId = data[2].Trim();
csl.PlayerName = data[3].Trim();
break;
case "Q":
if (data.Length < 4)
{
csl.LineType = LogLineType.Blank;
break;
}
csl.LineType = LogLineType.Quit;
csl.PlayerId = data[2].Trim();
csl.PlayerName = data[3].Trim();
break;
case "say":
if (data.Length < 5)
{
csl.LineType = LogLineType.Blank;
break;
}
csl.LineType = LogLineType.Say;
csl.PlayerId = data[2].Trim();
csl.PlayerName = data[3].Trim();
if (data.Length > 4 && data[4].Contains(RulesTrigger))
{
csl.RulesRequest = true;
}
break;
case "D":
case "K":
if (data.Length < 12)
{
csl.LineType = LogLineType.Blank;
//broken line
break;
}
csl.LineType = LogLineType.Kill_Damage;
csl.PlayerId = data[6].Trim();
csl.PlayerName = data[8].Trim();
csl.Weapon = data[9].Trim();
if(data[11].Contains("MOD_MELEE"))
{
csl.IsMelee = true;
}
break;
default:
if (data[0].Contains("InitGame:"))
{
csl.LineType = LogLineType.Init;
}
else if (data[0].Contains("ShutdownGame:"))
{
csl.LineType = LogLineType.Shutdown;
}
else
{
csl.LineType = LogLineType.Blank;
}
break;
}
return csl;
}
}
}