Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "net/http"
  6. )
  7.  
  8. const (
  9. UserTypeFacebook string = "facebook"
  10. UserTypeGameCenter string = "game_center"
  11. UserTypeGooglePlay string = "google_play"
  12. UserTypeTouringIOS string = "touring_ios"
  13. UserTypeTouringAndroid string = "touring_android"
  14. UserTypeSignInWithApple string = "sign_in_with_apple"
  15. UserTypeLine string = "line"
  16. )
  17.  
  18. type Message struct {
  19. Title string `json:"title"`
  20. Message string `json:"message"`
  21. Gold string `json:"gold"`
  22. Chip string `json:"chip"`
  23. Ticket string `json:"ticket"`
  24. UIDS string `json:"UIDS"`
  25. GMUsername string `json:"GMUsername"`
  26. }
  27.  
  28. func main() {
  29. fmt.Println("----- Start server at port 11433 -----")
  30.  
  31. // http.Handle("/addGmGiftReward", withCors(addGmGiftReward))
  32. // http.Handle("/getInventoryItems", withCors(GetInventoryItems))
  33. //http.Handle("/getInventoryItems", withCors(GetInventoryItems))
  34. http.HandleFunc("/getInventoryItems", GetInventoryItems)
  35.  
  36. http.ListenAndServe("0.0.0.0:11433", nil)
  37. //log.Fatal(http.ListenAndServeTLS("0.0.0.0:11433", "certs/fullchain.pem", "certs/privkey.pem", nil))
  38.  
  39. }
  40.  
  41. func withCors(handler func(w http.ResponseWriter, r *http.Request)) http.Handler {
  42. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  43. addCors(&w)
  44. if r.Method == http.MethodOptions {
  45. return
  46. }
  47. handler(w, r)
  48. })
  49. }
  50.  
  51. func addCors(w *http.ResponseWriter) {
  52. (*w).Header().Set("Access-Control-Allow-Credentials", "true")
  53. (*w).Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
  54. (*w).Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
  55. (*w).Header().Set("Access-Control-Allow-Origin", "*")
  56. }
  57.  
  58. func addGmGiftReward(w http.ResponseWriter, r *http.Request) {
  59. // b, err := ioutil.ReadAll(r.Body)
  60. // defer r.Body.Close()
  61. // if err != nil {
  62. // // http.Error(w, err.Error(), 500)
  63. // fmt.Print("send err", err)
  64. // return
  65. // }
  66.  
  67. // // Unmarshal
  68. // var msg Message
  69. // err = json.Unmarshal(b, &msg)
  70. // if err != nil {
  71. // fmt.Print("Unmarshal err", err, "body ", string(b))
  72. // http.Error(w, err.Error(), 500)
  73. // return
  74. // }
  75.  
  76. // dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
  77. // config.GameDBUser,
  78. // config.GameDBPassword,
  79. // config.GameDBHost,
  80. // config.GameDBPort,
  81. // config.GameDBName)
  82.  
  83. // conn, err := sql.Open("mysql", dataSource)
  84. // if err != nil {
  85. // fmt.Print("conn open err", err)
  86. // http.Error(w, err.Error(), 500)
  87. // return
  88. // }
  89. // defer conn.Close()
  90. // msg.Message = strings.ReplaceAll(msg.Message, ",", "")
  91. // uids := strings.Fields(msg.UIDS)
  92.  
  93. // Param := fmt.Sprintf("{ gold_free=%s , chip_free=%s , ticket_free=%s, source=gm_gift, title=%s, message=%s}", msg.Gold, msg.Chip, msg.Ticket, msg.Title, msg.Message)
  94. // for i := 0; i < len(uids); i++ {
  95. // platform, err := models.GetUserPlatform(conn, uids[i])
  96. // if err == nil {
  97. // switch platform {
  98. // case UserTypeFacebook:
  99. // models.SaveUserBatch(conn, uids[i], platform, "fb", Param)
  100. // case UserTypeLine:
  101. // models.SaveUserBatch(conn, uids[i], platform, "ln", Param)
  102. // case UserTypeGooglePlay:
  103. // models.SaveUserBatch(conn, uids[i], platform, "gp", Param)
  104. // case UserTypeGameCenter:
  105. // models.SaveUserBatch(conn, uids[i], platform, "gc", Param)
  106. // case UserTypeTouringIOS:
  107. // models.SaveUserBatch(conn, uids[i], platform, "gi", Param)
  108. // case UserTypeSignInWithApple:
  109. // models.SaveUserBatch(conn, uids[i], platform, "ap", Param)
  110. // }
  111. // }
  112. // }
  113. // numUser := len(uids)
  114. // gold, _ := strconv.Atoi(msg.Gold)
  115. // chip, _ := strconv.Atoi(msg.Chip)
  116. // ticket, _ := strconv.Atoi(msg.Ticket)
  117. // giftLog := fmt.Sprintf("gold=%v ,chip=%v ,ticket=%v ", gold*numUser, chip*numUser, ticket*numUser)
  118. // go saveWebLog(msg.GMUsername, Param, msg.UIDS, "GM_Gift", numUser, giftLog)
  119. // fmt.Fprint(w, "success")
  120. }
  121.  
  122. func GetInventoryItems(w http.ResponseWriter, r *http.Request) {
  123.  
  124. // dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
  125. // config.GameDBUser,
  126. // config.GameDBPassword,
  127. // config.GameDBHost,
  128. // config.GameDBPort,
  129. // config.GameDBName)
  130.  
  131. // conn, err := sql.Open("mysql", dataSource)
  132. // if err != nil {
  133. // fmt.Print("conn open err", err)
  134. // http.Error(w, err.Error(), 500)
  135. // return
  136. // }
  137. // defer conn.Close()
  138. // respItems, err := models.GetProfileItemList(conn)
  139. // fmt.Print("err GetInventoryItems ", err)
  140. // jsonResp, err := json.Marshal(respItems)
  141. // if err != nil {
  142. // fmt.Print("json.Marshal ", err)
  143. // }
  144. // // go saveWebLog(msg.GMUsername, Param, msg.UIDS, "GM_Gift", numUser, giftLog)
  145. fmt.Fprint(w, "Done")
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement