mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-23 03:02:48 +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
|
// send quit messages to friends
|
||||||
if !beingResumed {
|
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 {
|
for friend := range friends {
|
||||||
if client.quitMessage == "" {
|
if client.quitMessage == "" {
|
||||||
client.quitMessage = "Exited"
|
client.quitMessage = "Exited"
|
||||||
|
@ -1293,21 +1293,13 @@ func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
|
|||||||
// LUSERS [<mask> [<server>]]
|
// LUSERS [<mask> [<server>]]
|
||||||
func lusersHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
func lusersHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
|
||||||
//TODO(vegax87) Fix network statistics and additional parameters
|
//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
|
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))
|
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 may now be unthrottled by the fakelag system
|
||||||
client.resetFakelag()
|
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] {
|
if client.flags[change.Mode] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if change.Mode == modes.Invisible {
|
||||||
|
client.server.stats.ChangeInvisible(1)
|
||||||
|
}
|
||||||
|
|
||||||
client.flags[change.Mode] = true
|
client.flags[change.Mode] = true
|
||||||
applied = append(applied, change)
|
applied = append(applied, change)
|
||||||
|
|
||||||
@ -44,6 +49,15 @@ func (client *Client) applyUserModeChanges(force bool, changes modes.ModeChanges
|
|||||||
if !client.flags[change.Mode] {
|
if !client.flags[change.Mode] {
|
||||||
continue
|
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)
|
delete(client.flags, change.Mode)
|
||||||
applied = append(applied, change)
|
applied = append(applied, change)
|
||||||
}
|
}
|
||||||
|
@ -131,6 +131,7 @@ type Server struct {
|
|||||||
stsEnabled bool
|
stsEnabled bool
|
||||||
webirc []webircConfig
|
webirc []webircConfig
|
||||||
whoWas *WhoWasList
|
whoWas *WhoWasList
|
||||||
|
stats *Stats
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -164,6 +165,7 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
|
|||||||
signals: make(chan os.Signal, len(ServerExitSignals)),
|
signals: make(chan os.Signal, len(ServerExitSignals)),
|
||||||
snomasks: NewSnoManager(),
|
snomasks: NewSnoManager(),
|
||||||
whoWas: NewWhoWasList(config.Limits.WhowasEntries),
|
whoWas: NewWhoWasList(config.Limits.WhowasEntries),
|
||||||
|
stats: NewStats(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := server.applyConfig(config, true); err != nil {
|
if err := server.applyConfig(config, true); err != nil {
|
||||||
@ -472,6 +474,9 @@ func (server *Server) tryRegister(c *Client) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// count new user in statistics
|
||||||
|
server.stats.ChangeTotal(1)
|
||||||
|
|
||||||
// continue registration
|
// continue registration
|
||||||
server.logger.Debug("localconnect", fmt.Sprintf("Client registered [%s] [u:%s] [r:%s]", c.nick, c.username, c.realname))
|
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))
|
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