public void Write(string dataPath) { string decPath = (dataPath + "\\metafile_" + Name + "_dec"); string encPath = (dataPath + "\\metafile_" + Name + "_enc"); using (Stream stream = File.Create(decPath)) { using (BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding(949))) { writer.Write((byte)(Elements.Count / 256)); writer.Write((byte)(Elements.Count % 256)); foreach (Element el in Elements) { writer.Write(el.Text); writer.Write((byte)(el.Properties.Count / 256)); writer.Write((byte)(el.Properties.Count % 256)); foreach (string p in el.Properties) { byte[] data = Encoding.GetEncoding(949).GetBytes(p); writer.Write((byte)(data.Length / 256)); writer.Write((byte)(data.Length % 256)); writer.Write(data); } } writer.Flush(); } } this.Checksum = ~CRC32.Calculate(File.ReadAllBytes(decPath)); ZLIB.Compress(decPath, encPath); this.RawData = File.ReadAllBytes(encPath); File.Delete(decPath); File.Delete(encPath); }
public static void LoadServers() { LobbyServer = new LobbyServer(); GameServers = new List <GameServer>(); string[] directories = Directory.GetDirectories("GameServers"); foreach (string directory in directories) { if (File.Exists(directory + "\\config.xml")) { GameServer gs = new GameServer(directory); gs.Index = GameServers.Count; GameServers.Add(gs); gs.LoginServer.Start(); gs.Start(); } } string decPath = (StartupPath + "\\mServer_dec"); string encPath = (StartupPath + "\\mServer_enc"); using (Stream stream = File.Create(decPath)) { using (BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding(949))) { byte i = 0; writer.Write((byte)GameServers.Count); foreach (GameServer gs in GameServers) { byte[] addressBytes = gs.LoginServer.EndPoint.Address.GetAddressBytes(); Array.Reverse(addressBytes); writer.Write(i++); writer.Write(addressBytes); writer.Write((byte)(gs.LoginServer.EndPoint.Port / 256)); writer.Write((byte)(gs.LoginServer.EndPoint.Port % 256)); writer.Write(Encoding.GetEncoding(949).GetBytes(string.Format("{0};{1}\0", gs.Name, gs.Description))); writer.Write((byte)0x00); } } } Checksum = ~CRC32.Calculate(File.ReadAllBytes(decPath)); ZLIB.Compress(decPath, encPath); RawData = File.ReadAllBytes(encPath); File.Delete(decPath); File.Delete(encPath); Program.WriteLine("{0} game servers loaded!", GameServers.Count); LobbyServer.Start(); }
public void Write(string dataPath) { string decPath = (dataPath + "\\notification_dec"); string encPath = (dataPath + "\\notification_enc"); using (Stream stream = File.Create(decPath)) { using (BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding(949))) { writer.Write(Encoding.GetEncoding(949).GetBytes(this.Text)); } } this.Checksum = ~CRC32.Calculate(File.ReadAllBytes(decPath)); ZLIB.Compress(decPath, encPath); this.RawData = File.ReadAllBytes(encPath); File.Delete(decPath); File.Delete(encPath); }