- if (clients) {
- len = 0;
- freebase = TRUE;
- while ((entry = silc_dlist_get(clients))) {
- if (entry->internal.valid && entry != client_entry)
- len++;
- if (entry->internal.valid && entry != client_entry &&
- silc_utf8_strcasecmp(entry->nickname, client_entry->nickname)) {
- freebase = FALSE;
- unformatted = entry;
- }
+ /* Is the requested client formatted already */
+ if (client_entry->nickname_normalized &&
+ !silc_utf8_strcasecmp(client_entry->nickname,
+ client_entry->nickname_normalized))
+ formatted = TRUE;
+
+ if (client->internal->params->nickname_force_format)
+ formatted = FALSE;
+
+ /* Find unformatted client entry */
+ while ((entry = silc_dlist_get(clients))) {
+ if (!entry->internal.valid)
+ continue;
+ if (entry == client_entry)
+ continue;
+ if (silc_utf8_strcasecmp(entry->nickname, entry->nickname_normalized)) {
+ unformatted = entry;
+ break;
+ }
+ }
+
+ /* If there are no other unformatted clients and the requested client is
+ unformatted, just return it. */
+ if (!unformatted && !formatted) {
+ silc_client_list_free(client, conn, clients);
+ return client_entry;
+ }
+
+ /* If priority formatting then the requested client will get the
+ unformatted nickname, and the unformatted client will get a new
+ formatted nickname. */
+ if (priority) {
+ if (formatted) {
+ /* Simply change the client's nickname to unformatted */
+ if (!silc_client_nickname_parse(client, conn, client_entry->nickname,
+ &cp))
+ return NULL;
+
+ silc_snprintf(client_entry->nickname, sizeof(client_entry->nickname),
+ cp);
+ silc_free(cp);