From a2db21001224e2f05ac3db988441511327f87214 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Mon, 6 Aug 2012 22:11:42 -0300 Subject: [PATCH] Create stdext net, changes to outfit and exit windows. --- modules/game_interface/styles/exitwindow.otui | 8 +-- modules/game_outfit/outfitwindow.otui | 22 ++----- src/framework/CMakeLists.txt | 2 + src/framework/luafunctions.cpp | 1 + src/framework/stdext/net.cpp | 64 +++++++++++++++++++ src/framework/stdext/net.h | 36 +++++++++++ src/framework/stdext/string.cpp | 9 +-- src/framework/stdext/string.h | 1 - 8 files changed, 113 insertions(+), 30 deletions(-) create mode 100644 src/framework/stdext/net.cpp create mode 100644 src/framework/stdext/net.h diff --git a/modules/game_interface/styles/exitwindow.otui b/modules/game_interface/styles/exitwindow.otui index 0054e3bf..14a89449 100644 --- a/modules/game_interface/styles/exitwindow.otui +++ b/modules/game_interface/styles/exitwindow.otui @@ -1,15 +1,13 @@ ExitWindow < MainWindow id: exitWindow !text: tr('Exit') - size: 550 135 + size: 570 135 Label !text: tr("If you shut down the program, your character might stay in the game.\nClick on 'Logout' to ensure that you character leaves the game properly.\nClick on 'Exit' if you want to exit the program without logging out your character.") - width: 500 - height: 45 - anchors.left: parent.left + text-auto-resize: true + anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top - margin-left: 10 margin-top: 2 Button diff --git a/modules/game_outfit/outfitwindow.otui b/modules/game_outfit/outfitwindow.otui index 14592b63..c16ec5a7 100644 --- a/modules/game_outfit/outfitwindow.otui +++ b/modules/game_outfit/outfitwindow.otui @@ -10,25 +10,20 @@ NextMountButton < NextButton PrevMountButton < PreviousButton icon-source: /images/arrow_left.png -Window +MainWindow !text: tr('Select Outfit') size: 338 375 - padding: 0 0 0 0 - - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter @onEnter: modules.game_outfit.accept() @onEscape: modules.game_outfit.destroy() // Creature Boxes - Creature id: outfitCreatureBox anchors.top: parent.top anchors.left: parent.left - margin-top: 48 - margin-left: 40 + margin-top: 15 + margin-left: 22 padding: 4 4 4 4 fixed-creature-size: true @@ -60,8 +55,8 @@ Window id: mountCreatureBox anchors.top: parent.top anchors.right: parent.right - margin-top: 48 - margin-right: 40 + margin-top: 15 + margin-right: 22 padding: 4 4 4 4 fixed-creature-size: true @@ -98,7 +93,7 @@ Window anchors.top: outfitCreatureBox.bottom anchors.left: parent.left margin-top: 6 - margin-left: 18 + margin-left: 2 enabled: false CheckBox @@ -182,8 +177,6 @@ Window anchors.left: parent.left anchors.right: parent.right anchors.bottom: next.top - margin-left: 16 - margin-right: 16 margin-bottom: 10 margin-top: 5 @@ -193,7 +186,6 @@ Window width: 64 anchors.right: next.left anchors.bottom: parent.bottom - margin-bottom: 16 margin-right: 16 @onClick: modules.game_outfit.accept() @@ -203,6 +195,4 @@ Window width: 64 anchors.right: parent.right anchors.bottom: parent.bottom - margin-bottom: 16 - margin-right: 16 @onClick: modules.game_outfit.destroy() diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 4c54c6fa..bfd5b070 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -44,6 +44,8 @@ set(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/stdext/format.h ${CMAKE_CURRENT_LIST_DIR}/stdext/math.cpp ${CMAKE_CURRENT_LIST_DIR}/stdext/math.h + ${CMAKE_CURRENT_LIST_DIR}/stdext/net.cpp + ${CMAKE_CURRENT_LIST_DIR}/stdext/net.h ${CMAKE_CURRENT_LIST_DIR}/stdext/packed_any.h ${CMAKE_CURRENT_LIST_DIR}/stdext/packed_storage.h ${CMAKE_CURRENT_LIST_DIR}/stdext/packed_vector.h diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 432b9be8..9c6acc04 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #ifdef FW_GRAPHICS #include diff --git a/src/framework/stdext/net.cpp b/src/framework/stdext/net.cpp new file mode 100644 index 00000000..ed8f0cb8 --- /dev/null +++ b/src/framework/stdext/net.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010-2012 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "net.h" +#include +#include +#include + +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); +} + +uint32 string_to_ip(const std::string& string) +{ + uint32 ip = 0; + inet_pton(AF_INET, string.c_str(), &ip); + return ip; +} + +void listSubnetAddresses(std::string subnet, std::vector& list) +{ + std::vector strVec; + boost::split(strVec, subnet, boost::is_any_of("/")); + uint32 address = inet_addr(strVec[0].c_str()); + if(address != INADDR_NONE && strVec.size() == 2) { + uint32 mask = boost::lexical_cast(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) { + list.push_back(ip); + } + } + } + } +} + + + +} diff --git a/src/framework/stdext/net.h b/src/framework/stdext/net.h new file mode 100644 index 00000000..7abc299f --- /dev/null +++ b/src/framework/stdext/net.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010-2012 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef STDEXT_NET_H +#define STDEXT_NET_H + +#include "types.h" +#include +#include + +namespace stdext { + std::string ip_to_string(uint32 ip); + uint32 string_to_ip(const std::string& string); + void listSubnetAddresses(std::string subnet, std::vector& list); +} + +#endif diff --git a/src/framework/stdext/string.cpp b/src/framework/stdext/string.cpp index eccb32e0..c4556566 100644 --- a/src/framework/stdext/string.cpp +++ b/src/framework/stdext/string.cpp @@ -66,13 +66,6 @@ uint64_t hex_to_dec(const std::string& str) return num; } -std::string ip_to_string(uint32_t ip) -{ - char host[16]; - sprintf(host, "%d.%d.%d.%d", (uint8_t)ip, (uint8_t)(ip >> 8), (uint8_t)(ip >> 16), (uint8_t)(ip >> 24)); - return std::string(host); -} - std::string utf8_to_latin1(uchar *utf8) { auto utf8CharToLatin1 = [](uchar *utf8, int *read) -> char { @@ -142,4 +135,4 @@ std::vector split(const std::string& str, const std::string& separa return splitted; } -} \ No newline at end of file +} diff --git a/src/framework/stdext/string.h b/src/framework/stdext/string.h index eb6ab4f7..07b2ef8c 100644 --- a/src/framework/stdext/string.h +++ b/src/framework/stdext/string.h @@ -42,7 +42,6 @@ std::string date_time_string(); std::string dec_to_hex(uint64_t num); uint64_t hex_to_dec(const std::string& str); -std::string ip_to_string(uint32_t ip); std::string utf8_to_latin1(uchar *utf8); void tolower(std::string& str); void toupper(std::string& str);