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

Contents of /lbbs/src/bbs.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.37 - (show annotations)
Tue Nov 4 14:58:56 2025 UTC (4 months, 1 week ago) by sysadm
Branch: MAIN
Changes since 1.36: +1 -1 lines
Content type: text/x-csrc
Refine file header information comments

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

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