X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fclient.c;h=2ad53ba983273dbee7256d925a9b210829cb7826;hb=4a60669fa1d85ec4644acaed84bad7ac8f79fdba;hp=e515a454e0082ae731d4bc9b15f3fa24c0730b76;hpb=14a67bc74c81651015bbbad075f7eb1c41218cf7;p=umurmur.git diff --git a/src/client.c b/src/client.c index e515a45..2ad53ba 100644 --- a/src/client.c +++ b/src/client.c @@ -1,5 +1,5 @@ -/* Copyright (C) 2009-2010, Martin Johansson - Copyright (C) 2005-2010, Thorvald Natvig +/* Copyright (C) 2009-2011, Martin Johansson + Copyright (C) 2005-2011, Thorvald Natvig All rights reserved. @@ -200,7 +200,7 @@ void recheckCodecVersions() // it as alpha and announce it. If another codec now got the // majority set it as the opposite of the currently valid bPreferAlpha // and announce it. - if (version == (uint32_t)0x8000000a) + if (version == (uint32_t)0x8000000b) bPreferAlpha = true; else bPreferAlpha = ! bPreferAlpha; @@ -211,8 +211,8 @@ void recheckCodecVersions() iCodecBeta = version; sendmsg = Msg_create(CodecVersion); - sendmsg->payload.codecVersion->alpha = version; - sendmsg->payload.codecVersion->beta = version; + sendmsg->payload.codecVersion->alpha = iCodecAlpha; + sendmsg->payload.codecVersion->beta = iCodecBeta; sendmsg->payload.codecVersion->prefer_alpha = bPreferAlpha; Client_send_message_except(NULL, sendmsg); @@ -259,6 +259,8 @@ int Client_add(int fd, struct sockaddr_in *remote) } newclient->availableBandwidth = maxBandwidth; Timer_init(&newclient->lastActivity); + Timer_init(&newclient->connectTime); + Timer_init(&newclient->idleTime); newclient->sessionId = findFreeSessionId(); if (newclient->sessionId < 0) Log_fatal("Could not find a free session ID"); @@ -317,6 +319,8 @@ void Client_free(client_t *client) free(client->release); if (client->os) free(client->os); + if (client->os_version) + free(client->os_version); if (client->username) free(client->username); if (client->context) @@ -350,10 +354,10 @@ int Client_read_fd(int fd) break; } } - if (client == NULL) - Log_fatal("No client found for fd %d", fd); - - return Client_read(client); + if (client != NULL) + return Client_read(client); + else + return -1; } int Client_read(client_t *client) @@ -453,10 +457,10 @@ int Client_write_fd(int fd) break; } } - if (client == NULL) - Log_fatal("No client found for fd %d", fd); - Client_write(client); - return 0; + if (client != NULL) + return Client_write(client); + else + return -1; } int Client_write(client_t *client) @@ -501,6 +505,15 @@ int Client_write(client_t *client) return 0; } +int Client_send_message_ver(client_t *client, message_t *msg, uint32_t version) +{ + if ((version == 0) || (client->version >= version) || + ((version & 0x80000000) && (client->version < (~version)))) + return Client_send_message(client, msg); + else + Msg_free(msg); +} + int Client_send_message(client_t *client, message_t *msg) { if (!client->authenticated && msg->messageType != Version) { @@ -573,6 +586,29 @@ int Client_send_message_except(client_t *client, message_t *msg) return 0; } +int Client_send_message_except_ver(client_t *client, message_t *msg, uint32_t version) +{ + client_t *itr = NULL; + int count = 0; + + Msg_inc_ref(msg); /* Make sure a reference is held during the whole iteration. */ + while (Client_iterate(&itr) != NULL) { + if (itr != client) { + if (count++ > 0) + Msg_inc_ref(msg); /* One extra reference for each new copy */ + Log_debug("Msg %d to %s refcount %d", msg->messageType, itr->username, msg->refcount); + Client_send_message_ver(itr, msg, version); + } + } + Msg_free(msg); /* Free our reference to the message */ + + if (count == 0) + Msg_free(msg); /* If only 1 client is connected then no message is passed + * to Client_send_message(). Free it here. */ + + return 0; +} + static bool_t checkDecrypt(client_t *client, const uint8_t *encrypted, uint8_t *plain, unsigned int len) { if (CryptState_isValid(&client->cryptState) && @@ -654,7 +690,6 @@ int Client_read_udp() memcpy(&itr->remote_udp, &from, sizeof(struct sockaddr_in)); break; } - else Log_warn("Bad cryptstate from peer"); } } /* while */ } @@ -719,6 +754,8 @@ int Client_voiceMsg(client_t *client, uint8_t *data, int len) goto out; /* Discard */ client->availableBandwidth -= packetsize; + Timer_restart(&client->idleTime); + counter = Pds_get_numval(pdi); /* step past session id */ do { counter = Pds_next8(pdi);