Skip to content

Commit

Permalink
Merge a44ef68 into a618189
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko authored Feb 6, 2024
2 parents a618189 + a44ef68 commit 46978a9
Show file tree
Hide file tree
Showing 10 changed files with 489 additions and 37 deletions.
30 changes: 28 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Config struct {
SteamPath string `json:"steamPath"` // steam路径
CommunityServer bool `json:"communityServer"` // 社区服务器开关
UseDll bool `json:"useDll"` // dll注入
DllPort string `json:"dllPort"` // dll通信port
Cert string `json:"cert"` // 证书
Key string `json:"key"` // 密钥
Address string `json:"address"` // 服务器 IP 地址
Expand Down Expand Up @@ -70,6 +71,7 @@ var defaultConfig = Config{
ProcessName: "PalServer",
Onebotv11HttpApiPath: "",
UseDll: false,
DllPort: "53000",
Cert: "",
Key: "",
SteamCmdPath: "C:\\Program Files\\PalServer\\steam",
Expand Down Expand Up @@ -250,6 +252,18 @@ func ReadConfig() Config {
writeConfigToFile(config)
}

// 刷新dll通信端口 构造rconsettings.ini的完整路径
filePath := filepath.Join(config.GamePath, "Pal", "Binaries", "Win64", "rconsettings.ini")

// 准备写入文件的内容
content := fmt.Sprintf("[rcon]\nport=%s\n", config.DllPort)

// 写入文件
err = os.WriteFile(filePath, []byte(content), 0644) // 使用0644权限创建或覆盖文件
if err != nil {
fmt.Printf("Failed to write to %s: %v", filePath, err)
}

return config
}

Expand Down Expand Up @@ -492,7 +506,8 @@ func ReadGameWorldSettings(config *Config) (*GameWorldSettings, error) {
fmt.Printf("控制台默认密码(在AdminPassword配置):useradmin\n")
fmt.Printf("登录cookie 24小时有效,若在控制台修改后需立即刷新,删除cookie.db并使用新的用户名密码登录\n")
} else {
settingsString = optionSettingsKey.String()
// 去除settingsString中的所有反引号
settingsString = strings.Replace(optionSettingsKey.String(), "`", "", -1)
}

// 解析设置字符串
Expand Down Expand Up @@ -597,7 +612,16 @@ func settingsToString(settings *GameWorldSettings) string {
var valueString string
switch fieldValue.Kind() {
case reflect.String:
valueString = "\"" + fieldValue.String() + "\"" // 添加双引号
// 特殊处理:如果字段名为"Difficulty"且值为"0",则输出"None";否则,不添加引号
if field.Name == "Difficulty" {
if fieldValue.String() == "0" {
valueString = "None" // 特殊值处理
} else {
valueString = fieldValue.String() // 不添加双引号
}
} else {
valueString = "\"" + fieldValue.String() + "\"" // 为其他字符串值添加双引号
}
case reflect.Float64:
valueString = strconv.FormatFloat(fieldValue.Float(), 'f', 6, 64) // 格式化浮点数,保留6位小数
case reflect.Int:
Expand Down Expand Up @@ -643,6 +667,8 @@ func WriteGameWorldSettings(config *Config, settings *GameWorldSettings) error {

// 使用settingsToString函数生成OptionSettings值
optionSettingsValue := settingsToString(settings)
// 去除optionSettingsValue中的所有反引号
optionSettingsValue = strings.Replace(optionSettingsValue, "`", "", -1)

// 获取或创建OptionSettings项,并设置其值
optionSettingsKey, err := section.GetKey("OptionSettings")
Expand Down
99 changes: 99 additions & 0 deletions front/palworld-front/src/components/BanManage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<template>
<q-page padding>
<q-btn icon="refresh" color="primary" @click="loadPlayers" class="q-mb-md"
>刷新</q-btn
>

<div v-if="loading">加载中...</div>
<div v-else>
<q-list bordered separator>
<q-item
v-for="player in players"
:key="player.playeruid"
clickable
@click="selectPlayer(player)"
>
<q-item-section>
<div class="text-h6">{{ player.name }}</div>
<div>playeruid: {{ player.playeruid }}</div>
<div>steamid: {{ player.steamid }}</div>
<div>上次上线时间: {{ player.last_online }}</div>
<!-- 添加显示上次上线时间 -->
</q-item-section>
<q-item-section side>
<q-btn flat color="red" icon="block" @click.stop="setUnBan(player)"
>解除封禁</q-btn
>
</q-item-section>
</q-item>
</q-list>
</div>
</q-page>
</template>

<script setup lang="ts">
import { ref, onMounted, computed } from 'vue';
import { useQuasar } from 'quasar';
import axios from 'axios';
interface Player {
name: string;
playeruid: string;
steamid: string;
last_online: string;
}
const players = ref<Player[]>([]);
const loading = ref(true);
const $q = useQuasar();
const loadPlayers = async () => {
loading.value = true;
try {
const response = await axios.get('/api/getban');
// 取出bannedPlayers数组并赋值
players.value = response.data.bannedPlayers;
} catch (error) {
console.error('API 请求失败', error);
$q.notify({ type: 'negative', message: '加载失败' });
} finally {
loading.value = false;
}
};
// 解除玩家封禁的函数
const setUnBan = async (player: Player) => {
try {
const response = await axios.post('/api/setunban', {
steamid: player.steamid,
});
if (response.status === 200) {
$q.notify({
type: 'positive',
message: '解除封禁成功',
});
// 重新加载封禁列表以反映更新
await loadPlayers();
}
} catch (error) {
console.error('API 请求失败', error);
$q.notify({
type: 'negative',
message: '解除封禁失败',
});
}
};
onMounted(loadPlayers);
const selectPlayer = (player: Player) => {
// 记录选中的playeruid和steamid
console.log('选中的玩家:', player);
};
</script>

<style scoped lang="scss">
/* 可以添加自定义样式 */
</style>
76 changes: 51 additions & 25 deletions front/palworld-front/src/pages/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<q-tab name="command" label="服务器指令" />
<q-tab name="player-manage" label="玩家管理" />
<q-tab name="player-white" label="玩家白名单" />
<q-tab name="ban-manage" label="封禁玩家管理" />
<q-tab name="advanced" label="SAV修改" @click="redirectToSav" />
<q-tab name="server-check" label="主机管理" />
<q-tab name="save-manage" label="存档管理" />
Expand Down Expand Up @@ -55,7 +56,19 @@
<q-input
filled
v-model="config.maintenanceWarningMessage"
label="维护公告消息(英文)"
label="维护公告消息"
class="q-my-md"
/>
<q-input
filled
v-model="config.webuiPort"
label="webui端口(多服务端请自行错开)"
class="q-my-md"
/>
<q-input
filled
v-model="config.dllPort"
label="dll通信端口(多服务端请自行错开)"
class="q-my-md"
/>
<q-input
Expand Down Expand Up @@ -275,11 +288,11 @@
<!-- 难度和死亡掉落 -->
<!-- 难度选择框 -->
<div class="q-my-md">
<q-select
<q-input
filled
v-model="config.worldSettings.difficulty"
:options="difficultyOptions"
label="难度"
label="难度 0默认 1简单 2中等 3复杂"
class="q-my-md"
/>
<q-btn
icon="help"
Expand All @@ -289,7 +302,7 @@
@click="toggleTooltip2('difficulty')"
/>
<q-tooltip v-if="showDifficultyTooltip">
难度说明:简单(Eazy),困难(Difficult)
难度说明:数字越大,越难
</q-tooltip>
</div>

Expand Down Expand Up @@ -412,7 +425,7 @@
filled
v-model.number="config.worldSettings.palDamageRateDefense"
type="number"
label="Pal 防御伤害率"
label="Pal 承受伤害倍率"
class="q-my-md"
/>
<q-input
Expand All @@ -426,7 +439,7 @@
filled
v-model.number="config.worldSettings.playerDamageRateDefense"
type="number"
label="玩家防御伤害率"
label="玩家承受伤害倍率"
class="q-my-md"
/>
<q-input
Expand Down Expand Up @@ -954,6 +967,10 @@
</div>
</div>
</q-page>
<!-- 封禁玩家管理组件 -->
<q-page padding v-if="tab === 'ban-manage'">
<ban-manage />
</q-page>
<q-page padding v-if="tab === 'server-check'">
<div class="text-h6">服务器检测页面</div>
<running-process-status
Expand All @@ -977,10 +994,12 @@
import { ref, onMounted, onUnmounted, onBeforeUnmount, watch } from 'vue';
import axios from 'axios';
import { QPage, QCard, QCardSection } from 'quasar';
import { useQuasar } from 'quasar';
import RunningProcessStatus from 'components/RunningProcessStatus.vue';
import PlayerManage from 'components/PlayerManage.vue';
import SaveManage from 'components/SaveManage.vue';
import BotManage from 'components/BotManage.vue';
import BanManage from 'components/BanManage.vue';
//给components传递数据
const props = defineProps({
Expand All @@ -992,8 +1011,7 @@ const players = ref([]);
const status = ref(null); // 假设 ProcessInfo 是一个对象,这里使用 null 作为初始值
const tab = ref('guard'); // 默认选中守护配置修改
// 难度选项
const difficultyOptions = ['Eazy', 'None', 'Difficult'];
// 死亡掉落选项
const deathPenaltyOptions = ['None', 'Item', 'ItemAndEquipment', 'All'];
Expand All @@ -1014,19 +1032,6 @@ const redirectToSav = () => {
window.location.href = '/sav/index.html'; // 重定向到 /sav 路径
};
// // 难度选项
// const difficultyOptions = [
// { label: '简单', value: 'Eazy' },
// { label: '困难', value: 'Difficult' },
// ];
// // 死亡掉落选项
// const deathPenaltyOptions = [
// { label: '不掉落', value: 'None' },
// { label: '只掉落物品', value: 'Item' },
// { label: '掉落物品和装备', value: 'ItemAndEquipment' },
// { label: '掉落物品、装备和帕鲁', value: 'All' },
// ];
const config = ref({});
// 增加一个消息到数组
Expand Down Expand Up @@ -1058,20 +1063,41 @@ function removePlayer(index) {
}
onMounted(async () => {
const $q = useQuasar();
try {
const response = await axios.get('/api/getjson');
const response = await axios.get('/api/getjson', {
withCredentials: true, // 确保携带 cookie
});
config.value = response.data;
$q.notify({
type: 'positive',
message: '配置加载成功',
});
} catch (error) {
console.error('Error fetching configuration:', error);
$q.notify({
type: 'negative',
message: '获取配置失败',
});
}
});
const saveConfig = async () => {
const $q = useQuasar();
try {
await axios.post('/api/savejson', config.value);
alert('配置已保存!');
await axios.post('/api/savejson', config.value, {
withCredentials: true, // 确保携带 cookie
});
$q.notify({
type: 'positive',
message: '配置已保存!',
});
} catch (error) {
console.error('Error saving configuration:', error);
$q.notify({
type: 'negative',
message: '保存配置失败',
});
}
};
Expand Down
Binary file modified mod/embeds/PalServerInject.exe
Binary file not shown.
Binary file modified mod/embeds/pal-plugin-loader.dll
Binary file not shown.
20 changes: 20 additions & 0 deletions status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package status

var memoryIssueDetected bool = false
var successReadGameWorldSettings bool = false
var manualServerShutdown bool = false // 存储是否手动关闭服务器的状态
var globalpid int = 0

// SetMemoryIssueDetected 设置内存问题检测标志
func SetMemoryIssueDetected(flag bool) {
Expand All @@ -23,3 +25,21 @@ func SetsuccessReadGameWorldSettings(flag bool) {
func GetsuccessReadGameWorldSettings() bool {
return successReadGameWorldSettings
}

// SetManualServerShutdown 设置手动关闭服务器的状态
func SetManualServerShutdown(flag bool) {
manualServerShutdown = flag
}

// GetManualServerShutdown 获取手动关闭服务器的状态
func GetManualServerShutdown() bool {
return manualServerShutdown
}

func SetGlobalPid(pid int) {
globalpid = pid
}

func GetGlobalPid() int {
return globalpid
}
Loading

0 comments on commit 46978a9

Please sign in to comment.