This commit is contained in:
Settel 2021-08-01 15:56:53 +02:00
parent dd76910326
commit 8231bda18b
5 changed files with 58 additions and 12 deletions

View File

@ -6,6 +6,8 @@ import (
"sirlab.de/go/knyt/app"
"sirlab.de/go/knyt/engine"
"sirlab.de/go/knyt/handler"
"sirlab.de/go/knyt/user"
"sirlab.de/go/knyt/users"
)
func main() {
@ -15,6 +17,12 @@ func main() {
App.Eng = engine.NewEngine()
http.Handle("/", App.Mux)
usrs := users.NewUsers()
u1 := user.NewUser("123", "Volkmar", user.ROLE_PLAYER)
u2 := user.NewUser("123", "Annabell", user.ROLE_GAMEMASTER)
usrs.AddUser(u1)
usrs.AddUser(u2)
App.Mux.PublicHandleFunc("/__intern__/exit", handler.Exit)
// default handler

13
server/src/user/struct.go Normal file
View File

@ -0,0 +1,13 @@
package user
const (
ROLE_ADMIN = "admin"
ROLE_GAMEMASTER = "gamemaster"
ROLE_PLAYER = "player"
)
type User struct {
Id string `json:"id"`
Name string `json:"name"`
Role string `json:"role"`
}

21
server/src/user/user.go Normal file
View File

@ -0,0 +1,21 @@
package user
func NewUser(id, name, role string) *User {
return &User{
Id: id,
Name: name,
Role: role,
}
}
func (user *User) IsPlayer() bool {
return true
}
func (user *User) IsGamemaster() bool {
return user.Role == ROLE_GAMEMASTER || user.Role == ROLE_ADMIN
}
func (user *User) IsAdmin() bool {
return user.Role == ROLE_ADMIN
}

View File

@ -1,7 +0,0 @@
package users
type User struct {
Id string `json:"id"`
Name string `json:"name"`
Role string `json:"role"`
}

View File

@ -1,8 +1,19 @@
package users
func NewUser(id, name string) *User {
return &User{
id: id,
name: name,
import (
"sirlab.de/go/knyt/user"
)
type Users map[string]*user.User
func NewUsers() Users {
return make(Users)
}
func (users Users) AddUser(usr *user.User) {
users[usr.Id] = usr
}
func (users Users) GetUserById(id string) *user.User {
return users[id]
}