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

Diff of /lbbs/src/bbs.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.3 by sysadm, Fri Oct 22 15:20:32 2004 UTC Revision 1.38 by sysadm, Wed Nov 5 04:19:21 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                              bbs.c  -  description  /*
3                               -------------------   * bbs
4      begin                : Mon Oct 18 2004   *   - BBS related common definitions
5      copyright            : (C) 2004 by Leaflet   *
6      email                : leaflet@leafok.com   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7   ***************************************************************************/   */
   
 /***************************************************************************  
  *                                                                         *  
  *   This program is free software; you can redistribute it and/or modify  *  
  *   it under the terms of the GNU General Public License as published by  *  
  *   the Free Software Foundation; either version 2 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
9  #include "bbs.h"  #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>  #include <time.h>
16    
17  //BBS enviroment  enum _bbs_port_constant_t
18  char BBS_id[20] = "";  {
19  char BBS_name[50] = "";          BBS_port_default = 23,
20  char BBS_server[256] = "";          BBS_ssh_port_default = 22,
21  char BBS_address[50] = "";  };
22  unsigned int BBS_port = 23;  
23  long BBS_max_client = 256;  // BBS enviroment
24  long BBS_max_user = 10000;  char BBS_id[BBS_id_max_len + 1] = "Example BBS";
25  char BBS_start_dt[50] = "2004 1 1";  char BBS_name[BBS_name_max_len + 1] = "Example Site Name";
26    char BBS_server[BBS_server_max_len + 1] = "bbs.example.com";
27  BBS_user_priv BBS_priv;  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_passwd_complex = 0;  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;  time_t BBS_login_tm;
47  time_t BBS_last_access_tm;  time_t BBS_last_access_tm;
48  time_t BBS_last_sub_tm;  
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    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

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