| 30 |
#include <regex.h> |
#include <regex.h> |
| 31 |
#include <unistd.h> |
#include <unistd.h> |
| 32 |
#include <mysql/mysql.h> |
#include <mysql/mysql.h> |
| 33 |
|
#include <sys/param.h> |
| 34 |
|
|
| 35 |
int bbs_login(void) |
int bbs_login(void) |
| 36 |
{ |
{ |
| 488 |
{ |
{ |
| 489 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 490 |
|
|
| 491 |
if (user_online_del(db) != 0) |
snprintf(sql, sizeof(sql), |
| 492 |
|
"INSERT INTO visit_log(dt, IP) VALUES(NOW(), '%s')", |
| 493 |
|
hostaddr_client); |
| 494 |
|
if (mysql_query(db, sql) != 0) |
| 495 |
{ |
{ |
| 496 |
|
log_error("Add visit log error: %s\n", mysql_error(db)); |
| 497 |
return -1; |
return -1; |
| 498 |
} |
} |
| 499 |
|
|
| 500 |
|
if (user_online_del(db) != 0) |
| 501 |
|
{ |
| 502 |
|
return -2; |
| 503 |
|
} |
| 504 |
|
|
| 505 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 506 |
"INSERT INTO user_online(SID, UID, ip, login_tm, last_tm) " |
"INSERT INTO user_online(SID, UID, ip, current_action, login_tm, last_tm) " |
| 507 |
"VALUES('Telnet_Process_%d', %d, '%s', NOW(), NOW())", |
"VALUES('Telnet_Process_%d', %d, '%s', 'LOGIN', NOW(), NOW())", |
| 508 |
getpid(), BBS_priv.uid, hostaddr_client); |
getpid(), BBS_priv.uid, hostaddr_client); |
| 509 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 510 |
{ |
{ |
| 511 |
log_error("Add user_online error: %s\n", mysql_error(db)); |
log_error("Add user_online error: %s\n", mysql_error(db)); |
| 512 |
return -1; |
return -3; |
| 513 |
} |
} |
| 514 |
|
|
| 515 |
return 0; |
return 0; |
| 531 |
return 0; |
return 0; |
| 532 |
} |
} |
| 533 |
|
|
| 534 |
|
int user_online_exp(MYSQL *db) |
| 535 |
|
{ |
| 536 |
|
char sql[SQL_BUFFER_LEN]; |
| 537 |
|
|
| 538 |
|
// +1 exp for every 5 minutes online since last logout |
| 539 |
|
// but at most 24 hours worth of exp can be gained in Telnet session |
| 540 |
|
snprintf(sql, sizeof(sql), |
| 541 |
|
"UPDATE user_pubinfo SET exp = exp + FLOOR(LEAST(TIMESTAMPDIFF(" |
| 542 |
|
"SECOND, GREATEST(last_login_dt, IF(last_logout_dt IS NULL, last_login_dt, last_logout_dt)), NOW()" |
| 543 |
|
") / 60 / 5, 12 * 24)), last_logout_dt = NOW() " |
| 544 |
|
"WHERE UID = %d", |
| 545 |
|
BBS_priv.uid); |
| 546 |
|
if (mysql_query(db, sql) != 0) |
| 547 |
|
{ |
| 548 |
|
log_error("Update user_pubinfo error: %s\n", mysql_error(db)); |
| 549 |
|
return -1; |
| 550 |
|
} |
| 551 |
|
|
| 552 |
|
return 0; |
| 553 |
|
} |
| 554 |
|
|
| 555 |
int user_online_update(const char *action) |
int user_online_update(const char *action) |
| 556 |
{ |
{ |
| 557 |
MYSQL *db = NULL; |
MYSQL *db = NULL; |
| 579 |
} |
} |
| 580 |
|
|
| 581 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 582 |
"UPDATE user_online SET current_action = '%s', last_tm=NOW() " |
"UPDATE user_online SET current_action = '%s', last_tm = NOW() " |
| 583 |
"WHERE SID = 'Telnet_Process_%d'", |
"WHERE SID = 'Telnet_Process_%d'", |
| 584 |
BBS_current_action, getpid()); |
BBS_current_action, getpid()); |
| 585 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |