mirror of https://github.com/OpenTTD/OpenTTD
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
and 'void' where needed, prefixed all functions, typedefs and global vars with 'Network' and organized all externals nicely.release/0.4.5
parent
bb5dca016d
commit
0e19f74c16
|
@ -147,7 +147,7 @@ DEF_CONSOLE_CMD(ConStatus)
|
||||||
{
|
{
|
||||||
const char *status;
|
const char *status;
|
||||||
int lag;
|
int lag;
|
||||||
const ClientState *cs;
|
const NetworkClientState *cs;
|
||||||
const NetworkClientInfo *ci;
|
const NetworkClientInfo *ci;
|
||||||
FOR_ALL_CLIENTS(cs) {
|
FOR_ALL_CLIENTS(cs) {
|
||||||
lag = NetworkCalculateLag(cs);
|
lag = NetworkCalculateLag(cs);
|
||||||
|
@ -217,7 +217,7 @@ DEF_CONSOLE_CMD(ConKick)
|
||||||
DEF_CONSOLE_CMD(ConResetCompany)
|
DEF_CONSOLE_CMD(ConResetCompany)
|
||||||
{
|
{
|
||||||
Player *p;
|
Player *p;
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
|
|
|
@ -402,7 +402,7 @@ static void PlayersCheckBankrupt(Player *p)
|
||||||
// If we are the server, make sure it is clear that his player is no
|
// If we are the server, make sure it is clear that his player is no
|
||||||
// longer with us!
|
// longer with us!
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
/* Find all clients that were in control of this company */
|
/* Find all clients that were in control of this company */
|
||||||
FOR_ALL_CLIENTS(cs) {
|
FOR_ALL_CLIENTS(cs) {
|
||||||
ci = DEREF_CLIENT_INFO(cs);
|
ci = DEREF_CLIENT_INFO(cs);
|
||||||
|
|
82
network.c
82
network.c
|
@ -35,6 +35,10 @@ static byte _network_clients_connected = 0;
|
||||||
// The index counter for new clients (is never decreased)
|
// The index counter for new clients (is never decreased)
|
||||||
static uint16 _network_client_index = NETWORK_SERVER_INDEX + 1;
|
static uint16 _network_client_index = NETWORK_SERVER_INDEX + 1;
|
||||||
|
|
||||||
|
/* Some externs / forwards */
|
||||||
|
extern void ShowJoinStatusWindow();
|
||||||
|
extern void StateGameLoop();
|
||||||
|
|
||||||
// Function that looks up the CI for a given client-index
|
// Function that looks up the CI for a given client-index
|
||||||
NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index)
|
NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index)
|
||||||
{
|
{
|
||||||
|
@ -48,9 +52,9 @@ NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function that looks up the CS for a given client-index
|
// Function that looks up the CS for a given client-index
|
||||||
ClientState *NetworkFindClientStateFromIndex(uint16 client_index)
|
NetworkClientState *NetworkFindClientStateFromIndex(uint16 client_index)
|
||||||
{
|
{
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
|
|
||||||
for (cs = _clients; cs != &_clients[MAX_CLIENT_INFO]; cs++)
|
for (cs = _clients; cs != &_clients[MAX_CLIENT_INFO]; cs++)
|
||||||
if (cs->index == client_index)
|
if (cs->index == client_index)
|
||||||
|
@ -61,7 +65,7 @@ ClientState *NetworkFindClientStateFromIndex(uint16 client_index)
|
||||||
|
|
||||||
// NetworkGetClientName is a server-safe function to get the name of the client
|
// NetworkGetClientName is a server-safe function to get the name of the client
|
||||||
// if the user did not send it yet, Client #<no> is used.
|
// if the user did not send it yet, Client #<no> is used.
|
||||||
void NetworkGetClientName(char *client_name, size_t size, ClientState *cs)
|
void NetworkGetClientName(char *client_name, size_t size, const NetworkClientState *cs)
|
||||||
{
|
{
|
||||||
NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
|
NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
|
||||||
if (ci->client_name[0] == '\0')
|
if (ci->client_name[0] == '\0')
|
||||||
|
@ -119,7 +123,7 @@ void CDECL NetworkTextMessage(NetworkAction action, uint16 color, const char *na
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the frame-lag of a client
|
// Calculate the frame-lag of a client
|
||||||
uint NetworkCalculateLag(const ClientState *cs)
|
uint NetworkCalculateLag(const NetworkClientState *cs)
|
||||||
{
|
{
|
||||||
int lag = cs->last_frame_server - cs->last_frame;
|
int lag = cs->last_frame_server - cs->last_frame;
|
||||||
// This client has missed his ACK packet after 1 DAY_TICKS..
|
// This client has missed his ACK packet after 1 DAY_TICKS..
|
||||||
|
@ -150,7 +154,7 @@ void ServerStartError(char *error) {
|
||||||
NetworkError(STR_NETWORK_ERR_SERVER_START);
|
NetworkError(STR_NETWORK_ERR_SERVER_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkClientError(byte res, ClientState *cs) {
|
static void NetworkClientError(byte res, NetworkClientState *cs) {
|
||||||
// First, send a CLIENT_ERROR to the server, so he knows we are
|
// First, send a CLIENT_ERROR to the server, so he knows we are
|
||||||
// disconnection (and why!)
|
// disconnection (and why!)
|
||||||
NetworkErrorCode errorno;
|
NetworkErrorCode errorno;
|
||||||
|
@ -158,7 +162,7 @@ void NetworkClientError(byte res, ClientState *cs) {
|
||||||
// We just want to close the connection..
|
// We just want to close the connection..
|
||||||
if (res == NETWORK_RECV_STATUS_CLOSE_QUERY) {
|
if (res == NETWORK_RECV_STATUS_CLOSE_QUERY) {
|
||||||
cs->quited = true;
|
cs->quited = true;
|
||||||
CloseClient(cs);
|
NetworkCloseClient(cs);
|
||||||
_networking = false;
|
_networking = false;
|
||||||
|
|
||||||
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
|
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
|
||||||
|
@ -179,12 +183,12 @@ void NetworkClientError(byte res, ClientState *cs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_switch_mode = SM_MENU;
|
_switch_mode = SM_MENU;
|
||||||
CloseClient(cs);
|
NetworkCloseClient(cs);
|
||||||
_networking = false;
|
_networking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find all IP-aliases for this host
|
// Find all IP-aliases for this host
|
||||||
void NetworkFindIPs(void)
|
static void NetworkFindIPs(void)
|
||||||
{
|
{
|
||||||
int i, last;
|
int i, last;
|
||||||
|
|
||||||
|
@ -388,9 +392,9 @@ void ParseConnectionString(const byte **player, const byte **port, byte *connect
|
||||||
|
|
||||||
// Creates a new client from a socket
|
// Creates a new client from a socket
|
||||||
// Used both by the server and the client
|
// Used both by the server and the client
|
||||||
static ClientState *AllocClient(SOCKET s)
|
static NetworkClientState *NetworkAllocClient(SOCKET s)
|
||||||
{
|
{
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
byte client_no;
|
byte client_no;
|
||||||
|
|
||||||
|
@ -429,7 +433,7 @@ static ClientState *AllocClient(SOCKET s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close a connection
|
// Close a connection
|
||||||
void CloseClient(ClientState *cs)
|
void NetworkCloseClient(NetworkClientState *cs)
|
||||||
{
|
{
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
// Socket is already dead
|
// Socket is already dead
|
||||||
|
@ -442,7 +446,7 @@ void CloseClient(ClientState *cs)
|
||||||
NetworkErrorCode errorno = NETWORK_ERROR_CONNECTION_LOST;
|
NetworkErrorCode errorno = NETWORK_ERROR_CONNECTION_LOST;
|
||||||
char str1[100], str2[100];
|
char str1[100], str2[100];
|
||||||
char client_name[NETWORK_NAME_LENGTH];
|
char client_name[NETWORK_NAME_LENGTH];
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
|
|
||||||
NetworkGetClientName(client_name, sizeof(client_name), cs);
|
NetworkGetClientName(client_name, sizeof(client_name), cs);
|
||||||
|
|
||||||
|
@ -503,10 +507,8 @@ void CloseClient(ClientState *cs)
|
||||||
ci->client_index = NETWORK_EMPTY_INDEX;
|
ci->client_index = NETWORK_EMPTY_INDEX;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void ShowJoinStatusWindow();
|
|
||||||
|
|
||||||
// A client wants to connect to a server
|
// A client wants to connect to a server
|
||||||
bool NetworkConnect(const char *hostname, int port)
|
static bool NetworkConnect(const char *hostname, int port)
|
||||||
{
|
{
|
||||||
SOCKET s;
|
SOCKET s;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
@ -550,7 +552,7 @@ bool NetworkConnect(const char *hostname, int port)
|
||||||
}
|
}
|
||||||
|
|
||||||
// in client mode, only the first client field is used. it's pointing to the server.
|
// in client mode, only the first client field is used. it's pointing to the server.
|
||||||
AllocClient(s);
|
NetworkAllocClient(s);
|
||||||
|
|
||||||
ShowJoinStatusWindow();
|
ShowJoinStatusWindow();
|
||||||
|
|
||||||
|
@ -564,7 +566,7 @@ static void NetworkAcceptClients(void)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
SOCKET s;
|
SOCKET s;
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
#ifndef __MORPHOS__
|
#ifndef __MORPHOS__
|
||||||
int sin_len;
|
int sin_len;
|
||||||
#else
|
#else
|
||||||
|
@ -594,7 +596,7 @@ static void NetworkAcceptClients(void)
|
||||||
{int b = 1; setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b));}
|
{int b = 1; setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b));}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cs = AllocClient(s);
|
cs = NetworkAllocClient(s);
|
||||||
if (cs == NULL) {
|
if (cs == NULL) {
|
||||||
// no more clients allowed?
|
// no more clients allowed?
|
||||||
// Send to the client that we are full!
|
// Send to the client that we are full!
|
||||||
|
@ -626,7 +628,7 @@ static void NetworkAcceptClients(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the listen socket for the server
|
// Set up the listen socket for the server
|
||||||
bool NetworkListen(void)
|
static bool NetworkListen(void)
|
||||||
{
|
{
|
||||||
SOCKET ls;
|
SOCKET ls;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
@ -682,16 +684,16 @@ bool NetworkListen(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close all current connections
|
// Close all current connections
|
||||||
void NetworkClose(void)
|
static void NetworkClose(void)
|
||||||
{
|
{
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
|
|
||||||
FOR_ALL_CLIENTS(cs) {
|
FOR_ALL_CLIENTS(cs) {
|
||||||
if (!_network_server) {
|
if (!_network_server) {
|
||||||
SEND_COMMAND(PACKET_CLIENT_QUIT)("leaving");
|
SEND_COMMAND(PACKET_CLIENT_QUIT)("leaving");
|
||||||
NetworkSend_Packets(cs);
|
NetworkSend_Packets(cs);
|
||||||
}
|
}
|
||||||
CloseClient(cs);
|
NetworkCloseClient(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_network_server) {
|
if (_network_server) {
|
||||||
|
@ -704,9 +706,9 @@ void NetworkClose(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inits the network (cleans sockets and stuff)
|
// Inits the network (cleans sockets and stuff)
|
||||||
void NetworkInitialize(void)
|
static void NetworkInitialize(void)
|
||||||
{
|
{
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
_local_command_queue = NULL;
|
_local_command_queue = NULL;
|
||||||
|
@ -735,7 +737,7 @@ void NetworkInitialize(void)
|
||||||
// add all servers from the config file to our list
|
// add all servers from the config file to our list
|
||||||
for (i=0; i != lengthof(_network_server_list); i++) {
|
for (i=0; i != lengthof(_network_server_list); i++) {
|
||||||
if (_network_server_list[i] == NULL) break;
|
if (_network_server_list[i] == NULL) break;
|
||||||
AddServer(_network_server_list[i]);
|
NetworkAddServer(_network_server_list[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -775,22 +777,25 @@ void NetworkQueryServer(const byte* host, unsigned short port, bool game_info)
|
||||||
|
|
||||||
// validates an address entered as a string and adds the server to
|
// validates an address entered as a string and adds the server to
|
||||||
// the list
|
// the list
|
||||||
void AddServer(byte *b)
|
void NetworkAddServer(const byte *b)
|
||||||
{
|
{
|
||||||
if (*b != '\0') {
|
if (*b != '\0') {
|
||||||
const byte *port = NULL;
|
const byte *port = NULL;
|
||||||
const byte *player = NULL;
|
const byte *player = NULL;
|
||||||
|
byte host[NETWORK_HOSTNAME_LENGTH];
|
||||||
uint16 rport;
|
uint16 rport;
|
||||||
|
|
||||||
|
ttd_strlcpy(host, b, lengthof(host));
|
||||||
|
|
||||||
ttd_strlcpy(_network_default_ip, b, lengthof(_network_default_ip));
|
ttd_strlcpy(_network_default_ip, b, lengthof(_network_default_ip));
|
||||||
rport = NETWORK_DEFAULT_PORT;
|
rport = NETWORK_DEFAULT_PORT;
|
||||||
|
|
||||||
ParseConnectionString(&player, &port, b);
|
ParseConnectionString(&player, &port, host);
|
||||||
|
|
||||||
if (player != NULL) _network_playas = atoi(player);
|
if (player != NULL) _network_playas = atoi(player);
|
||||||
if (port != NULL) rport = atoi(port);
|
if (port != NULL) rport = atoi(port);
|
||||||
|
|
||||||
NetworkQueryServer(b, rport, true);
|
NetworkQueryServer(host, rport, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -823,7 +828,7 @@ bool NetworkClientConnectGame(const byte* host, unsigned short port)
|
||||||
return _networking;
|
return _networking;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkInitGameInfo(void)
|
static void NetworkInitGameInfo(void)
|
||||||
{
|
{
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
|
|
||||||
|
@ -913,7 +918,7 @@ bool NetworkServerStart(void)
|
||||||
void NetworkReboot(void)
|
void NetworkReboot(void)
|
||||||
{
|
{
|
||||||
if (_network_server) {
|
if (_network_server) {
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
FOR_ALL_CLIENTS(cs) {
|
FOR_ALL_CLIENTS(cs) {
|
||||||
SEND_COMMAND(PACKET_SERVER_NEWGAME)(cs);
|
SEND_COMMAND(PACKET_SERVER_NEWGAME)(cs);
|
||||||
NetworkSend_Packets(cs);
|
NetworkSend_Packets(cs);
|
||||||
|
@ -937,7 +942,7 @@ void NetworkReboot(void)
|
||||||
void NetworkDisconnect(void)
|
void NetworkDisconnect(void)
|
||||||
{
|
{
|
||||||
if (_network_server) {
|
if (_network_server) {
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
FOR_ALL_CLIENTS(cs) {
|
FOR_ALL_CLIENTS(cs) {
|
||||||
SEND_COMMAND(PACKET_SERVER_SHUTDOWN)(cs);
|
SEND_COMMAND(PACKET_SERVER_SHUTDOWN)(cs);
|
||||||
NetworkSend_Packets(cs);
|
NetworkSend_Packets(cs);
|
||||||
|
@ -964,9 +969,9 @@ void NetworkDisconnect(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receives something from the network
|
// Receives something from the network
|
||||||
bool NetworkReceive(void)
|
static bool NetworkReceive(void)
|
||||||
{
|
{
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
int n;
|
int n;
|
||||||
fd_set read_fd, write_fd;
|
fd_set read_fd, write_fd;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
@ -1022,7 +1027,7 @@ bool NetworkReceive(void)
|
||||||
// This sends all buffered commands (if possible)
|
// This sends all buffered commands (if possible)
|
||||||
static void NetworkSend(void)
|
static void NetworkSend(void)
|
||||||
{
|
{
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
FOR_ALL_CLIENTS(cs) {
|
FOR_ALL_CLIENTS(cs) {
|
||||||
if (cs->writable) {
|
if (cs->writable) {
|
||||||
NetworkSend_Packets(cs);
|
NetworkSend_Packets(cs);
|
||||||
|
@ -1036,7 +1041,7 @@ static void NetworkSend(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the local-command-queue
|
// Handle the local-command-queue
|
||||||
void NetworkHandleLocalQueue(void)
|
static void NetworkHandleLocalQueue(void)
|
||||||
{
|
{
|
||||||
if (_local_command_queue != NULL) {
|
if (_local_command_queue != NULL) {
|
||||||
CommandPacket *cp;
|
CommandPacket *cp;
|
||||||
|
@ -1071,10 +1076,7 @@ void NetworkHandleLocalQueue(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool NetworkDoClientLoop(void)
|
||||||
extern void StateGameLoop();
|
|
||||||
|
|
||||||
bool NetworkDoClientLoop(void)
|
|
||||||
{
|
{
|
||||||
_frame_counter++;
|
_frame_counter++;
|
||||||
|
|
||||||
|
@ -1168,7 +1170,7 @@ void NetworkGameLoop(void)
|
||||||
NetworkSend();
|
NetworkSend();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkGenerateUniqueId()
|
static void NetworkGenerateUniqueId(void)
|
||||||
{
|
{
|
||||||
md5_state_t state;
|
md5_state_t state;
|
||||||
md5_byte_t digest[16];
|
md5_byte_t digest[16];
|
||||||
|
|
|
@ -193,6 +193,6 @@ VARDEF byte _network_playas; // an id to play as..
|
||||||
|
|
||||||
void ParseConnectionString(const byte **player, const byte **port, byte *connection_string);
|
void ParseConnectionString(const byte **player, const byte **port, byte *connection_string);
|
||||||
void NetworkUpdateClientInfo(uint16 client_index);
|
void NetworkUpdateClientInfo(uint16 client_index);
|
||||||
void AddServer(byte *b);
|
void NetworkAddServer(const byte *b);
|
||||||
|
|
||||||
#endif /* NETWORK_H */
|
#endif /* NETWORK_H */
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
// This file handles all the client-commands
|
// This file handles all the client-commands
|
||||||
|
|
||||||
|
|
||||||
|
extern const char _openttd_revision[];
|
||||||
|
|
||||||
// So we don't make too much typos ;)
|
// So we don't make too much typos ;)
|
||||||
#define MY_CLIENT DEREF_CLIENT(0)
|
#define MY_CLIENT DEREF_CLIENT(0)
|
||||||
|
|
||||||
|
@ -43,8 +45,6 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO)
|
||||||
NetworkSend_Packet(p, MY_CLIENT);
|
NetworkSend_Packet(p, MY_CLIENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const char _openttd_revision[];
|
|
||||||
|
|
||||||
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
|
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
@ -805,7 +805,7 @@ void NetworkClient_Connected(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads the packets from the socket-stream, if available
|
// Reads the packets from the socket-stream, if available
|
||||||
NetworkRecvStatus NetworkClient_ReadPackets(ClientState *cs)
|
NetworkRecvStatus NetworkClient_ReadPackets(NetworkClientState *cs)
|
||||||
{
|
{
|
||||||
Packet *p;
|
Packet *p;
|
||||||
NetworkRecvStatus res = NETWORK_RECV_STATUS_OKAY;
|
NetworkRecvStatus res = NETWORK_RECV_STATUS_OKAY;
|
||||||
|
|
|
@ -14,7 +14,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password);
|
||||||
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name);
|
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name);
|
||||||
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK);
|
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK);
|
||||||
|
|
||||||
NetworkRecvStatus NetworkClient_ReadPackets(ClientState *cs);
|
NetworkRecvStatus NetworkClient_ReadPackets(NetworkClientState *cs);
|
||||||
void NetworkClient_Connected(void);
|
void NetworkClient_Connected(void);
|
||||||
|
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
|
|
|
@ -86,7 +86,7 @@ assert_compile(sizeof(PacketSize) == 2);
|
||||||
// as soon as possible
|
// as soon as possible
|
||||||
// (that is: the next tick, or maybe one tick later if the
|
// (that is: the next tick, or maybe one tick later if the
|
||||||
// OS-network-buffer is full)
|
// OS-network-buffer is full)
|
||||||
void NetworkSend_Packet(Packet *packet, ClientState *cs)
|
void NetworkSend_Packet(Packet *packet, NetworkClientState *cs)
|
||||||
{
|
{
|
||||||
Packet *p;
|
Packet *p;
|
||||||
assert(packet != NULL);
|
assert(packet != NULL);
|
||||||
|
@ -114,9 +114,9 @@ void NetworkSend_Packet(Packet *packet, ClientState *cs)
|
||||||
// this handles what to do.
|
// this handles what to do.
|
||||||
// For clients: close connection and drop back to main-menu
|
// For clients: close connection and drop back to main-menu
|
||||||
// For servers: close connection and that is it
|
// For servers: close connection and that is it
|
||||||
NetworkRecvStatus CloseConnection(ClientState *cs)
|
NetworkRecvStatus CloseConnection(NetworkClientState *cs)
|
||||||
{
|
{
|
||||||
CloseClient(cs);
|
NetworkCloseClient(cs);
|
||||||
|
|
||||||
// Clients drop back to the main menu
|
// Clients drop back to the main menu
|
||||||
if (!_network_server) {
|
if (!_network_server) {
|
||||||
|
@ -136,7 +136,7 @@ NetworkRecvStatus CloseConnection(ClientState *cs)
|
||||||
// 2) the OS reports back that it can not send any more
|
// 2) the OS reports back that it can not send any more
|
||||||
// data right now (full network-buffer, it happens ;))
|
// data right now (full network-buffer, it happens ;))
|
||||||
// 3) sending took too long
|
// 3) sending took too long
|
||||||
bool NetworkSend_Packets(ClientState *cs)
|
bool NetworkSend_Packets(NetworkClientState *cs)
|
||||||
{
|
{
|
||||||
ssize_t res;
|
ssize_t res;
|
||||||
Packet *p;
|
Packet *p;
|
||||||
|
@ -242,7 +242,7 @@ void NetworkRecv_string(Packet *p, char* buffer, size_t size)
|
||||||
// (the line: 'p->size = (uint16)p->buffer[0];' and below)
|
// (the line: 'p->size = (uint16)p->buffer[0];' and below)
|
||||||
assert_compile(sizeof(PacketSize) == 2);
|
assert_compile(sizeof(PacketSize) == 2);
|
||||||
|
|
||||||
Packet *NetworkRecv_Packet(ClientState *cs, NetworkRecvStatus *status)
|
Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
|
||||||
{
|
{
|
||||||
ssize_t res;
|
ssize_t res;
|
||||||
Packet *p;
|
Packet *p;
|
||||||
|
@ -330,7 +330,7 @@ Packet *NetworkRecv_Packet(ClientState *cs, NetworkRecvStatus *status)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a command to the local command queue
|
// Add a command to the local command queue
|
||||||
void NetworkAddCommandQueue(ClientState *cs, CommandPacket *cp)
|
void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp)
|
||||||
{
|
{
|
||||||
CommandPacket *new_cp = malloc(sizeof(CommandPacket));
|
CommandPacket *new_cp = malloc(sizeof(CommandPacket));
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ void NetworkSend_Command(uint32 tile, uint32 p1, uint32 p2, uint32 cmd, CommandC
|
||||||
// client on the server can do everything 1 tick faster then others.
|
// client on the server can do everything 1 tick faster then others.
|
||||||
// So to keep the game fair, we delay the command with 1 tick
|
// So to keep the game fair, we delay the command with 1 tick
|
||||||
// which gives about the same speed as most clients.
|
// which gives about the same speed as most clients.
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
|
|
||||||
// And we queue it for delivery to the clients
|
// And we queue it for delivery to the clients
|
||||||
FOR_ALL_CLIENTS(cs) {
|
FOR_ALL_CLIENTS(cs) {
|
||||||
|
|
|
@ -107,7 +107,7 @@ typedef enum {
|
||||||
} NetworkPasswordType;
|
} NetworkPasswordType;
|
||||||
|
|
||||||
// To keep the clients all together
|
// To keep the clients all together
|
||||||
typedef struct ClientState {
|
typedef struct NetworkClientState {
|
||||||
int socket;
|
int socket;
|
||||||
uint16 index;
|
uint16 index;
|
||||||
uint32 last_frame;
|
uint32 last_frame;
|
||||||
|
@ -122,7 +122,7 @@ typedef struct ClientState {
|
||||||
Packet *packet_recv; // Partially received packet
|
Packet *packet_recv; // Partially received packet
|
||||||
|
|
||||||
CommandPacket *command_queue; // The command-queue awaiting delivery
|
CommandPacket *command_queue; // The command-queue awaiting delivery
|
||||||
} ClientState;
|
} NetworkClientState;
|
||||||
|
|
||||||
// What packet types are there
|
// What packet types are there
|
||||||
// WARNING: The first 3 packets can NEVER change order again
|
// WARNING: The first 3 packets can NEVER change order again
|
||||||
|
@ -173,17 +173,17 @@ SOCKET _udp_client_socket; // udp client socket
|
||||||
|
|
||||||
// Here we keep track of the clients
|
// Here we keep track of the clients
|
||||||
// (and the client uses [0] for his own communication)
|
// (and the client uses [0] for his own communication)
|
||||||
ClientState _clients[MAX_CLIENTS];
|
NetworkClientState _clients[MAX_CLIENTS];
|
||||||
#define DEREF_CLIENT(i) (&_clients[i])
|
#define DEREF_CLIENT(i) (&_clients[i])
|
||||||
// This returns the NetworkClientInfo from a ClientState
|
// This returns the NetworkClientInfo from a NetworkClientState
|
||||||
#define DEREF_CLIENT_INFO(cs) (&_network_client_info[cs - _clients])
|
#define DEREF_CLIENT_INFO(cs) (&_network_client_info[cs - _clients])
|
||||||
|
|
||||||
// Macros to make life a bit more easier
|
// Macros to make life a bit more easier
|
||||||
#define DEF_CLIENT_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(Packet *p)
|
#define DEF_CLIENT_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(Packet *p)
|
||||||
#define DEF_CLIENT_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command(void)
|
#define DEF_CLIENT_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command(void)
|
||||||
#define DEF_CLIENT_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command
|
#define DEF_CLIENT_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command
|
||||||
#define DEF_SERVER_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(ClientState *cs, Packet *p)
|
#define DEF_SERVER_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(NetworkClientState *cs, Packet *p)
|
||||||
#define DEF_SERVER_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command(ClientState *cs)
|
#define DEF_SERVER_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command(NetworkClientState *cs)
|
||||||
#define DEF_SERVER_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command
|
#define DEF_SERVER_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command
|
||||||
|
|
||||||
#define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command
|
#define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command
|
||||||
|
@ -197,27 +197,27 @@ void NetworkSend_uint16(Packet *packet, uint16 data);
|
||||||
void NetworkSend_uint32(Packet *packet, uint32 data);
|
void NetworkSend_uint32(Packet *packet, uint32 data);
|
||||||
void NetworkSend_uint64(Packet *packet, uint64 data);
|
void NetworkSend_uint64(Packet *packet, uint64 data);
|
||||||
void NetworkSend_string(Packet *packet, const char* data);
|
void NetworkSend_string(Packet *packet, const char* data);
|
||||||
void NetworkSend_Packet(Packet *packet, ClientState *cs);
|
void NetworkSend_Packet(Packet *packet, NetworkClientState *cs);
|
||||||
|
|
||||||
uint8 NetworkRecv_uint8(Packet *packet);
|
uint8 NetworkRecv_uint8(Packet *packet);
|
||||||
uint16 NetworkRecv_uint16(Packet *packet);
|
uint16 NetworkRecv_uint16(Packet *packet);
|
||||||
uint32 NetworkRecv_uint32(Packet *packet);
|
uint32 NetworkRecv_uint32(Packet *packet);
|
||||||
uint64 NetworkRecv_uint64(Packet *packet);
|
uint64 NetworkRecv_uint64(Packet *packet);
|
||||||
void NetworkRecv_string(Packet *packet, char* buffer, size_t size);
|
void NetworkRecv_string(Packet *packet, char* buffer, size_t size);
|
||||||
Packet *NetworkRecv_Packet(ClientState *cs, NetworkRecvStatus *status);
|
Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status);
|
||||||
|
|
||||||
bool NetworkSend_Packets(ClientState *cs);
|
bool NetworkSend_Packets(NetworkClientState *cs);
|
||||||
void NetworkExecuteCommand(CommandPacket *cp);
|
void NetworkExecuteCommand(CommandPacket *cp);
|
||||||
void NetworkAddCommandQueue(ClientState *cs, CommandPacket *cp);
|
void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp);
|
||||||
|
|
||||||
// from network.c
|
// from network.c
|
||||||
void CloseClient(ClientState *cs);
|
void NetworkCloseClient(NetworkClientState *cs);
|
||||||
void CDECL NetworkTextMessage(NetworkAction action, uint16 color, const char *name, const char *str, ...);
|
void CDECL NetworkTextMessage(NetworkAction action, uint16 color, const char *name, const char *str, ...);
|
||||||
void NetworkGetClientName(char *clientname, size_t size, ClientState *cs);
|
void NetworkGetClientName(char *clientname, size_t size, const NetworkClientState *cs);
|
||||||
uint NetworkCalculateLag(const ClientState *cs);
|
uint NetworkCalculateLag(const NetworkClientState *cs);
|
||||||
byte NetworkGetCurrentLanguageIndex();
|
byte NetworkGetCurrentLanguageIndex();
|
||||||
NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index);
|
NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index);
|
||||||
ClientState *NetworkFindClientStateFromIndex(uint16 client_index);
|
NetworkClientState *NetworkFindClientStateFromIndex(uint16 client_index);
|
||||||
unsigned long NetworkResolveHost(const char *hostname);
|
unsigned long NetworkResolveHost(const char *hostname);
|
||||||
|
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
|
|
|
@ -65,7 +65,7 @@ NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkGameListAddQueriedItem(NetworkGameInfo *info, bool server_online)
|
void NetworkGameListAddQueriedItem(const NetworkGameInfo *info, bool server_online)
|
||||||
{
|
{
|
||||||
// We queried a server and now we are going to add it to the list
|
// We queried a server and now we are going to add it to the list
|
||||||
NetworkGameList *item;
|
NetworkGameList *item;
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
|
|
||||||
void NetworkGameListClear(void);
|
void NetworkGameListClear(void);
|
||||||
NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port);
|
NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port);
|
||||||
void NetworkGameListAddQueriedItem(NetworkGameInfo *info, bool server_online);
|
void NetworkGameListAddQueriedItem(const NetworkGameInfo *info, bool server_online);
|
||||||
|
|
||||||
#endif /* NETWORK_GAMELIST_H */
|
#endif /* NETWORK_GAMELIST_H */
|
||||||
|
|
|
@ -317,7 +317,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WE_ON_EDIT_TEXT: {
|
case WE_ON_EDIT_TEXT: {
|
||||||
AddServer(e->edittext.str);
|
NetworkAddServer(e->edittext.str);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WE_CREATE: {
|
case WE_CREATE: {
|
||||||
|
|
|
@ -15,18 +15,20 @@
|
||||||
|
|
||||||
// This file handles all the server-commands
|
// This file handles all the server-commands
|
||||||
|
|
||||||
void NetworkHandleCommandQueue(ClientState *cs);
|
void NetworkHandleCommandQueue(NetworkClientState *cs);
|
||||||
void NetworkPopulateCompanyInfo(void);
|
void NetworkPopulateCompanyInfo(void);
|
||||||
void NetworkSendPatchSettings(ClientState *cs);
|
void NetworkSendPatchSettings(NetworkClientState *cs);
|
||||||
|
|
||||||
|
extern const char _openttd_revision[];
|
||||||
|
|
||||||
// Is the network enabled?
|
// Is the network enabled?
|
||||||
|
|
||||||
// **********
|
// **********
|
||||||
// Sending functions
|
// Sending functions
|
||||||
// DEF_SERVER_SEND_COMMAND has parameter: ClientState *cs
|
// DEF_SERVER_SEND_COMMAND has parameter: NetworkClientState *cs
|
||||||
// **********
|
// **********
|
||||||
|
|
||||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CLIENT_INFO)(ClientState *cs, NetworkClientInfo *ci)
|
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CLIENT_INFO)(NetworkClientState *cs, NetworkClientInfo *ci)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Packet: SERVER_CLIENT_INFO
|
// Packet: SERVER_CLIENT_INFO
|
||||||
|
@ -119,7 +121,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(ClientState *cs, NetworkErrorCode error)
|
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientState *cs, NetworkErrorCode error)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Packet: SERVER_ERROR
|
// Packet: SERVER_ERROR
|
||||||
|
@ -128,7 +130,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(ClientState *cs, NetworkError
|
||||||
// uint8: ErrorID (see network_data.h, NetworkErrorCode)
|
// uint8: ErrorID (see network_data.h, NetworkErrorCode)
|
||||||
//
|
//
|
||||||
|
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
char str1[100], str2[100];
|
char str1[100], str2[100];
|
||||||
char client_name[NETWORK_NAME_LENGTH];
|
char client_name[NETWORK_NAME_LENGTH];
|
||||||
|
|
||||||
|
@ -167,10 +169,10 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(ClientState *cs, NetworkError
|
||||||
NetworkSend_Packets(cs);
|
NetworkSend_Packets(cs);
|
||||||
|
|
||||||
// The client made a mistake, so drop his connection now!
|
// The client made a mistake, so drop his connection now!
|
||||||
CloseClient(cs);
|
NetworkCloseClient(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_NEED_PASSWORD)(ClientState *cs, NetworkPasswordType type)
|
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_NEED_PASSWORD)(NetworkClientState *cs, NetworkPasswordType type)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Packet: SERVER_NEED_PASSWORD
|
// Packet: SERVER_NEED_PASSWORD
|
||||||
|
@ -194,7 +196,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WELCOME)
|
||||||
//
|
//
|
||||||
|
|
||||||
Packet *p;
|
Packet *p;
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
|
|
||||||
// Invalid packet when status is AUTH or higher
|
// Invalid packet when status is AUTH or higher
|
||||||
if (cs->status >= STATUS_AUTH)
|
if (cs->status >= STATUS_AUTH)
|
||||||
|
@ -226,7 +228,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WAIT)
|
||||||
// uint8: Clients awaiting map
|
// uint8: Clients awaiting map
|
||||||
//
|
//
|
||||||
int waiting = 0;
|
int waiting = 0;
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
Packet *p;
|
Packet *p;
|
||||||
|
|
||||||
// Count how many players are waiting in the queue
|
// Count how many players are waiting in the queue
|
||||||
|
@ -327,7 +329,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP)
|
||||||
fclose(file_pointer);
|
fclose(file_pointer);
|
||||||
|
|
||||||
{
|
{
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
bool new_map_client = false;
|
bool new_map_client = false;
|
||||||
// Check if there is a client waiting for receiving the map
|
// Check if there is a client waiting for receiving the map
|
||||||
// and start sending him the map
|
// and start sending him the map
|
||||||
|
@ -364,7 +366,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_JOIN)(ClientState *cs, uint16 client_index)
|
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_JOIN)(NetworkClientState *cs, uint16 client_index)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Packet: SERVER_JOIN
|
// Packet: SERVER_JOIN
|
||||||
|
@ -430,7 +432,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SYNC)
|
||||||
NetworkSend_Packet(p, cs);
|
NetworkSend_Packet(p, cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(ClientState *cs, CommandPacket *cp)
|
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkClientState *cs, CommandPacket *cp)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Packet: SERVER_COMMAND
|
// Packet: SERVER_COMMAND
|
||||||
|
@ -470,7 +472,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(ClientState *cs, CommandPac
|
||||||
NetworkSend_Packet(p, cs);
|
NetworkSend_Packet(p, cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(ClientState *cs, NetworkAction action, uint16 client_index, const char *msg)
|
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkClientState *cs, NetworkAction action, uint16 client_index, const char *msg)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Packet: SERVER_CHAT
|
// Packet: SERVER_CHAT
|
||||||
|
@ -490,7 +492,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(ClientState *cs, NetworkAction
|
||||||
NetworkSend_Packet(p, cs);
|
NetworkSend_Packet(p, cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(ClientState *cs, uint16 client_index, NetworkErrorCode errorno)
|
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkClientState *cs, uint16 client_index, NetworkErrorCode errorno)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Packet: SERVER_ERROR_QUIT
|
// Packet: SERVER_ERROR_QUIT
|
||||||
|
@ -509,7 +511,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(ClientState *cs, uint16
|
||||||
NetworkSend_Packet(p, cs);
|
NetworkSend_Packet(p, cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(ClientState *cs, uint16 client_index, const char *leavemsg)
|
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(NetworkClientState *cs, uint16 client_index, const char *leavemsg)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Packet: SERVER_ERROR_QUIT
|
// Packet: SERVER_ERROR_QUIT
|
||||||
|
@ -556,7 +558,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME)
|
||||||
|
|
||||||
// **********
|
// **********
|
||||||
// Receiving functions
|
// Receiving functions
|
||||||
// DEF_SERVER_RECEIVE_COMMAND has parameter: ClientState *cs, Packet *p
|
// DEF_SERVER_RECEIVE_COMMAND has parameter: NetworkClientState *cs, Packet *p
|
||||||
// **********
|
// **********
|
||||||
|
|
||||||
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO)
|
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO)
|
||||||
|
@ -564,8 +566,6 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO)
|
||||||
SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)(cs);
|
SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const char _openttd_revision[];
|
|
||||||
|
|
||||||
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
|
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
|
||||||
{
|
{
|
||||||
char name[NETWORK_NAME_LENGTH];
|
char name[NETWORK_NAME_LENGTH];
|
||||||
|
@ -682,7 +682,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD)
|
||||||
|
|
||||||
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP)
|
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP)
|
||||||
{
|
{
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
|
|
||||||
// The client was never joined.. so this is impossible, right?
|
// The client was never joined.. so this is impossible, right?
|
||||||
// Ignore the packet, give the client a warning, and close his connection
|
// Ignore the packet, give the client a warning, and close his connection
|
||||||
|
@ -711,7 +711,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK)
|
||||||
if (cs->status == STATUS_DONE_MAP && !cs->quited) {
|
if (cs->status == STATUS_DONE_MAP && !cs->quited) {
|
||||||
char client_name[NETWORK_NAME_LENGTH];
|
char client_name[NETWORK_NAME_LENGTH];
|
||||||
char str[100];
|
char str[100];
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
GetString(str, STR_NETWORK_CLIENT_JOINED);
|
GetString(str, STR_NETWORK_CLIENT_JOINED);
|
||||||
|
|
||||||
NetworkGetClientName(client_name, sizeof(client_name), cs);
|
NetworkGetClientName(client_name, sizeof(client_name), cs);
|
||||||
|
@ -747,7 +747,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
|
||||||
// The client has done a command and wants us to handle it
|
// The client has done a command and wants us to handle it
|
||||||
int i;
|
int i;
|
||||||
byte callback;
|
byte callback;
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
char *dparam_char;
|
char *dparam_char;
|
||||||
|
|
||||||
|
@ -832,7 +832,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
|
||||||
{
|
{
|
||||||
// This packets means a client noticed an error and is reporting this
|
// This packets means a client noticed an error and is reporting this
|
||||||
// to us. Display the error and report it to the other clients
|
// to us. Display the error and report it to the other clients
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
byte errorno = NetworkRecv_uint8(p);
|
byte errorno = NetworkRecv_uint8(p);
|
||||||
char str1[100], str2[100];
|
char str1[100], str2[100];
|
||||||
char client_name[NETWORK_NAME_LENGTH];
|
char client_name[NETWORK_NAME_LENGTH];
|
||||||
|
@ -865,7 +865,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
|
||||||
{
|
{
|
||||||
// The client wants to leave. Display this and report it to the other
|
// The client wants to leave. Display this and report it to the other
|
||||||
// clients.
|
// clients.
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
char str1[100], str2[100];
|
char str1[100], str2[100];
|
||||||
char client_name[NETWORK_NAME_LENGTH];
|
char client_name[NETWORK_NAME_LENGTH];
|
||||||
|
|
||||||
|
@ -908,7 +908,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK)
|
||||||
|
|
||||||
void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest, const char *msg, byte from_index)
|
void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest, const char *msg, byte from_index)
|
||||||
{
|
{
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
NetworkClientInfo *ci, *ci_own, *ci_to;
|
NetworkClientInfo *ci, *ci_own, *ci_to;
|
||||||
|
|
||||||
switch (desttype) {
|
switch (desttype) {
|
||||||
|
@ -1036,7 +1036,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The layout for the receive-functions by the server
|
// The layout for the receive-functions by the server
|
||||||
typedef void NetworkServerPacket(ClientState *cs, Packet *p);
|
typedef void NetworkServerPacket(NetworkClientState *cs, Packet *p);
|
||||||
|
|
||||||
|
|
||||||
// This array matches PacketType. At an incoming
|
// This array matches PacketType. At an incoming
|
||||||
|
@ -1084,7 +1084,7 @@ extern const SettingDesc patch_settings[];
|
||||||
// This is a TEMPORARY solution to get the patch-settings
|
// This is a TEMPORARY solution to get the patch-settings
|
||||||
// to the client. When the patch-settings are saved in the savegame
|
// to the client. When the patch-settings are saved in the savegame
|
||||||
// this should be removed!!
|
// this should be removed!!
|
||||||
void NetworkSendPatchSettings(ClientState *cs)
|
void NetworkSendPatchSettings(NetworkClientState *cs)
|
||||||
{
|
{
|
||||||
const SettingDesc *item;
|
const SettingDesc *item;
|
||||||
Packet *p = NetworkSend_Init(PACKET_SERVER_MAP);
|
Packet *p = NetworkSend_Init(PACKET_SERVER_MAP);
|
||||||
|
@ -1122,7 +1122,7 @@ void NetworkPopulateCompanyInfo(void)
|
||||||
Player *p;
|
Player *p;
|
||||||
Vehicle *v;
|
Vehicle *v;
|
||||||
Station *s;
|
Station *s;
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
int i;
|
int i;
|
||||||
uint16 months_empty;
|
uint16 months_empty;
|
||||||
|
@ -1222,7 +1222,7 @@ void NetworkPopulateCompanyInfo(void)
|
||||||
// Send a packet to all clients with updated info about this client_index
|
// Send a packet to all clients with updated info about this client_index
|
||||||
void NetworkUpdateClientInfo(uint16 client_index)
|
void NetworkUpdateClientInfo(uint16 client_index)
|
||||||
{
|
{
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
|
|
||||||
ci = NetworkFindClientInfoFromIndex(client_index);
|
ci = NetworkFindClientInfoFromIndex(client_index);
|
||||||
|
@ -1242,7 +1242,7 @@ void NetworkUpdateClientInfo(uint16 client_index)
|
||||||
(and item 1. happens a year later) */
|
(and item 1. happens a year later) */
|
||||||
static void NetworkAutoCleanCompanies()
|
static void NetworkAutoCleanCompanies()
|
||||||
{
|
{
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
Player *p;
|
Player *p;
|
||||||
bool clients_in_company[MAX_PLAYERS];
|
bool clients_in_company[MAX_PLAYERS];
|
||||||
|
@ -1300,7 +1300,7 @@ static void NetworkAutoCleanCompanies()
|
||||||
// and it returns true if that succeeded.
|
// and it returns true if that succeeded.
|
||||||
bool NetworkFindName(char new_name[NETWORK_NAME_LENGTH])
|
bool NetworkFindName(char new_name[NETWORK_NAME_LENGTH])
|
||||||
{
|
{
|
||||||
ClientState *new_cs;
|
NetworkClientState *new_cs;
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
bool found_name = false;
|
bool found_name = false;
|
||||||
byte number = 0;
|
byte number = 0;
|
||||||
|
@ -1341,7 +1341,7 @@ bool NetworkFindName(char new_name[NETWORK_NAME_LENGTH])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads a packet from the stream
|
// Reads a packet from the stream
|
||||||
bool NetworkServer_ReadPackets(ClientState *cs)
|
bool NetworkServer_ReadPackets(NetworkClientState *cs)
|
||||||
{
|
{
|
||||||
Packet *p;
|
Packet *p;
|
||||||
NetworkRecvStatus res;
|
NetworkRecvStatus res;
|
||||||
|
@ -1358,7 +1358,7 @@ bool NetworkServer_ReadPackets(ClientState *cs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the local command-queue
|
// Handle the local command-queue
|
||||||
void NetworkHandleCommandQueue(ClientState *cs) {
|
void NetworkHandleCommandQueue(NetworkClientState *cs) {
|
||||||
if (cs->command_queue != NULL) {
|
if (cs->command_queue != NULL) {
|
||||||
CommandPacket *cp;
|
CommandPacket *cp;
|
||||||
CommandPacket *cp_prev;
|
CommandPacket *cp_prev;
|
||||||
|
@ -1389,7 +1389,7 @@ void NetworkServer_Tick(void)
|
||||||
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
|
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
|
||||||
static uint32 last_sync_frame = 0;
|
static uint32 last_sync_frame = 0;
|
||||||
#endif
|
#endif
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
bool send_frame = false;
|
bool send_frame = false;
|
||||||
|
|
||||||
// Update max-frame-counter
|
// Update max-frame-counter
|
||||||
|
@ -1410,7 +1410,7 @@ void NetworkServer_Tick(void)
|
||||||
// Client did still not report in after 4 game-day, drop him
|
// Client did still not report in after 4 game-day, drop him
|
||||||
// (that is, the 3 of above, + 1 before any lag is counted)
|
// (that is, the 3 of above, + 1 before any lag is counted)
|
||||||
IConsolePrintF(_iconsole_color_error,"Client #%d is dropped because the client did not respond for more then 4 game-days", cs->index);
|
IConsolePrintF(_iconsole_color_error,"Client #%d is dropped because the client did not respond for more then 4 game-days", cs->index);
|
||||||
CloseClient(cs);
|
NetworkCloseClient(cs);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1453,7 +1453,7 @@ void NetworkServer_Tick(void)
|
||||||
NetworkUDPAdvertise();
|
NetworkUDPAdvertise();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkServerMonthlyLoop()
|
void NetworkServerMonthlyLoop(void)
|
||||||
{
|
{
|
||||||
NetworkAutoCleanCompanies();
|
NetworkAutoCleanCompanies();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,17 @@
|
||||||
#ifdef ENABLE_NETWORK
|
#ifdef ENABLE_NETWORK
|
||||||
|
|
||||||
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP);
|
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP);
|
||||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(ClientState *cs, uint16 client_index, NetworkErrorCode errorno);
|
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkClientState *cs, uint16 client_index, NetworkErrorCode errorno);
|
||||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(ClientState *cs, NetworkErrorCode error);
|
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientState *cs, NetworkErrorCode error);
|
||||||
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SHUTDOWN);
|
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SHUTDOWN);
|
||||||
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME);
|
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME);
|
||||||
|
|
||||||
bool NetworkFindName(char new_name[NETWORK_NAME_LENGTH]);
|
bool NetworkFindName(char new_name[NETWORK_NAME_LENGTH]);
|
||||||
void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest, const char *msg, byte from_index);
|
void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest, const char *msg, byte from_index);
|
||||||
|
|
||||||
bool NetworkServer_ReadPackets(ClientState *cs);
|
bool NetworkServer_ReadPackets(NetworkClientState *cs);
|
||||||
void NetworkServer_Tick();
|
void NetworkServer_Tick(void);
|
||||||
void NetworkServerMonthlyLoop();
|
void NetworkServerMonthlyLoop(void);
|
||||||
|
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE)
|
||||||
|
|
||||||
DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_DETAIL_INFO)
|
DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_DETAIL_INFO)
|
||||||
{
|
{
|
||||||
ClientState *cs;
|
NetworkClientState *cs;
|
||||||
NetworkClientInfo *ci;
|
NetworkClientInfo *ci;
|
||||||
Packet *packet;
|
Packet *packet;
|
||||||
Player *player;
|
Player *player;
|
||||||
|
@ -471,7 +471,7 @@ void NetworkUDPQueryServer(const byte* host, unsigned short port)
|
||||||
|
|
||||||
/* Register us to the master server
|
/* Register us to the master server
|
||||||
This function checks if it needs to send an advertise */
|
This function checks if it needs to send an advertise */
|
||||||
void NetworkUDPAdvertise()
|
void NetworkUDPAdvertise(void)
|
||||||
{
|
{
|
||||||
struct sockaddr_in out_addr;
|
struct sockaddr_in out_addr;
|
||||||
Packet *p;
|
Packet *p;
|
||||||
|
|
|
@ -6,6 +6,6 @@ bool NetworkUDPListen(uint32 host, uint16 port);
|
||||||
void NetworkUDPReceive(void);
|
void NetworkUDPReceive(void);
|
||||||
void NetworkUDPSearchGame(void);
|
void NetworkUDPSearchGame(void);
|
||||||
void NetworkUDPQueryServer(const byte* host, unsigned short port);
|
void NetworkUDPQueryServer(const byte* host, unsigned short port);
|
||||||
void NetworkUDPAdvertise();
|
void NetworkUDPAdvertise(void);
|
||||||
|
|
||||||
#endif /* NETWORK_LAN_H */
|
#endif /* NETWORK_LAN_H */
|
||||||
|
|
Loading…
Reference in New Issue