From b75083be838e620f08ac0e812d5b2ea931d54822 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Tue, 20 Oct 2015 19:40:45 +0200 Subject: [PATCH] Added broadcast --- ErgometerLibrary/NetCommand.cs | 28 +++++++++++++++++++-- ErgometerLibrary/Properties/AssemblyInfo.cs | 4 +-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index 6bf167e..fa1a753 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -9,7 +9,7 @@ namespace ErgometerLibrary { public class NetCommand { - public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST, LENGTH, SESSIONDATA, ERROR } + public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST, LENGTH, SESSIONDATA, ERROR, BROADCAST } public enum RequestType { USERS, ALLSESSIONS, OLDDATA, SESSIONDATA, CHAT } public enum ResponseType { LOGINOK, LOGINWRONG, ERROR, NOTLOGGEDIN } public enum ValueType { TIME, POWER, ENERGY, DISTANCE } @@ -104,6 +104,16 @@ namespace ErgometerLibrary ChatMessage = chat.Replace("\n", ""); } + //BROADCAST + public NetCommand(string broadcast, int session) + { + Type = CommandType.BROADCAST; + Session = session; + Timestamp = Helper.Now; + + ChatMessage = broadcast.Replace("\n", ""); + } + //SETVALUE public NetCommand(ValueType value, int val, int session) { @@ -184,11 +194,23 @@ namespace ErgometerLibrary return ParseLength(session, args); case 11: return ParseSessionData(session, args); + case 12: + return ParseBroadcast(session, args); default: throw new FormatException("Error in NetCommand: " + comType + " is not a valid command type."); } } + private static NetCommand ParseBroadcast(int session, string[] args) + { + if (args.Length != 1) + throw new MissingFieldException("Error in NetCommand: Broadcast Message is missing arguments"); + + NetCommand temp = new NetCommand(args[0], session); + + return temp; + } + private static NetCommand ParseSessionData(int session, string[] args) { if (args.Length != 2) @@ -384,7 +406,9 @@ namespace ErgometerLibrary break; case CommandType.SESSIONDATA: command += "11»ses" + Session + "»" + DisplayName + "»" + Timestamp; - Console.WriteLine("Lib: " + command); + break; + case CommandType.BROADCAST: + command += "12»ses" + Session + "»" + ChatMessage; break; case CommandType.ERROR: command += "ERROR IN NETCOMMAND"; diff --git a/ErgometerLibrary/Properties/AssemblyInfo.cs b/ErgometerLibrary/Properties/AssemblyInfo.cs index 269ba2c..380be99 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.3.5")] -[assembly: AssemblyFileVersion("1.0.3.5")] +[assembly: AssemblyVersion("1.0.3.6")] +[assembly: AssemblyFileVersion("1.0.3.6")]