-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogParser.cs
More file actions
129 lines (110 loc) · 4.22 KB
/
logParser.cs
File metadata and controls
129 lines (110 loc) · 4.22 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace chatwindow
{
class logParser
{
private const string isLoginLine = "[Accounts - Login] Logged in successfully.";
private const string usernameGetter = @" (\w+)#\d+";
private const string matchConnected = "[UnityCrossThreadLogger]==> Event.MatchCreated";
private const string opponenetGetter = "\"opponentScreenName\":\"(\\w+)\"";
private const string gameEnded = "[UnityCrossThreadLogger]";
private const string gameEnded2 = "MatchGameRoomStateType_MatchCompleted";
private static FileStream fileStreamy;
private static StreamReader streamy;
public static void OpenLogFile()
{
//Discover the newest log file
var directory = new DirectoryInfo(configLoader.logLocation);
var newestLog = directory.GetFiles()
.OrderByDescending(f => f.LastWriteTime)
.First().FullName;
fileStreamy = new FileStream(newestLog, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
streamy = new StreamReader(fileStreamy);
}
public static string GetUsername()
{
Regex reg = new Regex(usernameGetter);
int count = 0;
// read from file
string line = "";
do
{
//Console.WriteLine("After Sleep");
//THere is maybe a another character for us to read
//string line = streamy.ReadLine();
line = streamy.ReadLine();
while (line != null && line != "")
{
if (line.Contains(isLoginLine))
{
Match matchy = reg.Match(line);
Group user = matchy.Groups[1];
string username = user.Value;
return username;
}
//Console.WriteLine(line + count);
count++;
line = streamy.ReadLine();
}
Thread.Sleep(250);
} while (true);
}
public static string GetOpponent()
{
//Figure out what our opponents name is
Regex reg = new Regex(opponenetGetter);
// read from file
string line = "";
streamy = new StreamReader(fileStreamy);
do
{
//Console.WriteLine("After Sleep");
//THere is maybe a another character for us to read
line = streamy.ReadLine();
while (line != null && line != "")
{
//Console.WriteLine(line);
if (line.Contains("opponentScreenName"))
{
Match matchy = reg.Match(line);
Group user = matchy.Groups[1];
string username = user.Value;
Console.WriteLine("Opponent is:");
return username;
}
line = streamy.ReadLine();
//Console.WriteLine(line + count);
}
Thread.Sleep(250);
} while (true);
}
public static async Task GameEnded()
{
string line = "";
do
{
Thread.Sleep(250);
//Console.WriteLine("After Sleep");
//THere is maybe a another character for us to read
//string line = streamy.ReadLine();
line = streamy.ReadLine();
while (line != null && line != "")
{
if (line.Contains(gameEnded2))
{
//The game has ended
}
line = streamy.ReadLine();
//Console.WriteLine(line + count);
}
} while (true);
}
}
}