- allow using new cmake var for finding glest.ini called MG_CMAKE_INSTALL_PREFIX to solve issue #167
This commit is contained in:
parent
de8d05b882
commit
5d0f5013fd
|
@ -1,4 +1,3 @@
|
||||||
CMAKE_MINIMUM_REQUIRED( VERSION 2.8.2 )
|
|
||||||
PROJECT( MegaGlest )
|
PROJECT( MegaGlest )
|
||||||
|
|
||||||
#SET(CMAKE_VERBOSE_MAKEFILE ON)
|
#SET(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
|
@ -341,6 +340,12 @@ IF(NOT WANT_DEPRECATION_WARNINGS)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
MARK_AS_ADVANCED(WANT_DEPRECATION_WARNINGS)
|
MARK_AS_ADVANCED(WANT_DEPRECATION_WARNINGS)
|
||||||
|
|
||||||
|
#ADD_DEFINITIONS("-DMG_CMAKE_INSTALL_PREFIX='\\\"${CMAKE_INSTALL_PREFIX}\\\"'")
|
||||||
|
IF(NOT MG_CMAKE_INSTALL_PREFIX)
|
||||||
|
SET(MG_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
||||||
|
ENDIF()
|
||||||
|
MESSAGE(STATUS "**NOTE: MG_CMAKE_INSTALL_PREFIX is [${MG_CMAKE_INSTALL_PREFIX}]")
|
||||||
|
|
||||||
SET(SDL_WINDOWS_DIR_DINC "SDL-2.0.x")
|
SET(SDL_WINDOWS_DIR_DINC "SDL-2.0.x")
|
||||||
SET(SDL_VERSION_NAME "SDL2")
|
SET(SDL_VERSION_NAME "SDL2")
|
||||||
SET(SDL_VERSION_SNAME "sdl")
|
SET(SDL_VERSION_SNAME "sdl")
|
||||||
|
|
|
@ -185,7 +185,13 @@ Config::Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> f
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Look in standard linux shared paths for ini files
|
#if defined(MG_CMAKE_INSTALL_PREFIX)
|
||||||
|
if(foundPath == false) {
|
||||||
|
foundPath = tryCustomPath(cfgType, fileName, formatPath(TOSTRING(MG_CMAKE_INSTALL_PREFIX)));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Look in standard linux shared paths for ini files
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
if(foundPath == false) {
|
if(foundPath == false) {
|
||||||
foundPath = tryCustomPath(cfgType, fileName, "/usr/share/megaglest/");
|
foundPath = tryCustomPath(cfgType, fileName, "/usr/share/megaglest/");
|
||||||
|
|
|
@ -213,6 +213,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void throwException(string str);
|
static void throwException(string str);
|
||||||
|
static void getLocalIPAddressListForPlatform(std::vector<std::string> &ipList);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SafeSocketBlockToggleWrapper {
|
class SafeSocketBlockToggleWrapper {
|
||||||
|
|
|
@ -675,7 +675,6 @@ uint32 Socket::getConnectedIPAddress(string IP) {
|
||||||
|
|
||||||
std::vector<std::string> Socket::getLocalIPAddressList() {
|
std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
std::vector<std::string> ipList;
|
std::vector<std::string> ipList;
|
||||||
|
|
||||||
/* get my host name */
|
/* get my host name */
|
||||||
char myhostname[101]="";
|
char myhostname[101]="";
|
||||||
gethostname(myhostname,100);
|
gethostname(myhostname,100);
|
||||||
|
@ -684,8 +683,6 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
if(myhostent) {
|
if(myhostent) {
|
||||||
// get all host IP addresses (Except for loopback)
|
// get all host IP addresses (Except for loopback)
|
||||||
char myhostaddr[101] = "";
|
char myhostaddr[101] = "";
|
||||||
//int ipIdx = 0;
|
|
||||||
//while (myhostent->h_addr_list[ipIdx] != 0) {
|
|
||||||
for(int ipIdx = 0; myhostent->h_addr_list[ipIdx] != NULL; ++ipIdx) {
|
for(int ipIdx = 0; myhostent->h_addr_list[ipIdx] != NULL; ++ipIdx) {
|
||||||
Ip::Inet_NtoA(SockAddrToUint32((struct in_addr *)myhostent->h_addr_list[ipIdx]), myhostaddr);
|
Ip::Inet_NtoA(SockAddrToUint32((struct in_addr *)myhostent->h_addr_list[ipIdx]), myhostaddr);
|
||||||
|
|
||||||
|
@ -697,25 +694,26 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
strncmp(myhostaddr,"0.",2) != 0) {
|
strncmp(myhostaddr,"0.",2) != 0) {
|
||||||
ipList.push_back(myhostaddr);
|
ipList.push_back(myhostaddr);
|
||||||
}
|
}
|
||||||
//ipIdx++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Socket::getLocalIPAddressListForPlatform(ipList);
|
||||||
|
return ipList;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
void Socket::getLocalIPAddressListForPlatform(std::vector<std::string> &ipList) {
|
||||||
// Now check all linux network devices
|
// Now check all linux network devices
|
||||||
|
struct ifaddrs *ifap = NULL;
|
||||||
struct ifaddrs *ifap, *ifa;
|
getifaddrs(&ifap);
|
||||||
struct sockaddr_in *sa;
|
for(struct ifaddrs *ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
||||||
char *addr;
|
if (ifa->ifa_addr->sa_family == AF_INET) {
|
||||||
|
struct sockaddr_in *sa = (struct sockaddr_in *) ifa->ifa_addr;
|
||||||
getifaddrs (&ifap);
|
char *addr = inet_ntoa(sa->sin_addr);
|
||||||
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
|
||||||
if (ifa->ifa_addr->sa_family==AF_INET) {
|
|
||||||
sa = (struct sockaddr_in *) ifa->ifa_addr;
|
|
||||||
addr = inet_ntoa(sa->sin_addr);
|
|
||||||
//printf("Interface: %s\tAddress: %s\n", ifa->ifa_name, addr);
|
//printf("Interface: %s\tAddress: %s\n", ifa->ifa_name, addr);
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Interface: [%s] address: [%s]\n",__FILE__,__FUNCTION__,__LINE__,ifa->ifa_name,addr);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Interface: [%s] address: [%s]\n",__FILE__,__FUNCTION__,__LINE__,ifa->ifa_name,addr);
|
||||||
|
}
|
||||||
if(strlen(addr) > 0 &&
|
if(strlen(addr) > 0 &&
|
||||||
strncmp(addr,"127.",4) != 0 &&
|
strncmp(addr,"127.",4) != 0 &&
|
||||||
strncmp(addr,"0.",2) != 0) {
|
strncmp(addr,"0.",2) != 0) {
|
||||||
|
@ -727,7 +725,6 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
}
|
}
|
||||||
freeifaddrs(ifap);
|
freeifaddrs(ifap);
|
||||||
|
|
||||||
//std::vector<string> intfTypes;
|
|
||||||
if(Socket::intfTypes.empty()) {
|
if(Socket::intfTypes.empty()) {
|
||||||
Socket::intfTypes.push_back("lo");
|
Socket::intfTypes.push_back("lo");
|
||||||
Socket::intfTypes.push_back("eth");
|
Socket::intfTypes.push_back("eth");
|
||||||
|
@ -752,14 +749,11 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
string intfName = Socket::intfTypes[intfIdx];
|
string intfName = Socket::intfTypes[intfIdx];
|
||||||
for(int idx = 0; idx < 10; ++idx) {
|
for(int idx = 0; idx < 10; ++idx) {
|
||||||
PLATFORM_SOCKET fd = socket(AF_INET, SOCK_DGRAM, 0);
|
PLATFORM_SOCKET fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
//PLATFORM_SOCKET fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
||||||
|
|
||||||
/* I want to get an IPv4 IP address */
|
/* I want to get an IPv4 IP address */
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
struct ifreq ifrA;
|
struct ifreq ifrA;
|
||||||
ifr.ifr_addr.sa_family = AF_INET;
|
ifr.ifr_addr.sa_family = AF_INET;
|
||||||
ifrA.ifr_addr.sa_family = AF_INET;
|
ifrA.ifr_addr.sa_family = AF_INET;
|
||||||
|
|
||||||
/* I want IP address attached to "eth0" */
|
/* I want IP address attached to "eth0" */
|
||||||
char szBuf[100]="";
|
char szBuf[100]="";
|
||||||
snprintf(szBuf,100,"%s%d",intfName.c_str(),idx);
|
snprintf(szBuf,100,"%s%d",intfName.c_str(),idx);
|
||||||
|
@ -767,7 +761,6 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
//printf("In [%s::%s Line: %d] Trying NIC named [%s]\n",__FILE__,__FUNCTION__,__LINE__,szBuf);
|
//printf("In [%s::%s Line: %d] Trying NIC named [%s]\n",__FILE__,__FUNCTION__,__LINE__,szBuf);
|
||||||
|
|
||||||
int maxIfNameLength = std::min((int)strlen(szBuf),IFNAMSIZ-1);
|
int maxIfNameLength = std::min((int)strlen(szBuf),IFNAMSIZ-1);
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, szBuf, maxIfNameLength);
|
strncpy(ifr.ifr_name, szBuf, maxIfNameLength);
|
||||||
ifr.ifr_name[maxIfNameLength] = '\0';
|
ifr.ifr_name[maxIfNameLength] = '\0';
|
||||||
strncpy(ifrA.ifr_name, szBuf, maxIfNameLength);
|
strncpy(ifrA.ifr_name, szBuf, maxIfNameLength);
|
||||||
|
@ -775,16 +768,15 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
|
|
||||||
int result_ifaddrr = ioctl(fd, SIOCGIFADDR, &ifr);
|
int result_ifaddrr = ioctl(fd, SIOCGIFADDR, &ifr);
|
||||||
ioctl(fd, SIOCGIFFLAGS, &ifrA);
|
ioctl(fd, SIOCGIFFLAGS, &ifrA);
|
||||||
if(fd >= 0) close(fd);
|
if(fd >= 0) {
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
if(result_ifaddrr >= 0) {
|
if(result_ifaddrr >= 0) {
|
||||||
struct sockaddr_in *pSockAddr = (struct sockaddr_in *)&ifr.ifr_addr;
|
struct sockaddr_in *pSockAddr = (struct sockaddr_in *)&ifr.ifr_addr;
|
||||||
if(pSockAddr != NULL) {
|
if(pSockAddr != NULL) {
|
||||||
|
|
||||||
char myhostaddr[101] = "";
|
char myhostaddr[101] = "";
|
||||||
Ip::Inet_NtoA(SockAddrToUint32(&pSockAddr->sin_addr), myhostaddr);
|
Ip::Inet_NtoA(SockAddrToUint32(&pSockAddr->sin_addr), myhostaddr);
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] szBuf [%s], myhostaddr = [%s], ifr.ifr_flags = %d, ifrA.ifr_flags = %d, ifr.ifr_name [%s]\n",__FILE__,__FUNCTION__,__LINE__,szBuf,myhostaddr,ifr.ifr_flags,ifrA.ifr_flags,ifr.ifr_name);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] szBuf [%s], myhostaddr = [%s], ifr.ifr_flags = %d, ifrA.ifr_flags = %d, ifr.ifr_name [%s]\n",__FILE__,__FUNCTION__,__LINE__,szBuf,myhostaddr,ifr.ifr_flags,ifrA.ifr_flags,ifr.ifr_name);
|
||||||
|
|
||||||
// Now only include interfaces that are both UP and running
|
// Now only include interfaces that are both UP and running
|
||||||
if( (ifrA.ifr_flags & IFF_UP) == IFF_UP &&
|
if( (ifrA.ifr_flags & IFF_UP) == IFF_UP &&
|
||||||
(ifrA.ifr_flags & IFF_RUNNING) == IFF_RUNNING) {
|
(ifrA.ifr_flags & IFF_RUNNING) == IFF_RUNNING) {
|
||||||
|
@ -800,54 +792,41 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#ifdef WIN32
|
||||||
|
void Socket::getLocalIPAddressListForPlatform(std::vector<std::string> &ipList) {
|
||||||
ULONG outBufLen = 0;
|
ULONG outBufLen = 0;
|
||||||
GetAdaptersAddresses(AF_INET, 0, NULL, NULL, &outBufLen);
|
GetAdaptersAddresses(AF_INET, 0, NULL, NULL, &outBufLen);
|
||||||
|
|
||||||
PIP_ADAPTER_ADDRESSES pAddresses = (IP_ADAPTER_ADDRESSES*)malloc(outBufLen);
|
PIP_ADAPTER_ADDRESSES pAddresses = (IP_ADAPTER_ADDRESSES*)malloc(outBufLen);
|
||||||
GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST, NULL, pAddresses, &outBufLen);
|
GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST, NULL, pAddresses, &outBufLen);
|
||||||
|
|
||||||
PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
|
PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
|
||||||
PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL;
|
PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL;
|
||||||
LPSOCKADDR addr = NULL;
|
LPSOCKADDR addr = NULL;
|
||||||
pCurrAddresses = pAddresses;
|
pCurrAddresses = pAddresses;
|
||||||
char buff[100];
|
char buff[100];
|
||||||
DWORD bufflen=100;
|
DWORD bufflen=100;
|
||||||
|
|
||||||
//ifaddrinfo_ipv4_t addr_t;
|
|
||||||
while (pCurrAddresses) {
|
while (pCurrAddresses) {
|
||||||
if (pCurrAddresses->OperStatus != IfOperStatusUp) {
|
if (pCurrAddresses->OperStatus != IfOperStatusUp) {
|
||||||
pCurrAddresses = pCurrAddresses->Next;
|
pCurrAddresses = pCurrAddresses->Next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pUnicast = pCurrAddresses->FirstUnicastAddress;
|
pUnicast = pCurrAddresses->FirstUnicastAddress;
|
||||||
|
|
||||||
while (pUnicast) {
|
while (pUnicast) {
|
||||||
addr = pUnicast->Address.lpSockaddr;
|
addr = pUnicast->Address.lpSockaddr;
|
||||||
if (addr->sa_family == AF_INET && pCurrAddresses->IfType != MIB_IF_TYPE_LOOPBACK) {
|
if (addr->sa_family == AF_INET && pCurrAddresses->IfType != MIB_IF_TYPE_LOOPBACK) {
|
||||||
sockaddr_in *sa_in = (sockaddr_in *)addr;
|
sockaddr_in *sa_in = (sockaddr_in *)addr;
|
||||||
char* strIP = ::inet_ntoa((sa_in->sin_addr));
|
char *strIP = ::inet_ntoa((sa_in->sin_addr));
|
||||||
//addr_t.ifa_name = strIP;
|
//printf("\tIPV4:%s\n", strIP);
|
||||||
//addr_t.ifa_ip = sa_in->sin_addr.S_un.S_addr;
|
if (SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) {
|
||||||
//socket_inet_ntop(sa_in->sin_family, &(sa_in->sin_addr), addr_t.ip, sizeof(addr_t.ip));
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork, "In [%s::%s Line: %d] strIP [%s]\n", __FILE__, __FUNCTION__, __LINE__, strIP);
|
||||||
//if (pCurrAddresses->IfType == IF_TYPE_IEEE80211) {
|
}
|
||||||
// _addrs.insert(_addrs.begin(), addr_t);
|
if( strlen(strIP) > 0 &&
|
||||||
//}
|
strncmp(strIP,"127.",4) != 0 &&
|
||||||
//else {
|
strncmp(strIP,"0.",2) != 0) {
|
||||||
// _addrs.push_back(addr_t);
|
if(std::find(ipList.begin(),ipList.end(),strIP) == ipList.end()) {
|
||||||
//}
|
ipList.push_back(strIP);
|
||||||
//sockaddr_in *sa_in = (sockaddr_in *)pUnicast->Address.lpSockaddr;
|
|
||||||
//char *ip_address = inet_ntop(AF_INET,&(sa_in->sin_addr),buff,bufflen);
|
|
||||||
|
|
||||||
char *ip_address = strIP;
|
|
||||||
//printf("\tIPV4:%s\n", ip_address);
|
|
||||||
if (SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork, "In [%s::%s Line: %d] ip_address [%s]\n", __FILE__, __FUNCTION__, __LINE__, ip_address);
|
|
||||||
if( strlen(ip_address) > 0 &&
|
|
||||||
strncmp(ip_address,"127.",4) != 0 &&
|
|
||||||
strncmp(ip_address,"0.",2) != 0) {
|
|
||||||
if(std::find(ipList.begin(),ipList.end(),ip_address) == ipList.end()) {
|
|
||||||
ipList.push_back(ip_address);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -856,12 +835,9 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
|
||||||
pCurrAddresses = pCurrAddresses->Next;
|
pCurrAddresses = pCurrAddresses->Next;
|
||||||
}
|
}
|
||||||
free(pAddresses);
|
free(pAddresses);
|
||||||
//return !_addrs.empty();
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ipList;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Socket::isSocketValid() const {
|
bool Socket::isSocketValid() const {
|
||||||
return Socket::isSocketValid(&sock);
|
return Socket::isSocketValid(&sock);
|
||||||
|
|
Loading…
Reference in New Issue