correção de xss e mais uma porrada coisas '-'

This commit is contained in:
2025-06-22 05:24:22 -03:00
parent 5c9de60169
commit fd452dd177
10 changed files with 302 additions and 67 deletions

Binary file not shown.

View File

@@ -11,29 +11,45 @@ type Table struct {
Name string
}
type plyInv struct {
ID int `json:"id"`
ItemName string `json:"itemname"`
ItemQuantidade int `json:"itemquantidade"`
ItemPeso int `json:"itempeso"`
}
type plyPwr struct {
ID int `json:"id"`
Name string `json:"name"`
Desc string `json:"desc"`
}
type logEntry struct {
ID int `json:"id"`
Log string `json:"log"`
}
type resp_json struct {
Status string `json:"Status"`
Message string `json:"Message,omitempty"`
Logs []logEntry `json:"Logs,omitempty"`
Foto string `json:"Foto,omitempty"`
PlayerName string `json:"PlayerName,omitempty"`
Conhecimento *int64 `json:"Conhecimento,omitempty"`
Level *int64 `json:"Level,omitempty"`
Idade *int64 `json:"Idade,omitempty"`
Altura *float64 `json:"Altura,omitempty"`
Vida string `json:"Vida,omitempty"`
Destresa *int64 `json:"Destresa,omitempty"`
Inteligencia *int64 `json:"Inteligencia,omitempty"`
Força *int64 `json:"Força,omitempty"`
Constituição *int64 `json:"Constituição,omitempty"`
Cárisma *int64 `json:"Cárisma,omitempty"`
Inventario *int64 `json:"Inventario,omitempty"`
Descrição string `json:"Descrição,omitempty"`
Status string `json:"Status"`
Message string `json:"Message,omitempty"`
Logs []logEntry `json:"Logs,omitempty"`
InvPeso int `json:"invPeso,omitempty"`
InvItems []plyInv `json:"InvItems,omitempty"`
InvPws []plyPwr `json:"InvPws,omitempty"`
Foto string `json:"Foto,omitempty"`
PlayerName string `json:"PlayerName,omitempty"`
Conhecimento *int64 `json:"Conhecimento,omitempty"`
Level *int64 `json:"Level,omitempty"`
Idade *int64 `json:"Idade,omitempty"`
Altura *float64 `json:"Altura,omitempty"`
Vida string `json:"Vida,omitempty"`
VidaPorcentagem *float64 `json:"VidaPorcentagem,omitempty"`
Destresa *int64 `json:"Destresa,omitempty"`
Inteligencia *int64 `json:"Inteligencia,omitempty"`
Força *int64 `json:"Força,omitempty"`
Constituição *int64 `json:"Constituição,omitempty"`
Cárisma *int64 `json:"Cárisma,omitempty"`
Inventario *int64 `json:"Inventario,omitempty"`
Descrição string `json:"Descrição,omitempty"`
}
var (

View File

@@ -98,6 +98,7 @@ func main() {
e.POST("login", login, timeoutMiddleware, rateLimit)
e.GET("login", badreq)
e.GET("player", player_data)
e.GET("player/inv", inv_get)
e.POST("player/update", player_updateInputs)
e.PATCH("player/:atb/:updown", player_update)

View File

@@ -150,7 +150,7 @@ func registrar(c echo.Context) error {
}
log.Printf("tabela invPower_%s foi criada.\n", player)
query = fmt.Sprintf(`CREATE TABLE inv_%s (id INT NOT NULL , item_nome VARCHAR(30) NOT NULL , quantidade INT NOT NULL DEFAULT '1' , item_peso INT NOT NULL DEFAULT '1' , item_durabilit BOOLEAN NOT NULL DEFAULT FALSE ) ENGINE = InnoDB;`, player)
query = fmt.Sprintf(`CREATE TABLE inv_%s (id INT NOT NULL AUTO_INCREMENT, item_nome VARCHAR(30) NOT NULL , quantidade INT NOT NULL DEFAULT '1' , item_peso INT NOT NULL DEFAULT '1' , item_durabilit BOOLEAN NOT NULL DEFAULT FALSE ) ENGINE = InnoDB;`, player)
newInv, err := db.Query(query)
if err != nil {
return c.JSON(http.StatusInternalServerError, resp_json{
@@ -322,22 +322,24 @@ func player_data(c echo.Context) error {
err = db.QueryRow("SELECT foto, nome, conhecimento, level, idade, altura, vida, vida_maxima, destresa, inteligencia, força, constituição, cárisma, inventario, descrição FROM players WHERE id=? LIMIT 1;", userSession["user_id"]).Scan(&foto, &playername, &conhecimento, &level, &idade, &altura, &vd, &vdm, &destresa, &inteligencia, &força, &constituição, &cárisma, &inventario, &descrição)
if err == nil {
vida = fmt.Sprintf("%v/%v", vd, vdm)
porcentagem := (float64(vd) / float64(vdm)) * 100
return c.JSON(http.StatusOK, resp_json{
Status: "Success",
Foto: foto,
PlayerName: playername,
Conhecimento: &conhecimento,
Level: &level,
Idade: &idade,
Altura: &altura,
Vida: vida,
Destresa: &destresa,
Inteligencia: &inteligencia,
Força: &força,
Constituição: &constituição,
Cárisma: &cárisma,
Inventario: &inventario,
Descrição: descrição,
Status: "Success",
Foto: foto,
PlayerName: playername,
Conhecimento: &conhecimento,
Level: &level,
Idade: &idade,
Altura: &altura,
Vida: vida,
VidaPorcentagem: &porcentagem,
Destresa: &destresa,
Inteligencia: &inteligencia,
Força: &força,
Constituição: &constituição,
Cárisma: &cárisma,
Inventario: &inventario,
Descrição: descrição,
})
}
return c.JSON(http.StatusBadRequest, resp_json{
@@ -419,6 +421,7 @@ func player_updateInputs(c echo.Context) error {
nome := c.FormValue("nome")
altura := c.FormValue("altura")
inv := c.FormValue("inventario")
lore := c.FormValue("lore")
if vida != "" {
_, err = db.Exec("UPDATE players SET vida=?, vida_maxima=? WHERE id=?;", vida, vida, userSession["user_id"])
@@ -468,6 +471,18 @@ func player_updateInputs(c echo.Context) error {
lista = append(lista, "inventario")
}
if lore != "" {
_, err = db.Exec("UPDATE players SET descrição=? WHERE id=?;", lore, userSession["user_id"])
if err != nil {
log.Println(err)
return c.JSON(http.StatusInternalServerError, resp_json{
Status: "Error",
Message: "algo deu errado ao alterar a sua historia.",
})
}
lista = append(lista, "lore")
}
if len(lista) <= 0 {
return c.JSON(http.StatusUnauthorized, resp_json{
Status: "Error",
@@ -479,3 +494,56 @@ func player_updateInputs(c echo.Context) error {
Message: fmt.Sprintf("você mudou as seguintes informaçôes: %s", lista),
})
}
func inv_get(c echo.Context) error {
userSession, err := ValidSession(c)
if err != nil {
return c.JSON(http.StatusUnauthorized, resp_json{
Status: "Error",
Message: err.Error(),
})
}
row, err := db.Query(fmt.Sprintf("SELECT id, item_nome, quantidade, item_peso FROM inv_%s ORDER BY id DESC;", userSession["playerName"]))
if err != nil {
log.Println(err)
log.Println("Erro ao consultar inventario do inventario.")
return c.JSON(http.StatusInternalServerError, resp_json{
Status: "Error",
Message: "Erro ao consultar inventario do inventario.",
})
}
var peso_total int = 0
var lista []plyInv
for row.Next() {
var id int
var nome string
var quantidade int
var peso int
if err := row.Scan(&id, &nome, &quantidade, &peso); err != nil {
return c.JSON(http.StatusInternalServerError, resp_json{
Status: "Error",
Message: "algo deu errado ao inventario",
})
}
lista = append(lista, plyInv{ID: id, ItemName: nome, ItemQuantidade: quantidade, ItemPeso: peso})
peso_total = peso_total + peso
}
sort.Slice(lista, func(i, j int) bool {
return lista[i].ID < lista[j].ID
})
if len(lista) <= 0 {
return c.JSON(http.StatusNotFound, resp_json{
Status: "NoDB",
Message: "o Inventario ainda esta vazio",
})
}
return c.JSON(http.StatusOK, resp_json{
Status: "Success",
InvPeso: peso_total,
InvItems: lista,
})
}

View File

@@ -31,3 +31,16 @@ body {
}
}
}
@media only screen and (max-width: 1080px) {
#login_form {
width: 80%;
ul {
padding-top: 0;
justify-content: center;
li {
margin-top: 3vw;
}
}
}
}

View File

@@ -40,3 +40,16 @@ body {
}
}
}
@media only screen and (max-width: 1080px) {
#register_form {
width: 80%;
ul {
padding-top: 0;
justify-content: center;
li {
margin-top: 3vw;
}
}
}
}

View File

@@ -351,7 +351,12 @@
#text_lore {
ul {
position: relative;
#btn {
width: 100%;
min-height: 20dvw;
display: flex;
align-items: center;
flex-direction: column;
a {
position: absolute;
top: 1dvh;
right: 1dvh;
@@ -369,6 +374,35 @@
font-size: 1.5em;
padding: 1vw;
white-space: pre-wrap;
width: 100%;
min-height: 45dvw;
}
textarea {
width: 100%;
min-height: 45dvw;
resize: none;
border: none;
background-color: transparent;
font-family: arial;
font-size: 1.5em;
padding: 1vw;
white-space: pre-wrap;
color: #ffffff;
}
.lore_edit {
border: none;
margin: 1dvw 0 1dvw 0;
padding: 0.5dvh;
width: 99%;
background-color: var(--btncolor);
font-family: Arial, Helvetica, sans-serif;
font-size: 2em;
border-radius: 1dvw;
cursor: pointer;
transition: 0.3s;
}
.lore_edit:hover {
background-color: var(--lines);
}
}
}
@@ -435,4 +469,15 @@
width: 30%;
transform: translateY(50px) translateX(-50px);
}
#box_2 {
#text_lore {
a {
height: 200dvw;
}
textarea {
height: 200dvw;
}
}
}
}

