using System; using System.IO; using System.Collections.Generic; using System.Collections; using System.Xml; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; /******************************************************************************/ public static class zpravy /******************************************************************************/ { public static bool server; public static void log(string s) { string log_jmeno_souboru; if (server) { log_jmeno_souboru = "das.server.log"; } else { log_jmeno_souboru = "das.klient.log"; } //Console.WriteLine(s); try { using (StreamWriter sw = File.AppendText(log_jmeno_souboru)) { sw.Write(Convert.ToString(System.DateTime.Now) + " "); sw.WriteLine(s); sw.Flush(); sw.Close(); } } catch { } } static string[] ostatni_udalost_parametry = new string[6]; static string[] ostatni_udalost = new string[6]; static string[] text = new string[6]; public static void notifikuj(int hrac, string a) { text[hrac] = a; zpravy.log("notifikace pro hrace #" + hrac + " " + a); } public static string udalost(int hrac) { string a = text[hrac]; return a; } public static void notifikuj2(int hrac, string a, string b) { ostatni_udalost[hrac] = a; ostatni_udalost_parametry[hrac] = b; zpravy.log("parametricka notifikace pro hrace #" + hrac + " " + a + "(" + b + ")"); } public static string ostatni_udalosti(int hrac) { string a = ostatni_udalost[hrac]; return a; } public static string parametry_ostatni_udalosti(int hrac) { string a = ostatni_udalost_parametry[hrac]; return a; } public static void smaz_ostatni_udalosti(int hrac) { ostatni_udalost[hrac] = ""; ostatni_udalost_parametry[hrac] = ""; } public static void smaz_udalost(int hrac) { text[hrac] = ""; } public static string base64Encode(string data) { try { byte[] encData_byte = new byte[data.Length]; encData_byte = System.Text.Encoding.UTF8.GetBytes(data); string encodedData = Convert.ToBase64String(encData_byte); return encodedData; } catch(Exception e) { return("Error in base64Encode" + e.Message); } } public static string base64Decode(string data) { try { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(data); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return result; } catch(Exception e) { return("Error in base64Decode" + e.Message); } } }