diff options
Diffstat (limited to 'src/time')
| -rw-r--r-- | src/time/timo.cpp | 55 | ||||
| -rw-r--r-- | src/time/timo.h | 46 | ||||
| -rw-r--r-- | src/time/timr.cpp | 182 | ||||
| -rw-r--r-- | src/time/timr.h | 75 |
4 files changed, 358 insertions, 0 deletions
diff --git a/src/time/timo.cpp b/src/time/timo.cpp new file mode 100644 index 0000000..276b517 --- /dev/null +++ b/src/time/timo.cpp @@ -0,0 +1,55 @@ +/*:* + *: File: ./src/time/timo.cpp + *: + *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: Copyright (C) 2006, 2007 Paul C. Buetow + *: + *: This program is free software; you can redistribute it and/or + *: modify it under the terms of the GNU General Public License + *: as published by the Free Software Foundation; either version 2 + *: of the License, or (at your option) any later version. + *: + *: This program is distributed in the hope that it will be useful, + *: but WITHOUT ANY WARRANTY; without even the implied warranty of + *: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *: GNU General Public License for more details. + *: + *: You should have received a copy of the GNU General Public License + *: along with this program; if not, write to the Free Software + *: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *:*/ + +#ifndef TIMO_CPP +#define TIMO_CPP + +#include "timo.h" + +using namespace std; + +timo::timo() +{} + +timo::~timo() +{} + +double +timo::get_last_activity( ) +{ + double d_ret; + + d_ret = wrap::TIMR->get_time_diff( t_time ); + + return d_ret; +} + +void +timo::renew_timeout( ) +{ + time( &t_time ); +} + +#endif diff --git a/src/time/timo.h b/src/time/timo.h new file mode 100644 index 0000000..5ded5ff --- /dev/null +++ b/src/time/timo.h @@ -0,0 +1,46 @@ +/*:* + *: File: ./src/time/timo.h + *: + *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: Copyright (C) 2006, 2007 Paul C. Buetow + *: + *: This program is free software; you can redistribute it and/or + *: modify it under the terms of the GNU General Public License + *: as published by the Free Software Foundation; either version 2 + *: of the License, or (at your option) any later version. + *: + *: This program is distributed in the hope that it will be useful, + *: but WITHOUT ANY WARRANTY; without even the implied warranty of + *: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *: GNU General Public License for more details. + *: + *: You should have received a copy of the GNU General Public License + *: along with this program; if not, write to the Free Software + *: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *:*/ + +#include "../incl.h" + +#ifndef TIMO_H +#define TIMO_H + +using namespace std; + +class timo // timeout class +{ +protected: + time_t t_time; // last activity time. + +public: + timo( ); + ~timo( ); + + double get_last_activity(); + virtual void renew_timeout(); +}; + +#endif diff --git a/src/time/timr.cpp b/src/time/timr.cpp new file mode 100644 index 0000000..0d049c3 --- /dev/null +++ b/src/time/timr.cpp @@ -0,0 +1,182 @@ +/*:* + *: File: ./src/time/timr.cpp + *: + *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: Copyright (C) 2006, 2007 Paul C. Buetow + *: + *: This program is free software; you can redistribute it and/or + *: modify it under the terms of the GNU General Public License + *: as published by the Free Software Foundation; either version 2 + *: of the License, or (at your option) any later version. + *: + *: This program is distributed in the hope that it will be useful, + *: but WITHOUT ANY WARRANTY; without even the implied warranty of + *: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *: GNU General Public License for more details. + *: + *: You should have received a copy of the GNU General Public License + *: along with this program; if not, write to the Free Software + *: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *:*/ + +#ifndef TIMR_CPP +#define TIMR_CPP + +#include <sys/time.h> +#include "timr.h" + +using namespace std; + +timr::timr() +{ + wrap::system_message( TIMERIN ); + b_timer_active = true; + + + i_time_offset = tool::string2int( wrap::CONF->get_elem("chat.timeoffset") ); + wrap::system_message( TIMEROF + tool::int2string( i_time_offset ) ); + + s_time = "00:00:00"; + s_uptime = "00:00:00"; +} + +timr::~timr() +{} + +bool +timr::get_timer_active() const +{ + return b_timer_active; +} + +int +timr::get_offset() +{ + int i_ret_val = i_time_offset; + return i_ret_val; +} + +void +timr::start( void *v_ptr ) +{ + wrap::system_message( TIMERTH ); + + time_t clock_start; + time_t clock_now; + + time( &clock_start ); + tm time_start = *localtime( &clock_start ); + tm time_now; + + while ( get_timer_active() ) + { + // sleep a second! + usleep( 1000000 ); + + // get the current time! + time( &clock_now ); + + time_now = *localtime( &clock_now ); + + // set the current time && the current ychat uptime! + set_time( difftime( clock_now, clock_start ), + time_now.tm_sec, time_now.tm_min, time_now.tm_hour ); + + // run every minute: + if ( time_now.tm_sec == 0 ) + { +#ifdef SERVMSG + cout << TIMERUP << get_uptime() << endl; +#endif + //<<* + int* p_timeout_settings = new int[3]; + p_timeout_settings[0] = tool::string2int(wrap::CONF->get_elem("chat.idle.timeout")); + p_timeout_settings[1] = tool::string2int(wrap::CONF->get_elem("chat.idle.awaytimeout")); + p_timeout_settings[2] = tool::string2int(wrap::CONF->get_elem("chat.idle.autoawaytimeout")); + wrap::CHAT->check_timeout( p_timeout_settings ); + delete p_timeout_settings; + + string s_ping = "<!-- PING! //-->\n"; + wrap::CHAT->msg_post( &s_ping ); + +#ifdef DATABASE + // Disconnecting idle database conenction + wrap::DATA->check_data_con_timeout(); +#endif + //*>> + // Run every ten minutes: + if ( time_now.tm_min % 10 == 0 ) + { + + wrap::SOCK->clean_ipcache(); + // Run every hour + if ( time_now.tm_min % 60 == 0 ) + { + wrap::GCOL->remove_garbage(); //<< + + // Run every day + if (time_now.tm_min == 0 || time_now.tm_min == 60 ) + if (time_now.tm_hour == 0 || time_now.tm_hour == 24) + wrap::STAT->update_rusage_history(); + } + } + } + } +} + +void +timr::set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur_hours ) +{ + + int i_hours = (int) d_uptime / 3600; + int i_minutes = (int) d_uptime / 60; + + while ( i_minutes >= 60 ) + i_minutes -= 60; + + while ( d_uptime >= 60 ) + d_uptime -= 60; + + // Calculate offset time + i_cur_hours += get_offset(); + + for ( int i = 24-i_cur_hours; i < 0; i = 24-i_cur_hours ) + i_cur_hours =- i; + + if (i_cur_hours == 24) + i_cur_hours = 0; + + s_time = add_zero_to_front( tool::int2string( i_cur_hours ) ) + ":" + + add_zero_to_front( tool::int2string( i_cur_minutes ) ) + ":" + + add_zero_to_front( tool::int2string( i_cur_seconds ) ); + + s_uptime = add_zero_to_front( tool::int2string( i_hours ) ) + ":" + + add_zero_to_front( tool::int2string( i_minutes ) ) + ":" + + add_zero_to_front( tool::int2string( (int) d_uptime ) ); +} + +string +timr::add_zero_to_front( string s_time ) +{ + if ( s_time.length() == 1 ) + { + string s_new = "0" + s_time; + return s_new; + } + + return s_time; +} + +double +timr::get_time_diff( time_t &clock_diff ) +{ + time_t clock_now; + time( &clock_now ); + + return difftime(clock_now, clock_diff); +} +#endif diff --git a/src/time/timr.h b/src/time/timr.h new file mode 100644 index 0000000..69d411c --- /dev/null +++ b/src/time/timr.h @@ -0,0 +1,75 @@ +/*:* + *: File: ./src/time/timr.h + *: + *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: Copyright (C) 2006, 2007 Paul C. Buetow + *: + *: This program is free software; you can redistribute it and/or + *: modify it under the terms of the GNU General Public License + *: as published by the Free Software Foundation; either version 2 + *: of the License, or (at your option) any later version. + *: + *: This program is distributed in the hope that it will be useful, + *: but WITHOUT ANY WARRANTY; without even the implied warranty of + *: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *: GNU General Public License for more details. + *: + *: You should have received a copy of the GNU General Public License + *: along with this program; if not, write to the Free Software + *: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *:*/ + +#include "../incl.h" + +#ifndef TIMR_H +#define TIMR_H + +#include <unistd.h> + +using namespace std; + +class timr +{ +private: + bool b_timer_active; + int i_time_offset; + string s_uptime; + string s_time; + + +public: + timr(); + ~timr(); + + bool get_timer_active() const; + void start( void *v_ptr ); + + void set_time( double d_uptime, int i_cur_seconds, int i_cur_minutes, int i_cur_hours ); + string add_zero_to_front( string s_time ); + + // inline for dynamic module access! + string + get_time( ) + { + string s_ret; + s_ret = this->s_time; + return s_ret; + } + + string + get_uptime( ) + { + string s_ret; + s_ret = this->s_uptime; + return s_ret; + } + + int get_offset(); + double get_time_diff( time_t &clock_diff ); +}; + +#endif |
