/[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.14 by sysadm, Tue May 6 05:31:26 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 current_action NOT IN ('exit')) AS t1");
51            if (mysql_query(db, sql) != 0)
52            {
53                    log_error("Query user_online failed\n");
54                    return -2;
55            }
56            if ((rs = mysql_store_result(db)) == NULL)
57            {
58                    log_error("Get user_online data failed\n");
59                    return -2;
60            }
61            if ((row = mysql_fetch_row(rs)))
62            {
63                    u_online = (u_int32_t)atoi(row[0]);
64            }
65            mysql_free_result(rs);
66    
67            snprintf(sql, sizeof(sql),
68                       "SELECT COUNT(*) AS cc FROM "
69                       "(SELECT DISTINCT SID FROM user_online "
70                       "WHERE UID = 0 AND current_action NOT IN ('exit')) AS t1");
71            if (mysql_query(db, sql) != 0)
72            {
73                    log_error("Query user_online failed\n");
74                    return -2;
75            }
76            if ((rs = mysql_store_result(db)) == NULL)
77            {
78                    log_error("Get user_online data failed\n");
79                    return -2;
80            }
81            if ((row = mysql_fetch_row(rs)))
82            {
83                    u_anonymous = (u_int32_t)atoi(row[0]);
84            }
85            mysql_free_result(rs);
86    
87            snprintf(sql, sizeof(sql), "SELECT COUNT(UID) AS cc FROM user_list WHERE enable");
88            if (mysql_query(db, sql) != 0)
89            {
90                    log_error("Query user_list failed\n");
91                    return -2;
92            }
93            if ((rs = mysql_store_result(db)) == NULL)
94            {
95                    log_error("Get user_list data failed\n");
96                    return -2;
97            }
98            if ((row = mysql_fetch_row(rs)))
99            {
100                    u_total = (u_int32_t)atoi(row[0]);
101            }
102            mysql_free_result(rs);
103    
104            snprintf(sql, sizeof(sql), "SELECT ID FROM user_login_log ORDER BY ID LIMIT 1");
105            if (mysql_query(db, sql) != 0)
106            {
107                    log_error("Query user_login_log failed\n");
108                    return -2;
109            }
110            if ((rs = mysql_store_result(db)) == NULL)
111            {
112                    log_error("Get user_login_log data failed\n");
113                    return -2;
114            }
115            if ((row = mysql_fetch_row(rs)))
116            {
117                    u_login_count = (u_int32_t)atoi(row[0]);
118            }
119            mysql_free_result(rs);
120    
121            mysql_close(db);
122    
123            // Log max user_online
124            FILE *fin, *fout;
125            if ((fin = fopen(VAR_MAX_USER_ONLINE, "r")) != NULL)
126            {
127                    fscanf(fin, "%d", &max_u_online);
128                    fclose(fin);
129            }
130            if (u_online > max_u_online)
131            {
132                    max_u_online = u_online;
133                    if ((fout = fopen(VAR_MAX_USER_ONLINE, "w")) == NULL)
134                    {
135                            log_error("Open max_user_online.dat failed\n");
136                            return -3;
137                    }
138                    fprintf(fout, "%d\n", max_u_online);
139                    fclose(fout);
140            }
141    
142            // Display logo
143            display_file(DATA_WELCOME);
144    
145            // Display welcome message
146            prints("\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n"
147                       "\033[32m目前上站人数 [\033[36m%d/%d\033[32m] "
148                       "匿名游客[\033[36m%d\033[32m] "
149                       "注册用户数[\033[36m%d/%d\033[32m]\r\n"
150                       "从 [\033[36m%s\033[32m] 起,最高人数记录:"
151                       "[\033[36m%d\033[32m],累计访问人次:[\033[36m%d\033[32m]\r\n",
152                       BBS_name, u_online, BBS_max_client, u_anonymous, u_total,
153                       BBS_max_user, BBS_start_dt, max_u_online, u_login_count);
154    
155            return 0;
156  }  }


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

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