diff options
Diffstat (limited to 'src/user.c')
| -rw-r--r-- | src/user.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -591,6 +591,32 @@ void l2_user_delete(struct l2_user *user) } } +struct l2_user *l2_user_search(const char *searchstr) +{ + uuid_t uuid; + bool have_uuid = false; + + if (l2_uuid_from_string(&uuid, searchstr) == 0) { + have_uuid = true; + } else { + if (l2_uuid_from_string_short(&uuid, searchstr) == 0) { + have_uuid = true; + } + } + + for (struct l2_user *cur = l2_state.users_head; cur; cur = cur->next) { + if (have_uuid && !l2_uuid_compare(&cur->profile.uuid, &uuid)) { + return cur; + } else if (cur->nickname && !strcmp(searchstr, cur->nickname)) { + return cur; + } else if (!strcmp(searchstr, cur->profile.name)) { + return cur; + } + } + + return NULL; +} + void l2_user_init(struct l2_user *user) { /* using calloc works as well, so that's what we do in this file (elsewhere should use this function though) */ |
