mirror of
https://github.com/jeremyd/ergo.git
synced 2026-07-21 06:48:10 -07:00
break up types.go
- remove old interfaces, move to relevant files - remove Phase in favor of a boolean flag
This commit is contained in:
+44
-32
@@ -16,10 +16,15 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
SERVER_SIGNALS = []os.Signal{syscall.SIGINT, syscall.SIGHUP,
|
||||
syscall.SIGTERM, syscall.SIGQUIT}
|
||||
)
|
||||
type ServerCommand interface {
|
||||
Command
|
||||
HandleServer(*Server)
|
||||
}
|
||||
|
||||
type RegServerCommand interface {
|
||||
Command
|
||||
HandleRegServer(*Server)
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
channels ChannelNameMap
|
||||
@@ -37,6 +42,11 @@ type Server struct {
|
||||
whoWas *WhoWasList
|
||||
}
|
||||
|
||||
var (
|
||||
SERVER_SIGNALS = []os.Signal{syscall.SIGINT, syscall.SIGHUP,
|
||||
syscall.SIGTERM, syscall.SIGQUIT}
|
||||
)
|
||||
|
||||
func NewServer(config *Config) *Server {
|
||||
server := &Server{
|
||||
channels: make(ChannelNameMap),
|
||||
@@ -111,34 +121,33 @@ func (server *Server) processCommand(cmd Command) {
|
||||
client := cmd.Client()
|
||||
Log.debug.Printf("%s → %s %s", client, server, cmd)
|
||||
|
||||
switch client.phase {
|
||||
case Registration:
|
||||
if !client.registered {
|
||||
regCmd, ok := cmd.(RegServerCommand)
|
||||
if !ok {
|
||||
client.Quit("unexpected command")
|
||||
return
|
||||
}
|
||||
regCmd.HandleRegServer(server)
|
||||
|
||||
case Normal:
|
||||
srvCmd, ok := cmd.(ServerCommand)
|
||||
if !ok {
|
||||
client.ErrUnknownCommand(cmd.Code())
|
||||
return
|
||||
}
|
||||
switch srvCmd.(type) {
|
||||
case *PingCommand, *PongCommand:
|
||||
client.Touch()
|
||||
|
||||
case *QuitCommand:
|
||||
// no-op
|
||||
|
||||
default:
|
||||
client.Active()
|
||||
client.Touch()
|
||||
}
|
||||
srvCmd.HandleServer(server)
|
||||
return
|
||||
}
|
||||
|
||||
srvCmd, ok := cmd.(ServerCommand)
|
||||
if !ok {
|
||||
client.ErrUnknownCommand(cmd.Code())
|
||||
return
|
||||
}
|
||||
switch srvCmd.(type) {
|
||||
case *PingCommand, *PongCommand:
|
||||
client.Touch()
|
||||
|
||||
case *QuitCommand:
|
||||
// no-op
|
||||
|
||||
default:
|
||||
client.Active()
|
||||
client.Touch()
|
||||
}
|
||||
srvCmd.HandleServer(server)
|
||||
}
|
||||
|
||||
func (server *Server) Shutdown() {
|
||||
@@ -197,14 +206,17 @@ func (s *Server) listen(addr string) {
|
||||
//
|
||||
|
||||
func (s *Server) tryRegister(c *Client) {
|
||||
if c.HasNick() && c.HasUsername() && (c.capState != CapNegotiating) {
|
||||
c.Register()
|
||||
c.RplWelcome()
|
||||
c.RplYourHost()
|
||||
c.RplCreated()
|
||||
c.RplMyInfo()
|
||||
s.MOTD(c)
|
||||
if c.registered || !c.HasNick() || !c.HasUsername() ||
|
||||
(c.capState == CapNegotiating) {
|
||||
return
|
||||
}
|
||||
|
||||
c.Register()
|
||||
c.RplWelcome()
|
||||
c.RplYourHost()
|
||||
c.RplCreated()
|
||||
c.RplMyInfo()
|
||||
s.MOTD(c)
|
||||
}
|
||||
|
||||
func (server *Server) MOTD(client *Client) {
|
||||
|
||||
Reference in New Issue
Block a user