From 9c8c87efaaf261acf369b3e0e72800f0d726028e Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 2 Oct 2015 13:40:02 +0200 Subject: [PATCH] Bugfixes --- ErgometerLibrary/FileHandler.cs | 2 +- ErgometerLibrary/NetCommand.cs | 6 +++- ErgometerLibrary/NetHelper.cs | 32 ++++++++++++++++++--- ErgometerLibrary/Properties/AssemblyInfo.cs | 4 +-- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/ErgometerLibrary/FileHandler.cs b/ErgometerLibrary/FileHandler.cs index 4333b82..e01925a 100644 --- a/ErgometerLibrary/FileHandler.cs +++ b/ErgometerLibrary/FileHandler.cs @@ -22,7 +22,7 @@ namespace ErgometerLibrary string[] existingSessions = Directory.GetDirectories(DataFolder); Random rand = new Random(); - int sessionID = rand.Next(int.MinValue, int.MaxValue); + int sessionID = rand.Next(0, int.MaxValue); while (existingSessions.Contains(sessionID.ToString())) diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index 1f2586d..5edc183 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -52,7 +52,7 @@ namespace ErgometerLibrary ChatMessage = chat; } - public NetCommand(string name, bool doctor, int session) + public NetCommand(string name, bool doctor, string password, int session) { Type = CommandType.LOGIN; Session = session; @@ -60,12 +60,16 @@ namespace ErgometerLibrary DisplayName = name; IsDoctor = doctor; + Password = password; } public static NetCommand Parse(string command) { string[] com = command.Split('»'); + Console.WriteLine(command); + Console.WriteLine(com[0]); + int comType = int.Parse(com[0]); int session = 0; if (com[1].StartsWith("ses")) diff --git a/ErgometerLibrary/NetHelper.cs b/ErgometerLibrary/NetHelper.cs index 942934d..f10b7fb 100644 --- a/ErgometerLibrary/NetHelper.cs +++ b/ErgometerLibrary/NetHelper.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Net; using System.Net.Sockets; using System.Text; @@ -9,33 +10,56 @@ namespace ErgometerLibrary { public static void SendNetCommand(TcpClient client, NetCommand command) { - byte[] b = Encoding.ASCII.GetBytes(command.ToString()); + /* + byte[] b = Encoding.Unicode.GetBytes(command.ToString()); client.GetStream().Write(b, 0, b.Length); client.GetStream().Flush(); + */ + SendString(client, command.ToString()); } public static void SendString(TcpClient client, string command) { - byte[] b = Encoding.ASCII.GetBytes(command); + /* + byte[] b = Encoding.Unicode.GetBytes(command); client.GetStream().Write(b, 0, b.Length); client.GetStream().Flush(); + */ + + StreamWriter wr = new StreamWriter(client.GetStream(), Encoding.Unicode); + wr.WriteLine(command); + Console.WriteLine("sent " + command); + wr.Flush(); } public static NetCommand ReadNetCommand(TcpClient client) { + /* byte[] bytesFrom = new byte[(int) client.ReceiveBufferSize]; client.GetStream().Read(bytesFrom, 0, (int)client.ReceiveBufferSize); - string response = Encoding.ASCII.GetString(bytesFrom); + string response = Encoding.Unicode.GetString(bytesFrom); NetCommand net = NetCommand.Parse(response); return net; + */ + + string str = ReadString(client); + NetCommand net = NetCommand.Parse(str); + return net; } public static string ReadString(TcpClient client) { + /* byte[] bytesFrom = new byte[(int)client.ReceiveBufferSize]; client.GetStream().Read(bytesFrom, 0, (int)client.ReceiveBufferSize); - string response = Encoding.ASCII.GetString(bytesFrom); + string response = Encoding.Unicode.GetString(bytesFrom); return response; + */ + + StreamReader rd = new StreamReader(client.GetStream(), Encoding.Unicode); + string str = rd.ReadLine(); + Console.WriteLine("rec " + str); + return str; } public static IPAddress GetIP(string ipstring) diff --git a/ErgometerLibrary/Properties/AssemblyInfo.cs b/ErgometerLibrary/Properties/AssemblyInfo.cs index 8db4017..72800b3 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.1")] -[assembly: AssemblyFileVersion("1.0.2.1")] +[assembly: AssemblyVersion("1.0.2.2")] +[assembly: AssemblyFileVersion("1.0.2.2")]