private void StartGame(string code) { ProcessStartInfo _processStartInfo = new ProcessStartInfo(); _processStartInfo.WorkingDirectory = Settings.GrandFantasiaWorkingPath; _processStartInfo.FileName = Settings.GrandFantasiaExecutable; _processStartInfo.Arguments = "EasyFun -a " + code + " -p xlwlogin"; Action processDelegate = delegate { Process process = new Process(); process.StartInfo = _processStartInfo; process.EnableRaisingEvents = true; process.Exited += new EventHandler(GFInstance_Exited); process.Start(); }; string error = ""; try { processDelegate.Invoke(); StateGameInstance = StateGameInstanceEnumeration.Started; } catch (Exception) { error = Strings.ERROR_EXE; StateGameInstance = StateGameInstanceEnumeration.Error; } SendStateUpdate(error); }
public void UpdateState(StateGameInstanceEnumeration state, string errorMessage) { if (InvokeRequired) { this.Invoke(new Action(() => UpdateState(state, errorMessage))); return; } switch (state) { case StateGameInstanceEnumeration.Started: ButtonDemarrerJeu.Text = Strings.STRING_STARTBUTTON_RUNNING; ButtonDemarrerJeu.Enabled = false; break; case StateGameInstanceEnumeration.Starting: ButtonDemarrerJeu.Text = Strings.STRING_STARTBUTTON_STARTING; ButtonDemarrerJeu.Enabled = false; break; case StateGameInstanceEnumeration.Error: ButtonDemarrerJeu.Text = Strings.STRING_STARTBUTTON_START; ButtonDemarrerJeu.Enabled = true; MessageBox.Show(errorMessage, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); break; case StateGameInstanceEnumeration.Stop: ButtonDemarrerJeu.Text = Strings.STRING_STARTBUTTON_START; ButtonDemarrerJeu.Enabled = true; break; default: break; } }
public void StartSession() { StateGameInstance = StateGameInstanceEnumeration.Starting; SendStateUpdate(); string loginPageHtml = Resources.login .Replace("{PASSWORD}", Account.UncryptedPassword) .Replace("{ID}", Account.Id) .Replace("{IDCLIENT}", Settings.IdClient); WebBrowser = new WebBrowser(); WebBrowser.DocumentText = loginPageHtml; WaitForCode(); }
private async void WaitForCode() { Regex regexCode = new Regex("code=(.*)$"); Match regexMatch = null; int i = 0; while (i < Settings.TimeoutBeforeCode) { await Task.Delay(10); regexMatch = regexCode.Match(WebBrowser.Url.AbsoluteUri); if (regexMatch.Success) { ResetCookies(); StartGame(regexMatch.Groups[1].Value); return; } i += 10; } Match match = Regex.Match(WebBrowser.DocumentText, @"<div class=""messages error"">((\s|.)[^<]*)<"); StateGameInstance = StateGameInstanceEnumeration.Error; string error = Strings.UNKNOWNERROR_IDENTIFICATION; if (match.Success) { error = match.Groups[1].Value.Trim(); } else if (WebBrowser.Url.AbsoluteUri.Contains("missing")) { error = Strings.ERROR_IDCLIENT; } SendStateUpdate(error); }
public GameInstanceManager(Account account, Action <StateGameInstanceEnumeration, string> UpdateStateFunction) { this.Account = account; this.UpdateStateFunction = UpdateStateFunction; StateGameInstance = StateGameInstanceEnumeration.Stop; }
private void GFInstance_Exited(object sender, System.EventArgs e) { StateGameInstance = StateGameInstanceEnumeration.Stop; SendStateUpdate(); }