add new role "setup" if game is not initialized yet
This commit is contained in:
parent
ea7caa322b
commit
37198001a3
@ -1 +0,0 @@
|
||||
{"name":"Massive Demo","lang":"de","created":1651603106}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "12.2",
|
||||
"source": "9c5a22d3-1e82-4bad-95a4-c9efb169ede0"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "1.1",
|
||||
"source": "4b1c22b8-6fa1-4c9d-98d7-cbf498035074"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "11.2",
|
||||
"source": "cede08c4-768a-4792-b92f-8df162a07307"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "4.1",
|
||||
"source": "b190ebb1-86c0-4308-a6b6-bf34237c10f8"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "Admin #1",
|
||||
"source": "f30802dc-1c18-4169-99fe-04d1d8e7bd9e"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "7.2",
|
||||
"source": "3945635e-c65a-4fb7-a46c-675ec53abebe"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "16.1",
|
||||
"source": "49295e5b-0d0a-44ea-9bff-e74acaaa6dcf"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "3.2",
|
||||
"source": "4fa78612-accd-491d-93e6-cca251ac0e5a"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "5.1",
|
||||
"source": "3c60f533-676b-4464-8542-1f3e6fc49d13"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "Admin #2",
|
||||
"source": "f30802dc-1c18-4169-99fe-04d1d8e7bd9e"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "2.2",
|
||||
"source": "da6fdb50-8773-40ce-889f-c6f565ca35e3"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "6.1",
|
||||
"source": "38f508e0-b808-4d28-be5b-d2f5cb54fd69"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "4.2",
|
||||
"source": "b190ebb1-86c0-4308-a6b6-bf34237c10f8"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "13.1",
|
||||
"source": "233dd18b-cb0d-4f77-b0ee-248dc7fec65d"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "9.2",
|
||||
"source": "f99ee1de-af5c-4d7e-a1f4-622ad0cd40ac"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "12.1",
|
||||
"source": "9c5a22d3-1e82-4bad-95a4-c9efb169ede0"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "5.2",
|
||||
"source": "3c60f533-676b-4464-8542-1f3e6fc49d13"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "9.1",
|
||||
"source": "f99ee1de-af5c-4d7e-a1f4-622ad0cd40ac"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "8.2",
|
||||
"source": "81cf1907-8566-4b03-a433-3f6ea9bf8c85"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "15.1",
|
||||
"source": "4706f51a-c014-4e0a-99f7-866e98b19986"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "1.2",
|
||||
"source": "4b1c22b8-6fa1-4c9d-98d7-cbf498035074"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "11.1",
|
||||
"source": "cede08c4-768a-4792-b92f-8df162a07307"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "10.2",
|
||||
"source": "8f688b3b-6e2f-4bf2-bdfa-03762f2c7b72"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "6.2",
|
||||
"source": "38f508e0-b808-4d28-be5b-d2f5cb54fd69"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "13.2",
|
||||
"source": "233dd18b-cb0d-4f77-b0ee-248dc7fec65d"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "8.1",
|
||||
"source": "81cf1907-8566-4b03-a433-3f6ea9bf8c85"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "10.1",
|
||||
"source": "8f688b3b-6e2f-4bf2-bdfa-03762f2c7b72"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "16.2",
|
||||
"source": "49295e5b-0d0a-44ea-9bff-e74acaaa6dcf"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "14.2",
|
||||
"source": "51c4c7cb-8382-4bef-ad2d-c457c5af12f2"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "2.1",
|
||||
"source": "da6fdb50-8773-40ce-889f-c6f565ca35e3"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "14.1",
|
||||
"source": "51c4c7cb-8382-4bef-ad2d-c457c5af12f2"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "3.1",
|
||||
"source": "4fa78612-accd-491d-93e6-cca251ac0e5a"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "7.1",
|
||||
"source": "3945635e-c65a-4fb7-a46c-675ec53abebe"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "15.2",
|
||||
"source": "4706f51a-c014-4e0a-99f7-866e98b19986"
|
||||
}
|
@ -1 +0,0 @@
|
||||
{"name":"Bumsquatsch","lang":"de","created":1670881903}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"quote": "Extra Bumsquatsch vom Oberadmin",
|
||||
"source": "6ef8620b-2b5e-4749-821e-b0722b8d8117",
|
||||
"created": 1670882004
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"quote": "Bumsquatsch #2",
|
||||
"source": "c5e0cbf4-1556-4488-93de-9367f84e5ce8",
|
||||
"created": 1670881947
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"quote": "Bumsquatsch #1",
|
||||
"source": "c5e0cbf4-1556-4488-93de-9367f84e5ce8",
|
||||
"created": 1670881943
|
||||
}
|
@ -1 +0,0 @@
|
||||
{"name":"Team Hogwards","lang":"en","created":1650831066}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "I'm friends with spiders.",
|
||||
"source": "23c93faa-ac5b-4e37-bf32-4276aba682bb"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "My first magic wand - an exclusive model from designer Thoronus Karpes — was a gift from my father.",
|
||||
"source": "15c03b7c-729f-4202-a880-3bcc7214dad9"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "My stupid brothers frequently test their latest invention on me.",
|
||||
"source": "bff68447-513c-4fa3-9224-fc59d83da81a"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "Since first grade, I've been best in all subjects and courses without a single miss.",
|
||||
"source": "99e1aa2e-6e37-43c7-809c-28f093e2ae81"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "My private collection has 4031 different potions.",
|
||||
"source": "35ee06ca-82c7-4f23-9bb9-bd0943848b07"
|
||||
}
|
@ -1 +0,0 @@
|
||||
{"name":"Team Hogwards","lang":"de","created":1649841591}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "Ich bin seit der ersten Klasse in allen Fächern Klassenbeste:r.",
|
||||
"source": "de69fa89-2b55-4c78-8718-9084458ceada"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "Meine Privatsammlung umfasst 4031 verschiedene Zaubertränke.",
|
||||
"source": "c885c77f-bbc8-4547-a3b4-baac5a58e76e"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "Meinen ersten Zauberstab — ein exklusives Modell von Edeldesigner Thoronus Karpes — hat mir mein Vater geschenkt.",
|
||||
"source": "cf230e60-9e1e-4158-93eb-ca184e15a6af"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "Ich bin mit Spinnen befreundet.",
|
||||
"source": "47ff4d04-b403-468f-b152-72226762e373"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"quote": "Meine blöden Brüder testen ständig ihre neusten Erfindungen an mir.",
|
||||
"source": "fae6e837-d603-436d-ba0c-df6a850350c0"
|
||||
}
|
@ -1 +0,0 @@
|
||||
{"authcode":"","name":"Draco","role":"player","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831166,"lastLoggedIn":0}
|
@ -1 +0,0 @@
|
||||
{"authcode":"805088","name":"Player #13","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603645,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"","name":"Hagrid","role":"player","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831162,"lastLoggedIn":0}
|
@ -1 +0,0 @@
|
||||
{"authcode":"","name":"Snape","role":"player","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831158,"lastLoggedIn":0}
|
@ -1 +0,0 @@
|
||||
{"authcode":"406234","name":"Player #06","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603311,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"098577","name":"Player #07","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603340,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"044843","name":"Player #05","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603278,"lastLoggedIn":1651603989}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"authcode": "646162",
|
||||
"name": "Settel (Admin)",
|
||||
"role": "admin"
|
||||
}
|
@ -1 +0,0 @@
|
||||
{"authcode":"606242","name":"Player #15","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603679,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"","name":"Hagrid","role":"player","game":"e24444aa-8a18-48aa-a36d-8f84620726f8","created":1649841804}
|
@ -1 +0,0 @@
|
||||
{"authcode":"920510","name":"Player #16","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603703,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"350736","name":"Player #01","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603175,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"160658","name":"Player #03","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603237,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"529733","name":"Player #14","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603656,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"171903","name":"Admin von Bumsquatsch","role":"gamemaster","game":"652e36de-99c4-4365-b557-8fd189a396ab","created":1670881903,"lastLoggedIn":1670881992}
|
@ -1 +0,0 @@
|
||||
{"authcode":"776678","name":"Player #08","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603395,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"837254","name":"Player #10","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603471,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"","name":"Hermine","role":"player","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831149,"lastLoggedIn":0}
|
@ -1 +0,0 @@
|
||||
{"authcode":"370173","name":"Player #12","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603619,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"934289","name":"Harry","role":"player","game":"e24444aa-8a18-48aa-a36d-8f84620726f8","created":1649841804}
|
@ -1 +0,0 @@
|
||||
{"authcode":"001002","name":"Dumbledore","role":"gamemaster","game":"e24444aa-8a18-48aa-a36d-8f84620726f8","created":1649841804,"lastLoggedIn":1649841540}
|
@ -1 +0,0 @@
|
||||
{"authcode":"576653","name":"Player #04","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603258,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"","name":"Ron","role":"player","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831153,"lastLoggedIn":0}
|
@ -1 +0,0 @@
|
||||
{"authcode":"000000","name":"Harald von Bumsquatsch","role":"player","game":"652e36de-99c4-4365-b557-8fd189a396ab","created":1670881923,"lastLoggedIn":1670881950}
|
@ -1 +0,0 @@
|
||||
{"authcode":"","name":"Snape","role":"player","game":"e24444aa-8a18-48aa-a36d-8f84620726f8","created":1649841804}
|
@ -1 +0,0 @@
|
||||
{"authcode":"019048","name":"Player #11","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603541,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"","name":"Draco","role":"player","game":"e24444aa-8a18-48aa-a36d-8f84620726f8","created":1649841804}
|
@ -1 +0,0 @@
|
||||
{"authcode":"123456","name":"Harry","role":"player","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831122,"lastLoggedIn":1661949675}
|
@ -1 +0,0 @@
|
||||
{"authcode":"256473","name":"Player #02","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603188,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"","name":"Hermine","role":"player","game":"e24444aa-8a18-48aa-a36d-8f84620726f8","created":1649841804}
|
@ -1 +0,0 @@
|
||||
{"authcode":"002002","name":"Dumbledore","role":"gamemaster","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831066,"lastLoggedIn":1661965111}
|
@ -1 +0,0 @@
|
||||
{"authcode":"631854","name":"Admin","role":"gamemaster","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603106,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"494434","name":"Player #09","role":"player","game":"64efba47-87dc-4c19-851c-aa68c9f0e2c1","created":1651603452,"lastLoggedIn":1651603989}
|
@ -1 +0,0 @@
|
||||
{"authcode":"","name":"Ron","role":"player","game":"e24444aa-8a18-48aa-a36d-8f84620726f8","created":1649841804}
|
@ -1,20 +0,0 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (app *Application) GetServerInfo(w http.ResponseWriter, r *http.Request) {
|
||||
app.mu.Lock()
|
||||
defer app.mu.Unlock()
|
||||
|
||||
serverInfo := ServerInfo{
|
||||
IsInitialized: len(app.users) > 1,
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
jsonString, _ := json.Marshal(serverInfo)
|
||||
fmt.Fprintf(w, "%s", string(jsonString))
|
||||
}
|
8
server/src/application/isInitialized.go
Normal file
8
server/src/application/isInitialized.go
Normal file
@ -0,0 +1,8 @@
|
||||
package application
|
||||
|
||||
func (app *Application) IsInitialized() bool {
|
||||
app.mu.Lock()
|
||||
defer app.mu.Unlock()
|
||||
|
||||
return len(app.users) > 1
|
||||
}
|
25
server/src/handler/checkSetup.go
Normal file
25
server/src/handler/checkSetup.go
Normal file
@ -0,0 +1,25 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"sirlab.de/go/knowyt/user"
|
||||
)
|
||||
|
||||
func (authMux *AuthMux) CheckSetup(w http.ResponseWriter, r *http.Request) {
|
||||
if authMux.app.IsInitialized() {
|
||||
authMux.accessDenied(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
usrSetup := UserInfoJson{
|
||||
Name: "setup",
|
||||
Role: user.ROLE_SETUP,
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
jsonString, _ := json.Marshal(usrSetup)
|
||||
fmt.Fprintf(w, "%s", string(jsonString))
|
||||
}
|
@ -8,18 +8,22 @@ import (
|
||||
"sirlab.de/go/knowyt/user"
|
||||
)
|
||||
|
||||
func (authMux *AuthMux) PrivateHandleFunc(pattern string, handlerFunc PrivateHandlerFunc) {
|
||||
func (authMux *AuthMux) PrivateOrPublicHandleFunc(pattern string, privateHandlerFunc PrivateHandlerFunc, publicHandlerFunc HandlerFunc) {
|
||||
authMux.mux.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
|
||||
usr, err := authMux.getUserFromSession(r)
|
||||
if err != nil {
|
||||
authMux.accessDenied(w, r)
|
||||
return
|
||||
// could not authenticate
|
||||
publicHandlerFunc(w, r)
|
||||
} else {
|
||||
privateHandlerFunc(usr, w, r)
|
||||
}
|
||||
|
||||
handlerFunc(usr, w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func (authMux *AuthMux) PrivateHandleFunc(pattern string, handlerFunc PrivateHandlerFunc) {
|
||||
authMux.PrivateOrPublicHandleFunc(pattern, handlerFunc, authMux.accessDenied)
|
||||
}
|
||||
|
||||
func (authMux *AuthMux) accessDenied(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
fmt.Fprintf(w, "Forbidden")
|
||||
|
@ -22,9 +22,8 @@ func main() {
|
||||
mux.PublicHandleFunc("/api/login", mux.Login)
|
||||
mux.PublicHandleFunc("/api/logout", mux.Logout)
|
||||
mux.PublicHandleFunc("/api/createGame", app.CreateGame)
|
||||
mux.PublicHandleFunc("/api/serverinfo", app.GetServerInfo)
|
||||
mux.PrivateOrPublicHandleFunc("/api/userinfo", mux.GetUserInfo, mux.CheckSetup)
|
||||
mux.PrivateHandleFunc("/api/cameo", mux.Cameo)
|
||||
mux.PrivateHandleFunc("/api/userinfo", mux.GetUserInfo)
|
||||
mux.PrivateHandleFunc("/api/gameinfo", app.GetGameInfo)
|
||||
mux.PrivateHandleFunc("/api/games", app.GetGames)
|
||||
mux.PrivateHandleFunc("/api/setGameName", app.SetGameName)
|
||||
|
@ -8,6 +8,7 @@ const (
|
||||
ROLE_ADMIN = "admin"
|
||||
ROLE_GAMEMASTER = "gamemaster"
|
||||
ROLE_PLAYER = "player"
|
||||
ROLE_SETUP = "setup"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
Loading…
Reference in New Issue
Block a user