Commit 92131fd9010388c981cfa3252ca512e239cac503

Authored by zhangqijia
1 parent 944a2ef6

fix: gm支持GET请求

Showing 1 changed file with 25 additions and 10 deletions   Show diff stats
cmd/gameserver/service/gm.go
... ... @@ -23,13 +23,33 @@ func NewGmServer(server components.IServer, port ...string) *GmServer {
23 23  
24 24 func (s *GmServer) HandlerFuncObj(tvl, obj reflect.Value) gin.HandlerFunc {
25 25 return func(c *gin.Context) {
26   - c.Request.ParseForm()
27   - roleId, ok := c.GetPostForm("role_id")
  26 + var roleId string
  27 + var ok bool
  28 + properties := make(map[string]interface{})
  29 + //请求类型,以及 format 参数
  30 + if c.Request.Method == "POST" {
  31 + c.Request.ParseForm()
  32 + for k, v := range c.Request.PostForm {
  33 + properties[k] = v[0]
  34 + }
  35 + roleId, ok = c.GetPostForm("role_id")
  36 +
  37 + } else if c.Request.Method == "GET" {
  38 + roleId, ok = c.GetQuery("role_id")
  39 + for k, v := range c.Request.URL.Query() {
  40 + properties[k] = v[0]
  41 + }
  42 + } else {
  43 + c.JSON(http.StatusOK, gin.H{"code": -101, "message": "not support method"})
  44 + return
  45 + }
  46 +
28 47 if !ok {
29   - c.JSON(http.StatusOK, gin.H{"code": -101, "message": "role not exist"})
  48 + c.JSON(http.StatusOK, gin.H{"code": -102, "message": "role not exist"})
30 49 return
31 50 }
32 51  
  52 + //role start
33 53 conn := s.Server.GetConnManage().GetConnByRID(roleId)
34 54 var role *models.RoleModel
35 55 if conn != nil {
... ... @@ -39,21 +59,16 @@ func (s *GmServer) HandlerFuncObj(tvl, obj reflect.Value) gin.HandlerFunc {
39 59 //离线
40 60 role = models.NewRole(roleId)
41 61 if err := role.Load(); err != nil {
42   - c.JSON(http.StatusOK, gin.H{"code": -102, "message": "role not exist"})
  62 + c.JSON(http.StatusOK, gin.H{"code": -103, "message": "role not exist"})
43 63 return
44 64 }
45 65 role.LoadAll()
46 66 }
47 67  
48   - properties := make(map[string]interface{})
49   -
50   - for k, v := range c.Request.PostForm {
51   - properties[k] = v[0]
52   - }
53   -
54 68 properties["_conn"] = conn
55 69 properties["_role"] = role
56 70  
  71 + //func start
57 72 v := tvl.Call([]reflect.Value{obj, reflect.ValueOf(properties)})
58 73  
59 74 role.SaveRoleData(0)
... ...