using System; using System.Collections.Generic; using System.IO; using System.Diagnostics; using System.Security.Cryptography; using KaduhServer; namespace PatcherServer.FileCheck { public class FileSecurity { public static byte[] Version = new byte[] { 1, 0, 0, 3 }; //Version public static string LogPath = "Log.txt"; public static string DBName = ""; public static TextWriter tWriter; public static string localPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); public static bool Running = true; public static Dictionary FileChecks = new Dictionary(); public static HackServer Server; public static ushort HackPort = 9334; public static ushort TunnelPort = 9333; public static string ClientName = ""; public static void Start() { tWriter = new StreamWriter(localPath + "\\" + LogPath, true); LoadSettings("ShieldSettings.txt"); LoadFileChecks(); Log.WriteLine(ELogLevel.Info, "Lade {0} file checks.", FileChecks.Count); Listener lGameListener = new Listener(TunnelPort, 9010, "127.0.0.1"); Server = new HackServer(); } static void LoadSettings(string pPath) { if (!File.Exists(pPath)) { Log.WriteLine(ELogLevel.Warn, "Einstellungen nicht gefunden."); return; } try { TextReader reader = new StreamReader(pPath); string output = ""; while ((output = reader.ReadLine()) != null) { string[] command = output.Split('='); switch (command[0].ToLower()) { case "db": DBName = command[1]; break; case "debug": Log.isDebug = bool.Parse(command[1]); break; case "tunnelport": TunnelPort = ushort.Parse(command[1]); break; case "hackport": HackPort = ushort.Parse(command[1]); break; case "clientname": ClientName = command[1]; break; default: Log.WriteLine(ELogLevel.Info, "Settings file weird formatting."); break; } } reader.Close(); } catch (Exception ex) { Log.WriteLine(ELogLevel.Exception, "Settings error: {0}", ex.Message); } } static void LoadFileChecks() { if (!File.Exists(localPath + "\\FileCheck.txt")) { Log.WriteLine(ELogLevel.Error, "Cannot find FileCheck file."); return; } TextReader reader = new StreamReader(localPath + "\\FileCheck.txt"); MD5 md5 = new MD5CryptoServiceProvider(); string line = ""; while ((line = reader.ReadLine()) != null) { if (line.Contains("#")) continue; string FilePath = localPath + "\\" + line; if (!File.Exists(FilePath)) { Log.WriteLine(ELogLevel.Warn, "File not found: {0}", line); continue; } FileStream fStream = File.Open(FilePath, FileMode.Open); FileChecks.Add(line, md5.ComputeHash(fStream)); fStream.Close(); } reader.Close(); } } }