Added Request
This commit is contained in:
@@ -8,8 +8,8 @@ namespace ErgometerLibrary
|
|||||||
{
|
{
|
||||||
public class NetCommand
|
public class NetCommand
|
||||||
{
|
{
|
||||||
public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST };
|
public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST }
|
||||||
public enum RequestType { USERS}
|
public enum RequestType { USERS }
|
||||||
public enum ResponseType { LOGINOK, LOGINWRONG, ERROR, NOTLOGGEDIN }
|
public enum ResponseType { LOGINOK, LOGINWRONG, ERROR, NOTLOGGEDIN }
|
||||||
public enum ValueType { TIME, POWER, ENERGY, DISTANCE }
|
public enum ValueType { TIME, POWER, ENERGY, DISTANCE }
|
||||||
|
|
||||||
@@ -44,6 +44,15 @@ namespace ErgometerLibrary
|
|||||||
Response = response;
|
Response = response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//REQUEST
|
||||||
|
public NetCommand(RequestType request, int session)
|
||||||
|
{
|
||||||
|
Type = CommandType.REQUEST;
|
||||||
|
Session = session;
|
||||||
|
Timestamp = Helper.Now;
|
||||||
|
Request = request;
|
||||||
|
}
|
||||||
|
|
||||||
//STANDARD
|
//STANDARD
|
||||||
public NetCommand(CommandType commandtype, int session)
|
public NetCommand(CommandType commandtype, int session)
|
||||||
{
|
{
|
||||||
@@ -138,11 +147,27 @@ namespace ErgometerLibrary
|
|||||||
return ParseValue(session, args);
|
return ParseValue(session, args);
|
||||||
case 8:
|
case 8:
|
||||||
return ParseUsers(session, args);
|
return ParseUsers(session, args);
|
||||||
|
case 9:
|
||||||
|
return ParseRequest(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 ParseRequest(int session, string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length != 1)
|
||||||
|
throw new MissingFieldException("Error in NetCommand: Request is missing arguments");
|
||||||
|
|
||||||
|
switch (args[0])
|
||||||
|
{
|
||||||
|
case "users":
|
||||||
|
return new NetCommand(ResponseType.LOGINOK, session);
|
||||||
|
default:
|
||||||
|
throw new FormatException("Error in NetCommand: Request type not recognised");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static NetCommand ParseUsers(int session, string[] args)
|
private static NetCommand ParseUsers(int session, string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length < 2)
|
if (args.Length < 2)
|
||||||
@@ -287,6 +312,9 @@ namespace ErgometerLibrary
|
|||||||
command += "»" + keys.Key + "|" + keys.Value;
|
command += "»" + keys.Key + "|" + keys.Value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CommandType.REQUEST:
|
||||||
|
command += "9»ses" + Session + "»" + Request.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");
|
||||||
|
|||||||
Reference in New Issue
Block a user