From dffe8310b331dd89d1301539346f237e191be8e2 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Fri, 14 Nov 2014 22:50:00 -0500 Subject: [PATCH] s/player/profile in various places --- bomb.go | 26 +++++++++++++------------- commands.go | 6 +++--- connection.go | 30 +++++++++++++++--------------- db.go | 2 +- game.go | 8 ++++---- player.go | 22 +++++++++++----------- scan.go | 4 ++-- system.go | 2 +- 8 files changed, 50 insertions(+), 50 deletions(-) diff --git a/bomb.go b/bomb.go index 9ac43ad..734f508 100644 --- a/bomb.go +++ b/bomb.go @@ -6,12 +6,12 @@ import ( ) type Bomb struct { - player *Connection - origin *System - target *System - start time.Time - done bool - fti int64 // frames to impact + profile *Connection + origin *System + target *System + start time.Time + done bool + fti int64 // frames to impact } func NewBomb(from *Connection, to *System) *Bomb { @@ -19,13 +19,13 @@ func NewBomb(from *Connection, to *System) *Bomb { dist := origin.DistanceTo(to) fti := int64(dist / (options.lightSpeed * options.bombSpeed)) 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{ - player: from, - origin: origin, - target: to, - fti: fti, - start: time.Now(), + profile: from, + origin: origin, + target: to, + fti: fti, + start: time.Now(), } } @@ -36,7 +36,7 @@ func (b *Bomb) Dead() bool { func (b *Bomb) Tick(frame int64) { b.fti -= 1 if b.fti <= 0 { - b.target.Bombed(b.player) + b.target.Bombed(b.profile) b.done = true log_info("bomb went off on %s", b.target.Label()) } diff --git a/commands.go b/commands.go index 2f248b3..cf5c26e 100644 --- a/commands.go +++ b/commands.go @@ -131,7 +131,7 @@ var broadcastCommand = &Command{ msg := strings.Join(args, " ") system := conn.System() 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) }, } @@ -178,7 +178,7 @@ var colonizeCommand = &Command{ if conn.money > 2000 { conn.Withdraw(2000) 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 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", handler: func(conn *Connection, args ...string) { for other, _ := range currentGame.connections { - conn.Printf("%v\n", other.PlayerName()) + conn.Printf("%v\n", other.Name()) } }, } diff --git a/connection.go b/connection.go index 4784406..83b5a85 100644 --- a/connection.go +++ b/connection.go @@ -12,7 +12,7 @@ import ( type Connection struct { net.Conn *bufio.Reader - player *Player + profile *Profile location *System dest *System travelRemaining int64 @@ -60,19 +60,19 @@ func (c *Connection) Login() { continue } log_info("player connected: %v", name) - player, err := loadPlayer(name) + profile, err := loadProfile(name) if err != nil { - log_error("could not read player: %v", err) - player = &Player{name: name} - if err := player.Create(); err != nil { - log_error("unable to create player record: %v", err) + log_error("could not read profile: %v", err) + profile = &Profile{name: name} + if err := profile.Create(); err != nil { + 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.player = player + c.profile = profile } else { - c.player = player - c.Printf("welcome back, %s.\n", player.name) + c.profile = profile + c.Printf("welcome back, %s.\n", profile.name) } break } @@ -181,7 +181,7 @@ func (c *Connection) System() *System { } func (c *Connection) Close() error { - log_info("player disconnecting: %s", c.PlayerName()) + log_info("player disconnecting: %s", c.Name()) currentGame.Quit(c) if c.Conn != nil { return c.Conn.Close() @@ -189,11 +189,11 @@ func (c *Connection) Close() error { return nil } -func (c *Connection) PlayerName() string { - if c.player == nil { +func (c *Connection) Name() string { + if c.profile == nil { return "" } - return c.player.name + return c.profile.name } func (c *Connection) InTransit() bool { @@ -229,7 +229,7 @@ func (c *Connection) NextBomb() time.Duration { func (c *Connection) MadeKill(victim *Connection) { if c == victim { - log_info("player %s commited suicide.", c.PlayerName()) + log_info("player %s commited suicide.", c.Name()) return } c.kills += 1 diff --git a/db.go b/db.go index 49ea91c..d91eadb 100644 --- a/db.go +++ b/db.go @@ -67,7 +67,7 @@ func setupDb() { planetsTable() planetsData() edgesTable() - playersTable() + profilesTable() gamesTable() fillEdges() } diff --git a/game.go b/game.go index 649affa..740412e 100644 --- a/game.go +++ b/game.go @@ -47,7 +47,7 @@ func NewGame() *Game { if currentGame != nil { log_info("passing %d connections...", len(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) game.Join(conn) } @@ -88,14 +88,14 @@ func (g *Game) Quit(conn *Connection) { func (g *Game) Win(winner *Connection, method string) { defer close(g.done) g.end = time.Now() - g.winner = winner.PlayerName() + g.winner = winner.Name() g.winMethod = method 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 { - 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) } } diff --git a/player.go b/player.go index b119089..9bf1c5e 100644 --- a/player.go +++ b/player.go @@ -11,39 +11,39 @@ func ValidName(name string) bool { return namePattern.MatchString(name) } -type Player struct { +type Profile struct { id int name string } -func (p *Player) Create() error { +func (p *Profile) Create() error { _, err := db.Exec(` - insert into players + insert into profiles (name) values (?) ;`, p.name) if err != nil { - return fmt.Errorf("unable to create player: %v", err) + return fmt.Errorf("unable to create profile: %v", err) } return nil } -func playersTable() { - stmnt := `create table if not exists players ( +func profilesTable() { + stmnt := `create table if not exists profiles ( id integer not null primary key autoincrement, name text unique );` 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) { - row := db.QueryRow(`select * from players where name = ?`, name) - var p Player +func loadProfile(name string) (*Profile, error) { + row := db.QueryRow(`select * from profiles where name = ?`, name) + var p Profile 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 } diff --git a/scan.go b/scan.go index 7ed0922..61d388c 100644 --- a/scan.go +++ b/scan.go @@ -31,7 +31,7 @@ func (r *scanResult) playerNames() []string { } names := make([]string, 0, len(r.players)) for conn := range r.players { - names = append(names, conn.PlayerName()) + names = append(names, conn.Name()) } return names } @@ -102,7 +102,7 @@ func (s *scan) echos() { s.origin.NotifyInhabitants("\tinhabitants: %v\n", inhabitants) } if res.colonizedBy != nil { - s.origin.NotifyInhabitants("\tcolonized by: %v\n", res.colonizedBy.PlayerName()) + s.origin.NotifyInhabitants("\tcolonized by: %v\n", res.colonizedBy.Name()) } } } diff --git a/system.go b/system.go index 6837fa0..9584874 100644 --- a/system.go +++ b/system.go @@ -41,7 +41,7 @@ func (s *System) Reset() { func (s *System) Arrive(conn *Connection) { 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 { s.players = make(map[*Connection]bool, 8) }