s/player/profile in various places

slack
Jordan Orelli 10 years ago
parent 5b4fff43e3
commit dffe8310b3

@ -6,12 +6,12 @@ import (
) )
type Bomb struct { type Bomb struct {
player *Connection profile *Connection
origin *System origin *System
target *System target *System
start time.Time start time.Time
done bool done bool
fti int64 // frames to impact fti int64 // frames to impact
} }
func NewBomb(from *Connection, to *System) *Bomb { func NewBomb(from *Connection, to *System) *Bomb {
@ -19,13 +19,13 @@ func NewBomb(from *Connection, to *System) *Bomb {
dist := origin.DistanceTo(to) dist := origin.DistanceTo(to)
fti := int64(dist / (options.lightSpeed * options.bombSpeed)) fti := int64(dist / (options.lightSpeed * options.bombSpeed))
eta := time.Duration(fti) * time.Second / time.Duration(options.frameRate) eta := time.Duration(fti) * time.Second / time.Duration(options.frameRate)
log_info("bomb from: %s to: %s ETA: %v", from.PlayerName(), to.Label(), eta) log_info("bomb from: %s to: %s ETA: %v", from.Name(), to.Label(), eta)
return &Bomb{ return &Bomb{
player: from, profile: from,
origin: origin, origin: origin,
target: to, target: to,
fti: fti, fti: fti,
start: time.Now(), start: time.Now(),
} }
} }
@ -36,7 +36,7 @@ func (b *Bomb) Dead() bool {
func (b *Bomb) Tick(frame int64) { func (b *Bomb) Tick(frame int64) {
b.fti -= 1 b.fti -= 1
if b.fti <= 0 { if b.fti <= 0 {
b.target.Bombed(b.player) b.target.Bombed(b.profile)
b.done = true b.done = true
log_info("bomb went off on %s", b.target.Label()) log_info("bomb went off on %s", b.target.Label())
} }

@ -131,7 +131,7 @@ var broadcastCommand = &Command{
msg := strings.Join(args, " ") msg := strings.Join(args, " ")
system := conn.System() system := conn.System()
b := NewBroadcast(system, msg) b := NewBroadcast(system, msg)
log_info("player %s send broadcast from system %s: %v\n", conn.PlayerName(), system.Label(), msg) log_info("player %s send broadcast from system %s: %v\n", conn.Name(), system.Label(), msg)
currentGame.Register(b) currentGame.Register(b)
}, },
} }
@ -178,7 +178,7 @@ var colonizeCommand = &Command{
if conn.money > 2000 { if conn.money > 2000 {
conn.Withdraw(2000) conn.Withdraw(2000)
if system.colonizedBy != nil { if system.colonizedBy != nil {
system.colonizedBy.Printf("your colony on %s has been stolen by %s\n", system.Label(), conn.PlayerName()) system.colonizedBy.Printf("your colony on %s has been stolen by %s\n", system.Label(), conn.Name())
} }
system.colonizedBy = conn system.colonizedBy = conn
conn.Printf("set up a mining colony on %s\n", conn.System().name) conn.Printf("set up a mining colony on %s\n", conn.System().name)
@ -244,7 +244,7 @@ var playersCommand = &Command{
help: "lists the connected players", help: "lists the connected players",
handler: func(conn *Connection, args ...string) { handler: func(conn *Connection, args ...string) {
for other, _ := range currentGame.connections { for other, _ := range currentGame.connections {
conn.Printf("%v\n", other.PlayerName()) conn.Printf("%v\n", other.Name())
} }
}, },
} }

@ -12,7 +12,7 @@ import (
type Connection struct { type Connection struct {
net.Conn net.Conn
*bufio.Reader *bufio.Reader
player *Player profile *Profile
location *System location *System
dest *System dest *System
travelRemaining int64 travelRemaining int64
@ -60,19 +60,19 @@ func (c *Connection) Login() {
continue continue
} }
log_info("player connected: %v", name) log_info("player connected: %v", name)
player, err := loadPlayer(name) profile, err := loadProfile(name)
if err != nil { if err != nil {
log_error("could not read player: %v", err) log_error("could not read profile: %v", err)
player = &Player{name: name} profile = &Profile{name: name}
if err := player.Create(); err != nil { if err := profile.Create(); err != nil {
log_error("unable to create player record: %v", err) log_error("unable to create profile record: %v", err)
} }
c.Printf("you look new around these parts, %s.\n", player.name) c.Printf("you look new around these parts, %s.\n", profile.name)
c.Printf(`if you'd like a description of how to play, type the "help" command\n`) c.Printf(`if you'd like a description of how to play, type the "help" command\n`)
c.player = player c.profile = profile
} else { } else {
c.player = player c.profile = profile
c.Printf("welcome back, %s.\n", player.name) c.Printf("welcome back, %s.\n", profile.name)
} }
break break
} }
@ -181,7 +181,7 @@ func (c *Connection) System() *System {
} }
func (c *Connection) Close() error { func (c *Connection) Close() error {
log_info("player disconnecting: %s", c.PlayerName()) log_info("player disconnecting: %s", c.Name())
currentGame.Quit(c) currentGame.Quit(c)
if c.Conn != nil { if c.Conn != nil {
return c.Conn.Close() return c.Conn.Close()
@ -189,11 +189,11 @@ func (c *Connection) Close() error {
return nil return nil
} }
func (c *Connection) PlayerName() string { func (c *Connection) Name() string {
if c.player == nil { if c.profile == nil {
return "" return ""
} }
return c.player.name return c.profile.name
} }
func (c *Connection) InTransit() bool { func (c *Connection) InTransit() bool {
@ -229,7 +229,7 @@ func (c *Connection) NextBomb() time.Duration {
func (c *Connection) MadeKill(victim *Connection) { func (c *Connection) MadeKill(victim *Connection) {
if c == victim { if c == victim {
log_info("player %s commited suicide.", c.PlayerName()) log_info("player %s commited suicide.", c.Name())
return return
} }
c.kills += 1 c.kills += 1

@ -67,7 +67,7 @@ func setupDb() {
planetsTable() planetsTable()
planetsData() planetsData()
edgesTable() edgesTable()
playersTable() profilesTable()
gamesTable() gamesTable()
fillEdges() fillEdges()
} }

@ -47,7 +47,7 @@ func NewGame() *Game {
if currentGame != nil { if currentGame != nil {
log_info("passing %d connections...", len(currentGame.connections)) log_info("passing %d connections...", len(currentGame.connections))
for conn, _ := range currentGame.connections { for conn, _ := range currentGame.connections {
log_info("moving player %s to new game", conn.PlayerName()) log_info("moving player %s to new game", conn.Name())
currentGame.Quit(conn) currentGame.Quit(conn)
game.Join(conn) game.Join(conn)
} }
@ -88,14 +88,14 @@ func (g *Game) Quit(conn *Connection) {
func (g *Game) Win(winner *Connection, method string) { func (g *Game) Win(winner *Connection, method string) {
defer close(g.done) defer close(g.done)
g.end = time.Now() g.end = time.Now()
g.winner = winner.PlayerName() g.winner = winner.Name()
g.winMethod = method g.winMethod = method
g.Store() g.Store()
log_info("player %s has won by %s victory", winner.PlayerName(), method) log_info("player %s has won by %s victory", winner.Name(), method)
for conn, _ := range g.connections { for conn, _ := range g.connections {
conn.Printf("player %s has won by %s victory.\n", winner.PlayerName(), method) conn.Printf("player %s has won by %s victory.\n", winner.Name(), method)
} }
} }

@ -11,39 +11,39 @@ func ValidName(name string) bool {
return namePattern.MatchString(name) return namePattern.MatchString(name)
} }
type Player struct { type Profile struct {
id int id int
name string name string
} }
func (p *Player) Create() error { func (p *Profile) Create() error {
_, err := db.Exec(` _, err := db.Exec(`
insert into players insert into profiles
(name) (name)
values values
(?) (?)
;`, p.name) ;`, p.name)
if err != nil { if err != nil {
return fmt.Errorf("unable to create player: %v", err) return fmt.Errorf("unable to create profile: %v", err)
} }
return nil return nil
} }
func playersTable() { func profilesTable() {
stmnt := `create table if not exists players ( stmnt := `create table if not exists profiles (
id integer not null primary key autoincrement, id integer not null primary key autoincrement,
name text unique name text unique
);` );`
if _, err := db.Exec(stmnt); err != nil { if _, err := db.Exec(stmnt); err != nil {
log_error("couldn't create player table: %v", err) log_error("couldn't create profiles table: %v", err)
} }
} }
func loadPlayer(name string) (*Player, error) { func loadProfile(name string) (*Profile, error) {
row := db.QueryRow(`select * from players where name = ?`, name) row := db.QueryRow(`select * from profiles where name = ?`, name)
var p Player var p Profile
if err := row.Scan(&p.id, &p.name); err != nil { if err := row.Scan(&p.id, &p.name); err != nil {
return nil, fmt.Errorf("unable to fetch player from database: %v", err) return nil, fmt.Errorf("unable to fetch profile from database: %v", err)
} }
return &p, nil return &p, nil
} }

@ -31,7 +31,7 @@ func (r *scanResult) playerNames() []string {
} }
names := make([]string, 0, len(r.players)) names := make([]string, 0, len(r.players))
for conn := range r.players { for conn := range r.players {
names = append(names, conn.PlayerName()) names = append(names, conn.Name())
} }
return names return names
} }
@ -102,7 +102,7 @@ func (s *scan) echos() {
s.origin.NotifyInhabitants("\tinhabitants: %v\n", inhabitants) s.origin.NotifyInhabitants("\tinhabitants: %v\n", inhabitants)
} }
if res.colonizedBy != nil { if res.colonizedBy != nil {
s.origin.NotifyInhabitants("\tcolonized by: %v\n", res.colonizedBy.PlayerName()) s.origin.NotifyInhabitants("\tcolonized by: %v\n", res.colonizedBy.Name())
} }
} }
} }

@ -41,7 +41,7 @@ func (s *System) Reset() {
func (s *System) Arrive(conn *Connection) { func (s *System) Arrive(conn *Connection) {
conn.SetSystem(s) conn.SetSystem(s)
log_info("player %s has arrived at system %s", conn.PlayerName(), s.Label()) log_info("player %s has arrived at system %s", conn.Name(), s.Label())
if s.players == nil { if s.players == nil {
s.players = make(map[*Connection]bool, 8) s.players = make(map[*Connection]bool, 8)
} }

Loading…
Cancel
Save