rename users table to players

master
Jordan Orelli 5 years ago
parent 853f39fb0f
commit c4893fd0cd

@ -20,15 +20,20 @@ func OpenSQLite(path string) (*SQLite, error) {
} }
if _, err := db.Exec(` if _, err := db.Exec(`
create table if not exists users ( create table if not exists players (
id integer primary key autoincrement, id integer primary key autoincrement,
name text unique not null, name text unique not null,
phash text not null, phash text not null,
psalt text not null psalt text not null
);`); err != nil { );`); err != nil {
fmt.Fprintf(os.Stderr, "failed to create users table: %v\n", err) fmt.Fprintf(os.Stderr, "failed to create players table: %v\n", err)
} }
// if _, err := db.Exec(`
// create table if not exists corpses (
// id integer primary key autoincrement,
// player integer fo
return &SQLite{db: db}, nil return &SQLite{db: db}, nil
} }
@ -40,7 +45,7 @@ func (db *SQLite) CreateUser(name, pass, salt string) error {
} }
hash := string(hashBytes) hash := string(hashBytes)
if _, err := db.db.Exec(` if _, err := db.db.Exec(`
insert into users (name, phash, psalt) insert into players (name, phash, psalt)
values (?, ?, ?); values (?, ?, ?);
`, name, hash, salt); err != nil { `, name, hash, salt); err != nil {
return fmt.Errorf("unable to insert user: %v", err) return fmt.Errorf("unable to insert user: %v", err)
@ -50,7 +55,7 @@ func (db *SQLite) CreateUser(name, pass, salt string) error {
func (db *SQLite) CheckPassword(name, pass string) error { func (db *SQLite) CheckPassword(name, pass string) error {
rows, err := db.db.Query(` rows, err := db.db.Query(`
select phash, psalt from users where name = ?; select phash, psalt from players where name = ?;
`, name) `, name)
if err != nil { if err != nil {
return fmt.Errorf("failed to fetch row for user %s: %v", name, err) return fmt.Errorf("failed to fetch row for user %s: %v", name, err)
@ -86,7 +91,7 @@ func (db *SQLite) SetPassword(name, pass, salt string) error {
} }
hash := string(hashBytes) hash := string(hashBytes)
if _, err := db.db.Exec(` if _, err := db.db.Exec(`
update users update players
set phash = ?, psalt = ? set phash = ?, psalt = ?
where name = ?; where name = ?;
`, hash, salt, name); err != nil { `, hash, salt, name); err != nil {

@ -3,6 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"time"
) )
type request struct { type request struct {
@ -85,6 +86,26 @@ func (l *login) exec(s *server, from *player) {
b, _ := json.Marshal(res) b, _ := json.Marshal(res)
msg := fmt.Sprintf("login-result %s", string(b)) msg := fmt.Sprintf("login-result %s", string(b))
from.outbox <- msg from.outbox <- msg
messages := make([]string, 0, len(s.souls))
for _, soul := range s.souls {
b, _ := json.Marshal(soul)
msg := fmt.Sprintf("spawn-soul %s", string(b))
messages = append(messages, msg)
}
go func() {
time.Sleep(1 * time.Second)
for _, msg := range messages {
select {
case from.outbox <- msg:
default:
}
}
}()
} }
type death struct { type death struct {

Loading…
Cancel
Save