Implemented Winsock functions for UDP which I totally forgot about; Now when leaving game in any way, close sockets and Winsock stuff
This commit is contained in:
parent
47307bd25b
commit
7009221170
|
@ -3,6 +3,7 @@ D1X-Rebirth Changelog
|
|||
20100704
|
||||
--------
|
||||
main/net_udp.c: Fixed Compiler-warning on Windows
|
||||
main/net_ipx.c, main/net_udp.c: Implemented Winsock functions for UDP which I totally forgot about; Now when leaving game in any way, close sockets and Winsock stuff
|
||||
|
||||
20100701
|
||||
--------
|
||||
|
|
|
@ -169,7 +169,6 @@ void ipxdrv_close()
|
|||
// -5 if error with getting internetwork address
|
||||
int ipxdrv_init( int socket_number )
|
||||
{
|
||||
static int cleanup = 0;
|
||||
#ifdef _WIN32
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
|
@ -206,10 +205,6 @@ int ipxdrv_init( int socket_number )
|
|||
|
||||
ipxdrv_installed = 1;
|
||||
|
||||
if (!cleanup)
|
||||
atexit(ipxdrv_close);
|
||||
cleanup = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -643,9 +638,6 @@ int net_ipx_endlevel_poll( newmenu *menu, d_event *event, int *secret )
|
|||
if (choice == 0)
|
||||
{
|
||||
Players[Player_num].connected = CONNECT_DISCONNECTED;
|
||||
window_close(newmenu_get_window(menu));
|
||||
if (Game_wind)
|
||||
window_close(Game_wind); // exit game
|
||||
return 0;
|
||||
}
|
||||
if (choice > -2)
|
||||
|
@ -875,13 +867,22 @@ int net_ipx_endlevel(int *secret)
|
|||
sprintf(title, "%s\n%s", TXT_WAITING, TXT_ESC_ABORT);
|
||||
|
||||
menu = newmenu_do3(NULL, title, N_players+1, m, (int (*)( newmenu *, d_event *, void * ))net_ipx_endlevel_poll, secret,
|
||||
0, STARS_BACKGROUND);
|
||||
0, NULL);
|
||||
|
||||
// Stay here until finished
|
||||
wind = newmenu_get_window(menu);
|
||||
while (window_exists(wind))
|
||||
event_process();
|
||||
|
||||
// Player canceled between levels
|
||||
if (Players[Player_num].connected == CONNECT_DISCONNECTED)
|
||||
{
|
||||
if (Game_wind)
|
||||
window_close(Game_wind);
|
||||
show_menus();
|
||||
ipxdrv_close();
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
@ -2549,6 +2550,9 @@ int net_ipx_setup_game()
|
|||
|
||||
i = newmenu_do1( NULL, NULL, optnum, m, (int (*)( newmenu *, d_event *, void * ))net_ipx_game_param_handler, &opt, 1 );
|
||||
|
||||
if (i < 0)
|
||||
ipxdrv_close();
|
||||
|
||||
return i >= 0;
|
||||
}
|
||||
|
||||
|
@ -3242,7 +3246,7 @@ int net_ipx_join_poll( newmenu *menu, d_event *event, void *menu_text )
|
|||
case EVENT_WINDOW_CLOSE:
|
||||
d_free(menu_text);
|
||||
d_free(menus);
|
||||
|
||||
ipxdrv_close();
|
||||
if (!Game_wind)
|
||||
Network_status = NETSTAT_MENU; // they cancelled
|
||||
break;
|
||||
|
@ -3399,6 +3403,7 @@ net_ipx_level_sync(void)
|
|||
{
|
||||
Players[Player_num].connected = CONNECT_DISCONNECTED;
|
||||
net_ipx_send_endlevel_packet();
|
||||
ipxdrv_close();
|
||||
if (Game_wind)
|
||||
window_close(Game_wind);
|
||||
show_menus();
|
||||
|
@ -3530,6 +3535,7 @@ void net_ipx_leave_game()
|
|||
change_playernum_to(0);
|
||||
Game_mode = GM_GAME_OVER;
|
||||
net_ipx_flush();
|
||||
ipxdrv_close();
|
||||
}
|
||||
|
||||
void net_ipx_flush()
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
|
||||
// Prototypes
|
||||
void net_udp_init();
|
||||
void net_udp_close();
|
||||
void net_udp_request_game_info(struct _sockaddr game_addr, int lite);
|
||||
void net_udp_listen();
|
||||
int net_udp_show_game_info();
|
||||
|
@ -452,6 +453,7 @@ static int manual_join_game_handler(newmenu *menu, d_event *event, direct_join *
|
|||
|
||||
case EVENT_WINDOW_CLOSE:
|
||||
d_free(dj);
|
||||
net_udp_close();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -565,7 +567,7 @@ int net_udp_list_join_poll( newmenu *menu, d_event *event, void *menu_text )
|
|||
case EVENT_WINDOW_CLOSE:
|
||||
d_free(menu_text);
|
||||
d_free(menus);
|
||||
|
||||
net_udp_close();
|
||||
if (!Game_wind)
|
||||
Network_status = NETSTAT_MENU; // they cancelled
|
||||
break;
|
||||
|
@ -763,6 +765,17 @@ void net_udp_init()
|
|||
|
||||
int save_pnum = Player_num;
|
||||
|
||||
#ifdef _WIN32
|
||||
{
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
wVersionRequested = MAKEWORD(2, 0);
|
||||
WSACleanUp();
|
||||
if (WSAStartup( wVersionRequested, &wsaData))
|
||||
nm_messagebox( TXT_ERROR, 1, TXT_OK, "Cannot init Winsock!"); // no break here... game will fail at socket creation anyways...
|
||||
}
|
||||
#endif
|
||||
|
||||
if( UDP_Socket[0] != -1 )
|
||||
udp_close_socket(0);
|
||||
if( UDP_Socket[1] != -1 )
|
||||
|
@ -789,6 +802,18 @@ void net_udp_init()
|
|||
Netgame.PacketsPerSec = 10;
|
||||
}
|
||||
|
||||
void net_udp_close()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WSACleanUp();
|
||||
#endif
|
||||
|
||||
if( UDP_Socket[0] != -1 )
|
||||
udp_close_socket(0);
|
||||
if( UDP_Socket[1] != -1 )
|
||||
udp_close_socket(1);
|
||||
}
|
||||
|
||||
// Send PID_ENDLEVEL in regular intervals and listen for them (host also does the packets for playing clients)
|
||||
int net_udp_kmatrix_poll1( newmenu *menu, d_event *event, void *userdata )
|
||||
{
|
||||
|
@ -937,6 +962,7 @@ net_udp_disconnect_player(int playernum)
|
|||
multi_quit_game = 1;
|
||||
game_leave_menus();
|
||||
multi_reset_stuff();
|
||||
net_udp_close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2893,7 +2919,7 @@ int net_udp_setup_game()
|
|||
char srmaxnet[50];
|
||||
|
||||
net_udp_init();
|
||||
|
||||
|
||||
change_playernum_to(0);
|
||||
|
||||
for (i=0;i<MAX_PLAYERS;i++)
|
||||
|
@ -2965,6 +2991,9 @@ int net_udp_setup_game()
|
|||
|
||||
i = newmenu_do1( NULL, NULL, optnum, m, (int (*)( newmenu *, d_event *, void * ))net_udp_game_param_handler, &opt, 1 );
|
||||
|
||||
if (i < 0)
|
||||
net_udp_close();
|
||||
|
||||
return i >= 0;
|
||||
}
|
||||
|
||||
|
@ -3540,6 +3569,7 @@ net_udp_level_sync(void)
|
|||
{
|
||||
Players[Player_num].connected = CONNECT_DISCONNECTED;
|
||||
net_udp_send_endlevel_packet();
|
||||
net_udp_close();
|
||||
if (Game_wind)
|
||||
window_close(Game_wind);
|
||||
show_menus();
|
||||
|
@ -3608,11 +3638,7 @@ void net_udp_leave_game()
|
|||
change_playernum_to(0);
|
||||
Game_mode = GM_GAME_OVER;
|
||||
net_udp_flush();
|
||||
|
||||
if( UDP_Socket[0] != -1 )
|
||||
udp_close_socket(0);
|
||||
if( UDP_Socket[1] != -1 )
|
||||
udp_close_socket(1);
|
||||
net_udp_close();
|
||||
}
|
||||
|
||||
void net_udp_flush()
|
||||
|
|
Loading…
Reference in a new issue