X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fclient.c;h=367f18dee165e383f892b9c4ae3f2e979a8a4759;hb=454ad122eb158b4391e2690fe6a7e127d24c525b;hp=963ec4dd5fb8b1b62a4acb1d99fa59500cd00c33;hpb=4c75c8f9eb45c0a696f992c277dcc8ffb77fa3ba;p=umurmur.git diff --git a/src/client.c b/src/client.c index 963ec4d..367f18d 100644 --- a/src/client.c +++ b/src/client.c @@ -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; @@ -505,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) { @@ -577,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) &&