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

Diff of /lbbs/src/welcome.c

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

Revision 1.2 by sysadm, Fri Oct 22 15:20:32 2004 UTC Revision 1.16 by sysadm, Fri May 9 11:21:11 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            main.c  -  description                                                    main.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Mon Oct 11 2004          Copyright            : (C) 2004-2025 by Leaflet
5      copyright            : (C) 2004 by Leaflet          Email                : leaflet@leafok.com
     email                : leaflet@leafok.com  
6   ***************************************************************************/   ***************************************************************************/
7    
8  /***************************************************************************  /***************************************************************************
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
12   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 3 of the License, or     *
13   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #include "welcome.h"
18  #include "bbs.h"  #include "bbs.h"
19  #include "common.h"  #include "common.h"
20    #include "log.h"
21  #include "io.h"  #include "io.h"
22    #include "screen.h"
23    #include "database.h"
24  #include <mysql.h>  #include <mysql.h>
25  #include <string.h>  #include <string.h>
26    
27  int  int bbs_welcome()
 bbs_welcome ()  
28  {  {
29    char buffer[256], sql[1024], temp[256];          char sql[SQL_BUFFER_LEN];
   long u_online = 0, u_anonymous = 0, u_total = 0,  
     max_u_online = 0, u_login_count = 0;  
   MYSQL *db;  
   MYSQL_RES *rs;  
   MYSQL_ROW row;  
   
   db = (MYSQL*) db_open();  
   if (db == NULL)  
   {  
     return -1;  
   }  
   
   strcpy(sql,  
     "select SID as cc from user_online where current_action not in"  
     " ('max_user_limit','max_ip_limit','max_session_limit','exit')"  
     " group by SID");  
   if (mysql_query(db, sql) != 0)  
   {  
     log_error("Query user_online failed\n");  
     return -2;  
   }  
   if ((rs = mysql_store_result(db)) == NULL)  
   {  
     log_error("Get user_online data failed\n");  
     return -2;  
   }  
   u_online = mysql_num_rows(rs);  
   mysql_free_result(rs);  
   
   strcpy(sql,  
     "select SID as cc from user_online where UID=0 and current_action not in"  
     " ('max_user_limit','max_ip_limit','max_session_limit','exit')"  
     " group by SID");  
   if (mysql_query(db, sql) != 0)  
   {  
     log_error("Query user_online failed\n");  
     return -2;  
   }  
   if ((rs = mysql_store_result(db)) == NULL)  
   {  
     log_error("Get user_online data failed\n");  
     return -2;  
   }  
   u_anonymous = mysql_num_rows(rs);  
   mysql_free_result(rs);  
   
   strcpy(sql,  
     "select count(*) as cc from user_list where enable");  
   if (mysql_query(db, sql) != 0)  
   {  
     log_error("Query user_list failed\n");  
     return -2;  
   }  
   if ((rs = mysql_store_result(db)) == NULL)  
   {  
     log_error("Get user_list data failed\n");  
     return -2;  
   }  
   if (row = mysql_fetch_row(rs))  
   {  
     u_total = atol(row[0]);  
   }  
   mysql_free_result(rs);  
   
   strcpy(sql,  
     "select max(ID) as login_count from user_login_log");  
   if (mysql_query(db, sql) != 0)  
   {  
     log_error("Query user_login_log failed\n");  
     return -2;  
   }  
   if ((rs = mysql_store_result(db)) == NULL)  
   {  
     log_error("Get user_login_log data failed\n");  
     return -2;  
   }  
   if (row = mysql_fetch_row(rs))  
   {  
     u_login_count = atol(row[0]);  
   }  
   mysql_free_result(rs);  
   
   mysql_close(db);  
   
   //Log max user_online  
   FILE *fin, *fout;  
   strcpy(temp, app_home_dir);  
   strcat(temp, "data/max_user_online.dat");  
   if ((fin = fopen(temp, "r")) != NULL)  
   {  
     fscanf(fin, "%ld", &max_u_online);  
     fclose(fin);  
   }  
   if (u_online > max_u_online)  
   {  
     max_u_online = u_online;  
     if ((fout = fopen(temp, "w")) == NULL)  
     {  
       log_error("Open max_user_online.dat failed\n");  
       return -3;  
     }  
     fprintf(fout, "%ld\n", max_u_online);  
     fclose(fout);  
   }  
   
   //Display logo  
   strcpy(temp, app_home_dir);  
   strcat(temp, "data/welcome.dat");  
   display_file(temp);  
   
   //Display welcome message  
   prints (  
    "\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n"  
    "\033[32m目前上站人数 [\033[36m%ld/%ld\033[32m] "  
    "匿名游客[\033[36m%ld\033[32m] "  
    "注册用户数[\033[36m%ld/%ld\033[32m]\r\n"  
    "从 [\033[36m%s\033[32m] 起,最高人数记录:"  
    "[\033[36m%ld\033[32m],累计访问人次:[\033[36m%ld\033[32m]\r\n",  
    BBS_name, u_online, BBS_max_client, u_anonymous, u_total,  
    BBS_max_user, BBS_start_dt, max_u_online, u_login_count);  
30    
31    return 0;          u_int32_t u_online = 0;
32            u_int32_t u_anonymous = 0;
33            u_int32_t u_total = 0;
34            u_int32_t max_u_online = 0;
35            u_int32_t u_login_count = 0;
36    
37            MYSQL *db;
38            MYSQL_RES *rs;
39            MYSQL_ROW row;
40    
41            db = (MYSQL *)db_open();
42            if (db == NULL)
43            {
44                    return -1;
45            }
46    
47            snprintf(sql, sizeof(sql),
48                             "SELECT COUNT(*) AS cc FROM "
49                             "(SELECT DISTINCT SID FROM user_online "
50                             "WHERE last_tm >= SUBDATE(NOW(), INTERVAL %d SECOND)) AS t1",
51                             BBS_user_off_line);
52            if (mysql_query(db, sql) != 0)
53            {
54                    log_error("Query user_online failed\n");
55                    return -2;
56            }
57            if ((rs = mysql_store_result(db)) == NULL)
58            {
59                    log_error("Get user_online data failed\n");
60                    return -2;
61            }
62            if ((row = mysql_fetch_row(rs)))
63            {
64                    u_online = (u_int32_t)atoi(row[0]);
65            }
66            mysql_free_result(rs);
67    
68            snprintf(sql, sizeof(sql),
69                             "SELECT COUNT(*) AS cc FROM "
70                             "(SELECT DISTINCT SID FROM user_online "
71                             "WHERE UID = 0 AND last_tm >= SUBDATE(NOW(), INTERVAL %d SECOND)) AS t1",
72                             BBS_user_off_line);
73            if (mysql_query(db, sql) != 0)
74            {
75                    log_error("Query user_online failed\n");
76                    return -2;
77            }
78            if ((rs = mysql_store_result(db)) == NULL)
79            {
80                    log_error("Get user_online data failed\n");
81                    return -2;
82            }
83            if ((row = mysql_fetch_row(rs)))
84            {
85                    u_anonymous = (u_int32_t)atoi(row[0]);
86            }
87            mysql_free_result(rs);
88    
89            snprintf(sql, sizeof(sql), "SELECT COUNT(UID) AS cc FROM user_list WHERE enable");
90            if (mysql_query(db, sql) != 0)
91            {
92                    log_error("Query user_list failed\n");
93                    return -2;
94            }
95            if ((rs = mysql_store_result(db)) == NULL)
96            {
97                    log_error("Get user_list data failed\n");
98                    return -2;
99            }
100            if ((row = mysql_fetch_row(rs)))
101            {
102                    u_total = (u_int32_t)atoi(row[0]);
103            }
104            mysql_free_result(rs);
105    
106            snprintf(sql, sizeof(sql), "SELECT ID FROM user_login_log ORDER BY ID LIMIT 1");
107            if (mysql_query(db, sql) != 0)
108            {
109                    log_error("Query user_login_log failed\n");
110                    return -2;
111            }
112            if ((rs = mysql_store_result(db)) == NULL)
113            {
114                    log_error("Get user_login_log data failed\n");
115                    return -2;
116            }
117            if ((row = mysql_fetch_row(rs)))
118            {
119                    u_login_count = (u_int32_t)atoi(row[0]);
120            }
121            mysql_free_result(rs);
122    
123            mysql_close(db);
124    
125            // Log max user_online
126            FILE *fin, *fout;
127            if ((fin = fopen(VAR_MAX_USER_ONLINE, "r")) != NULL)
128            {
129                    fscanf(fin, "%d", &max_u_online);
130                    fclose(fin);
131            }
132            if (u_online > max_u_online)
133            {
134                    max_u_online = u_online;
135                    if ((fout = fopen(VAR_MAX_USER_ONLINE, "w")) == NULL)
136                    {
137                            log_error("Open max_user_online.dat failed\n");
138                            return -3;
139                    }
140                    fprintf(fout, "%d\n", max_u_online);
141                    fclose(fout);
142            }
143    
144            // Count current user before login
145            u_online++;
146            u_anonymous++;
147    
148            // Display logo
149            display_file(DATA_WELCOME);
150    
151            // Display welcome message
152            prints("\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n"
153                       "\033[32m目前上站人数 [\033[36m%d/%d\033[32m] "
154                       "匿名游客[\033[36m%d\033[32m] "
155                       "注册用户数[\033[36m%d/%d\033[32m]\r\n"
156                       "从 [\033[36m%s\033[32m] 起,最高人数记录:"
157                       "[\033[36m%d\033[32m],累计访问人次:[\033[36m%d\033[32m]\r\n",
158                       BBS_name, u_online, BBS_max_client, u_anonymous, u_total,
159                       BBS_max_user, BBS_start_dt, max_u_online, u_login_count);
160    
161            return 0;
162  }  }


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

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