widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #00091
[Merge] lp:~jarih/widelands/fix-windows-gzz-host into lp:widelands
Tino has proposed merging lp:~jarih/widelands/fix-windows-gzz-host into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
#554290 Windows client cannot open a new multiplayer room in the online lobby
https://bugs.launchpad.net/bugs/554290
Allows also players on win32 to host multiplayer games through the ggz lobby.
--
https://code.launchpad.net/~jarih/widelands/fix-windows-gzz-host/+merge/26378
Your team Widelands Developers is requested to review the proposed merge of lp:~jarih/widelands/fix-windows-gzz-host into lp:widelands.
=== modified file 'src/network/network_ggz.cc'
--- src/network/network_ggz.cc 2010-03-27 13:43:00 +0000
+++ src/network/network_ggz.cc 2010-05-30 09:44:35 +0000
@@ -116,12 +116,20 @@
FD_ZERO(&fdset);
FD_SET(fd, &fdset);
while (ggzmod_get_state(mod) != GGZMOD_STATE_PLAYING) {
+ // just to prevent busy looping.
+ // TODO: mod fd may not remain constant during processing in linux.
select(fd + 1, &fdset, 0, 0, &timeout);
- ggzmod_dispatch(mod);
+ // make sure all incoming data is processed before continuing
+ while (data_is_pending(ggzmod_get_fd(mod)))
+ if (ggzmod_dispatch(mod) < 0) break;
//log("GGZ ## timeout!\n");
if (usedcore())
datacore();
}
+ // Hosting a ggz game on windows requires more processing.
+ ggzmod_dispatch(mod);
+ if (usedcore())
+ datacore();
return true;
}
@@ -286,6 +294,8 @@
ggzserver = 0;
ggzcore_destroy();
ggzcore_ready = false;
+ channelfd = -1;
+ gamefd = -1;
}
@@ -376,6 +386,34 @@
#pragma GCC diagnostic error "-Wold-style-cast"
+/* Check for incoming data */
+/// \note The FD_SET macro from glibc uses old-style cast. We can not fix this
+/// ourselves, so we temporarily turn the error into a warning. It is turned
+/// back into an error after this function.
+#pragma GCC diagnostic warning "-Wold-style-cast"
+int NetGGZ::data_is_pending(int fd)
+{
+ if (fd >= 0) {
+ fd_set read_fd_set;
+ int result;
+ struct timeval tv;
+
+ FD_ZERO(&read_fd_set);
+ FD_SET(fd, &read_fd_set);
+
+ tv.tv_sec = tv.tv_usec = 0;
+
+ result =
+ select(fd + 1, &read_fd_set, NULL, NULL, &tv);
+ if (result > 0) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+#pragma GCC diagnostic error "-Wold-style-cast"
+
//\FIXME: mallformed updatedata, if the user is in a room and too many seats
// are open (~ > 4).
/// checks for events on server, room and game
@@ -388,7 +426,8 @@
if (ggzcore_server_data_is_pending(ggzserver))
ggzcore_server_read_data(ggzserver, ggzcore_server_get_fd(ggzserver));
- if (channelfd != -1)
+ if (channelfd != -1 &&
+ data_is_pending(ggzcore_server_get_channel(ggzserver)))
ggzcore_server_read_data
(ggzserver, ggzcore_server_get_channel(ggzserver));
=== modified file 'src/network/network_ggz.h'
--- src/network/network_ggz.h 2010-03-25 17:40:52 +0000
+++ src/network/network_ggz.h 2010-05-30 09:44:35 +0000
@@ -185,6 +185,8 @@
void write_tablelist();
void write_userlist();
+ int data_is_pending(int fd);
+
bool use_ggz;
int32_t m_fd;
int32_t channelfd;
=== modified file 'src/ui_fsmenu/netsetup_ggz.cc'
--- src/ui_fsmenu/netsetup_ggz.cc 2010-04-24 18:35:24 +0000
+++ src/ui_fsmenu/netsetup_ggz.cc 2010-05-30 09:44:35 +0000
@@ -156,10 +156,6 @@
// try to connect to the metaserver
if (!NetGGZ::ref().usedcore())
connectToMetaserver();
-#ifdef WIN32
- //bug in ggz on windows - not able to open a server
- hostgame.set_enabled(false);
-#endif
}
@@ -210,10 +206,7 @@
{
// List and button cleanup
opengames.clear();
-#ifndef WIN32
- //bug in ggz on windows - not able to open a server
hostgame.set_enabled(true);
-#endif
joingame.set_enabled(false);
std::string localservername = servername.text();
localservername += " (" + build_id() + ")";
@@ -360,10 +353,6 @@
/// called when the servername was changed
void Fullscreen_Menu_NetSetupGGZ::change_servername()
{
-#ifdef WIN32
- //bug in ggz on windows - not able to open a server
- return;
-#endif
// Allow user to enter a servername manually
hostgame.set_enabled(true);