Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "net/http"
- )
- const (
- UserTypeFacebook string = "facebook"
- UserTypeGameCenter string = "game_center"
- UserTypeGooglePlay string = "google_play"
- UserTypeTouringIOS string = "touring_ios"
- UserTypeTouringAndroid string = "touring_android"
- UserTypeSignInWithApple string = "sign_in_with_apple"
- UserTypeLine string = "line"
- )
- type Message struct {
- Title string `json:"title"`
- Message string `json:"message"`
- Gold string `json:"gold"`
- Chip string `json:"chip"`
- Ticket string `json:"ticket"`
- UIDS string `json:"UIDS"`
- GMUsername string `json:"GMUsername"`
- }
- func main() {
- fmt.Println("----- Start server at port 11433 -----")
- // http.Handle("/addGmGiftReward", withCors(addGmGiftReward))
- // http.Handle("/getInventoryItems", withCors(GetInventoryItems))
- //http.Handle("/getInventoryItems", withCors(GetInventoryItems))
- http.HandleFunc("/getInventoryItems", GetInventoryItems)
- http.ListenAndServe("0.0.0.0:11433", nil)
- //log.Fatal(http.ListenAndServeTLS("0.0.0.0:11433", "certs/fullchain.pem", "certs/privkey.pem", nil))
- }
- func withCors(handler func(w http.ResponseWriter, r *http.Request)) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- addCors(&w)
- if r.Method == http.MethodOptions {
- return
- }
- handler(w, r)
- })
- }
- func addCors(w *http.ResponseWriter) {
- (*w).Header().Set("Access-Control-Allow-Credentials", "true")
- (*w).Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
- (*w).Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
- (*w).Header().Set("Access-Control-Allow-Origin", "*")
- }
- func addGmGiftReward(w http.ResponseWriter, r *http.Request) {
- // b, err := ioutil.ReadAll(r.Body)
- // defer r.Body.Close()
- // if err != nil {
- // // http.Error(w, err.Error(), 500)
- // fmt.Print("send err", err)
- // return
- // }
- // // Unmarshal
- // var msg Message
- // err = json.Unmarshal(b, &msg)
- // if err != nil {
- // fmt.Print("Unmarshal err", err, "body ", string(b))
- // http.Error(w, err.Error(), 500)
- // return
- // }
- // dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
- // config.GameDBUser,
- // config.GameDBPassword,
- // config.GameDBHost,
- // config.GameDBPort,
- // config.GameDBName)
- // conn, err := sql.Open("mysql", dataSource)
- // if err != nil {
- // fmt.Print("conn open err", err)
- // http.Error(w, err.Error(), 500)
- // return
- // }
- // defer conn.Close()
- // msg.Message = strings.ReplaceAll(msg.Message, ",", "")
- // uids := strings.Fields(msg.UIDS)
- // 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)
- // for i := 0; i < len(uids); i++ {
- // platform, err := models.GetUserPlatform(conn, uids[i])
- // if err == nil {
- // switch platform {
- // case UserTypeFacebook:
- // models.SaveUserBatch(conn, uids[i], platform, "fb", Param)
- // case UserTypeLine:
- // models.SaveUserBatch(conn, uids[i], platform, "ln", Param)
- // case UserTypeGooglePlay:
- // models.SaveUserBatch(conn, uids[i], platform, "gp", Param)
- // case UserTypeGameCenter:
- // models.SaveUserBatch(conn, uids[i], platform, "gc", Param)
- // case UserTypeTouringIOS:
- // models.SaveUserBatch(conn, uids[i], platform, "gi", Param)
- // case UserTypeSignInWithApple:
- // models.SaveUserBatch(conn, uids[i], platform, "ap", Param)
- // }
- // }
- // }
- // numUser := len(uids)
- // gold, _ := strconv.Atoi(msg.Gold)
- // chip, _ := strconv.Atoi(msg.Chip)
- // ticket, _ := strconv.Atoi(msg.Ticket)
- // giftLog := fmt.Sprintf("gold=%v ,chip=%v ,ticket=%v ", gold*numUser, chip*numUser, ticket*numUser)
- // go saveWebLog(msg.GMUsername, Param, msg.UIDS, "GM_Gift", numUser, giftLog)
- // fmt.Fprint(w, "success")
- }
- func GetInventoryItems(w http.ResponseWriter, r *http.Request) {
- // dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
- // config.GameDBUser,
- // config.GameDBPassword,
- // config.GameDBHost,
- // config.GameDBPort,
- // config.GameDBName)
- // conn, err := sql.Open("mysql", dataSource)
- // if err != nil {
- // fmt.Print("conn open err", err)
- // http.Error(w, err.Error(), 500)
- // return
- // }
- // defer conn.Close()
- // respItems, err := models.GetProfileItemList(conn)
- // fmt.Print("err GetInventoryItems ", err)
- // jsonResp, err := json.Marshal(respItems)
- // if err != nil {
- // fmt.Print("json.Marshal ", err)
- // }
- // // go saveWebLog(msg.GMUsername, Param, msg.UIDS, "GM_Gift", numUser, giftLog)
- fmt.Fprint(w, "Done")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement