Skip to content

Commit 27c8121

Browse files
committed
Allow binding to specific IP address
closes #264 Add server bind address field to network options
1 parent a3a01ea commit 27c8121

3 files changed

Lines changed: 96 additions & 92 deletions

File tree

source/glest_game/menu/menu_state_options_network.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,14 @@ void MenuStateOptionsNetwork::mouseMove(int x, int y, const MouseState *ms) {
373373
}
374374

375375
// bool MenuStateOptionsNetwork::isInSpecialKeyCaptureEvent() {
376-
// return (activeInputLabel != NULL);
377-
// }
378-
//
379-
// void MenuStateOptionsNetwork::keyDown(SDL_KeyboardEvent key) {
380-
// if(activeInputLabel != NULL) {
381-
// keyDownEditLabel(key, &activeInputLabel);
382-
// }
383-
// }
376+
// return (activeInputLabel != NULL);
377+
//}
378+
379+
void MenuStateOptionsNetwork::keyDown(SDL_KeyboardEvent key) {
380+
if (activeInputLabel != NULL) {
381+
keyDownEditLabel(key, &activeInputLabel);
382+
}
383+
}
384384

385385
void MenuStateOptionsNetwork::keyPress(SDL_KeyboardEvent c) {
386386
// if(activeInputLabel != NULL) {
@@ -468,7 +468,14 @@ void MenuStateOptionsNetwork::saveConfig() {
468468
console.addLine(lang.getString("SettingsSaved"));
469469
}
470470

471-
void MenuStateOptionsNetwork::setActiveInputLable(GraphicLabel *newLable) {}
471+
bool MenuStateOptionsNetwork::textInput(std::string text) {
472+
if (activeInputLabel != NULL) {
473+
if (&labelServerBindIpTextInput == activeInputLabel) {
474+
return textInputEditLabel(text, &activeInputLabel);
475+
}
476+
}
477+
return false;
478+
}
472479

473480
} // namespace Game
474481
} // namespace Glest

source/shared_lib/include/platform/sdl/platform_main.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const char *GAME_ARGS[] = {"--help",
3434
"--headless-server-status",
3535
"--server-title",
3636
"--use-ports",
37-
37+
"--bind-address",
3838
"--load-scenario",
3939
"--load-mod",
4040
"--preview-map",
@@ -100,10 +100,7 @@ const char *GAME_ARGS[] = {"--help",
100100
"--steam",
101101
"--steam-debug",
102102
"--steam-reset-stats",
103-
104-
"--verbose"
105-
106-
};
103+
"--verbose"};
107104

