ruleviolation.lua

main 152 lines · 4.8 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1rvreasons = {}
2rvreasons[1] = tr("1a) Offensive Name")
3rvreasons[2] = tr("1b) Invalid Name Format")
4rvreasons[3] = tr("1c) Unsuitable Name")
5rvreasons[4] = tr("1d) Name Inciting Rule Violation")
6rvreasons[5] = tr("2a) Offensive Statement")
7rvreasons[6] = tr("2b) Spamming")
8rvreasons[7] = tr("2c) Illegal Advertising")
9rvreasons[8] = tr("2d) Off-Topic Public Statement")
10rvreasons[9] = tr("2e) Non-English Public Statement")
11rvreasons[10] = tr("2f) Inciting Rule Violation")
12rvreasons[11] = tr("3a) Bug Abuse")
13rvreasons[12] = tr("3b) Game Weakness Abuse")
14rvreasons[13] = tr("3c) Using Unofficial Software to Play")
15rvreasons[14] = tr("3d) Hacking")
16rvreasons[15] = tr("3e) Multi-Clienting")
17rvreasons[16] = tr("3f) Account Trading or Sharing")
18rvreasons[17] = tr("4a) Threatening Gamemaster")
19rvreasons[18] = tr("4b) Pretending to Have Influence on Rule Enforcement")
20rvreasons[19] = tr("4c) False Report to Gamemaster")
21rvreasons[20] = tr("Destructive Behaviour")
22rvreasons[21] = tr("Excessive Unjustified Player Killing")
23
24rvactions = {}
25rvactions[0] = tr("Notation")
26rvactions[1] = tr("Name Report")
27rvactions[2] = tr("Banishment")
28rvactions[3] = tr("Name Report + Banishment")
29rvactions[4] = tr("Banishment + Final Warning")
30rvactions[5] = tr("Name Report + Banishment + Final Warning")
31rvactions[6] = tr("Statement Report")
32
33ruleViolationWindow = nil
34reasonsTextList = nil
35actionsTextList = nil
36
37function init()
38 connect(g_game, { onGMActions = loadReasons })
39
40 ruleViolationWindow = g_ui.displayUI('ruleviolation')
41 ruleViolationWindow:setVisible(false)
42
43 reasonsTextList = ruleViolationWindow:getChildById('reasonList')
44 actionsTextList = ruleViolationWindow:getChildById('actionList')
45
46 g_keyboard.bindKeyDown('Ctrl+Y', function() show() end)
47
48 if g_game.isOnline() then
49 loadReasons()
50 end
51end
52
53function terminate()
54 disconnect(g_game, { onGMActions = loadReasons })
55 g_keyboard.unbindKeyDown('Ctrl+Y')
56
57 ruleViolationWindow:destroy()
58end
59
60function hasWindowAccess()
61 return reasonsTextList:getChildCount() > 0
62end
63
64function loadReasons()
65 reasonsTextList:destroyChildren()
66 actionsTextList:destroyChildren()
67
68 local actions = g_game.getGMActions()
69 for reason, actionFlags in pairs(actions) do
70 local label = g_ui.createWidget('RVListLabel', reasonsTextList)
71 label.onFocusChange = onSelectReason
72 label:setText(rvreasons[reason])
73 label.reasonId = reason
74 label.actionFlags = actionFlags
75 end
76
77 if not hasWindowAccess() and ruleViolationWindow:isVisible() then hide() end
78end
79
80function show(target, statement)
81 if g_game.isOnline() and hasWindowAccess() then
82 if target then
83 ruleViolationWindow:getChildById('nameText'):setText(target)
84 end
85
86 if statement then
87 ruleViolationWindow:getChildById('statementText'):setText(statement)
88 end
89
90 ruleViolationWindow:show()
91 ruleViolationWindow:raise()
92 ruleViolationWindow:focus()
93 ruleViolationWindow:getChildById('commentText'):focus()
94 end
95end
96
97function hide()
98 ruleViolationWindow:hide()
99 clearForm()
100end
101
102function onSelectReason(reasonLabel, focused)
103 if reasonLabel.actionFlags and focused then
104 actionsTextList:destroyChildren()
105 for actionBaseFlag = 0, #rvactions do
106 local actionFlagString = rvactions[actionBaseFlag]
107 if bit32.band(reasonLabel.actionFlags, math.pow(2, actionBaseFlag)) > 0 then
108 local label = g_ui.createWidget('RVListLabel', actionsTextList)
109 label:setText(actionFlagString)
110 label.actionId = actionBaseFlag
111 end
112 end
113 end
114end
115
116function report()
117 local reasonLabel = reasonsTextList:getFocusedChild()
118 if not reasonLabel then
119 displayErrorBox(tr("Error"), tr("You must select a reason."))
120 return
121 end
122
123 local actionLabel = actionsTextList:getFocusedChild()
124 if not actionLabel then
125 displayErrorBox(tr("Error"), tr("You must select an action."))
126 return
127 end
128
129 local target = ruleViolationWindow:getChildById('nameText'):getText()
130 local reason = reasonLabel.reasonId
131 local action = actionLabel.actionId
132 local comment = ruleViolationWindow:getChildById('commentText'):getText()
133 local statement = ruleViolationWindow:getChildById('statementText'):getText()
134 local statementId = 0 -- TODO: message unique id ?
135 local ipBanishment = ruleViolationWindow:getChildById('ipBanCheckBox'):isChecked()
136 if action == 6 and statement == "" then
137 displayErrorBox(tr("Error"), tr("No statement has been selected."))
138 elseif comment == "" then
139 displayErrorBox(tr("Error"), tr("You must enter a comment."))
140 else
141 g_game.reportRuleViolation(target, reason, action, comment, statement, statementId, ipBanishment)
142 hide()
143 end
144end
145
146function clearForm()
147 ruleViolationWindow:getChildById('nameText'):clearText()
148 ruleViolationWindow:getChildById('commentText'):clearText()
149 ruleViolationWindow:getChildById('statementText'):clearText()
150 ruleViolationWindow:getChildById('ipBanCheckBox'):setChecked(false)
151end
152
Top