| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
bbs.c - description |
/* |
| 3 |
------------------- |
* bbs |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - BBS related common definitions |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* 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 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 8 |
|
|
| 9 |
#include "bbs.h" |
#include "bbs.h" |
| 10 |
#include "common.h" |
#include "common.h" |
| 28 |
char BBS_start_dt[BBS_start_dt_max_len + 1] = "2000年 1月 1日"; |
char BBS_start_dt[BBS_start_dt_max_len + 1] = "2000年 1月 1日"; |
| 29 |
int BBS_sys_id = 1; |
int BBS_sys_id = 1; |
| 30 |
|
|
| 31 |
const int BBS_section_list_load_interval = 5; // second |
const int BBS_section_list_load_interval = 1; // second |
| 32 |
|
|
| 33 |
// User |
// User |
| 34 |
const int BBS_user_list_load_interval = 60; // 1 minute |
const int BBS_user_list_load_interval = 60; // 1 minute |
| 54 |
static const char *astro_names[] = { |
static const char *astro_names[] = { |
| 55 |
"摩羯", "水瓶", "双鱼", "白羊", "金牛", "双子", "巨蟹", "狮子", "处女", "天秤", "天蝎", "射手", "摩羯"}; |
"摩羯", "水瓶", "双鱼", "白羊", "金牛", "双子", "巨蟹", "狮子", "处女", "天秤", "天蝎", "射手", "摩羯"}; |
| 56 |
|
|
| 57 |
static const int user_level_points[] = { |
static const int BBS_user_level_points[] = { |
| 58 |
INT_MIN, // 0 |
INT_MIN, // 0 |
| 59 |
50, // 1 |
50, // 1 |
| 60 |
200, // 2 |
200, // 2 |
| 71 |
80000, // 13 |
80000, // 13 |
| 72 |
90000, // 14 |
90000, // 14 |
| 73 |
100000, // 15 |
100000, // 15 |
|
INT_MAX, // 16 |
|
| 74 |
}; |
}; |
| 75 |
|
|
| 76 |
static const char *user_level_names[] = { |
static const char *BBS_user_level_names[] = { |
| 77 |
"新手上路", // 0 |
"新手上路", // 0 |
| 78 |
"初来乍练", // 1 |
"初来乍练", // 1 |
| 79 |
"白手起家", // 2 |
"白手起家", // 2 |
| 92 |
"★★★★★", // 15 |
"★★★★★", // 15 |
| 93 |
}; |
}; |
| 94 |
|
|
| 95 |
static const int user_level_cnt = sizeof(user_level_names) / sizeof(const char *); |
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) |
const char *get_astro_name(time_t birthday) |
| 98 |
{ |
{ |
| 108 |
return astro_names[tm_birth.tm_mon + 1]; |
return astro_names[tm_birth.tm_mon + 1]; |
| 109 |
} |
} |
| 110 |
|
|
| 111 |
const char *get_user_level_name(int point) |
int get_user_level(int point) |
| 112 |
{ |
{ |
| 113 |
int left; |
int left; |
| 114 |
int right; |
int right; |
| 115 |
int mid; |
int mid; |
| 116 |
|
|
| 117 |
left = 0; |
left = 0; |
| 118 |
right = user_level_cnt - 1; |
right = BBS_user_level_cnt - 1; |
| 119 |
|
|
| 120 |
while (left < right) |
while (left < right) |
| 121 |
{ |
{ |
| 122 |
mid = (left + right) / 2; |
mid = (left + right) / 2; |
| 123 |
if (point < user_level_points[mid + 1]) |
if (point < BBS_user_level_points[mid]) |
| 124 |
{ |
{ |
| 125 |
right = mid; |
right = mid - 1; |
| 126 |
} |
} |
| 127 |
else if (point > user_level_points[mid + 1]) |
else if (point > BBS_user_level_points[mid]) |
| 128 |
{ |
{ |
| 129 |
left = mid + 1; |
left = mid + 1; |
| 130 |
} |
} |
| 131 |
else // if (point == user_level_points[mid]) |
else // if (point == user_level_points[mid]) |
| 132 |
{ |
{ |
| 133 |
left = mid + 1; |
left = mid; |
| 134 |
break; |
break; |
| 135 |
} |
} |
| 136 |
} |
} |
| 137 |
|
|
| 138 |
return user_level_names[left]; |
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) |
char *setuserfile(char *buf, size_t len, const char *filename) |