Esempio n. 1
0
func OnJuXianBill(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")
	order_amount := req.FormValue("order_amount")
	order_id := req.FormValue("order_id")
	server_id := req.FormValue("server_id")
	sign := req.FormValue("sign")
	logging.Debug("juxian request bill:%s,%s,%s", qid, req.RemoteAddr, req.URL.Path)
	hash := md5.New()
	mystr := qid + order_amount + order_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 + "&order_amount=" + order_amount + "&order_id=" + order_id + "&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=" + qid + "&order_amount=" + order_amount + "&order_id=" + order_id + "&server_id=" + server_id + "&sign=" + 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("md5 check err:%s,%s,%s,%s,%s", mystr, mystr1, mystr2, mysign, sign)
				w.Write([]byte("0"))
				return
			}
		}
	}

	myaccid, err := db.GetMyAccountByAccountId(game.GetPlatNameByUrl(req.URL.Path), qid)
	if err != nil {
		logging.Debug("bill account err:%s", qid)
		w.Write([]byte("3"))
		return
	}
	zoneid, _ := strconv.Atoi(server_id)
	gameid, _ := db.GetZonenameByZoneid(uint32(zoneid))
	logging.Debug("request bill 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("bill checkname err:%d,%s", myaccid, qid)
		w.Write([]byte("3"))
		return
	}
	moneynum, _ := strconv.ParseFloat(order_amount, 32)
	game.Billing(game.GetGameNameByUrl(req.URL.Path), server_id, myaccid, 0, uint32(moneynum*100))
	w.Write([]byte("1"))
}
Esempio n. 2
0
func OnlineCountryServer(w http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()
	min := int((GetUnixTime())/60) - 1
	if last_online_country_min == min && last_online_country_out_string != "" {
		io.WriteString(w, last_online_country_out_string+"\n")
		logging.Debug("quest online num:%s,%s,%d,%s", req.RemoteAddr, req.URL.Path, min, last_online_country_out_string)
		return
	}
	last_online_country_min = min
	rows, res, err := db_login.Query("SELECT zone FROM zoneInfo")
	if err != nil {
		logging.Error("select err:%s", err.Error())
		return
	}
	zones := make(map[int]int)
	for _, row := range rows {
		zoneid := res.Map("zone")
		id := row.Int(zoneid)
		zones[(id<<16)+3] = 0
		zones[(id<<16)+4] = 0
		zones[(id<<16)+5] = 0
		zones[(id<<16)+6] = 0
	}
	rows, res, err = db_monitor.Query("select * from COUNTRYONLINENUM_TODAY where timestamp_min = " + strconv.Itoa(min))
	if err != nil {
		logging.Error("select err:%s", err.Error())
	}
	if len(rows) == 0 {
		min = int((GetUnixTime())/60) - 2
		rows, res, err = db_monitor.Query("select * from COUNTRYONLINENUM_TODAY where timestamp_min = " + strconv.Itoa(min))
		if err != nil {
			logging.Error("select err:%s", err.Error())
		}

	}
	last_online_country_out_string = ""
	for _, row := range rows {
		zoneid := res.Map("ZONEID")
		country := res.Map("COUNTRY")
		onlinenum := res.Map("ONLINENUM")
		zones[int(((row.Int(zoneid)&0X0000FFFF)<<16)+row.Int(country))] = row.Int(onlinenum)
	}
	for id, num := range zones {
		if num > 0 {
			last_online_country_out_string += strconv.Itoa(int(id>>16)) + "\\" + strconv.Itoa(int(int16(id))) + "\\" + strconv.Itoa(num) + ";"
		}
	}
	io.WriteString(w, last_online_country_out_string+"\n")
	logging.Debug("quest online num:%s,%s,%d,%s", req.RemoteAddr, req.URL.Path, min, last_online_country_out_string)
}
Esempio n. 3
0
func HandleMaxlevel(w http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()
	maxlevel := 0
	sndaid, _ := strconv.Atoi(req.FormValue("sndaId"))
	rows, res, err := db_monitor.Query("SELECT MAXLEVEL FROM USERMAXLEVEL WHERE ACCOUNT = 'S:" + req.FormValue("sndaId") + ":" + req.FormValue("sndaId") + "'")
	if err != nil {
		logging.Error("select err:%s", err.Error())
		return
	}
	if len(rows) != 0 {
		level := res.Map("MAXLEVEL")
		maxlevel = rows[0].Int(level)
	}
	ret := SdoRet{
		Return_code:    0,
		Return_message: "",
		Data: SdoRetData{
			SndaId:   uint(sndaid),
			MaxLevel: maxlevel,
		},
	}
	b, _ := json.Marshal(ret)
	w.Write(b)
	logging.Debug("maxlevel:%s,%d", req.FormValue("sndaId"), maxlevel)
}
Esempio n. 4
0
func HandleIsOnline(w http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()
	accid, sndaid := GetAccidBySndaId(req.FormValue("sndaId"))
	ret := SdoRet{
		Return_code:    0,
		Return_message: "",
		Data: SdoRetData{
			SndaId:  uint(sndaid),
			Logined: false,
		},
	}
	for zoneid, _ := range zoneid_map {
		query_string := fmt.Sprintf("SELECT LASTDAY FROM USER_DATA_%d where ACCID=%d", zoneid, accid)
		rows, res, err := db_monitor.Query(query_string)
		if err != nil {
			continue
		}
		if len(rows) != 0 {
			LASTDAY := res.Map("LASTDAY")
			lastday := rows[0].Int(LASTDAY)
			if int(lastday/1440) == int(GetUnixTime()/86400) {
				ret.Data.Logined = true
				break
			}
		}
	}
	b, _ := json.Marshal(ret)
	w.Write(b)
	logging.Debug("isonline:%s,%v", req.FormValue("sndaId"), ret.Data.Logined)
}
Esempio n. 5
0
func HandleGonghuiKeyCard(w http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()
	var keystring string
	var count int
	rows, res, err := db_monitor.Query("SELECT COUNT(USERID) AS COUNT FROM SDO_GONGHUI_CARD_USER WHERE KEYSTRING = '" + req.FormValue("KeyString") + "'")
	if err != nil {
		logging.Error("select err:%s", err.Error())
		return
	}
	if len(rows) != 0 {
		COUNT := res.Map("COUNT")
		count = rows[0].Int(COUNT)
	}
	ret := SdoRetCardCount{
		Return_code:    0,
		Return_message: "",
		Data: SdoRetCardCountData{
			KeyString: keystring,
			Count:     uint(count),
		},
	}
	b, _ := json.Marshal(ret)
	w.Write(b)
	logging.Debug("gonghui keystring:%s", req.FormValue("sndaId"))
}
Esempio n. 6
0
func HandleIsPrecreate(w http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()
	accid, sndaid := GetAccidBySndaId(req.FormValue("sndaId"))
	ret := SdoRet{
		Return_code:    0,
		Return_message: "",
		Data: SdoRetData{
			SndaId:      uint(sndaid),
			IsPreCreate: false,
		},
	}
	for zoneid, _ := range zoneid_map {
		query_string := fmt.Sprintf("SELECT FIRSTDAY FROM USER_DATA_%d where ACCID=%d", zoneid, accid)
		rows, res, err := db_monitor.Query(query_string)
		if err != nil {
			continue
		}
		if len(rows) != 0 {
			FIRSTDAY := res.Map("FIRSTDAY")
			firstday := rows[0].Int(FIRSTDAY)
			//if firstday < int(GetUnixTime()/60) {
			if firstday < int(1406181600/60) {
				ret.Data.IsPreCreate = true
				break
			}
		}
	}
	b, _ := json.Marshal(ret)
	w.Write(b)
	logging.Debug("isprecreate:%s,%v", req.FormValue("sndaId"), ret.Data.IsPreCreate)
}
Esempio n. 7
0
// juxian game auth
func On619GameAuth(w http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()
	logging.Debug("619 request login:%s,%s", req.RemoteAddr, req.URL.Path)
	game_plat := game.GetGameNameByUrl(req.URL.Path) + "_" + game.GetPlatNameByUrl(req.URL.Path)
	StationId := req.FormValue("StationId")
	account := req.FormValue("UserId")
	timestr := req.FormValue("Time")
	game_id := req.FormValue("GameId")
	server_id := req.FormValue("ServerId")
	sign := req.FormValue("Sign")
	hash := md5.New()
	mystr := "StationId=" + StationId + "&" + account + "&" + game_id + "&" + server_id + "&" + config.GetConfigStr(game_plat+"_key") + "_" + timestr
	io.WriteString(hash, mystr)
	mysign := fmt.Sprintf("%x", hash.Sum(nil))
	if mysign != sign {
		logging.Debug("md5 check err:%s,%s,%s", mystr, mysign, sign)
		//TODO redirect error page
		http.Redirect(w, req, config.GetConfigStr(game_plat+"_err"), 303)
		return
	}
	if account == "" {
		http.Redirect(w, req, config.GetConfigStr(game_plat+"_err"), 303)
		logging.Debug("account and qid can not be none both:%s", mystr)
		return
	}
	tr, _ := strconv.Atoi(timestr)
	diffsec := math.Abs(float64(time.Now().Unix() - int64(tr)))
	if diffsec > time.Hour.Seconds()*24 {
		http.Redirect(w, req, config.GetConfigStr(game_plat+"_err"), 303)
		logging.Debug("time err:%s,%d,%d", mystr, time.Now().Unix(), diffsec)
		return
	}

	myaccount, myaccid, err := db.GetMyAccount(game.GetPlatNameByUrl(req.URL.Path), account, "")
	if err != nil {
		http.Redirect(w, req, config.GetConfigStr(game_plat+"_err"), 303)
		return
	}
	logging.Debug("request login ok:%s,%d", myaccount, myaccid)
	gameid, _ := strconv.Atoi(game_id)
	serverid, _ := strconv.Atoi(server_id)
	server_id = strconv.Itoa((gameid << 16) + serverid)
	game.AddLoginToken(game.GetGameNameByUrl(req.URL.Path), server_id, myaccount, myaccid, 1, mysign, w, game.GetPlatNameByUrl(req.URL.Path), req, config.GetConfigStr(game_plat+"_err"))
	//para := fmt.Sprintf("?account=%s&accid=%d&server_id=%s", myaccount, myaccid, server_id)
	//http.Redirect(w, req, config.GetConfigStr(game_plat+"_ok")+para, 303)
	//TODO redirect to gamepage
}
Esempio n. 8
0
func OnlineServer(w http.ResponseWriter, req *http.Request) {
	defer req.Body.Close()
	min := int((GetUnixTime())/60) - 1
	if last_online_min == min && last_online_out_string != "" {
		io.WriteString(w, last_online_out_string+"\n")
		logging.Debug("quest online num:%s,%s,%d,%s", req.RemoteAddr, req.URL.Path, min, last_online_out_string)
		return
	}
	last_online_min = min
	rows, res, err := db_login.Query("SELECT game,zone,name FROM zoneInfo")
	if err != nil {
		logging.Error("select err:%s", err.Error())
		return
	}
	zones := make(map[int]int)
	for _, row := range rows {
		zoneid := res.Map("zone")
		gameid := res.Map("game")
		name := res.Map("name")
		id := row.Int(zoneid)
		zones[id] = 0
		zoneid_map[uint32(row.Int(gameid)<<16+row.Int(zoneid))] = row.Str(name)
	}
	rows, res, err = db_monitor.Query("select * from ONLINENUM_TODAY where timestamp_min = " + strconv.Itoa(min))
	if err != nil {
		logging.Error("select err:%s", err.Error())
	}
	if len(rows) == 0 {
		min = int((GetUnixTime())/60) - 2
		rows, res, err = db_monitor.Query("select * from ONLINENUM_TODAY where timestamp_min = " + strconv.Itoa(min))
		if err != nil {
			logging.Error("select err:%s", err.Error())
		}

	}
	last_online_out_string = ""
	for _, row := range rows {
		zoneid := res.Map("zone_id")
		onlinenum := res.Map("online_number")
		zones[int(int16(row.Int(zoneid)))] = row.Int(onlinenum)
	}
	for id, num := range zones {
		last_online_out_string += strconv.Itoa(int(int16(id))) + "\\" + strconv.Itoa(num) + ";"
	}
	io.WriteString(w, last_online_out_string+"\n")
	logging.Debug("quest online num:%s,%s,%d,%s", req.RemoteAddr, req.URL.Path, min, last_online_out_string)
}
Esempio n. 9
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)
}
Esempio n. 10
0
func (self *GameLoginBw) Login(zoneid uint32, myaccount string, myaccid uint32, isAdult uint32, token string, w http.ResponseWriter, platname string, req *http.Request, err_url string) error {
	game := 0
	game, tmpl_data.Zonename = db.GetZonenameByZoneid(zoneid)
	tmpl_data.Token = token
	tmpl_data.Zoneid = strconv.Itoa(int(zoneid))
	tmpl_data.Zonetype = "0"
	tmpl_data.Nettype = "0"
	starttype := req.FormValue("starttype")
	if starttype != "" {
		tmpl_data.Starttype = starttype
	}
	logintype := req.FormValue("logintype")
	tmpl_data.Configpath = config.GetConfigStr("bw_configpath") + platname + ".xml"
	cmd := Cmd.NewStWebLoginUserTokenWebGateUserCmd()
	cmd.Zoneid = uint32((game << 16) + int(zoneid))
	cmd.Accid = myaccid
	for i, v := range myaccount {
		cmd.Account[i] = byte(v)
	}
	cmd.Lifetime = 3600 //token过期时间,0表示只登陆一次
	cmd.UserType = 1    ///ChannelType
	cmd.Type = isAdult
	for i, v := range token {
		cmd.Token[i] = byte(v)
	}
	if self.task != nil {
		self.task.SendCmd(cmd)
	}
	if logintype == "1" {
		page := `<!DOCTYPE html>
	<html>
		<head>
			<title></title>
		</head>
		<body>
			<script type="text/javascript">
				window.location.href = "%s";
			</script>
		</body>
	</html>
		`
		url := fmt.Sprintf("/api/entergame?server=%d&servername=%s&token=%s", zoneid, tmpl_data.Zonename, token)
		w.Write([]byte(fmt.Sprintf(page, url)))
		return nil
	}
	tmpl_data.Loginurl = err_url
	err := tmpl.Execute(w, tmpl_data)
	if err != nil {
		logging.Debug("excute game page error:%s", err.Error())
		return err
	}

	return nil
}
Esempio n. 11
0
func GetAccidBySndaId(sndastr string) (uint32, uint32) {
	sndaid, _ := strconv.Atoi(sndastr)
	accid := uint32(0)
	rows, res, err := db_account.Query("SELECT ACCID FROM ACCOUNT WHERE ACCOUNTID = " + strconv.Itoa(int(sndaid)))
	if err != nil {
		logging.Error("select err:%s", err.Error())
		return accid, uint32(sndaid)
	}
	if len(rows) != 0 {
		id := res.Map("ACCID")
		accid = uint32(rows[0].Int(id))
	}
	logging.Debug("accid:%d,%d", sndaid, accid)
	return accid, uint32(sndaid)
}
Esempio n. 12
0
func (self *GameLoginBw) Connect() *net.TCPConn {
	cfg := config.NewConfig()
	if err := cfg.LoadFromFile(config.GetConfigStr("loginServerList"), "LoginServerList"); err != nil {
		logging.Error("init game err,%s", err.Error())
		return nil
	}
	addr := cfg.GetConfigStr("ip") + ":" + cfg.GetConfigStr("port")
	raddr, _ := net.ResolveTCPAddr("tcp", addr)
	conn, err := net.DialTCP("tcp", nil, raddr)
	if err != nil {
		logging.Error("conn err:%s,1%s", addr, err.Error())
		return nil
	}
	logging.Debug("new connection:%s", conn.RemoteAddr())
	return conn
}
Esempio n. 13
0
func (self *GameLoginBw) Init(name string) bool {
	conn := self.Connect()
	tick := time.Tick(time.Second)
	tmpl_data = &BwGameTemplate{}
	tmpl_data.GameName = config.GetConfigStr("bw_gamename")
	tmpl_data.Starttype = config.GetConfigStr("bw_starttype")
	tmpl_data.Patchurl = config.GetConfigStr("bw_patchurl")
	tmpl_data.Allurl = config.GetConfigStr("bw_allurl")
	tmpl_data.Setuppath = config.GetConfigStr("bw_setuppath") + "#" + strconv.Itoa(int(time.Now().Unix()))
	tmpl_data.Loginaddr = config.GetConfigStr("bw_loginaddr")
	tmpl_data.Loginport = config.GetConfigStr("bw_loginport")
	tmpl_data.Configpath = config.GetConfigStr("bw_configpath")
	var err error
	tmpl, err = template.ParseFiles(config.GetConfigStr("bw_plugin") + "/templates/game.html")
	if err != nil {
		logging.Debug("open game page error:%s", err.Error())
		return false
	}
	for {
		select {
		case <-tick:
			if conn == nil {
				conn = self.Connect()
			}
			if conn != nil {
				self.task = bwtask.NewBwTask(conn, "LBW")
				self.task.SetHandleMessage(&handleMessageMap)
				cmd := Cmd.NewStRequestLoginLoginCmd()
				self.task.SendCmd(cmd)
				self.task.Id = 1 //rand.Int63()
				self.task.Name = name
				self.task.Start()
				<-self.task.StopChan
				conn = nil
			}
		}
	}
	return true
}
Esempio n. 14
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)
}
Esempio n. 15
0
func OnJuUcjoyBill(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("accountid")
	gameid := req.FormValue("gameid")
	server_id := req.FormValue("serverid")
	orderid := req.FormValue("orderid")
	order_amount := req.FormValue("point")
	giftcoin := req.FormValue("giftcoin")
	timestamp := req.FormValue("timestamp")
	remark := req.FormValue("remark")
	sign := req.FormValue("sign")
	logging.Debug("ucjoy request bill:%s,%s,%s", qid, req.RemoteAddr, req.URL.Path)
	hash := md5.New()
	mystr := qid + gameid + server_id + orderid + order_amount + giftcoin + timestamp + remark + config.GetConfigStr(game_plat+"_key")
	io.WriteString(hash, mystr)
	mysign := fmt.Sprintf("%x", hash.Sum(nil))
	if strings.ToLower(mysign) != strings.ToLower(sign) {
		logging.Debug("md5 check err:%s,%s,%s", mystr, mysign, sign)
		w.Write([]byte("4"))
		return
	}

	myaccid, err := db.GetMyAccountByAccountId(game.GetPlatNameByUrl(req.URL.Path), qid)
	if err != nil {
		logging.Debug("bill account err:%s", qid)
		w.Write([]byte("3"))
		return
	}
	zoneid, _ := strconv.Atoi(server_id)
	zid := config.GetConfigInt("zqb_zoneid_" + server_id)
	if zid != 0 {
		zoneid = zid
	}
	if zoneid == 11211 {
		zoneid = 11012
	}
	if zoneid == 11238 {
		zoneid = 11013
	}
	if zoneid == 11351 {
		zoneid = 11014
	}
	if zoneid == 11397 {
		zoneid = 11015
	}
	if zoneid == 11396 {
		zoneid = 11999
	}
	if zoneid == 11491 {
		zoneid = 11016
	}
	if zoneid == 11551 {
		zoneid = 11017
	}
	if zoneid == 11592 {
		zoneid = 11018
	}
	if zoneid == 11651 {
		zoneid = 11019
	}
	if zoneid == 11694 {
		zoneid = 11998
	}
	if zoneid == 11771 {
		zoneid = 11020
	}
	if zoneid == 11872 {
		zoneid = 11021
	}
	if zoneid == 11912 {
		zoneid = 11022
	}
	if zoneid == 11931 {
		zoneid = 11023
	}
	if zoneid == 12011 {
		zoneid = 11024
	}
	if zoneid == 12071 {
		zoneid = 11099
	}
	if zoneid == 12091 {
		zoneid = 11025
	}
	if zoneid == 12133 {
		zoneid = 11026
	}
	if zoneid == 12211 {
		zoneid = 11027
	}
	if zoneid == 12220 {
		zoneid = 11098
	}
	mygameid, _ := db.GetZonenameByZoneid(uint32(zoneid))
	logging.Debug("request bill ok:%s,%d,%d,%d", qid, myaccid, mygameid, zoneid)
	serverid := zoneid
	server_id = strconv.Itoa((mygameid << 16) + serverid)
	names := db.GetAllZoneCharNameByAccid(server_id, myaccid)
	if names == nil || len(names) == 0 {
		logging.Debug("bill checkname err:%d,%s", myaccid, qid)
		w.Write([]byte("3"))
		return
	}
	moneynum, _ := strconv.ParseFloat(order_amount, 32)
	game.Billing(game.GetGameNameByUrl(req.URL.Path), server_id, myaccid, 0, uint32(moneynum))
	w.Write([]byte("1"))
}
Esempio n. 16
0
// juxian game auth
func OnJuXianAuth(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")
	timestr := req.FormValue("time")
	server_id := req.FormValue("server_id")
	sign := req.FormValue("sign")
	isAdult := req.FormValue("isAdult")
	account := req.FormValue("account")
	logging.Debug("juxian request login:%s,%s,%s", qid, req.RemoteAddr, req.URL.Path)
	hash := md5.New()
	mystr := "qid=" + qid + "&time=" + timestr + "&server_id=" + server_id + config.GetConfigStr(game_plat+"_key")
	io.WriteString(hash, mystr)
	logging.Debug("%s", mystr)
	mysign := fmt.Sprintf("%x", hash.Sum(nil))
	if strings.ToLower(mysign) != strings.ToLower(sign) {
		hash.Reset()
		mystr1 := "qid=" + qid + "&time=" + timestr + "&server_id=" + server_id + "&sign=" + config.GetConfigStr(game_plat+"_key")
		io.WriteString(hash, mystr1)
		logging.Debug("%s", mystr)
		mysign := fmt.Sprintf("%x", hash.Sum(nil))
		if strings.ToLower(mysign) != strings.ToLower(sign) {
			hash.Reset()
			mystr2 := qid + timestr + server_id + config.GetConfigStr(game_plat+"_key")
			io.WriteString(hash, mystr1)
			logging.Debug("%s", mystr2)
			mysign := fmt.Sprintf("%x", hash.Sum(nil))
			if strings.ToLower(mysign) != strings.ToLower(sign) {
				logging.Debug("md5 check err:%s,%s,%s,%s,%s", mystr, mystr1, mystr2, mysign, sign)
				//TODO redirect error page
				http.Redirect(w, req, config.GetConfigStr(game_plat+"_err"), 303)
				return
			}
		}
	}
	if account == "" {
		account = qid
	}
	if account == "" {
		http.Redirect(w, req, config.GetConfigStr(game_plat+"_err"), 303)
		logging.Debug("account and qid can not be none both:%s", mystr)
		return
	}
	tr, _ := strconv.Atoi(timestr)
	diffsec := math.Abs(float64(time.Now().Unix() - int64(tr)))
	if diffsec > time.Hour.Seconds()*24 {
		http.Redirect(w, req, config.GetConfigStr(game_plat+"_err"), 303)
		logging.Debug("time err:%s,%d,%d", mystr, time.Now().Unix(), diffsec)
		return
	}

	myaccount, myaccid, err := db.GetMyAccount(game.GetPlatNameByUrl(req.URL.Path), account, qid)
	if err != nil {
		http.Redirect(w, req, config.GetConfigStr(game_plat+"_err"), 303)
		return
	}
	logging.Debug("request login ok:%s,%d", myaccount, myaccid)
	adult, _ := strconv.Atoi(isAdult)
	game.AddLoginToken(game.GetGameNameByUrl(req.URL.Path), server_id, myaccount, myaccid, uint32(adult), mysign, w, game.GetPlatNameByUrl(req.URL.Path), req, config.GetConfigStr(game_plat+"_err"))
	//para := fmt.Sprintf("?account=%s&accid=%d&server_id=%s", myaccount, myaccid, server_id)

	//http.Redirect(w, req, config.GetConfigStr(game_plat+"_ok")+para, 303)
	//TODO redirect to gamepage
}
Esempio n. 17
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)
}
Esempio n. 18
0
// juxian game auth
func OnKuaiWanAuth(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")
	timestr := req.FormValue("time")
	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=" + from_id + "&game_id=" + game_id + "&login_name=" + account + "&server_id=" + server_id + "&time=" + timestr + "&key=" + config.GetConfigStr(game_plat+"_key")
	io.WriteString(hash, mystr)
	mysign := fmt.Sprintf("%x", hash.Sum(nil))
	if mysign != sign {
		logging.Debug("OnKuaiWanAuth md5 check err:%s,%s,%s", mystr, mysign, sign)
		ret := ErrorState{Result: "-1"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	if account == "" || len(account) > 20 {
		logging.Debug("account err:%s", mystr)
		ret := ErrorState{Result: "-2"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	if game_id == "" || server_id == "" {
		logging.Debug("account err:%s", mystr)
		ret := ErrorState{Result: "-3"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	if from_id == "" {
		logging.Debug("account err:%s", mystr)
		ret := ErrorState{Result: "-4"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	tr, _ := strconv.Atoi(timestr)
	diffsec := math.Abs(float64(time.Now().Unix() - int64(tr)))
	if diffsec > time.Hour.Seconds()*24 {
		ret := ErrorState{Result: "-5"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}

	account = from_id + "_" + account
	myaccount, myaccid, err := db.GetMyAccount(game.GetPlatNameByUrl(req.URL.Path), account, "")
	if err != nil {
		ret := ErrorState{Result: "-5"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	logging.Debug("request login ok:%s,%d", myaccount, myaccid)
	gameid, _ := strconv.Atoi(game_id)
	serverid, _ := strconv.Atoi(server_id)
	server_id = strconv.Itoa((gameid << 16) + serverid)
	game.AddLoginToken(game.GetGameNameByUrl(req.URL.Path), server_id, myaccount, myaccid, 1, mysign, w, game.GetPlatNameByUrl(req.URL.Path), req, config.GetConfigStr(game_plat+"_err"))
	//para := fmt.Sprintf("?account=%s&accid=%d&server_id=%s", myaccount, myaccid, server_id)
	//http.Redirect(w, req, config.GetConfigStr(game_plat+"_ok")+para, 303)
	//TODO redirect to gamepage
}
Esempio n. 19
0
// juxian game auth
func OnKuaiWanBill(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")
	money := req.FormValue("money")
	order_no := req.FormValue("order_no")
	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 + money + order_no + server_id + config.GetConfigStr(game_plat+"_key")
	io.WriteString(hash, mystr)
	mysign := fmt.Sprintf("%x", hash.Sum(nil))
	if mysign != sign {
		logging.Debug("OnKuaiWanBill md5 check err:%s,%s,%s", mystr, mysign, sign)
		ret := ErrorState{Result: "-1"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	if account == "" || len(account) > 20 {
		logging.Debug("account err:%s", mystr)
		ret := ErrorState{Result: "-2"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	if game_id == "" || server_id == "" {
		logging.Debug("account err:%s", mystr)
		ret := ErrorState{Result: "-3"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	if from_id == "" {
		logging.Debug("account err:%s", mystr)
		ret := ErrorState{Result: "-3"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	moneynum, _ := strconv.Atoi(money)
	if moneynum <= 0 {
		ret := ErrorState{Result: "-4"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	if v, ok := order_map[order_no]; ok {
		if time.Now().Unix()-v < 86400 {
			ret := ErrorState{Result: "-5"}
			b, _ := json.Marshal(ret)
			w.Write(b)
			return
		}
		delete(order_map, order_no)
	}
	order_map[order_no] = time.Now().Unix()

	account = from_id + "_" + account
	myaccount, myaccid, err := db.GetMyAccount(game.GetPlatNameByUrl(req.URL.Path), account, "")
	if err != nil {
		ret := ErrorState{Result: "-6"}
		b, _ := json.Marshal(ret)
		w.Write(b)
		return
	}
	logging.Debug("request OnKuaiWanBill ok:%s,%d", myaccount, myaccid)
	gameid, _ := strconv.Atoi(game_id)
	serverid, _ := strconv.Atoi(server_id)
	server_id = strconv.Itoa((gameid << 16) + serverid)
	game.Billing(game.GetGameNameByUrl(req.URL.Path), server_id, myaccid, 0, uint32(moneynum))
	ret := ErrorState{Result: "1"}
	b, _ := json.Marshal(ret)
	w.Write(b)
}
Esempio n. 20
0
func main() {
	flag.Parse()
	config.SetConfig("config", *flag.String("config", "config.xml", "config xml file for start"))
	config.SetConfig("logfilename", *flag.String("logfilename", "/log/authserver.log", "log file name"))
	config.SetConfig("daemon", *flag.String("daemon", "false", "need run as daemon"))
	config.SetConfig("port", *flag.String("port", "8000", "http port "))
	config.SetConfig("log", *flag.String("log", "debug", "logger level "))
	config.SetConfig("loginServerList", *flag.String("loginServerList", "loginServerList.xml", "server list config"))
	config.SetConfig("bw_plugin", *flag.String("bw_plugin", "game/bw/", "bw_plugin dir"))
	config.LoadFromFile(config.GetConfigStr("config"), "global")
	if err := config.LoadFromFile(config.GetConfigStr("config"), "AuthServer"); err != nil {
		fmt.Println(err)
		return
	}
	if err := config.LoadFromFile(config.GetConfigStr("key"), "Key"); err != nil {
		fmt.Println(err)
		return
	}

	logger, err := logging.NewTimeRotationHandler(config.GetConfigStr("logfilename"), "060102-15")
	if err != nil {
		fmt.Println(err)
		return
	}
	logger.SetLevel(logging.DEBUG)
	logging.AddHandler("AU", logger)
	if config.GetConfigStr("daemon") == "true" {
		logging.DisableStdout()
	}
	logging.Info("server starting...")
	mysqlurl := config.GetConfigStr("mysql")
	if ok, err := regexp.MatchString("^mysql://.*:.*@.*/.*$", mysqlurl); ok == false || err != nil {
		logging.Error("mysql config syntax err:%s", mysqlurl)
		return
	}
	mysqlurl = strings.Replace(mysqlurl, "mysql://", "", 1)
	mysqlurl = strings.Replace(mysqlurl, "@", ":", 1)
	mysqlurl = strings.Replace(mysqlurl, "/", ":", 1)
	mysqlurls := strings.Split(mysqlurl, ":")
	config.SetConfig("dbname", mysqlurls[4])
	db.InitDatabase(mysqlurls[2]+":"+mysqlurls[3], mysqlurls[0], mysqlurls[1], mysqlurls[4])
	mysqlurl = config.GetConfigStr("mysql_checkname")
	if ok, err := regexp.MatchString("^mysql://.*:.*@.*/.*$", mysqlurl); ok == false || err != nil {
		logging.Error("mysql config syntax err:%s", mysqlurl)
		return
	}
	mysqlurl = strings.Replace(mysqlurl, "mysql://", "", 1)
	mysqlurl = strings.Replace(mysqlurl, "@", ":", 1)
	mysqlurl = strings.Replace(mysqlurl, "/", ":", 1)
	mysqlurls = strings.Split(mysqlurl, ":")
	db.InitCheckNameDatabase(mysqlurls[2]+":"+mysqlurls[3], mysqlurls[0], mysqlurls[1], mysqlurls[4])
	plat.InitPlat()
	game.InitLogin()
	game.InitBill()
	//addr, err := net.InterfaceByIndex(0)
	ifname, err := net.InterfaceByName(config.GetConfigStr("ifname"))
	if err != nil {
		fmt.Println("GetLocalIp Err:", err)
		logging.Debug("GetLocalIp Err:%s", err.Error())
	}
	addrs, err := ifname.Addrs()
	if err != nil {
		fmt.Println("GetLocalIp Err:", err)
		logging.Debug("GetLocalIp Err:%s", err.Error())
	} else {
		fmt.Println(addrs[0].String(), addrs[0].Network(), strings.Split(addrs[0].String(), "/")[0])
	}
	//err = http.ListenAndServe(strings.Split(addrs[0].String(), "/")[0]+":"+config.GetConfigStr("port"), nil)
	err = http.ListenAndServe(":"+config.GetConfigStr("port"), nil)
	if err != nil {
		fmt.Println(err)
		logging.Debug("ListenAndServe:%s", err.Error())
	}
	logging.Info("server stop...")
}