-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
143 lines (115 loc) · 2.86 KB
/
server.lua
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Groups = {
--[[
[groupId] = {
invitationCode = "ABC"
members[memberId] = {
{role = "Owner"}
}
}
]]--
}
GroupId = 0
local function getGroups()
return Groups
end
local function createGroup()
GroupId = GroupId + 1
local groupId = tostring(GroupId)
Groups[groupId] = {
members = {}
}
return groupId
end
local function removeGroup(groupId)
if Groups[groupId] then
Groups[groupId] = nil
return true
end
return false
end
local function getGroup(groupId)
if Groups[groupId] then
return true, Groups[groupId]
end
return false
end
local function setGroupState(groupId, key, value)
local group = Groups[groupId]
if (group) then
group[key] = value
return true
end
return false
end
local function getGroupState(groupId, key)
local group = Groups[groupId]
if (group) then
return true, group[key]
end
return false
end
local function addMemberToGroup(groupId, memberId)
local group = Groups[groupId]
if (group) then
group.members[tostring(memberId)] = {}
return true
end
return false
end
local function removeMemberFromGroup(groupId, memberId)
local group = Groups[groupId]
if (group) then
group.members[tostring(memberId)] = nil
return true
end
return false
end
local function getMemberFromGroup(groupId, memberId)
local group = Groups[groupId]
if (group) then
return true, group.members[tostring(memberId)]
end
return false
end
local function getMemberState(groupId, memberId, key)
local group = Groups[groupId]
if (group) then
local member = group.members[tostring(memberId)]
if (member) then
return true, member[key]
end
end
return false
end
local function setMemberState(groupId, memberId, key, value)
local group = Groups[groupId]
if (group) then
local member = group.members[tostring(memberId)]
if (member) then
member[key] = value
return true
end
end
return false
end
local function getGroupsFromMember(memberId)
local groups = {}
for groupId, group in pairs(Groups) do
if (group.members[tostring(memberId)]) then
table.insert(groups, groupId)
end
end
return groups
end
exports("getGroups", getGroups)
exports("getGroup", getGroup)
exports("createGroup", createGroup)
exports("removeGroup", removeGroup)
exports("getGroupState", getGroupState)
exports("setGroupState", setGroupState)
exports("getMemberFromGroup", getMemberFromGroup)
exports("addMemberToGroup", addMemberToGroup)
exports("removeMemberFromGroup", removeMemberFromGroup)
exports("getMemberState", getMemberState)
exports("setMemberState", setMemberState)
exports("getGroupsFromMember", getGroupsFromMember)