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

Contents of /lbbs/src/bbs.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.38 - (show annotations)
Wed Nov 5 04:19:21 2025 UTC (4 months, 1 week ago) by sysadm
Branch: MAIN
Changes since 1.37: +5 -2 lines
Content type: text/x-csrc
Use enum / const int instead of macro define constant integers
Use const char * instead of macro define for constant strings

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

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