public bool RconAuth(string password) { this.rconRequestId = (new Random()).Next(); this.rconSocket.Send(new RCONAuthRequestPacket(this.rconRequestId, password)); RCONAuthResponsePacket reply = this.rconSocket.GetReply() as RCONAuthResponsePacket; return(reply.RequestId == this.rconRequestId); }
private void OnClientMessage(byte[] message) { // Read RCON message RCONPacket packet = RCONPacket.ReadData(message); // Check if packet is server response (0) or invalid // RCON auth response (-1) if (packet.ID != 0 && packet.ID != -1) return; switch (packet.Type) { case RCONPacketType.AUTH_RESPONSE: { // Read packet as AuthResponse RCONAuthResponsePacket authPacket = packet as RCONAuthResponsePacket; if (!authPacket.WasSuccessful()) { OutputFunction.Invoke("Failed to connect: incorrect password."); break; } OutputFunction.Invoke("Successfully connected!"); break; } case RCONPacketType.RESPONSE_VALUE: { if (string.IsNullOrEmpty(packet.Body)) break; OutputFunction.Invoke(packet.Body); break; } case RCONPacketType.DATA: { if (string.IsNullOrEmpty(packet.Body)) break; OutputFunction.Invoke(packet.Body); break; } default: { OutputFunction.Invoke($"Received uncaught packet of type {packet.Type}"); break; } } packet.Dispose(); }