mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-12 23:14:36 +01:00
prevent object index reuse
This commit is contained in:
@@ -10,9 +10,25 @@ import (
|
||||
func handleMsgSysCreateObject(s *Session, p mhfpacket.MHFPacket) {
|
||||
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()
|
||||
newObj := &Object{
|
||||
id: s.stage.NextObjectID(),
|
||||
id: nextID,
|
||||
ownerCharID: s.charID,
|
||||
x: pkt.X,
|
||||
y: pkt.Y,
|
||||
|
||||
Reference in New Issue
Block a user