public static String2Bytes ( string s ) : byte[] | ||
s | string | |
return | byte[] |
private EBattlEyeCommandResult SendAcknowledgePacket(string command) { try { if (!_socket.Connected) { return(EBattlEyeCommandResult.NotConnected); } var crc32 = new CRC32(); string packet; string header = "BE"; string hash = crc32.ComputeHash(Helpers.String2Bytes(Helpers.Hex2Ascii("FF02") + command)).Aggregate <byte, string>(null, (current, b) => current + b.ToString( "X2")); hash = Helpers.Hex2Ascii(hash); hash = new string(hash.ToCharArray().Reverse().ToArray()); header += hash; packet = header + Helpers.Hex2Ascii("FF02") + command; _socket.Send(Helpers.String2Bytes(packet)); _commandSend = DateTime.Now; } catch { return(EBattlEyeCommandResult.Error); } return(EBattlEyeCommandResult.Success); }
private byte[] ConstructPacket(BattlEyePacketType packetType, int sequenceNumber, string command) { string type; switch (packetType) { case BattlEyePacketType.Login: type = Helpers.Hex2Ascii("FF00"); break; case BattlEyePacketType.Command: type = Helpers.Hex2Ascii("FF01"); break; case BattlEyePacketType.Acknowledge: type = Helpers.Hex2Ascii("FF02"); break; default: return(new byte[] { }); } if (packetType != BattlEyePacketType.Acknowledge) { if (command != null) { command = Encoding.GetEncoding(1252).GetString(Encoding.UTF8.GetBytes(command)); } } string count = Helpers.Bytes2String(new byte[] { (byte)sequenceNumber }); byte[] byteArray = new CRC32().ComputeHash(Helpers.String2Bytes(type + ((packetType != BattlEyePacketType.Command) ? "" : count) + command)); string hash = new string(Helpers.Hex2Ascii(BitConverter.ToString(byteArray).Replace("-", "")).ToCharArray().Reverse().ToArray()); string packet = "BE" + hash + type + ((packetType != BattlEyePacketType.Command) ? "" : count) + command; return(Helpers.String2Bytes(packet)); }
public EBattlEyeCommandResult SendCommandPacket(EBattlEyeCommand command, string parameters) { try { if (!_socket.Connected) { return(EBattlEyeCommandResult.NotConnected); } var crc32 = new CRC32(); string packet; string header = "BE"; string hash = crc32.ComputeHash( Helpers.String2Bytes(Helpers.Hex2Ascii("FF01") + Helpers.Bytes2String(new byte[] { 0 }) + Helpers.StringValueOf(command) + parameters)).Aggregate <byte, string>(null, (current, b) => current + b.ToString( "X2")); hash = Helpers.Hex2Ascii(hash); hash = new string(hash.ToCharArray().Reverse().ToArray()); header += hash; packet = header + Helpers.Hex2Ascii("FF01") + Helpers.Bytes2String(new byte[] { 0 }) + Helpers.StringValueOf(command) + parameters; _socket.Send(Helpers.String2Bytes(packet)); _commandSend = DateTime.Now; } catch { return(EBattlEyeCommandResult.Error); } return(EBattlEyeCommandResult.Success); }