diff options
Diffstat (limited to 'server/server.go')
| -rw-r--r-- | server/server.go | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/server/server.go b/server/server.go index c549122..b747b14 100644 --- a/server/server.go +++ b/server/server.go @@ -34,6 +34,7 @@ type worldState struct { LastId levelId SpawnLevel levelId SpawnPos entityPos + Banned map[string]string } func NewServer(info ServerInfo) *Server { @@ -66,6 +67,9 @@ func NewServer(info ServerInfo) *Server { }) s.worldState = <-loaded } + if s.worldState.Banned == nil { + s.worldState.Banned = make(map[string]string) + } return s } @@ -179,11 +183,11 @@ func (s *Server) OnDisconnect(cl *client, username string, pl *player) { } if s.players[username] == pl { delete(s.players, username) + s.Broadcast(nil, fmt.Sprintf("&e%s has left", username)) } if username == "" { return } - s.Broadcast(nil, fmt.Sprintf("&e%s has left", username)) }) } @@ -250,9 +254,37 @@ func (s *Server) changePlayerAuth( }) } +func (s *Server) ban(playerName string, reason string) { + log.Printf("banning %s for '%s'", playerName, reason) + s.kick(playerName, reason) + s.worldState.Banned[playerName] = reason +} + +func (s *Server) unban(playerName string) { + log.Printf("unbanning %s", playerName) + delete(s.worldState.Banned, playerName) +} + +func (s *Server) kick(playerName string, reason string) bool { + pl := s.players[playerName] + if pl == nil { + return false + } + if reason == "" { + reason = "Bye!" + } + pl.Kick(s, reason) + return true +} + func (s *Server) NewPlayer( from phony.Actor, cl *client, name string, reply func(*player)) { s.Act(from, func() { + banReason, ok := s.worldState.Banned[name] + if ok { + cl.Disconnect(s, banReason) + return + } s.Broadcast(nil, fmt.Sprintf("&e%s has joined", name)) if s.players[name] != nil { s.players[name].Act(s, func() { |
