mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
Implement command /identify.
This commit is contained in:
parent
e7e8a9b555
commit
a76f225bc0
4 changed files with 77 additions and 2 deletions
|
@ -1860,6 +1860,39 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
|||
if err != nil {
|
||||
return c.error(err)
|
||||
}
|
||||
case "identify":
|
||||
if !member("op", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
}
|
||||
d := g.GetClient(m.Dest)
|
||||
if d == nil {
|
||||
return c.error(
|
||||
group.UserError("client not found"),
|
||||
)
|
||||
}
|
||||
value := make(map[string]any)
|
||||
value["id"] = d.Id()
|
||||
if username := d.Username(); username != "" {
|
||||
value["username"] = username
|
||||
}
|
||||
if addr := d.Addr(); addr != nil {
|
||||
value["address"] = addr.String()
|
||||
}
|
||||
type warner interface {
|
||||
Warn(bool, string) error
|
||||
}
|
||||
w, ok := d.(warner)
|
||||
if ok {
|
||||
w.Warn(false, "Your IP address has been " +
|
||||
"communicated to user " +
|
||||
c.Username() + ".")
|
||||
}
|
||||
c.write(clientMessage{
|
||||
Type: "usermessage",
|
||||
Kind: "userinfo",
|
||||
Privileged: true,
|
||||
Value: value,
|
||||
})
|
||||
case "kick":
|
||||
if !member("op", c.permissions) {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
|
|
|
@ -2276,6 +2276,9 @@ function userMenu(elt) {
|
|||
items.push({label: 'Kick out', onClick: () => {
|
||||
serverConnection.userAction('kick', id);
|
||||
}});
|
||||
items.push({label: 'Identify', onClick: () => {
|
||||
serverConnection.userAction('identify', id);
|
||||
}});
|
||||
}
|
||||
}
|
||||
/** @ts-ignore */
|
||||
|
@ -2807,6 +2810,19 @@ function gotUserMessage(id, dest, username, time, privileged, kind, error, messa
|
|||
}
|
||||
localMessage(s);
|
||||
break;
|
||||
case 'userinfo':
|
||||
if(!privileged) {
|
||||
console.error(`Got unprivileged message of kind ${kind}`);
|
||||
return;
|
||||
}
|
||||
let u = message.username ?
|
||||
'username ' + message.username :
|
||||
'unknown username';
|
||||
let a = message.address ?
|
||||
'address ' + message.address :
|
||||
'unknown address';
|
||||
localMessage(`User ${message.id} has ${u} and ${a}.`);
|
||||
break;
|
||||
default:
|
||||
console.warn(`Got unknown user message ${kind}`);
|
||||
break;
|
||||
|
@ -3422,6 +3438,13 @@ commands.kick = {
|
|||
f: userCommand,
|
||||
};
|
||||
|
||||
commands.identify = {
|
||||
parameters: 'user [message]',
|
||||
description: 'identify a user',
|
||||
predicate: operatorPredicate,
|
||||
f: userCommand,
|
||||
};
|
||||
|
||||
commands.op = {
|
||||
parameters: 'user',
|
||||
description: 'give operator status',
|
||||
|
|
|
@ -524,8 +524,18 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
|
|||
log.Printf("Websocket upgrade: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var addr net.Addr
|
||||
println(r.RemoteAddr)
|
||||
tcpaddr, err := net.ResolveTCPAddr("tcp", r.RemoteAddr)
|
||||
if err != nil {
|
||||
log.Printf("ResolveTCPAddr: %v", err)
|
||||
} else {
|
||||
addr = tcpaddr
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := rtpconn.StartClient(conn)
|
||||
err := rtpconn.StartClient(conn, addr)
|
||||
if err != nil {
|
||||
log.Printf("client: %v", err)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
@ -216,7 +217,15 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
c := rtpconn.NewWhipClient(g, id, token)
|
||||
var addr net.Addr
|
||||
tcpaddr, err := net.ResolveTCPAddr("tcp", r.RemoteAddr)
|
||||
if err != nil {
|
||||
log.Printf("ResolveTCPAddr: %v", err)
|
||||
} else {
|
||||
addr = tcpaddr
|
||||
}
|
||||
|
||||
c := rtpconn.NewWhipClient(g, id, token, addr)
|
||||
|
||||
_, err = group.AddClient(g.Name(), c, creds)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue