diff options
Diffstat (limited to 'src/chat')
| -rwxr-xr-x | src/chat/chat.cpp | 9 | ||||
| -rwxr-xr-x | src/chat/user.cpp | 87 | ||||
| -rwxr-xr-x | src/chat/user.h | 35 |
3 files changed, 108 insertions, 23 deletions
diff --git a/src/chat/chat.cpp b/src/chat/chat.cpp index e405472..ed8f48d 100755 --- a/src/chat/chat.cpp +++ b/src/chat/chat.cpp @@ -170,7 +170,6 @@ chat::login( map<string,string> &map_params ) map_params["tmpid"] = p_sess->get_tmpid(); p_user->set_tmpid( map_params["tmpid"] ); p_user->set_has_sess( true ); - wrap::system_message("New tmpid: " + map_params["tmpid"] ); } } else // if ( p_user == NULL ) // If not in garbage create a new user! @@ -224,7 +223,6 @@ chat::login( map<string,string> &map_params ) sess* p_sess = wrap::SMAN->create_session(); p_sess->set_user(p_user); map_params["tmpid"] = p_sess->get_tmpid(); - wrap::system_message("New tmpid: " + map_params["tmpid"] ); p_user->set_tmpid( map_params["tmpid"] ); p_user->set_col1( map_params["color1"] ); p_user->set_col2( map_params["color2"] ); @@ -328,6 +326,13 @@ chat::post( user* p_user, map<string,string> &map_params ) if ( i_pos == 0 ) return p_user->command( s_msg ); + if (p_user->get_is_gag()) + { + p_user->msg_post(wrap::CONF->colored_error_msg("chat.msgs.err.gagged")); + return; + } + + string_replacer(&s_msg); string s_post; diff --git a/src/chat/user.cpp b/src/chat/user.cpp index 2b76ec8..eb49f8c 100755 --- a/src/chat/user.cpp +++ b/src/chat/user.cpp @@ -25,6 +25,7 @@ user::~user() pthread_mutex_destroy( & mut_b_invisible ); pthread_mutex_destroy( & mut_b_has_sess ); pthread_mutex_destroy( & mut_b_is_reg ); + pthread_mutex_destroy( & mut_b_is_gag ); pthread_mutex_destroy( & mut_s_mess ); pthread_mutex_destroy( & mut_s_pass ); pthread_mutex_destroy( & mut_p_room ); @@ -41,11 +42,14 @@ user::~user() void user::initialize() { + time(&t_flood_time); init_strings(wrap::CONF->get_vector("chat.fields.userstrings")); init_ints(wrap::CONF->get_vector("chat.fields.userints")); init_bools(wrap::CONF->get_vector("chat.fields.userbools")); + this -> p_room = 0; this -> b_is_reg = false; + this -> b_is_gag = false; this -> b_set_changed_data = false; this -> b_away = false; this -> b_fake = false; @@ -60,6 +64,7 @@ user::initialize() pthread_mutex_init( & mut_b_invisible , NULL ); pthread_mutex_init( & mut_b_has_sess , NULL ); pthread_mutex_init( & mut_b_is_reg , NULL ); + pthread_mutex_init( & mut_b_is_gag , NULL ); pthread_mutex_init( & mut_s_mess , NULL ); pthread_mutex_init( & mut_s_pass , NULL ); pthread_mutex_init( & mut_p_room , NULL ); @@ -72,7 +77,6 @@ user::initialize() pthread_cond_init ( &cond_message, NULL); pthread_mutex_init( &mut_message , NULL); renew_timeout(); - } void @@ -181,6 +185,16 @@ user::get_is_reg( ) return b_ret; } +bool +user::get_is_gag( ) +{ + bool b_ret; + pthread_mutex_lock ( &mut_b_is_gag ); + b_ret = b_is_gag; + pthread_mutex_unlock( &mut_b_is_gag ); + return b_ret; +} + void user::set_is_reg( bool b_is_reg ) { @@ -188,6 +202,14 @@ user::set_is_reg( bool b_is_reg ) } void +user::set_is_gag( bool b_is_gag ) +{ + pthread_mutex_lock ( &mut_b_is_gag ); + this -> b_is_gag = b_is_gag; + pthread_mutex_unlock( &mut_b_is_gag ); +} + +void user::set_online( bool b_online ) { pthread_mutex_lock ( &mut_b_online ); @@ -489,13 +511,52 @@ user::msg_post( string *p_msg ) } void -user::check_timeout( int* i_idle_timeout ) +user::post_action_msg(string s_msgkey) +{ + get_room()->msg_post(wrap::TIMR->get_time()+" "+get_colored_bold_name()+wrap::CONF->get_elem(s_msgkey)+"<br>\n"); +} + +void +user::renew_timeout() { - int i_user_timeout = (int) get_last_activity(); + timo::renew_timeout(); + double d_time_diff = wrap::TIMR->get_time_diff(t_flood_time); - if ( get_away() ? i_idle_timeout[1] <= i_user_timeout : i_idle_timeout[0] <= i_user_timeout ) + if (d_time_diff < static_cast<double>(wrap::CONF->get_int("chat.floodprotection.seconds"))) { - wrap::system_message( string(TIMERTO) + "(" + get_name() + "," + tool::int2string(i_user_timeout) + ")"); + if (++i_flood_messages > static_cast<double>(wrap::CONF->get_int("chat.floodprotection.messages"))) + { + room* p_room = get_room(); + if (p_room == 0) + { + i_flood_messages = 0; + return; + } + + wrap::system_message(CHATFLO+get_name()+","+p_room->get_name()+","+tool::int2string(i_flood_messages)+")"); + msg_post(wrap::CONF->colored_error_msg("chat.msgs.err.flooding")); + if (!get_is_gag()) + { + set_is_gag(true); + post_action_msg("chat.msgs.floodgag"); + } + } + } + + else + { + time(&t_flood_time); + i_flood_messages = 0; + } +} + +void +user::check_timeout( int* i_idle_timeout ) +{ + double d_user_timeout = get_last_activity(); + if ( get_away() ? i_idle_timeout[1] <= d_user_timeout : i_idle_timeout[0] <= d_user_timeout ) + { + wrap::system_message( string(TIMERTO) + "(" + get_name() + "," + tool::int2string((int)d_user_timeout) + ")"); string s_quit = "<script language=JavaScript>top.location.href='/" + wrap::CONF->get_elem("httpd.startsite") + "';</script>"; @@ -504,9 +565,9 @@ user::check_timeout( int* i_idle_timeout ) pthread_cond_signal( &cond_message ); } - else if ( ! get_away() && i_idle_timeout[2] <= i_user_timeout ) + else if ( ! get_away() && i_idle_timeout[2] <= d_user_timeout ) { - wrap::system_message( string(TIMERAT) + "(" + get_name() + "," + tool::int2string(i_user_timeout) + ")"); + wrap::system_message( string(TIMERAT) + "(" + get_name() + "," + tool::int2string((int)d_user_timeout) + ")"); string s_msg = wrap::CONF->get_elem("chat.msgs.userautoawaytimeout"); set_away( true, s_msg ); string s_msg2 = wrap::TIMR->get_time() + " <b>" + get_colored_name()+ "</b>" + s_msg + "<br>\n"; @@ -599,5 +660,17 @@ user::dumpit() ("TempID: " + get_tmpid()); } +bool +user::same_rooms(user *p_user) +{ + return p_user->get_room()->get_lowercase_name() + .compare(this->get_room()->get_lowercase_name()) == 0; +} + +string +user::make_colors(string s_msg) +{ + return "<font color=\"#" + get_col1() + "\">" + s_msg + "</font>"; +} #endif diff --git a/src/chat/user.h b/src/chat/user.h index 62814b5..06310ca 100755 --- a/src/chat/user.h +++ b/src/chat/user.h @@ -23,16 +23,19 @@ private: // private members: string s_mess; // message string which has to be sent to the user. - bool b_online; // true if user is online. - bool b_has_sess; // true if user already has a session! - bool b_is_reg; // true if user is registered - bool b_away; // true if user is away. - bool b_fake; // true if user hides his status logo (does not work for guest) - bool b_invisible; // true if user hides his status logo (does not work for guest) - bool b_set_changed_data; // Only set change data if required! - - int i_status; // user's rang ( see enum rang @ globals.h ). - int i_old_status; // user's previous status. + bool b_online; // true if user is online. + bool b_has_sess; // true if user already has a session! + bool b_is_reg; // true if user is registered + bool b_is_gag; // true if user is gagged + bool b_away; // true if user is away. + bool b_fake; // true if user hides his status logo (does not work for guest) + bool b_invisible; // true if user hides his status logo (does not work for guest) + bool b_set_changed_data; // Only set change data if required! + + int i_status; // user's rang ( see enum rang @ globals.h ). + int i_old_status; // user's previous status. + int i_flood_messages; // user's message posts (needed for flood protection, does not need to be syncronized) + time_t t_flood_time; // user's time count (needed for flood protection, does not need to be syncronized) string s_tmpid; string s_agnt; // user's http user agent. @@ -55,6 +58,7 @@ private: pthread_mutex_t mut_b_invisible; pthread_mutex_t mut_b_has_sess; pthread_mutex_t mut_b_is_reg; + pthread_mutex_t mut_b_is_gag; pthread_mutex_t mut_s_pass; pthread_mutex_t mut_p_room; pthread_mutex_t mut_s_col1; @@ -94,15 +98,14 @@ public: bool get_invisible(); bool get_has_sess(); bool get_is_reg(); + bool get_is_gag(); void set_online( bool b_online ); void set_fake( bool b_fake ); void set_invisible( bool b_invisible ); void set_has_sess( bool b_has_sess ); void set_is_reg( bool b_is_reg ); - void set_changed_data_on() - { - b_set_changed_data = 1; - } + void set_is_gag( bool b_is_gag ); + void set_changed_data_on() { b_set_changed_data = 1; } bool get_away( ); string get_away_msg( ); void set_away( bool b_away, string s_away ); @@ -122,7 +125,9 @@ public: int get_status( ); void set_status( int i_status ); bool new_msgs ( ); + void post_action_msg(string s_msgkey); void check_timeout( int* i_idle_timeout ); + void renew_timeout(); // executes a command. void command( string &s_command ); @@ -142,6 +147,8 @@ public: void get_user_list( string &s_list ); void check_restore_away(); void reconf(); + bool same_rooms(user *p_user); + string make_colors(string s_msg); }; #endif |
