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