mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-04-18 20:40:26 +00:00
finished but untest
This commit is contained in:
24
RedisBungee-API/src/main/resources/lua/get_player_count.lua
Normal file
24
RedisBungee-API/src/main/resources/lua/get_player_count.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
local c = redis.call
|
||||
|
||||
local curTime = c("TIME")
|
||||
local time = tonumber(curTime[1])
|
||||
|
||||
local heartbeats = c("HGETALL", "heartbeats")
|
||||
local total = 0
|
||||
local key
|
||||
|
||||
for _, v in ipairs(heartbeats) do
|
||||
if not key then
|
||||
key = v
|
||||
else
|
||||
local n = tonumber(v)
|
||||
if n then
|
||||
if n + 30 >= time then
|
||||
total = total + c("SCARD", "proxy:" .. key .. ":usersOnline")
|
||||
end
|
||||
end
|
||||
key = nil
|
||||
end
|
||||
end
|
||||
|
||||
return total
|
||||
18
RedisBungee-API/src/main/resources/lua/server_to_players.lua
Normal file
18
RedisBungee-API/src/main/resources/lua/server_to_players.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
local call = redis.call
|
||||
local ipairs = ipairs
|
||||
|
||||
local serverToData = {}
|
||||
|
||||
for _, proxy in ipairs(ARGV) do
|
||||
local players = call("SMEMBERS", "proxy:" .. proxy .. ":usersOnline")
|
||||
for _, player in ipairs(players) do
|
||||
local server = call("HGET", "player:" .. player, "server")
|
||||
if server then
|
||||
local sz = #serverToData
|
||||
serverToData[sz + 1] = server
|
||||
serverToData[sz + 2] = player
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return serverToData
|
||||
Reference in New Issue
Block a user