/[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.8 by sysadm, Mon Apr 28 03:30:59 2025 UTC Revision 1.36 by sysadm, Tue Nov 4 13:49:51 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 by 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>  #include <signal.h>
15  #include <time.h>  #include <time.h>
16    
17    #define BBS_port_default 23
18    #define BBS_ssh_port_default 22
19    
20  // BBS enviroment  // BBS enviroment
21  char BBS_id[20] = "";  char BBS_id[BBS_id_max_len + 1] = "Example BBS";
22  char BBS_name[50] = "";  char BBS_name[BBS_name_max_len + 1] = "Example Site Name";
23  char BBS_server[256] = "";  char BBS_server[BBS_server_max_len + 1] = "bbs.example.com";
24  char BBS_address[50] = "";  char BBS_address[BBS_address_max_len + 1] = "0.0.0.0";
25  unsigned int BBS_port = 23;  in_port_t BBS_port[2] = {BBS_port_default, BBS_ssh_port_default};
26  long BBS_max_client = 256;  int BBS_max_client = MAX_CLIENT_LIMIT;
27  long BBS_max_user = 10000;  int BBS_max_client_per_ip = MAX_CLIENT_PER_IP_LIMIT;
28  char BBS_start_dt[50] = "2004 1 1";  char BBS_start_dt[BBS_start_dt_max_len + 1] = "2000年 1月 1日";
29    int BBS_sys_id = 1;
30  char BBS_username[BBS_max_username_length];  
31  BBS_user_priv BBS_priv;  const int BBS_section_list_load_interval = 1; // second
32  int BBS_passwd_complex = 0;  
33  int BBS_user_money = 0;  // 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;  time_t BBS_login_tm;
44  time_t BBS_last_access_tm;  time_t BBS_last_access_tm;
 time_t BBS_last_sub_tm;  
45    
46  char BBS_current_section_name[20];  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  char *  static const int BBS_user_level_cnt = sizeof(BBS_user_level_names) / sizeof(const char *);
96  setuserfile(char *buf, const char *filename)  
97    const char *get_astro_name(time_t birthday)
98  {  {
99          sprintf(buf, "data/%s/%ld", filename, BBS_priv.uid);          struct tm tm_birth;
100          return buf;  
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 *  char *setuserfile(char *buf, size_t len, const char *filename)
 sethomefile(char *buf, long int uid, char *filename)  
152  {  {
153          sprintf(buf, "data/%s/%ld", filename, uid);          snprintf(buf, len, "%s/%d", filename, BBS_priv.uid);
154          return buf;          return buf;
155  }  }


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

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