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


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

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