/[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.9 by sysadm, Wed Apr 30 09:18:20 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            main.c  -  description                                                    main.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Mon Oct 11 2004          begin                : Mon Oct 11 2004
5      copyright            : (C) 2004 by Leaflet          copyright            : (C) 2004 by Leaflet
6      email                : leaflet@leafok.com          email                : leaflet@leafok.com
7   ***************************************************************************/   ***************************************************************************/
8    
9  /***************************************************************************  /***************************************************************************
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18    #include "welcome.h"
19  #include "bbs.h"  #include "bbs.h"
20  #include "common.h"  #include "common.h"
21    #include "log.h"
22  #include "io.h"  #include "io.h"
23    #include "screen.h"
24    #include "database.h"
25  #include <mysql.h>  #include <mysql.h>
26  #include <string.h>  #include <string.h>
27    
28  int  int bbs_welcome()
 bbs_welcome ()  
29  {  {
30    char buffer[256], sql[1024], temp[256];          char buffer[256], sql[1024], temp[256];
31    long u_online = 0, u_anonymous = 0, u_total = 0,          long u_online = 0, u_anonymous = 0, u_total = 0,
32      max_u_online = 0, u_login_count = 0;                   max_u_online = 0, u_login_count = 0;
33    MYSQL *db;          MYSQL *db;
34    MYSQL_RES *rs;          MYSQL_RES *rs;
35    MYSQL_ROW row;          MYSQL_ROW row;
36    
37    db = (MYSQL*) db_open();          db = (MYSQL *)db_open();
38    if (db == NULL)          if (db == NULL)
39    {          {
40      return -1;                  return -1;
41    }          }
42    
43    strcpy(sql,          strcpy(sql,
44      "select SID as cc from user_online where current_action not in"                     "select SID as cc from user_online where current_action not in"
45      " ('max_user_limit','max_ip_limit','max_session_limit','exit')"                     " ('max_user_limit','max_ip_limit','max_session_limit','exit')"
46      " group by SID");                     " group by SID");
47    if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
48    {          {
49      log_error("Query user_online failed\n");                  log_error("Query user_online failed\n");
50      return -2;                  return -2;
51    }          }
52    if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
53    {          {
54      log_error("Get user_online data failed\n");                  log_error("Get user_online data failed\n");
55      return -2;                  return -2;
56    }          }
57    u_online = mysql_num_rows(rs);          u_online = mysql_num_rows(rs);
58    mysql_free_result(rs);          mysql_free_result(rs);
59    
60    strcpy(sql,          strcpy(sql,
61      "select SID as cc from user_online where UID=0 and current_action not in"                     "select SID as cc from user_online where UID=0 and current_action not in"
62      " ('max_user_limit','max_ip_limit','max_session_limit','exit')"                     " ('max_user_limit','max_ip_limit','max_session_limit','exit')"
63      " group by SID");                     " group by SID");
64    if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
65    {          {
66      log_error("Query user_online failed\n");                  log_error("Query user_online failed\n");
67      return -2;                  return -2;
68    }          }
69    if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
70    {          {
71      log_error("Get user_online data failed\n");                  log_error("Get user_online data failed\n");
72      return -2;                  return -2;
73    }          }
74    u_anonymous = mysql_num_rows(rs);          u_anonymous = mysql_num_rows(rs);
75    mysql_free_result(rs);          mysql_free_result(rs);
76    
77    strcpy(sql,          strcpy(sql, "select count(*) as cc from user_list where enable");
78      "select count(*) as cc from user_list where enable");          if (mysql_query(db, sql) != 0)
79    if (mysql_query(db, sql) != 0)          {
80    {                  log_error("Query user_list failed\n");
81      log_error("Query user_list failed\n");                  return -2;
82      return -2;          }
83    }          if ((rs = mysql_store_result(db)) == NULL)
84    if ((rs = mysql_store_result(db)) == NULL)          {
85    {                  log_error("Get user_list data failed\n");
86      log_error("Get user_list data failed\n");                  return -2;
87      return -2;          }
88    }          if (row = mysql_fetch_row(rs))
89    if (row = mysql_fetch_row(rs))          {
90    {                  u_total = atol(row[0]);
91      u_total = atol(row[0]);          }
92    }          mysql_free_result(rs);
93    mysql_free_result(rs);  
94            strcpy(sql, "select max(ID) as login_count from user_login_log");
95    strcpy(sql,          if (mysql_query(db, sql) != 0)
96      "select max(ID) as login_count from user_login_log");          {
97    if (mysql_query(db, sql) != 0)                  log_error("Query user_login_log failed\n");
98    {                  return -2;
99      log_error("Query user_login_log failed\n");          }
100      return -2;          if ((rs = mysql_store_result(db)) == NULL)
101    }          {
102    if ((rs = mysql_store_result(db)) == NULL)                  log_error("Get user_login_log data failed\n");
103    {                  return -2;
104      log_error("Get user_login_log data failed\n");          }
105      return -2;          if (row = mysql_fetch_row(rs))
106    }          {
107    if (row = mysql_fetch_row(rs))                  u_login_count = atol(row[0]);
108    {          }
109      u_login_count = atol(row[0]);          mysql_free_result(rs);
110    }  
111    mysql_free_result(rs);          mysql_close(db);
112    
113    mysql_close(db);          // Log max user_online
114            FILE *fin, *fout;
115    //Log max user_online          strcpy(temp, app_home_dir);
116    FILE *fin, *fout;          strcat(temp, "var/max_user_online.dat");
117    strcpy(temp, app_home_dir);          if ((fin = fopen(temp, "r")) != NULL)
118    strcat(temp, "data/max_user_online.dat");          {
119    if ((fin = fopen(temp, "r")) != NULL)                  fscanf(fin, "%ld", &max_u_online);
120    {                  fclose(fin);
121      fscanf(fin, "%ld", &max_u_online);          }
122      fclose(fin);          if (u_online > max_u_online)
123    }          {
124    if (u_online > max_u_online)                  max_u_online = u_online;
125    {                  if ((fout = fopen(temp, "w")) == NULL)
126      max_u_online = u_online;                  {
127      if ((fout = fopen(temp, "w")) == NULL)                          log_error("Open max_user_online.dat failed\n");
128      {                          return -3;
129        log_error("Open max_user_online.dat failed\n");                  }
130        return -3;                  fprintf(fout, "%ld\n", max_u_online);
131      }                  fclose(fout);
132      fprintf(fout, "%ld\n", max_u_online);          }
133      fclose(fout);  
134    }          // Display logo
135            strcpy(temp, app_home_dir);
136    //Display logo          strcat(temp, "data/welcome.txt");
137    strcpy(temp, app_home_dir);          display_file(temp);
138    strcat(temp, "data/welcome.dat");  
139    display_file(temp);          // Display welcome message
140            prints("\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n"
141    //Display welcome message                     "\033[32m目前上站人数 [\033[36m%ld/%ld\033[32m] "
142    prints (                     "匿名游客[\033[36m%ld\033[32m] "
143     "\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n"                     "注册用户数[\033[36m%ld/%ld\033[32m]\r\n"
144     "\033[32m目前上站人数 [\033[36m%ld/%ld\033[32m] "                     "从 [\033[36m%s\033[32m] 起,最高人数记录:"
145     "匿名游客[\033[36m%ld\033[32m] "                     "[\033[36m%ld\033[32m],累计访问人次:[\033[36m%ld\033[32m]\r\n",
146     "注册用户数[\033[36m%ld/%ld\033[32m]\r\n"                     BBS_name, u_online, BBS_max_client, u_anonymous, u_total,
147     "从 [\033[36m%s\033[32m] 起,最高人数记录:"                     BBS_max_user, BBS_start_dt, max_u_online, u_login_count);
    "[\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);  
148    
149    return 0;          return 0;
150  }  }


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

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