Skip to content

Commit

Permalink
Merge pull request #99 from carrot-hu23/多层版本-1.4.0
Browse files Browse the repository at this point in the history
多层版本 1.4.0
  • Loading branch information
carrot-hu23 authored Jan 6, 2025
2 parents 9b4b526 + eb8d031 commit da5e341
Show file tree
Hide file tree
Showing 14 changed files with 821 additions and 68 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# dependencies
/dist
/dst
.idea

first
dst-admin-go
dst-admin-go.exe
dst-admin-go.log
dst-db
password.txt
Expand Down Expand Up @@ -33,5 +35,4 @@ yarn-error.log*
/py-dst-cli/__pycache__
/py-dst-cli/data


/test
50 changes: 24 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
FROM debian:buster-slim
# 使用官方的Ubuntu基础镜像
FROM ubuntu:20.04

LABEL maintainer="hujinbo23 jinbohu23@outlook.com"
LABEL description="DoNotStarveTogehter server panel written in golang. github: https://github.com/hujinbo23/dst-admin-go"

# 切换到清华大学的 apt 镜像源
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
&& sed -i 's|security.debian.org/debian-security|mirrors.tuna.tsinghua.edu.cn/debian-security|g' /etc/apt/sources.list

# 更新软件包索引
RUN apt-get update

