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

Annotation of /lbbs/src/bbs.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.35 - (hide annotations)
Mon Nov 3 15:08:54 2025 UTC (4 months, 1 week ago) by sysadm
Branch: MAIN
Changes since 1.34: +1 -1 lines
Content type: text/x-csrc
Reduce BBS_section_list_load_interval from 5 seconds to 1 second, to reduce update letency of article operations.

1 sysadm 1.1 /***************************************************************************
2 sysadm 1.8 bbs.c - description
3     -------------------
4 sysadm 1.15 Copyright : (C) 2004-2025 by Leaflet
5     Email : leaflet@leafok.com
6 sysadm 1.1 ***************************************************************************/
7    
8     /***************************************************************************
9     * *
10     * 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 *
12 sysadm 1.15 * the Free Software Foundation; either version 3 of the License, or *
13 sysadm 1.1 * (at your option) any later version. *
14     * *
15     ***************************************************************************/
16    
17 sysadm 1.3 #include "bbs.h"
18 sysadm 1.20 #include "common.h"
19 sysadm 1.10 #include "user_priv.h"
20 sysadm 1.32 #include <limits.h>
21 sysadm 1.10 #include <stdio.h>
22 sysadm 1.7 #include <signal.h>
23 sysadm 1.3 #include <time.h>
24    
25 sysadm 1.22 #define BBS_port_default 23
26     #define BBS_ssh_port_default 22
27    
28 sysadm 1.8 // BBS enviroment
29 sysadm 1.20 char BBS_id[BBS_id_max_len + 1] = "Example BBS";
30     char BBS_name[BBS_name_max_len + 1] = "Example Site Name";
31     char BBS_server[BBS_server_max_len + 1] = "bbs.example.com";
32     char BBS_address[BBS_address_max_len + 1] = "0.0.0.0";
33 sysadm 1.22 in_port_t BBS_port[2] = {BBS_port_default, BBS_ssh_port_default};
34 sysadm 1.20 int BBS_max_client = MAX_CLIENT_LIMIT;
35     int BBS_max_client_per_ip = MAX_CLIENT_PER_IP_LIMIT;
36 sysadm 1.26 char BBS_start_dt[BBS_start_dt_max_len + 1] = "2000年 1月 1日";
37 sysadm 1.28 int BBS_sys_id = 1;
38 sysadm 1.3
39 sysadm 1.35 const int BBS_section_list_load_interval = 1; // second
40 sysadm 1.30
41     // User
42 sysadm 1.31 const int BBS_user_list_load_interval = 60; // 1 minute
43     const int BBS_user_online_list_load_interval = 5; // 5 seconds
44 sysadm 1.30 const int BBS_user_off_line = 900; // 15 minutes
45    
46 sysadm 1.11 char BBS_username[BBS_username_max_len + 1];
47 sysadm 1.24 char BBS_nickname[BBS_nickname_max_len + 1];
48 sysadm 1.17 char BBS_user_tz[BBS_user_tz_max_len + 1];
49 sysadm 1.24 int BBS_user_exp;
50 sysadm 1.3
51     time_t BBS_login_tm;
52     time_t BBS_last_access_tm;
53 sysadm 1.4
54 sysadm 1.25 char BBS_current_action[BBS_current_action_max_len + 1];
55 sysadm 1.27 time_t BBS_current_action_tm;
56 sysadm 1.6
57 sysadm 1.30 const int BBS_current_action_refresh_interval = 60; // 1 minute
58    
59 sysadm 1.32 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 sysadm 1.33 static const int BBS_user_level_points[] = {
66 sysadm 1.32 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     };
83    
84 sysadm 1.33 static const char *BBS_user_level_names[] = {
85 sysadm 1.32 "新手上路", // 0
86     "初来乍练", // 1
87     "白手起家", // 2
88     "略懂一二", // 3
89     "小有作为", // 4
90     "对答如流", // 5
91     "精于此道", // 6
92     "博大精深", // 7
93     "登峰造极", // 8
94     "论坛砥柱", // 9
95     "☆☆☆☆☆", // 10
96     "★☆☆☆☆", // 11
97     "★★☆☆☆", // 12
98     "★★★☆☆", // 13
99     "★★★★☆", // 14
100     "★★★★★", // 15
101     };
102    
103 sysadm 1.33 static const int BBS_user_level_cnt = sizeof(BBS_user_level_names) / sizeof(const char *);
104 sysadm 1.32
105     const char *get_astro_name(time_t birthday)
106     {
107     struct tm tm_birth;
108    
109     gmtime_r(&birthday, &tm_birth);
110    
111     if (tm_birth.tm_mday < astro_dates[tm_birth.tm_mon])
112     {
113     return astro_names[tm_birth.tm_mon];
114     }
115    
116     return astro_names[tm_birth.tm_mon + 1];
117     }
118    
119 sysadm 1.33 int get_user_level(int point)
120 sysadm 1.32 {
121     int left;
122     int right;
123     int mid;
124    
125     left = 0;
126 sysadm 1.33 right = BBS_user_level_cnt - 1;
127 sysadm 1.32
128     while (left < right)
129     {
130     mid = (left + right) / 2;
131 sysadm 1.34 if (point < BBS_user_level_points[mid])
132 sysadm 1.32 {
133 sysadm 1.34 right = mid - 1;
134 sysadm 1.32 }
135 sysadm 1.34 else if (point > BBS_user_level_points[mid])
136 sysadm 1.32 {
137     left = mid + 1;
138     }
139     else // if (point == user_level_points[mid])
140     {
141 sysadm 1.34 left = mid;
142 sysadm 1.32 break;
143     }
144     }
145    
146 sysadm 1.34 if (point < BBS_user_level_points[left])
147     {
148     left--;
149     }
150    
151 sysadm 1.33 return left;
152     }
153    
154     const char *get_user_level_name(int level)
155     {
156     return BBS_user_level_names[level];
157 sysadm 1.32 }
158    
159 sysadm 1.13 char *setuserfile(char *buf, size_t len, const char *filename)
160 sysadm 1.6 {
161 sysadm 1.23 snprintf(buf, len, "%s/%d", filename, BBS_priv.uid);
162 sysadm 1.8 return buf;
163 sysadm 1.6 }

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