Use Client_find_by_session() instead of a few open-coded loops.
[umurmur.git] / src / client.c
index 240700e1253f1c270a6239c050289714dcbc8f70..8f5fb7316b3e365a6afdf5ee51581eadab9ef025 100644 (file)
@@ -427,6 +427,21 @@ void Client_disconnect_all()
        }
 }
 
+client_t *Client_find_by_session(int session_id)
+{
+       struct dlist *itr;
+
+       list_iterate(itr, &clients) {
+               client_t *client = list_get_entry(itr, client_t, node);
+
+               if (client->sessionId == session_id) {
+                       return client;
+               }
+       }
+
+       return NULL;
+}
+
 client_t *Client_find_by_fd(int fd)
 {
        struct dlist *itr;
@@ -986,11 +1001,11 @@ int Client_voiceMsg(client_t *client, uint8_t *data, int len)
                        client_t *c = NULL;
                        buffer[0] = (uint8_t) (type | 2);
                        Log_debug("Whisper session %d", vt->sessions[i]);
-                       while (Client_iterate(&c) != NULL) {
-                               if (c->sessionId == vt->sessions[i]) {
-                                       Client_send_voice(client, c, buffer, pds->offset + 1, poslen);
-                                       break;
-                               }
+
+                       c = Client_find_by_session(vt->sessions[i]);
+
+                       if (c != NULL) {
+                               Client_send_voice(client, c, buffer, pds->offset + 1, poslen);
                        }
                }
        }