| 2323 | } |
| 2324 | |
| 2325 | int nw_SendWithID(uint8_t id, uint8_t *data, int len, network_address *who_to) { |
| 2326 | uint8_t packet_data[1500]; |
| 2327 | int send_this_packet = 1; |
| 2328 | SOCKET send_sock; |
| 2329 | SOCKADDR_IN sock_addr; // UDP/TCP socket structure |
| 2330 | |
| 2331 | int ret, send_len; |
| 2332 | uint8_t iaddr[6], *send_data; |
| 2333 | int16_t port; |
| 2334 | fd_set wfds; |
| 2335 | |
| 2336 | ASSERT(data); |
| 2337 | ASSERT(len); |
| 2338 | ASSERT(who_to); |
| 2339 | |
| 2340 | timeval timeout = {0, 0}; |
| 2341 | |
| 2342 | packet_data[0] = id; |
| 2343 | memcpy(packet_data + 1, data, len); |
| 2344 | len++; // Account for the added byte |
| 2345 | |
| 2346 | // if (NetDebugFile) |
| 2347 | // cfprintf (NetDebugFile,"nw_SendWithID packet of id=%d type %d at %f |
| 2348 | // seconds.\n",id,data[0],timer_GetTime()); |
| 2349 | |
| 2350 | // mprintf(0,"Sending packet for id %d.\n",id); |
| 2351 | #ifdef WIN32 |
| 2352 | if (Use_DirectPlay) |
| 2353 | return dp_DirectPlaySend(who_to, (uint8_t *)data, len, false); |
| 2354 | #endif |
| 2355 | |
| 2356 | // mprintf(1, "network: type %d\n", who_to->connection_type); |
| 2357 | // send_sock = *Unreliable_socket; |
| 2358 | switch (who_to->connection_type) { |
| 2359 | case NP_TCP: |
| 2360 | if (id == NWT_RELIABLE) { |
| 2361 | NetStatistics.tcp_total_packets_sent++; |
| 2362 | NetStatistics.tcp_total_bytes_sent += len; |
| 2363 | } else if (id == NWT_UNRELIABLE) { |
| 2364 | NetStatistics.udp_total_packets_sent++; |
| 2365 | NetStatistics.udp_total_bytes_sent += len; |
| 2366 | } |
| 2367 | |
| 2368 | send_sock = TCP_socket; |
| 2369 | if (!TCP_active) |
| 2370 | return 0; |
| 2371 | break; |
| 2372 | default: |
| 2373 | mprintf(2, "Unknown protocol type in nw_Send()\n"); |
| 2374 | Int3(); |
| 2375 | return 0; |
| 2376 | } |
| 2377 | |
| 2378 | /* |
| 2379 | uint8_t compdata[MAX_PACKET_SIZE*3]; |
| 2380 | uint8_t testdata[MAX_PACKET_SIZE*3]; |
| 2381 | int uncompsize; |
| 2382 |
no test coverage detected