This commit is contained in:
Jeffrey Paul 2019-08-21 10:18:10 +02:00
parent 203a445deb
commit b6cb283555
3 changed files with 59 additions and 59 deletions

44
main.go
View File

@ -10,35 +10,35 @@ var Buildtime string
func main() {
// set up logging
// set up logging
log := logrus.New()
log.SetLevel(logrus.DebugLevel)
log.SetReportCaller(true)
log.Println("sircd starting up")
c := viper.New()
// default config variables
c.SetDefault("myhostname", "irc.example.com")
c.SetDefault("network", "ExampleNet")
c.SetDefault("admin", "webmaster@example.com")
c.SetDefault("version", Version)
c.SetDefault("buildtime", Buildtime)
c := viper.New()
// default config variables
c.SetDefault("myhostname", "irc.example.com")
c.SetDefault("network", "ExampleNet")
c.SetDefault("admin", "webmaster@example.com")
c.SetDefault("version", Version)
c.SetDefault("buildtime", Buildtime)
// read config file
c.SetConfigName("sircd") // name of config file (without extension)
c.AddConfigPath("/etc/sircd/") // path to look for the config file in
c.AddConfigPath("$HOME/.config/sircd") // call multiple times to add many search paths
c.AddConfigPath(".") // optionally look for config in the working directory
err := c.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
// read config file
c.SetConfigName("sircd") // name of config file (without extension)
c.AddConfigPath("/etc/sircd/") // path to look for the config file in
c.AddConfigPath("$HOME/.config/sircd") // call multiple times to add many search paths
c.AddConfigPath(".") // optionally look for config in the working directory
err := c.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
// instantiate server
s := sircd.New(c)
// give it our logger
s.SetLogger(log)
// instantiate server
s := sircd.New(c)
// give it our logger
s.SetLogger(log)
// run it
// run it
s.Start()
}

View File

