back_end e front_end, motoes de editar, tela de login e os caralho a4 '-'

This commit is contained in:
2025-06-21 00:38:02 -03:00
parent 9a818eee5f
commit e51f7f41dc
12 changed files with 553 additions and 111 deletions

Binary file not shown.

View File

@@ -32,13 +32,30 @@ func sessionCookie(id int, player string) (*http.Cookie, error) {
cookie := &http.Cookie{ cookie := &http.Cookie{
Name: cookieName, Name: cookieName,
Value: sessionID, Value: sessionID,
Path: "/*", Path: "/",
HttpOnly: true, //HttpOnly: true,
//Secure: true,
//SameSite: http.SameSiteNoneMode,
Expires: time.Now().Add(24 * time.Hour), Expires: time.Now().Add(24 * time.Hour),
} }
return cookie, nil return cookie, nil
} }
func delCookie(c echo.Context, sessionID string) error {
cookie := &http.Cookie{
Name: cookieName,
Value: "",
Path: "/",
MaxAge: -1,
}
err := redisCL.Del(ctx, sessionID).Err()
if err != nil {
log.Println(sessionID + "não era um cookie valido")
}
c.SetCookie(cookie)
return nil
}
func verifyTabeles(tbex []string, tb string) bool { func verifyTabeles(tbex []string, tb string) bool {
for _, a := range tbex { for _, a := range tbex {
if tb == a { if tb == a {
@@ -112,6 +129,7 @@ func ValidSession(c echo.Context) (map[string]string, error) {
sessionID := cookie.Value sessionID := cookie.Value
dataSession, err := redisCL.HGetAll(ctx, sessionID).Result() dataSession, err := redisCL.HGetAll(ctx, sessionID).Result()
if err != nil { if err != nil {
delCookie(c, sessionID)
return nil, fmt.Errorf("sessão invalida ou expirada.") return nil, fmt.Errorf("sessão invalida ou expirada.")
} }

View File

@@ -41,7 +41,7 @@ var (
redisCL *redis.Client redisCL *redis.Client
ctx = context.Background() ctx = context.Background()
table_list = map[string]string{ table_list = map[string]string{
"players": "CREATE TABLE players (`id` INT NOT NULL AUTO_INCREMENT,`foto` MEDIUMTEXT NOT NULL,`player` VARCHAR(15) NOT NULL,`password` TEXT NOT NULL,`nome` VARCHAR(30) NOT NULL, `conhecimento` INT NOT NULL DEFAULT '0',`level` INT NOT NULL DEFAULT '0',`idade` INT NOT NULL DEFAULT '18',`altura` FLOAT NOT NULL DEFAULT '1.40',`vida` INT NOT NULL DEFAULT '10',`vida_maxima` INT NOT NULL DEFAULT '10',`destresa` INT NOT NULL DEFAULT '0',`inteligencia` INT NOT NULL DEFAULT '0',`força` INT NOT NULL DEFAULT '0',`constituição` INT NOT NULL DEFAULT '0',`cárisma` INT NOT NULL DEFAULT '0',`inventario` INT NOT NULL DEFAULT '10',`descrição` TEXT NOT NULL,PRIMARY KEY (`id`)) ENGINE = InnoDB;", "players": "CREATE TABLE players (`id` INT NOT NULL AUTO_INCREMENT,`foto` LONGTEXT NOT NULL,`player` VARCHAR(15) NOT NULL,`password` TEXT NOT NULL,`nome` VARCHAR(30) NOT NULL, `conhecimento` INT NOT NULL DEFAULT '0',`level` INT NOT NULL DEFAULT '0',`idade` INT NOT NULL DEFAULT '18',`altura` FLOAT NOT NULL DEFAULT '1.40',`vida` INT NOT NULL DEFAULT '10',`vida_maxima` INT NOT NULL DEFAULT '10',`destresa` INT NOT NULL DEFAULT '0',`inteligencia` INT NOT NULL DEFAULT '0',`força` INT NOT NULL DEFAULT '0',`constituição` INT NOT NULL DEFAULT '0',`cárisma` INT NOT NULL DEFAULT '0',`inventario` INT NOT NULL DEFAULT '10',`descrição` TEXT NOT NULL,PRIMARY KEY (`id`)) ENGINE = InnoDB;",
"roll_logs": "CREATE TABLE roll_logs (`id` INT NOT NULL AUTO_INCREMENT , `log` TEXT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;", "roll_logs": "CREATE TABLE roll_logs (`id` INT NOT NULL AUTO_INCREMENT , `log` TEXT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;",
} }
formatFILES = map[string]bool{ formatFILES = map[string]bool{
@@ -50,5 +50,5 @@ var (
".jpeg": true, ".jpeg": true,
".gif": true, ".gif": true,
} }
cookieName string = "PlayerSession" cookieName string = "playerSession"
) )

View File

@@ -84,7 +84,7 @@ func main() {
log.Println("concluido, back_end rodando") log.Println("concluido, back_end rodando")
/* rotas */ /* rotas */
e.GET("logout", logout)
e.GET("/", online) e.GET("/", online)
e.GET("roll", roll_get) e.GET("roll", roll_get)
e.POST("roll", roll) e.POST("roll", roll)
@@ -93,6 +93,8 @@ func main() {
e.POST("login", login, timeoutMiddleware, rateLimit) e.POST("login", login, timeoutMiddleware, rateLimit)
e.GET("login", badreq) e.GET("login", badreq)
e.GET("player", player_data) e.GET("player", player_data)
e.POST("player/update", player_updateInputs)
e.PATCH("player/:atb/:updown", player_update)
/* log */ /* log */
e.Logger.Fatal(e.Start(fmt.Sprintf(":%s", load_data["port"]))) e.Logger.Fatal(e.Start(fmt.Sprintf(":%s", load_data["port"])))

View File

@@ -17,6 +17,25 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )
func logout(c echo.Context) error {
_, err := ValidSession(c)
if err != nil {
return c.JSON(http.StatusUnauthorized, resp_json{
Status: "Error",
Message: "para fazer logout você deve estar logado seu cabaço",
})
}
cookie, _ := c.Cookie(cookieName)
sessionID := cookie.Value
delCookie(c, sessionID)
return c.JSON(http.StatusOK, resp_json{
Status: "Success",
Message: "Você fez foi deslogado.",
})
}
func online(c echo.Context) error { func online(c echo.Context) error {
return c.JSON(http.StatusOK, resp_json{ return c.JSON(http.StatusOK, resp_json{
Status: "Success", Status: "Success",
@@ -91,10 +110,10 @@ func registrar(c echo.Context) error {
}) })
} }
defer openfile.Close() defer openfile.Close()
if ImageFile.Size > 3*1024*1024 { if ImageFile.Size > 25*1024*1024 {
return c.JSON(http.StatusBadRequest, resp_json{ return c.JSON(http.StatusBadRequest, resp_json{
Status: "Error", Status: "Error",
Message: "Sua imagem deve ter no maximo 3MB", Message: "Sua imagem deve ter no maximo 25MB",
}) })
} }
@@ -157,7 +176,7 @@ func registrar(c echo.Context) error {
Message: "sua conta foi criada com sucesso", Message: "sua conta foi criada com sucesso",
}) })
} }
log.Println(err)
return c.JSON(http.StatusInternalServerError, resp_json{ return c.JSON(http.StatusInternalServerError, resp_json{
Status: "Error", Status: "Error",
Message: "Erro ao criar sua conta, tente novamente", Message: "Erro ao criar sua conta, tente novamente",
@@ -327,3 +346,136 @@ func player_data(c echo.Context) error {
}) })
} }
func player_update(c echo.Context) error {
userSession, err := ValidSession(c)
if err != nil {
return c.JSON(http.StatusUnauthorized, resp_json{
Status: "Error",
Message: err.Error(),
})
}
updown := c.Param("updown")
atb := c.Param("atb")
var sinal string
switch updown {
case "up":
sinal = "+"
case "down":
sinal = "-"
default:
return c.JSON(http.StatusBadRequest, resp_json{
Status: "Error",
Message: "você passou um parametro invalido em updown, use up ou down.",
})
}
var updateList = map[string]string{
"vida": fmt.Sprintf("UPDATE players SET vida = vida %s 1 WHERE id=?;", sinal),
"level": fmt.Sprintf("UPDATE players SET level = level %s 1 WHERE id=?;", sinal),
"idade": fmt.Sprintf("UPDATE players SET idade = idade %s 1 WHERE id=?;", sinal),
"conhecimento": fmt.Sprintf("UPDATE players SET conhecimento = conhecimento %s 1 WHERE id=?;", sinal),
"força": fmt.Sprintf("UPDATE players SET força = força %s 1 WHERE id=?;", sinal),
"destresa": fmt.Sprintf("UPDATE players SET destresa = destresa %s 1 WHERE id=?;", sinal),
"constituição": fmt.Sprintf("UPDATE players SET constituição = constituição %s 1 WHERE id=?;", sinal),
"inteligencia": fmt.Sprintf("UPDATE players SET inteligencia = inteligencia %s 1 WHERE id=?;", sinal),
"cárisma": fmt.Sprintf("UPDATE players SET cárisma = cárisma %s 1 WHERE id=?;", sinal),
}
query, ok := updateList[atb]
if !ok {
return c.JSON(http.StatusBadRequest, resp_json{
Status: "Error",
Message: "você passou um parametro invalido, tente novamente com um parametro correto",
})
}
_, err = db.Exec(query, userSession["user_id"])
if err != nil {
return c.JSON(http.StatusInternalServerError, resp_json{
Status: "Error",
Message: "algo deu errado a atualizar sua ficha",
})
}
return c.JSON(http.StatusOK, resp_json{
Status: "Success",
Message: sinal + "1 em " + atb,
})
}
func player_updateInputs(c echo.Context) error {
userSession, err := ValidSession(c)
if err != nil {
return c.JSON(http.StatusUnauthorized, resp_json{
Status: "Error",
Message: err.Error(),
})
}
var lista []string
vida := c.FormValue("vida")
nome := c.FormValue("nome")
altura := c.FormValue("altura")
inv := c.FormValue("inventario")
if vida != "" {
_, err = db.Exec("UPDATE players SET vida=?, vida_maxima=? WHERE id=?;", vida, vida, userSession["user_id"])
if err != nil {
log.Println(err)
return c.JSON(http.StatusInternalServerError, resp_json{
Status: "Error",
Message: "algo deu errado ao alterar sua vida.",
})
}
lista = append(lista, "vida")
}
if nome != "" {
_, err = db.Exec("UPDATE players SET nome=? WHERE id=?;", nome, userSession["user_id"])
if err != nil {
log.Println(err)
return c.JSON(http.StatusInternalServerError, resp_json{
Status: "Error",
Message: "algo deu errado ao alterar seu nome.",
})
}
lista = append(lista, "nome")
}
if altura != "" {
_, err = db.Exec("UPDATE players SET altura=? WHERE id=?;", altura, userSession["user_id"])
if err != nil {
log.Println(err)
return c.JSON(http.StatusInternalServerError, resp_json{
Status: "Error",
Message: "algo deu errado ao alterar sua altura.",
})
}
lista = append(lista, "altura")
}
if inv != "" {
_, err = db.Exec("UPDATE players SET inventario=? WHERE id=?;", inv, userSession["user_id"])
if err != nil {
log.Println(err)
return c.JSON(http.StatusInternalServerError, resp_json{
Status: "Error",
Message: "algo deu errado ao alterar o tamanho do seu inventario.",
})
}
lista = append(lista, "inventario")
}
if len(lista) <= 0 {
return c.JSON(http.StatusUnauthorized, resp_json{
Status: "Error",
Message: "você é obrigado a alguma informação seu cabaço.",
})
}
return c.JSON(http.StatusOK, resp_json{
Status: "Success",
Message: fmt.Sprintf("você mudou as seguintes informaçôes: %s", lista),
})
}

View File

@@ -12,9 +12,8 @@
gap: 1vw; gap: 1vw;
#hero { #hero {
width: 15%; width: 25dvh;
height: auto; height: 25dvh;
max-height: 30dvh;
border: solid 3px var(--backredcolor); border: solid 3px var(--backredcolor);
border-radius: 100dvh; border-radius: 100dvh;
object-fit: cover; object-fit: cover;
@@ -96,6 +95,12 @@
border-radius: 1dvw; border-radius: 1dvw;
label { label {
a {
display: flex;
align-content: center;
align-items: center;
}
padding-left: 1dvh; padding-left: 1dvh;
display: flex; display: flex;
align-items: center; align-items: center;
@@ -177,6 +182,7 @@
#log { #log {
flex-grow: 1; flex-grow: 1;
overflow-y: auto; overflow-y: auto;
li { li {
cursor: pointer; cursor: pointer;
font-size: 1.5em; font-size: 1.5em;
@@ -212,6 +218,7 @@
position: relative; position: relative;
cursor: pointer; cursor: pointer;
cursor: pointer; cursor: pointer;
a { a {
position: absolute; position: absolute;
right: 1dvh; right: 1dvh;
@@ -233,6 +240,7 @@
background-color: var(--backdarkredcolor); background-color: var(--backdarkredcolor);
} }
} }
li:hover { li:hover {
background-color: var(--lines); background-color: var(--lines);
} }
@@ -330,6 +338,42 @@
} }
} }
#box_2 {
h1 {
min-height: 4dvh;
width: 100%;
background: var(--btncolor);
font-family: "Share Tech Mono", monospace;
display: flex;
padding: 0 0 0 1vw;
align-items: center;
}
#text_lore {
ul {
position: relative;
#btn {
position: absolute;
top: 1dvh;
right: 1dvh;
width: 4dvh;
height: 4dvh;
background-color: var(--btncolor);
border-radius: 100vh;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
p {
font-family: arial;
font-size: 1.5em;
padding: 1vw;
white-space: pre-wrap;
}
}
}
}
/* Responsividade */ /* Responsividade */
@media only screen and (max-width: 1080px) { @media only screen and (max-width: 1080px) {
#playerDATA { #playerDATA {
@@ -338,8 +382,8 @@
height: auto; height: auto;
#hero { #hero {
width: 40vw; width: 40dvw;
height: 40vw; height: 40dvw;
} }
ul li { ul li {
@@ -349,15 +393,18 @@
#box_1 { #box_1 {
flex-direction: column; flex-direction: column;
#dados, #dados,
#status, #status,
#inv, #inv,
#powers { #powers {
width: 100%; width: 100%;
min-height: 43vh; min-height: 43vh;
hgroup input[type="text"] { hgroup input[type="text"] {
width: 20dvw; width: 20dvw;
} }
hgroup input[type="number"] { hgroup input[type="number"] {
width: 8dvw; width: 8dvw;
} }
@@ -366,13 +413,6 @@
#status li { #status li {
border-top-right-radius: 2dvh; border-top-right-radius: 2dvh;
border-bottom-right-radius: 2dvh; border-bottom-right-radius: 2dvh;
label {
a {
display: flex;
align-content: center;
align-items: center;
}
}
} }
#dados #list { #dados #list {

