add auxmsg publish

This commit is contained in:
Iris Lightshard 2023-05-07 22:24:40 -06:00
parent 1fd828f6fd
commit 42bb254d84
Signed by: nilix
GPG key ID: 3B7FBC22144E6398
3 changed files with 19 additions and 6 deletions

View file

@ -221,7 +221,7 @@ func (self *GameTableServer) writeToDB(tableMsg models.TableMessage) error {
} }
} }
// map image change and token addition/removal require admin authorization // map image change, aux message, and token addition/removal require admin authorization
if tableMsg.Auth != nil { if tableMsg.Auth != nil {
authorized, _ := self.udb.ValidateToken(*tableMsg.Auth) authorized, _ := self.udb.ValidateToken(*tableMsg.Auth)
if authorized { if authorized {
@ -231,6 +231,12 @@ func (self *GameTableServer) writeToDB(tableMsg models.TableMessage) error {
return err return err
} }
} }
if tableMsg.AuxMsg != nil {
err := self.dbAdapter.SetAuxMessage(key, *tableMsg.AuxMsg)
if err != nil {
return err
}
}
} }
} }
return nil return nil

View file

@ -17,12 +17,13 @@ type DiceRoll struct {
Timestamp time.Time `json:"timestamp"` Timestamp time.Time `json:"timestamp"`
} }
type Token struct { type Token struct {
Id string `json:"id"` Id string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
SpriteUri string `json:"spriteUrl"` SpriteUri string `json:"spriteUrl"`
X int `json:"x"` X *int `json:"x"`
Y int `json:"y"` Y *int `json:"y"`
} }
type Table struct { type Table struct {

View file

@ -23,9 +23,8 @@ async function getTable(name, pass) {
document.getElementById("input_table_name").value = name; document.getElementById("input_table_name").value = name;
document.getElementById("input_table_pass").value = pass; document.getElementById("input_table_pass").value = pass;
dial(); dial();
infoHtml = "<a href='#' onclick='getTables()'>&larr; table list</a><br><pre>"; infoHtml = "<a href='#' onclick='getTables()'>&larr; table list</a><br>";
infoHtml += await res.text(); infoHtml += `<textarea id='auxMsgZone'>${(await res.json()).auxMsg}</textarea><br><button onclick='publishAuxMsg()'>Change</button>`
infoHtml += "</pre>"
infoHtml += "<button onclick='destroyTable()'>Destroy</button>" infoHtml += "<button onclick='destroyTable()'>Destroy</button>"
infoHtml += "<input id='map_img_upload' type='file'>Map Image</input><button onclick='uploadMapImg()'>Upload</button>" infoHtml += "<input id='map_img_upload' type='file'>Map Image</input><button onclick='uploadMapImg()'>Upload</button>"
if (mapImgs.ok) { if (mapImgs.ok) {
@ -48,6 +47,13 @@ async function getTable(name, pass) {
} }
} }
function publishAuxMsg() {
const txtArea = document.getElementById("auxMsgZone");
if (txtArea != null) {
publish({auxMsg: txtArea.value, auth: adminToken.access_token});
}
}
function sendMapImg(url) { function sendMapImg(url) {
publish({mapImg: url, auth: adminToken.access_token}); publish({mapImg: url, auth: adminToken.access_token});
} }