@ -24,30 +24,30 @@ func (s *ircd) sayHello(c *ircClient) {
//372 motd (repeating)
//376 end motd
// change user mode (from server) :sneak!sneak@butt9q8.a.b.IP MODE sneak :+x
/*
:irc.butt.es 001 sneak :Welcome to the Buttes IRC Network sneak!sneak@1.2.3.4
:irc.butt.es 002 sneak :Your host is irc.butt.es, running version InspIRCd-3
:irc.butt.es 003 sneak :This server was created 09:33:24 Aug 05 2019
:irc.butt.es 004 sneak irc.butt.es InspIRCd-3 BHIRSWcghiorswxz ACFHIMNOPQRSTXYZbcefijklmnoprstvwz :FHIXYZbefjklovw
:irc.butt.es 005 sneak ACCEPT=30 AWAYLEN=200 CALLERID=g CASEMAPPING=ascii CHANLIMIT=#:20 CHANMODES=IXYZbew,k,FHfjl,ACMNOPQRSTcimnprstz CHANNELLEN=64 CHANTYPES=# ELIST=CMNTU ESILENCE=CcdiNnPpTtx EXCEPTS=e EXTBAN=,ACGNOQRSTUacjmprz :are supported by this server
:irc.butt.es 005 sneak HOSTLEN=64 INVEX=I KEYLEN=32 KICKLEN=255 LINELEN=512 MAXLIST=IXbew:512 MAXTARGETS=20 MODES=20 NAMESX NETWORK=Buttes NICKLEN=32 OPERLOG OVERRIDE :are supported by this server
:irc.butt.es 005 sneak PREFIX=(ov)@+ REMOVE SAFELIST SECURELIST SILENCE=32 STATUSMSG=@+ TOPICLEN=500 USERIP USERLEN=11 VBANLIST WHOX :are supported by this server
:irc.butt.es 251 sneak :There are 34 users and 33 invisible on 2 servers
:irc.butt.es 252 sneak 2 :operator(s) online
:irc.butt.es 253 sneak 1 :unknown connections
:irc.butt.es 254 sneak 33 :channels formed
:irc.butt.es 255 sneak :I have 60 clients and 1 servers
:irc.butt.es 265 sneak :Current local users: 60 Max: 65
:irc.butt.es 266 sneak :Current global users: 67 Max: 72
:irc.butt.es 375 sneak :irc.butt.es message of the day
:irc.butt.es 372 sneak :- ____ _ _ _____ _____ _____ ____
:irc.butt.es 372 sneak :- | __ )| | | |_ _|_ _| ____/ ___|
:irc.butt.es 372 sneak :- | _ \| | | | | | | | | _| \___ \
/*
:irc.butt.es 001 sneak :Welcome to the Buttes IRC Network sneak!sneak@1.2.3.4
:irc.butt.es 002 sneak :Your host is irc.butt.es, running version InspIRCd-3
:irc.butt.es 003 sneak :This server was created 09:33:24 Aug 05 2019
:irc.butt.es 004 sneak irc.butt.es InspIRCd-3 BHIRSWcghiorswxz ACFHIMNOPQRSTXYZbcefijklmnoprstvwz :FHIXYZbefjklovw
:irc.butt.es 005 sneak ACCEPT=30 AWAYLEN=200 CALLERID=g CASEMAPPING=ascii CHANLIMIT=#:20 CHANMODES=IXYZbew,k,FHfjl,ACMNOPQRSTcimnprstz CHANNELLEN=64 CHANTYPES=# ELIST=CMNTU ESILENCE=CcdiNnPpTtx EXCEPTS=e EXTBAN=,ACGNOQRSTUacjmprz :are supported by this server
:irc.butt.es 005 sneak HOSTLEN=64 INVEX=I KEYLEN=32 KICKLEN=255 LINELEN=512 MAXLIST=IXbew:512 MAXTARGETS=20 MODES=20 NAMESX NETWORK=Buttes NICKLEN=32 OPERLOG OVERRIDE :are supported by this server
:irc.butt.es 005 sneak PREFIX=(ov)@+ REMOVE SAFELIST SECURELIST SILENCE=32 STATUSMSG=@+ TOPICLEN=500 USERIP USERLEN=11 VBANLIST WHOX :are supported by this server
:irc.butt.es 251 sneak :There are 34 users and 33 invisible on 2 servers
:irc.butt.es 252 sneak 2 :operator(s) online
:irc.butt.es 253 sneak 1 :unknown connections
:irc.butt.es 254 sneak 33 :channels formed
:irc.butt.es 255 sneak :I have 60 clients and 1 servers
:irc.butt.es 265 sneak :Current local users: 60 Max: 65
:irc.butt.es 266 sneak :Current global users: 67 Max: 72
:irc.butt.es 375 sneak :irc.butt.es message of the day
:irc.butt.es 372 sneak :- ____ _ _ _____ _____ _____ ____
:irc.butt.es 372 sneak :- | __ )| | | |_ _|_ _| ____/ ___|
:irc.butt.es 372 sneak :- | _ \| | | | | | | | | _| \___ \
:irc.butt.es 376 sneak :End of message of the day.
:irc.butt.es 396 sneak butt9q8.a.b.IP :is now your displayed host
:sneak!sneak@butt9q8.a.b.IP MODE sneak :+x
*/
:irc.butt.es 376 sneak :End of message of the day.
:irc.butt.es 396 sneak butt9q8.a.b.IP :is now your displayed host
:sneak!sneak@butt9q8.a.b.IP MODE sneak :+x
*/
}
func (s *ircd) processUnknownCommand(m *ircMessage) {

View File

@ -16,7 +16,7 @@ type ircd struct {
newClients chan *ircClient
deadClients chan *ircClient
messageQueue chan *ircMessage
c *viper.Viper
c *viper.Viper
}
const (
@ -29,8 +29,8 @@ func New(config *viper.Viper) *ircd {
s := new(ircd)
s.Running = true
s.ircClients = make(map[*ircClient]bool)
s.c = config
s.serverName = s.c.GetString("myhostname")
s.c = config
s.serverName = s.c.GetString("myhostname")
return s
}
@ -43,7 +43,7 @@ func (s *ircd) SetServerName(name string) {
}
func (s *ircd) Start() {
s.log.Infof("sircd version=%s buildtime=%s starting.", s.c.GetString("version"), s.c.GetString("buildtime"))
s.log.Infof("sircd version=%s buildtime=%s starting.", s.c.GetString("version"), s.c.GetString("buildtime"))
s.newClients = make(chan *ircClient, 128)
s.deadClients = make(chan *ircClient, 128)
s.messageQueue = make(chan *ircMessage, 128)
@ -63,19 +63,19 @@ func (s *ircd) Start() {
s.newClients <- newIrcClient(conn, s.log, s.messageQueue, s)
}()
// FIXME have this do 'go s.handlemessages()' and process an input channel
// of messages from all clients in its own goroutine, and then call
// directly into the main loop here and only do client i/o in this
// goroutine
go s.processMessages()
// FIXME have this do 'go s.handlemessages()' and process an input channel
// of messages from all clients in its own goroutine, and then call
// directly into the main loop here and only do client i/o in this
// goroutine
go s.processMessages()
s.mainLoop()
}
func (s *ircd) processMessages() {
for {
message := <-s.messageQueue
s.processIRCMessage(message)
}
for {
message := <-s.messageQueue
s.processIRCMessage(message)
}
}
func (s *ircd) mainLoop() {
@ -90,7 +90,7 @@ func (s *ircd) mainLoop() {
nbyte, err := client.conn.Read(buf)
if err != nil {
//this will surface it in the deadClients channel
//reader below
//reader below
client.Kill()
break
} else {