Commit 10526d47 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Add command /clear.

parent fd1772ed
......@@ -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"))
......
......@@ -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()
......
......@@ -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':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment