s/player/profile in various places

slack
Jordan Orelli 10 years ago
parent 5b4fff43e3
commit dffe8310b3

@ -6,7 +6,7 @@ import (
)
type Bomb struct {
player *Connection
profile *Connection
origin *System
target *System
start time.Time
@ -19,9 +19,9 @@ 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,
profile: from,
origin: origin,
target: to,
fti: fti,
@ -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())
}

@ -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())
}
},
}

@ -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

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

@ -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)
}
}

@ -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
}

@ -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())
}
}
}

@ -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)
}

Loading…
Cancel
Save