/[LeafOK_CVS]/innwebd/base.cpp
ViewVC logotype

Diff of /innwebd/base.cpp

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

Revision 1.10 by sysadm, Fri Sep 17 02:34:27 2004 UTC Revision 1.15 by sysadm, Fri Apr 11 17:14:49 2008 UTC
# Line 1  Line 1 
1  /*******************************************************/  /*******************************************************/
2  /*                                                     */  /*                                                     */
3  /*  LeafOK Innbbsd                                     */  /*  LeafOK Innbbsd                                     */
 /*  Copyright (C) LeafOK.com, 2003-2004                */  
4  /*                                                     */  /*                                                     */
5  /*  Programmed by Leaf                                 */  /*  Copyright (C) LeafOK.com, 2003-2008                */
 /*  E-mail:leaflet@leafok.com  QQ:6049044              */  
6  /*                                                     */  /*                                                     */
7  /*  http://bbs.leafok.com                              */  /*  http://www.leafok.com                              */
 /*  http://bbs.leafok.net                              */  
 /*  http://bbs.fenglin.info                            */  
8  /*                                                     */  /*                                                     */
9  /*******************************************************/  /*******************************************************/
10    
# Line 46  int base::s_exec(const char* in_str, CSt Line 42  int base::s_exec(const char* in_str, CSt
42          }          }
43          catch(CException* e)          catch(CException* e)
44          {          {
45                  syslog << logfile::log_head << "Error in s_exec()" << endl;                  char strErrMsg[1024];
46                    e->GetErrorMessage(strErrMsg,1024);
47                    syslog << logfile::log_head << "Error in s_exec() [" << strErrMsg << "]" << endl;
48                  e->Delete();                  e->Delete();
49                  return -1;                  return -1;
50          }          }
# Line 59  int base::db_open(const char* conn_str) Line 57  int base::db_open(const char* conn_str)
57          try          try
58          {          {
59                  this->Db.Open("",0,0,conn_str,0);                  this->Db.Open("",0,0,conn_str,0);
60                    this->Db.ExecuteSQL("SET CHARACTER SET gb2312");
61                    this->Db.ExecuteSQL("SET NAMES 'gb2312'");
62          }          }
63          catch(CException* e)          catch(CException* e)
64          {          {
65                  syslog << logfile::log_head << "Open database failed in db_open()" << endl;                  char strErrMsg[1024];
66                    e->GetErrorMessage(strErrMsg,1024);
67                    syslog << logfile::log_head << "Open database failed in db_open() [" << strErrMsg << "]" << endl;
68                  e->Delete();                  e->Delete();
69                  return -1;                  return -1;
70          }          }
# Line 78  int base::db_close(void) Line 80  int base::db_close(void)
80          }          }
81          catch(CException* e)          catch(CException* e)
82          {          {
83                  syslog << logfile::log_head << "Close database failed in db_close()" << endl;                  char strErrMsg[1024];
84                    e->GetErrorMessage(strErrMsg,1024);
85                    syslog << logfile::log_head << "Close database failed in db_close() [" << strErrMsg << "]" << endl;
86                  e->Delete();                  e->Delete();
87                  return -1;                  return -1;
88          }          }
# Line 105  int base::bbs_post(const CString& head, Line 109  int base::bbs_post(const CString& head,
109          bool head_find;          bool head_find;
110          CString head_name,head_value,path,from,subject,newsgroups,organization,date,msg_id; //Head          CString head_name,head_value,path,from,subject,newsgroups,organization,date,msg_id; //Head
111          DateTimeConvert sub_dt;          DateTimeConvert sub_dt;
112          CString ptitle,nickname,dt_str,content,msg_content,sql;          CString ptitle,username,nickname,dt_str,content,msg_content,sql;
113          int length;          int length;
114          long id,aid,cid,rid;          long id,aid,cid;
115    
116          try          try
117          {          {
# Line 197  int base::bbs_post(const CString& head, Line 201  int base::bbs_post(const CString& head,
201                          if (subject.GetLength() > 80)                          if (subject.GetLength() > 80)
202                                  subject = subject.Left(75) + " ……";                                  subject = subject.Left(75) + " ……";
203    
204                          //Get nickname                          //Get username
205                          nickname = "cn.bbs";                          username = "cn.bbs.";
206                          for (int i=0;i<from.GetLength();i++)                          for (int i=0;i<from.GetLength();i++)
207                          {                          {
208                                  if (from[i] == '.' || from[i] == '@')                                  if (from[i] == '.' || from[i] == '@')
# Line 209  int base::bbs_post(const CString& head, Line 213  int base::bbs_post(const CString& head,
213                                                  if (from[j] == ' ' || from[j] == '<')                                                  if (from[j] == ' ' || from[j] == '<')
214                                                          break;                                                          break;
215                                          }                                          }
216                                          nickname = from.Mid(j+1,i-j-1) + ".";                                          username = from.Mid(j+1,i-j-1) + ".";
217                                            break;
218                                    }
219                            }
220                            if (username.GetLength() > 12)
221                                    username = username.Left(12) + ".";
222    
223                            //Get nickname
224                            nickname = "cn.bbs";
225                            for (int i=0;i<from.GetLength();i++)
226                            {
227                                    if (from[i] == '(')
228                                    {
229                                            int j;
230                                            for (j=i+1;j<from.GetLength();j++)
231                                            {
232                                                    if (from[j] == ')')
233                                                            break;
234                                            }
235                                            nickname = from.Mid(i+1,j-i-1);
236                                          break;                                          break;
237                                  }                                  }
238                          }                          }
239                          if (nickname.GetLength() > 20)                          if (nickname.GetLength() > 20)
240                                  nickname = nickname.Left(19) + ".";                                  nickname = nickname.Left(19) + " ";
241    
242                          //Reference /bbs/add_sub.php                          //Reference /bbs/add_sub.php
243    
# Line 223  int base::bbs_post(const CString& head, Line 246  int base::bbs_post(const CString& head,
246                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
247                          cid = this->last_insert_id();                          cid = this->last_insert_id();
248    
249                          sql.Format("insert into bbs(SID,TID,UID,nickname,title,CID,sub_dt,"                          sql.Format("insert into bbs(SID,TID,UID,username,nickname,title,CID,sub_dt,"
250                                          "sub_ip,last_reply_dt,icon,length,transship)"                                          "sub_ip,last_reply_dt,icon,length,transship)"
251                                          "values(%d,%ld,%ld,'%s','%s',%ld,adddate('%s',interval '8' hour),"                                          "values(%d,%ld,%ld,'%s','%s','%s',%ld,adddate('%s',interval '8' hour),"
252                                          "'%s',adddate('%s',interval '8' hour),1,%d,1)",                                          "'%s',adddate('%s',interval '8' hour),1,%d,1)",
253                                          sid,id,this->innd_uid,addslashes(nickname),addslashes(subject),                                          sid,id,this->innd_uid,addslashes(username),addslashes(nickname),addslashes(subject),
254                                          cid,dt_str,this->hostaddr,dt_str,length);                                          cid,dt_str,this->hostaddr,dt_str,length);
255                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
256                          aid = this->last_insert_id();                          aid = this->last_insert_id();
# Line 246  int base::bbs_post(const CString& head, Line 269  int base::bbs_post(const CString& head,
269                          {                          {
270                                  sql.Format("update bbs set cached=0, reply_count=reply_count+1,"                                  sql.Format("update bbs set cached=0, reply_count=reply_count+1,"
271                                                  "last_reply_dt=adddate('%s',interval '8' hour),last_reply_UID=%ld,"                                                  "last_reply_dt=adddate('%s',interval '8' hour),last_reply_UID=%ld,"
272                                                  "last_reply_nickname='%s' where aid=%ld",                                                  "last_reply_username='%s',last_reply_nickname='%s' where aid=%ld",
273                                                  dt_str,this->innd_uid,nickname,id);                                                  dt_str,this->innd_uid,username,nickname,id);
274                                  this->Db.ExecuteSQL(sql);                                  this->Db.ExecuteSQL(sql);
275                          }                          }
276    
277                          //Notify the author of the artile which is replyed.                          //Notify the author of the artile which is replyed.
278                          if (id != 0)                          if (id != 0)
279                          {                          {
280                                  sql.Format("select user_pubinfo.UID,user_pubinfo.nickname,"                                  sql.Format("select distinct UID from bbs where (AID=%ld or TID=%ld)"
281                                          "user_pubinfo.email from bbs left join user_pubinfo on"                                          " and visible and reply_note and UID<>%ld",id,id,this->innd_uid);
                                         " bbs.UID=user_pubinfo.UID where AID=%ld and reply_note",  
                                         id);  
282                                  RS.Open(CRecordset::snapshot,sql,CRecordset::forwardOnly | CRecordset::readOnly);                                  RS.Open(CRecordset::snapshot,sql,CRecordset::forwardOnly | CRecordset::readOnly);
283                    
284                                  if (!RS.IsEOF())                                  while (!RS.IsEOF())
285                                  {                                  {
286                                          RS.GetFieldValue("UID",dbVar),SQL_C_SLONG;                                          //Send notication message
287                                          if (dbVar.m_lVal != innd_uid)  
288                                          {                      msg_content.Format("[hide]SYS_R_Reply_Article[/hide]"
289                                                  sql.Format("update user_pubinfo set exp=exp+1 where UID=%ld",                                                  "有人回复了您所发表的文章,快来[article %ld#%ld"
290                                                          dbVar.m_lVal);                                                  "]看看[/article]《%s》吧!\n",id,aid,addslashes(subject));
291                                                  this->Db.ExecuteSQL(sql);  
292                                            RS.GetFieldValue("UID",dbVar,SQL_C_SLONG);
293                                                  RS.GetFieldValue("email",dbVar,SQL_C_CHAR);  
294                                                  sql.Format("insert into bbs_recommend(UID,TID,type,dt,email,ip)"                                          sql.Format("insert into bbs_msg(fromUID,toUID,content,send_dt,send_ip)"
295                                                          " values(%ld,%ld,'D',now(),'%s','%s')",                                                  " values(%ld,%ld,'%s',now(),'%s')",
296                                                          this->innd_uid,aid,dbVar.m_pstring,this->hostaddr);                                          this->innd_uid,dbVar.m_lVal,addslashes(msg_content),this->hostaddr);
297                                                  this->Db.ExecuteSQL(sql);                                          this->Db.ExecuteSQL(sql);
298                                                  rid = this->last_insert_id();                                  }
   
                                                 //Send notication message  
   
                           msg_content.Format("[hide]SYS_R_Reply_Article[/hide]"  
                                                         "有人回复了您所发表的文章,快来[url recommend_view.php?id=%ld"  
                                                         "]看看[/url]《%s》吧!\n",rid,addslashes(subject));  
   
                                                 RS.GetFieldValue("UID",dbVar,SQL_C_SLONG);  
                                                 sql.Format("insert into bbs_msg(fromUID,toUID,content,send_dt,send_ip)"  
                                                                 " values(%ld,%ld,'%s',now(),'%s')",  
                                                                 this->innd_uid,dbVar.m_lVal,addslashes(msg_content),this->hostaddr);  
                                                 this->Db.ExecuteSQL(sql);  
                                         }  
                                 }  
299                                  RS.Close();                                  RS.Close();
300                          }                          }
301    
# Line 348  long base::last_insert_id(void) Line 355  long base::last_insert_id(void)
355          }          }
356          catch(CException* e)          catch(CException* e)
357          {          {
358                  syslog << logfile::log_head << "Error in last_insert_id()" << endl;                  char strErrMsg[1024];
359                    e->GetErrorMessage(strErrMsg,1024);
360                    syslog << logfile::log_head << "Error in last_insert_id() [" << strErrMsg << "]" << endl;
361                  e->Delete();                  e->Delete();
362                  return 0;                  return 0;
363          }          }
# Line 422  int base::s_send(const char* in_str, boo Line 431  int base::s_send(const char* in_str, boo
431          }          }
432          catch(CException* e)          catch(CException* e)
433          {          {
434                  syslog << logfile::log_head << "Error in s_send()" << endl;                  char strErrMsg[1024];
435                    e->GetErrorMessage(strErrMsg,1024);
436                    syslog << logfile::log_head << "Error in s_send() [" << strErrMsg << "]" << endl;
437                  e->Delete();                  e->Delete();
438                  return -1;                  return -1;
439          }          }
# Line 459  int base::s_receive(CString& out_str, ch Line 470  int base::s_receive(CString& out_str, ch
470          }          }
471          catch(CException* e)          catch(CException* e)
472          {          {
473                  syslog << logfile::log_head << "Error in s_receive()" << endl;                  char strErrMsg[1024];
474                    e->GetErrorMessage(strErrMsg,1024);
475                    syslog << logfile::log_head << "Error in s_receive() [" << strErrMsg << "]" << endl;
476                  e->Delete();                  e->Delete();
477                  return -1;                  return -1;
478          }          }
# Line 474  int base::begin(void) Line 487  int base::begin(void)
487          unsigned int time_wait = 0;          unsigned int time_wait = 0;
488    
489          if (!this->IsShutdown())          if (!this->IsShutdown())
490                  return 1;                  return 0;
491    
492          if (hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base::Thread,(LPVOID)this,0,&ulThreadId))          if (hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base::Thread,(LPVOID)this,0,&ulThreadId))
493          {          {
# Line 491  int base::begin(void) Line 504  int base::begin(void)
504          {          {
505          Sleep(100);          Sleep(100);
506                  time_wait += 100;                  time_wait += 100;
507                  if (time_wait > 10000) //Wait 10 seconds                  if (time_wait > 30000) //Wait 30 seconds
508                  {                  {
509                          syslog << logfile::log_head << "Module timeout in begin()" << endl;                          syslog << logfile::log_head << "Module timeout in begin()" << endl;
510                          this->end();                          this->end();
# Line 513  DWORD base::Thread(LPVOID pParam) Line 526  DWORD base::Thread(LPVOID pParam)
526    
527          p->ulMainThreadId = GetCurrentThreadId();          p->ulMainThreadId = GetCurrentThreadId();
528    
529          if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 30) != 0)          if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 60) != 0)
530          {          {
531                  syslog << logfile::log_head << "Register thread ... Failed" << endl;                  syslog << logfile::log_head << "Register thread ... Failed" << endl;
532          }          }


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

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