correção do bug do inventario '-'

This commit is contained in:
2025-06-22 06:47:39 -03:00
parent fd452dd177
commit 3d9832648d
2 changed files with 30 additions and 0 deletions

Binary file not shown.

View File

@@ -460,6 +460,36 @@ func player_updateInputs(c echo.Context) error {
}
if inv != "" {
row, err := db.Query(fmt.Sprintf("SELECT id, 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
for row.Next() {
var id int
var peso int
if err := row.Scan(&id, &peso); err != nil {
return c.JSON(http.StatusInternalServerError, resp_json{
Status: "Error",
Message: "algo deu errado ao inventario",
})
}
peso_total = peso_total + peso
}
valorInv, _ := strconv.Atoi(inv)
if peso_total > valorInv {
return c.JSON(http.StatusUnauthorized, resp_json{
Status: "Error",
Message: "você não pode ter um inventario com menos capacidade do que esta carregando.",
})
}
_, err = db.Exec("UPDATE players SET inventario=? WHERE id=?;", inv, userSession["user_id"])
if err != nil {
log.Println(err)