2022-11-06 10:38:37 +00:00

71 lines
1.5 KiB
Go

package main
import (
"fmt"
"time"
"golang.org/x/crypto/bcrypt"
"github.com/google/uuid"
)
type State int
const (
CoreZombie State = iota
Zombie
StunnedZombie
InfectedHuman
Human
Dead
)
type Player struct {
Id string `json:"id"`
Name string `json:"name"`
password string
State State `json:"state"`
Last_tagged time.Time `json:"last_tagged"`
Kills int `json:"kills"`
Last_kill time.Time `json:"last_kill"`
Cures int `json:"cures"`
Revives int `json:"revives"`
Extensions int `json:"extensions"`
}
type Login struct {
Name string `json:"name"`
Pass string `json:"password"`
}
func gen_pass(password string) (string) {
password_bytes := []byte(password)
hashed_bytes, _ := bcrypt.GenerateFromPassword(password_bytes, bcrypt.MinCost)
return string(hashed_bytes)
}
func new_player(name string, password string, state State) (Player) {
new_player := Player{
Id: uuid.New().String()[0:7],
Name: name,
password: gen_pass(password),
State: state,
Kills: 0,
Cures: 3,
Revives: 3,
Extensions: 3,
}
return new_player
}
func (p *Player) login (password string) (bool) {
succ := bcrypt.CompareHashAndPassword([]byte(p.password), []byte(password))
if (succ == nil) {
return true
} else {
fmt.Println(succ)
return false
}
}