--- lbbs/include/user_priv.h 2025/05/19 02:16:24 1.3 +++ lbbs/include/user_priv.h 2025/11/16 11:06:06 1.11 @@ -1,18 +1,10 @@ -/*************************************************************************** - user_priv.h - description - ------------------- - Copyright : (C) 2004-2025 by Leaflet - Email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * user_priv + * - basic operations of user privilege + * + * Copyright (C) 2004-2025 Leaflet + */ #ifndef _USER_PRIV_H_ #define _USER_PRIV_H_ @@ -21,35 +13,42 @@ #include // User privilege -#define S_NONE 0x0 -#define S_LIST 0x1 -#define S_GETEXP 0x2 -#define S_POST 0x4 -#define S_MSG 0x8 -#define S_MAN_S 0x20 -#define S_MAN_M 0x60 //(0x40 | 0x20) -#define S_ADMIN 0xe0 //(0x80 | 0x40 | 0x20) -#define S_ALL 0xff -#define S_DEFAULT 0x3 // 0x1 | 0x2 - -#define P_GUEST 0x0 //游客 -#define P_USER 0x1 //普通用户 -//#define P_AUTH_USER 0x2 // Reserved -#define P_MAN_S 0x4 //副版主 -#define P_MAN_M 0x8 //正版主 -#define P_MAN_C 0x10 // Reserved -#define P_ADMIN_S 0x20 //副系统管理员 -#define P_ADMIN_M 0x40 //主系统管理员 +enum user_priv_t +{ + S_NONE = 0x0, + S_LIST = 0x1, + S_GETEXP = 0x2, + S_POST = 0x4, + S_MSG = 0x8, + S_MAN_S = 0x20, + S_MAN_M = 0x60, //(0x40 | 0x20) + S_ADMIN = 0xe0, //(0x80 | 0x40 | 0x20) + S_ALL = 0xff, + S_DEFAULT = 0x3, // 0x1 | 0x2 +}; + +enum user_level_t +{ + P_GUEST = 0x0, // 娓稿 + P_USER = 0x1, // 鏅氱敤鎴 + P_AUTH_USER = 0x2, // Reserved + P_MAN_S = 0x4, // 鍓増涓 + P_MAN_M = 0x8, // 姝g増涓 + P_MAN_C = 0x10, // Reserved + P_ADMIN_S = 0x20, // 鍓郴缁熺鐞嗗憳 + P_ADMIN_M = 0x40, // 涓荤郴缁熺鐞嗗憳 +}; struct user_priv { - long int uid; + int uid; int level; int g_priv; struct { int sid; int s_priv; + int is_favor; } s_priv_list[BBS_max_section]; int s_count; }; @@ -75,15 +74,23 @@ inline int checklevel2(BBS_user_priv *p_ return ((p_priv->level >= level) ? 1 : 0); } -extern int setpriv(BBS_user_priv *p_priv, int sid, int priv); +extern int setpriv(BBS_user_priv *p_priv, int sid, int priv, int is_favor); -extern int getpriv(BBS_user_priv *p_priv, int sid); +extern int getpriv(BBS_user_priv *p_priv, int sid, int *p_is_favor); inline int checkpriv(BBS_user_priv *p_priv, int sid, int priv) { - return (((getpriv(p_priv, sid) & priv)) == priv ? 1 : 0); + int is_favor = 0; + return (((getpriv(p_priv, sid, &is_favor) & priv)) == priv ? 1 : 0); +} + +inline int is_favor(BBS_user_priv *p_priv, int sid) +{ + int is_favor = 0; + getpriv(p_priv, sid, &is_favor); + return is_favor; } -extern int load_priv(MYSQL *db, BBS_user_priv *p_priv, long int uid); +extern int load_priv(MYSQL *db, BBS_user_priv *p_priv, int uid); #endif //_USER_PRIV_H_