View File

@@ -16,39 +16,54 @@
<ul> <ul>
<li> <li>
<label>vida:</label> <label>vida:</label>
<p>0/0</p> <p id="vdp">0/0</p>
<a id="btn"> <a id="btn" class="updown" data-atb="vida" data-updown="up">
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_upward arrow_upward
</span> </span>
</a> </a>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="vida"
data-updown="down"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_downward arrow_downward
</span> </span>
</a> </a>
<a id="btn" class="editbtn player_life"> <a id="btn" class="editbtn vida">
<span class="material-symbols-outlined"> edit </span> <span class="material-symbols-outlined"> edit </span>
edit edit
</a> </a>
</li> </li>
<li> <li>
<label>nome:</label> <label>nome:</label>
<p>you user name</p> <p id="nmp">you user name</p>
<a id="btn" class="editbtn player_name"> <a id="btn" class="editbtn nome">
<span class="material-symbols-outlined"> edit </span> <span class="material-symbols-outlined"> edit </span>
edit edit
</a> </a>
</li> </li>
<li> <li>
<label>level:</label> <label>level:</label>
<p>0</p> <p id="lvp">0</p>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="level"
data-updown="up"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_upward arrow_upward
</span> </span>
</a> </a>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="level"
data-updown="down"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_downward arrow_downward
</span> </span>
@@ -56,13 +71,23 @@
</li> </li>
<li> <li>
<label>idade:</label> <label>idade:</label>
<p>0</p> <p id="idp">0</p>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="idade"
data-updown="up"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_upward arrow_upward
</span> </span>
</a> </a>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="idade"
data-updown="down"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_downward arrow_downward
</span> </span>
@@ -70,8 +95,8 @@
</li> </li>
<li> <li>
<label>altura:</label> <label>altura:</label>
<p>0,0</p> <p id="alp">0,0</p>
<a id="btn" class="editbtn"> <a id="btn" class="editbtn altura">
<span class="material-symbols-outlined"> edit </span> <span class="material-symbols-outlined"> edit </span>
edit edit
</a> </a>
@@ -82,7 +107,7 @@
<div id="dados"> <div id="dados">
<h1>Dados</h1> <h1>Dados</h1>
<ul id="list"> <ul id="list">
<li> <li onclick="roll(6)">
<a> <a>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
casino casino
@@ -90,7 +115,7 @@
1d6 1d6
</a> </a>
</li> </li>
<li> <li onclick="roll(10)">
<a> <a>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
casino casino
@@ -98,7 +123,7 @@
1d10 1d10
</a> </a>
</li> </li>
<li> <li onclick="roll(20)">
<a> <a>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
casino casino
@@ -106,7 +131,7 @@
1d20 1d20
</a> </a>
</li> </li>
<li> <li onclick="roll(40)">
<a> <a>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
casino casino
@@ -114,7 +139,7 @@
1d40 1d40
</a> </a>
</li> </li>
<li> <li onclick="roll(50)">
<a> <a>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
casino casino
@@ -122,7 +147,7 @@
1d50 1d50
</a> </a>
</li> </li>
<li> <li onclick="roll(100)">
<a> <a>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
casino casino
@@ -139,151 +164,169 @@
<li> <li>
<label> <label>
conh: conh:
<p id="life" class="status_player">0</p> <p id="conhecimento" class="status_player">0</p>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="conhecimento"
data-updown="up"
>
<span <span
class="material-symbols-outlined btn-left" class="material-symbols-outlined btn-left"
> >
arrow_upward arrow_upward
</span> </span>
</a> </a>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="conhecimento"
data-updown="down"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_downward arrow_downward
</span> </span>
</a> </a>
<a id="btn" class="editbtn">
<span
class="material-symbols-outlined btn-right"
>
edit
</span>
</a>
</label> </label>
</li> </li>
<li> <li>
<label> <label>
for: for:
<p id="power" class="status_player">0</p> <p id="força" class="status_player">0</p>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="força"
data-updown="up"
>
<span <span
class="material-symbols-outlined btn-left" class="material-symbols-outlined btn-left"
> >
arrow_upward arrow_upward
</span> </span>
</a> </a>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="força"
data-updown="down"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_downward arrow_downward
</span> </span>
</a> </a>
<a id="btn" class="editbtn">
<span
class="material-symbols-outlined btn-right"
>
edit
</span>
</a>
</label> </label>
</li> </li>
<li> <li>
<label> <label>
des: des:
<p id="dexterity" class="status_player">0</p> <p id="destresa" class="status_player">0</p>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="destresa"
data-updown="up"
>
<span <span
class="material-symbols-outlined btn-left" class="material-symbols-outlined btn-left"
> >
arrow_upward arrow_upward
</span> </span>
</a> </a>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="destresa"
data-updown="down"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_downward arrow_downward
</span> </span>
</a> </a>
<a id="btn" class="editbtn">
<span
class="material-symbols-outlined btn-right"
>
edit
</span>
</a>
</label> </label>
</li> </li>
<li> <li>
<label> <label>
const: const:
<p id="constitution" class="status_player">0</p> <p id="constitution" class="status_player">0</p>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="constituição"
data-updown="up"
>
<span <span
class="material-symbols-outlined btn-left" class="material-symbols-outlined btn-left"
> >
arrow_upward arrow_upward
</span> </span>
</a> </a>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="constituição"
data-updown="down"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_downward arrow_downward
</span> </span>
</a> </a>
<a id="btn" class="editbtn">
<span
class="material-symbols-outlined btn-right"
>
edit
</span>
</a>
</label> </label>
</li> </li>
<li> <li>
<label> <label>
int: int:
<p id="intellect" class="status_player">0</p> <p id="inteligencia" class="status_player">0</p>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="inteligencia"
data-updown="up"
>
<span <span
class="material-symbols-outlined btn-left" class="material-symbols-outlined btn-left"
> >
arrow_upward arrow_upward
</span> </span>
</a> </a>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="inteligencia"
data-updown="down"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_downward arrow_downward
</span> </span>
</a> </a>
<a id="btn" class="editbtn">
<span
class="material-symbols-outlined btn-right"
>
edit
</span>
</a>
</label> </label>
</li> </li>
<li> <li>
<label> <label>
car: car:
<p id="charisma" class="status_player">0</p> <p id="cárisma" class="status_player">0</p>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="cárisma"
data-updown="up"
>
<span <span
class="material-symbols-outlined btn-left" class="material-symbols-outlined btn-left"
> >
arrow_upward arrow_upward
</span> </span>
</a> </a>
<a id="btn"> <a
id="btn"
class="updown"
data-atb="cárisma"
data-updown="down"
>
<span class="material-symbols-outlined"> <span class="material-symbols-outlined">
arrow_downward arrow_downward
</span> </span>
</a> </a>
<a id="btn" class="editbtn">
<span
class="material-symbols-outlined btn-right"
>
edit
</span>
</a>
</label> </label>
</li> </li>
</ul> </ul>
@@ -314,8 +357,8 @@
<label> <label>
<p>0</p> <p>0</p>
/ /
<p>0</p> <p id="mip">0</p>
<a id="btn"> <a id="btn" class="editbtn inventario">
<span class="material-symbols-outlined btn-right"> <span class="material-symbols-outlined btn-right">
edit edit
</span> </span>
@@ -330,7 +373,19 @@
</ul> </ul>
</div> </div>
</div> </div>
<div id="box_2"></div> <div id="box_2">
<h1>Texto do Player</h1>
<div id="text_lore">
<ul>
<a id="btn">
<span class="material-symbols-outlined btn-right">
edit
</span>
</a>
<p id="lore"></p>
</ul>
</div>
</div>
<!-- scripts --> <!-- scripts -->
<script type="text/javascript" src="javascript/script.js"></script> <script type="text/javascript" src="javascript/script.js"></script>

