forked from cuberite/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb_players.lua
More file actions
66 lines (53 loc) · 1.98 KB
/
web_players.lua
File metadata and controls
66 lines (53 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function HandleRequest_Players ( Request )
-- Define the content variable.
local Content = ""
-- If a player needed to be kicked, kick them.
if (Request.Params["players-kick"] ~= nil) then
local KickPlayerName = Request.Params["players-kick"]
cRoot:Get():ForEachWorld( -- For each world...
function(World)
World:QueueTask( -- ... queue a task...
function(a_World)
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
)
end
-- Count all the players in the root.
local playerCount = 0
local playerCountCallback = function ( Player )
playerCount = playerCount + 1
end
cRoot:Get():ForEachPlayer( playerCountCallback )
Content = Content .. "<p>Total Players: " .. playerCount .. "</p>"
-- Count the numbers of players per-world.
local perWorldPlayersCallback = function ( World )
-- Name the world:
Content = Content .. "<h4>" .. cWebAdmin:GetHTMLEscapedString( World:GetName() ) .. "</h4>"
-- Create a table for players to sit in.
Content = Content .. "<table>"
-- Go through the players in the world and add them to the table.
local PlayerNum = 0
local AddPlayerToTable = function( Player )
PlayerNum = PlayerNum + 1
Content = Content .. "<tr>"
Content = Content .. "<td style='width: 10px;'>" .. PlayerNum .. ".</td>"
Content = Content .. "<td>" .. cWebAdmin:GetHTMLEscapedString( Player:GetName() ) .. "</td>"
Content = Content .. "<td><a href='?players-kick=" .. cWebAdmin:GetHTMLEscapedString( Player:GetName() ) .. "'>Kick</a></td>"
Content = Content .. "</tr>"
end
World:ForEachPlayer( AddPlayerToTable )
if PlayerNum == 0 then
Content = Content .. "<tr><td>None</td></tr>"
end
Content = Content .. "</table>"
Content = Content .. "<br>"
end
cRoot:Get():ForEachWorld( perWorldPlayersCallback )
return Content
end