mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 15:34:38 +01:00
prevent object index reuse
This commit is contained in:
@@ -10,9 +10,25 @@ import (
|
|||||||
func handleMsgSysCreateObject(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgSysCreateObject(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgSysCreateObject)
|
pkt := p.(*mhfpacket.MsgSysCreateObject)
|
||||||
|
|
||||||
|
// Prevent reusing an object index
|
||||||
|
var nextID uint32
|
||||||
|
for {
|
||||||
|
exists := false
|
||||||
|
nextID = s.stage.NextObjectID()
|
||||||
|
for _, object := range s.stage.objects {
|
||||||
|
if object.id == nextID {
|
||||||
|
exists = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if exists == false {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
s.stage.Lock()
|
s.stage.Lock()
|
||||||
newObj := &Object{
|
newObj := &Object{
|
||||||
id: s.stage.NextObjectID(),
|
id: nextID,
|
||||||
ownerCharID: s.charID,
|
ownerCharID: s.charID,
|
||||||
x: pkt.X,
|
x: pkt.X,
|
||||||
y: pkt.Y,
|
y: pkt.Y,
|
||||||
|
|||||||
Reference in New Issue
Block a user