| 106 |
{ |
{ |
| 107 |
return 1; |
return 1; |
| 108 |
} |
} |
| 109 |
|
else if (p1->id < p2->id) |
| 110 |
|
{ |
| 111 |
|
return -1; |
| 112 |
|
} |
| 113 |
|
else if (p1->id > p2->id) |
| 114 |
|
{ |
| 115 |
|
return 1; |
| 116 |
|
} |
| 117 |
return 0; |
return 0; |
| 118 |
} |
} |
| 119 |
|
|
| 124 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 125 |
int ret = 0; |
int ret = 0; |
| 126 |
int i; |
int i; |
| 127 |
|
int32_t last_uid = -1; |
| 128 |
|
|
| 129 |
if (db == NULL || p_list == NULL) |
if (db == NULL || p_list == NULL) |
| 130 |
{ |
{ |
| 132 |
return -1; |
return -1; |
| 133 |
} |
} |
| 134 |
|
|
| 135 |
|
if (p_list->user_count > 0) |
| 136 |
|
{ |
| 137 |
|
last_uid = p_list->users[p_list->user_count - 1].uid; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 141 |
"SELECT user_list.UID AS UID, username, nickname, gender, gender_pub, life, exp, " |
"SELECT user_list.UID AS UID, username, nickname, gender, gender_pub, life, exp, " |
| 142 |
"UNIX_TIMESTAMP(signup_dt), UNIX_TIMESTAMP(last_login_dt), UNIX_TIMESTAMP(birthday) " |
"UNIX_TIMESTAMP(signup_dt), UNIX_TIMESTAMP(last_login_dt), UNIX_TIMESTAMP(birthday) " |
| 190 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 191 |
rs = NULL; |
rs = NULL; |
| 192 |
|
|
|
p_list->user_count = i; |
|
|
|
|
| 193 |
// Sort index |
// Sort index |
| 194 |
qsort(p_list->index_uid, (size_t)i, sizeof(USER_INFO_INDEX_UID), user_info_index_uid_comp); |
if (i != p_list->user_count || p_list->users[i - 1].uid != last_uid) // Count of users changed |
| 195 |
|
{ |
| 196 |
|
qsort(p_list->index_uid, (size_t)i, sizeof(USER_INFO_INDEX_UID), user_info_index_uid_comp); |
| 197 |
|
#ifdef _DEBUG |
| 198 |
|
log_error("Rebuild index of %d users, last_uid=%d\n", i, p_list->users[i - 1].uid); |
| 199 |
|
#endif |
| 200 |
|
} |
| 201 |
|
|
| 202 |
|
p_list->user_count = i; |
| 203 |
|
|
| 204 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 205 |
log_error("Loaded %d users\n", p_list->user_count); |
log_error("Loaded %d users\n", p_list->user_count); |
| 283 |
p_list->users[i].login_tm = (row[4] == NULL ? 0 : atol(row[4])); |
p_list->users[i].login_tm = (row[4] == NULL ? 0 : atol(row[4])); |
| 284 |
p_list->users[i].last_tm = (row[5] == NULL ? 0 : atol(row[5])); |
p_list->users[i].last_tm = (row[5] == NULL ? 0 : atol(row[5])); |
| 285 |
|
|
| 286 |
|
// index |
| 287 |
|
p_list->index_uid[i].uid = p_list->users[i].user_info.uid; |
| 288 |
|
p_list->index_uid[i].id = i; |
| 289 |
|
|
| 290 |
i++; |
i++; |
| 291 |
if (i >= BBS_max_user_online_count) |
if (i >= BBS_max_user_online_count) |
| 292 |
{ |
{ |
| 297 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 298 |
rs = NULL; |
rs = NULL; |
| 299 |
|
|
| 300 |
|
// Sort index |
| 301 |
|
if (i > 0) |
| 302 |
|
{ |
| 303 |
|
qsort(p_list->index_uid, (size_t)i, sizeof(USER_INFO_INDEX_UID), user_info_index_uid_comp); |
| 304 |
|
#ifdef _DEBUG |
| 305 |
|
log_error("Rebuild index of %d online users\n", i); |
| 306 |
|
#endif |
| 307 |
|
} |
| 308 |
|
|
| 309 |
p_list->user_count = i; |
p_list->user_count = i; |
| 310 |
|
|
| 311 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 312 |
log_error("Loaded %d users\n", p_list->user_count); |
log_error("Loaded %d online users\n", p_list->user_count); |
| 313 |
#endif |
#endif |
| 314 |
|
|
| 315 |
cleanup: |
cleanup: |
| 512 |
log_error("user_online_list_load() error\n"); |
log_error("user_online_list_load() error\n"); |
| 513 |
return -2; |
return -2; |
| 514 |
} |
} |
| 515 |
|
|
| 516 |
|
// No online user, no need to swap lists |
| 517 |
|
if (p_user_list_pool->p_online_current->user_count == 0 && p_user_list_pool->p_online_new->user_count == 0) |
| 518 |
|
{ |
| 519 |
|
return 0; |
| 520 |
|
} |
| 521 |
} |
} |
| 522 |
else |
else |
| 523 |
{ |
{ |