# Install packages
RUN dpkg --add-architecture i386 \
&& apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
libcurl4-gnutls-dev:i386 \
lib32gcc1 \
lib32stdc++6 \
libcurl4-gnutls-dev \
libgcc1 \
libstdc++6 \
wget \
ca-certificates \
screen \
procps \
sudo \
&& apt-get clean \
# 更新并安装必要的软件包
RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get install -y \
curl \
libcurl4-gnutls-dev:i386 \
lib32gcc1 \
lib32stdc++6 \
libcurl4-gnutls-dev \
libgcc1 \
libstdc++6 \
wget \
ca-certificates \
screen \
procps \
sudo \
unzip \
&& rm -rf /var/lib/apt/lists/*

# 设置工作目录
Expand All @@ -44,11 +39,14 @@ COPY dist /app/dist
COPY static /app/static

# 内嵌源配置信息

# 控制面板访问的端口
EXPOSE 8082/tcp
# 饥荒世界通信的端口
EXPOSE 10888/udp
# 饥荒洞穴世界的端口
EXPOSE 10998/udp
# 饥荒森林世界的端口
EXPOSE 10999/udp

# 运行命令
ENTRYPOINT ["./docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]
135 changes: 135 additions & 0 deletions api/dstMapApi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package api

import (
"dst-admin-go/service"
"dst-admin-go/utils/dstConfigUtils"
"dst-admin-go/utils/dstUtils"
"dst-admin-go/utils/fileUtils"
"dst-admin-go/vo"
"fmt"
"github.com/gin-gonic/gin"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"strings"
"time"
)

type DstMapApi struct {
}

func (d *DstMapApi) GenDstMap(ctx *gin.Context) {

dstConfig := dstConfigUtils.GetDstConfig()
outputImage := filepath.Join(dstUtils.GetClusterBasePath(dstConfig.Cluster), "dst_map.png")
sessionPath := filepath.Join(dstUtils.GetKleiDstPath(), dstConfig.Cluster, "Master", "save", "session")
filePath, err := findLatestMetaFile(sessionPath)
if err != nil {
log.Panicln(err)
}
log.Println("生成地图", filePath, outputImage)
generator := service.NewDSTMapGenerator()
height, width, err := service.ExtractDimensions(filePath)
if err != nil {
log.Panicln(err)
}
err = generator.GenerateMap(
filePath,
outputImage,
height,
width,
)
if err != nil {
log.Panicln(err)
}
ctx.JSON(http.StatusOK, vo.Response{
Code: 200,
Msg: "success",
Data: nil,
})
}

func (d *DstMapApi) GetDstMapImage(ctx *gin.Context) {

dstConfig := dstConfigUtils.GetDstConfig()
outputImage := filepath.Join(dstUtils.GetClusterBasePath(dstConfig.Cluster), "dst_map.png")
log.Println(outputImage)
// 使用 Gin 提供的文件传输方法返回图片
ctx.File(outputImage)
ctx.Header("Content-Type", "image/png")

}

func (d *DstMapApi) HasWalrusHutPlains(ctx *gin.Context) {

dstConfig := dstConfigUtils.GetDstConfig()
sessionPath := filepath.Join(dstUtils.GetKleiDstPath(), dstConfig.Cluster, "Master", "save", "session")
filePath, err := findLatestMetaFile(sessionPath)
if err != nil {
log.Panicln(err)
}
file, err := fileUtils.ReadFile(filePath)
if err != nil {
log.Panicln(err)
}
hasWalrusHutPlains := strings.Contains(file, "WalrusHut_Plains")
ctx.JSON(http.StatusOK, vo.Response{
Code: 200,
Msg: "success",
Data: hasWalrusHutPlains,
})

}

func findLatestMetaFile(directory string) (string, error) {
// 检查指定目录是否存在
_, err := os.Stat(directory)
if os.IsNotExist(err) {
return "", fmt.Errorf("目录不存在:%s", directory)
}

// 获取指定目录下一级的所有子目录
subdirs, err := ioutil.ReadDir(directory)
if err != nil {
return "", fmt.Errorf("读取目录失败:%s", err)
}

// 用于存储最新的.meta文件路径和其修改时间
var latestMetaFile string
var latestMetaFileTime time.Time

for _, subdir := range subdirs {
// 检查子目录是否是目录
if subdir.IsDir() {
subdirPath := filepath.Join(directory, subdir.Name())

// 获取子目录下的所有文件
files, err := ioutil.ReadDir(subdirPath)
if err != nil {
return "", fmt.Errorf("读取子目录失败:%s", err)
}

for _, file := range files {
// 检查文件是否是.meta文件
if !file.IsDir() && filepath.Ext(file.Name()) != ".meta" {
// 获取文件的修改时间
modifiedTime := file.ModTime()

// 如果找到的文件的修改时间比当前最新的.meta文件的修改时间更晚,则更新最新的.meta文件路径和修改时间
if modifiedTime.After(latestMetaFileTime) {
latestMetaFile = filepath.Join(subdirPath, file.Name())
latestMetaFileTime = modifiedTime
}
}
}
}
}

if latestMetaFile == "" {
return "", fmt.Errorf("未找到文件")
}

return latestMetaFile, nil
}
5 changes: 0 additions & 5 deletions build_linux.bat

This file was deleted.

1 change: 1 addition & 0 deletions build_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GOOS=linux GOARCH=amd64 go build
1 change: 1 addition & 0 deletions build_window.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GOOS=windows GOARCH=amd64 go build
File renamed without changes.
31 changes: 0 additions & 31 deletions docs/dcokerfile/README.md

This file was deleted.

85 changes: 85 additions & 0 deletions py-dst-cli/parse_TooManyItemPlus_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import os
import re
import json

# 定义修饰词规则
SPICE_TRANSLATIONS = {
"_SPICE_GARLIC": "蒜",
"_SPICE_CHILI": "辣",
"_SPICE_SUGAR": "甜",
"_SPICE_SALT": "盐",
}

def parse_po_file(po_file):
"""解析 .po 文件,从第 9 行开始,返回仅包含 STRINGS.NAMES 的 msgctxt 与 msgstr 的映射"""
translations = {}
with open(po_file, "r", encoding="utf-8") as f:
lines = f.readlines()

# 从第 9 行开始解析
lines = lines[8:]

msgctxt, msgid, msgstr = None, None, None
for line in lines:
line = line.strip()
if line.startswith("msgctxt") and "STRINGS.NAMES." in line:
msgctxt = re.search(r'"STRINGS\.NAMES\.(.+)"', line).group(1) # 提取物品名
elif line.startswith("msgid"):
msgid = re.search(r'"(.*)"', line).group(1) # 捕获空字符串
elif line.startswith("msgstr"):
msgstr = re.search(r'"(.*)"', line).group(1) # 捕获空字符串

# 只有在 msgctxt、msgid 和 msgstr 都非空时才保存
if msgctxt and msgid and msgstr:
translations[msgctxt] = msgstr

# 重置状态
msgctxt, msgid, msgstr = None, None, None
return translations

def apply_spice_rule(item, base_translation):
print(item)
"""根据规则生成修饰后的翻译"""
for suffix, spice_translation in SPICE_TRANSLATIONS.items():
if item.endswith(suffix):
base_item = item.replace(suffix, "")
if base_item in base_translation:
return f"{base_translation[base_item]}-{spice_translation}"
return "未翻译"

def generate_translations(input_folder, po_file, output_file):
"""生成带翻译的 JSON 数据"""
# 解析 .po 文件
translations = parse_po_file(po_file)

# 初始化结果字典
result = {}

# 遍历输入文件夹,处理分类数据
for filename in os.listdir(input_folder):
if filename.endswith(".lua"):
category_name = os.path.splitext(filename)[0]
file_path = os.path.join(input_folder, filename)
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
if "return" in content:
content = content.split("return", 1)[1].strip().strip("{}")
items = [item.strip().strip('"') for item in content.split(",")]
result[category_name] = {
item: translations.get(item.upper(), apply_spice_rule(item.upper(), translations))
for item in items
}

# 保存结果为 JSON 文件
with open(output_file, "w", encoding="utf-8") as f:
json.dump(result, f, ensure_ascii=False, indent=4)
print(f"翻译结果已保存到 {output_file}")


# 设置文件路径
input_folder = "./scripts/TMIP/list" # 替换为文件夹路径
po_file = "./chinese_s.po" # 替换为 .po 文件路径
output_file = "tooManyItemPlus.json" # 输出文件路径

# 运行生成函数
generate_translations(input_folder, po_file, output_file)
18 changes: 18 additions & 0 deletions router/dstGenMap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package router

import (
"dst-admin-go/api"
"github.com/gin-gonic/gin"
)

func initDstGenMapRouter(router *gin.RouterGroup) {

dstMapApi := api.DstMapApi{}
dstMap := router.Group("/api/dst/map/")
{
dstMap.GET("/gen", dstMapApi.GenDstMap)
dstMap.GET("image", dstMapApi.GetDstMapImage)
dstMap.GET("/has/walrusHut/plains", dstMapApi.HasWalrusHutPlains)
}

}
3 changes: 2 additions & 1 deletion router/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewRoute() *gin.Engine {
store := cookie.NewStore([]byte("secret"))
store.Options(sessions.Options{
// 设置过期时间为 30 分钟
MaxAge: int(30 * time.Minute.Seconds()),
MaxAge: int(60 * 24 * 7 * time.Minute.Seconds()),
Path: "/",
HttpOnly: true, // 仅允许在 HTTP 请求中使用,增加安全性
})
Expand Down Expand Up @@ -56,6 +56,7 @@ func NewRoute() *gin.Engine {
initLevel2(router)

initFile(router)
initDstGenMapRouter(router)

initStaticFile(app)

Expand Down
Loading

0 comments on commit da5e341

Please sign in to comment.