| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- #include "Win32.h"
- #include "Config.h"
- #include "Function.h"
- #include "SharedValue.h"
- #include <vector>
- //basic
- static std::vector<std::string> ConfigRead()
- {
- std::ifstream read("server.properties");
- Err(&read, _T("打开配置文件失败"));
- std::vector<std::string> configs;
- std::string config;
- while (getline(read, config))
- {
- configs.push_back(config);
- }
- read.close();
- return configs;
- }
- static void ConfigWrite(std::vector<std::string> &configText)
- {
- std::ofstream write("server.properties", std::ios::out);
- Err(&write, _T("写入配置文件失败"));
- for (const auto& in : configText)
- {
- write << in << "\n";
- }
- write.close();
- }
- //normal
- static void ConfigSet_EDIT(std::vector<std::string> &configText, HWND hWnd1, std::string target, int id)
- {
- char newText[1024] = { 0 };
- GetWindowTextA(GetDlgItem(hWnd1, id), newText, 1024);
- if (newText != "不修改")
- {
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + '=' + newText;
- }
- return;
- }
- }
- }
- static void ConfigSet_CHECK_1(std::vector<std::string>& configText, HWND hWnd1, std::string target, int id, int no_id)
- {
- if (IsDlgButtonChecked(hWnd1, no_id) != BST_CHECKED)
- {
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- if(IsDlgButtonChecked(hWnd1, id) == BST_CHECKED)
- l = target + "=true";
- else l = target + "=false";
- return;
- }
- }
- }
- }
- static void ConfigSet_CHECK_2(std::vector<std::string>& configText, HWND hWnd1, std::string target, int id, int no_id)
- {
- if (IsDlgButtonChecked(hWnd1, no_id) != BST_CHECKED)
- {
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- if (IsDlgButtonChecked(hWnd1, id) == BST_CHECKED)
- l = target + "=false";
- else l = target + "=true";
- return;
- }
- }
- }
- }
- //DIY
- static void ConfigSet_CheckDIY_Mute(std::vector<std::string>& configText, HWND hWnd1, std::string target, int id, int no_id)
- {
- if (IsDlgButtonChecked(hWnd1, no_id) != BST_CHECKED)
- {
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- if (IsDlgButtonChecked(hWnd1, id) == BST_CHECKED)
- l = target + "=Disabled";
- else l = target + "=None";
- return;
- }
- }
- }
- }
- static void ConfigSet_CheckDIY_AntiCheat(std::vector<std::string>& configText, HWND hWnd1)
- {
- if (IsDlgButtonChecked(hWnd1, CONF_AntiCheat_NOEDIT) != BST_CHECKED)
- {
- std::string targetA = "server-authoritative-movement-strict",
- targetB = "server-authoritative-dismount-strict",
- targetC = "server-authoritative-entity-interactions-strict";
- for (auto& l : configText)
- {
- bool check = (IsDlgButtonChecked(hWnd1, CONF_AntiCheat) == BST_CHECKED);
- if (l.find(targetA) != std::string::npos)
- {
- if(check)
- l = targetA + "=true";
- else l = targetA + "=false";
- }
- if (l.find(targetB) != std::string::npos)
- {
- if (check)
- l = targetB + "=true";
- else l = targetB + "=false";
- }
- if (l.find(targetC) != std::string::npos)
- {
- if (check)
- l = targetC + "=true";
- else l = targetC + "=false";
- }
- }
- }
- }
- static void ConfigSet_ComboDIY_Gamemode(std::vector<std::string>& configText, HWND hWnd1)
- {
- int selected = SendMessage(hGamemode, CB_GETCURSEL, 0, 0);
- std::string target;
- switch (selected)
- {
- case 0:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- case 1:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- case 2:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- case 3:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- }
- }
- static void ConfigSet_ComboDIY_Difficuty(std::vector<std::string>& configText, HWND hWnd1)
- {
- int selected = SendMessage(hDifficulty, CB_GETCURSEL, 0, 0);
- std::string target;
- switch (selected)
- {
- case 0:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- case 1:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- case 2:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- case 3:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- case 4:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- }
- }
- static void ConfigSet_ComboDIY_Level(std::vector<std::string>& configText, HWND hWnd1)
- {
- int selected = SendMessage(hPermission, CB_GETCURSEL, 0, 0);
- std::string target;
- switch (selected)
- {
- case 0:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- case 1:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- case 2:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- case 3:
- for (auto& l : configText)
- {
- if (l.find(target) != std::string::npos)
- {
- l = target + "=";
- return;
- }
- }
- break;
- }
- }
- //whole
- void Submit(HWND hWnd1)
- {
- std::vector<std::string> configText = ConfigRead();
- //EDIT
- ConfigSet_EDIT(configText, hWnd1,
- "server-name", CONF_ServerName);
- ConfigSet_EDIT(configText, hWnd1,
- "level-name", CONF_LevelName);
- ConfigSet_EDIT(configText, hWnd1,
- "level-seed", CONF_LevelSeed);
- ConfigSet_EDIT(configText, hWnd1,
- "max-players", CONF_MaxPlayer);
-
- //CHECK
- ConfigSet_CHECK_1(configText, hWnd1,
- "allow-cheats", CONF_Cheat, CONF_Cheat_NOEDIT);
- ConfigSet_CHECK_1(configText, hWnd1,
- "online-mode", CONF_OnlineMode, CONF_OnlineMode_NOEDIT);
- ConfigSet_CHECK_1(configText, hWnd1,
- "enable-lan-visibility", CONF_LanVisible, CONF_LanVisible_NOEDIT);
- ConfigSet_CHECK_1(configText, hWnd1,
- "allow-list", CONF_Whitelist, CONF_Whitelist_NOEDIT);
- ConfigSet_CHECK_1(configText, hWnd1,
- "texturepack-required", CONF_FroceTexture, CONF_FroceTexture_NOEDIT);
- ConfigSet_CHECK_1(configText, hWnd1,
- "disable-custom-skins", CONF_BanSkin, CONF_BanSkin_NOEDIT);
- //CheckDIY
- ConfigSet_CheckDIY_Mute(configText, hWnd1,
- "chat-restriction", CONF_Mute, CONF_Mute_NOEDIT);
- ConfigSet_CheckDIY_AntiCheat(configText, hWnd1);
- //ComboDIY
- ConfigSet_ComboDIY_Gamemode(configText, hWnd1);
- ConfigSet_ComboDIY_Difficuty(configText, hWnd1);
- ConfigSet_ComboDIY_Level(configText, hWnd1);
- //submit
- ConfigWrite(configText);
- MessageBox(hWnd,
- L"已尝试提交", TITLE,
- MB_OK);
- }
|