Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 public static void EnsureAllDataFoldersExist()
 {
     string[] folders = { "characters", "LaunchFiles", "Logs", "Profiles", "Running", "Servers" };
     foreach (var folderName in folders)
     {
         string directory = Path.Combine(AppFolder, folderName);
         FileLocations.EnsureFolderExists(directory);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Called by ThwargLauncher
        /// </summary>
        public static void RecordLaunchInfo(string serverName, string accountName, string characterName, DateTime timestampUtc)
        {
            string filepath = FileLocations.GetCurrentLaunchFilePath(ServerName: serverName, AccountName: accountName);

            using (var file = new StreamWriter(filepath, append: false))
            {
                file.WriteLine("FileVersion:{0}", LaunchInfo.MASTER_FILE_VERSION);
                file.WriteLine("Timestamp=TimeUtc:'{0:o}'", timestampUtc);
                file.WriteLine("ServerName:{0}", serverName);
                file.WriteLine("AccountName:{0}", accountName);
                file.WriteLine("CharacterName:{0}", characterName);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Called by ThwargFilter
        /// </summary>
        internal static void RecordLaunchResponse(DateTime timestampUtc)
        {
            string filepath = FileLocations.GetCurrentLaunchResponseFilePath(ServerName: GameRepo.Game.Server, AccountName: GameRepo.Game.Account);

            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: {0:o}", timestampUtc);
                file.WriteLine("ProcessId:{0}", pid);
                file.WriteLine("ThwargFilterVersion:{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
            }
        }
Esempio n. 7
0
        /// <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 + @"\ThwargFilter_%PID%_log.txt";
            }
            _logFilepath = FileLocations.ExpandFilepath(filepath);
            // Create any needed folders
            FileLocations.CreateAnyNeededFoldersOfFile(_logFilepath);
        }
Esempio n. 8
0
        public static List <string> EnumerateCharacterFilepaths()
        {
            List <string> filepaths = new List <string>();
            string        xpath     = FileLocations.GetCharacterFilePath(ServerName: GameRepo.Game.Server, AccountName: GameRepo.Game.Account);
            string        chardir   = System.IO.Path.GetDirectoryName(xpath);

            FileLocations.EnsureFolderExists(chardir);
            foreach (string charfilename in Directory.GetFiles(chardir))
            {
                string path = Path.Combine(chardir, charfilename);
                filepaths.Add(path);
            }
            return(filepaths);
        }
        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));
        }
Esempio n. 10
0
        public static void WriteCharacters(string ServerName, 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");
                }
            }

            // Pass info to Heartbeat
            Heartbeat.RecordServer(launchInfo.ServerName);
            Heartbeat.RecordAccount(launchInfo.AccountName);

            string key   = GetKey(server: launchInfo.ServerName, accountName: launchInfo.AccountName);
            var    clist = new ServerCharacterListByAccount()
            {
                ZoneId        = zonename,
                CharacterList = characters
            };

            // Create a dictionary of only our characters to save
            Dictionary <string, ServerCharacterListByAccount> solodict = new Dictionary <string, ServerCharacterListByAccount>();

            solodict[key] = clist;

            string contents = JsonConvert.SerializeObject(solodict, Formatting.Indented);
            string path     = FileLocations.GetCharacterFilePath(ServerName: launchInfo.ServerName, AccountName: launchInfo.AccountName);

            using (var file = new StreamWriter(path, append: false))
            {
                file.Write(contents);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Called by ThwargFilter
        /// </summary>
        internal static LaunchInfo GetLaunchInfo()
        {
            var info = new LaunchInfo();

            try
            {
                string filepath = FileLocations.GetCurrentLaunchFilePath(ServerName: GameRepo.Game.Server, AccountName: GameRepo.Game.Account);

                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);
        }
Esempio n. 12
0
        /// <summary>
        /// Called by ThwargLauncher
        /// </summary>
        public static LaunchResponse GetLaunchResponse(string ServerName, string AccountName, TimeSpan maxLatency)
        {
            var info = new LaunchResponse();

            try
            {
                string filepath = FileLocations.GetCurrentLaunchResponseFilePath(ServerName: ServerName, AccountName: AccountName);
                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.ToUniversalTime() >= maxLatency)
                {
                    return(info);
                }
                info.ProcessId           = SettingHelpers.GetSingleIntValue(settings, "ProcessId");
                info.ThwargFilterVersion = SettingHelpers.GetSingleStringValue(settings, "ThwargFilterVersion");
                info.ServerNameReported  = SettingHelpers.GetSingleStringValue(settings, "ServerNameReported");

                info.IsValid = true;
            }
            catch (Exception exc)
            {
                log.WriteError("GetLaunchResponse exception: {0}", exc);
            }
            return(info);
        }
        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();
                // to avoid json vulnerability, do not use TypeNameHandling.All
                var           data    = JsonConvert.DeserializeObject <Dictionary <string, ServerCharacterListByAccount> >(contents);
                CharacterBook charMgr = new CharacterBook(data);
                return(charMgr);
            }
        }
Esempio n. 14
0
        }                                            // for game emulator

        protected override void Startup()
        {
            Debug.Init(FileLocations.PluginPersonalFolder.FullName + @"\Exceptions.txt", PluginName);
            SettingsFile.Init(FileLocations.GetFilterSettingsFilepath(), PluginName);
            LogStartup();
            theFilterCore = this;

            defaultFirstCharacterManager = new DefaultFirstCharacterManager(loginCharacterTools);
            chooseCharacterManager       = new LauncherChooseCharacterManager(loginCharacterTools);
            ThwargFilterCommandExecutor  = new ThwargFilterCommandExecutor();
            ThwargFilterCommandParser    = new ThwargFilterCommandParser(ThwargFilterCommandExecutor);
            Heartbeat.SetCommandParser(ThwargFilterCommandParser);
            loginNextCharacterManager           = new LoginNextCharacterManager(loginCharacterTools);
            thwargInventory                     = new ThwargInventory();
            ThwargFilterCommandParser.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);
        }