Skip to content

Commit 83d0ea2

Browse files
committed
add cleandb
1 parent 5939b45 commit 83d0ea2

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

fact/playerDB.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func PlayerLevelGet(pname string, modifyOnly bool) int {
361361
}
362362

363363
/* Load database */
364-
func LoadPlayers(bootMode bool) {
364+
func LoadPlayers(bootMode, minimize bool) {
365365
glob.PlayerListWriteLock.Lock()
366366
defer glob.PlayerListWriteLock.Unlock()
367367

@@ -388,6 +388,14 @@ func LoadPlayers(bootMode bool) {
388388
//Add name back in, makes db file smaller
389389
glob.PlayerListLock.Lock()
390390
for pname := range tempData {
391+
if minimize {
392+
if tempData[pname].Level == 0 {
393+
continue
394+
}
395+
if tempData[pname].Level == 1 {
396+
continue
397+
}
398+
}
391399
if banCount > 5 {
392400
doBan = false
393401
}

main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ func main() {
3131
glob.DoDeregisterCommands = flag.Bool("deregCommands", false, "Deregister discord commands")
3232
glob.LocalTestMode = flag.Bool("localTest", false, "Turn off public/auth mode for testing")
3333
glob.NoAutoLaunch = flag.Bool("noAutoLaunch", false, "Turn off auto-launch")
34+
cleanDB := flag.Bool("cleanDB", false, "Clean/minimize player database and exit.")
35+
36+
if *cleanDB {
37+
fact.LoadPlayers(true, true)
38+
fact.WritePlayers()
39+
return
40+
}
3441

3542
debug.SetMemoryLimit(1024 * 1024 * 250) //250mb
3643
//debug.SetMaxThreads(1000)
@@ -144,8 +151,7 @@ func main() {
144151
fact.SetupSchedule()
145152

146153
/* Read in player list */
147-
/* Skip banned and level 0 (new) players on first load */
148-
fact.LoadPlayers(true)
154+
fact.LoadPlayers(true, false)
149155

150156
/* Read in cached discord role data */
151157
disc.ReadRoleList()

support/mainLoops.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func MainLoops() {
279279
updated = false
280280

281281
//cwlog.DoLogCW("Database file modified, loading.")
282-
fact.LoadPlayers(false)
282+
fact.LoadPlayers(false, false)
283283

284284
/* Sleep after reading */
285285
time.Sleep(5 * time.Second)

0 commit comments

Comments
 (0)