| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
user_list.c - description |
/* |
| 3 |
------------------- |
* user_list |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - data model and basic operations of (online) user list |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
| 8 |
/*************************************************************************** |
|
| 9 |
* * |
#ifdef HAVE_CONFIG_H |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
#include "config.h" |
| 11 |
* it under the terms of the GNU General Public License as published by * |
#endif |
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 12 |
|
|
| 13 |
#include "common.h" |
#include "common.h" |
| 14 |
#include "database.h" |
#include "database.h" |
| 37 |
}; |
}; |
| 38 |
#endif // #ifdef _SEM_SEMUN_UNDEFINED |
#endif // #ifdef _SEM_SEMUN_UNDEFINED |
| 39 |
|
|
| 40 |
#define USER_LIST_TRY_LOCK_WAIT_TIME 1 // second |
enum _user_list_constant_t |
| 41 |
#define USER_LIST_TRY_LOCK_TIMES 10 |
{ |
| 42 |
|
USER_LIST_TRY_LOCK_WAIT_TIME = 1, // second |
| 43 |
|
USER_LIST_TRY_LOCK_TIMES = 10, |
| 44 |
|
}; |
| 45 |
|
|
| 46 |
struct user_list_pool_t |
struct user_list_pool_t |
| 47 |
{ |
{ |
| 188 |
p_list->users[i].signup_dt = (row[8] == NULL ? 0 : atol(row[8])); |
p_list->users[i].signup_dt = (row[8] == NULL ? 0 : atol(row[8])); |
| 189 |
p_list->users[i].last_login_dt = (row[9] == NULL ? 0 : atol(row[9])); |
p_list->users[i].last_login_dt = (row[9] == NULL ? 0 : atol(row[9])); |
| 190 |
p_list->users[i].last_logout_dt = (row[10] == NULL ? 0 : atol(row[10])); |
p_list->users[i].last_logout_dt = (row[10] == NULL ? 0 : atol(row[10])); |
| 191 |
p_list->users[i].birthday = (row[10] == NULL ? 0 : atol(row[11])); |
p_list->users[i].birthday = (row[11] == NULL ? 0 : atol(row[11])); |
| 192 |
intro_len = strlen((row[12] == NULL ? "" : row[12])); |
intro_len = strlen((row[12] == NULL ? "" : row[12])); |
| 193 |
if (intro_len >= sizeof(p_list->user_intro_buf) - 1 - intro_buf_offset) |
if (intro_len >= sizeof(p_list->user_intro_buf) - 1 - intro_buf_offset) |
| 194 |
{ |
{ |
| 342 |
} |
} |
| 343 |
|
|
| 344 |
qsort(p_online_list->index_uid, (size_t)user_cnt, sizeof(USER_INFO_INDEX_UID), user_info_index_uid_comp); |
qsort(p_online_list->index_uid, (size_t)user_cnt, sizeof(USER_INFO_INDEX_UID), user_info_index_uid_comp); |
|
|
|
|
#ifdef _DEBUG |
|
|
log_error("Rebuild index of %d online users\n", user_cnt); |
|
|
#endif |
|
| 345 |
} |
} |
| 346 |
|
|
| 347 |
p_online_list->user_count = user_cnt; |
p_online_list->user_count = user_cnt; |
| 348 |
p_online_list->guest_count = guest_cnt; |
p_online_list->guest_count = guest_cnt; |
| 349 |
|
|
|
#ifdef _DEBUG |
|
|
log_error("Loaded %d online users and %d guest users\n", p_list->user_count, p_list->guest_count); |
|
|
#endif |
|
|
|
|
| 350 |
cleanup: |
cleanup: |
| 351 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 352 |
|
|
| 502 |
log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno); |
log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno); |
| 503 |
} |
} |
| 504 |
|
|
| 505 |
if (shmctl(shmid, IPC_RMID, NULL) == -1) |
if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1) |
| 506 |
{ |
{ |
| 507 |
log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno); |
log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno); |
| 508 |
} |
} |