users
This commit is contained in:
parent
dd76910326
commit
8231bda18b
@ -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
13
server/src/user/struct.go
Normal 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
21
server/src/user/user.go
Normal 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
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package users
|
||||
|
||||
type User struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Role string `json:"role"`
|
||||
}
|
@ -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]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user