diff --git a/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj b/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj index 243dfe0..6f234aa 100644 --- a/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj +++ b/ErgometerDoctorApplication/ErgometerDoctorApplication.csproj @@ -33,6 +33,9 @@ 4 + + ..\..\..\ErgometerLibrary\ErgometerLibrary\ErgometerLibrary\bin\Debug\ErgometerLibrary.dll + @@ -61,6 +64,13 @@ Component + + Form + + + LoginWindow.cs + + Form @@ -69,6 +79,9 @@ + + LoginWindow.cs + MainWindow.cs diff --git a/ErgometerDoctorApplication/LoginWindow.Designer.cs b/ErgometerDoctorApplication/LoginWindow.Designer.cs new file mode 100644 index 0000000..21834a1 --- /dev/null +++ b/ErgometerDoctorApplication/LoginWindow.Designer.cs @@ -0,0 +1,71 @@ +namespace ErgometerDoctorApplication +{ + partial class LoginWindow + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.LoginButton = new System.Windows.Forms.Button(); + this.PasswordTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // LoginButton + // + this.LoginButton.Location = new System.Drawing.Point(197, 12); + this.LoginButton.Name = "LoginButton"; + this.LoginButton.Size = new System.Drawing.Size(75, 23); + this.LoginButton.TabIndex = 0; + this.LoginButton.Text = "Login"; + this.LoginButton.UseVisualStyleBackColor = true; + this.LoginButton.Click += new System.EventHandler(this.LoginButton_Click); + // + // PasswordTextBox + // + this.PasswordTextBox.Location = new System.Drawing.Point(13, 13); + this.PasswordTextBox.Name = "PasswordTextBox"; + this.PasswordTextBox.Size = new System.Drawing.Size(178, 20); + this.PasswordTextBox.TabIndex = 1; + // + // LoginWindow + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 53); + this.Controls.Add(this.PasswordTextBox); + this.Controls.Add(this.LoginButton); + this.Name = "LoginWindow"; + this.Text = "LoginWindow"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button LoginButton; + private System.Windows.Forms.TextBox PasswordTextBox; + } +} \ No newline at end of file diff --git a/ErgometerDoctorApplication/LoginWindow.cs b/ErgometerDoctorApplication/LoginWindow.cs new file mode 100644 index 0000000..ac16d46 --- /dev/null +++ b/ErgometerDoctorApplication/LoginWindow.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ErgometerDoctorApplication +{ + public partial class LoginWindow : Form + { + public LoginWindow() + { + InitializeComponent(); + } + + private void LoginButton_Click(object sender, EventArgs e) + { + if(MainClient.Connect(PasswordTextBox.Text)) + { + PasswordTextBox.BackColor = System.Drawing.SystemColors.Window; + Close(); + } + else + { + PasswordTextBox.BackColor = Color.Red; + } + } + } +} diff --git a/ErgometerDoctorApplication/LoginWindow.resx b/ErgometerDoctorApplication/LoginWindow.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ErgometerDoctorApplication/LoginWindow.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ErgometerDoctorApplication/MainClient.cs b/ErgometerDoctorApplication/MainClient.cs new file mode 100644 index 0000000..0f4b5d0 --- /dev/null +++ b/ErgometerDoctorApplication/MainClient.cs @@ -0,0 +1,99 @@ +using ErgometerLibrary; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace ErgometerDoctorApplication +{ + class MainClient + { + + public static TcpClient Server { get; } + + public static bool Loggedin; + + private static Thread t; + private static bool running; + + private static int Session; + + public static string HOST = "127.0.0.1"; + public static int PORT = 8888; + + static MainClient() + { + Server = new TcpClient(); + + t = new Thread(run); + + Loggedin = false; + } + + public static bool Connect(string password) + { + if (!Server.Connected) + { + Server.Connect(HOST, PORT); + + NetCommand net = NetHelper.ReadNetCommand(Server); + if (net.Type == NetCommand.CommandType.SESSION) + Session = net.Session; + else + throw new Exception("Session not assigned"); + + running = true; + t.Start(); + } + + if (!Loggedin) + { + NetCommand command = new NetCommand("Doctor0tVfW", true, password, Session); + NetHelper.SendNetCommand(Server, command); + + NetCommand response = NetHelper.ReadNetCommand(Server); + if (response.Type == NetCommand.CommandType.RESPONSE && response.Response == NetCommand.ResponseType.LOGINWRONG) + { + Loggedin = false; + return false; + } + + Loggedin = true; + } + + return true; + } + + public static void Disconnect() + { + + if (Server.Connected) + { + NetHelper.SendNetCommand(Server, new NetCommand(NetCommand.CommandType.LOGOUT, Session)); + Loggedin = false; + Server.Close(); + running = false; + } + } + + public static void run() + { + while (running) + { + if (Server.Connected && Server.Available > 0) + { + NetCommand command = NetHelper.ReadNetCommand(Server); + HandToClient(command); + } + } + } + + private static void HandToClient(NetCommand command) + { + throw new NotImplementedException(); + } + } +}