-
Notifications
You must be signed in to change notification settings - Fork 1
/
roomPlayerTemplet.go
85 lines (72 loc) · 1.79 KB
/
roomPlayerTemplet.go
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package src
import (
logtool "github.com/adimax2953/log-tool"
"github.com/pkg/errors"
)
// RoomPlayer function - keys, args[] string - return interface{} , error
func (s *MyScriptor) RoomPlayer(
keys []string,
platformID string,
gameID string,
countryCode string,
) (interface{}, error) {
args := []string{
platformID,
gameID,
countryCode,
}
res, err := s.Scriptor.ExecSha(RoomPlayerID, keys, args)
if err != nil {
logtool.LogError("RoomPlayer ExecSha Error", err)
return "", errors.WithStack(err)
}
return res, nil
}
// RoomPlayer - 查詢玩家
const (
RoomPlayerID = "RoomPlayer"
RoomPlayerTemplate = `
local DBKey = tonumber(KEYS[1])
local ProjectKey = KEYS[2]
local TagKey = KEYS[3]
local platformId = ARGV[1]
local gameId = ARGV[2]
local countrycode = ARGV[3]
local scope = table.concat({ProjectKey, platformId, gameId, countrycode}, "/")
local function log(v)
local s = ""
if type(v) == 'table' then
s = cjson.encode(v)
else
s = tostring(v)
end
redis.call("RPUSH", "log", s)
end
---@param list table
---@return string
local function joinBySlash(list)
return table.concat(list, "/")
end
---@param list table
---@return string
local function makeKey(list)
return joinBySlash({scope, unpack(list)})
end
---@param key string
---@return table
local function hgetall(key)
local entries = redis.call('HGETALL', key)
local result = {}
for i = 1, #entries, 2 do
result[entries[i]] = entries[i + 1]
end
return result
end
redis.call("SELECT", DBKey)
local playerlist = hgetall(makeKey({"playerToRoom"}))
if playerlist == false or next(playerlist) == nil then
return "[]"
end
return cjson.encode(playerlist)
`
)