From 3559d9ba9ba1f949328ab112446c14afd3e47015 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 27 Jun 2023 20:06:51 -0500 Subject: [PATCH] switched NPC autoincremented ID to atomic int --- core/entity/npc.go | 11 +++++++---- login/loginserver.go | 2 +- shard/shardserver.go | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/entity/npc.go b/core/entity/npc.go index b948a87..15cf4d6 100644 --- a/core/entity/npc.go +++ b/core/entity/npc.go @@ -1,6 +1,10 @@ package entity -import "github.com/CPunch/gopenfusion/core/protocol" +import ( + "sync/atomic" + + "github.com/CPunch/gopenfusion/core/protocol" +) type NPC struct { ID int @@ -12,12 +16,11 @@ type NPC struct { Chunk ChunkPosition } -var nextNPCID = 0 +var nextNPCID = &atomic.Int32{} func NewNPC(X, Y, Z, Angle int, npcType int) *NPC { - nextNPCID++ return &NPC{ - ID: nextNPCID, + ID: int(nextNPCID.Add(1)), X: X, Y: Y, Z: Z, diff --git a/login/loginserver.go b/login/loginserver.go index e7dbdb8..fda73b4 100644 --- a/login/loginserver.go +++ b/login/loginserver.go @@ -105,7 +105,7 @@ func (server *LoginServer) handlePacket(peer *protocol.CNPeer, typeID uint32, pk return err } } else { - log.Printf("[WARN] invalid packet ID: %x\n", typeID) + log.Printf("[WARN] unknown packet ID: %x\n", typeID) } return nil diff --git a/shard/shardserver.go b/shard/shardserver.go index e8a049e..0d2b5fd 100644 --- a/shard/shardserver.go +++ b/shard/shardserver.go @@ -108,7 +108,7 @@ func (server *ShardServer) handlePacket(peer *protocol.CNPeer, typeID uint32, pk return err } } else { - log.Printf("[WARN] invalid packet ID: %x\n", typeID) + log.Printf("[WARN] unknown packet ID: %x\n", typeID) } return nil