View File

@@ -1,4 +1,38 @@
let img;
let update; let update;
function load_ficha() {
$.ajax({
url: window.api + "player",
type: "GET",
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);
$("#idp").text(resp.Idade);
$("#alp").text(resp.Altura);
$("#conhecimento").text(resp.Conhecimento);
$("#força").text(resp.Força);
$("#destresa").text(resp.Destresa);
$("#constitution").text(resp.Constituição);
$("#inteligencia").text(resp.Inteligencia);
$("#cárisma").text(resp.Cárisma);
$("#mip").text(resp.Inventario);
$("#lore").text(resp.Descrição);
},
error: function (resp, status, jqXHR) {
window.location.href = "login.html";
},
});
}
function roll_load() { function roll_load() {
$.ajax({ $.ajax({
url: window.api + "roll", url: window.api + "roll",
@@ -34,8 +68,42 @@ function roll_load() {
}); });
} }
$(document).ready(function () { function roll(d) {
setInterval(function () { $.ajax({
roll_load(); url: window.api + "roll",
}, 1000); type: "POST",
data: { roll: d },
xhrFields: { withCredentials: true },
success: function (resp) {
msg(resp.Status, resp.Message);
},
});
}
load_ficha();
$(document).ready(function () {
$(".updown").click(function () {
const atb = $(this).data("atb");
const updown = $(this).data("updown");
$.ajax({
url: `${window.api}player/${atb}/${updown}`,
type: "PATCH",
xhrFields: {
withCredentials: true,
},
error: function (resp, status, jqXHR) {
msg(
resp.responseJSON?.Status || "Erro",
resp.responseJSON?.Message || "Algo deu errado.",
);
},
});
});
setInterval(function () {
load_ficha();
roll_load();
}, 500);
}); });

64
rpg/javascript/login.js Normal file
View File

@@ -0,0 +1,64 @@
function load_ficha() {
$.ajax({
url: window.api + "player",
type: "GET",
xhrFields: {
withCredentials: true,
},
success: function (resp) {
window.location.href = "index.html";
},
});
}
function verifyInputs(player, passwd) {
if (player && !player.includes(" ") && passwd && !passwd.includes(" ")) {
return true;
}
return false;
}
$(document).ready(function () {
load_ficha();
$("#loginBtn").on("click", function () {
const $btn = $(this);
$btn.prop("disabled", true).val("Logando ...");
const player = $("#loginInput[name='player']").val();
const password = $("#loginInput[name='password']").val();
if (!verifyInputs(player, password)) {
msg("Error", "Por favor, preencha todos os dados corretamente.");
return finalizarErro($btn, "Login");
}
const form = new FormData();
form.append("player", player);
form.append("password", password);
$.ajax({
url: window.api + "login",
type: "POST",
data: form,
contentType: false,
processData: false,
xhrFields: { withCredentials: true },
success: function (resp) {
msg(resp.Status, resp.Message);
$btn.val("Concluído");
window.location.href = "index.html";
},
error: function (resp) {
msg(
resp.responseJSON?.Status || "Erro",
resp.responseJSON?.Message || "Algo deu errado.",
);
finalizarErro($btn, "Login");
},
});
});
function finalizarErro($btn, texto = "Login") {
$btn.prop("disabled", false).val(texto);
}
});

View File

@@ -1,3 +1,16 @@
function load_ficha() {
$.ajax({
url: window.api + "player",
type: "GET",
xhrFields: {
withCredentials: true,
},
success: function (resp) {
window.location.href = "index.html";
},
});
}
function verifyInputs(player, passwd, confpasswd, lore) { function verifyInputs(player, passwd, confpasswd, lore) {
if ( if (
player && player &&
@@ -25,6 +38,7 @@ $("#inputImagem").on("change", function () {
}); });
$(document).ready(function () { $(document).ready(function () {
load_ficha();
$("#loginBtn").on("click", function () { $("#loginBtn").on("click", function () {
const $btn = $(this); const $btn = $(this);
$btn.prop("disabled", true).val("Criando conta..."); $btn.prop("disabled", true).val("Criando conta...");

View File

@@ -3,6 +3,29 @@ var $inp;
let cordX = 0; let cordX = 0;
let cordY = 0; let cordY = 0;
function data_update(name, value) {
return new Promise((resulve, reject) => {
$.ajax({
url: window.api + "player/update",
type: "POST",
data: { [name]: value },
xhrFields: { withCredentials: true },
success: function (resp) {
msg(resp.Status, resp.Message);
resulve(true);
},
error: function (resp, status, jqXHR) {
msg(
resp.responseJSON?.Status || "Erro",
resp.responseJSON?.Message || "Algo deu errado.",
);
resulve(false);
},
});
});
}
function editInput(name, x, y) { function editInput(name, x, y) {
var input = ` var input = `
<nav id="FloatInput" style="top: ${y - 50}px; left: ${x - 100}px"> <nav id="FloatInput" style="top: ${y - 50}px; left: ${x - 100}px">
@@ -15,8 +38,13 @@ function editInput(name, x, y) {
if (e.which === 13) { if (e.which === 13) {
switch ($(this).find("input").val().length > 0) { switch ($(this).find("input").val().length > 0) {
case true: case true:
console.log($(this).find("input").val()); let name = $(this).find("input").attr("name");
alert($(this).find("input").val()); let value = $(this).find("input").val();
data_update(name, value).then((result) => {
if (result) {
$(this).remove();
}
});
break; break;
case false: case false:
$(this).remove(); $(this).remove();

View File

@@ -25,7 +25,7 @@
<li> <li>
<input <input
type="password" type="password"
name="passowrd" name="password"
placeholder="senha" placeholder="senha"
id="loginInput" id="loginInput"
/> />
@@ -34,5 +34,6 @@
<li><a href="registro.html">Criar conta</a></li> <li><a href="registro.html">Criar conta</a></li>
</ul> </ul>
</div> </div>
<script type="text/javascript" src="javascript/login.js"></script>
</body> </body>
</html> </html>