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


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

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