FS2_Open
Open source remastering of the Freespace 2 engine
|
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <errno.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <limits.h>
#include <algorithm>
#include "globalincs/pstypes.h"
#include "network/psnet2.h"
#include "network/multi.h"
#include "network/multiutil.h"
#include "network/multilag.h"
#include "osapi/osregistry.h"
#include "io/timer.h"
#include "network/multi_log.h"
#include "network/multi_rate.h"
#include "cmdline/cmdline.h"
Go to the source code of this file.
Classes | |
struct | network_packet |
struct | network_packet_buffer |
struct | network_packet_buffer_list |
struct | reliable_header |
struct | reliable_net_sendbuffer |
struct | reliable_net_rcvbuffer |
struct | reliable_socket |
Typedefs | |
typedef struct network_packet | network_naked_packet |
typedef struct network_packet_buffer | network_packet_buffer |
typedef struct network_packet_buffer_list | network_packet_buffer_list |
#define CONNECTSEQ 0x142 |
Definition at line 213 of file psnet2.cpp.
#define MAX_LINGER_TIME 0 |
Definition at line 132 of file psnet2.cpp.
#define MAX_PACKET_BUFFERS 75 |
Definition at line 90 of file psnet2.cpp.
#define MAX_PING_HISTORY 10 |
Definition at line 169 of file psnet2.cpp.
#define MAX_RECEIVE_BUFSIZE 4096 |
Definition at line 130 of file psnet2.cpp.
#define MAX_SEND_RETRIES 20 |
Definition at line 131 of file psnet2.cpp.
#define MAX_TOP_LAYER_PACKET_SIZE 680 |
Definition at line 86 of file psnet2.cpp.
#define MAXHOSTNAME 128 |
Definition at line 128 of file psnet2.cpp.
#define MAXNETBUFFERS 150 |
Definition at line 136 of file psnet2.cpp.
#define MAXRELIABLESOCKETS 40 |
Definition at line 142 of file psnet2.cpp.
#define MIN_NET_RETRYTIME 0.2f |
Definition at line 139 of file psnet2.cpp.
#define NETBUFFERSIZE 600 |
Definition at line 143 of file psnet2.cpp.
#define NETHEARTBEATTIME 3 |
Definition at line 141 of file psnet2.cpp.
#define NETRETRYTIME 0.75f |
Definition at line 138 of file psnet2.cpp.
#define NETTIMEOUT 30 |
Definition at line 140 of file psnet2.cpp.
#define NETWORK_CONNECTION_DIALUP 2 |
Definition at line 71 of file psnet2.cpp.
#define NETWORK_CONNECTION_LAN 3 |
Definition at line 72 of file psnet2.cpp.
#define NETWORK_CONNECTION_NONE 1 |
Definition at line 70 of file psnet2.cpp.
#define NETWORK_STATUS_NO_PROTOCOL 3 |
Definition at line 77 of file psnet2.cpp.
#define NETWORK_STATUS_NO_RELIABLE 4 |
Definition at line 78 of file psnet2.cpp.
#define NETWORK_STATUS_NO_WINSOCK 2 |
Definition at line 76 of file psnet2.cpp.
#define NETWORK_STATUS_NOT_INITIALIZED 1 |
Definition at line 75 of file psnet2.cpp.
#define NETWORK_STATUS_RUNNING 5 |
Definition at line 79 of file psnet2.cpp.
#define RELIABLE_CONNECT_TIME 7 |
Definition at line 145 of file psnet2.cpp.
#define RELIABLE_PACKET_HEADER_ONLY_SIZE (sizeof(reliable_header)-NETBUFFERSIZE) |
Definition at line 168 of file psnet2.cpp.
#define RNT_ACK 1 |
Definition at line 150 of file psnet2.cpp.
#define RNT_DATA 2 |
Definition at line 151 of file psnet2.cpp.
#define RNT_DATA_COMP 3 |
Definition at line 152 of file psnet2.cpp.
#define RNT_DISCONNECT 5 |
Definition at line 154 of file psnet2.cpp.
#define RNT_HEARTBEAT 6 |
Definition at line 155 of file psnet2.cpp.
#define RNT_I_AM_HERE 7 |
Definition at line 156 of file psnet2.cpp.
#define RNT_REQ_CONN 4 |
Definition at line 153 of file psnet2.cpp.
#define WSAGetLastError | ( | ) | (errno) |
Definition at line 30 of file psnet2.cpp.
typedef struct network_packet network_naked_packet |
Definition for a non-checksum packet
typedef struct network_packet_buffer network_packet_buffer |
Structure definition for our packet buffers
typedef struct network_packet_buffer_list network_packet_buffer_list |
Structure for a bunch of network packet buffers
char* psnet_addr_to_string | ( | char * | text, |
net_addr * | address | ||
) |
Convert a net_addr to a string
Definition at line 705 of file psnet2.cpp.
Broadcast data on unreliable socket
Definition at line 897 of file psnet2.cpp.
int psnet_buffer_get_next | ( | network_packet_buffer_list * | l, |
ubyte * | data, | ||
int * | length, | ||
net_addr * | from | ||
) |
Get the index of the next packet in order!
Definition at line 1861 of file psnet2.cpp.
void psnet_buffer_init | ( | network_packet_buffer_list * | l | ) |
Initialize the buffering system
Definition at line 1804 of file psnet2.cpp.
void psnet_buffer_packet | ( | network_packet_buffer_list * | l, |
ubyte * | data, | ||
int | length, | ||
net_addr * | from | ||
) |
Buffer a packet (maintain order!)
Definition at line 1825 of file psnet2.cpp.
void psnet_close | ( | ) |
Shutdown psnet
Definition at line 563 of file psnet2.cpp.
void psnet_flush | ( | ) |
Flush all sockets
Definition at line 927 of file psnet2.cpp.
Get data from the unreliable socket
Definition at line 881 of file psnet2.cpp.
int psnet_get_ip | ( | ) |
Returns the IP address of this computer
Definition at line 1751 of file psnet2.cpp.
int psnet_get_network_status | ( | ) |
Get the status of the network
Definition at line 670 of file psnet2.cpp.
float psnet_get_time | ( | ) |
Get time in seconds
Definition at line 2166 of file psnet2.cpp.
Initialize psnet to use the specified port
Definition at line 458 of file psnet2.cpp.
Initialize reliable sockets
Definition at line 1777 of file psnet2.cpp.
int psnet_init_tcp | ( | ) |
Initialize tcp socket
Definition at line 2125 of file psnet2.cpp.
If the passed string is a valid IP string
Definition at line 938 of file psnet2.cpp.
int psnet_is_valid_numeric_ip | ( | char * | ip | ) |
If the string is a legally formatted IP string
Definition at line 1904 of file psnet2.cpp.
void psnet_mark_received | ( | PSNET_SOCKET_RELIABLE | socket | ) |
Mark a socket as having received data
Definition at line 2174 of file psnet2.cpp.
int psnet_rel_check | ( | ) |
Definition at line 1067 of file psnet2.cpp.
Checks the Listen_socket for possibly incoming requests to be connected.
Definition at line 1555 of file psnet2.cpp.
void psnet_rel_close | ( | ) |
Definition at line 1783 of file psnet2.cpp.
void psnet_rel_close_socket | ( | PSNET_SOCKET_RELIABLE * | sockp | ) |
Function to shutdown and close the given socket.
It takes a couple of things into consideration when closing, such as possibly reiniting reliable sockets if they are closed here.
Definition at line 1008 of file psnet2.cpp.
void psnet_rel_connect_to_server | ( | PSNET_SOCKET * | socket, |
net_addr * | server_addr | ||
) |
Attempt to connect() to the server's tcp socket. socket parameter is simply assigned to the Reliable_socket socket created in psnet_init
Definition at line 1593 of file psnet2.cpp.
int psnet_rel_get | ( | PSNET_SOCKET | socketid, |
ubyte * | buffer, | ||
int | max_len | ||
) |
Definition at line 1152 of file psnet2.cpp.
int psnet_rel_get_status | ( | PSNET_SOCKET_RELIABLE | socketid | ) |
Get the status of a reliable socket, see RNF_* defines above
Definition at line 1542 of file psnet2.cpp.
int psnet_rel_send | ( | PSNET_SOCKET_RELIABLE | socketid, |
ubyte * | data, | ||
int | length, | ||
int | np_index | ||
) |
Send data reliably
Definition at line 1075 of file psnet2.cpp.
Definition at line 975 of file psnet2.cpp.
void psnet_rel_work | ( | ) |
Process all active reliable sockets
Definition at line 1187 of file psnet2.cpp.
Compare 2 addresses
Definition at line 785 of file psnet2.cpp.
Send data unreliably
Definition at line 793 of file psnet2.cpp.
Set some options on a socket
Definition at line 2088 of file psnet2.cpp.
Convert a string to a net addr
Definition at line 732 of file psnet2.cpp.
void PSNET_TOP_LAYER_PROCESS | ( | ) |
Call this once per frame to read everything off of our socket
Definition at line 360 of file psnet2.cpp.
Set the protocol to use
Definition at line 596 of file psnet2.cpp.
int RECVFROM | ( | SOCKET | s, |
char * | buf, | ||
int | len, | ||
int | flags, | ||
sockaddr * | from, | ||
int * | fromlen, | ||
int | psnet_type | ||
) |
Wrappers around select() and recvfrom() for lagging/losing data
Definition at line 271 of file psnet2.cpp.
int SELECT | ( | int | nfds, |
fd_set * | readfds, | ||
fd_set * | writefds, | ||
fd_set * | exceptfds, | ||
struct timeval * | timeout, | ||
int | psnet_type | ||
) |
Wrappers around select() and recvfrom() for lagging/losing data
Definition at line 317 of file psnet2.cpp.
Wrappers around sendto to sorting through different packet types
Definition at line 345 of file psnet2.cpp.
int Can_broadcast |
Definition at line 57 of file psnet2.cpp.
float First_sent_iamhere = 0 |
Definition at line 210 of file psnet2.cpp.
float Last_sent_iamhere = 0 |
Definition at line 211 of file psnet2.cpp.
int Nettimeout = NETTIMEOUT |
Definition at line 147 of file psnet2.cpp.
int Network_status |
Definition at line 62 of file psnet2.cpp.
ubyte Null_address[6] |
Definition at line 54 of file psnet2.cpp.
int Psnet_connection |
Definition at line 65 of file psnet2.cpp.
ushort Psnet_default_port |
Definition at line 67 of file psnet2.cpp.
net_addr Psnet_my_addr |
Definition at line 52 of file psnet2.cpp.
int Psnet_my_addr_valid |
Definition at line 51 of file psnet2.cpp.
network_packet_buffer_list Psnet_top_buffers[PSNET_NUM_TYPES] |
Definition at line 221 of file psnet2.cpp.
int Ras_connected |
Definition at line 64 of file psnet2.cpp.
reliable_socket Reliable_sockets[MAXRELIABLESOCKETS] |
Definition at line 202 of file psnet2.cpp.
unsigned int Serverconn = 0xffffffff |
Definition at line 215 of file psnet2.cpp.
int Socket_type |
Definition at line 56 of file psnet2.cpp.
int Tcp_active = 0 |
Definition at line 60 of file psnet2.cpp.
int Tcp_can_broadcast = 0 |
Definition at line 58 of file psnet2.cpp.
int Tcp_failure_code = 0 |
Definition at line 63 of file psnet2.cpp.
SOCKET TCP_socket |
Definition at line 205 of file psnet2.cpp.
SOCKET Unreliable_socket = INVALID_SOCKET |
Definition at line 208 of file psnet2.cpp.