← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~tino79/widelands/using_sdl_net_init into lp:widelands

 

Tino has proposed merging lp:~tino79/widelands/using_sdl_net_init into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~tino79/widelands/using_sdl_net_init/+merge/141519

On windows you'll have to init winsock before any network communication.
This branch does this via SDL_Net_Init() instead with win32 specific code. 
Also instead of doing this twice in the code (MP-game menu & dedicated mode) i am calling init() and quit() in widelands main con- and destructor.

Please test on linux/unix/macosx that i did not break anything.
-- 
https://code.launchpad.net/~tino79/widelands/using_sdl_net_init/+merge/141519
Your team Widelands Developers is requested to review the proposed merge of lp:~tino79/widelands/using_sdl_net_init into lp:widelands.
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc	2012-12-30 21:09:13 +0000
+++ src/wlapplication.cc	2012-12-31 12:38:24 +0000
@@ -304,6 +304,10 @@
 	if (TTF_Init() == -1)
 		throw wexception
 			("True Type library did not initialize: %s\n", TTF_GetError());
+
+	if (SDLNet_Init() == -1)
+		throw wexception("SDLNet_Init failed: %s\n", SDLNet_GetError());
+
 	UI::g_fh = new UI::Font_Handler();
 	UI::g_fh1 = UI::create_fonthandler(*g_gr, g_fs);
 
@@ -330,6 +334,8 @@
 	delete UI::g_fh1;
 	UI::g_fh1 = 0;
 
+	SDLNet_Quit();
+
 	TTF_Quit(); // TODO not here
 
 	assert(g_fs);
@@ -366,7 +372,7 @@
 		} catch (Widelands::game_data_error const & e) {
 			log("Game not loaded: Game data error: %s\n", e.what());
 		} catch (std::exception const & e) {
-			log("Fata exception: %s\n", e.what());
+			log("Fatal exception: %s\n", e.what());
 			emergency_save(game);
 			throw;
 		}
@@ -377,19 +383,12 @@
 		} catch (Widelands::game_data_error const & e) {
 			log("Scenario not started: Game data error: %s\n", e.what());
 		} catch (std::exception const & e) {
-			log("Fata exception: %s\n", e.what());
+			log("Fatal exception: %s\n", e.what());
 			emergency_save(game);
 			throw;
 		}
 	} else if (m_game_type == INTERNET) {
 		Widelands::Game game;
-		#ifdef WIN32
-			//  The Winsock2 library needs to get called through WSAStartup, to initiate
-			//  the use of the Winsock DLL by Widelands.
-			WSADATA wsaData;
-			if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
-				throw wexception("initialization of Wsock2-library failed");
-		#endif // WIN32
 		try {
 			// disable sound completely
 			g_sound_handler.m_nosound = true;
@@ -454,10 +453,6 @@
 
 				InternetGaming::ref().logout();
 			}
-		#ifdef WIN32
-			// Clean up winsock2 data
-			WSACleanup();
-		#endif
 		} catch (std::exception const & e) {
 			log("Fatal exception: %s\n", e.what());
 			emergency_save(game);
@@ -1081,7 +1076,6 @@
 			<< endl;
 
 	init_graphics(0, 0, 0, false, false);
-
 	SDL_QuitSubSystem
 		(SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_CDROM|SDL_INIT_JOYSTICK);
 
@@ -1653,14 +1647,6 @@
  */
 void WLApplication::mainmenu_multiplayer()
 {
-#ifdef WIN32
-	//  The Winsock2 library needs to get called through WSAStartup, to initiate
-	//  the use of the Winsock DLL by Widelands.
-	WSADATA wsaData;
-	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
-		throw wexception("initialization of Wsock2-library failed");
-#endif // WIN32
-
 	int32_t menu_result = Fullscreen_Menu_NetSetupLAN::JOINGAME; // dummy init;
 	for (;;) { // stay in menu until player clicks "back" button
 		bool internet = false;
@@ -1734,10 +1720,6 @@
 			}
 		}
 	}
-#ifdef WIN32
-	// Clean up winsock2 data
-	WSACleanup();
-#endif
 }
 
 void WLApplication::mainmenu_editor()


Follow ups