/[LeafOK_CVS]/lbbs/src/bbs.c
ViewVC logotype

Contents of /lbbs/src/bbs.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.42 - (show annotations)
Sat Jan 3 10:27:14 2026 UTC (2 months, 1 week ago) by sysadm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.41: +1 -1 lines
Content type: text/x-csrc
Update copyright info

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

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1