| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
bbs.c - description |
bbs.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 18 2004 |
Copyright : (C) 2004-2025 by Leaflet |
| 5 |
copyright : (C) 2004 by Leaflet |
Email : leaflet@leafok.com |
|
email : leaflet@leafok.com |
|
| 6 |
***************************************************************************/ |
***************************************************************************/ |
| 7 |
|
|
| 8 |
/*************************************************************************** |
/*************************************************************************** |
| 9 |
* * |
* * |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
| 11 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
| 12 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 3 of the License, or * |
| 13 |
* (at your option) any later version. * |
* (at your option) any later version. * |
| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
| 17 |
#include "bbs.h" |
#include "bbs.h" |
| 18 |
|
#include "common.h" |
| 19 |
|
#include "user_priv.h" |
| 20 |
|
#include <limits.h> |
| 21 |
|
#include <stdio.h> |
| 22 |
#include <signal.h> |
#include <signal.h> |
| 23 |
#include <time.h> |
#include <time.h> |
| 24 |
|
|
| 25 |
//BBS enviroment |
#define BBS_port_default 23 |
| 26 |
char BBS_id[20] = ""; |
#define BBS_ssh_port_default 22 |
| 27 |
char BBS_name[50] = ""; |
|
| 28 |
char BBS_server[256] = ""; |
// BBS enviroment |
| 29 |
char BBS_address[50] = ""; |
char BBS_id[BBS_id_max_len + 1] = "Example BBS"; |
| 30 |
unsigned int BBS_port = 23; |
char BBS_name[BBS_name_max_len + 1] = "Example Site Name"; |
| 31 |
long BBS_max_client = 256; |
char BBS_server[BBS_server_max_len + 1] = "bbs.example.com"; |
| 32 |
long BBS_max_user = 10000; |
char BBS_address[BBS_address_max_len + 1] = "0.0.0.0"; |
| 33 |
char BBS_start_dt[50] = "2004�� 1�� 1��"; |
in_port_t BBS_port[2] = {BBS_port_default, BBS_ssh_port_default}; |
| 34 |
|
int BBS_max_client = MAX_CLIENT_LIMIT; |
| 35 |
char BBS_username[BBS_max_username_length]; |
int BBS_max_client_per_ip = MAX_CLIENT_PER_IP_LIMIT; |
| 36 |
BBS_user_priv BBS_priv; |
char BBS_start_dt[BBS_start_dt_max_len + 1] = "2000年 1月 1日"; |
| 37 |
int BBS_passwd_complex = 0; |
int BBS_sys_id = 1; |
| 38 |
int BBS_user_money = 0; |
|
| 39 |
|
const int BBS_section_list_load_interval = 5; // second |
| 40 |
|
|
| 41 |
|
// User |
| 42 |
|
const int BBS_user_list_load_interval = 60; // 1 minute |
| 43 |
|
const int BBS_user_online_list_load_interval = 5; // 5 seconds |
| 44 |
|
const int BBS_user_off_line = 900; // 15 minutes |
| 45 |
|
|
| 46 |
|
char BBS_username[BBS_username_max_len + 1]; |
| 47 |
|
char BBS_nickname[BBS_nickname_max_len + 1]; |
| 48 |
|
char BBS_user_tz[BBS_user_tz_max_len + 1]; |
| 49 |
|
int BBS_user_exp; |
| 50 |
|
|
| 51 |
time_t BBS_login_tm; |
time_t BBS_login_tm; |
| 52 |
time_t BBS_last_access_tm; |
time_t BBS_last_access_tm; |
|
time_t BBS_last_sub_tm; |
|
| 53 |
|
|
| 54 |
char BBS_current_section_name[20]; |
char BBS_current_action[BBS_current_action_max_len + 1]; |
| 55 |
|
time_t BBS_current_action_tm; |
| 56 |
|
|
| 57 |
|
const int BBS_current_action_refresh_interval = 60; // 1 minute |
| 58 |
|
|
| 59 |
|
static const int astro_dates[] = { |
| 60 |
|
21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22}; |
| 61 |
|
|
| 62 |
|
static const char *astro_names[] = { |
| 63 |
|
"摩羯", "水瓶", "双鱼", "白羊", "金牛", "双子", "巨蟹", "狮子", "处女", "天秤", "天蝎", "射手", "摩羯"}; |
| 64 |
|
|
| 65 |
|
static const int BBS_user_level_points[] = { |
| 66 |
|
INT_MIN, // 0 |
| 67 |
|
50, // 1 |
| 68 |
|
200, // 2 |
| 69 |
|
500, // 3 |
| 70 |
|
1000, // 4 |
| 71 |
|
2000, // 5 |
| 72 |
|
5000, // 6 |
| 73 |
|
10000, // 7 |
| 74 |
|
20000, // 8 |
| 75 |
|
30000, // 9 |
| 76 |
|
50000, // 10 |
| 77 |
|
60000, // 11 |
| 78 |
|
70000, // 12 |
| 79 |
|
80000, // 13 |
| 80 |
|
90000, // 14 |
| 81 |
|
100000, // 15 |
| 82 |
|
INT_MAX, // 16 |
| 83 |
|
}; |
| 84 |
|
|
| 85 |
|
static const char *BBS_user_level_names[] = { |
| 86 |
|
"新手上路", // 0 |
| 87 |
|
"初来乍练", // 1 |
| 88 |
|
"白手起家", // 2 |
| 89 |
|
"略懂一二", // 3 |
| 90 |
|
"小有作为", // 4 |
| 91 |
|
"对答如流", // 5 |
| 92 |
|
"精于此道", // 6 |
| 93 |
|
"博大精深", // 7 |
| 94 |
|
"登峰造极", // 8 |
| 95 |
|
"论坛砥柱", // 9 |
| 96 |
|
"☆☆☆☆☆", // 10 |
| 97 |
|
"★☆☆☆☆", // 11 |
| 98 |
|
"★★☆☆☆", // 12 |
| 99 |
|
"★★★☆☆", // 13 |
| 100 |
|
"★★★★☆", // 14 |
| 101 |
|
"★★★★★", // 15 |
| 102 |
|
}; |
| 103 |
|
|
| 104 |
|
static const int BBS_user_level_cnt = sizeof(BBS_user_level_names) / sizeof(const char *); |
| 105 |
|
|
| 106 |
|
const char *get_astro_name(time_t birthday) |
| 107 |
|
{ |
| 108 |
|
struct tm tm_birth; |
| 109 |
|
|
| 110 |
|
gmtime_r(&birthday, &tm_birth); |
| 111 |
|
|
| 112 |
char * |
if (tm_birth.tm_mday < astro_dates[tm_birth.tm_mon]) |
| 113 |
setuserfile (char *buf, const char *filename) |
{ |
| 114 |
|
return astro_names[tm_birth.tm_mon]; |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
return astro_names[tm_birth.tm_mon + 1]; |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
int get_user_level(int point) |
| 121 |
|
{ |
| 122 |
|
int left; |
| 123 |
|
int right; |
| 124 |
|
int mid; |
| 125 |
|
|
| 126 |
|
left = 0; |
| 127 |
|
right = BBS_user_level_cnt - 1; |
| 128 |
|
|
| 129 |
|
while (left < right) |
| 130 |
|
{ |
| 131 |
|
mid = (left + right) / 2; |
| 132 |
|
if (point < BBS_user_level_points[mid + 1]) |
| 133 |
|
{ |
| 134 |
|
right = mid; |
| 135 |
|
} |
| 136 |
|
else if (point > BBS_user_level_points[mid + 1]) |
| 137 |
|
{ |
| 138 |
|
left = mid + 1; |
| 139 |
|
} |
| 140 |
|
else // if (point == user_level_points[mid]) |
| 141 |
|
{ |
| 142 |
|
left = mid + 1; |
| 143 |
|
break; |
| 144 |
|
} |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
return left; |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
const char *get_user_level_name(int level) |
| 151 |
{ |
{ |
| 152 |
sprintf (buf, "data/%s/%ld", filename, BBS_priv.uid); |
return BBS_user_level_names[level]; |
|
return buf; |
|
| 153 |
} |
} |
| 154 |
|
|
| 155 |
char * |
char *setuserfile(char *buf, size_t len, const char *filename) |
| 156 |
sethomefile (char *buf, long int uid, char *filename) { |
{ |
| 157 |
sprintf (buf, "data/%s/%ld", filename, uid); |
snprintf(buf, len, "%s/%d", filename, BBS_priv.uid); |
| 158 |
return buf; |
return buf; |
| 159 |
} |
} |