| 1607 | } |
| 1608 | |
| 1609 | void nw_ConnectToServer(SOCKET *socket, network_address *server_addr) { |
| 1610 | |
| 1611 | // Send out a RNT_REQ_CONN packet, and wait for it to be acked. |
| 1612 | |
| 1613 | float time_sent_req = 0; |
| 1614 | float first_sent_req = 0; |
| 1615 | static reliable_header conn_header; |
| 1616 | static reliable_header ack_header; |
| 1617 | int bytesin; |
| 1618 | struct timeval timeout; |
| 1619 | *socket = INVALID_SOCKET; |
| 1620 | |
| 1621 | if (Use_DirectPlay) { |
| 1622 | // We need a session description to do this, so we don't use this function |
| 1623 | return; |
| 1624 | } |
| 1625 | |
| 1626 | conn_header.type = RNT_REQ_CONN; |
| 1627 | conn_header.seq = INTEL_SHORT((int16_t)CONNECTSEQ); |
| 1628 | conn_header.data_len = 0; |
| 1629 | |
| 1630 | timeout.tv_sec = 0; |
| 1631 | timeout.tv_usec = 0; |
| 1632 | |
| 1633 | if ((server_addr->connection_type == NP_TCP) && (!TCP_active)) { |
| 1634 | return; |
| 1635 | } |
| 1636 | |
| 1637 | Net_connect_sequence = R_NET_SEQUENCE_CONNECTING; |
| 1638 | |
| 1639 | memset(&ack_header, 0, sizeof(reliable_header)); |
| 1640 | bytesin = 0; |
| 1641 | |
| 1642 | network_address d3_rcv_addr; |
| 1643 | memset(&d3_rcv_addr, 0, sizeof(network_address)); |
| 1644 | |
| 1645 | int ret = nw_SendWithID(NWT_RELIABLE, (uint8_t *)&conn_header, RELIABLE_PACKET_HEADER_ONLY_SIZE, server_addr); |
| 1646 | if (SOCKET_ERROR == ret) { |
| 1647 | mprintf(0, "Unable to send packet in nw_ConnectToServer()! -- %d\n", WSAGetLastError()); |
| 1648 | return; |
| 1649 | } |
| 1650 | |
| 1651 | first_sent_req = timer_GetTime(); |
| 1652 | time_sent_req = timer_GetTime(); |
| 1653 | |
| 1654 | // Wait until we get a response from the server or we timeout |
| 1655 | |
| 1656 | do { |
| 1657 | nw_DoReceiveCallbacks(); |
| 1658 | // Now we wait for the connection to be made.... |
| 1659 | if (Net_connect_sequence == R_NET_SEQUENCE_CONNECTED) { |
| 1660 | *socket = Net_connect_socket_id; |
| 1661 | return; |
| 1662 | } |
| 1663 | if ((timer_GetTime() - time_sent_req) > 2) { |
| 1664 | mprintf(0, "Resending connect request.\n"); |
| 1665 | int ret = nw_SendWithID(NWT_RELIABLE, (uint8_t *)&conn_header, RELIABLE_PACKET_HEADER_ONLY_SIZE, server_addr); |
| 1666 | if (ret != SOCKET_ERROR) { |
no test coverage detected