void NET_CL_Run(void) { net_addr_t *addr; net_packet_t *packet; if (!net_client_connected) { return; } while (NET_RecvPacket(client_context, &addr, &packet)) { // only accept packets from the server if (addr == server_addr) { NET_CL_ParsePacket(packet); } else { NET_FreeAddress(addr); } NET_FreePacket(packet); } // Run the common connection code to send any packets as needed NET_Conn_Run(&client_connection); if (client_connection.state == NET_CONN_STATE_DISCONNECTED || client_connection.state == NET_CONN_STATE_DISCONNECTED_SLEEP) { NET_CL_Disconnected(); NET_CL_Shutdown(); } net_waiting_for_launch = client_connection.state == NET_CONN_STATE_CONNECTED && client_state == CLIENT_STATE_WAITING_LAUNCH; if (client_state == CLIENT_STATE_IN_GAME) { // Possibly advance the receive window NET_CL_AdvanceWindow(); // Check if our resend requests have timed out NET_CL_CheckResends(); } }
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; } }