Fix messagebox width, use boost in stdext net
This commit is contained in:
parent
466d8e8820
commit
93fdd2e326
|
@ -35,7 +35,7 @@ function UIMessageBox.display(title, message, flags)
|
|||
connect(messagebox, { onEscape = function(self) self:cancel() end })
|
||||
end
|
||||
|
||||
messagebox:setWidth(messageLabel:getWidth() + messagebox:getPaddingLeft() + messagebox:getPaddingRight())
|
||||
messagebox:setWidth(math.max(messageLabel:getWidth(), messagebox:getTextSize().width) + messagebox:getPaddingLeft() + messagebox:getPaddingRight())
|
||||
messagebox:setHeight(messageLabel:getHeight() + messagebox:getPaddingTop() + messagebox:getPaddingBottom() + buttonRight:getHeight() + 10)
|
||||
|
||||
--messagebox:lock()
|
||||
|
|
|
@ -63,7 +63,7 @@ void Application::registerLuaFunctions()
|
|||
g_lua.bindGlobalFunction("sizetostring", [](const Size& v) { return stdext::to_string(v); });
|
||||
g_lua.bindGlobalFunction("iptostring", [](int v) { return stdext::ip_to_string(v); });
|
||||
g_lua.bindGlobalFunction("stringtoip", [](const std::string& v) { return stdext::string_to_ip(v); });
|
||||
g_lua.bindGlobalFunction("listSubnetAddresses", [](const std::string& v) { return stdext::listSubnetAddresses(v); });
|
||||
g_lua.bindGlobalFunction("listSubnetAddresses", [](uint32 a, uint8 b) { return stdext::listSubnetAddresses(a, b); });
|
||||
|
||||
// Application
|
||||
g_lua.registerSingletonClass("g_app");
|
||||
|
|
|
@ -23,41 +23,37 @@
|
|||
#include "net.h"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <arpa/inet.h>
|
||||
#include <boost/asio/ip/address_v4.hpp>
|
||||
|
||||
namespace stdext {
|
||||
|
||||
std::string ip_to_string(uint32 ip)
|
||||
{
|
||||
char host[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &ip, host, INET_ADDRSTRLEN);
|
||||
return std::string(host);
|
||||
ip = boost::asio::detail::socket_ops::network_to_host_long(ip);
|
||||
boost::asio::ip::address_v4 address_v4 = boost::asio::ip::address_v4(ip);
|
||||
return address_v4.to_string();
|
||||
}
|
||||
|
||||
uint32 string_to_ip(const std::string& string)
|
||||
{
|
||||
uint32 ip = 0;
|
||||
inet_pton(AF_INET, string.c_str(), &ip);
|
||||
return ip;
|
||||
boost::asio::ip::address_v4 address_v4 = boost::asio::ip::address_v4::from_string(string);
|
||||
return boost::asio::detail::socket_ops::host_to_network_long(address_v4.to_ulong());
|
||||
}
|
||||
|
||||
std::vector<uint32> listSubnetAddresses(const std::string& subnet)
|
||||
std::vector<uint32> listSubnetAddresses(uint32 address, uint8 mask)
|
||||
{
|
||||
std::vector<uint32> list;
|
||||
std::vector<std::string> strVec;
|
||||
boost::split(strVec, subnet, boost::is_any_of("/"));
|
||||
uint32 address = string_to_ip(strVec[0]);
|
||||
if(address != INADDR_NONE && strVec.size() == 2) {
|
||||
uint32 mask = boost::lexical_cast<uint32>(strVec[1]);
|
||||
if(mask <= 32) {
|
||||
for(uint32 i=0; i <= (0xFFFFFFFF >> mask); i++) {
|
||||
uint32 ip = htonl((htonl(address) & (~(0xFFFFFFFF >> mask))) | i);
|
||||
if((ip >> 24) != 0 && (ip >> 24) != 0xFF) {
|
||||
if(mask < 32) {
|
||||
uint32 bitmask = (0xFFFFFFFF >> mask);
|
||||
for(uint32 i = 0; i <= bitmask; i++) {
|
||||
uint32 ip = boost::asio::detail::socket_ops::host_to_network_long((boost::asio::detail::socket_ops::network_to_host_long(address) & (~bitmask)) | i);
|
||||
if((ip >> 24) != 0 && (ip >> 24) != 0xFF)
|
||||
list.push_back(ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
list.push_back(address);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
namespace stdext {
|
||||
std::string ip_to_string(uint32 ip);
|
||||
uint32 string_to_ip(const std::string& string);
|
||||
std::vector<uint32> listSubnetAddresses(const std::string& subnet);
|
||||
std::vector<uint32> listSubnetAddresses(uint32 address, uint8 mask);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -25,9 +25,6 @@
|
|||
#include <framework/luaengine/luainterface.h>
|
||||
#include <otclient/otclient.h>
|
||||
|
||||
#include "otclient/item.h"
|
||||
#include "otclient/tile.h"
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
std::vector<std::string> args(argv, argv + argc);
|
||||
|
|
Loading…
Reference in New Issue