summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/APIDump/WebWorldThreads.html
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-04-19 16:15:57 +0200
committermadmaxoft <github@xoft.cz>2014-04-19 16:15:57 +0200
commit62991d46fed9b5a7b181a2ef165935784d572b06 (patch)
tree6e8c5f2f8fad4fe0f9eb15d4d91a2d1ff0048ef0 /MCServer/Plugins/APIDump/WebWorldThreads.html
parentFixed formatting, made function static. (diff)
downloadcuberite-62991d46fed9b5a7b181a2ef165935784d572b06.tar
cuberite-62991d46fed9b5a7b181a2ef165935784d572b06.tar.gz
cuberite-62991d46fed9b5a7b181a2ef165935784d572b06.tar.bz2
cuberite-62991d46fed9b5a7b181a2ef165935784d572b06.tar.lz
cuberite-62991d46fed9b5a7b181a2ef165935784d572b06.tar.xz
cuberite-62991d46fed9b5a7b181a2ef165935784d572b06.tar.zst
cuberite-62991d46fed9b5a7b181a2ef165935784d572b06.zip
Diffstat (limited to 'MCServer/Plugins/APIDump/WebWorldThreads.html')
-rw-r--r--MCServer/Plugins/APIDump/WebWorldThreads.html48
1 files changed, 24 insertions, 24 deletions
diff --git a/MCServer/Plugins/APIDump/WebWorldThreads.html b/MCServer/Plugins/APIDump/WebWorldThreads.html
index fc80a6178..ee0b172e6 100644
--- a/MCServer/Plugins/APIDump/WebWorldThreads.html
+++ b/MCServer/Plugins/APIDump/WebWorldThreads.html
@@ -39,31 +39,31 @@
<h2>Example</h2>
The Core has the facility to kick players using the web interface. It used the following code for the kicking (inside the webadmin handler):
- <pre class="prettyprint lang-lua">
- local KickPlayerName = Request.Params["players-kick"]
- local FoundPlayerCallback = function(Player)
- if (Player:GetName() == KickPlayerName) then
- Player:GetClientHandle():Kick("You were kicked from the game!")
- end
+<pre class="prettyprint lang-lua">
+local KickPlayerName = Request.Params["players-kick"]
+local FoundPlayerCallback = function(Player)
+ if (Player:GetName() == KickPlayerName) then
+ Player:GetClientHandle():Kick("You were kicked from the game!")
+ end
+end
+cRoot:Get():FindAndDoWithPlayer(KickPlayerName, FoundPlayerCallback)
+</pre>
+The cRoot:FindAndDoWithPlayer() is unsafe and could have caused a deadlock. The new solution is queue a task; but since we don't know in which world the player is, we need to queue the task to all worlds:
+<pre class="prettyprint lang-lua">
+cRoot:Get():ForEachWorld( -- For each world...
+ function(World)
+ World:QueueTask( -- ... queue a task...
+ function(a_World)
+ a_World:DoWithPlayer(KickPlayerName, -- ... to walk the playerlist...
+ function (a_Player)
+ a_Player:GetClientHandle():Kick("You were kicked from the game!") -- ... and kick the player
end
- cRoot:Get():FindAndDoWithPlayer(KickPlayerName, FoundPlayerCallback)
- </pre>
- The cRoot:FindAndDoWithPlayer() is unsafe and could have caused a deadlock. The new solution is queue a task; but since we don't know in which world the player is, we need to queue the task to all worlds:
- <pre class="prettyprint lang-lua">
- cRoot:Get():ForEachWorld( -- For each world...
- function(World)
- World:QueueTask( -- ... queue a task...
- function(a_World)
- a_World:DoWithPlayer(KickPlayerName, -- ... to walk the playerlist...
- function (a_Player)
- a_Player:GetClientHandle():Kick("You were kicked from the game!") -- ... and kick the player
- end
- )
- end
- )
- end
- )
- </pre>
+ )
+ end
+ )
+ end
+)
+</pre>
<script>
prettyPrint();
</script>