introduced controller framework, simple control test implementation
This commit is contained in:
1 parent
1147d612fe
commit
b959c5ff8a
11 files changed
+356
-113
No files matched your search
+2
-4
@@ -43,7 +43,5 @@ Output/Songs
|
||||
/ClientServerLib/ClientServerLib/bin/Debug/ClientServerLib.dll
|
||||
/ClientServerLib/ClientTest/bin/Debug/ClientServerLib.dll
|
||||
/ClientServerLib/ClientServerLib/bin/ClientServerLib.dll
|
||||
/ClientServerLib/ClientTest/bin/Debug/ClientTest.exe
|
||||
/ClientServerLib/ClientTest/bin/Debug/ClientTest.vshost.exe
|
||||
/ClientServerLib/ClientTest/bin/Release/ClientTest.vshost.exe
|
||||
/ClientServerLib/ClientTest/bin/Release/ClientTest.vshost.exe.manifest
|
||||
ClientTest.exe
|
||||
*.vshost.*
|
||||
@@ -33,6 +33,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Runtime.Serialization.Formatters;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Security.Cryptography;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
namespace Vocaluxe.Base.Server
|
||||
@@ -14,30 +15,35 @@ namespace Vocaluxe.Base.Server
|
||||
{
|
||||
public static SHA256Managed SHA256 = new SHA256Managed();
|
||||
|
||||
public const int ResponseOK = 1;
|
||||
public const int ResponseNOK = 2;
|
||||
|
||||
public const int CommandLogin = 20;
|
||||
public const int ResponseLoginWrongPassword = 21;
|
||||
public const int ResponseLoginFailed = 22;
|
||||
public const int ResponseLoginOK = 23;
|
||||
|
||||
|
||||
public const int CommandSendKeyEvent = 100;
|
||||
public const int CommandSendKeyStroke = 101;
|
||||
|
||||
public const int CommandSendMouseMoveEvent = 200;
|
||||
public const int CommandSendMouseLBDownEvent = 220;
|
||||
public const int CommandSendMouseLBUpEvent = 221;
|
||||
public const int CommandSendMouseRBDownEvent = 230;
|
||||
public const int CommandSendMouseRBUpEvent = 231;
|
||||
public const int ComamndSendMouseMBDownEvent = 240;
|
||||
public const int ComamndSendMouseMBUpEvent = 241;
|
||||
public const int CommandSendMouseWheelEvent = 250;
|
||||
|
||||
#region General
|
||||
public static byte[] CreateCommandWithoutParams(int Command)
|
||||
{
|
||||
return BitConverter.GetBytes(Command);
|
||||
}
|
||||
#endregion General
|
||||
|
||||
/*
|
||||
public static byte[] CreateResponseSendUserNames(SUsers Users)
|
||||
{
|
||||
return Serialize<SUsers>(ResponseSendUserNames, Users);
|
||||
}
|
||||
|
||||
public static SUsers DecodeResponseSendUserNames(byte[] response)
|
||||
{
|
||||
SUsers users;
|
||||
TryDeserialize<SUsers>(response, out users);
|
||||
return users;
|
||||
}
|
||||
*/
|
||||
|
||||
#region Login
|
||||
public static byte[] CreateCommandLogin(string Password)
|
||||
{
|
||||
SLoginData data = new SLoginData();
|
||||
@@ -46,11 +52,25 @@ namespace Vocaluxe.Base.Server
|
||||
return Serialize<SLoginData>(CommandLogin, data);
|
||||
}
|
||||
|
||||
public static bool ResponseCommandLogin(byte[] Message, out SLoginData LoginData)
|
||||
public static bool DecodeCommandLogin(byte[] Message, out SLoginData LoginData)
|
||||
{
|
||||
return TryDeserialize<SLoginData>(Message, out LoginData);
|
||||
}
|
||||
#endregion Login
|
||||
|
||||
#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
|
||||
|
||||
|
||||
private static byte[] Serialize<T>(int Command, T obj)
|
||||
{
|
||||
byte[] command = BitConverter.GetBytes(Command);
|
||||
|
||||
+125
-82
@@ -28,60 +28,28 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.lbServerIP = new System.Windows.Forms.Label();
|
||||
this.lbPort = new System.Windows.Forms.Label();
|
||||
this.tbServerIP = new System.Windows.Forms.TextBox();
|
||||
this.tbPort = new System.Windows.Forms.TextBox();
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this.lbConnectionStatus = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.lbConnectionStatusText = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.btConnect = new System.Windows.Forms.Button();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.tbDataSending = new System.Windows.Forms.TextBox();
|
||||
this.lbDateSending = new System.Windows.Forms.Label();
|
||||
this.lbDataReceiving = new System.Windows.Forms.Label();
|
||||
this.tbDataReceiving = new System.Windows.Forms.TextBox();
|
||||
this.lbPort = new System.Windows.Forms.Label();
|
||||
this.tbPort = new System.Windows.Forms.TextBox();
|
||||
this.tbServerIP = new System.Windows.Forms.TextBox();
|
||||
this.btConnect = new System.Windows.Forms.Button();
|
||||
this.lbServerIP = new System.Windows.Forms.Label();
|
||||
this.tbPassword = new System.Windows.Forms.TextBox();
|
||||
this.lbPassword = new System.Windows.Forms.Label();
|
||||
this.btLogin = new System.Windows.Forms.Button();
|
||||
this.btLeft = new System.Windows.Forms.Button();
|
||||
this.btRight = new System.Windows.Forms.Button();
|
||||
this.btUp = new System.Windows.Forms.Button();
|
||||
this.btDown = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.panel1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// lbServerIP
|
||||
//
|
||||
this.lbServerIP.AutoSize = true;
|
||||
this.lbServerIP.Location = new System.Drawing.Point(3, 0);
|
||||
this.lbServerIP.Name = "lbServerIP";
|
||||
this.lbServerIP.Size = new System.Drawing.Size(54, 13);
|
||||
this.lbServerIP.TabIndex = 0;
|
||||
this.lbServerIP.Text = "Server IP:";
|
||||
//
|
||||
// lbPort
|
||||
//
|
||||
this.lbPort.AutoSize = true;
|
||||
this.lbPort.Location = new System.Drawing.Point(3, 26);
|
||||
this.lbPort.Name = "lbPort";
|
||||
this.lbPort.Size = new System.Drawing.Size(29, 13);
|
||||
this.lbPort.TabIndex = 1;
|
||||
this.lbPort.Text = "Port:";
|
||||
//
|
||||
// tbServerIP
|
||||
//
|
||||
this.tbServerIP.Location = new System.Drawing.Point(85, -3);
|
||||
this.tbServerIP.Name = "tbServerIP";
|
||||
this.tbServerIP.Size = new System.Drawing.Size(86, 20);
|
||||
this.tbServerIP.TabIndex = 2;
|
||||
this.tbServerIP.Text = "127.0.0.1";
|
||||
//
|
||||
// tbPort
|
||||
//
|
||||
this.tbPort.Location = new System.Drawing.Point(85, 23);
|
||||
this.tbPort.Name = "tbPort";
|
||||
this.tbPort.Size = new System.Drawing.Size(86, 20);
|
||||
this.tbPort.TabIndex = 3;
|
||||
this.tbPort.Text = "3000";
|
||||
//
|
||||
// statusStrip1
|
||||
//
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
@@ -105,31 +73,6 @@
|
||||
this.lbConnectionStatusText.Size = new System.Drawing.Size(79, 17);
|
||||
this.lbConnectionStatusText.Text = "Disconnected";
|
||||
//
|
||||
// btConnect
|
||||
//
|
||||
this.btConnect.Location = new System.Drawing.Point(6, 49);
|
||||
this.btConnect.Name = "btConnect";
|
||||
this.btConnect.Size = new System.Drawing.Size(165, 23);
|
||||
this.btConnect.TabIndex = 5;
|
||||
this.btConnect.Text = "Connect";
|
||||
this.btConnect.UseVisualStyleBackColor = true;
|
||||
this.btConnect.Click += new System.EventHandler(this.btConnect_Click);
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.btLogin);
|
||||
this.panel1.Controls.Add(this.lbPassword);
|
||||
this.panel1.Controls.Add(this.tbPassword);
|
||||
this.panel1.Controls.Add(this.lbServerIP);
|
||||
this.panel1.Controls.Add(this.btConnect);
|
||||
this.panel1.Controls.Add(this.tbServerIP);
|
||||
this.panel1.Controls.Add(this.tbPort);
|
||||
this.panel1.Controls.Add(this.lbPort);
|
||||
this.panel1.Location = new System.Drawing.Point(822, 12);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(174, 513);
|
||||
this.panel1.TabIndex = 6;
|
||||
//
|
||||
// tbDataSending
|
||||
//
|
||||
this.tbDataSending.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
@@ -137,7 +80,7 @@
|
||||
this.tbDataSending.Location = new System.Drawing.Point(12, 25);
|
||||
this.tbDataSending.Multiline = true;
|
||||
this.tbDataSending.Name = "tbDataSending";
|
||||
this.tbDataSending.Size = new System.Drawing.Size(804, 120);
|
||||
this.tbDataSending.Size = new System.Drawing.Size(810, 120);
|
||||
this.tbDataSending.TabIndex = 7;
|
||||
//
|
||||
// lbDateSending
|
||||
@@ -165,12 +108,56 @@
|
||||
this.tbDataReceiving.Location = new System.Drawing.Point(12, 213);
|
||||
this.tbDataReceiving.Multiline = true;
|
||||
this.tbDataReceiving.Name = "tbDataReceiving";
|
||||
this.tbDataReceiving.Size = new System.Drawing.Size(804, 120);
|
||||
this.tbDataReceiving.Size = new System.Drawing.Size(810, 120);
|
||||
this.tbDataReceiving.TabIndex = 9;
|
||||
//
|
||||
// lbPort
|
||||
//
|
||||
this.lbPort.AutoSize = true;
|
||||
this.lbPort.Location = new System.Drawing.Point(828, 41);
|
||||
this.lbPort.Name = "lbPort";
|
||||
this.lbPort.Size = new System.Drawing.Size(29, 13);
|
||||
this.lbPort.TabIndex = 1;
|
||||
this.lbPort.Text = "Port:";
|
||||
//
|
||||
// tbPort
|
||||
//
|
||||
this.tbPort.Location = new System.Drawing.Point(910, 38);
|
||||
this.tbPort.Name = "tbPort";
|
||||
this.tbPort.Size = new System.Drawing.Size(86, 20);
|
||||
this.tbPort.TabIndex = 3;
|
||||
this.tbPort.Text = "3000";
|
||||
//
|
||||
// tbServerIP
|
||||
//
|
||||
this.tbServerIP.Location = new System.Drawing.Point(910, 12);
|
||||
this.tbServerIP.Name = "tbServerIP";
|
||||
this.tbServerIP.Size = new System.Drawing.Size(86, 20);
|
||||
this.tbServerIP.TabIndex = 2;
|
||||
this.tbServerIP.Text = "127.0.0.1";
|
||||
//
|
||||
// btConnect
|
||||
//
|
||||
this.btConnect.Location = new System.Drawing.Point(831, 64);
|
||||
this.btConnect.Name = "btConnect";
|
||||
this.btConnect.Size = new System.Drawing.Size(165, 23);
|
||||
this.btConnect.TabIndex = 5;
|
||||
this.btConnect.Text = "Connect";
|
||||
this.btConnect.UseVisualStyleBackColor = true;
|
||||
this.btConnect.Click += new System.EventHandler(this.btConnect_Click);
|
||||
//
|
||||
// lbServerIP
|
||||
//
|
||||
this.lbServerIP.AutoSize = true;
|
||||
this.lbServerIP.Location = new System.Drawing.Point(828, 15);
|
||||
this.lbServerIP.Name = "lbServerIP";
|
||||
this.lbServerIP.Size = new System.Drawing.Size(54, 13);
|
||||
this.lbServerIP.TabIndex = 0;
|
||||
this.lbServerIP.Text = "Server IP:";
|
||||
//
|
||||
// tbPassword
|
||||
//
|
||||
this.tbPassword.Location = new System.Drawing.Point(85, 113);
|
||||
this.tbPassword.Location = new System.Drawing.Point(910, 128);
|
||||
this.tbPassword.Name = "tbPassword";
|
||||
this.tbPassword.Size = new System.Drawing.Size(86, 20);
|
||||
this.tbPassword.TabIndex = 6;
|
||||
@@ -179,7 +166,7 @@
|
||||
// lbPassword
|
||||
//
|
||||
this.lbPassword.AutoSize = true;
|
||||
this.lbPassword.Location = new System.Drawing.Point(3, 116);
|
||||
this.lbPassword.Location = new System.Drawing.Point(828, 131);
|
||||
this.lbPassword.Name = "lbPassword";
|
||||
this.lbPassword.Size = new System.Drawing.Size(56, 13);
|
||||
this.lbPassword.TabIndex = 7;
|
||||
@@ -188,7 +175,7 @@
|
||||
// btLogin
|
||||
//
|
||||
this.btLogin.Enabled = false;
|
||||
this.btLogin.Location = new System.Drawing.Point(6, 139);
|
||||
this.btLogin.Location = new System.Drawing.Point(831, 154);
|
||||
this.btLogin.Name = "btLogin";
|
||||
this.btLogin.Size = new System.Drawing.Size(165, 23);
|
||||
this.btLogin.TabIndex = 8;
|
||||
@@ -196,23 +183,76 @@
|
||||
this.btLogin.UseVisualStyleBackColor = true;
|
||||
this.btLogin.Click += new System.EventHandler(this.btLogin_Click);
|
||||
//
|
||||
// btLeft
|
||||
//
|
||||
this.btLeft.Enabled = false;
|
||||
this.btLeft.Location = new System.Drawing.Point(831, 238);
|
||||
this.btLeft.Name = "btLeft";
|
||||
this.btLeft.Size = new System.Drawing.Size(69, 23);
|
||||
this.btLeft.TabIndex = 10;
|
||||
this.btLeft.Text = "Left";
|
||||
this.btLeft.UseVisualStyleBackColor = true;
|
||||
this.btLeft.Click += new System.EventHandler(this.btLeft_Click);
|
||||
//
|
||||
// btRight
|
||||
//
|
||||
this.btRight.Enabled = false;
|
||||
this.btRight.Location = new System.Drawing.Point(927, 238);
|
||||
this.btRight.Name = "btRight";
|
||||
this.btRight.Size = new System.Drawing.Size(69, 23);
|
||||
this.btRight.TabIndex = 11;
|
||||
this.btRight.Text = "Right";
|
||||
this.btRight.UseVisualStyleBackColor = true;
|
||||
this.btRight.Click += new System.EventHandler(this.brRight_Click);
|
||||
//
|
||||
// btUp
|
||||
//
|
||||
this.btUp.Enabled = false;
|
||||
this.btUp.Location = new System.Drawing.Point(877, 209);
|
||||
this.btUp.Name = "btUp";
|
||||
this.btUp.Size = new System.Drawing.Size(69, 23);
|
||||
this.btUp.TabIndex = 12;
|
||||
this.btUp.Text = "Up";
|
||||
this.btUp.UseVisualStyleBackColor = true;
|
||||
this.btUp.Click += new System.EventHandler(this.btUp_Click);
|
||||
//
|
||||
// btDown
|
||||
//
|
||||
this.btDown.Enabled = false;
|
||||
this.btDown.Location = new System.Drawing.Point(877, 267);
|
||||
this.btDown.Name = "btDown";
|
||||
this.btDown.Size = new System.Drawing.Size(69, 23);
|
||||
this.btDown.TabIndex = 13;
|
||||
this.btDown.Text = "Down";
|
||||
this.btDown.UseVisualStyleBackColor = true;
|
||||
this.btDown.Click += new System.EventHandler(this.btDown_Click);
|
||||
//
|
||||
// ClientTest
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1008, 550);
|
||||
this.Controls.Add(this.btDown);
|
||||
this.Controls.Add(this.btUp);
|
||||
this.Controls.Add(this.btRight);
|
||||
this.Controls.Add(this.btLeft);
|
||||
this.Controls.Add(this.btLogin);
|
||||
this.Controls.Add(this.tbDataReceiving);
|
||||
this.Controls.Add(this.lbPassword);
|
||||
this.Controls.Add(this.lbDataReceiving);
|
||||
this.Controls.Add(this.tbPassword);
|
||||
this.Controls.Add(this.lbDateSending);
|
||||
this.Controls.Add(this.lbServerIP);
|
||||
this.Controls.Add(this.tbDataSending);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.btConnect);
|
||||
this.Controls.Add(this.tbServerIP);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Controls.Add(this.tbPort);
|
||||
this.Controls.Add(this.lbPort);
|
||||
this.Name = "ClientTest";
|
||||
this.Text = "ClientTest";
|
||||
this.statusStrip1.ResumeLayout(false);
|
||||
this.statusStrip1.PerformLayout();
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@@ -220,22 +260,25 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Label lbServerIP;
|
||||
private System.Windows.Forms.Label lbPort;
|
||||
private System.Windows.Forms.TextBox tbServerIP;
|
||||
private System.Windows.Forms.TextBox tbPort;
|
||||
private System.Windows.Forms.StatusStrip statusStrip1;
|
||||
private System.Windows.Forms.ToolStripStatusLabel lbConnectionStatus;
|
||||
private System.Windows.Forms.ToolStripStatusLabel lbConnectionStatusText;
|
||||
private System.Windows.Forms.Button btConnect;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.TextBox tbDataSending;
|
||||
private System.Windows.Forms.Label lbDateSending;
|
||||
private System.Windows.Forms.Label lbDataReceiving;
|
||||
private System.Windows.Forms.TextBox tbDataReceiving;
|
||||
private System.Windows.Forms.Button btLogin;
|
||||
private System.Windows.Forms.Label lbPassword;
|
||||
private System.Windows.Forms.Label lbPort;
|
||||
private System.Windows.Forms.TextBox tbPort;
|
||||
private System.Windows.Forms.TextBox tbServerIP;
|
||||
private System.Windows.Forms.Button btConnect;
|
||||
private System.Windows.Forms.Label lbServerIP;
|
||||
private System.Windows.Forms.TextBox tbPassword;
|
||||
private System.Windows.Forms.Label lbPassword;
|
||||
private System.Windows.Forms.Button btLogin;
|
||||
private System.Windows.Forms.Button btLeft;
|
||||
private System.Windows.Forms.Button btRight;
|
||||
private System.Windows.Forms.Button btUp;
|
||||
private System.Windows.Forms.Button btDown;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,14 @@ namespace ClientTest
|
||||
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)
|
||||
{
|
||||
if (!client.Connected)
|
||||
@@ -114,6 +122,10 @@ namespace ClientTest
|
||||
lbConnectionStatusText.Text = "Connected";
|
||||
btConnect.Text = "Disconnect";
|
||||
btLogin.Enabled = true;
|
||||
btUp.Enabled = true;
|
||||
btDown.Enabled = true;
|
||||
btLeft.Enabled = true;
|
||||
btRight.Enabled = true;
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -126,6 +138,10 @@ namespace ClientTest
|
||||
btLogin.Text = "Login";
|
||||
btLogin.Enabled = false;
|
||||
loggedIn = false;
|
||||
btUp.Enabled = false;
|
||||
btDown.Enabled = false;
|
||||
btLeft.Enabled = false;
|
||||
btRight.Enabled = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -163,5 +179,37 @@ namespace ClientTest
|
||||
tbDataReceiving.Text = text;
|
||||
});
|
||||
}
|
||||
|
||||
private void btUp_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!client.Connected || !loggedIn)
|
||||
return;
|
||||
|
||||
client.SendMessage(CCommands.CreateCommandSendKeyEvent(Keys.Up), null);
|
||||
}
|
||||
|
||||
private void btLeft_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!client.Connected || !loggedIn)
|
||||
return;
|
||||
|
||||
client.SendMessage(CCommands.CreateCommandSendKeyEvent(Keys.Left), null);
|
||||
}
|
||||
|
||||
private void btDown_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!client.Connected || !loggedIn)
|
||||
return;
|
||||
|
||||
client.SendMessage(CCommands.CreateCommandSendKeyEvent(Keys.Down), null);
|
||||
}
|
||||
|
||||
private void brRight_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!client.Connected || !loggedIn)
|
||||
return;
|
||||
|
||||
client.SendMessage(CCommands.CreateCommandSendKeyEvent(Keys.Right), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -20,6 +20,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Vocaluxe.Base.Server;
|
||||
using Vocaluxe.Lib.Input;
|
||||
using Vocaluxe.Lib.Input.WiiMote;
|
||||
using VocaluxeLib.Menu;
|
||||
@@ -40,6 +41,7 @@ namespace Vocaluxe.Base
|
||||
_MousePool = new List<SMouseEvent>();
|
||||
|
||||
_Controller.Add(new CWiiMote());
|
||||
_Controller.Add(CVocaluxeServer.Controller);
|
||||
|
||||
foreach (IController controller in _Controller)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Vocaluxe.Base;
|
||||
using Vocaluxe.Lib.Input;
|
||||
using VocaluxeLib.Menu;
|
||||
|
||||
namespace Vocaluxe.Base.Server
|
||||
{
|
||||
@@ -13,6 +18,7 @@ namespace Vocaluxe.Base.Server
|
||||
public CClientHandler(int ConnectionID)
|
||||
{
|
||||
this.ConnectionID = ConnectionID;
|
||||
LoggedIn = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using ClientServerLib;
|
||||
using Vocaluxe.Base;
|
||||
using Vocaluxe.Lib.Input;
|
||||
using VocaluxeLib.Menu;
|
||||
|
||||
namespace Vocaluxe.Base.Server
|
||||
@@ -13,10 +16,13 @@ namespace Vocaluxe.Base.Server
|
||||
private static CServer _Server;
|
||||
private static Dictionary<int, CClientHandler> _Clients;
|
||||
|
||||
public static CControllerFramework Controller = new CControllerFramework();
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
_Clients = new Dictionary<int, CClientHandler>();
|
||||
_Server = new CServer(RequestHandler, CConfig.ServerPort);
|
||||
Controller.Init();
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
@@ -39,6 +45,7 @@ namespace Vocaluxe.Base.Server
|
||||
if (Message.Length < 4)
|
||||
return null;
|
||||
|
||||
bool loggedIn = false;
|
||||
lock (_Clients)
|
||||
{
|
||||
if (!_Clients.ContainsKey(ConnectionID))
|
||||
@@ -46,6 +53,8 @@ namespace Vocaluxe.Base.Server
|
||||
CClientHandler client = new CClientHandler(ConnectionID);
|
||||
_Clients.Add(ConnectionID, client);
|
||||
}
|
||||
|
||||
loggedIn = _Clients[ConnectionID].LoggedIn;
|
||||
}
|
||||
|
||||
int command = BitConverter.ToInt32(Message, 0);
|
||||
@@ -56,28 +65,39 @@ namespace Vocaluxe.Base.Server
|
||||
case CCommands.CommandLogin:
|
||||
SLoginData data;
|
||||
|
||||
if (!CCommands.ResponseCommandLogin(Message, out data))
|
||||
if (!CCommands.DecodeCommandLogin(Message, out data))
|
||||
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseLoginFailed);
|
||||
else
|
||||
{
|
||||
byte[] serverPW = CCommands.SHA256.ComputeHash(Encoding.UTF8.GetBytes(CConfig.ServerPassword));
|
||||
|
||||
bool ok = true;
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if (serverPW[i] != data.SHA256[i])
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
if (!serverPW.SequenceEqual(data.SHA256))
|
||||
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseLoginWrongPassword);
|
||||
else
|
||||
{
|
||||
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseLoginOK);
|
||||
_Clients[ConnectionID].LoggedIn = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!loggedIn)
|
||||
return answer;
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case CCommands.CommandSendKeyEvent:
|
||||
Keys key;
|
||||
if (!CCommands.DecodeCommandSendKeyEvent(Message, out key))
|
||||
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseNOK);
|
||||
else
|
||||
{
|
||||
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
|
||||
}
|
||||
|
||||
Controller.AddKeyEvent(new SKeyEvent(ESender.Keyboard, false, false, false, false, Char.MinValue, key));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using VocaluxeLib.Menu;
|
||||
|
||||
namespace Vocaluxe.Lib.Input
|
||||
{
|
||||
public class CControllerFramework : IController
|
||||
{
|
||||
private List<SKeyEvent> _KeysPool;
|
||||
private List<SKeyEvent> _CurrentKeysPool;
|
||||
private readonly Object _KeyCopyLock = new Object();
|
||||
|
||||
private List<SMouseEvent> _MousePool;
|
||||
private List<SMouseEvent> _CurrentMousePool;
|
||||
private readonly Object _MouseCopyLock = new Object();
|
||||
|
||||
public virtual void Init()
|
||||
{
|
||||
_KeysPool = new List<SKeyEvent>();
|
||||
_CurrentKeysPool = new List<SKeyEvent>();
|
||||
_MousePool = new List<SMouseEvent>();
|
||||
_CurrentMousePool = new List<SMouseEvent>();
|
||||
}
|
||||
|
||||
public virtual void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Connect()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Disconnect()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual bool IsConnected()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
lock (_KeyCopyLock)
|
||||
{
|
||||
foreach (SKeyEvent e in _KeysPool)
|
||||
_CurrentKeysPool.Add(e);
|
||||
_KeysPool.Clear();
|
||||
}
|
||||
|
||||
lock (_MouseCopyLock)
|
||||
{
|
||||
foreach (SMouseEvent e in _MousePool)
|
||||
_CurrentMousePool.Add(e);
|
||||
_MousePool.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool PollKeyEvent(ref SKeyEvent keyEvent)
|
||||
{
|
||||
if (_CurrentKeysPool.Count > 0)
|
||||
{
|
||||
keyEvent = _CurrentKeysPool[0];
|
||||
_CurrentKeysPool.RemoveAt(0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool PollMouseEvent(ref SMouseEvent mouseEvent)
|
||||
{
|
||||
if (_CurrentMousePool.Count > 0)
|
||||
{
|
||||
mouseEvent = _CurrentMousePool[0];
|
||||
_CurrentMousePool.RemoveAt(0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void SetRumble(float duration)
|
||||
{
|
||||
}
|
||||
|
||||
public void AddKeyEvent(SKeyEvent keyEvent)
|
||||
{
|
||||
lock (_KeyCopyLock)
|
||||
{
|
||||
_KeysPool.Add(keyEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddMouseEvent(SMouseEvent mouseEvent)
|
||||
{
|
||||
lock (_MousePool)
|
||||
{
|
||||
_MousePool.Add(mouseEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,6 +207,7 @@
|
||||
</Compile>
|
||||
<Compile Include="GameModes\CGameMode.cs" />
|
||||
<Compile Include="GameModes\CGameModes.cs" />
|
||||
<Compile Include="Lib\Input\CControllerFramework.cs" />
|
||||
<Compile Include="SongQueue\CSongQueue.cs" />
|
||||
<Compile Include="GameModes\IGameMode.cs" />
|
||||
<Compile Include="SongQueue\ISongQueue.cs" />
|
||||
|
||||
Reference in new issue
Block a user