internal static string GetGameHeartbeatFilepath(int processId) { string filename = string.Format("game_{0}.txt", processId); string filepath = System.IO.Path.Combine(FileLocations.GetRunningFolder(), filename); return(filepath); }
private void StartBeating() { if (_timer != null) { // already started return; } AssemblySettings settings = new AssemblySettings(); _offlineTimeoutSeconds = StringToInt(settings.GetValue("ServerOnlineTimeoutSeconds", "30"), 30); int dllProcessId = System.Diagnostics.Process.GetCurrentProcess().Id; _gameToLauncherFilepath = FileLocations.GetGameHeartbeatFilepath(dllProcessId); int intervalMilliseconds = 1000 * TIMER_SECONDS; _timer = new System.Timers.Timer(); _timer.Interval = intervalMilliseconds; _timer.Elapsed += _timer_Elapsed; _timer.Enabled = true; _timer.Start(); StartChannelFileWatcher(); AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; }
public static string GetLauncherToGameFilepath(int processId) { string filename = string.Format("launcherToGame_{0}.txt", processId); string filepath = System.IO.Path.Combine(FileLocations.GetRunningFolder(), filename); return(filepath); }
/// <summary> /// Initialize log location /// Called from static class constructor /// </summary> private static void InitConfigureLogLocation(AssemblySettings settings) { string filepath = settings["LogFilepath"]; // If no log path specified, default to our normal app logs folder if (string.IsNullOrEmpty(filepath)) { filepath = FileLocations.AppLogsFolder + @"\Mag-Filter_%PID%_log.txt"; } _logFilepath = FileLocations.ExpandFilepath(filepath); // Create any needed folders FileLocations.CreateAnyNeededFoldersOfFile(_logFilepath); }
/// <summary> /// Called by ThwargLauncher /// </summary> public static void RecordLaunchInfo(string serverName, string accountName, string characterName, DateTime timestampUtc) { string filepath = FileLocations.GetCurrentLaunchFilePath(); using (var file = new StreamWriter(filepath, append: false)) { file.WriteLine("FileVersion:{0}", LaunchInfo.MASTER_FILE_VERSION); file.WriteLine("Timestamp=TimeUtc:'{0}'", timestampUtc); file.WriteLine("ServerName:{0}", serverName); file.WriteLine("AccountName:{0}", accountName); file.WriteLine("CharacterName:{0}", characterName); } }
/// <summary> /// Called by Mag-Filter /// </summary> internal static void RecordLaunchResponse(DateTime timestampUtc) { string filepath = FileLocations.GetCurrentLaunchResponseFilePath(); using (var file = new StreamWriter(filepath, append: false)) { int pid = System.Diagnostics.Process.GetCurrentProcess().Id; file.WriteLine("FileVersion:{0}", LaunchResponse.MASTER_FILE_VERSION); file.WriteLine("TimeUtc:" + timestampUtc); file.WriteLine("ProcessId:{0}", pid); file.WriteLine("MagFilterVersion:{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); } }
private string GetFilepath(bool global) { string filename = ""; if (global) { filename = "LoginCommandsGlobal.txt"; } else { filename = string.Format("LoginCommands-{0}-{1}-{2}.txt", _accountName, _serverName, _characterName); // TODO - encode to ASCII } return(Path.Combine(FileLocations.GetLoginCommandsFolder(), filename)); }
private void StartBeating() { int dllProcessId = System.Diagnostics.Process.GetCurrentProcess().Id; _gameToLauncherFilepath = FileLocations.GetGameHeartbeatFilepath(dllProcessId); int intervalMilliseconds = 1000 * TIMER_SECONDS; _timer = new System.Timers.Timer(); _timer.Interval = intervalMilliseconds; _timer.Elapsed += _timer_Elapsed; _timer.Enabled = true; _timer.Start(); StartChannelFileWatcher(); AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; }
public void WriteCharacters(string zonename, List <Character> characters) { var launchInfo = LaunchControl.GetLaunchInfo(); if (!launchInfo.IsValid) { log.WriteError("LaunchInfo not valid"); return; } if (!IsValidCharacterName(launchInfo.CharacterName)) { try { log.WriteInfo("WriteCharacters called with no character name, so writing launch response"); LaunchControl.RecordLaunchResponse(DateTime.UtcNow); } catch { log.WriteError("WriteCharacters: Exception trying to record launch response"); } } log.WriteDebug("LaunchInfo valid"); // Pass info to Heartbeat Heartbeat.RecordServer(launchInfo.ServerName); Heartbeat.RecordAccount(launchInfo.AccountName); GameRepo.Game.SetServerAccount(server: launchInfo.ServerName, account: launchInfo.AccountName); string key = GetKey(server: launchInfo.ServerName, accountName: launchInfo.AccountName); var clist = new ServerCharacterListByAccount() { ZoneId = zonename, CharacterList = characters }; log.WriteInfo("Writing characters: " + clist.ToString()); this._data[key] = clist; string contents = JsonConvert.SerializeObject(_data, Formatting.Indented); string path = FileLocations.GetCharacterFilePath(); using (var file = new StreamWriter(path, append: false)) { file.Write(contents); } }
/// <summary> /// Called by Mag-Filter /// </summary> internal static LaunchInfo GetLaunchInfo() { var info = new LaunchInfo(); try { string filepath = FileLocations.GetCurrentLaunchFilePath(); if (!File.Exists(filepath)) { log.WriteError("No launch file found: '{0}'", filepath); return(info); } var settings = (new SettingsFileLoader()).ReadSettingsFile(filepath); info.FileVersion = SettingHelpers.GetSingleStringValue(settings, "FileVersion"); if (!info.FileVersion.StartsWith(LaunchInfo.MASTER_FILE_VERSION_COMPAT)) { throw new Exception(string.Format( "Incompatible launch info file version: {0}", info.FileVersion)); } info.LaunchTime = settings.GetValue("Timestamp").GetDateParam("TimeUtc"); TimeSpan maxLatency = new TimeSpan(0, 0, 0, 45); // 30 seconds max latency from exe call to game launch if (DateTime.UtcNow - info.LaunchTime >= maxLatency) { log.WriteInfo("DateTime.UtcNow-'{0}', info.LaunchTime='{1}', maxLatency='{2}'", DateTime.UtcNow, info.LaunchTime, maxLatency); log.WriteInfo("Launch file TimeUtc too old"); return(info); } info.ServerName = SettingHelpers.GetSingleStringValue(settings, "ServerName"); info.AccountName = SettingHelpers.GetSingleStringValue(settings, "AccountName"); info.CharacterName = SettingHelpers.GetSingleStringValue(settings, "CharacterName"); info.IsValid = true; } catch (Exception exc) { log.WriteError("GetLaunchInfo exception: {0}", exc); } return(info); }
/// <summary> /// Called by ThwargLauncher /// </summary> public static LaunchResponse GetLaunchResponse(TimeSpan maxLatency) { var info = new LaunchResponse(); try { string filepath = FileLocations.GetCurrentLaunchResponseFilePath(); if (string.IsNullOrEmpty(filepath)) { return(info); } if (!File.Exists(filepath)) { return(info); } var settings = (new SettingsFileLoader()).ReadSettingsFile(filepath); info.FileVersion = SettingHelpers.GetSingleStringValue(settings, "FileVersion"); if (!info.FileVersion.StartsWith(LaunchResponse.MASTER_FILE_VERSION_COMPAT)) { throw new Exception(string.Format( "Incompatible launch response file version: {0}", info.FileVersion)); } info.ResponseTime = SettingHelpers.GetSingleDateTimeValue(settings, "TimeUtc"); if (DateTime.UtcNow - info.ResponseTime >= maxLatency) { return(info); } info.ProcessId = SettingHelpers.GetSingleIntValue(settings, "ProcessId"); info.MagFilterVersion = SettingHelpers.GetSingleStringValue(settings, "MagFilterVersion"); info.IsValid = true; } catch (Exception exc) { log.WriteError("GetLaunchResponse exception: {0}", exc); } return(info); }
} // for game emulator protected override void Startup() { Debug.Init(FileLocations.PluginPersonalFolder.FullName + @"\Exceptions.txt", PluginName); SettingsFile.Init(FileLocations.GetFilterSettingsFilepath(), PluginName); LogStartup(); defaultFirstCharacterManager = new DefaultFirstCharacterManager(loginCharacterTools); chooseCharacterManager = new LauncherChooseCharacterManager(loginCharacterTools); magFilterCommandExecutor = new MagFilterCommandExecutor(); magFilterCommandParser = new MagFilterCommandParser(magFilterCommandExecutor); Heartbeat.SetCommandParser(magFilterCommandParser); loginNextCharacterManager = new LoginNextCharacterManager(loginCharacterTools); thwargInventory = new ThwargInventory(); magFilterCommandParser.Inventory = thwargInventory; ClientDispatch += new EventHandler <NetworkMessageEventArgs>(FilterCore_ClientDispatch); ServerDispatch += new EventHandler <NetworkMessageEventArgs>(FilterCore_ServerDispatch); WindowMessage += new EventHandler <WindowMessageEventArgs>(FilterCore_WindowMessage); CommandLineText += new EventHandler <ChatParserInterceptEventArgs>(FilterCore_CommandLineText); }
private static CharacterBook ReadCharactersImpl() { string path = FileLocations.GetCharacterFilePath(); if (!File.Exists(path)) { path = FileLocations.GetOldCharacterFilePath(); } if (!File.Exists(path)) { return(new CharacterBook()); } using (var file = new StreamReader(path)) { string contents = file.ReadToEnd(); var data = JsonConvert.DeserializeObject <Dictionary <string, ServerCharacterListByAccount> >(contents); CharacterBook charMgr = new CharacterBook(data); return(charMgr); } }