Browse Source

Reset sky on redirect - properly

master
HimbeerserverDE 1 year ago
parent
commit
52cb29e369
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
  1. 40
      init.go
  2. 5
      peer.go
  3. 6
      proto.go
  4. 2
      redirect.go

40
init.go

@ -26,8 +26,8 @@ func Init(p, p2 *Peer, ignMedia, noAccessDenied bool, fin chan *Peer) {
data[1] = uint8(ToServerInit)
data[2] = uint8(0x1c)
binary.BigEndian.PutUint16(data[3:5], uint16(0x0000))
binary.BigEndian.PutUint16(data[5:7], uint16(0x0025))
binary.BigEndian.PutUint16(data[7:9], uint16(0x0027))
binary.BigEndian.PutUint16(data[5:7], uint16(ProtoMin))
binary.BigEndian.PutUint16(data[7:9], uint16(ProtoLatest))
binary.BigEndian.PutUint16(data[9:11], uint16(len(p.Username())))
copy(data[11:], []byte(p.Username()))
@ -56,6 +56,8 @@ func Init(p, p2 *Peer, ignMedia, noAccessDenied bool, fin chan *Peer) {
switch cmd := binary.BigEndian.Uint16(pkt.Data[0:2]); cmd {
case ToClientHello:
p2.protoVer = binary.BigEndian.Uint16(pkt.Data[5:7])
if pkt.Data[10]&AuthMechSRP > 0 {
// Compute and send SRP_BYTES_A
_, _, err := srp.NewClient([]byte(strings.ToLower(p.Username())), passPhrase)
@ -232,13 +234,45 @@ func Init(p, p2 *Peer, ignMedia, noAccessDenied bool, fin chan *Peer) {
// Process data
p2.username = string(pkt.Data[11:])
// Find protocol version
cliProtoMin := binary.BigEndian.Uint16(pkt.Data[5:7])
cliProtoMax := binary.BigEndian.Uint16(pkt.Data[7:9])
var protov uint16
if cliProtoMax >= ProtoMin || cliProtoMin <= ProtoLatest {
if cliProtoMax > ProtoLatest {
protov = ProtoLatest
} else {
protov = ProtoLatest
}
}
p2.protoVer = protov
if protov < ProtoMin || protov > ProtoLatest {
data := []byte{
0, ToClientAccessDenied,
AccessDeniedWrongVersion, 0, 0, 0, 0,
}
ack, err := p2.Send(rudp.Pkt{Data: data})
if err != nil {
log.Print(err)
}
<-ack
p2.SendDisco(0, true)
p2.Close()
fin <- p
return
}
// Send HELLO
data := make([]byte, 13+len(p2.Username()))
data[0] = uint8(0x00)
data[1] = uint8(ToClientHello)
data[2] = uint8(0x1c)
binary.BigEndian.PutUint16(data[3:5], uint16(0x0000))
binary.BigEndian.PutUint16(data[5:7], uint16(0x0027))
binary.BigEndian.PutUint16(data[5:7], uint16(protov))
// Check if user is banned
banned, bname, err := p2.IsBanned()

5
peer.go

@ -17,6 +17,8 @@ var connectedPeersMu sync.RWMutex
type Peer struct {
*rudp.Peer
protoVer uint16
username string
srp_s []byte
srp_A []byte
@ -52,6 +54,9 @@ type Peer struct {
inv *mt.Inv
}
// ProtoVer returns the protocol version of the Peer
func (p *Peer) ProtoVer() uint16 { return p.protoVer }
// Username returns the username of the Peer
// if it isn't a server
func (p *Peer) Username() string { return p.username }

6
proto.go

@ -0,0 +1,6 @@
package main
const (
ProtoMin = 0x0025
ProtoLatest = 0x0027
)

2
redirect.go

@ -209,6 +209,8 @@ func (p *Peer) Redirect(newsrv string) error {
return err
}
log.Print(p.ProtoVer())
// Reset sky
switch p.ProtoVer() {
case 39:

Loading…
Cancel
Save