1
Fork 0

Add command /clear.

This commit is contained in:
Juliusz Chroboczek 2020-04-30 19:13:10 +02:00
parent fd1772ed72
commit 10526d474e
3 changed files with 25 additions and 0 deletions

View File

@ -1061,6 +1061,13 @@ func handleClientMessage(c *client, m clientMessage) error {
for _, cc := range clients {
cc.write(m)
}
case "clearchat":
c.group.clearChatHistory()
m := clientMessage{Type: "clearchat"}
clients := c.group.getClients(nil)
for _, cc := range clients {
cc.write(m)
}
case "op", "unop", "present", "unpresent":
if !c.permissions.Op {
c.error(userError("not authorised"))

View File

@ -361,6 +361,12 @@ func (g *group) Range(f func(c *client) bool) {
const maxChatHistory = 20
func (g *group) clearChatHistory() {
g.mu.Lock()
defer g.mu.Unlock()
g.history = nil
}
func (g *group) addToChatHistory(id, user, value string, me bool) {
g.mu.Lock()
defer g.mu.Unlock()

View File

@ -435,6 +435,9 @@ function serverConnect() {
case 'chat':
addToChatbox(m.id, m.username, m.value, m.me);
break;
case 'clearchat':
resetChat();
break;
case 'ping':
send({
type: 'pong',
@ -750,6 +753,15 @@ function handleInput() {
case '/leave':
socket.close();
return;
case '/clear':
if(!permissions.op) {
displayError("You're not an operator");
return;
}
send({
type: 'clearchat',
});
return;
case '/op':
case '/unop':
case '/kick':