예제 #1
0
파일: mysql.go 프로젝트: navy1125/gameauth
func addMyAccount(channel, account, accountid string) (string, uint32, error) {
	query_string := "insert into ACCOUNT (CHANNEL,ACCOUNT,ACCOUNTID) values( '" + channel + "' , '" + account + "' , " + accountid + ")"
	_, res, err := db.Query(query_string)
	if err != nil {
		logging.Error("insert err:%s", err.Error())
		return "", 0, err
	}
	logging.Info("new account,%s,%d", channel+":"+account+":"+accountid, uint32(res.InsertId()))
	return channel + ":" + account + ":" + accountid, uint32(res.InsertId()), nil
}
예제 #2
0
파일: bw.go 프로젝트: navy1125/gameauth
func (self *GameBillingBw) Billing(zoneid uint32, myaccid uint32, charid uint32, moneynum uint32) error {
	cmd := Cmd.NewStReturnPlatformToGoldZoneBillUserCmd()
	cmd.Zoneid = zoneid
	cmd.Accid = myaccid
	cmd.Charid = charid
	cmd.DwNum = moneynum
	if self.task != nil {
		self.task.SendCmd(cmd)
	}
	logging.Info("bw billing :%d,%d,%d,%d", zoneid, myaccid, charid, moneynum)

	return nil
}
예제 #3
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/logfilename.log", "log file name"))
	config.SetConfig("deamon", *flag.String("deamon", "false", "need run as demo"))
	config.SetConfig("port", *flag.String("port", "8000", "http port "))
	config.SetConfig("log", *flag.String("log", "debug", "logger level "))
	config.LoadFromFile(config.GetConfigStr("config"), "global")
	if err := config.LoadFromFile(config.GetConfigStr("config"), "SdoOnlineServer"); 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("SDO", logger)
	mysqlurl := config.GetConfigStr("mysql")
	if ok, err := regexp.MatchString("^mysql://.*:.*@.*/.*$", mysqlurl); ok == false || err != nil {
		logging.Error("mysql config syntax err:%s", mysqlurl)
		return
	}
	logging.Info("server starting...")
	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_login = mysql.New("tcp", "", mysqlurls[2]+":"+mysqlurls[3], mysqlurls[0], mysqlurls[1], mysqlurls[4])
	if err != nil {
		logging.Error("db connect error:%s", err.Error())
		return
	}
	mysqlurl = config.GetConfigStr("mysql_monitor")
	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_monitor = mysql.New("tcp", "", mysqlurls[2]+":"+mysqlurls[3], mysqlurls[0], mysqlurls[1], mysqlurls[4])
	if err != nil {
		logging.Error("db connect error:%s", err.Error())
		return
	}
	mysqlurl = config.GetConfigStr("mysql_account")
	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_account = mysql.New("tcp", "", mysqlurls[2]+":"+mysqlurls[3], mysqlurls[0], mysqlurls[1], mysqlurls[4])
	if err != nil {
		logging.Error("db connect error:%s", err.Error())
		return
	}
	http.HandleFunc("/online", OnlineServer)
	http.HandleFunc("/online/country", OnlineCountryServer)
	http.HandleFunc("/gjia/maxlevel", HandleMaxlevel)
	http.HandleFunc("/gjia/isprecreate", HandleIsPrecreate)
	http.HandleFunc("/gjia/isonline", HandleIsOnline)
	http.HandleFunc("/card/gonghuiuser", HandleGonghuiUserCard)
	http.HandleFunc("/card/gonghuikey", HandleGonghuiKeyCard)
	err = http.ListenAndServe(":"+config.GetConfigStr("port"), nil)
	if err != nil {
		logging.Error("ListenAndServe:%s", err.Error())
	}
	logging.Info("server stop...")
}
예제 #4
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...")
}