knowyt/server/src/application/application.go

29 lines
583 B
Go
Raw Normal View History

2021-08-01 17:06:33 +00:00
package application
import (
2021-08-01 18:05:00 +00:00
"sirlab.de/go/knyt/applicationConfig"
2021-08-04 22:12:28 +00:00
"sirlab.de/go/knyt/game"
"sirlab.de/go/knyt/user"
2021-08-09 09:16:30 +00:00
"time"
2021-08-01 17:06:33 +00:00
)
2021-08-01 18:32:40 +00:00
func NewApplication(config applicationConfig.ApplicationConfig) (*Application, error) {
2021-08-01 17:06:33 +00:00
app := Application{
2021-08-09 09:16:30 +00:00
config: config,
users: make(map[string]*user.User),
games: make(map[string]*game.Game),
playerATime: make(map[string]time.Time),
2021-08-01 17:06:33 +00:00
}
2021-08-04 22:12:28 +00:00
if err := app.loadUsers(); err != nil {
return nil, err
}
if err := app.loadGames(); err != nil {
2021-08-01 18:32:40 +00:00
return nil, err
}
2021-08-01 17:06:33 +00:00
2021-08-09 12:48:44 +00:00
go app.expireInactivePlayersThread()
2021-08-01 18:32:40 +00:00
return &app, nil
2021-08-01 17:06:33 +00:00
}