()
| 644 | } |
| 645 | |
| 646 | func (w *World) UpdateStats() { |
| 647 | s := web.GetStats() |
| 648 | s.Reset() |
| 649 | |
| 650 | c := configs.GetNetworkConfig() |
| 651 | |
| 652 | for _, u := range users.GetAllActiveUsers() { |
| 653 | info := u.GetOnlineInfo() |
| 654 | s.OnlineUsers = append(s.OnlineUsers, info) |
| 655 | switch info.ConnType { |
| 656 | case "websocket": |
| 657 | s.WebSocketConnections++ |
| 658 | case "ssh": |
| 659 | s.SSHConnections++ |
| 660 | default: |
| 661 | s.TelnetConnections++ |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | sort.Slice(s.OnlineUsers, func(i, j int) bool { |
| 666 | if s.OnlineUsers[i].Role == users.RoleAdmin { |
| 667 | return true |
| 668 | } |
| 669 | if s.OnlineUsers[j].Role == users.RoleAdmin { |
| 670 | return false |
| 671 | } |
| 672 | return s.OnlineUsers[i].OnlineTime > s.OnlineUsers[j].OnlineTime |
| 673 | }) |
| 674 | |
| 675 | for _, t := range c.TelnetPort { |
| 676 | p, _ := strconv.Atoi(t) |
| 677 | if p > 0 { |
| 678 | s.TelnetPorts = append(s.TelnetPorts, p) |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | s.WebSocketPort = int(c.HttpPort) |
| 683 | s.SSHPort = int(c.SSHPort) |
| 684 | |
| 685 | web.UpdateStats(s) |
| 686 | } |
| 687 | |
| 688 | // Force disconnect a user (Makes them linkdead) |
| 689 | func (w *World) Kick(userId int, reason string) { |
no test coverage detected