Cache player inventories
parent
c98750c6bb
commit
3bac5f0e6b
13
command.go
13
command.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/subtle"
|
||||
"encoding/binary"
|
||||
"log"
|
||||
|
@ -187,6 +188,18 @@ func processPktCommand(src, dst *Peer, pkt *rudp.Pkt) bool {
|
|||
id = dst.currentPlayerCao
|
||||
}
|
||||
binary.BigEndian.PutUint16(pkt.Data[107+texturelen:109+texturelen], id)
|
||||
case ToClientInventory:
|
||||
if err := dst.Inv().Deserialize(bytes.NewReader(pkt.Data[2:])); err != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
// updateHandCapabs(dst)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
dst.Inv().Serialize(buf)
|
||||
pkt.Data = append(pkt.Data[:2], buf.Bytes()...)
|
||||
|
||||
return false
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.16
|
|||
|
||||
require (
|
||||
github.com/HimbeerserverDE/srp v0.0.0-20210220165753-1b954ef7b017
|
||||
github.com/anon55555/mt v0.0.0-20210220163106-8b61ee961a91
|
||||
github.com/anon55555/mt v0.0.0-20210223182933-4896d8f03c3f
|
||||
github.com/mattn/go-sqlite3 v1.14.6
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,7 +1,7 @@
|
|||
github.com/HimbeerserverDE/srp v0.0.0-20210220165753-1b954ef7b017 h1:0vIYOfwAd3MtssbclXpCuUHVVV+5VOH0H1ld9+zSxgM=
|
||||
github.com/HimbeerserverDE/srp v0.0.0-20210220165753-1b954ef7b017/go.mod h1:pxNH8S2nh4n2DWE0ToX5GnnDr/uEAuaAhJsCpkDLIWw=
|
||||
github.com/anon55555/mt v0.0.0-20210220163106-8b61ee961a91 h1:R4TxnNwEQ/APFfAjnb99WyOzwWE9URNeDcZ34gVO4qE=
|
||||
github.com/anon55555/mt v0.0.0-20210220163106-8b61ee961a91/go.mod h1:jH4ER+ahjl7H6TczzK+q4V9sXY++U2Geh6/vt3r4Xvs=
|
||||
github.com/anon55555/mt v0.0.0-20210223182933-4896d8f03c3f h1:Q8Q0Xt6aAudgGcxYxcwGLsgVjfnO+w9xyScldMbzAw4=
|
||||
github.com/anon55555/mt v0.0.0-20210223182933-4896d8f03c3f/go.mod h1:jH4ER+ahjl7H6TczzK+q4V9sXY++U2Geh6/vt3r4Xvs=
|
||||
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
|
||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/anon55555/mt"
|
||||
"github.com/anon55555/mt/rudp"
|
||||
)
|
||||
|
||||
|
@ -51,6 +52,7 @@ func (l *Listener) Accept() (*Peer, error) {
|
|||
clt.modChs = make(map[string]bool)
|
||||
clt.huds = make(map[uint32]bool)
|
||||
clt.sounds = make(map[int32]bool)
|
||||
clt.inv = &mt.Inv{}
|
||||
|
||||
maxPeers, ok := GetConfKey("player_limit").(int)
|
||||
if !ok {
|
||||
|
|
6
peer.go
6
peer.go
|
@ -6,6 +6,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/anon55555/mt"
|
||||
"github.com/anon55555/mt/rudp"
|
||||
)
|
||||
|
||||
|
@ -46,6 +47,8 @@ type Peer struct {
|
|||
huds map[uint32]bool
|
||||
|
||||
sounds map[int32]bool
|
||||
|
||||
inv *mt.Inv
|
||||
}
|
||||
|
||||
// Username returns the username of the Peer
|
||||
|
@ -115,6 +118,9 @@ func (p *Peer) SetUseRpc(useRpc bool) {
|
|||
p.useRpc = useRpc
|
||||
}
|
||||
|
||||
// Inv returns the inventory of the Peer
|
||||
func (p *Peer) Inv() *mt.Inv { return p.inv }
|
||||
|
||||
// Connect connects to the server on conn
|
||||
// and closes conn when the Peer disconnects
|
||||
func Connect(conn net.PacketConn, addr net.Addr) (*Peer, error) {
|
||||
|
|
Loading…
Reference in New Issue