diff --git a/ErgometerLibrary/FileHandler.cs b/ErgometerLibrary/FileHandler.cs index f0c1450..90df8f6 100644 --- a/ErgometerLibrary/FileHandler.cs +++ b/ErgometerLibrary/FileHandler.cs @@ -22,7 +22,7 @@ namespace ErgometerLibrary using (Stream stream = File.Open(UsersFile, FileMode.Create)) { BinaryWriter writer = new BinaryWriter(stream); - writer.Write(0); + writer.Write(1); writer.Write("doctor"); writer.Write("password"); } diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index 34cd778..7617399 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -8,8 +8,8 @@ namespace ErgometerLibrary { public class NetCommand { - public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION }; - + public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, RESPONSE }; + public enum ResponseType { LOGINOK, LOGINWRONG, ERROR, NOTLOGGEDIN } public double Timestamp { get; set; } public int Session { get; set; } @@ -19,6 +19,7 @@ namespace ErgometerLibrary public string Password { get; set; } public string ChatMessage { get; set; } public Meting Meting { get; set; } + public ResponseType Response { get; set; } public NetCommand(int session) { @@ -27,6 +28,14 @@ namespace ErgometerLibrary Timestamp = Helper.Now; } + public NetCommand(ResponseType response, int session) + { + Type = CommandType.RESPONSE; + Session = session; + Timestamp = Helper.Now; + Response = response; + } + public NetCommand(CommandType commandtype, int session) { Type = commandtype; @@ -94,11 +103,31 @@ namespace ErgometerLibrary return ParseLogoutRequest(session, args); case 5: return ParseSession(session); + case 6: + return ParseResponse(session, args); default: throw new FormatException("Error in NetCommand: " + comType + " is not a valid command type."); } } + private static NetCommand ParseResponse(int session, string[] args) + { + if (args.Length != 1) + throw new MissingFieldException("Error in NetCommand: Response is missing arguments"); + + switch(args[0]) + { + case "loginok": + return new NetCommand(ResponseType.LOGINOK, session); + case "loginwrong": + return new NetCommand(ResponseType.LOGINWRONG, session); + case "notloggedin": + return new NetCommand(ResponseType.NOTLOGGEDIN, session); + default: + throw new FormatException("Error in NetCommand: Response type not recognised"); + } + } + private static NetCommand ParseSession(int session) { NetCommand temp = new NetCommand(CommandType.SESSION, session); @@ -174,6 +203,9 @@ namespace ErgometerLibrary case CommandType.SESSION: command += "5»ses" + Session; break; + case CommandType.RESPONSE: + command += "6»ses" + Session + "»" + Response.ToString().ToLower(); + break; default: throw new FormatException("Error in NetCommand: Cannot find type of command"); diff --git a/ErgometerLibrary/Properties/AssemblyInfo.cs b/ErgometerLibrary/Properties/AssemblyInfo.cs index f1aff4e..c2e2538 100644 --- a/ErgometerLibrary/Properties/AssemblyInfo.cs +++ b/ErgometerLibrary/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.2.5")] -[assembly: AssemblyFileVersion("1.0.2.5")] +[assembly: AssemblyVersion("1.0.2.6")] +[assembly: AssemblyFileVersion("1.0.2.6")]