void NET_SV_Shutdown(void) { int i; boolean running; int start_time; if (!server_initialized) { return; } fprintf(stderr, "SV: Shutting down server...\n"); // Disconnect all clients for (i=0; i<MAXNETNODES; ++i) { if (clients[i].active) { NET_SV_DisconnectClient(&clients[i]); } } // Wait for all clients to finish disconnecting start_time = I_GetTimeMS(); running = true; while (running) { // Check if any clients are still not finished running = false; for (i=0; i<MAXNETNODES; ++i) { if (clients[i].active) { running = true; } } // Timed out? if (I_GetTimeMS() - start_time > 5000) { running = false; fprintf(stderr, "SV: Timed out waiting for clients to disconnect.\n"); } // Run the client code in case this is a loopback client. NET_CL_Run(); NET_SV_Run(); // Don't hog the CPU I_Sleep(1); } }
void NET_WaitForLaunch(void) { if (!TXT_Init()) { fprintf(stderr, "Failed to initialize GUI\n"); exit(-1); } I_InitWindowIcon(); OpenWaitDialog(); had_warning = false; while (net_waiting_for_launch) { UpdateGUI(); CheckSHA1Sums(); CheckMasterStatus(); TXT_DispatchEvents(); TXT_DrawDesktop(); NET_CL_Run(); NET_SV_Run(); if (!net_client_connected) { I_Error("Lost connection to server"); } TXT_Sleep(100); } TXT_Shutdown(); }
void NetUpdate (void) { int nowtime; int newtics; int i; // If we are running with singletics (timing a demo), this // is all done separately. if (singletics) return; #ifdef FEATURE_MULTIPLAYER // Run network subsystems NET_CL_Run(); NET_SV_Run(); #endif // check time nowtime = GetAdjustedTime() / ticdup; newtics = nowtime - lasttime; lasttime = nowtime; if (skiptics <= newtics) { newtics -= skiptics; skiptics = 0; } else { skiptics -= newtics; newtics = 0; } // build new ticcmds for console player for (i=0 ; i<newtics ; i++) { if (!BuildNewTic()) { break; } } }
static void BlockUntilStart(net_gamesettings_t *settings, netgame_startup_callback_t callback) { while (!NET_CL_GetSettings(settings)) { NET_CL_Run(); NET_SV_Run(); if (!net_client_connected) { I_Error("Lost connection to server"); } if (callback != NULL && !callback(net_client_wait_data.ready_players, net_client_wait_data.num_players)) { I_Error("Netgame startup aborted."); } I_Sleep(100); } }
void NET_CL_Disconnect(void) { int start_time; if (!net_client_connected) { return; } NET_Conn_Disconnect(&client_connection); start_time = I_GetTimeMS(); while (client_connection.state != NET_CONN_STATE_DISCONNECTED && client_connection.state != NET_CONN_STATE_DISCONNECTED_SLEEP) { if (I_GetTimeMS() - start_time > 5000) { // time out after 5 seconds client_state = NET_CONN_STATE_DISCONNECTED; fprintf(stderr, "NET_CL_Disconnect: Timeout while disconnecting from server\n"); break; } NET_CL_Run(); NET_SV_Run(); I_Sleep(1); } // Finished sending disconnect packets, etc. NET_CL_Shutdown(); }
boolean NET_CL_Connect(net_addr_t *addr) { int start_time; int last_send_time; server_addr = addr; // Are we recording a demo? Possibly set lowres turn mode if (M_CheckParm("-record") > 0 && M_CheckParm("-longtics") == 0) { lowres_turn = true; } // Read checksums of our WAD directory and dehacked information W_Checksum(net_local_wad_md5sum); DEH_Checksum(net_local_deh_md5sum); // Are we playing with the Freedoom IWAD? net_local_is_freedoom = W_CheckNumForName("FREEDOOM") >= 0; // create a new network I/O context and add just the // necessary module client_context = NET_NewContext(); // initialize module for client mode if (!addr->module->InitClient()) { return false; } NET_AddModule(client_context, addr->module); net_client_connected = true; net_client_received_wait_data = false; // Initialize connection NET_Conn_InitClient(&client_connection, addr); // try to connect start_time = I_GetTimeMS(); last_send_time = -1; while (client_connection.state == NET_CONN_STATE_CONNECTING) { int nowtime = I_GetTimeMS(); // Send a SYN packet every second. if (nowtime - last_send_time > 1000 || last_send_time < 0) { NET_CL_SendSYN(); last_send_time = nowtime; } // time out after 5 seconds if (nowtime - start_time > 5000) { break; } // run client code NET_CL_Run(); // run the server, just incase we are doing a loopback // connect NET_SV_Run(); // Don't hog the CPU I_Sleep(1); } if (client_connection.state == NET_CONN_STATE_CONNECTED) { // connected ok! client_state = CLIENT_STATE_WAITING_START; return true; } else { // failed to connect NET_CL_Shutdown(); return false; } }
boolean NET_CL_Connect(net_addr_t *addr, net_connect_data_t *data) { int start_time; int last_send_time; server_addr = addr; memcpy(net_local_wad_sha1sum, data->wad_sha1sum, sizeof(sha1_digest_t)); memcpy(net_local_deh_sha1sum, data->deh_sha1sum, sizeof(sha1_digest_t)); net_local_is_freedoom = data->is_freedoom; // create a new network I/O context and add just the // necessary module client_context = NET_NewContext(); // initialize module for client mode if (!addr->module->InitClient()) { return false; } NET_AddModule(client_context, addr->module); net_client_connected = true; net_client_received_wait_data = false; // Initialize connection NET_Conn_InitClient(&client_connection, addr); // try to connect start_time = I_GetTimeMS(); last_send_time = -1; while (client_connection.state == NET_CONN_STATE_CONNECTING) { int nowtime = I_GetTimeMS(); // Send a SYN packet every second. if (nowtime - last_send_time > 1000 || last_send_time < 0) { NET_CL_SendSYN(data); last_send_time = nowtime; } // time out after 5 seconds if (nowtime - start_time > 5000) { break; } // run client code NET_CL_Run(); // run the server, just incase we are doing a loopback // connect NET_SV_Run(); // Don't hog the CPU I_Sleep(1); } if (client_connection.state == NET_CONN_STATE_CONNECTED) { // connected ok! client_state = CLIENT_STATE_WAITING_LAUNCH; drone = data->drone; return true; } else { // failed to connect NET_CL_Shutdown(); return false; } }
// // haleyjd 20141022: [SVE] Alternate waiting on Steam clients // void NET_WaitForSteamLaunch(void) { boolean isServer = (net_SteamNodeType == NET_STEAM_SERVER); const char *strConn = "Connecting Netgame"; char numConn[64]; char pressStr[64]; char pressStr2[64]; int strConnWidth, pressStrWidth, pressStrX, numConnWidth; const char *keyActivateName = GetNameForKey(key_menu_activate); const char *keyForwardName = GetNameForKey(key_menu_forward); if(!keyActivateName) keyActivateName = "key_menu_activate"; if(!keyForwardName) keyForwardName = "key_menu_forward"; M_snprintf(pressStr, sizeof(pressStr), "(Press %s to cancel%c", keyActivateName, isServer ? ',' : ')'); if(isServer) { M_snprintf(pressStr2, sizeof(pressStr2), "%s to start now)", keyForwardName); } strConnWidth = V_BigFontStringWidth(strConn); pressStrWidth = M_StringWidth(pressStr); pressStrX = (SCREENWIDTH - pressStrWidth) / 2; expected_nodes = net_SteamNumNodes; while(net_waiting_for_launch) { event_t *ev; CheckAutoLaunch(); I_StartTic(); while((ev = D_PopEvent())) { switch(ev->type) { case ev_keydown: if(ev->data1 == key_menu_activate) I_Quit(); if(ev->data1 == key_menu_forward && isServer) StartGame(NULL, NULL); break; default: break; } } if(use3drenderer) RB_ClearBuffer(GLCB_COLOR); M_snprintf(numConn, sizeof(numConn), "%d of %d nodes connected", NumConnected(), net_SteamNumNodes); numConnWidth = M_StringWidth(numConn); V_DrawFilledBox(0, 0, SCREENWIDTH, SCREENHEIGHT, 0); V_WriteBigText(strConn, (SCREENWIDTH - strConnWidth)/2, 60); M_WriteText((SCREENWIDTH - numConnWidth)/2, 100, numConn); M_WriteText(pressStrX, 112, pressStr); if(isServer) M_WriteText(pressStrX+12, 124, pressStr2); NET_CL_Run(); NET_SV_Run(); if(!net_client_connected) I_Error("Lost connection to server"); I_FinishUpdate(); I_Sleep(100); } }