public async Task <bool> CreateAccountWithMacVerificationAsync(string username, string password, string idCode) { bool regStatus = false; var macAddr = ATGateUtil.GetMacAddr(); try { if (!CheckIfMacRegisterLimitExceeds(macAddr)) { if (CreateAccount(username, password, macAddr, idCode)) { MessageBox.Show("注册成功!"); regStatus = true; } } else { new MsgBox("[DW1]", "超过注册数限制", "该电脑已超过注册数限制,请联系管理员。", server_ip + "\nPC: " + macAddr).ShowDialog(); } } catch (Exception) { Console.WriteLine("数据库未连接 Server: " + server_ip); } return(regStatus); }
public static void AskToCreateShortcut() { //check if shutcut exist object shDesktop = (object)"Desktop"; WshShell shell = new WshShell(); string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\" + Application.ProductName + ".lnk"; if (!System.IO.File.Exists(shortcutAddress)) { if (Properties.Settings.Default.wantShortcut) { if (MessageBox.Show( "是否添加桌面快捷键?", "桌面快捷键", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes) { ATGateUtil.CreateDesktopShortcut(); } else { Properties.Settings.Default.wantShortcut = false; Properties.Settings.Default.Save(); } } } }
public static void ReportCrash(Exception exception, string developerMessage = "") { if (exception.GetType().Equals(new FileLoadException().GetType())) { ATGateUtil.HandleDotNetException(); } else { var reportCrash = new ReportCrash(Properties.Resources.crash_report_email); reportCrash.Send(exception); Environment.Exit(0); } }
private async void btn_change_pass_Click(object sender, EventArgs e) { try { EnableControls(false); string username = tb_username.Text; string newPassword = tb_password.Text; string idCode = tb_id_code.Text; if (!username.Equals("") && !newPassword.Equals("") && !idCode.Equals("")) //确保用户名和密码必填 { if (newPassword.Length > int.Parse(Properties.Resources.passwd_min)) //确保密码长度 > 3 { DBWrapper dw = new DBWrapper(server.getRegisterIp(), server.RegisterDbSchema); regStatus = await Task.Factory.StartNew(() => dw.ResetAccountPasswordWithIdCode(username, newPassword, idCode)); } else { MessageBox.Show("密码过短。"); EnableControls(true); return; } } else { MessageBox.Show("请输入用户名, 新密码与验证码。"); EnableControls(true); return; } if (regStatus.Result) { this.Close(); } else { EnableControls(true); } } catch (System.IO.FileLoadException) { ATGateUtil.HandleDotNetException(); } catch (NullReferenceException) { new MsgBox("[R2]", "更改失败", "无法更改请重试。").ShowDialog(); Close(); } }
static void Main() { InitilizeProgram(); if (CheckPreRequisite()) { bool createdNew = true; using (Mutex mutex = new Mutex(false, Application.ProductName, out createdNew)) { if (!createdNew) { MessageBox.Show("[P1]\n启动器已运行", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else { try { #if NeedVerify if (StartVerification()) { Application.Run(new Homepage()); } else { Environment.Exit(0); } #else Application.Run(new Homepage()); #endif } catch (System.IO.FileLoadException) { ATGateUtil.HandleDotNetException(); } } } } else { return; } }
/// <summary> /// 注册按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_register_Click(object sender, EventArgs e) { try { Console.WriteLine("Register server " + selectedServer); Server server = serverList[selectedServer]; Register register = new Register(server) { Text = server.Name + " - 注册账号" }; register.ShowDialog(this); } catch (System.IO.FileLoadException) { ATGateUtil.HandleDotNetException(); } catch (Exception) { new MsgBox("[HP4]", "注册账号", "注册失败,请重试。").ShowDialog(); return; } }
/// <summary> /// 检查启动条件 /// </summary> /// <returns>真/假</returns> private static bool CheckPreRequisite() { string gameFile = "asktao.mod"; //check if in game file if (!System.IO.File.Exists(gameFile)) { ATGateUtil.HandleGameNotFound(); } else { AskToCreateShortcut(); if (ATGateUtil.IfdotNet4AndLaterInstalled()) { return(true); } else { ATGateUtil.HandleDotNetException(); } } return(false); }
private void btn_create_shortcut_Click(object sender, EventArgs e) { ATGateUtil.CreateDesktopShortcut(); Properties.Settings.Default.wantShortcut = true; Properties.Settings.Default.Save(); }
/// <summary> /// 开始游戏按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Btn_start_game_Click(object sender, EventArgs e) { try { #if DEBUG string absPath = @"asktao.mod"; #else string absPath = @Directory.GetCurrentDirectory() + "/asktao.mod"; #endif if (!CheckServerStatus()) { return; } Console.WriteLine("Starting Game " + selectedServer); Server server = serverList[selectedServer]; if (!File.Exists(absPath)) { ATGateUtil.HandleGameNotFound(); } else { btn_start_game.Enabled = false; btn_register.Enabled = false; btn_about.Enabled = false; lb_startGameStatus.Visible = true; bool status = false; await Task.Factory.StartNew(() => { if (cb_use_cp_mode.Checked == false) { status = HandleStartGame.StartProcessByCmd(server); } else { status = HandleStartGame.StartProcessSimplify(absPath, server.getCmdArgs); } }); if (status) { await Task.Factory.StartNew(() => { Thread.Sleep(3000); Console.WriteLine("Game Started, Ending Launcher."); Environment.Exit(0); }); } else { btn_start_game.Enabled = true; btn_register.Enabled = true; btn_about.Enabled = true; lb_startGameStatus.Visible = false; new MsgBox("[HP3]", "游戏启动失败", "游戏启动失败").ShowDialog(); } } } catch (FileLoadException) { ATGateUtil.HandleDotNetException(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// 更新服务器状态 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void UpdateServerStatus(object sender, EventArgs e) { int index = 0; try { serverRefreashBtn.Enabled = false; cb_skip_ping.Enabled = false; if (selectedServer != lv_serverlist.SelectedIndices[0] || serverList[lv_serverlist.SelectedIndices[0]].Status.Equals("已连接")) { refreashServerTryCount = 0; } selectedServer = lv_serverlist.SelectedIndices[0]; index = selectedServer; lv_serverlist.Items[index].SubItems[1].Text = "..."; await Task.Factory.StartNew(() => { Tuple <bool, string, bool> tuple = ATGateUtil.CheckServerStatus(serverList[index]); if (tuple.Item1) { serverList[index].Status = "已连接"; } else { serverList[index].Status = "未连接"; } serverList[index].RegisterServerStatus = tuple.Item3; serverList[index].Delay = tuple.Item2; this.Invoke((MethodInvoker) delegate { btn_register.Enabled = tuple.Item3; btn_start_game.Enabled = tuple.Item1; }); }); lv_serverlist.Items[index].SubItems[1].Text = serverList[index].Delay; lv_serverlist.Items[index].SubItems[0].Text = serverList[index].Name + " - " + serverList[index].Status; Console.WriteLine(index); if (refreashServerTryCount > 4 && serverList[index].Status.Equals("未连接")) { if (new MsgBox("[HP1]", "尝试直接启动", "更新服务器状态失败,是否尝试直接启动游戏?", serverList[index].Ip.Split('.')[2] + "." + serverList[index].Ip.Split('.')[3]).ShowDialog() == DialogResult.Yes) { skipPing = true; } } refreashServerTryCount++; serverRefreashBtn.Enabled = true; cb_skip_ping.Enabled = true; } catch (FileLoadException) { ATGateUtil.HandleDotNetException(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); new MsgBox("[HP2]", "更新服务器状态", "更新服务器状态失败,请重试。", serverList[index].Ip.Split('.')[2] + "." + serverList[index].Ip.Split('.')[3]).ShowDialog(); serverRefreashBtn.Enabled = true; } }