Skip to content

Commit

Permalink
Beta37 (#95)
Browse files Browse the repository at this point in the history
* beta9

* beta11

* beta11

* beta13

* beta12

* beta13

* beta15

* beta16

* beta17

* beta18

* beta19

* beta20

* beta21

* add_playermanager_api

* beta22

* beta23

* beta24

* beta25

* beta26

* beta27

* beta28

* beta28

* beta29

* beta30

* beta31

* beta32

* beta33

* beta34

* beta35

* beta35

* beta36

* beta37
  • Loading branch information
Hoshinonyaruko authored Feb 18, 2024
1 parent 67f74f7 commit 39bc31c
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 87 deletions.
111 changes: 98 additions & 13 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type Config struct {
WhiteCheckTime int `json:"whiteCheckTime"` // 白名单检测时间
SaveDeleteDays int `json:"saveDeleteDays"` // 存档删除时间
SteamCmdPath string `json:"steamCmdPath"` // 自定义steamcmd路径
EnableUe4Debug bool `json:"enableUe4Debug"` // 是否开启UE4 Debug窗口
EnableEngineSetting bool `json:"enableEngineSetting"` // 是否开启引擎设置
}

// 默认配置
Expand All @@ -83,6 +85,8 @@ var defaultConfig = Config{
CheckInterval: 30, // 30 秒
WebuiPort: "52000", // Webui 端口号
AutolaunchWebui: true,
EnableUe4Debug: false,
EnableEngineSetting: true,
BackupInterval: 1800, // 30 分钟
MemoryCheckInterval: 30, // 30 秒
MemoryUsageThreshold: 80, // 80%
Expand Down Expand Up @@ -432,23 +436,31 @@ func AutoConfigurePaths(config *Config) error {
return err
}
}
engine, err := ReadEngineSettings(config)
if err != nil {
log.Printf("解析游戏engine.ini出错,错误%v", err)
if config.EnableEngineSetting {
engine, err := ReadEngineSettings(config)
if err != nil {
log.Printf("解析游戏engine.ini出错,错误%v", err)

} else {
config.Engine = engine
log.Println("从游戏engine.ini解析配置成功.")
log.Printf("从游戏engine.ini解析配置成功.%v", config.Engine)
} else {
config.Engine = engine
log.Println("从游戏engine.ini解析配置成功.")
log.Printf("从游戏engine.ini解析配置成功.%v", config.Engine)

// 将更新后的配置写回文件
updatedConfig, err := json.MarshalIndent(config, "", " ")
if err != nil {
return err
// 将更新后的配置写回文件
updatedConfig, err := json.MarshalIndent(config, "", " ")
if err != nil {
return err
}
err = os.WriteFile("config.json", updatedConfig, 0644)
if err != nil {
return err
}
}
err = os.WriteFile("config.json", updatedConfig, 0644)
} else {
// 调用RemoveEngineSettings函数
err := RemoveEngineSettings(config)
if err != nil {
return err
log.Printf("从游戏engine.ini删除配置失败.%v\n", err)
}
}

Expand Down Expand Up @@ -846,6 +858,43 @@ func WriteEngineSettings(config *Config, engine *Engine) error {
return os.WriteFile(iniPath, []byte(content), 0644)
}

// RemoveEngineSettings 从INI文件中删除Engine结构体的数据
func RemoveEngineSettings(config *Config) error {
var iniPath string

// 根据操作系统选择不同的路径
switch runtime.GOOS {
case "windows":
iniPath = filepath.Join(config.GameSavePath, "Config", "WindowsServer", "Engine.ini")
case "linux":
iniPath = filepath.Join(config.GameSavePath, "Config", "LinuxServer", "Engine.ini")
default:
iniPath = filepath.Join(config.GameSavePath, "Config", "LinuxServer", "Engine.ini")
}

// 读取INI文件的所有内容
fileContent, err := ioutil.ReadFile(iniPath)
if err != nil {
return err
}

// 将文件内容转换为字符串
content := string(fileContent)

// 定义要删除的节的列表
sectionsToRemove := []string{
"/script/engine.player",
"/script/socketsubsystemepic.epicnetdriver",
"/script/engine.engine",
}

// 删除指定的节
updatedContent := removeIniSections(content, sectionsToRemove)

// 将更新后的内容写回文件
return os.WriteFile(iniPath, []byte(updatedContent), 0644)
}

// updateIniSection 更新或添加INI文件中的特定section
func updateIniSection(content, sectionName string, data interface{}) string {
// 将结构体转换为键值对映射
Expand Down Expand Up @@ -967,3 +1016,39 @@ func structToMap(data interface{}) map[string]string {

return kvMap
}

// removeIniSections 从INI文件内容中删除指定的节
func removeIniSections(content string, sectionsToRemove []string) string {
var lines = strings.Split(content, "\n")
var updatedLines []string
var inSectionToRemove bool

for _, line := range lines {
trimmedLine := strings.TrimSpace(line)
// 检查当前行是否标记了新的节的开始
if strings.HasPrefix(trimmedLine, "[") && strings.HasSuffix(trimmedLine, "]") {
sectionName := trimmedLine[1 : len(trimmedLine)-1] // 移除括号获取节名
inSectionToRemove = contains(sectionsToRemove, sectionName)
if !inSectionToRemove {
// 如果当前节不在要删除的列表中,保留这一行
updatedLines = append(updatedLines, line)
}
} else if !inSectionToRemove {
// 如果当前不在要删除的节中,保留这一行
updatedLines = append(updatedLines, line)
}
// 如果inSectionToRemove为true,则自动跳过这一行,不将其添加到updatedLines中
}

return strings.Join(updatedLines, "\n")
}

// contains 检查字符串切片中是否包含特定的字符串
func contains(slice []string, val string) bool {
for _, item := range slice {
if item == val {
return true
}
}
return false
}
24 changes: 23 additions & 1 deletion front/palworld-front/src/pages/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
@click="restartServer"
class="q-mt-md"
/>
<!-- 答疑按钮 -->
<q-btn
color="secondary"
label="遇到问题,答疑按钮"
@click="getGroupLink"
class="q-mt-md"
/>
<!-- 文本输入框 -->
<q-input
filled
Expand Down Expand Up @@ -69,14 +76,24 @@
/>
<q-toggle
v-model="config.useDll"
label="自动注入UE4SS和可输入命令控制台DLL"
label="自动注入UE4SS和可输入命令控制台DLL(发中文rcon)"
class="q-my-md"
/>
<q-toggle
v-model="config.gameService"
label="是否采用systemctl方式管理游戏服务"
class="q-my-md"
/>
<q-toggle
v-model="config.enableUe4Debug"
label="是否开启UE4窗口(关闭可以解决闪退,内存占用问题)"
class="q-my-md"
/>
<q-toggle
v-model="config.enableEngineSetting"
label="是否启用引擎配置,部分电脑修改引擎配置会卡顿,可关闭"
class="q-my-md"
/>
<q-input
filled
v-model="config.maintenanceWarningMessage"
Expand Down Expand Up @@ -1266,6 +1283,11 @@ const fillCommand = (cmd) => {
//服务器检测
const getGroupLink = () => {
window.location.href =
'https://qm.qq.com/cgi-bin/qm/qr?k=7aDJFyxLC6a450LMZfzG9Q1lwWy2veQj&jump_from=webapi&authKey=Im38dkervx6ISKg78NudQZgZnZv/O4bmb8f8CFrgMmJKY+MH5LsVNJ+KdJB5byY1';
};
async function updateStatus() {
try {
// 移除了 $q.loadingBar 的调用
Expand Down
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,14 @@ func main() {
} else {
fmt.Println("Game world settings saved successfully.")
}
//保存引擎配置
err = config.WriteEngineSettings(&jsonconfig, jsonconfig.Engine)
if err != nil {
fmt.Println("Error writing Engine settings:", err)
} else {
fmt.Println("Engine settings saved successfully.")
if jsonconfig.EnableEngineSetting {
//保存引擎配置
err = config.WriteEngineSettings(&jsonconfig, jsonconfig.Engine)
if err != nil {
fmt.Println("Error writing Engine settings:", err)
} else {
fmt.Println("Engine settings saved successfully.")
}
}
}
}()
Expand Down
Binary file modified mod/embeds/UE4SS.dll
Binary file not shown.
Binary file added mod/embeds/dwmapi.dll
Binary file not shown.
32 changes: 32 additions & 0 deletions sys/restart_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ func RestartService(config config.Config) {
log.Printf("Failed to write files: %v", err)
return
}
// 调用ConfigureUE4DebugSettings
err = ConfigureUE4DebugSettings(config.GamePath, config.EnableUe4Debug)
if err != nil {
log.Printf("Failed to configure UE4 debug settings: %v", err)
return
}
exePath = filepath.Join(config.GamePath, "Pal", "Binaries", "Win64", "PalServerInject.exe")
args = []string{
"-RconEnabled=True",
Expand Down Expand Up @@ -265,3 +271,29 @@ func RestartService(config config.Config) {
}

}

// ConfigureUE4DebugSettings 根据config.EnableUe4Debug的值配置UE4SS-settings.ini文件
func ConfigureUE4DebugSettings(gamePath string, enableDebug bool) error {
iniPath := filepath.Join(gamePath, "Pal", "Binaries", "Win64", "UE4SS-settings.ini")
cfg, err := ini.Load(iniPath)
if err != nil {
return fmt.Errorf("failed to load INI file: %v", err)
}

// 根据enableDebug的值设置对应的配置项
debugVal := 0
if enableDebug {
debugVal = 1
}

cfg.Section("Debug").Key("ConsoleEnabled").SetValue(fmt.Sprintf("%d", 1)) //开启console输出
cfg.Section("Debug").Key("GuiConsoleEnabled").SetValue(fmt.Sprintf("%d", debugVal))
cfg.Section("Debug").Key("GuiConsoleVisible").SetValue(fmt.Sprintf("%d", debugVal))

// 保存更改
if err := cfg.SaveTo(iniPath); err != nil {
return fmt.Errorf("failed to save INI file: %v", err)
}

return nil
}
14 changes: 8 additions & 6 deletions webui/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,14 @@ func HandleSaveJSON(c *gin.Context, cfg config.Config) {
} else {
fmt.Println("Game world settings saved successfully.")
}

err = config.WriteEngineSettings(&newConfig, newConfig.Engine)
if err != nil {
fmt.Println("Error writing Engine settings:", err)
} else {
fmt.Println("Engine settings saved successfully.")
// 写引擎配置
if newConfig.EnableEngineSetting {
err = config.WriteEngineSettings(&newConfig, newConfig.Engine)
if err != nil {
fmt.Println("Error writing Engine settings:", err)
} else {
fmt.Println("Engine settings saved successfully.")
}
}

c.JSON(http.StatusOK, gin.H{"message": "Config updated successfully"})
Expand Down
61 changes: 0 additions & 61 deletions webui/dist2/assets/index-GfMuE0Qm.js

This file was deleted.

61 changes: 61 additions & 0 deletions webui/dist2/assets/index-PXu6TukB.js

Large diffs are not rendered by default.

0 comments on commit 39bc31c

Please sign in to comment.