some optimizations

This commit is contained in:
Alexander Eckart committed 2013-05-05 11:23:55 +02:00
1 parent b959c5ff8a
commit 80b54cad25
7 files changed
+33 -38

No files matched your search

+1 -1
View File
@@ -115,7 +115,7 @@ namespace ClientServerLib
connected = true; connected = true;
RaiseOnConnectionChanged(); RaiseOnConnectionChanged();
} }
catch (Exception e) catch
{ {
connected = false; connected = false;
RaiseOnConnectionChanged(); RaiseOnConnectionChanged();
@@ -71,7 +71,7 @@ namespace ClientServerLib
if (Data == null || !keySet) if (Data == null || !keySet)
return Data; return Data;
using (Aes aes = Aes.Create()) using (Aes aes = new AesManaged())
{ {
aes.Key = dh.Key; aes.Key = dh.Key;
aes.GenerateIV(); aes.GenerateIV();
@@ -117,7 +117,7 @@ namespace ClientServerLib
Array.Copy(Data, 4, IV, 0, 16); Array.Copy(Data, 4, IV, 0, 16);
int dataLength = BitConverter.ToInt32(Data, 20); int dataLength = BitConverter.ToInt32(Data, 20);
using (Aes aes = Aes.Create()) using (Aes aes = new AesManaged())
{ {
aes.Key = dh.Key; aes.Key = dh.Key;
aes.IV = IV; aes.IV = IV;
@@ -6,7 +6,6 @@ using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.Text; using System.Text;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Windows.Forms;
namespace Vocaluxe.Base.Server namespace Vocaluxe.Base.Server
@@ -24,8 +23,11 @@ namespace Vocaluxe.Base.Server
public const int ResponseLoginOK = 23; public const int ResponseLoginOK = 23;
public const int CommandSendKeyEvent = 100; public const int CommandSendKeyStroke = 100;
public const int CommandSendKeyStroke = 101; public const int CommandSendKeyUp = 110;
public const int CommandSendKeyDown = 111;
public const int CommandSendKeyLeft = 112;
public const int CommandSendKeyRight = 113;
public const int CommandSendMouseMoveEvent = 200; public const int CommandSendMouseMoveEvent = 200;
public const int CommandSendMouseLBDownEvent = 220; public const int CommandSendMouseLBDownEvent = 220;
@@ -59,15 +61,7 @@ namespace Vocaluxe.Base.Server
#endregion Login #endregion Login
#region Keyboard #region Keyboard
public static byte[] CreateCommandSendKeyEvent(Keys Key)
{
return Serialize<Keys>(CommandSendKeyEvent, Key);
}
public static bool DecodeCommandSendKeyEvent(byte[] Message, out Keys Key)
{
return TryDeserialize<Keys>(Message, out Key);
}
#endregion Keyboard #endregion Keyboard
@@ -109,7 +103,7 @@ namespace Vocaluxe.Base.Server
obj = (T)formatter.Deserialize(ms); obj = (T)formatter.Deserialize(ms);
return true; return true;
} }
catch (Exception) catch (Exception e)
{ {
return false; return false;
} }
+4 -12
View File
@@ -32,14 +32,6 @@ namespace ClientTest
base.OnClosing(e); base.OnClosing(e);
} }
private void OnKeyDown(object sender, KeyEventArgs e)
{
if (!client.Connected || !loggedIn)
return;
client.SendMessage(CCommands.CreateCommandSendKeyEvent(e.KeyCode), null);
}
private void btConnect_Click(object sender, EventArgs e) private void btConnect_Click(object sender, EventArgs e)
{ {
if (!client.Connected) if (!client.Connected)
@@ -185,7 +177,7 @@ namespace ClientTest
if (!client.Connected || !loggedIn) if (!client.Connected || !loggedIn)
return; return;
client.SendMessage(CCommands.CreateCommandSendKeyEvent(Keys.Up), null); client.SendMessage(CCommands.CreateCommandWithoutParams(CCommands.CommandSendKeyUp), null);
} }
private void btLeft_Click(object sender, EventArgs e) private void btLeft_Click(object sender, EventArgs e)
@@ -193,7 +185,7 @@ namespace ClientTest
if (!client.Connected || !loggedIn) if (!client.Connected || !loggedIn)
return; return;
client.SendMessage(CCommands.CreateCommandSendKeyEvent(Keys.Left), null); client.SendMessage(CCommands.CreateCommandWithoutParams(CCommands.CommandSendKeyLeft), null);
} }
private void btDown_Click(object sender, EventArgs e) private void btDown_Click(object sender, EventArgs e)
@@ -201,7 +193,7 @@ namespace ClientTest
if (!client.Connected || !loggedIn) if (!client.Connected || !loggedIn)
return; return;
client.SendMessage(CCommands.CreateCommandSendKeyEvent(Keys.Down), null); client.SendMessage(CCommands.CreateCommandWithoutParams(CCommands.CommandSendKeyDown), null);
} }
private void brRight_Click(object sender, EventArgs e) private void brRight_Click(object sender, EventArgs e)
@@ -209,7 +201,7 @@ namespace ClientTest
if (!client.Connected || !loggedIn) if (!client.Connected || !loggedIn)
return; return;
client.SendMessage(CCommands.CreateCommandSendKeyEvent(Keys.Right), null); client.SendMessage(CCommands.CreateCommandWithoutParams(CCommands.CommandSendKeyRight), null);
} }
} }
} }
Binary file not shown.
+19 -11
View File
@@ -58,7 +58,7 @@ namespace Vocaluxe.Base.Server
} }
int command = BitConverter.ToInt32(Message, 0); int command = BitConverter.ToInt32(Message, 0);
byte[] answer = null; byte[] answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseNOK); ;
switch (command) switch (command)
{ {
@@ -84,19 +84,27 @@ namespace Vocaluxe.Base.Server
if (!loggedIn) if (!loggedIn)
return answer; return answer;
switch (command) switch (command)
{ {
case CCommands.CommandSendKeyEvent: case CCommands.CommandSendKeyUp:
Keys key; answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
if (!CCommands.DecodeCommandSendKeyEvent(Message, out key)) Controller.AddKeyEvent(new SKeyEvent(ESender.Keyboard, false, false, false, false, Char.MinValue, Keys.Up));
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseNOK); break;
else
{
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
}
Controller.AddKeyEvent(new SKeyEvent(ESender.Keyboard, false, false, false, false, Char.MinValue, key)); case CCommands.CommandSendKeyDown:
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
Controller.AddKeyEvent(new SKeyEvent(ESender.Keyboard, false, false, false, false, Char.MinValue, Keys.Down));
break;
case CCommands.CommandSendKeyLeft:
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
Controller.AddKeyEvent(new SKeyEvent(ESender.Keyboard, false, false, false, false, Char.MinValue, Keys.Left));
break;
case CCommands.CommandSendKeyRight:
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
Controller.AddKeyEvent(new SKeyEvent(ESender.Keyboard, false, false, false, false, Char.MinValue, Keys.Right));
break; break;
default: default:
+1
View File
@@ -154,6 +154,7 @@
</Reference> </Reference>
<Reference Include="ClientServerLib"> <Reference Include="ClientServerLib">
<HintPath>..\ClientServerLib\ClientServerLib\bin\ClientServerLib.dll</HintPath> <HintPath>..\ClientServerLib\ClientServerLib\bin\ClientServerLib.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="Community.CsharpSqlite"> <Reference Include="Community.CsharpSqlite">
<HintPath>..\Output\Community.CsharpSqlite.dll</HintPath> <HintPath>..\Output\Community.CsharpSqlite.dll</HintPath>