config.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #include "Win32.h"
  2. #include "Config.h"
  3. #include "Function.h"
  4. #include "SharedValue.h"
  5. #include <vector>
  6. void Update(HWND hWnd1, int id, int id1 )
  7. {
  8. if (wmEvent == BN_CLICKED && wmId == id)
  9. SendMessage(GetDlgItem(hWnd1,id1), BM_SETCHECK, BST_UNCHECKED, 0);
  10. }
  11. //basic
  12. static std::vector<std::string> ConfigRead()
  13. {
  14. std::ifstream read("server.properties");
  15. Err(&read, _T("打开配置文件失败"));
  16. std::vector<std::string> configs;
  17. std::string config;
  18. while (getline(read, config))
  19. {
  20. configs.push_back(config);
  21. }
  22. read.close();
  23. return configs;
  24. }
  25. static void ConfigWrite(std::vector<std::string> &configText)
  26. {
  27. std::ofstream write("server.properties", std::ios::out);
  28. Err(&write, _T("写入配置文件失败"));
  29. for (const auto& in : configText)
  30. {
  31. write << in << "\n";
  32. }
  33. write.close();
  34. }
  35. //normal
  36. static void ConfigSet_EDIT(std::vector<std::string> &configText, HWND hWnd1, std::string target, int id)
  37. {
  38. char newText[1024] = { 0 };
  39. GetWindowTextA(GetDlgItem(hWnd1, id), newText, 1024);
  40. if (std::string(newText) != "不修改")
  41. {
  42. for (auto& l : configText)
  43. {
  44. if (l.find(target) != std::string::npos)
  45. {
  46. l = target + '=' + newText;
  47. return;
  48. }
  49. }
  50. }
  51. }
  52. static void ConfigSet_CHECK_1(std::vector<std::string>& configText, HWND hWnd1, std::string target, int id, int no_id)
  53. {
  54. if (IsDlgButtonChecked(hWnd1, no_id) != BST_CHECKED)
  55. {
  56. for (auto& l : configText)
  57. {
  58. if (l.find(target) != std::string::npos)
  59. {
  60. if(IsDlgButtonChecked(hWnd1, id) == BST_CHECKED)
  61. l = target + "=true";
  62. else l = target + "=false";
  63. return;
  64. }
  65. }
  66. }
  67. }
  68. static void ConfigSet_CHECK_2(std::vector<std::string>& configText, HWND hWnd1, std::string target, int id, int no_id)
  69. {
  70. if (IsDlgButtonChecked(hWnd1, no_id) != BST_CHECKED)
  71. {
  72. for (auto& l : configText)
  73. {
  74. if (l.find(target) != std::string::npos)
  75. {
  76. if (IsDlgButtonChecked(hWnd1, id) == BST_CHECKED)
  77. l = target + "=false";
  78. else l = target + "=true";
  79. return;
  80. }
  81. }
  82. }
  83. }
  84. //DIY
  85. static void ConfigSet_CheckDIY_Mute(std::vector<std::string>& configText, HWND hWnd1, std::string target, int id, int no_id)
  86. {
  87. if (IsDlgButtonChecked(hWnd1, no_id) != BST_CHECKED)
  88. {
  89. for (auto& l : configText)
  90. {
  91. if (l.find(target) != std::string::npos)
  92. {
  93. if (IsDlgButtonChecked(hWnd1, id) == BST_CHECKED)
  94. l = target + "=Disabled";
  95. else l = target + "=None";
  96. return;
  97. }
  98. }
  99. }
  100. }
  101. static void ConfigSet_CheckDIY_AntiCheat(std::vector<std::string>& configText, HWND hWnd1)
  102. {
  103. if (IsDlgButtonChecked(hWnd1, CONF_AntiCheat_NOEDIT) != BST_CHECKED)
  104. {
  105. std::string targetA = "server-authoritative-movement-strict",
  106. targetB = "server-authoritative-dismount-strict",
  107. targetC = "server-authoritative-entity-interactions-strict";
  108. for (auto& l : configText)
  109. {
  110. bool check = (IsDlgButtonChecked(hWnd1, CONF_AntiCheat) == BST_CHECKED);
  111. if (l.find(targetA) != std::string::npos)
  112. {
  113. if(check)
  114. l = targetA + "=true";
  115. else l = targetA + "=false";
  116. }
  117. if (l.find(targetB) != std::string::npos)
  118. {
  119. if (check)
  120. l = targetB + "=true";
  121. else l = targetB + "=false";
  122. }
  123. if (l.find(targetC) != std::string::npos)
  124. {
  125. if (check)
  126. l = targetC + "=true";
  127. else l = targetC + "=false";
  128. }
  129. }
  130. }
  131. }
  132. static void ConfigSet_ComboDIY_Gamemode(std::vector<std::string>& configText, HWND hWnd1)
  133. {
  134. int selected = SendMessage(hGamemode, CB_GETCURSEL, 0, 0);
  135. std::string target = "gamemode";
  136. switch (selected)
  137. {
  138. case 1:
  139. for (auto& l : configText)
  140. {
  141. if (l.find(target) != std::string::npos)
  142. {
  143. l = target + "=adventure";
  144. return;
  145. }
  146. }
  147. break;
  148. case 2:
  149. for (auto& l : configText)
  150. {
  151. if (l.find(target) != std::string::npos)
  152. {
  153. l = target + "=survival";
  154. return;
  155. }
  156. }
  157. break;
  158. case 3:
  159. for (auto& l : configText)
  160. {
  161. if (l.find(target) != std::string::npos)
  162. {
  163. l = target + "=creative";
  164. return;
  165. }
  166. }
  167. break;
  168. }
  169. }
  170. static void ConfigSet_ComboDIY_Difficuty(std::vector<std::string>& configText, HWND hWnd1)
  171. {
  172. int selected = SendMessage(hDifficulty, CB_GETCURSEL, 0, 0);
  173. std::string target = "difficulty";
  174. switch (selected)
  175. {
  176. case 1:
  177. for (auto& l : configText)
  178. {
  179. if (l.find(target) != std::string::npos)
  180. {
  181. l = target + "=peaceful";
  182. return;
  183. }
  184. }
  185. break;
  186. case 2:
  187. for (auto& l : configText)
  188. {
  189. if (l.find(target) != std::string::npos)
  190. {
  191. l = target + "=easy";
  192. return;
  193. }
  194. }
  195. break;
  196. case 3:
  197. for (auto& l : configText)
  198. {
  199. if (l.find(target) != std::string::npos)
  200. {
  201. l = target + "=normal";
  202. return;
  203. }
  204. }
  205. break;
  206. case 4:
  207. for (auto& l : configText)
  208. {
  209. if (l.find(target) != std::string::npos)
  210. {
  211. l = target + "=hard";
  212. return;
  213. }
  214. }
  215. break;
  216. }
  217. }
  218. static void ConfigSet_ComboDIY_Level(std::vector<std::string>& configText, HWND hWnd1)
  219. {
  220. int selected = SendMessage(hPermission, CB_GETCURSEL, 0, 0);
  221. std::string target = "default-player-permission-level";
  222. switch (selected)
  223. {
  224. case 1:
  225. for (auto& l : configText)
  226. {
  227. if (l.find(target) != std::string::npos)
  228. {
  229. l = target + "=visitor";
  230. return;
  231. }
  232. }
  233. break;
  234. case 2:
  235. for (auto& l : configText)
  236. {
  237. if (l.find(target) != std::string::npos)
  238. {
  239. l = target + "=member";
  240. return;
  241. }
  242. }
  243. break;
  244. case 3:
  245. for (auto& l : configText)
  246. {
  247. if (l.find(target) != std::string::npos)
  248. {
  249. l = target + "=operator";
  250. return;
  251. }
  252. }
  253. break;
  254. }
  255. }
  256. //whole
  257. void Submit(HWND hWnd1)
  258. {
  259. std::vector<std::string> configText = ConfigRead();
  260. //EDIT
  261. ConfigSet_EDIT(configText, hWnd1,
  262. "server-name", CONF_ServerName);
  263. ConfigSet_EDIT(configText, hWnd1,
  264. "level-name", CONF_LevelName);
  265. ConfigSet_EDIT(configText, hWnd1,
  266. "level-seed", CONF_LevelSeed);
  267. ConfigSet_EDIT(configText, hWnd1,
  268. "max-players", CONF_MaxPlayer);
  269. //CHECK
  270. ConfigSet_CHECK_1(configText, hWnd1,
  271. "allow-cheats", CONF_Cheat, CONF_Cheat_NOEDIT);
  272. ConfigSet_CHECK_1(configText, hWnd1,
  273. "online-mode", CONF_OnlineMode, CONF_OnlineMode_NOEDIT);
  274. ConfigSet_CHECK_1(configText, hWnd1,
  275. "enable-lan-visibility", CONF_LanVisible, CONF_LanVisible_NOEDIT);
  276. ConfigSet_CHECK_1(configText, hWnd1,
  277. "allow-list", CONF_Whitelist, CONF_Whitelist_NOEDIT);
  278. ConfigSet_CHECK_1(configText, hWnd1,
  279. "texturepack-required", CONF_FroceTexture, CONF_FroceTexture_NOEDIT);
  280. ConfigSet_CHECK_1(configText, hWnd1,
  281. "disable-custom-skins", CONF_BanSkin, CONF_BanSkin_NOEDIT);
  282. //CheckDIY
  283. ConfigSet_CheckDIY_Mute(configText, hWnd1,
  284. "chat-restriction", CONF_Mute, CONF_Mute_NOEDIT);
  285. ConfigSet_CheckDIY_AntiCheat(configText, hWnd1);
  286. //ComboDIY
  287. ConfigSet_ComboDIY_Gamemode(configText, hWnd1);
  288. ConfigSet_ComboDIY_Difficuty(configText, hWnd1);
  289. ConfigSet_ComboDIY_Level(configText, hWnd1);
  290. //submit
  291. ConfigWrite(configText);
  292. MessageBox(hWnd,
  293. L"已尝试提交", TITLE,
  294. MB_OK);
  295. }