mirror of
https://github.com/jech/galene.git
synced 2024-12-25 08:45:48 +01:00
Implement command /identify.
This commit is contained in:
parent
ae42f388fe
commit
f3e88a6d8b
4 changed files with 77 additions and 2 deletions
|
@ -1853,6 +1853,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"))
|
||||
|
|
|
@ -2251,6 +2251,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 */
|
||||
|
@ -2778,6 +2781,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;
|
||||
|
@ -3393,6 +3409,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',
|
||||
|
|
|
@ -538,8 +538,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