|
|
@ -1,7 +1,9 @@
|
|
|
|
package main
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"database/sql"
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
@ -72,8 +74,10 @@ type login struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type loginResult struct {
|
|
|
|
type loginResult struct {
|
|
|
|
Passed bool `json:"passed"`
|
|
|
|
Passed bool `json:"passed"`
|
|
|
|
Error string `json:"error,omitempty"`
|
|
|
|
Dead bool `json:"dead"`
|
|
|
|
|
|
|
|
DiedAt time.Time `json:"died_at"`
|
|
|
|
|
|
|
|
Error string `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l *login) exec(s *server, from *player) {
|
|
|
|
func (l *login) exec(s *server, from *player) {
|
|
|
@ -93,7 +97,6 @@ func (l *login) exec(s *server, from *player) {
|
|
|
|
fmt.Printf("login read row from database: %v\n", row)
|
|
|
|
fmt.Printf("login read row from database: %v\n", row)
|
|
|
|
|
|
|
|
|
|
|
|
if row.HasPassword(l.Password) {
|
|
|
|
if row.HasPassword(l.Password) {
|
|
|
|
sendResult(loginResult{Passed: true})
|
|
|
|
|
|
|
|
from.username = l.Username
|
|
|
|
from.username = l.Username
|
|
|
|
from.id = row.ID
|
|
|
|
from.id = row.ID
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -101,6 +104,22 @@ func (l *login) exec(s *server, from *player) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body := db.Body{PlayerID: row.ID}
|
|
|
|
|
|
|
|
if err := s.db.ReadBody(&body); err != nil {
|
|
|
|
|
|
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
|
|
|
|
|
|
sendResult(loginResult{Passed: true})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sendResult(loginResult{Error: err.Error()})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sendResult(loginResult{
|
|
|
|
|
|
|
|
Passed: true,
|
|
|
|
|
|
|
|
Dead: true,
|
|
|
|
|
|
|
|
DiedAt: body.DiedAt,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
messages := make([]string, 0, len(s.souls))
|
|
|
|
messages := make([]string, 0, len(s.souls))
|
|
|
|
|
|
|
|
|
|
|
|
for _, soul := range s.souls {
|
|
|
|
for _, soul := range s.souls {
|
|
|
|