correção de xss e mais uma porrada coisas '-'
This commit is contained in:
Binary file not shown.
@@ -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 (
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user