forked from WNP78/SR2Logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.ps1
39 lines (34 loc) · 1.36 KB
/
receiver.ps1
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
$LogPort = 2873;
Function Read([byte[]]$data) {
$stream = [System.IO.MemoryStream]::new($data)
$reader = [System.IO.BinaryReader]::new($stream)
$script:outstr = ""
do {
[int]$length = $reader.ReadUInt16();
[byte[]]$name = @($null)*$length;
$reader.Read($name,0,$length) | Out-Null;
$script:outstr += "$([System.Text.Encoding]::Default.GetString($name)) = ";
[int]$type = $reader.ReadByte();
switch ($type) {
0 { $script:outstr += "null`n"; }
1 { $script:outstr += "$($reader.ReadDouble())`n"; }
2 { $script:outstr += "$($reader.ReadBoolean())`n"; }
3 { $script:outstr += "($($reader.ReadDouble()),$($reader.ReadDouble()),$($reader.ReadDouble()))`n"; }
default { $script:outstr += "Unknown type`n"; }
}
} while ($stream.Position -lt $stream.Length)
$reader.Dispose();
$stream.Dispose();
}
If ($script:cli) { $script:cli.Dispose(); }
[System.Net.Sockets.UdpClient]$script:cli = [System.Net.Sockets.UdpClient]::new($LogPort);
If ($ep) { $ep = $null; }
$ep = [System.Net.IPEndPoint]::new([System.Net.IPAddress]::Any,$LogPort);
do {
If ($script:cli.Available -gt 0) {
Read($script:cli.Receive([ref]$ep))
cls
Write-Output $script:outStr ;
}
} while ($true)
$script:cli.Dispose(); $ep = $null;