Added login and user management

This commit is contained in:
2015-10-08 22:41:21 +02:00
parent 69ed0a7095
commit 43bf6a1e1b
3 changed files with 37 additions and 5 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ namespace ErgometerLibrary
using (Stream stream = File.Open(UsersFile, FileMode.Create)) using (Stream stream = File.Open(UsersFile, FileMode.Create))
{ {
BinaryWriter writer = new BinaryWriter(stream); BinaryWriter writer = new BinaryWriter(stream);
writer.Write(0); writer.Write(1);
writer.Write("doctor"); writer.Write("doctor");
writer.Write("password"); writer.Write("password");
} }
+34 -2
View File
@@ -8,8 +8,8 @@ namespace ErgometerLibrary
{ {
public class NetCommand 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 double Timestamp { get; set; }
public int Session { get; set; } public int Session { get; set; }
@@ -19,6 +19,7 @@ namespace ErgometerLibrary
public string Password { get; set; } public string Password { get; set; }
public string ChatMessage { get; set; } public string ChatMessage { get; set; }
public Meting Meting { get; set; } public Meting Meting { get; set; }
public ResponseType Response { get; set; }
public NetCommand(int session) public NetCommand(int session)
{ {
@@ -27,6 +28,14 @@ namespace ErgometerLibrary
Timestamp = Helper.Now; 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) public NetCommand(CommandType commandtype, int session)
{ {
Type = commandtype; Type = commandtype;
@@ -94,11 +103,31 @@ namespace ErgometerLibrary
return ParseLogoutRequest(session, args); return ParseLogoutRequest(session, args);
case 5: case 5:
return ParseSession(session); return ParseSession(session);
case 6:
return ParseResponse(session, args);
default: default:
throw new FormatException("Error in NetCommand: " + comType + " is not a valid command type."); 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) private static NetCommand ParseSession(int session)
{ {
NetCommand temp = new NetCommand(CommandType.SESSION, session); NetCommand temp = new NetCommand(CommandType.SESSION, session);
@@ -174,6 +203,9 @@ namespace ErgometerLibrary
case CommandType.SESSION: case CommandType.SESSION:
command += "5»ses" + Session; command += "5»ses" + Session;
break; break;
case CommandType.RESPONSE:
command += "6»ses" + Session + "»" + Response.ToString().ToLower();
break;
default: default:
throw new FormatException("Error in NetCommand: Cannot find type of command"); throw new FormatException("Error in NetCommand: Cannot find type of command");
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.5")] [assembly: AssemblyVersion("1.0.2.6")]
[assembly: AssemblyFileVersion("1.0.2.5")] [assembly: AssemblyFileVersion("1.0.2.6")]