Beispiel #1
0
func InitFights() {

	// read combos from techtree
	comboInfo = make([]*Combo, 1)
	comb, _ := techTree.Get("Combos").Map()
	for key, value := range comb {
		cmb := value.(map[string]interface{})
		cmbInfo := &Combo{}
		cmbInfo.Name = key
		cmbInfo.Monster = cmb["Monster"].(string)
		cmbInfo.Comb = cmb["Comb"].(string)
		cmbInfo.Effects = strings.Split(cmb["Effects"].(string), ",")
		cmbInfo.Length = int64(cmb["Length"].(float64))
		cmbInfo.Strength = int64(cmb["Strength"].(float64))
		comboInfo = append(comboInfo, cmbInfo)
	}
	// read effects from techtree
	ttEffInfo, _ := techTree.Get("Effects").Array()
	effectInfo = make([]string, len(ttEffInfo))
	for i, eff := range ttEffInfo {
		effInfo := eff.(map[string]interface{})
		effectInfo[i] = effInfo["Name"].(string)
	}
	// read creatures from techtree
	ttCrInfo, _ := techTree.Get("Creatures").Array()
	crInfo = make([]string, len(ttCrInfo))
	for i, cr := range ttCrInfo {
		ttCrInfo := cr.(map[string]interface{})
		crInfo[i] = ttCrInfo["Name"].(string)
	}

	lcFights = cache.NewLRUCache(&cache.LRUOptions{MaxAge: time.Minute * 10, NoAgeCheck: true})
	go FightsHandleRem()
}
Beispiel #2
0
func StartAuth() {
	gob.Register(make(map[string]string))
	authCache = cache.NewLRUCache(&cache.LRUOptions{Capacity: 128, MaxAge: time.Hour * 1})

	cfgCtrl := srv.Cfg().Get("server")
	sessionkey := cfgCtrl.Get("sessionkey").String()

	http.HandleFunc("/authorize", handleAuthorize)
	http.Handle("/oauth2callback", seshcookie.NewSessionHandler(
		&AuthHandler{},
		sessionkey, nil))

	cfgAU, _ := srv.Cfg().Get("authusers").Array()
	for i := 0; i < len(cfgAU); i++ {
		au := cfgAU[i].(map[string]interface{})
		id := au["id"].(string)
		name := au["name"].(string)
		log.Println("Authorized:", id, name)
		authUsers = append(authUsers, id)
	}

	port := cfgCtrl.Get("port").String()
	addr := cfgCtrl.Get("addr").String()
	if len(redirectAddr) > 0 {
		addr = redirectAddr
	}

	oauthCfg.RedirectURL = "http://" + addr + ":" + port + "/oauth2callback"

	table, _ = db.Main.InitTable(OAuth{})
}
Beispiel #3
0
func InitPlayerMgr() {
	InitConfigDB()
	qtPlayers = geom.NewQuadTree(-180, 180, -90, 90)
	lcPlayers = cache.NewLRUCache(&cache.LRUOptions{Capacity: 0, MaxAge: time.Minute * 5, NoAgeCheck: true})
	go PlayersPosHandleRem()

	tp, _ := db.Main.InitTable(Player{})
	tblPlayer = db.NewTableCached(tp, &db.CacheParams{1024, time.Minute * 30})
	//tblInvItem, _ = db.Main.InitTable(InvItem{})

	var err error
	techTree, err = util.LoadConfigFile("techtree.cfg")
	if err != nil {
		log.Println("Error: Invalid Config File:", err)
		return
	}
	InitResourceMgr()
	InitCreatureMgr()
	InitPOIs()
	InitFights()

	err = db.Main.ApplyRebuilds()
	if err != nil {
		panic(err)
	}
}
Beispiel #4
0
func (tbl *TableCached) AddChildTable(tblc *TableCached, varname string, cp *CacheParams) int {
	fidx := tbl.Table.FieldIndex(varname)
	if fidx == -1 {
		log.Println("Missing Child Table Variable: ", tbl.Table.Name, varname)
		return -1
	}
	fkidx := tblc.Table.FieldIndex(tbl.Table.PrimKey)
	if fkidx == -1 {
		log.Println("Missing Child Table Variable: ", tbl.Table.Name, tbl.Table.PrimKey)
		return -1
	}

	vidx := tbl.Table.FieldIndex(varname + "Version")

	var c *cache.LRUCache
	var capacity uint64
	var maxAge time.Duration
	if cp != nil {
		capacity = cp.Capacity
		maxAge = cp.MaxAge
	}
	if capacity > 0 || maxAge > 0 {
		c = cache.NewLRUCache(&cache.LRUOptions{Capacity: capacity, MaxAge: maxAge})
		allDbCaches = append(allDbCaches, c)
	}

	sliceType := reflect.SliceOf(reflect.PtrTo(tblc.Table.RefType))

	//save ids in array or db-enty-values

	opts := "opts:"
	if vidx != -1 {
		opts += "version"
	} else {
		opts += "unversioned"
	}
	if c != nil {
		opts += ",cache"
	} else {
		opts += ",uncached"
	}
	ids := false
	varSliceType := tbl.Table.RefType.Field(fidx).Type.Elem()
	ids = (varSliceType.String()[0] != '*')
	if ids {
		sliceType = tbl.Table.RefType.Field(fidx).Type
		opts += ",ids"
	}

	log.Println("AddChildTable: ", tbl.Table.Name, "->", tblc.Table.Name, opts)

	if tbl.Children == nil {
		tbl.Children = make([]*ChildTable, 0)
	}
	ct := &ChildTable{tblc, varname, fidx, fkidx, vidx, ids, sliceType, c}
	tbl.Children = append(tbl.Children, ct)
	return len(tbl.Children) - 1
}
Beispiel #5
0
func NewTableCached(tbl *Table, cp *CacheParams) *TableCached {
	var c *cache.LRUCache
	var capacity uint64
	var maxAge time.Duration
	if cp != nil {
		capacity = cp.Capacity
		maxAge = cp.MaxAge
	}
	if capacity > 0 || maxAge > 0 {
		c = cache.NewLRUCache(&cache.LRUOptions{Capacity: capacity, MaxAge: maxAge})
		allDbCaches = append(allDbCaches, c)
	}

	tbc := &TableCached{
		Table:          tbl,
		Cache:          c,
		_idxid:         tbl.FieldIndex(tbl.PrimKey),
		_idxversion:    tbl.FieldIndex("version"),
		_idxtimecreate: tbl.FieldIndex("timecreate"),
		_idxtimeaccess: tbl.FieldIndex("timeaccess"),
		_idxtimeonline: tbl.FieldIndex("timeonline"),
		_idxtimemodify: tbl.FieldIndex("timemodify"),
		_idxdbcache:    tbl.FieldIndex("dbcache"),
	}

	if tbc._idxid == -1 {
		log.Println("Missing Primary Key:", tbl.PrimKey, "in Table", tbl.Name)
		return nil
	}

	opts := "opts:"
	if tbc._idxversion != -1 {
		opts += "version"
	} else {
		opts += "unversioned"
	}
	if c != nil {
		opts += ",cache"
	} else {
		opts += ",uncached"
	}

	log.Println("NewTableCached: ", tbl.Name, opts)

	return tbc
}
Beispiel #6
0
func InitPOIs() {

	mt, _ := db.Main.InitTable(MapTile{})
	tblMapTile = db.NewTableCached(mt, &db.CacheParams{1024, time.Minute * 30})

	pt, _ := db.Main.InitTable(POI{})
	tblPOI = db.NewTableCached(pt, &db.CacheParams{})

	tblMapTile.AddChildTable(tblPOI, "Pois", &db.CacheParams{1024, time.Minute * 30})

	poi_max_respawn = 0
	poi_infoName = make(map[string]*POI_Info)
	poi_infoType = make(map[string]*POI_Info)
	poi_infos = make([]*POI_Info, 1)

	pois, _ := techTree.Get("POIs").Map()
	for key, value := range pois {
		poi := value.(map[string]interface{})
		poiInfo := &POI_Info{}
		poiInfo.Types = strings.Split(poi["Types"].(string), ",")
		poiInfo.Name = key
		poiInfo.Resource = poi["Resource"].(string)
		poiInfo.Level = int(poi["Level"].(float64))
		poiInfo.Respawn = int(poi["Respawn"].(float64))
		if poiInfo.Respawn > poi_max_respawn {
			poi_max_respawn = poiInfo.Respawn
		}
		poi_infos = append(poi_infos, poiInfo)
		for _, typ := range poiInfo.Types {
			poi_infoType[typ] = poiInfo
		}
		poi_infoName[poiInfo.Name] = poiInfo
		//log.Println(poiInfo)
	}
	poi_infos[0] = &POI_Info{} //dummy/none

	poiFarmCache = cache.NewLRUCache(&cache.LRUOptions{MaxAge: time.Minute * time.Duration(poi_max_respawn), NoMoveGet: true})

	MapTileScanner()

	ttpoi := techTree.Get("POI")
	POIScanVer, _ = ttpoi.Get("ScanVer").Int64()
	FarmItemsMin, _ = ttpoi.Get("FarmItemsMin").Int()
	FarmItemsMax, _ = ttpoi.Get("FarmItemsMax").Int()
	FarmLevelMax, _ = ttpoi.Get("FarmLevelMax").Int()
}