public BattlEyeConnectionResult Connect()
{
packetSent = DateTime.Now;
packetReceived = DateTime.Now;
sequenceNumber = 0;
currentPacket = -1;
packetQueue = new SortedDictionary<int, string[]>();
keepRunning = true;
EndPoint remoteEP = new IPEndPoint(loginCredentials.Host, loginCredentials.Port);
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.ReceiveBufferSize = Int32.MaxValue;
socket.ReceiveTimeout = 5000;
try
{
socket.Connect(remoteEP);
if (SendLoginPacket(loginCredentials.Password) == BattlEyeCommandResult.Error)
return BattlEyeConnectionResult.ConnectionFailed;
var bytesReceived = new Byte[4096];
int bytes = 0;
bytes = socket.Receive(bytesReceived, bytesReceived.Length, 0);
if (bytesReceived[7] == 0x00)
{
if (bytesReceived[8] == 0x01)
{
OnConnect(loginCredentials, BattlEyeConnectionResult.Success);
Receive();
}
else
{
OnConnect(loginCredentials, BattlEyeConnectionResult.InvalidLogin);
return BattlEyeConnectionResult.InvalidLogin;
}
}
}
catch
{
if (disconnectionType == BattlEyeDisconnectionType.ConnectionLost)
{
Disconnect(BattlEyeDisconnectionType.ConnectionLost);
Connect();
return BattlEyeConnectionResult.ConnectionFailed;
}
else
{
OnConnect(loginCredentials, BattlEyeConnectionResult.ConnectionFailed);
return BattlEyeConnectionResult.ConnectionFailed;
}
}
return BattlEyeConnectionResult.Success;
}