Commit bf201703 authored by mercury233's avatar mercury233 Committed by DailyShana

update resolve host address (#1902)

* update resolve host address
* update
* update
parent 9b9ddb8d
...@@ -100,12 +100,12 @@ bool Game::Initialize() { ...@@ -100,12 +100,12 @@ bool Game::Initialize() {
lstHostList->setItemHeight(18); lstHostList->setItemHeight(18);
btnLanRefresh = env->addButton(rect<s32>(240, 325, 340, 350), wLanWindow, BUTTON_LAN_REFRESH, dataManager.GetSysString(1217)); btnLanRefresh = env->addButton(rect<s32>(240, 325, 340, 350), wLanWindow, BUTTON_LAN_REFRESH, dataManager.GetSysString(1217));
env->addStaticText(dataManager.GetSysString(1221), rect<s32>(10, 360, 220, 380), false, false, wLanWindow); env->addStaticText(dataManager.GetSysString(1221), rect<s32>(10, 360, 220, 380), false, false, wLanWindow);
ebJoinIP = env->addEditBox(gameConf.lastip, rect<s32>(110, 355, 250, 380), true, wLanWindow); ebJoinHost = env->addEditBox(gameConf.lasthost, rect<s32>(110, 355, 350, 380), true, wLanWindow);
ebJoinIP->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); ebJoinHost->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
ebJoinPort = env->addEditBox(gameConf.lastport, rect<s32>(260, 355, 320, 380), true, wLanWindow); ebJoinPort = env->addEditBox(gameConf.lastport, rect<s32>(360, 355, 420, 380), true, wLanWindow);
ebJoinPort->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); ebJoinPort->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
env->addStaticText(dataManager.GetSysString(1222), rect<s32>(10, 390, 220, 410), false, false, wLanWindow); env->addStaticText(dataManager.GetSysString(1222), rect<s32>(10, 390, 220, 410), false, false, wLanWindow);
ebJoinPass = env->addEditBox(gameConf.roompass, rect<s32>(110, 385, 320, 410), true, wLanWindow); ebJoinPass = env->addEditBox(gameConf.roompass, rect<s32>(110, 385, 420, 410), true, wLanWindow);
ebJoinPass->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); ebJoinPass->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
btnJoinHost = env->addButton(rect<s32>(460, 355, 570, 380), wLanWindow, BUTTON_JOIN_HOST, dataManager.GetSysString(1223)); btnJoinHost = env->addButton(rect<s32>(460, 355, 570, 380), wLanWindow, BUTTON_JOIN_HOST, dataManager.GetSysString(1223));
btnJoinCancel = env->addButton(rect<s32>(460, 385, 570, 410), wLanWindow, BUTTON_JOIN_CANCEL, dataManager.GetSysString(1212)); btnJoinCancel = env->addButton(rect<s32>(460, 385, 570, 410), wLanWindow, BUTTON_JOIN_CANCEL, dataManager.GetSysString(1212));
...@@ -864,7 +864,7 @@ void Game::LoadConfig() { ...@@ -864,7 +864,7 @@ void Game::LoadConfig() {
gameConf.lastdeck[0] = 0; gameConf.lastdeck[0] = 0;
gameConf.numfont[0] = 0; gameConf.numfont[0] = 0;
gameConf.textfont[0] = 0; gameConf.textfont[0] = 0;
gameConf.lastip[0] = 0; gameConf.lasthost[0] = 0;
gameConf.lastport[0] = 0; gameConf.lastport[0] = 0;
gameConf.roompass[0] = 0; gameConf.roompass[0] = 0;
//settings //settings
...@@ -902,9 +902,9 @@ void Game::LoadConfig() { ...@@ -902,9 +902,9 @@ void Game::LoadConfig() {
BufferIO::CopyWStr(wstr, gameConf.numfont, 256); BufferIO::CopyWStr(wstr, gameConf.numfont, 256);
} else if(!strcmp(strbuf, "serverport")) { } else if(!strcmp(strbuf, "serverport")) {
gameConf.serverport = atoi(valbuf); gameConf.serverport = atoi(valbuf);
} else if(!strcmp(strbuf, "lastip")) { } else if(!strcmp(strbuf, "lasthost")) {
BufferIO::DecodeUTF8(valbuf, wstr); BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.lastip, 20); BufferIO::CopyWStr(wstr, gameConf.lasthost, 20);
} else if(!strcmp(strbuf, "lastport")) { } else if(!strcmp(strbuf, "lastport")) {
BufferIO::DecodeUTF8(valbuf, wstr); BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.lastport, 20); BufferIO::CopyWStr(wstr, gameConf.lastport, 20);
...@@ -969,8 +969,8 @@ void Game::SaveConfig() { ...@@ -969,8 +969,8 @@ void Game::SaveConfig() {
BufferIO::EncodeUTF8(gameConf.numfont, linebuf); BufferIO::EncodeUTF8(gameConf.numfont, linebuf);
fprintf(fp, "numfont = %s\n", linebuf); fprintf(fp, "numfont = %s\n", linebuf);
fprintf(fp, "serverport = %d\n", gameConf.serverport); fprintf(fp, "serverport = %d\n", gameConf.serverport);
BufferIO::EncodeUTF8(gameConf.lastip, linebuf); BufferIO::EncodeUTF8(gameConf.lasthost, linebuf);
fprintf(fp, "lastip = %s\n", linebuf); fprintf(fp, "lasthost = %s\n", linebuf);
BufferIO::EncodeUTF8(gameConf.lastport, linebuf); BufferIO::EncodeUTF8(gameConf.lastport, linebuf);
fprintf(fp, "lastport = %s\n", linebuf); fprintf(fp, "lastport = %s\n", linebuf);
//settings //settings
......
...@@ -16,7 +16,7 @@ struct Config { ...@@ -16,7 +16,7 @@ struct Config {
unsigned short antialias; unsigned short antialias;
unsigned short serverport; unsigned short serverport;
unsigned char textfontsize; unsigned char textfontsize;
wchar_t lastip[20]; wchar_t lasthost[100];
wchar_t lastport[10]; wchar_t lastport[10];
wchar_t nickname[20]; wchar_t nickname[20];
wchar_t gamename[20]; wchar_t gamename[20];
...@@ -218,7 +218,7 @@ public: ...@@ -218,7 +218,7 @@ public:
irr::gui::IGUIEditBox* ebNickName; irr::gui::IGUIEditBox* ebNickName;
irr::gui::IGUIListBox* lstHostList; irr::gui::IGUIListBox* lstHostList;
irr::gui::IGUIButton* btnLanRefresh; irr::gui::IGUIButton* btnLanRefresh;
irr::gui::IGUIEditBox* ebJoinIP; irr::gui::IGUIEditBox* ebJoinHost;
irr::gui::IGUIEditBox* ebJoinPort; irr::gui::IGUIEditBox* ebJoinPort;
irr::gui::IGUIEditBox* ebJoinPass; irr::gui::IGUIEditBox* ebJoinPass;
irr::gui::IGUIButton* btnJoinHost; irr::gui::IGUIButton* btnJoinHost;
......
...@@ -31,38 +31,36 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -31,38 +31,36 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break; break;
} }
case BUTTON_JOIN_HOST: { case BUTTON_JOIN_HOST: {
#if WINVER >= 0x0600
struct addrinfo hints, *servinfo;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM; /* Datagram socket */
hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
hints.ai_protocol = 0; /* Any protocol */
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
int status;
char hostname[100];
char ip[20]; char ip[20];
const wchar_t* pstr = mainGame->ebJoinIP->getText(); const wchar_t* pstr = mainGame->ebJoinHost->getText();
BufferIO::CopyWStr(pstr, hostname, 100);
if ((status = getaddrinfo(hostname, NULL, &hints, &servinfo)) == -1) {
fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
//error handling
BufferIO::CopyWStr(pstr, ip, 16);
} else
inet_ntop(AF_INET, &(((struct sockaddr_in *)servinfo->ai_addr)->sin_addr), ip, 20);
freeaddrinfo(servinfo);
#else
char hostname[100];
char ip[20];
const wchar_t* pstr = mainGame->ebJoinIP->getText();
BufferIO::CopyWStr(pstr, hostname, 100);
BufferIO::CopyWStr(pstr, ip, 16); BufferIO::CopyWStr(pstr, ip, 16);
#endif
unsigned int remote_addr = htonl(inet_addr(ip)); unsigned int remote_addr = htonl(inet_addr(ip));
if(remote_addr == -1) {
char hostname[100];
char port[6];
BufferIO::CopyWStr(pstr, hostname, 100);
BufferIO::CopyWStr(mainGame->ebJoinPort->getText(), port, 6);
struct evutil_addrinfo hints;
struct evutil_addrinfo *answer = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = EVUTIL_AI_ADDRCONFIG;
int status=evutil_getaddrinfo(hostname, port, &hints, &answer);
if(status != 0) {
mainGame->gMutex.Lock();
mainGame->env->addMessageBox(L"", dataManager.GetSysString(1412));
mainGame->gMutex.Unlock();
break;
} else {
sockaddr_in * sin = ((struct sockaddr_in *)answer->ai_addr);
evutil_inet_ntop(AF_INET, &(sin->sin_addr), ip, 20);
remote_addr = htonl(inet_addr(ip));
}
}
unsigned int remote_port = _wtoi(mainGame->ebJoinPort->getText()); unsigned int remote_port = _wtoi(mainGame->ebJoinPort->getText());
BufferIO::CopyWStr(pstr, mainGame->gameConf.lastip, 20); BufferIO::CopyWStr(pstr, mainGame->gameConf.lasthost, 100);
BufferIO::CopyWStr(mainGame->ebJoinPort->getText(), mainGame->gameConf.lastport, 20); BufferIO::CopyWStr(mainGame->ebJoinPort->getText(), mainGame->gameConf.lastport, 20);
if(DuelClient::StartClient(remote_addr, remote_port, false)) { if(DuelClient::StartClient(remote_addr, remote_port, false)) {
mainGame->btnCreateHost->setEnabled(false); mainGame->btnCreateHost->setEnabled(false);
...@@ -297,7 +295,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -297,7 +295,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int port = DuelClient::hosts[sel].port; int port = DuelClient::hosts[sel].port;
wchar_t buf[20]; wchar_t buf[20];
myswprintf(buf, L"%d.%d.%d.%d", addr & 0xff, (addr >> 8) & 0xff, (addr >> 16) & 0xff, (addr >> 24) & 0xff); myswprintf(buf, L"%d.%d.%d.%d", addr & 0xff, (addr >> 8) & 0xff, (addr >> 16) & 0xff, (addr >> 24) & 0xff);
mainGame->ebJoinIP->setText(buf); mainGame->ebJoinHost->setText(buf);
myswprintf(buf, L"%d", port); myswprintf(buf, L"%d", port);
mainGame->ebJoinPort->setText(buf); mainGame->ebJoinPort->setText(buf);
break; break;
......
...@@ -363,6 +363,7 @@ ...@@ -363,6 +363,7 @@
!system 1409 等待更换副卡组中... !system 1409 等待更换副卡组中...
!system 1410 卡组数量与先前不符合。 !system 1410 卡组数量与先前不符合。
!system 1411 版本不匹配(%X.0%X.%X)。 !system 1411 版本不匹配(%X.0%X.%X)。
!system 1412 无法解析主机地址。
!system 1500 决斗结束。 !system 1500 决斗结束。
!system 1501 录像结束。 !system 1501 录像结束。
!system 1502 连接已断开。 !system 1502 连接已断开。
......
...@@ -9,7 +9,7 @@ lastdeck = new ...@@ -9,7 +9,7 @@ lastdeck = new
textfont = c:/windows/fonts/simsun.ttc 14 textfont = c:/windows/fonts/simsun.ttc 14
numfont = c:/windows/fonts/arialbd.ttf numfont = c:/windows/fonts/arialbd.ttf
serverport = 7911 serverport = 7911
lastip = 127.0.0.1 lasthost = 127.0.0.1
lastport = 7911 lastport = 7911
autopos = 1 autopos = 1
randompos = 0 randompos = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment