Beispiel #1
0
func GetZonenameByZoneid(zoneid uint32) (int, string) {
	query_string := "select GAME,NAME from zoneInfo where zone = " + strconv.Itoa(int(zoneid))
	rows, res, err := db.Query(query_string)
	if err != nil {
		logging.Error("select err:%s,%s", err.Error(), zoneid)
		return 0, ""
	}
	if len(rows) == 0 {
		return 3055, "none"
	}
	game := res.Map("GAME")
	name := res.Map("NAME")
	convert, err1 := iconv.Open("GB2312", "UTF-8")
	for _, row := range rows {
		gamename := row.Str(name)
		if err1 == nil {
			var err2 error
			gamename, err2 = convert.ConvString(row.Str(name))
			if err2 != nil {
				gamename = row.Str(name)
			}
		}
		return row.Int(game), gamename
	}
	return 0, ""
}
Beispiel #2
0
func HandleGonghuiUserCard(w http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()
	sndaid, _ := strconv.Atoi(req.FormValue("sndaId"))
	maxlevel := 0
	keystring := ""
	userid := 0
	name := ""
	accid := 0
	plat_accid := 0
	zone := 0
	rows, res, err := db_monitor.Query("SELECT KEYSTRING,USERID,NAME,`ZONE`,ACCID,PLAT_ACCID FROM SDO_GONGHUI_CARD_USER WHERE PLAT_ACCID = " + req.FormValue("sndaId"))
	if err != nil {
		logging.Error("select err:%s", err.Error())
		return
	}
	convert, err1 := iconv.Open("GB2312", "UTF-8")
	if len(rows) != 0 {
		KEYSTRING := res.Map("KEYSTRING")
		USERID := res.Map("USERID")
		NAME := res.Map("NAME")
		ZONE := res.Map("ZONE")
		ACCID := res.Map("ACCID")
		PLAT_ACCID := res.Map("PLAT_ACCID")
		keystring = rows[0].Str(KEYSTRING)
		userid = rows[0].Int(USERID)
		if err1 == nil {
			var err2 error
			name, err2 = convert.ConvString(rows[0].Str(NAME))
			if err2 != nil {
				name = rows[0].Str(NAME)
			}
		} else {
			name = rows[0].Str(NAME)
		}
		accid = rows[0].Int(ACCID)
		zone = rows[0].Int(ZONE)
		plat_accid = rows[0].Int(PLAT_ACCID)
	}
	ret := SdoRetCard{
		Return_code:    0,
		Return_message: "",
		Data: SdoRetCardData{
			SndaId:     uint(sndaid),
			KeyString:  keystring,
			Charid:     uint(userid),
			Name:       name,
			Accid:      uint(accid),
			Zone:       uint(zone),
			Plat_accid: uint(plat_accid),
		},
	}
	b, _ := json.Marshal(ret)
	w.Write(b)
	logging.Debug("gonghui card:%s,%d", req.FormValue("sndaId"), maxlevel)
}
Beispiel #3
0
// juxian game auth
func OnJuXianCheckName(w http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()
	game_plat := game.GetGameNameByUrl(req.URL.Path) + "_" + game.GetPlatNameByUrl(req.URL.Path)
	qid := req.FormValue("qid")
	server_id := req.FormValue("server_id")
	sign := req.FormValue("sign")
	logging.Debug("juxian request checkname:%s,%s,%s", qid, req.RemoteAddr, req.URL.Path)
	hash := md5.New()
	mystr := "qid=" + qid + "&server_id=" + server_id + config.GetConfigStr(game_plat+"_key")
	io.WriteString(hash, mystr)
	mysign := fmt.Sprintf("%x", hash.Sum(nil))
	if strings.ToLower(mysign) != strings.ToLower(sign) {
		hash.Reset()
		mystr1 := "qid=" + qid + "&server_id=" + server_id + "&sign=" + config.GetConfigStr(game_plat+"_key")
		io.WriteString(hash, mystr1)
		mysign := fmt.Sprintf("%x", hash.Sum(nil))
		if strings.ToLower(mysign) != strings.ToLower(sign) {
			hash.Reset()
			mystr2 := qid + server_id + config.GetConfigStr(game_plat+"_key")
			io.WriteString(hash, mystr2)
			mysign := fmt.Sprintf("%x", hash.Sum(nil))
			if strings.ToLower(mysign) != strings.ToLower(sign) {
				logging.Debug("juxian md5 check err:%s,%s,%s,%s,%s", mystr, mystr1, mystr2, mysign, sign)
				ret := ErrorState{Result: "-1"}
				b, _ := json.Marshal(ret)
				w.Write(b)
				return
			}
			return
		}
	}

	//account := qid

	myaccid, err := db.GetMyAccountByAccountId(game.GetPlatNameByUrl(req.URL.Path), qid)
	if err != nil {
		http.Redirect(w, req, config.GetConfigStr(game_plat+"_err"), 303)
		return
	}
	zoneid, _ := strconv.Atoi(server_id)
	gameid, _ := db.GetZonenameByZoneid(uint32(zoneid))
	logging.Debug("request check ok:%s,%d,%d,%d", qid, myaccid, gameid, zoneid)
	serverid, _ := strconv.Atoi(server_id)
	server_id = strconv.Itoa((gameid << 16) + serverid)
	names := db.GetAllZoneCharNameByAccid(server_id, myaccid)
	if names == nil || len(names) == 0 {
		logging.Debug("names err:%d", myaccid)
		ret := ErrorState{Result: "-3"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	nicks := NickNameList{
		Result: "1",
		Data:   make([]NickName, len(names)),
	}
	convert, _ := iconv.Open("GB2312", "UTF-8")
	for i, name := range names {
		charname, _ := convert.ConvString(name.CharName)
		fmt.Println(name.CharId, charname)
		nicks.Data[i].Nickid = name.CharId
		nicks.Data[i].Nickname = charname
	}
	b, _ := json.Marshal(nicks)
	fmt.Println(string(b))
	w.Write(b)
}
Beispiel #4
0
// juxian game auth
func OnKuaiWanCheckName(w http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()
	logging.Debug("kw request login:%s,%s", req.RemoteAddr, req.URL.Path)
	game_plat := game.GetGameNameByUrl(req.URL.Path) + "_" + game.GetPlatNameByUrl(req.URL.Path)
	account := req.FormValue("login_name")
	game_id := req.FormValue("game_id")
	server_id := req.FormValue("server_id")
	from_id := req.FormValue("from_id")
	sign := req.FormValue("token")
	hash := md5.New()
	mystr := from_id + game_id + account + server_id + config.GetConfigStr(game_plat+"_key")
	io.WriteString(hash, mystr)
	mysign := fmt.Sprintf("%x", hash.Sum(nil))
	if mysign != sign {
		logging.Debug("kuaiwan md5 check err:%s,%s,%s", mystr, mysign, sign)
		ret := ErrorState{Result: "-1"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	if from_id == "" {
		logging.Debug("account err:%s", mystr)
		ret := ErrorState{Result: "-2"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	if account == "" || len(account) > 20 {
		logging.Debug("account err:%s", mystr)
		ret := ErrorState{Result: "-3"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}

	account = from_id + "_" + account
	_, myaccid, err := db.GetMyAccount(game.GetPlatNameByUrl(req.URL.Path), account, "")
	if err != nil {
		logging.Debug("my account err:%s", account)
		ret := ErrorState{Result: "-3"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	names := db.GetAllZoneCharNameByAccid(server_id, myaccid)
	if names == nil || len(names) == 0 {
		logging.Debug("names err:%d", myaccid)
		ret := ErrorState{Result: "-3"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	nicks := NickNameList{
		Result: "1",
		Data:   make([]NickName, len(names)),
	}
	convert, _ := iconv.Open("GB2312", "UTF-8")
	for i, name := range names {
		charname, _ := convert.ConvString(name.CharName)
		fmt.Println(name.CharId, charname)
		nicks.Data[i].Nickid = name.CharId
		nicks.Data[i].Nickname = charname
	}
	b, _ := json.Marshal(nicks)
	fmt.Println(string(b))
	w.Write(b)
}