Skip to content

Conversation

Dark-Dragon
Copy link
Contributor

banPlayer provides a lot of banning options, none of which votemanager currently supports changing for its ban votes. This commit adds the following settings to the resource:

  1. voteban_banip true/false (default: true);
  2. voteban_banusername true/false (default: false);
  3. voteban_banserial true/false (default: false);
  4. voteban_duration number in seconds (default: 3600)

Default values are the same as the default within banPlayer, except for duration, which is 1 hour instead of infinite. Note that voteban_enabled default remains false just as before.

The addition of the empty reason string when no reason is supplied via command is a workaround to avoid issues with lua's unpack() when unpacking tables containing nil entries. Here's an example: local tab = {true,false,false,nil,5} tab.cheese = "Yes" local a,b,c,d,e = unpack (tab) outputChatBox(tostring(e)) should output 5 but instead outputs nil. Without the modification tab.cheese = "Yes" it will correctly output 5. Meanwhile directly referencing it without unpack always seems to be working as intended local tab = {true,false,false,nil,5} tab.cheese = "Yes" local a,b,c,d,e = unpack (tab) outputChatBox(tostring(tab[5])) outputting 5 correctly. Unless banPlayer internally handles an empty string very differently to nil I don't see any major drawbacks with this. I can't think of any better workaround, as votemanager relies on further modifying the tables and unpack() to read from them. But maybe someone else has a good idea.

Lastly note that votekicks weren't functional before and will not be before multitheftauto/mtasa-blue#1301 gets resolved.

…e is provided

Saving nil in a table seems to have odd side effects when further adding key values to it. 

local tab = {true,false,false,nil,5} tab.cheese = "Yes" local a,b,c,d,e = unpack (tab) outputChatBox(tostring(e))

Should output 5 but instead outputs nil. If I remove the tab.cheese = "Yes"

local tab = {true,false,false,nil,5} local a,b,c,d,e = unpack (tab) outputChatBox(tostring(e))

It will correctly output 5 again. However I don't see any easy and clean way to get around it, as votemanager depends on some further modification of the tables and unpacking them later to work properly. Turning the vote reason into an empty string "" sounds like a rather small sacrifice to ensure proper functionality.
banPlayer provides a lot of banning options, none of which votemanager currently supports changing. This commit adds settings to the meta.xml for the following settings: voteban_banip true/false (default: true); voteban_banusername true/false (default: false); voteban_banserial true/false (default: false); voteban_duration number in seconds (default: 3600)
addendum to previous commit

banPlayer provides a lot of banning options, none of which votemanager currently supports changing. This commit adds settings to the meta.xml for the following settings: voteban_banip true/false (default: true); voteban_banusername true/false (default: false); voteban_banserial true/false (default: false); voteban_duration number in seconds (default: 3600)
…e is provided addendum

Removed unnecessary reason == "" from kill votes as it is never used after the initial use.
Comment on lines 51 to 54
<setting name="*voteban_banip" value="[true]"/>
<setting name="*voteban_banusername" value="[false]"/>
<setting name="*voteban_banserial" value="[false]"/>
<setting name="*voteban_duration" value="[3600]"/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding the 4 settings, the chosen setting names should be understandable intuitively

@@ -58,6 +58,12 @@ addEventHandler("onResourceStart", thisResourceRoot,
info.percentage = get(settingsGroup.."_percentage") or nil
info.timeout = get(settingsGroup.."_timeout") or nil
info.allowchange = get(settingsGroup.."_allowchange")
if name == "ban" then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not entirely sure whether this or if settingsGroup == "voteban" then would be better. I think either is fine.

@@ -426,6 +432,8 @@ function voteKick(player, reason)
local title = "Kick "..getPlayerName(player).."?"
if reason then
title = title.." ("..reason..")"
else
reason = ""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making reason an empty string if none is supplied for reasons explained in the pull request

@@ -446,14 +454,16 @@ function voteBan(player, reason)
local title = "Ban "..getPlayerName(player).."?"
if reason then
title = title.." ("..reason..")"
else
reason = ""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making reason an empty string if none is supplied for reasons explained in the pull request

end
return startPoll{
title=title,
percentage = vote.ban.percentage,
visibleTo = rootElement,
timeout = vote.ban.timeout,
allowchange = vote.ban.allowchange;
[1]={"Yes",banPlayer,player,serverConsole,reason},
[1]={"Yes",banPlayer,player,vote.ban.banip,vote.ban.banusername,vote.ban.banserial,serverConsole,reason,vote.ban.duration},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if reason was nil here it would result in the ban duration being ignored, because after unpacking the table in

optionTable[2](unpack(optionTable,3))
it would get lost

@jlillis
Copy link
Contributor

jlillis commented Nov 2, 2020

This PR appears to work as intended, but I think it would be better for players to be banned by serial by default. Thoughts?

@xLive
Copy link
Member

xLive commented Nov 2, 2020

and I think IP ban should be disabled by default?

I know some people play with each other and have the same IP
I don't think it's fair to ban all of them? and serial is enough

@Dark-Dragon
Copy link
Contributor Author

I chose the default to be consistent with the default of banPlayer as well as how voteban previously banned players, but if everyone agrees that serial is the way to go I see no problem with changing it to reflect that.

@jlillis jlillis merged commit a438ce5 into multitheftauto:master Nov 10, 2020
@qaisjp qaisjp added this to the 1.6 milestone Nov 24, 2020
@patrikjuvonen patrikjuvonen modified the milestones: 1.6, 1.5.9 Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants