FormLogin.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using DeepCore.Xml;
  2. using DeepMMO.Data;
  3. using DeepMMO.Protocol;
  4. using DeepMMO.Protocol.Client;
  5. using System;
  6. using System.ComponentModel;
  7. using System.Windows.Forms;
  8. namespace DeepMMO.Client.Win32.Forms
  9. {
  10. public partial class FormLogin : Form
  11. {
  12. private string save_file = Application.StartupPath + "/" + typeof(FormLogin).Name + ".save";
  13. private readonly RPGClient client;
  14. public FormLogin(RPGClient client)
  15. {
  16. this.client = client;
  17. this.client.OnGateEntered += Client_OnGateEntered;
  18. InitializeComponent();
  19. DeepCore.Properties.LoadStaticFieldsFromFile(new System.IO.FileInfo(save_file), typeof(FormLoginSave));
  20. this.txt_Password.Text = FormLoginSave.password;
  21. if (FormLoginSave.ipaddress != null)
  22. {
  23. for (int i = 0; i < FormLoginSave.ipaddress.Length; i++)
  24. {
  25. if (i == 0)
  26. {
  27. this.txt_Server.Text = FormLoginSave.ipaddress[0];
  28. }
  29. else if (!this.txt_Server.Items.Contains(FormLoginSave.ipaddress[i]))
  30. {
  31. this.txt_Server.Items.Add(FormLoginSave.ipaddress[i]);
  32. }
  33. }
  34. }
  35. if (FormLoginSave.accounts != null)
  36. {
  37. for (int i = 0; i < FormLoginSave.accounts.Length; i++)
  38. {
  39. if (i == 0)
  40. {
  41. this.txt_Account.Text = FormLoginSave.accounts[0];
  42. }
  43. else if (!this.txt_Account.Items.Contains(FormLoginSave.accounts[i]))
  44. {
  45. this.txt_Account.Items.Add(FormLoginSave.accounts[i]);
  46. }
  47. }
  48. }
  49. if (FormLoginSave.serverID != null)
  50. {
  51. for (int i = 0; i < FormLoginSave.serverID.Length; i++)
  52. {
  53. if (i == 0)
  54. {
  55. this.txt_ServerID.Text = FormLoginSave.serverID[0];
  56. }
  57. else if (!this.txt_ServerID.Items.Contains(FormLoginSave.serverID[i]))
  58. {
  59. this.txt_ServerID.Items.Add(FormLoginSave.serverID[i]);
  60. }
  61. }
  62. }
  63. foreach (var server in RPGClientTemplateManager.Instance.GetAllServers())
  64. {
  65. this.com_ServerInfo.Items.Add(server);
  66. }
  67. this.DialogResult = DialogResult.Ignore;
  68. }
  69. protected override void OnClosing(CancelEventArgs e)
  70. {
  71. this.client.OnGateEntered -= Client_OnGateEntered;
  72. FormLoginSave.accounts = new string[this.txt_Account.Items.Count + 1];
  73. FormLoginSave.accounts[0] = this.txt_Account.Text;
  74. for (int i = 0; i < this.txt_Account.Items.Count; i++)
  75. {
  76. FormLoginSave.accounts[i + 1] = this.txt_Account.Items[i].ToString();
  77. }
  78. FormLoginSave.ipaddress = new string[this.txt_Server.Items.Count + 1];
  79. FormLoginSave.ipaddress[0] = this.txt_Server.Text;
  80. for (int i = 0; i < this.txt_Server.Items.Count; i++)
  81. {
  82. FormLoginSave.ipaddress[i + 1] = this.txt_Server.Items[i].ToString();
  83. }
  84. FormLoginSave.serverID = new string[this.txt_ServerID.Items.Count + 1];
  85. FormLoginSave.serverID[0] = this.txt_ServerID.Text;
  86. for (int i = 0; i < this.txt_ServerID.Items.Count; i++)
  87. {
  88. FormLoginSave.serverID[i + 1] = this.txt_ServerID.Items[i].ToString();
  89. }
  90. FormLoginSave.password = this.txt_Password.Text;
  91. DeepCore.Properties.SaveStaticFieldsToFile(new System.IO.FileInfo(save_file), typeof(FormLoginSave));
  92. base.OnClosing(e);
  93. }
  94. private void Client_OnGateEntered(ClientEnterGateResponse obj)
  95. {
  96. if (!this.txt_Account.Items.Contains(this.txt_Account.Text))
  97. {
  98. this.txt_Account.Items.Add(this.txt_Account.Text);
  99. }
  100. if (!this.txt_Server.Items.Contains(this.txt_Server.Text))
  101. {
  102. this.txt_Server.Items.Add(this.txt_Server.Text);
  103. }
  104. if (!this.txt_ServerID.Items.Contains(this.txt_ServerID.Text))
  105. {
  106. this.txt_ServerID.Items.Add(this.txt_ServerID.Text);
  107. }
  108. client.Connect_Connect((rsp2) =>
  109. {
  110. if (Response.CheckSuccess(rsp2))
  111. {
  112. this.DialogResult = DialogResult.OK;
  113. this.Close();
  114. }
  115. else
  116. {
  117. MessageBox.Show("Can Not Connect Connector : " + rsp2);
  118. }
  119. });
  120. }
  121. protected virtual void btn_Regist_Click(object sender, EventArgs e)
  122. {
  123. }
  124. protected virtual void btn_Login_Click(object sender, EventArgs e)
  125. {
  126. try
  127. {
  128. var address = txt_Server.Text;
  129. var kv = address.Split(':');
  130. if (kv.Length > 1)
  131. {
  132. client.Gate_Connect(kv[0], int.Parse(kv[1]),
  133. this.txt_Account.Text,
  134. this.txt_Password.Text,
  135. this.txt_ServerID.Text, (rsp) =>
  136. {
  137. if (rsp.s2c_code == ClientEnterGateResponse.CODE_OK_IN_QUEUE)
  138. {
  139. new FormLoginQueue(this.client, rsp).ShowDialog(this);
  140. }
  141. else if (rsp.IsSuccess)
  142. {
  143. }
  144. else
  145. {
  146. MessageBox.Show("Can Not Connect Gate : " + rsp);
  147. }
  148. });
  149. }
  150. }
  151. catch (Exception err)
  152. {
  153. MessageBox.Show(err.Message);
  154. }
  155. }
  156. private void com_ServerInfo_SelectedIndexChanged(object sender, EventArgs e)
  157. {
  158. var server = com_ServerInfo.SelectedItem as ServerInfo;
  159. if (server != null)
  160. {
  161. this.txt_Server.Text = server.address;
  162. this.txt_ServerID.Text = server.id;
  163. this.g2DPropertyGrid1.SetSelectedObject(XmlUtil.CloneObject(server));
  164. }
  165. }
  166. protected virtual void on_error(Exception err)
  167. {
  168. MessageBox.Show(err.Message);
  169. }
  170. public class FormLoginSave
  171. {
  172. public static string[] ipaddress = new string[] { "127.0.0.1:19001" };
  173. public static string[] accounts = new string[] { "hzdsb" };
  174. public static string[] serverID = new string[] { "0" };
  175. public static string password = "123456";
  176. }
  177. }
  178. }