Skip to content

Commit

Permalink
修复查服接口
Browse files Browse the repository at this point in the history
  • Loading branch information
hu, jinbo committed Feb 21, 2024
1 parent 216030b commit fd60d94
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 14 deletions.
31 changes: 26 additions & 5 deletions api/thirdPartyApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,41 @@ func (t *ThirdPartyApi) GetDstHomeServerList(c *gin.Context) {
query_data["sort_type"] = param.SortType
query_data["sort_way"] = param.SortWay
query_data["search_type"] = param.Search_type
query_data["search_content"] = param.Search_content
if param.Mod != "" {
// 不区分是否使用mod
if param.Search_content != "" {
query_data["search_content"] = param.Search_content
}
if param.Mode != "" {
query_data["mode"] = param.Mode
}
if param.Season != "" {
query_data["season"] = param.Season
}
if param.Pvp != -1 {
query_data["pvp"] = param.Pvp
}
if param.Mod != -1 {
query_data["mod"] = param.Mod
}
if param.Password != -1 {
query_data["password"] = param.Password
}
if param.World != -1 {
query_data["world"] = param.World
}
if param.Playerpercent != "" {
query_data["playerpercent"] = param.Playerpercent
}

bytesData, err := json.Marshal(query_data)
log.Println("param", string(bytesData))

if err != nil {
log.Println("josn 解析异常")
}

b_reader := bytes.NewReader(bytesData)

url := "https://dst.liuyh.com/index/serverlist/getserverlist.html"
url := "http://dst.liuyh.com/index/serverlist/getserverlist.html"
req, _ := http.NewRequest("POST", url, b_reader)
// 比如说设置个token
req.Header.Set("X-Requested-With", "XMLHttpRequest")
Expand Down Expand Up @@ -112,7 +133,7 @@ func (t *ThirdPartyApi) GetDstHomeDetailList(c *gin.Context) {

b_reader := bytes.NewReader(bytesData)

url := "https://dst.liuyh.com/index/serverlist/getserverdetail.html"
url := "http://dst.liuyh.com/index/serverlist/getserverdetail.html"
req, _ := http.NewRequest("POST", url, b_reader)
// 比如说设置个token
req.Header.Set("X-Requested-With", "XMLHttpRequest")
Expand Down
37 changes: 29 additions & 8 deletions service/playerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,47 @@ func (p *PlayerService) GetPlayerList(clusterName string, levelName string) []vo

id := strconv.FormatInt(time.Now().Unix(), 10)

command := "for i, v in ipairs(TheNet:GetClientTable()) do print(string.format(\\\"%s %d %s %s %s %s \\\", " + "'" + id + "'" + ",i-1, string.format('%03d', v.playerage), v.userid, v.name, v.prefab)) end"
command := "for i, v in ipairs(TheNet:GetClientTable()) do print(string.format(\\\"player: {[%s] [%d] [%s] [%s] [%s] [%s]} \\\", " + "'" + id + "'" + ",i-1, string.format('%03d', v.playerage), v.userid, v.name, v.prefab)) end"
// command := "for i, v in ipairs(TheNet:GetClientTable()) do print(string.format(\\\"%s %d %s %s %s %s \\\", " + "'" + id + "'" + ",i-1, string.format('%03d', v.playerage), v.userid, v.name, v.prefab)) end"

playerCMD := "screen -S \"" + screenKey.Key(clusterName, levelName) + "\" -p 0 -X stuff \"" + command + "\\n\""

shellUtils.Shell(playerCMD)

time.Sleep(time.Duration(500) * time.Millisecond)

// TODO 如果只启动了洞穴,应该去读取洞穴的日志

// 读取日志
dstLogs := dstUtils.ReadLevelLog(clusterName, levelName, 100)
playerVOList := make([]vo.PlayerVO, 0)

for _, line := range dstLogs {
if strings.Contains(line, id) && strings.Contains(line, "KU") && !strings.Contains(line, "Host") {
str := strings.Split(line, " ")
log.Println("players:", str)
playerVO := vo.PlayerVO{Key: str[2], Day: str[3], KuId: str[4], Name: str[5], Role: str[6]}
playerVOList = append(playerVOList, playerVO)
//str := strings.Split(line, " ")
//log.Println("players:", str)
//playerVO := vo.PlayerVO{Key: str[2], Day: str[3], KuId: str[4], Name: str[5], Role: str[6]}
//playerVOList = append(playerVOList, playerVO)

log.Println(line)

// 提取 {} 中的内容
reCurlyBraces := regexp.MustCompile(`\{([^}]*)\}`)
curlyBracesMatches := reCurlyBraces.FindStringSubmatch(line)

if len(curlyBracesMatches) > 1 {
// curlyBracesMatches[1] 包含 {} 中的内容
contentInsideCurlyBraces := curlyBracesMatches[1]

// 提取 [] 中的内容
reSquareBrackets := regexp.MustCompile(`\[([^\]]*)\]`)
squareBracketsMatches := reSquareBrackets.FindAllStringSubmatch(contentInsideCurlyBraces, -1)
var result []string
for _, match := range squareBracketsMatches {
// match[1] 包含 [] 中的内容
contentInsideSquareBrackets := match[1]
result = append(result, contentInsideSquareBrackets)
}
playerVO := vo.PlayerVO{Key: result[1], Day: result[2], KuId: result[3], Name: result[4], Role: result[5]}
playerVOList = append(playerVOList, playerVO)
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion vo/third/DstHomeServerParam.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ type DstHomeServerParam struct {
SortWay int `json:"sort_way"`
Search_type int `json:"search_type"`
Search_content string `json:"search_content"`
Mod string `json:"mod"`
Mode string `json:"mode"`
Mod int `json:"mod"`
Season string `json:"season"`
Pvp int `json:"pvp"`
Password int `json:"password"`
World int `json:"world"`
Playerpercent string `json:"playerpercent"`
}

func NewDstHomeServerParam() *DstHomeServerParam {
Expand Down

0 comments on commit fd60d94

Please sign in to comment.