Ban command update, join/leave messages

* The /ban command doesn't require the target user to be online at the
  time of the ban.
* Update the presence messages so they will generally only go to the
  primary (first) public channel, and also to another public channel if
  the user is currently looking at one of the others.
This commit is contained in:
Noah 2023-12-16 15:10:48 -08:00
父節點 264b8f2a46
當前提交 f75ad32728
共有 3 個文件被更改,包括 19 次插入12 次删除

查看文件

@ -229,14 +229,11 @@ func (s *Server) BanCommand(words []string, sub *Subscriber) {
log.Info("Operator %s bans %s for %d hours", sub.Username, username, duration/time.Hour)
other, err := s.GetSubscriber(username)
if err != nil {
sub.ChatServer("/ban: username not found: %s", username)
} else {
// Ban them.
BanUser(username, duration)
// Add them to the ban list.
BanUser(username, duration)
// Broadcast it to everyone.
// If the target user is currently online, disconnect them and broadcast the ban to everybody.
if other, err := s.GetSubscriber(username); err == nil {
s.Broadcast(messages.Message{
Action: messages.ActionPresence,
Username: username,
@ -249,8 +246,9 @@ func (s *Server) BanCommand(words []string, sub *Subscriber) {
})
other.authenticated = false
other.Username = ""
sub.ChatServer("%s has been banned from the room for %d hours.", username, duration/time.Hour)
}
sub.ChatServer("%s has been banned from the room for %d hours.", username, duration/time.Hour)
}
// UnbanCommand handles the `/unban` operator command.

查看文件

@ -83,7 +83,6 @@ func (s *Server) OnLogin(sub *Subscriber, msg messages.Message) {
sub.SendJSON(messages.Message{
Action: messages.ActionKick,
})
s.DeleteSubscriber(sub)
return
}

查看文件

@ -1277,12 +1277,22 @@ export default {
isJoin = true;
}
// Push it to the history of all public channels (depending on user preference).
// Push it to the history of the public channels (respecting user preferences).
if ((isJoin && this.prefs.joinMessages) || (isLeave && this.prefs.exitMessages)
|| (!isJoin && !isLeave)) {
for (let channel of this.config.channels) {
// Always put them in the first public channel.
let channel = this.config.channels[0];
this.pushHistory({
channel: channel.ID,
action: msg.action,
username: msg.username,
message: msg.message,
});
// If the current user is focused on another public channel, also post it there.
if (!this.isDM && this.channel !== channel.ID) {
this.pushHistory({
channel: channel.ID,
channel: this.channel.ID,
action: msg.action,
username: msg.username,
message: msg.message,