Create stdext net, changes to outfit and exit windows.

This commit is contained in:
Henrique Santiago
2012-08-06 22:11:42 -03:00
parent 54f4e2b801
commit a2db210012
8 changed files with 113 additions and 30 deletions

View File

@@ -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

View File

@@ -32,6 +32,7 @@
#include <framework/util/crypt.h>
#include <framework/core/resourcemanager.h>
#include <framework/graphics/texturemanager.h>
#include <framework/stdext/net.h>
#ifdef FW_GRAPHICS
#include <framework/graphics/graphics.h>

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/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 <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <arpa/inet.h>
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<uint32>& list)
{
std::vector<std::string> 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<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) {
list.push_back(ip);
}
}
}
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/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 <string>
#include <vector>
namespace stdext {
std::string ip_to_string(uint32 ip);
uint32 string_to_ip(const std::string& string);
void listSubnetAddresses(std::string subnet, std::vector<uint32>& list);
}
#endif

View File

@@ -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<std::string> split(const std::string& str, const std::string& separa
return splitted;
}
}
}

View File

@@ -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);