-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCon.cs
86 lines (79 loc) · 1.96 KB
/
RCon.cs
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
using BattleNET;
using System;
namespace Whitelister
{
public class RCon
{
private BattlEyeLoginCredentials loginCredentials;
private IBattleNET b;
public void setLoginData(string host, int port, string password)
{
this.loginCredentials = new BattlEyeLoginCredentials
{
Host = host,
Port = port,
Password = password
};
}
public void connectClient()
{
this.b = new BattlEyeClient(this.loginCredentials);
this.b.MessageReceivedEvent += new BattlEyeMessageEventHandler(this.HandleMessage);
this.b.DisconnectEvent += new BattlEyeDisconnectEventHandler(this.HandleDisconnect);
this.b.ReconnectOnPacketLoss(true);
this.b.Connect();
}
public void disconnectClient()
{
this.b.SendCommandPacket(EBattlEyeCommand.Logout);
this.b.Disconnect();
}
private void HandleMessage(BattlEyeMessageEventArgs args)
{
if (args.Message != null)
{
if (args.Message.StartsWith("Player #") && args.Message.EndsWith("(unverified)"))
{
string message = args.Message;
string[] array = message.Split(new char[]
{
' '
}, 6, StringSplitOptions.RemoveEmptyEntries);
string text = array[1].Replace("#", "");
string text2 = array[2];
string text3 = array[5];
Console.WriteLine(string.Concat(new string[]
{
"#",
text,
" ",
text2,
" with GUID ",
text3,
" joined the game."
}));
}
}
}
private void HandleDisconnect(BattlEyeDisconnectEventArgs args)
{
switch (args.DisconnectionType)
{
case EBattlEyeDisconnectionType.Manual:
break;
case EBattlEyeDisconnectionType.ConnectionLost:
Console.WriteLine("Connection lost. Trying reconnect...");
break;
case EBattlEyeDisconnectionType.SocketException:
Console.WriteLine("Invalid host");
break;
case EBattlEyeDisconnectionType.LoginFailed:
Console.WriteLine("Login invalid!");
break;
default:
Console.WriteLine("Unknown error");
break;
}
}
}
}