Commit 17e83e819da125edbde78d5bd66629a3b2e03043
1 parent
06bda533
Exists in
master
提交
Showing
3 changed files
with
99 additions
and
3 deletions
Show diff stats
src/HttpServer/logic/datadef.go
@@ -263,7 +263,7 @@ type GetDataResult struct { | @@ -263,7 +263,7 @@ type GetDataResult struct { | ||
263 | } | 263 | } |
264 | 264 | ||
265 | type GetDataReq struct{ | 265 | type GetDataReq struct{ |
266 | - Token string `json:"token"` | 266 | + Uuid int `json:"uuid"` |
267 | Field string `json:"field"` | 267 | Field string `json:"field"` |
268 | } | 268 | } |
269 | 269 |
src/HttpServer/logic/httpserver.go
@@ -88,12 +88,38 @@ func startServerHttpServe() { | @@ -88,12 +88,38 @@ func startServerHttpServe() { | ||
88 | http.HandleFunc("/catcafe/user/enterInvite",EnterInvite) //别的玩家(新玩家)通过邀请连接进来 | 88 | http.HandleFunc("/catcafe/user/enterInvite",EnterInvite) //别的玩家(新玩家)通过邀请连接进来 |
89 | http.HandleFunc("/catcafe/user/queryInviteWork",QueryInviteWork) //获取邀请打工列表 | 89 | http.HandleFunc("/catcafe/user/queryInviteWork",QueryInviteWork) //获取邀请打工列表 |
90 | http.HandleFunc("/catcafe/user/saveDataBackup",SaveDataBackup) //保存玩家数据 备份数据接口 | 90 | http.HandleFunc("/catcafe/user/saveDataBackup",SaveDataBackup) //保存玩家数据 备份数据接口 |
91 | + http.HandleFunc("/catcafe/user/newGetData",NewGetData) //新的获取玩家数据接口 | ||
92 | + http.HandleFunc("/catcafe/user/newSaveData",NewSaveData) //新的保存玩家数据接口 | ||
91 | 93 | ||
92 | 94 | ||
93 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) | 95 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
94 | CheckErr(err) | 96 | CheckErr(err) |
95 | } | 97 | } |
96 | 98 | ||
99 | + | ||
100 | +func NewSaveData(w http.ResponseWriter, r *http.Request) { | ||
101 | + | ||
102 | + result, _ := ioutil.ReadAll(r.Body) | ||
103 | + r.Body.Close() | ||
104 | + | ||
105 | + s := string(result) | ||
106 | + logger.Info("NewSaveData , body:%v", s) | ||
107 | + | ||
108 | + HandleNewSaveData(w,s) | ||
109 | +} | ||
110 | + | ||
111 | + | ||
112 | +func NewGetData(w http.ResponseWriter, r *http.Request) { | ||
113 | + | ||
114 | + result, _ := ioutil.ReadAll(r.Body) | ||
115 | + r.Body.Close() | ||
116 | + | ||
117 | + s := string(result) | ||
118 | + logger.Info("NewGetData , body:%v", s) | ||
119 | + | ||
120 | + HandleNewGetData(w,s) | ||
121 | +} | ||
122 | + | ||
97 | func InitIndex(w http.ResponseWriter, r *http.Request) { | 123 | func InitIndex(w http.ResponseWriter, r *http.Request) { |
98 | 124 | ||
99 | result, _ := ioutil.ReadAll(r.Body) | 125 | result, _ := ioutil.ReadAll(r.Body) |
src/HttpServer/logic/logic.go
@@ -274,6 +274,46 @@ func HandleQueryInvite(w http.ResponseWriter, data string) { | @@ -274,6 +274,46 @@ func HandleQueryInvite(w http.ResponseWriter, data string) { | ||
274 | } | 274 | } |
275 | 275 | ||
276 | 276 | ||
277 | +func HandleNewSaveData(w http.ResponseWriter, data string) { | ||
278 | + SetHeader(w) | ||
279 | + var resp SaveDataBackupResp | ||
280 | + resp.Status = "true" | ||
281 | + var rdata SaveDataBackupReq | ||
282 | + err := json.Unmarshal([]byte(data), &rdata) | ||
283 | + for { | ||
284 | + if err != nil { | ||
285 | + logger.Error("HandleNewSaveData json unmarshal failed=%v", err) | ||
286 | + resp.Result.Code = ERROR_JSONUNMASHFAILED | ||
287 | + resp.Result.Data = "json unmarshal failed" | ||
288 | + break | ||
289 | + } | ||
290 | + | ||
291 | + | ||
292 | + // | ||
293 | + rkey := "cat:cafe:data:where:data_uid:" + strconv.Itoa(rdata.Uuid) | ||
294 | + val,err := redishandler.GetRedisClient().GetString(rkey) | ||
295 | + if err != nil { | ||
296 | + logger.Error("HandleNewSaveData ERROR_SRVDB_FAILED failed=%v,val=%v", err,val) | ||
297 | + resp.Result.Code = ERROR_SRVDB_FAILED | ||
298 | + resp.Result.Data = "get redis failed" | ||
299 | + break | ||
300 | + } | ||
301 | + | ||
302 | + //解析val json | ||
303 | + | ||
304 | + //首先解析value | ||
305 | + | ||
306 | + //比对数据 如果不符合则不保存 | ||
307 | + | ||
308 | + resp.Result.Code = ERROR_OK | ||
309 | + break | ||
310 | + } | ||
311 | + | ||
312 | + //回包 | ||
313 | + respstr, _ := json.Marshal(&resp) | ||
314 | + fmt.Fprint(w, string(respstr)) | ||
315 | +} | ||
316 | + | ||
277 | func HandleSaveDataBackup(w http.ResponseWriter, data string) { | 317 | func HandleSaveDataBackup(w http.ResponseWriter, data string) { |
278 | SetHeader(w) | 318 | SetHeader(w) |
279 | var resp SaveDataBackupResp | 319 | var resp SaveDataBackupResp |
@@ -305,7 +345,37 @@ func HandleSaveDataBackup(w http.ResponseWriter, data string) { | @@ -305,7 +345,37 @@ func HandleSaveDataBackup(w http.ResponseWriter, data string) { | ||
305 | fmt.Fprint(w, string(respstr)) | 345 | fmt.Fprint(w, string(respstr)) |
306 | } | 346 | } |
307 | 347 | ||
348 | +func HandleNewGetData(w http.ResponseWriter, data string) { | ||
349 | + var resp GetDataResp | ||
350 | + resp.Status = "true" | ||
351 | + resp.Result.Code = ERROR_OK | ||
352 | + var rdata GetDataReq | ||
353 | + err := json.Unmarshal([]byte(data), &rdata) | ||
354 | + for { | ||
355 | + if err != nil { | ||
356 | + logger.Error("HandleNewGetData json unmarshal failed=%v", err) | ||
357 | + resp.Result.Code = ERROR_JSONUNMASHFAILED | ||
358 | + break | ||
359 | + } | ||
360 | + | ||
361 | + rkey := "cat:cafe:data:where:data_uid:" + strconv.Itoa(rdata.Uuid) | ||
308 | 362 | ||
363 | + val,err := redishandler.GetRedisClient().GetString(rkey) | ||
364 | + if err != nil { | ||
365 | + logger.Error("HandleNewGetData err=%v",err) | ||
366 | + resp.Result.Code = ERROR_JSONUNMASHFAILED | ||
367 | + break | ||
368 | + } | ||
369 | + resp.Result.Data.Base_data = val | ||
370 | + logger.Info("HandleNewGetData new is=%v",val) | ||
371 | + | ||
372 | + break | ||
373 | + } | ||
374 | + | ||
375 | + //回包 | ||
376 | + respstr, _ := json.Marshal(&resp) | ||
377 | + fmt.Fprint(w, string(respstr)) | ||
378 | +} | ||
309 | 379 | ||
310 | func HandleInitIndex(w http.ResponseWriter, data string) { | 380 | func HandleInitIndex(w http.ResponseWriter, data string) { |
311 | 381 | ||
@@ -880,7 +950,7 @@ func HandlesaveData(w http.ResponseWriter, data string) { | @@ -880,7 +950,7 @@ func HandlesaveData(w http.ResponseWriter, data string) { | ||
880 | } | 950 | } |
881 | 951 | ||
882 | func HandlegetData(w http.ResponseWriter, data string) { | 952 | func HandlegetData(w http.ResponseWriter, data string) { |
883 | - SetHeader(w) | 953 | + /*SetHeader(w) |
884 | var resp GetDataResp | 954 | var resp GetDataResp |
885 | resp.Status = "true" | 955 | resp.Status = "true" |
886 | resp.Result.Code = ERROR_OK | 956 | resp.Result.Code = ERROR_OK |
@@ -916,7 +986,7 @@ func HandlegetData(w http.ResponseWriter, data string) { | @@ -916,7 +986,7 @@ func HandlegetData(w http.ResponseWriter, data string) { | ||
916 | 986 | ||
917 | //回包 | 987 | //回包 |
918 | respstr, _ := json.Marshal(&resp) | 988 | respstr, _ := json.Marshal(&resp) |
919 | - fmt.Fprint(w, string(respstr)) | 989 | + fmt.Fprint(w, string(respstr))*/ |
920 | } | 990 | } |
921 | 991 | ||
922 | func GetAccessToken() string{ | 992 | func GetAccessToken() string{ |