ConfigForm.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. using Server.MirEnvir;
  2. using System.Net;
  3. using System.Text.RegularExpressions;
  4. namespace Server
  5. {
  6. public partial class ConfigForm : Form
  7. {
  8. public ConfigForm()
  9. {
  10. InitializeComponent();
  11. VPathTextBox.Text = Settings.VersionPath;
  12. VersionCheckBox.Checked = Settings.CheckVersion;
  13. RelogDelayTextBox.Text = Settings.RelogDelay.ToString();
  14. IPAddressTextBox.Text = Settings.IPAddress;
  15. PortTextBox.Text = Settings.Port.ToString();
  16. TimeOutTextBox.Text = Settings.TimeOut.ToString();
  17. MaxUserTextBox.Text = Settings.MaxUser.ToString();
  18. StartHTTPCheckBox.Checked = Settings.StartHTTPService;
  19. HTTPIPAddressTextBox.Text = Settings.HTTPIPAddress;
  20. HTTPTrustedIPAddressTextBox.Text = Settings.HTTPTrustedIPAddress;
  21. AccountCheckBox.Checked = Settings.AllowNewAccount;
  22. PasswordCheckBox.Checked = Settings.AllowChangePassword;
  23. LoginCheckBox.Checked = Settings.AllowLogin;
  24. NCharacterCheckBox.Checked = Settings.AllowNewCharacter;
  25. DCharacterCheckBox.Checked = Settings.AllowDeleteCharacter;
  26. StartGameCheckBox.Checked = Settings.AllowStartGame;
  27. AllowAssassinCheckBox.Checked = Settings.AllowCreateAssassin;
  28. AllowArcherCheckBox.Checked = Settings.AllowCreateArcher;
  29. WarehousePasswordCheckBox.Checked = Settings.RequireStoragePassword;
  30. Resolution_textbox.Text = Settings.AllowedResolution.ToString();
  31. ObserveCheckBox.Checked = Settings.AllowObserve;
  32. SafeZoneBorderCheckBox.Checked = Settings.SafeZoneBorder;
  33. SafeZoneHealingCheckBox.Checked = Settings.SafeZoneHealing;
  34. gameMasterEffect_CheckBox.Checked = Settings.GameMasterEffect;
  35. lineMessageTimeTextBox.Text = Settings.LineMessageTimer.ToString();
  36. SaveDelayTextBox.Text = Settings.SaveDelay.ToString();
  37. ServerVersionLabel.Text = Application.ProductVersion;
  38. DBVersionLabel.Text = MirEnvir.Envir.LoadVersion.ToString() + ((MirEnvir.Envir.LoadVersion < MirEnvir.Envir.Version) ? " (Update needed)" : "");
  39. maxConnectionsPerIP.Text = Settings.MaxIP.ToString();
  40. expRateInput.Value = Math.Round((decimal)Settings.ExpRate, 2);
  41. dropRateInput.Value = Math.Round((decimal)Settings.DropRate, 2);
  42. tbRestedPeriod.Text = Settings.RestedPeriod.ToString();
  43. tbRestedBuffLength.Text = Settings.RestedBuffLength.ToString();
  44. tbRestedExpBonus.Text = Settings.RestedExpBonus.ToString();
  45. tbMaxRestedBonus.Text = Settings.RestedMaxBonus.ToString();
  46. }
  47. private void ConfigForm_FormClosed(object sender, FormClosedEventArgs e)
  48. {
  49. Settings.Save();
  50. Settings.LoadVersion();
  51. }
  52. private void SaveButton_Click(object sender, EventArgs e)
  53. {
  54. Save();
  55. Close();
  56. }
  57. public void Save()
  58. {
  59. Settings.VersionPath = VPathTextBox.Text;
  60. Settings.CheckVersion = VersionCheckBox.Checked;
  61. IPAddress tempIP;
  62. if (IPAddress.TryParse(IPAddressTextBox.Text, out tempIP))
  63. Settings.IPAddress = tempIP.ToString();
  64. Settings.StartHTTPService = StartHTTPCheckBox.Checked;
  65. if (tryParseHttp())
  66. Settings.HTTPIPAddress = HTTPIPAddressTextBox.Text.ToString();
  67. if (tryParseTrustedHttp())
  68. Settings.HTTPTrustedIPAddress = HTTPTrustedIPAddressTextBox.Text.ToString();
  69. ushort tempshort;
  70. int tempint;
  71. if (ushort.TryParse(PortTextBox.Text, out tempshort))
  72. Settings.Port = tempshort;
  73. if (ushort.TryParse(TimeOutTextBox.Text, out tempshort))
  74. Settings.TimeOut = tempshort;
  75. if (ushort.TryParse(MaxUserTextBox.Text, out tempshort))
  76. Settings.MaxUser = tempshort;
  77. if (ushort.TryParse(RelogDelayTextBox.Text, out tempshort))
  78. Settings.RelogDelay = tempshort;
  79. if (ushort.TryParse(SaveDelayTextBox.Text, out tempshort))
  80. Settings.SaveDelay = tempshort;
  81. Settings.AllowNewAccount = AccountCheckBox.Checked;
  82. Settings.AllowChangePassword = PasswordCheckBox.Checked;
  83. Settings.AllowLogin = LoginCheckBox.Checked;
  84. Settings.AllowNewCharacter = NCharacterCheckBox.Checked;
  85. Settings.AllowDeleteCharacter = DCharacterCheckBox.Checked;
  86. Settings.AllowStartGame = StartGameCheckBox.Checked;
  87. Settings.AllowCreateAssassin = AllowAssassinCheckBox.Checked;
  88. Settings.AllowCreateArcher = AllowArcherCheckBox.Checked;
  89. Settings.RequireStoragePassword = WarehousePasswordCheckBox.Checked;
  90. Settings.AllowObserve = ObserveCheckBox.Checked;
  91. if (int.TryParse(Resolution_textbox.Text, out tempint))
  92. Settings.AllowedResolution = tempint;
  93. Settings.SafeZoneBorder = SafeZoneBorderCheckBox.Checked;
  94. Settings.SafeZoneHealing = SafeZoneHealingCheckBox.Checked;
  95. Settings.GameMasterEffect = gameMasterEffect_CheckBox.Checked;
  96. if (int.TryParse(lineMessageTimeTextBox.Text, out tempint))
  97. Settings.LineMessageTimer = tempint;
  98. if (ushort.TryParse(maxConnectionsPerIP.Text, out tempshort))
  99. Settings.MaxIP = tempshort;
  100. Settings.ExpRate = (float)expRateInput.Value;
  101. Settings.DropRate = (float)dropRateInput.Value;
  102. Settings.RestedPeriod = Convert.ToInt32(tbRestedPeriod.Text);
  103. Settings.RestedBuffLength = Convert.ToInt32(tbRestedBuffLength.Text);
  104. Settings.RestedExpBonus = Convert.ToInt32(tbRestedExpBonus.Text);
  105. Settings.RestedMaxBonus = Convert.ToInt32(tbMaxRestedBonus.Text);
  106. }
  107. private void IPAddressCheck(object sender, EventArgs e)
  108. {
  109. if (ActiveControl != sender) return;
  110. IPAddress temp;
  111. ActiveControl.BackColor = !IPAddress.TryParse(ActiveControl.Text, out temp) ? Color.Red : SystemColors.Window;
  112. }
  113. private void CheckUShort(object sender, EventArgs e)
  114. {
  115. if (ActiveControl != sender) return;
  116. ushort temp;
  117. ActiveControl.BackColor = !ushort.TryParse(ActiveControl.Text, out temp) ? Color.Red : SystemColors.Window;
  118. }
  119. private void VPathBrowseButton_Click(object sender, EventArgs e)
  120. {
  121. if (VPathDialog.ShowDialog() == DialogResult.OK)
  122. {
  123. VPathTextBox.Text = string.Join(",", VPathDialog.FileNames);
  124. }
  125. }
  126. private void Resolution_textbox_TextChanged(object sender, EventArgs e)
  127. {
  128. if (ActiveControl != sender) return;
  129. int temp;
  130. ActiveControl.BackColor = !int.TryParse(ActiveControl.Text, out temp) ? Color.Red : SystemColors.Window;
  131. }
  132. private void tabPage3_Click(object sender, EventArgs e)
  133. {
  134. }
  135. private void SafeZoneBorderCheckBox_CheckedChanged(object sender, EventArgs e)
  136. {
  137. }
  138. private void SafeZoneHealingCheckBox_CheckedChanged(object sender, EventArgs e)
  139. {
  140. }
  141. private void HTTPIPAddressTextBox_TextChanged(object sender, EventArgs e)
  142. {
  143. if (ActiveControl != sender) return;
  144. ActiveControl.BackColor = !tryParseHttp() ? Color.Red : SystemColors.Window;
  145. }
  146. private void HTTPTrustedIPAddressTextBox_TextChanged(object sender, EventArgs e)
  147. {
  148. if (ActiveControl != sender) return;
  149. ActiveControl.BackColor = !tryParseTrustedHttp() ? Color.Red : SystemColors.Window;
  150. }
  151. bool tryParseHttp()
  152. {
  153. if ((HTTPIPAddressTextBox.Text.StartsWith("http://") || HTTPIPAddressTextBox.Text.StartsWith("https://")) && HTTPIPAddressTextBox.Text.EndsWith("/"))
  154. {
  155. return true;
  156. }
  157. return false;
  158. }
  159. bool tryParseTrustedHttp()
  160. {
  161. string pattern = @"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}";
  162. return Regex.IsMatch(HTTPTrustedIPAddressTextBox.Text, pattern);
  163. }
  164. private void StartHTTPCheckBox_CheckedChanged(object sender, EventArgs e)
  165. {
  166. Settings.StartHTTPService = StartHTTPCheckBox.Checked;
  167. }
  168. private void expRateInput_KeyPress(object sender, KeyPressEventArgs e)
  169. {
  170. if (e.KeyChar == ',')
  171. e.Handled = true;
  172. }
  173. private void dropRateInput_KeyPress(object sender, KeyPressEventArgs e)
  174. {
  175. if (e.KeyChar == ',')
  176. e.Handled = true;
  177. }
  178. private void expRateInput_ValueChanged(object sender, EventArgs e)
  179. {
  180. expRateInput.Value = Math.Round(expRateInput.Value, 2);
  181. }
  182. private void dropRateInput_ValueChanged(object sender, EventArgs e)
  183. {
  184. dropRateInput.Value = Math.Round(dropRateInput.Value, 2);
  185. }
  186. private void tbRestedPeriod_KeyPress(object sender, KeyPressEventArgs e)
  187. {
  188. if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
  189. e.Handled = true;
  190. }
  191. private void tbRestedBuffLength_KeyPress(object sender, KeyPressEventArgs e)
  192. {
  193. if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
  194. e.Handled = true;
  195. }
  196. private void tbRestedExpBonus_KeyPress(object sender, KeyPressEventArgs e)
  197. {
  198. if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
  199. e.Handled = true;
  200. }
  201. private void tbMaxRestedBonus_KeyPress(object sender, KeyPressEventArgs e)
  202. {
  203. if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
  204. e.Handled = true;
  205. }
  206. #region Drop Adjuster
  207. private Envir Envir => SMain.EditEnvir;
  208. private void ProcessFiles(RequiredClass targetClass, bool comment)
  209. {
  210. string dropPath = Path.Combine(Application.StartupPath, "Envir", "Drops");
  211. if (!Directory.Exists(dropPath))
  212. {
  213. MessageBox.Show("Drops directory not found!");
  214. return;
  215. }
  216. try
  217. {
  218. var itemLookup = Envir.ItemInfoList.ToLookup(
  219. i => i.Name.Trim(),
  220. StringComparer.OrdinalIgnoreCase
  221. );
  222. int totalModified = 0;
  223. foreach (string filePath in Directory.GetFiles(dropPath, "*.txt", SearchOption.AllDirectories))
  224. {
  225. var lines = File.ReadAllLines(filePath);
  226. bool modified = false;
  227. for (int i = 0; i < lines.Length; i++)
  228. {
  229. string originalLine = lines[i].Trim();
  230. if (string.IsNullOrWhiteSpace(originalLine)) continue;
  231. bool isCommented = originalLine.StartsWith(";");
  232. string workingLine = isCommented ? originalLine.Substring(1).TrimStart() : originalLine;
  233. string itemName = workingLine.Split()
  234. .Select(part => part.Trim())
  235. .FirstOrDefault(part => itemLookup.Contains(part));
  236. if (string.IsNullOrEmpty(itemName)) continue;
  237. foreach (ItemInfo item in itemLookup[itemName])
  238. {
  239. if (item.RequiredClass == RequiredClass.None) continue;
  240. if (!item.RequiredClass.HasFlag(targetClass)) continue;
  241. if (comment && !isCommented)
  242. {
  243. lines[i] = ";" + lines[i];
  244. modified = true;
  245. totalModified++;
  246. }
  247. else if (!comment && isCommented)
  248. {
  249. lines[i] = workingLine;
  250. modified = true;
  251. totalModified++;
  252. }
  253. break;
  254. }
  255. }
  256. if (modified)
  257. {
  258. File.WriteAllLines(filePath, lines);
  259. }
  260. }
  261. MessageBox.Show($"Processed files. Modified {totalModified} entries.");
  262. }
  263. catch (Exception ex)
  264. {
  265. MessageBox.Show($"Error: {ex.Message}");
  266. }
  267. }
  268. private void RemoveSinDrops_Click(object sender, EventArgs e)
  269. {
  270. ProcessFiles(RequiredClass.Assassin, true);
  271. }
  272. private void ReaddSinDrops_Click(object sender, EventArgs e)
  273. {
  274. ProcessFiles(RequiredClass.Assassin, false);
  275. }
  276. private void RemoveArcDrops_Click(object sender, EventArgs e)
  277. {
  278. ProcessFiles(RequiredClass.Archer, true);
  279. }
  280. private void ReaddArcDrops_Click(object sender, EventArgs e)
  281. {
  282. ProcessFiles(RequiredClass.Archer, false);
  283. }
  284. #endregion
  285. private void VersionCheckBox_CheckedChanged(object sender, EventArgs e)
  286. {
  287. Settings.CheckVersion = VersionCheckBox.Checked;
  288. }
  289. }
  290. }