108105
enum GAME_ARG_TYPE {
109106
GAME_ARG_HELP = 0,

source/shared_lib/sources/platform/posix/socket.cpp

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3578,86 +3578,86 @@ double Socket::getAveragePingMS(std::string host, int pingCount) {
35783578
#else
35793579
#error "Your compiler needs to support popen!"
35803580
3581-
#endif
3581+
#endif
35823582
3583-
if(debugPingOutput) printf("Running cmd [%s] got
3584-
[%s]\n",szCmd,buf);
3585-
3586-
// Linux
3587-
//softcoder@softhauslinux:~/Code/megaglest/trunk/mk/linux$
3588-
ping -c 5 soft-haus.com
3589-
//PING soft-haus.com (65.254.250.110) 56(84) bytes of
3590-
data.
3591-
//64 bytes from 65-254-250-110.yourhostingaccount.com
3592-
(65.254.250.110): icmp_seq=1 ttl=242 time=133 ms
3593-
//64 bytes from 65-254-250-110.yourhostingaccount.com
3594-
(65.254.250.110): icmp_seq=2 ttl=242 time=137 ms
3595-
//
3596-
// Windows XP
3597-
//C:\Code\megaglest\trunk\data\glest_game>ping -n 5
3598-
soft-haus.com
3599-
//
3600-
//Pinging soft-haus.com [65.254.250.110] with 32 bytes
3601-
of data:
3602-
//
3603-
//Reply from 65.254.250.110: bytes=32 time=125ms
3604-
TTL=242
3605-
//Reply from 65.254.250.110: bytes=32 time=129ms
3606-
TTL=242
3607-
3608-
std::string str = buf;
3609-
std::string::size_type ms_pos = 0;
3610-
int count = 0;
3611-
while ( ms_pos != std::string::npos) {
3612-
ms_pos = str.find("time=", ms_pos);
3613-
3614-
if(debugPingOutput) printf("count = %d ms_pos
3615-
= %d\n",count,ms_pos);
3616-
3617-
if ( ms_pos != std::string::npos ) {
3618-
++count;
3619-
3620-
int endPos = str.find(" ms", ms_pos+5
3621-
);
3622-
3623-
if(debugPingOutput) printf("count = %d
3624-
endPos = %d\n",count,endPos);
3625-
3626-
if(endPos == std::string::npos) {
3627-
endPos = str.find("ms ",
3628-
ms_pos+5 );
3629-
3630-
if(debugPingOutput)
3631-
printf("count = %d endPos = %d\n",count,endPos);
3632-
}
3633-
3634-
if(endPos != std::string::npos) {
3635-
3636-
if(count == 1) {
3637-
result = 0;
3638-
}
3639-
int startPos = ms_pos + 5;
3640-
int posLength = endPos -
3641-
startPos; if(debugPingOutput) printf("count = %d startPos = %d posLength = %d
3642-
str = [%s]\n",count,startPos,posLength,str.substr(startPos,
3643-
posLength).c_str());
3644-
3645-
float pingMS =
3646-
strToFloat(str.substr(startPos, posLength)); result += pingMS;
3647-
}
3648-
3649-
ms_pos += 5; // start next search
3650-
after this "time="
3651-
}
3652-
}
3583+
if(debugPingOutput) printf("Running cmd [%s] got
3584+
[%s]\n",szCmd,buf);
3585+
3586+
// Linux
3587+
//softcoder@softhauslinux:~/Code/megaglest/trunk/mk/linux$
3588+
ping -c 5 soft-haus.com
3589+
//PING soft-haus.com (65.254.250.110) 56(84) bytes of
3590+
data.
3591+
//64 bytes from 65-254-250-110.yourhostingaccount.com
3592+
(65.254.250.110): icmp_seq=1 ttl=242 time=133 ms
3593+
//64 bytes from 65-254-250-110.yourhostingaccount.com
3594+
(65.254.250.110): icmp_seq=2 ttl=242 time=137 ms
3595+
//
3596+
// Windows XP
3597+
//C:\Code\megaglest\trunk\data\glest_game>ping -n 5
3598+
soft-haus.com
3599+
//
3600+
//Pinging soft-haus.com [65.254.250.110] with 32 bytes
3601+
of data:
3602+
//
3603+
//Reply from 65.254.250.110: bytes=32 time=125ms
3604+
TTL=242
3605+
//Reply from 65.254.250.110: bytes=32 time=129ms
3606+
TTL=242
3607+
3608+
std::string str = buf;
3609+
std::string::size_type ms_pos = 0;
3610+
int count = 0;
3611+
while ( ms_pos != std::string::npos) {
3612+
ms_pos = str.find("time=", ms_pos);
3613+
3614+
if(debugPingOutput) printf("count = %d ms_pos
3615+
= %d\n",count,ms_pos);
3616+
3617+
if ( ms_pos != std::string::npos ) {
3618+
++count;
3619+
3620+
int endPos = str.find(" ms", ms_pos+5
3621+
);
3622+
3623+
if(debugPingOutput) printf("count = %d
3624+
endPos = %d\n",count,endPos);
3625+
3626+
if(endPos == std::string::npos) {
3627+
endPos = str.find("ms ",
3628+
ms_pos+5 );
3629+
3630+
if(debugPingOutput)
3631+
printf("count = %d endPos = %d\n",count,endPos);
3632+
}
3633+
3634+
if(endPos != std::string::npos) {
3635+
3636+
if(count == 1) {
3637+
result = 0;
3638+
}
3639+
int startPos = ms_pos + 5;
3640+
int posLength = endPos -
3641+
startPos; if(debugPingOutput) printf("count = %d startPos = %d posLength = %d
3642+
str = [%s]\n",count,startPos,posLength,str.substr(startPos,
3643+
posLength).c_str());
3644+
3645+
float pingMS =
3646+
strToFloat(str.substr(startPos, posLength)); result += pingMS;
3647+
}
3648+
3649+
ms_pos += 5; // start next search
3650+
after this "time="
3651+
}
3652+
}
36533653
3654-
if(result > 0 && count > 1) {
3655-
result /= count;
3656-
}
3657-
}
3658-
}
3659-
return result;
3660-
*/
3654+
if(result > 0 && count > 1) {
3655+
result /= count;
3656+
}
3657+
}
3658+
}
3659+
return result;
3660+
*/
36613661
}
36623662

36633663
std::string Socket::getIpAddress() {

0 commit comments

Comments
 (0)