mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
Stats for LUSERS logic now seperated, fixed params in LUSERS
This commit is contained in:
parent
19bb6d5a46
commit
744ad2ce0b
@ -724,6 +724,15 @@ func (client *Client) destroy(beingResumed bool) {
|
||||
|
||||
// send quit messages to friends
|
||||
if !beingResumed {
|
||||
client.server.stats.ChangeTotal(-1)
|
||||
if client.HasMode(modes.Invisible) {
|
||||
client.server.stats.ChangeInvisible(-1)
|
||||
}
|
||||
|
||||
if client.HasMode(modes.Operator) || client.HasMode(modes.LocalOperator) {
|
||||
client.server.stats.ChangeOperators(-1)
|
||||
}
|
||||
|
||||
for friend := range friends {
|
||||
if client.quitMessage == "" {
|
||||
client.quitMessage = "Exited"
|
||||
|
@ -1293,21 +1293,13 @@ func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
|
||||
// LUSERS [<mask> [<server>]]
|
||||
func lusersHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
||||
//TODO(vegax87) Fix network statistics and additional parameters
|
||||
var totalcount, invisiblecount, opercount int
|
||||
totalCount, invisibleCount, operCount := server.stats.GetStats()
|
||||
|
||||
rb.Add(nil, server.name, RPL_LUSERCLIENT, client.nick, fmt.Sprintf(client.t("There are %[1]d users and %[2]d invisible on %[3]d server(s)"), totalCount-invisibleCount, invisibleCount, 1))
|
||||
rb.Add(nil, server.name, RPL_LUSEROP, client.nick, strconv.Itoa(operCount), client.t("IRC Operators online"))
|
||||
rb.Add(nil, server.name, RPL_LUSERCHANNELS, client.nick, strconv.Itoa(server.channels.Len()), client.t("channels formed"))
|
||||
rb.Add(nil, server.name, RPL_LUSERME, client.nick, fmt.Sprintf(client.t("I have %[1]d clients and %[2]d servers"), totalCount, 1))
|
||||
|
||||
for _, onlineusers := range server.clients.AllClients() {
|
||||
totalcount++
|
||||
if onlineusers.flags[modes.Invisible] {
|
||||
invisiblecount++
|
||||
}
|
||||
if onlineusers.flags[modes.Operator] {
|
||||
opercount++
|
||||
}
|
||||
}
|
||||
rb.Add(nil, server.name, RPL_LUSERCLIENT, client.nick, fmt.Sprintf(client.t("There are %[1]d users and %[2]d invisible on %[3]d server(s)"), totalcount - invisiblecount, invisiblecount, 1))
|
||||
rb.Add(nil, server.name, RPL_LUSEROP, client.nick, fmt.Sprintf(client.t("%d IRC Operators online"), opercount))
|
||||
rb.Add(nil, server.name, RPL_LUSERCHANNELS, client.nick, fmt.Sprintf(client.t("%d channels formed"), server.channels.Len()))
|
||||
rb.Add(nil, server.name, RPL_LUSERME, client.nick, fmt.Sprintf(client.t("I have %[1]d clients and %[2]d servers"), totalcount, 1))
|
||||
return false
|
||||
}
|
||||
|
||||
@ -1792,6 +1784,9 @@ func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
|
||||
|
||||
server.snomasks.Send(sno.LocalOpers, fmt.Sprintf(ircfmt.Unescape("Client opered up $c[grey][$r%s$c[grey], $r%s$c[grey]]"), client.nickMaskString, client.operName))
|
||||
|
||||
// increase oper count
|
||||
server.stats.ChangeOperators(1)
|
||||
|
||||
// client may now be unthrottled by the fakelag system
|
||||
client.resetFakelag()
|
||||
|
||||
|
14
irc/modes.go
14
irc/modes.go
@ -37,6 +37,11 @@ func (client *Client) applyUserModeChanges(force bool, changes modes.ModeChanges
|
||||
if client.flags[change.Mode] {
|
||||
continue
|
||||
}
|
||||
|
||||
if change.Mode == modes.Invisible {
|
||||
client.server.stats.ChangeInvisible(1)
|
||||
}
|
||||
|
||||
client.flags[change.Mode] = true
|
||||
applied = append(applied, change)
|
||||
|
||||
@ -44,6 +49,15 @@ func (client *Client) applyUserModeChanges(force bool, changes modes.ModeChanges
|
||||
if !client.flags[change.Mode] {
|
||||
continue
|
||||
}
|
||||
|
||||
if change.Mode == modes.Invisible {
|
||||
client.server.stats.ChangeInvisible(-1)
|
||||
}
|
||||
|
||||
if change.Mode == modes.Operator || change.Mode == modes.LocalOperator {
|
||||
client.server.stats.ChangeOperators(-1)
|
||||
}
|
||||
|
||||
delete(client.flags, change.Mode)
|
||||
applied = append(applied, change)
|
||||
}
|
||||
|
@ -131,6 +131,7 @@ type Server struct {
|
||||
stsEnabled bool
|
||||
webirc []webircConfig
|
||||
whoWas *WhoWasList
|
||||
stats *Stats
|
||||
}
|
||||
|
||||
var (
|
||||
@ -164,6 +165,7 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
|
||||
signals: make(chan os.Signal, len(ServerExitSignals)),
|
||||
snomasks: NewSnoManager(),
|
||||
whoWas: NewWhoWasList(config.Limits.WhowasEntries),
|
||||
stats: NewStats(),
|
||||
}
|
||||
|
||||
if err := server.applyConfig(config, true); err != nil {
|
||||
@ -472,6 +474,9 @@ func (server *Server) tryRegister(c *Client) {
|
||||
return
|
||||
}
|
||||
|
||||
// count new user in statistics
|
||||
server.stats.ChangeTotal(1)
|
||||
|
||||
// continue registration
|
||||
server.logger.Debug("localconnect", fmt.Sprintf("Client registered [%s] [u:%s] [r:%s]", c.nick, c.username, c.realname))
|
||||
server.snomasks.Send(sno.LocalConnects, fmt.Sprintf(ircfmt.Unescape("Client registered $c[grey][$r%s$c[grey]] [u:$r%s$c[grey]] [h:$r%s$c[grey]] [r:$r%s$c[grey]]"), c.nick, c.username, c.rawHostname, c.realname))
|
||||
|
57
irc/stats.go
Normal file
57
irc/stats.go
Normal file
@ -0,0 +1,57 @@
|
||||
package irc
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Stats contains the numbers of total, invisible and operators on the server
|
||||
type Stats struct {
|
||||
sync.RWMutex
|
||||
|
||||
Total int
|
||||
Invisible int
|
||||
Operators int
|
||||
}
|
||||
|
||||
// NewStats creates a new instance of Stats
|
||||
func NewStats() *Stats {
|
||||
serverStats := &Stats{
|
||||
Total: 0,
|
||||
Invisible: 0,
|
||||
Operators: 0,
|
||||
}
|
||||
|
||||
return serverStats
|
||||
}
|
||||
|
||||
// ChangeTotal increments the total user count on server
|
||||
func (s *Stats) ChangeTotal(i int) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
s.Total += i
|
||||
}
|
||||
|
||||
// ChangeInvisible increments the invisible count
|
||||
func (s *Stats) ChangeInvisible(i int) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
s.Invisible += i
|
||||
}
|
||||
|
||||
// ChangeOperators increases the operator count
|
||||
func (s *Stats) ChangeOperators(i int) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
s.Operators += i
|
||||
}
|
||||
|
||||
// GetStats retrives total, invisible and oper count
|
||||
func (s *Stats) GetStats() (int, int, int) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
return s.Total, s.Invisible, s.Operators
|
||||
}
|
Loading…
Reference in New Issue
Block a user