Login to server.
Receive data: sessions, users..
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ErgometerDoctorApplication
|
||||
{
|
||||
class ClientThread
|
||||
{
|
||||
public int Session { get; }
|
||||
public string Name { get; }
|
||||
|
||||
public ClientThread(string name, int session)
|
||||
{
|
||||
Name = name;
|
||||
Session = session;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ namespace ErgometerDoctorApplication
|
||||
|
||||
public ConActiveSessions() : base()
|
||||
{
|
||||
this.labelActiveSessions = new System.Windows.Forms.Label();
|
||||
//
|
||||
// ConActiveSessions
|
||||
//
|
||||
@@ -20,7 +21,19 @@ namespace ErgometerDoctorApplication
|
||||
this.Name = "ConActiveSessions";
|
||||
this.Size = new System.Drawing.Size(584, 459);
|
||||
this.TabIndex = 0;
|
||||
|
||||
//
|
||||
// labelPassword
|
||||
//
|
||||
this.labelActiveSessions.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.labelActiveSessions.AutoSize = true;
|
||||
this.labelActiveSessions.Font = new System.Drawing.Font("Segoe UI Semibold", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.labelActiveSessions.Location = new System.Drawing.Point(0, 0);
|
||||
this.labelActiveSessions.Name = "labelActiveSessions";
|
||||
this.labelActiveSessions.Size = new System.Drawing.Size(103, 21);
|
||||
this.labelActiveSessions.TabIndex = 3;
|
||||
this.labelActiveSessions.Text = "Geen actieve sessies.";
|
||||
}
|
||||
|
||||
public System.Windows.Forms.Label labelActiveSessions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,13 @@ namespace ErgometerDoctorApplication
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.buttonLogin = new System.Windows.Forms.Button();
|
||||
this.labelPassword = new System.Windows.Forms.Label();
|
||||
this.labelLoginInfo = new System.Windows.Forms.Label();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
//
|
||||
// Container
|
||||
//
|
||||
this.BackColor = System.Drawing.Color.White;
|
||||
this.Controls.Add(this.labelLoginInfo);
|
||||
this.Controls.Add(this.labelPassword);
|
||||
this.Controls.Add(this.buttonLogin);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
@@ -74,6 +76,18 @@ namespace ErgometerDoctorApplication
|
||||
this.labelPassword.Size = new System.Drawing.Size(103, 21);
|
||||
this.labelPassword.TabIndex = 3;
|
||||
this.labelPassword.Text = "Wachtwoord";
|
||||
//
|
||||
// labelLoginInfo
|
||||
//
|
||||
this.labelLoginInfo.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.labelLoginInfo.AutoSize = true;
|
||||
this.labelLoginInfo.Font = new System.Drawing.Font("Segoe UI Semibold", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.labelLoginInfo.ForeColor = System.Drawing.Color.Red;
|
||||
this.labelLoginInfo.Location = new System.Drawing.Point(11, 140);
|
||||
this.labelLoginInfo.Name = "labelLoginInfo";
|
||||
this.labelLoginInfo.Size = new System.Drawing.Size(103, 21);
|
||||
this.labelLoginInfo.TabIndex = 4;
|
||||
this.labelLoginInfo.Text = "";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
|
||||
}
|
||||
@@ -86,6 +100,7 @@ namespace ErgometerDoctorApplication
|
||||
private PictureBox pictureBox1;
|
||||
private System.Windows.Forms.Button buttonLogin;
|
||||
private System.Windows.Forms.Label labelPassword;
|
||||
public System.Windows.Forms.Label labelLoginInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,8 +33,9 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ErgometerLibrary">
|
||||
<HintPath>..\..\ErgometerLibrary\ErgometerLibrary\obj\Debug\ErgometerLibrary.dll</HintPath>
|
||||
<Reference Include="ErgometerLibrary, Version=1.0.2.8, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\ErgometerLibrary\ErgometerLibrary\ErgometerLibrary\bin\Debug\ErgometerLibrary.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -49,6 +50,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ClientThread.cs" />
|
||||
<Compile Include="SessionWindow.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -14,23 +14,35 @@ namespace ErgometerDoctorApplication
|
||||
|
||||
public static TcpClient Server { get; }
|
||||
|
||||
public static bool Loggedin;
|
||||
public static bool loggedin;
|
||||
|
||||
private static Thread t;
|
||||
private static bool running;
|
||||
|
||||
private static int Session;
|
||||
public static int Session;
|
||||
|
||||
public static string HOST = "127.0.0.1";
|
||||
public static int PORT = 8888;
|
||||
|
||||
|
||||
//Server information
|
||||
public static List<ClientThread> clients;
|
||||
public static Dictionary<string, string> users;
|
||||
public static List<int> oldsessions;
|
||||
public static Dictionary<int, string> activesessions;
|
||||
|
||||
static MainClient()
|
||||
{
|
||||
Server = new TcpClient();
|
||||
|
||||
t = new Thread(run);
|
||||
|
||||
Loggedin = false;
|
||||
loggedin = false;
|
||||
|
||||
clients = new List<ClientThread>();
|
||||
users = new Dictionary<string, string>();
|
||||
oldsessions = new List<int>();
|
||||
activesessions = new Dictionary<int, string>();
|
||||
}
|
||||
|
||||
public static bool Connect(string password)
|
||||
@@ -49,7 +61,7 @@ namespace ErgometerDoctorApplication
|
||||
t.Start();
|
||||
}
|
||||
|
||||
if (!Loggedin)
|
||||
if (!loggedin)
|
||||
{
|
||||
NetCommand command = new NetCommand("Doctor0tVfW", true, password, Session);
|
||||
NetHelper.SendNetCommand(Server, command);
|
||||
@@ -57,11 +69,11 @@ namespace ErgometerDoctorApplication
|
||||
NetCommand response = NetHelper.ReadNetCommand(Server);
|
||||
if (response.Type == NetCommand.CommandType.RESPONSE && response.Response == NetCommand.ResponseType.LOGINWRONG)
|
||||
{
|
||||
Loggedin = false;
|
||||
loggedin = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
Loggedin = true;
|
||||
loggedin = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -73,9 +85,8 @@ namespace ErgometerDoctorApplication
|
||||
if (Server.Connected)
|
||||
{
|
||||
NetHelper.SendNetCommand(Server, new NetCommand(NetCommand.CommandType.LOGOUT, Session));
|
||||
Loggedin = false;
|
||||
Server.Close();
|
||||
running = false;
|
||||
loggedin = false;
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,14 +97,68 @@ namespace ErgometerDoctorApplication
|
||||
if (Server.Connected && Server.Available > 0)
|
||||
{
|
||||
NetCommand command = NetHelper.ReadNetCommand(Server);
|
||||
HandToClient(command);
|
||||
switch(command.Type)
|
||||
{
|
||||
case NetCommand.CommandType.LENGTH:
|
||||
switch(command.Length)
|
||||
{
|
||||
case NetCommand.LengthType.USERS:
|
||||
users.Clear();
|
||||
for(int i=0; i<command.LengthValue; i++)
|
||||
{
|
||||
NetCommand c = NetHelper.ReadNetCommand(Server);
|
||||
if(c.Type == NetCommand.CommandType.USER)
|
||||
{
|
||||
users.Add(c.DisplayName, c.Password);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NetCommand.LengthType.SESSIONS:
|
||||
oldsessions.Clear();
|
||||
for (int i = 0; i < command.LengthValue; i++)
|
||||
{
|
||||
NetCommand c = NetHelper.ReadNetCommand(Server);
|
||||
if (c.Type == NetCommand.CommandType.SESSION)
|
||||
{
|
||||
oldsessions.Add(c.Session);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NetCommand.LengthType.SESSIONDATA:
|
||||
activesessions.Clear();
|
||||
for (int i = 0; i < command.LengthValue; i++)
|
||||
{
|
||||
NetCommand c = NetHelper.ReadNetCommand(Server);
|
||||
if (c.Type == NetCommand.CommandType.SESSIONDATA)
|
||||
{
|
||||
activesessions.Add(c.Session, c.DisplayName);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new FormatException("Error in NetCommand: Length type is not recognised");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
HandToClient(command);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Server.Close();
|
||||
}
|
||||
|
||||
private static void HandToClient(NetCommand command)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//throw new NotImplementedException();
|
||||
Console.WriteLine(command);
|
||||
}
|
||||
|
||||
public static void SendNetCommand(NetCommand command)
|
||||
{
|
||||
NetHelper.SendNetCommand(Server, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using ErgometerLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@@ -20,8 +21,17 @@ namespace ErgometerDoctorApplication
|
||||
|
||||
private void BtnActiveSessions_Click(object sender, EventArgs e)
|
||||
{
|
||||
MainClient.SendNetCommand(new NetCommand(NetCommand.RequestType.SESSIONDATA, MainClient.Session));
|
||||
this.HeaderLabel.Text = "Actieve Sessies";
|
||||
conActiveSessions.BringToFront();
|
||||
|
||||
string str = "";
|
||||
foreach(string name in MainClient.activesessions.Values)
|
||||
{
|
||||
str += name + ", ";
|
||||
}
|
||||
conActiveSessions.labelActiveSessions.Text = str;
|
||||
Console.WriteLine(str);
|
||||
}
|
||||
|
||||
private void BtnSessionLibrary_Click(object sender, EventArgs e)
|
||||
@@ -43,13 +53,22 @@ namespace ErgometerDoctorApplication
|
||||
}
|
||||
public void validateLogin()
|
||||
{
|
||||
//enter login details
|
||||
showDashboard();
|
||||
if (MainClient.Connect(conPanelLogin.textBoxPassword.Text))
|
||||
{
|
||||
conPanelLogin.textBoxPassword.Text = "";
|
||||
conPanelLogin.labelLoginInfo.Text = "";
|
||||
showDashboard();
|
||||
}
|
||||
else
|
||||
{
|
||||
conPanelLogin.labelLoginInfo.Text = "Password incorrect";
|
||||
showLoginScreen();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonLogout_Click(object sender, EventArgs e)
|
||||
{
|
||||
//logout
|
||||
MainClient.Disconnect();
|
||||
showLoginScreen();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user