From 29cd8586227c871fe58d6d1615e99a9cc5fe5f32 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Mon, 14 Jan 2013 16:41:52 +0100 Subject: [PATCH] Fixed race condition in API addHandler() --- src/classes/PocketMinecraftServer.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/classes/PocketMinecraftServer.php b/src/classes/PocketMinecraftServer.php index c43fef0c..ea2ae9b2 100644 --- a/src/classes/PocketMinecraftServer.php +++ b/src/classes/PocketMinecraftServer.php @@ -191,10 +191,11 @@ class PocketMinecraftServer{ return false; } $priority = (int) $priority; - $this->handlers[$this->handCnt] = $callable; - $this->query("INSERT INTO handlers (ID, name, priority) VALUES (".$this->handCnt.", '".str_replace("'", "\\'", $event)."', ".$priority.");"); - console("[INTERNAL] New handler ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)." to special event ".$event." (ID ".$this->handCnt.")", true, true, 3); - return $this->handCnt++; + $hnid = $this->handCnt++; + $this->handlers[$hnid] = $callable; + $this->query("INSERT INTO handlers (ID, name, priority) VALUES (".$hnid.", '".str_replace("'", "\\'", $event)."', ".$priority.");"); + console("[INTERNAL] New handler ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)." to special event ".$event." (ID ".$hnid.")", true, true, 3); + return $hnid; } public function handle($event, &$data){