|
@@ -83,13 +83,13 @@ void NetworkSend_string(Packet *packet,
|
|
|
assert_compile(sizeof(PacketSize) == 2);
|
|
|
|
|
|
// This function puts the packet in the send-queue and it is send
|
|
|
// as soon as possible
|
|
|
// (that is: the next tick, or maybe one tick later if the
|
|
|
// OS-network-buffer is full)
|
|
|
void NetworkSend_Packet(Packet *packet, ClientState *cs)
|
|
|
void NetworkSend_Packet(Packet *packet, NetworkClientState *cs)
|
|
|
{
|
|
|
Packet *p;
|
|
|
assert(packet != NULL);
|
|
|
|
|
|
packet->pos = 0;
|
|
|
packet->next = NULL;
|
|
@@ -111,15 +111,15 @@ void NetworkSend_Packet(Packet *packet,
|
|
|
|
|
|
// Functions to help NetworkRecv_Packet/NetworkSend_Packet a bit
|
|
|
// A socket can make errors. When that happens
|
|
|
// this handles what to do.
|
|
|
// For clients: close connection and drop back to main-menu
|
|
|
// 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
|
|
|
if (!_network_server) {
|
|
|
_switch_mode = SM_MENU;
|
|
|
_networking = false;
|
|
|
_switch_mode_errorstr = STR_NETWORK_ERR_LOSTCONNECTION;
|
|
@@ -133,13 +133,13 @@ NetworkRecvStatus CloseConnection(Client
|
|
|
// Sends all the buffered packets out for this client
|
|
|
// it stops when:
|
|
|
// 1) all packets are send (queue is empty)
|
|
|
// 2) the OS reports back that it can not send any more
|
|
|
// data right now (full network-buffer, it happens ;))
|
|
|
// 3) sending took too long
|
|
|
bool NetworkSend_Packets(ClientState *cs)
|
|
|
bool NetworkSend_Packets(NetworkClientState *cs)
|
|
|
{
|
|
|
ssize_t res;
|
|
|
Packet *p;
|
|
|
|
|
|
// We can not write to this socket!!
|
|
|
if (!cs->writable) return false;
|
|
@@ -239,13 +239,13 @@ void NetworkRecv_string(Packet *p, char*
|
|
|
|
|
|
// If PacketSize changes of size, you have to change the 2 packet->size
|
|
|
// lines below matching the size of packet->size/PacketSize!
|
|
|
// (the line: 'p->size = (uint16)p->buffer[0];' and below)
|
|
|
assert_compile(sizeof(PacketSize) == 2);
|
|
|
|
|
|
Packet *NetworkRecv_Packet(ClientState *cs, NetworkRecvStatus *status)
|
|
|
Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
|
|
|
{
|
|
|
ssize_t res;
|
|
|
Packet *p;
|
|
|
|
|
|
*status = NETWORK_RECV_STATUS_OKAY;
|
|
|
|
|
@@ -327,13 +327,13 @@ Packet *NetworkRecv_Packet(ClientState *
|
|
|
cs->packet_recv = NULL;
|
|
|
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
// 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));
|
|
|
|
|
|
*new_cp = *cp;
|
|
|
|
|
|
if (cs->command_queue == NULL)
|
|
@@ -387,13 +387,13 @@ void NetworkSend_Command(uint32 tile, ui
|
|
|
if (_network_server) {
|
|
|
// If we are the server, we queue the command in our 'special' queue.
|
|
|
// In theory, we could execute the command right away, but then the
|
|
|
// 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
|
|
|
// which gives about the same speed as most clients.
|
|
|
ClientState *cs;
|
|
|
NetworkClientState *cs;
|
|
|
|
|
|
// And we queue it for delivery to the clients
|
|
|
FOR_ALL_CLIENTS(cs) {
|
|
|
if (cs->status > STATUS_AUTH) {
|
|
|
NetworkAddCommandQueue(cs, c);
|
|
|
}
|