2018-01-29 23:50:25 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2018 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package datacache
|
|
|
|
|
|
|
|
|
|
import (
|
2018-05-02 07:25:39 +04:00
|
|
|
|
"sync"
|
|
|
|
|
|
2018-05-19 12:14:25 +04:00
|
|
|
|
"github.com/fat0troll/i2_bot/lib/appcontext"
|
|
|
|
|
"github.com/fat0troll/i2_bot/lib/datacache/datacacheinterface"
|
|
|
|
|
"github.com/fat0troll/i2_bot/lib/datamapping"
|
|
|
|
|
"github.com/fat0troll/i2_bot/lib/dbmapping"
|
2018-01-29 23:50:25 +04:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
c *appcontext.Context
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// DataCache is a function-handling struct for package datacache.
|
|
|
|
|
// Also, it's a data cache: it handles all data, powered by DataCache functions.
|
|
|
|
|
type DataCache struct {
|
|
|
|
|
// Players — users of bot
|
|
|
|
|
players map[int]*dbmapping.Player
|
|
|
|
|
playersMutex sync.Mutex
|
|
|
|
|
// Profiles - game profiles, no matter, actual or not
|
|
|
|
|
profiles map[int]*dbmapping.Profile
|
|
|
|
|
profilesMutex sync.Mutex
|
|
|
|
|
// Current profiles - actual profiles for players, mostly used by bot
|
|
|
|
|
// Note: int in this array for player ID, not for profile ID
|
|
|
|
|
currentProfiles map[int]*dbmapping.Profile
|
|
|
|
|
currentProfilesMutex sync.Mutex
|
2018-05-05 10:33:40 +04:00
|
|
|
|
// Tournament reports
|
|
|
|
|
tournamentReports map[int]*dbmapping.TournamentReport
|
|
|
|
|
tournamentReportsByTournamentAndPlayer map[int]map[int]*dbmapping.TournamentReport
|
|
|
|
|
tournamentReportsMutex sync.Mutex
|
2018-01-29 23:50:25 +04:00
|
|
|
|
|
2018-02-17 07:03:58 +04:00
|
|
|
|
// Chats
|
|
|
|
|
chats map[int]*dbmapping.Chat
|
|
|
|
|
chatsMutex sync.Mutex
|
|
|
|
|
// Squads
|
|
|
|
|
squads map[int]*dbmapping.Squad
|
|
|
|
|
squadsWithChats map[int]*dbmapping.SquadChat
|
|
|
|
|
squadPlayersRelations map[int]*dbmapping.SquadPlayer
|
|
|
|
|
squadPlayers map[int]map[int]*dbmapping.SquadPlayerFull
|
|
|
|
|
squadsMutex sync.Mutex
|
|
|
|
|
|
2018-05-02 00:47:55 +04:00
|
|
|
|
// Rarely changing data
|
2018-01-29 23:50:25 +04:00
|
|
|
|
// Elements
|
2018-03-31 08:34:27 +04:00
|
|
|
|
elements map[int]*datamapping.Element
|
2018-01-29 23:50:25 +04:00
|
|
|
|
// Leagues
|
2018-03-31 08:34:27 +04:00
|
|
|
|
leagues map[int]*datamapping.League
|
2018-05-02 00:47:55 +04:00
|
|
|
|
// Levels
|
|
|
|
|
levels map[int]*datamapping.Level
|
2018-01-29 23:50:25 +04:00
|
|
|
|
// Locations
|
2018-03-31 08:34:27 +04:00
|
|
|
|
locations map[int]*datamapping.Location
|
2018-05-02 00:47:55 +04:00
|
|
|
|
// Pokememes
|
|
|
|
|
pokememes map[int]*datamapping.Pokememe
|
|
|
|
|
fullPokememes map[int]*datamapping.PokememeFull
|
|
|
|
|
pokememesGradeLocation map[int]map[int]int
|
2018-01-29 23:50:25 +04:00
|
|
|
|
// Weapons
|
2018-03-31 08:34:27 +04:00
|
|
|
|
weapons map[int]*datamapping.Weapon
|
2018-01-29 23:50:25 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// New is an initialization function for appcontext
|
|
|
|
|
func New(ac *appcontext.Context) {
|
|
|
|
|
c = ac
|
|
|
|
|
dc := &DataCache{}
|
|
|
|
|
c.RegisterDataCacheInterface(datacacheinterface.DataCacheInterface(dc))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Init is a initialization function for package
|
|
|
|
|
func (dc *DataCache) Init() {
|
|
|
|
|
c.Log.Info("Initializing DataCache...")
|
|
|
|
|
|
|
|
|
|
dc.initElements()
|
|
|
|
|
dc.loadElements()
|
|
|
|
|
dc.initLeagues()
|
|
|
|
|
dc.loadLeagues()
|
|
|
|
|
dc.initLocations()
|
|
|
|
|
dc.loadLocations()
|
|
|
|
|
dc.initWeapons()
|
|
|
|
|
dc.loadWeapons()
|
2018-05-02 00:47:55 +04:00
|
|
|
|
dc.initLevels()
|
|
|
|
|
dc.loadLevels()
|
2018-01-29 23:50:25 +04:00
|
|
|
|
dc.initPokememes()
|
|
|
|
|
dc.loadPokememes()
|
|
|
|
|
dc.initPlayers()
|
|
|
|
|
dc.loadPlayers()
|
|
|
|
|
dc.initProfiles()
|
|
|
|
|
dc.loadProfiles()
|
2018-05-05 10:33:40 +04:00
|
|
|
|
dc.initTournamentReports()
|
|
|
|
|
dc.loadTournamentReports()
|
2018-02-17 07:03:58 +04:00
|
|
|
|
dc.initChats()
|
|
|
|
|
dc.loadChats()
|
|
|
|
|
dc.initSquads()
|
|
|
|
|
dc.loadSquads()
|
2018-01-29 23:50:25 +04:00
|
|
|
|
}
|