View File

@@ -333,17 +333,7 @@
</div>
<div id="inv">
<h1>Inventario</h1>
<ul>
<li>
<label>item_name</label>
<label>quantidade</label>
<a id="DelBTN">
<span class="material-symbols-outlined">
close
</span>
</a>
</li>
</ul>
<ul></ul>
<hgroup>
<input type="text" placeholder="item name" />
<select name="durabilite">
@@ -355,7 +345,7 @@
<input type="number" placeholder="quantidade" max="100" />
<a id="btn">add</a>
<label>
<p>0</p>
<p id="invPA">0</p>
/
<p id="mip">0</p>
<a id="btn" class="editbtn inventario">
@@ -377,12 +367,20 @@
<h1>Texto do Player</h1>
<div id="text_lore">
<ul>
<a id="btn">
<a id="btn" class="lore">
<span class="material-symbols-outlined btn-right">
edit
</span>
</a>
<p id="lore"></p>
<textarea id="lore_edit" style="display: none"></textarea>
<input
type="submit"
id="btn"
class="lore_edit"
style="display: none"
value="atualizar"
/>
</ul>
</div>
</div>

View File

@@ -1,18 +1,25 @@
let img;
let update;
let invUpdate;
function delitem(id) {
alert(id);
}
function useItem(id) {
alert(id);
}
function load_ficha() {
$.ajax({
url: window.api + "player",
type: "GET",
xhrFields: {
withCredentials: true,
},
xhrFields: { withCredentials: true },
success: function (resp) {
if (img === undefined) {
img = resp.Foto;
$("#hero").attr("src", `data:image/*;base64,${resp.Foto}`);
}
$("#vdp").text(resp.Vida);
$("#nmp").text(resp.PlayerName);
$("#lvp").text(resp.Level);
@@ -26,8 +33,13 @@ function load_ficha() {
$("#cárisma").text(resp.Cárisma);
$("#mip").text(resp.Inventario);
$("#lore").text(resp.Descrição);
if ($("#lore_edit").attr("placeholder") !== resp.Descrição) {
$("#lore_edit").attr("placeholder", resp.Descrição);
$("#lore_edit").val(resp.Descrição);
}
},
error: function (resp, status, jqXHR) {
error: function () {
window.location.href = "login.html";
},
});
@@ -37,21 +49,25 @@ function roll_load() {
$.ajax({
url: window.api + "roll",
type: "GET",
xhrFields: {
withCredentials: true,
},
xhrFields: { withCredentials: true },
success: function (resp) {
switch (update) {
case undefined:
resp.Logs.forEach(function (item) {
$("#log").append(`<li> <label>${item.log}</label></li>`);
const $li = $("<li>");
const $label = $("<label>").text(item.log);
$li.append($label);
$("#log").append($li);
update = item.id;
});
break;
default:
resp.Logs.forEach(function (item) {
if (item.id > update) {
$("#log").append(`<li> <label>${item.log}</label></li>`);
const $li = $("<li>");
const $label = $("<label>").text(item.log);
$li.append($label);
$("#log").append($li);
update = item.id;
}
});
@@ -59,12 +75,6 @@ function roll_load() {
}
$("#log").scrollTop($("#log")[0].scrollHeight);
},
error: function (resp, status, jqXHR) {
/*msg(
resp.responseJSON?.Status || "Erro",
resp.responseJSON?.Message || "Algo deu errado.",
);*/
},
});
}
@@ -73,7 +83,6 @@ function roll(d) {
url: window.api + "roll",
type: "POST",
data: { roll: d },
xhrFields: { withCredentials: true },
success: function (resp) {
msg(resp.Status, resp.Message);
@@ -81,7 +90,49 @@ function roll(d) {
});
}
function invPlayer() {
$.ajax({
url: window.api + "player/inv",
type: "GET",
xhrFields: { withCredentials: true },
success: function (resp) {
const buildItem = function (item) {
const $li = $("<li>");
$li.append($("<label>").text(item.itemname));
$li.append($("<label>").text(`tem: ${item.itemquantidade}`));
$li.append($("<label>").text(`peso: ${item.itempeso}`));
const $delBtn = $("<a>")
.attr("id", "DelBTN")
.append(
$("<span>").addClass("material-symbols-outlined").text("close"),
);
$li.on("click", () => useItem(item.id));
$delBtn.on("click", (e) => {
e.stopPropagation();
delitem(item.id);
});
$li.append($delBtn);
return $li;
};
if (invUpdate === undefined || resp.invPeso !== invUpdate) {
$("#inv ul").empty();
resp.InvItems.forEach((item) => {
$("#inv ul").append(buildItem(item));
});
invUpdate = resp.invPeso;
}
$("#invPA").text(resp.invPeso);
},
});
}
load_ficha();
$(document).ready(function () {
$(".updown").click(function () {
const atb = $(this).data("atb");
@@ -90,10 +141,8 @@ $(document).ready(function () {
$.ajax({
url: `${window.api}player/${atb}/${updown}`,
type: "PATCH",
xhrFields: {
withCredentials: true,
},
error: function (resp, status, jqXHR) {
xhrFields: { withCredentials: true },
error: function (resp) {
msg(
resp.responseJSON?.Status || "Erro",
resp.responseJSON?.Message || "Algo deu errado.",
@@ -105,5 +154,6 @@ $(document).ready(function () {
setInterval(function () {
load_ficha();
roll_load();
invPlayer();
}, 500);
});

View File

@@ -1,5 +1,6 @@
var $inp;
let lore = false;
let cordX = 0;
let cordY = 0;
@@ -78,4 +79,34 @@ $(document).ready(function () {
? editInput(reqbtn[1], cordX, cordY)
: msg("Error", "erro, ainda não foi definido a classe desse botão");
});
$(".lore").on("click", function (e) {
switch (lore) {
case false:
$(".lore span").text("close");
$("#lore").hide();
$("#lore_edit").show();
$(".lore_edit").css("display", "block");
lore = true;
break;
case true:
$(".lore span").text("edit");
$("#lore").show();
$("#lore_edit").hide();
$(".lore_edit").css("display", "none");
lore = false;
break;
}
});
$(".lore_edit").on("click", function (e) {
data_update("lore", $("#lore_edit").val()).then((result) => {
if (result) {
$(".lore span").text("edit");
$("#lore").show();
$("#lore_edit").hide();
$(".lore_edit").css("display", "none");
lore = false;
}
});
});
});