forked from Ayin-a/hkrpg-go
/
dispatch.go
131 lines (106 loc) · 3.33 KB
/
dispatch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package SDK
import (
"encoding/base64"
"io"
"net/http"
"github.com/Eichs/hkrpg-go/pkg/config"
"github.com/Eichs/hkrpg-go/pkg/logger"
"github.com/Eichs/hkrpg-go/protocol/proto"
"github.com/gin-gonic/gin"
pb "google.golang.org/protobuf/proto"
)
func (s *Server) QueryDispatchHandler(c *gin.Context) {
dispatchRegionsData := new(proto.DispatchRegionData)
dispatchRegionsData.TopSeverRegionName = "hkrpg-go"
serverList := make([]*proto.RegionEntry, 0)
for _, cfg := range config.GetConfig().Dispatch {
server := &proto.RegionEntry{
Name: cfg.Name,
Title: cfg.Title,
EnvType: cfg.Type,
DispatchUrl: cfg.DispatchUrl,
}
serverList = append(serverList, server)
}
dispatchRegionsData.RegionList = serverList
reqdata, err := pb.Marshal(dispatchRegionsData)
if err != nil {
logger.Error("pb marshal DispatchRegionsData error: %v", err)
return
}
reqdataBase64 := base64.StdEncoding.EncodeToString(reqdata)
c.String(200, reqdataBase64)
}
func (s *Server) QueryGatewayHandler(c *gin.Context) {
queryGateway := new(proto.Gateserver)
queryGateway.Msg = "OK"
queryGateway.Ip = s.Config.Game.Addr
queryGateway.RegionName = "hkrpg-go"
queryGateway.Port = s.Config.Game.Port
queryGateway.ClientSecretKey = base64.RawStdEncoding.EncodeToString(s.Config.Ec2b.Bytes())
queryGateway.Unk1 = true
queryGateway.Unk2 = true
queryGateway.Unk3 = true
queryGateway.Unk4 = true
queryGateway.Unk5 = true
//queryGateway.Unk6 = true
reqdata, err := pb.Marshal(queryGateway)
if err != nil {
logger.Error("pb marshal Gateserver error: %v", err)
return
}
reqdataBase64 := base64.StdEncoding.EncodeToString(reqdata)
c.String(200, reqdataBase64)
}
func (s *Server) QueryGatewayHandlerCaptureOs(c *gin.Context) {
urlPath := c.Request.URL.RawQuery
rsps, err := http.Get("https://prod-official-asia-dp01.starrails.com/query_gateway?" + urlPath)
if err != nil {
logger.Error("Request failed:", err)
return
}
defer rsps.Body.Close()
data, err := io.ReadAll(rsps.Body)
if err != nil {
logger.Error("Read body failed:", err)
return
}
datamsg, _ := base64.StdEncoding.DecodeString(string(data))
dispatch := new(proto.Gateserver)
err = pb.Unmarshal(datamsg, dispatch)
if err != nil {
logger.Error("", err)
}
dispatch.Ip = s.Config.Game.Addr
dispatch.Port = s.Config.Game.Port
dispatch.ClientSecretKey = base64.RawStdEncoding.EncodeToString(s.Config.Ec2b.Bytes())
rspbin, _ := pb.Marshal(dispatch)
dispatchb64 := base64.StdEncoding.EncodeToString(rspbin)
c.String(200, dispatchb64)
}
func (s *Server) QueryGatewayHandlerCaptureCn(c *gin.Context) {
urlPath := c.Request.URL.RawQuery
rsps, err := http.Get("https://prod-gf-cn-dp01.bhsr.com/query_gateway?" + urlPath)
if err != nil {
logger.Error("Request failed:", err)
return
}
defer rsps.Body.Close()
data, err := io.ReadAll(rsps.Body)
if err != nil {
logger.Error("Read body failed:", err)
return
}
datamsg, _ := base64.StdEncoding.DecodeString(string(data))
dispatch := new(proto.Gateserver)
err = pb.Unmarshal(datamsg, dispatch)
if err != nil {
logger.Error("", err)
}
dispatch.Ip = s.Config.Game.Addr
dispatch.Port = s.Config.Game.Port
dispatch.ClientSecretKey = base64.RawStdEncoding.EncodeToString(s.Config.Ec2b.Bytes())
rspbin, _ := pb.Marshal(dispatch)
dispatchb64 := base64.StdEncoding.EncodeToString(rspbin)
c.String(200, dispatchb64)
}