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
parent 264b8f2a46
commit f75ad32728
3 changed files with 19 additions and 12 deletions

View File

@ -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) log.Info("Operator %s bans %s for %d hours", sub.Username, username, duration/time.Hour)
other, err := s.GetSubscriber(username) // Add them to the ban list.
if err != nil { BanUser(username, duration)
sub.ChatServer("/ban: username not found: %s", username)
} else {
// Ban them.
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{ s.Broadcast(messages.Message{
Action: messages.ActionPresence, Action: messages.ActionPresence,
Username: username, Username: username,
@ -249,8 +246,9 @@ func (s *Server) BanCommand(words []string, sub *Subscriber) {
}) })
other.authenticated = false other.authenticated = false
other.Username = "" 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. // UnbanCommand handles the `/unban` operator command.

View File

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

View File

@ -1277,12 +1277,22 @@ export default {
isJoin = true; 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) if ((isJoin && this.prefs.joinMessages) || (isLeave && this.prefs.exitMessages)
|| (!isJoin && !isLeave)) { || (!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({ this.pushHistory({
channel: channel.ID, channel: this.channel.ID,
action: msg.action, action: msg.action,
username: msg.username, username: msg.username,
message: msg.message, message: msg.message,