Remove CAOs when client is redirected
parent
46e23132b5
commit
94d7a353ff
|
@ -0,0 +1,51 @@
|
|||
package multiserver
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
var aoIDs map[PeerID]map[uint16]bool
|
||||
|
||||
func InitAOMap() {
|
||||
aoIDs = make(map[PeerID]map[uint16]bool)
|
||||
}
|
||||
|
||||
func processAORmAdd(p *Peer, data []byte) {
|
||||
countRm := binary.BigEndian.Uint16(data[2:4])
|
||||
aoRm := make([]uint16, countRm)
|
||||
aoRmI := 0
|
||||
for i := uint16(0); i < countRm; i += 2 {
|
||||
aoRm[aoRmI] = binary.BigEndian.Uint16(data[4 + i:6 + i])
|
||||
|
||||
aoRmI++
|
||||
}
|
||||
|
||||
countAdd := binary.BigEndian.Uint16(data[4 + countRm * 2:6 + countRm * 2])
|
||||
aoAdd := make([]uint16, countAdd)
|
||||
aoAddI := 0
|
||||
j := uint32(0)
|
||||
for i := uint32(0); i < uint32(countAdd); i++ {
|
||||
si := j + 6 + uint32(countRm) * 2
|
||||
initDataLen := binary.BigEndian.Uint32(data[3 + si:7 + si])
|
||||
|
||||
if data[2 + si] == uint8(0x65) && !p.initAoReceived {
|
||||
p.initAoReceived = true
|
||||
j += 7 + initDataLen
|
||||
continue
|
||||
}
|
||||
|
||||
aoAdd[aoAddI] = binary.BigEndian.Uint16(data[si:2 + si])
|
||||
|
||||
aoAddI++
|
||||
|
||||
j += 7 + initDataLen
|
||||
}
|
||||
|
||||
for i := range aoAdd {
|
||||
if aoAdd[i] != 0 {
|
||||
aoIDs[p.ID()][aoAdd[i]] = true
|
||||
}
|
||||
}
|
||||
|
||||
for i := range aoRm {
|
||||
aoIDs[p.ID()][aoRm[i]] = false
|
||||
}
|
||||
}
|
|
@ -3,3 +3,5 @@ player_limit: -1
|
|||
servers:
|
||||
lobby:
|
||||
address: "127.0.0.1:30000"
|
||||
map2:
|
||||
address: "127.0.0.1:30001"
|
||||
|
|
|
@ -9,6 +9,8 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
multiserver.InitAOMap()
|
||||
|
||||
multiserver.LoadConfig()
|
||||
|
||||
multiserver.InitLua()
|
||||
|
|
33
peer.go
33
peer.go
|
@ -73,6 +73,8 @@ type Peer struct {
|
|||
forward bool
|
||||
|
||||
srv *Peer
|
||||
|
||||
initAoReceived bool
|
||||
}
|
||||
|
||||
type pktchan struct {
|
||||
|
@ -212,6 +214,10 @@ func newPeer(conn net.PacketConn, addr net.Addr, id, idOfPeer PeerID) *Peer {
|
|||
|
||||
p.forward = true
|
||||
|
||||
if !p.IsSrv() {
|
||||
aoIDs[p.ID()] = make(map[uint16]bool)
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
|
@ -742,6 +748,33 @@ func Init(p, p2 *Peer, ignMedia bool, errs chan<- error, fin chan struct{}) {
|
|||
// Redirect closes the connection to srv1
|
||||
// and redirects the client to srv2
|
||||
func (p *Peer) Redirect(newsrv string) error {
|
||||
// Remove active objects
|
||||
len := 0
|
||||
for _ = range aoIDs[p.ID()] {
|
||||
len++
|
||||
}
|
||||
|
||||
data := make([]byte, 6 + len * 2)
|
||||
data[0] = uint8(0x00)
|
||||
data[1] = uint8(0x31)
|
||||
binary.BigEndian.PutUint16(data[2:4], uint16(len))
|
||||
i := 4
|
||||
for ao := range aoIDs[p.ID()] {
|
||||
binary.BigEndian.PutUint16(data[i:2 + i], ao)
|
||||
|
||||
i += 2
|
||||
}
|
||||
binary.BigEndian.PutUint16(data[i:2 + i], uint16(0))
|
||||
|
||||
ack, err := p.Send(Pkt{Data: data, ChNo: 0, Unrel: false})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
<-ack
|
||||
|
||||
aoIDs[p.ID()] = make(map[uint16]bool)
|
||||
|
||||
// Redirect
|
||||
straddr := GetConfKey("servers:" + newsrv + ":address")
|
||||
if straddr == nil || fmt.Sprintf("%T", straddr) != "string" {
|
||||
return ErrServerDoesNotExist
|
||||
|
|
5
proxy.go
5
proxy.go
|
@ -31,11 +31,16 @@ func Proxy(src, dst *Peer) {
|
|||
}
|
||||
|
||||
// Process
|
||||
// Chat message
|
||||
if pkt.Data[0] == uint8(0x00) && pkt.Data[1] == uint8(0x32) && !src.IsSrv() {
|
||||
if processChatMessage(src.ID(), pkt.Data) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
// Active object remove add
|
||||
if pkt.Data[0] == uint8(0x00) && pkt.Data[1] == uint8(0x31) && src.IsSrv() {
|
||||
processAORmAdd(dst, pkt.Data)
|
||||
}
|
||||
|
||||
// Forward
|
||||
if _, err := dst.Send(pkt); err != nil {
|
||||
|
|
Loading…
Reference in New Issue