-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove usages of Game.convertIpToString and mark as deprecated #4283
Conversation
data/lib/compat/compat.lua
Outdated
local result = {} | ||
for _, player in ipairs(Game.getPlayers()) do | ||
if bit.band(player:getIp(), mask) == masked then | ||
if player:getIp() == masked then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have a nil value there, variable masked
no longer exists within this function scope after your changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should look something like this right?
function getPlayersByIPAddress(ip, mask)
local players = {}
if type(ip) == "string" then
for _, player in ipairs(Game.getPlayers()) do
if player:getIp() == ip then
players[#players + 1] = player:getId()
end
end
else
if not mask then mask = 0xFFFFFFFF end
local masked = bit.band(ip, mask)
for _, player in ipairs(Game.getPlayers()) do
if bit.band(player:getIp(), mask) == masked then
players[#players + 1] = player:getId()
end
end
end
return players
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MillhioreBT Would be nice to have some function to convert string IP to numeric so mask would also be applied for strings. But anyway as there's IPv6 support (#3952) it should handle prefixes too ("subnet mask").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But actually as this is a only for compatibility it should be okay to accept numeric input only as all usecases in user scripts are numeric*.
One problem is comparison player:getIp()
(string) with ip
(number) and another is IPv6 prefix masks.
(*) But also return types of getIPByPlayerName/getIpByName
were changed from number to string so it's no longer valid that getPlayersByIPAddress
would always get numeric IP's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xmish yes, that's the reasoning. I just kept this compatibility of accepting numeric IPs for the extremely unlikely, but definitely possible scenario where someone manually blocked an IP by hardcoding it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Zbizu hope it is good enough now 😅
726fd49
to
4e10573
Compare
@omarcopires does this print just the return value of |
I'm using the code as in your branch, I didn't make any changes. |
However it's valid representation of IPv4, see: RFC4291. boost::asio::ip::address addr{boost::asio::ip::make_address("::ffff:127.0.0.1")};
boost::asio::ip::address_v6 ipv6 = addr.to_v6(); // convert to address_v6
if (ipv6.is_v4_mapped()) {
auto ipv4 = ipv6.to_v4();
std::string str = ipv4.to_string(); // 127.0.0.1
} |
As @xmish pointed out, that's a valid IP, and your server console is printing that the function has been deprecated, where it has been called (filename and line), and that you should skip calling it instead. What do you think, is this enough information for the server owner? |
I didn't realize that was the default behavior, sorry. |
Pull Request Prelude
Changes Proposed
Fixes a backwards-incompatibility introduced in #3952 where there are still some functions around that expect numeric IPs, which are not available anymore. Since most of the time the IP comes from
player:getIP()
, which returns string values, this function can be skipped, but if they come from somewhere else it will still try to convert the number.Issues addressed:
#4274