From 22e773d25a863fe5b962251334b3569257f01727 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Tue, 13 Oct 2015 22:05:27 +0200 Subject: [PATCH] Login to server. Receive data: sessions, users.. --- ErgometerDoctorApplication/ClientThread.cs | 21 +++++ .../ConActiveSessions.cs | 15 +++- ErgometerDoctorApplication/ConPanelLogin.cs | 15 ++++ .../ErgometerDoctorApplication.csproj | 6 +- ErgometerDoctorApplication/MainClient.cs | 87 ++++++++++++++++--- ErgometerDoctorApplication/MainWindow.cs | 27 +++++- 6 files changed, 153 insertions(+), 18 deletions(-) create mode 100644 ErgometerDoctorApplication/ClientThread.cs diff --git a/ErgometerDoctorApplication/ClientThread.cs b/ErgometerDoctorApplication/ClientThread.cs new file mode 100644 index 0000000..418043d --- /dev/null +++ b/ErgometerDoctorApplication/ClientThread.cs @@ -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; + } + + } +} diff --git a/ErgometerDoctorApplication/ConActiveSessions.cs b/ErgometerDoctorApplication/ConActiveSessions.cs index 254f483..90315a8 100644 --- a/ErgometerDoctorApplication/ConActiveSessions.cs +++ b/ErgometerDoctorApplication/ConActiveSessions.cs @@ -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; } } diff --git a/ErgometerDoctorApplication/ConPanelLogin.cs b/ErgometerDoctorApplication/ConPanelLogin.cs index cac3072..89b6fe4 100644 --- a/ErgometerDoctorApplication/ConPanelLogin.cs +++ b/ErgometerDoctorApplication/ConPanelLogin.cs @@ -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; } } diff --git a/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj b/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj index 3a9200e..9ac41c0 100644 --- a/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj +++ b/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj @@ -33,8 +33,9 @@ 4 - - ..\..\ErgometerLibrary\ErgometerLibrary\obj\Debug\ErgometerLibrary.dll + + False + ..\..\..\ErgometerLibrary\ErgometerLibrary\ErgometerLibrary\bin\Debug\ErgometerLibrary.dll @@ -49,6 +50,7 @@ + Form diff --git a/ErgometerDoctorApplication/MainClient.cs b/ErgometerDoctorApplication/MainClient.cs index 0f4b5d0..45d7e5e 100644 --- a/ErgometerDoctorApplication/MainClient.cs +++ b/ErgometerDoctorApplication/MainClient.cs @@ -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 clients; + public static Dictionary users; + public static List oldsessions; + public static Dictionary activesessions; + static MainClient() { Server = new TcpClient(); t = new Thread(run); - Loggedin = false; + loggedin = false; + + clients = new List(); + users = new Dictionary(); + oldsessions = new List(); + activesessions = new Dictionary(); } 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