diff options
| author | Paul Buetow <paul@buetow.org> | 2010-11-21 16:20:55 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2010-11-21 16:20:55 +0000 |
| commit | 6fde6b0fe90abde84011202edd40fe46eb06af44 (patch) | |
| tree | ef760338c50b4df3ae9cca96347bca962fdbec7e /src/chat | |
| parent | 55b08bd93257d32df76efc4e8e3f49311c39ee82 (diff) | |
Diffstat (limited to 'src/chat')
| -rw-r--r-- | src/chat/base.h | 5 | ||||
| -rw-r--r-- | src/chat/base.tmpl | 9 | ||||
| -rw-r--r-- | src/chat/chat.cpp | 55 | ||||
| -rw-r--r-- | src/chat/chat.h | 3 | ||||
| -rw-r--r-- | src/chat/gcol.cpp | 44 | ||||
| -rw-r--r-- | src/chat/gcol.h | 4 | ||||
| -rw-r--r-- | src/chat/perm.cpp | 3 | ||||
| -rw-r--r-- | src/chat/perm.h | 3 | ||||
| -rw-r--r-- | src/chat/room.cpp | 18 | ||||
| -rw-r--r-- | src/chat/room.h | 5 | ||||
| -rw-r--r-- | src/chat/sess.cpp | 5 | ||||
| -rw-r--r-- | src/chat/sess.h | 3 | ||||
| -rw-r--r-- | src/chat/sman.cpp | 21 | ||||
| -rw-r--r-- | src/chat/sman.h | 4 | ||||
| -rw-r--r-- | src/chat/user.cpp | 307 | ||||
| -rw-r--r-- | src/chat/user.h | 109 |
16 files changed, 349 insertions, 249 deletions
diff --git a/src/chat/base.h b/src/chat/base.h index bba37e0..145fb6c 100644 --- a/src/chat/base.h +++ b/src/chat/base.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/base.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -44,7 +43,7 @@ public: static string to_lower( string s ) { string s_tmp(""); - for (int i=0;i < s.size() ;i++) + for(int i=0;i < s.size() ;i++) s_tmp=s_tmp+(char)tolower(s.at(i)); return s_tmp; } diff --git a/src/chat/base.tmpl b/src/chat/base.tmpl index 9b1d682..a8db1a0 100644 --- a/src/chat/base.tmpl +++ b/src/chat/base.tmpl @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/base.tmpl *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -66,20 +65,20 @@ void base<type>::dumpit() { dumpable::add - ("[base]"); + ("[base]"); vector<string>* p_vec = nhashmap<type*>::get_key_vector(); vector<string>::iterator iter; for (iter = p_vec->begin(); iter != p_vec->end(); ++iter) { dumpable::add - (*iter); + (*iter); type* p_elem = get_elem(*iter); if (p_elem) { dumpable::next_no_newline(); dumpable::add - (p_elem->dump(dumpable::get_level())); + (p_elem->dump(dumpable::get_level())); } } diff --git a/src/chat/chat.cpp b/src/chat/chat.cpp index cea9ab6..066bfbc 100644 --- a/src/chat/chat.cpp +++ b/src/chat/chat.cpp @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/chat.cpp *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -37,15 +36,12 @@ using namespace std; chat::chat( ) { - { - // Set up replace strings; + { // Set up replace strings; wrap::system_message(CHATREP); vector<string>* p_vec_keys = wrap::CONF->get_key_vector(); - for (vector<string>::iterator iter = p_vec_keys-> - begin(); - iter != p_vec_keys->end(); - iter++ ) + for (vector<string>::iterator iter = p_vec_keys-> begin(); + iter != p_vec_keys->end(); iter++ ) { if ( iter->length() >= 24 && iter->compare( 0, 22, "chat.html.replace.from" ) == 0 ) { @@ -150,9 +146,17 @@ chat::login( map<string,string> &map_params ) return; } - // prove if nick is banned from chat - if (map_banned_nicks.exists(tool::to_lower(s_user))) + // prove if maxpoolsize (threads) allows this login + else if ( !pool::allow_user_login() ) { + map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.maxuserlimit" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. + wrap::system_message( LOGINE5 + s_user); + return; + } + + // prove if nick is banned from chat + if (map_banned_nicks.exists(tool::to_lower(s_user))) { map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.banned" ); map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); return; @@ -220,8 +224,7 @@ chat::login( map<string,string> &map_params ) return; } else - { - // If registered use saved options + { // If registered use saved options map_params["registered"] = "yes"; map_params["color1"] = map_results["color1"]; map_params["color2"] = map_results["color2"]; @@ -232,8 +235,7 @@ chat::login( map<string,string> &map_params ) else #endif - { - // If not registered prove if guest chatting is enabled. + { // If not registered prove if guest chatting is enabled. if (wrap::CONF->get_elem("chat.enableguest") != "true") { map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.noguest" ); @@ -302,7 +304,7 @@ chat::login( map<string,string> &map_params ) // Now we will store all wanted user data into MySQL after logging out! (recycled user already have this set) p_user->set_changed_data_on(); } - p_room->msg_post(&s_msg); + p_room->msg_post( &s_msg ); } void @@ -355,8 +357,8 @@ chat::post( user* p_user, map<string,string> &map_params ) if (p_user->get_is_gag()) { - p_user->msg_post(wrap::CONF->colored_error_msg("chat.msgs.err.gagged")); - return; + p_user->msg_post(wrap::CONF->colored_error_msg("chat.msgs.err.gagged")); + return; } @@ -399,30 +401,28 @@ void chat::dumpit() { dumpable::add - ("[chat]"); + ("[chat]"); base<room>::dumpit(); } string -chat::ban_nick(string &s_nick, string s_reason) -{ +chat::ban_nick(string &s_nick, string s_reason) { string s_lower_nick(tool::to_lower(s_nick)); if (map_banned_nicks.exists(s_lower_nick)) - return map_banned_nicks.get_elem(s_lower_nick); - + return map_banned_nicks.get_elem(s_lower_nick); + map_banned_nicks.add_elem(s_reason, s_lower_nick); return ""; } string -chat::unban_nick(string &s_nick) -{ +chat::unban_nick(string &s_nick) { string s_lower_nick(tool::to_lower(s_nick)); if (!map_banned_nicks.exists(s_lower_nick)) - return ""; - + return ""; + string s_ret(map_banned_nicks.get_elem(s_lower_nick)); map_banned_nicks.del_elem(s_lower_nick); @@ -430,8 +430,7 @@ chat::unban_nick(string &s_nick) } shashmap<string>* -chat::get_map_banned_nicks() -{ +chat::get_map_banned_nicks() { return &map_banned_nicks; } diff --git a/src/chat/chat.h b/src/chat/chat.h index edc5270..9da40e7 100644 --- a/src/chat/chat.h +++ b/src/chat/chat.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/chat.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 diff --git a/src/chat/gcol.cpp b/src/chat/gcol.cpp index dddb01d..ffdb8e5 100644 --- a/src/chat/gcol.cpp +++ b/src/chat/gcol.cpp @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/gcol.cpp *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -32,30 +31,37 @@ using namespace std; gcol::gcol() { + pthread_mutex_init( &mut_vec_rooms , NULL); p_map_users = new shashmap<user*>; wrap::system_message( GARBAGE ); + } gcol::~gcol() { remove_garbage(); + pthread_mutex_destroy( &mut_vec_rooms ); delete p_map_users; } void gcol::add_room_to_garbage( room* p_room ) { + pthread_mutex_lock ( &mut_vec_rooms ); vec_rooms.push_back( p_room ); + pthread_mutex_unlock( &mut_vec_rooms ); wrap::system_message( GARROOM + p_room->get_name() ); } void gcol::add_user_to_garbage( user* p_user ) { - p_user->destroy_session(); + p_user->s_mess_delete(); p_map_users->add_elem(p_user, tool::to_lower(p_user->get_name())); wrap::system_message(GARUSER + p_user->get_name()); + p_user->destroy_session(); + } bool @@ -63,13 +69,16 @@ gcol::remove_garbage() { bool b_empty; + pthread_mutex_lock ( &mut_vec_rooms ); b_empty = ( vec_rooms.empty() && p_map_users->size() == 0); + pthread_mutex_unlock( &mut_vec_rooms ); if ( b_empty ) return false; wrap::system_message( GARBACT ); + pthread_mutex_lock ( &mut_vec_rooms ); for ( vector<room*>::iterator iter = vec_rooms.begin(); iter != vec_rooms.end(); iter++ ) { @@ -77,6 +86,7 @@ gcol::remove_garbage() delete *iter; } vec_rooms.clear(); + pthread_mutex_unlock( &mut_vec_rooms ); p_map_users->run_func( delete_users_ ); @@ -88,12 +98,18 @@ gcol::remove_garbage() room* gcol::get_room_from_garbage() { + pthread_mutex_lock ( &mut_vec_rooms ); if ( vec_rooms.empty() ) + { + pthread_mutex_unlock( &mut_vec_rooms ); return NULL; + } + room* p_room = vec_rooms.back(); vec_rooms.pop_back(); + pthread_mutex_unlock( &mut_vec_rooms ); return p_room; } @@ -111,17 +127,17 @@ gcol::get_room_from_garbage_or_new( string s_room ) user* gcol::get_user_from_garbage( string s_user ) { - user* p_user = p_map_users->get_elem(tool::to_lower(s_user)); + + user* p_user = p_map_users->get_elem( tool::to_lower(s_user) ); if ( p_user != NULL ) { - p_map_users->del_elem(tool::to_lower(s_user)); - p_user->set_name(s_user); - p_user->set_online(true); - p_user->set_invisible(false); - p_user->set_sock(NULL); + p_map_users->del_elem( tool::to_lower(s_user) ); + p_user->set_name( s_user ); + p_user->set_online( true ); + p_user->set_invisible( false ); p_user->renew_timeout(); - wrap::system_message(GARUSE2 + p_user->get_name()); + wrap::system_message(GARUSE2 + p_user->get_name() ); } return p_user; @@ -137,10 +153,14 @@ gcol::delete_users_( user *user_obj ) void gcol::lock_mutex() -{} +{ + pthread_mutex_lock ( &mut_vec_rooms ); +} void gcol::unlock_mutex() -{} +{ + pthread_mutex_unlock ( &mut_vec_rooms ); +} #endif diff --git a/src/chat/gcol.h b/src/chat/gcol.h index 710fc5f..bce0db0 100644 --- a/src/chat/gcol.h +++ b/src/chat/gcol.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/gcol.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -42,6 +41,7 @@ private: vector<room*> vec_rooms; shashmap<user*>* p_map_users; + pthread_mutex_t mut_vec_rooms; static void delete_users_( user* user_obj ); diff --git a/src/chat/perm.cpp b/src/chat/perm.cpp index 8adb83f..544d2c0 100644 --- a/src/chat/perm.cpp +++ b/src/chat/perm.cpp @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/perm.cpp *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 diff --git a/src/chat/perm.h b/src/chat/perm.h index bac038e..709b60e 100644 --- a/src/chat/perm.h +++ b/src/chat/perm.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/perm.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 diff --git a/src/chat/room.cpp b/src/chat/room.cpp index 39177e7..a4d6549 100644 --- a/src/chat/room.cpp +++ b/src/chat/room.cpp @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/room.cpp *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -33,6 +32,7 @@ using namespace std; room::room( string s_name ) : name( s_name ) { + pthread_mutex_init( &mut_s_topic, NULL ); #ifdef LOGGING p_logd = new logd( wrap::CONF->get_elem("chat.logging.roomlogdir") + get_lowercase_name(), @@ -54,23 +54,29 @@ room::~room() delete p_logd; #endif + pthread_mutex_destroy( &mut_s_topic ); + pthread_mutex_destroy( &mut_s_name ); } string room::get_topic() { string s_ret; + pthread_mutex_lock ( &mut_s_topic ); s_ret = s_topic; + pthread_mutex_unlock( &mut_s_topic ); return s_ret; } void room::set_topic( string s_topic ) { + pthread_mutex_lock ( &mut_s_topic ); if ( s_topic == "" ) this->s_topic = ""; else this->s_topic = s_topic + "<br><br>"; + pthread_mutex_unlock( &mut_s_topic ); reload_onlineframe(); } @@ -83,7 +89,9 @@ room::set_topic( string s_topic, string s_color ) void room::clean_room() { + pthread_mutex_lock ( &mut_s_topic ); this->s_topic = ""; + pthread_mutex_unlock( &mut_s_topic ); wrap::CHAT->del_elem( get_lowercase_name() ); wrap::GCOL->add_room_to_garbage( this ); } @@ -121,11 +129,11 @@ void room::dumpit() { dumpable::add - ("[room]"); + ("[room]"); dumpable::add - ("Name: "+get_name()); + ("Name: "+get_name()); dumpable::add - ("Topic: "+get_topic()); + ("Topic: "+get_topic()); base<user>::dumpit(); } diff --git a/src/chat/room.h b/src/chat/room.h index 035633a..0988fd4 100644 --- a/src/chat/room.h +++ b/src/chat/room.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/room.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -43,6 +42,7 @@ class room : public base<user>, public name { private: string s_topic; + pthread_mutex_t mut_s_topic; #ifdef LOGGING logd* p_logd; @@ -89,6 +89,7 @@ public: #ifdef LOGGING p_logd->log_simple_line( logd::remove_html_tags(*p_msg) ); #endif + base<user>::msg_post( p_msg ); } diff --git a/src/chat/sess.cpp b/src/chat/sess.cpp index 9ba5636..846876d 100644 --- a/src/chat/sess.cpp +++ b/src/chat/sess.cpp @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/sess.cpp *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -80,7 +79,7 @@ sess::set_user(user* p_user) /* void -sess::invalidate() +sess::invalidate() { set_user(NULL); set_tmpid("!invalidated"); diff --git a/src/chat/sess.h b/src/chat/sess.h index d4e099f..db4ad11 100644 --- a/src/chat/sess.h +++ b/src/chat/sess.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/sess.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 diff --git a/src/chat/sman.cpp b/src/chat/sman.cpp index 8026497..187531d 100644 --- a/src/chat/sman.cpp +++ b/src/chat/sman.cpp @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/sman.cpp *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -34,12 +33,14 @@ sman::sman() { i_continous_session_count = i_session_count = 0; + pthread_mutex_init( &mut_i_session_count, NULL ); } sman::~sman() { // Delete each session object of the shashmap! shashmap<sess*>::run_func( mtools<sess*>::delete_obj ); + pthread_mutex_destroy( &mut_i_session_count ); } string sman::generate_id( int i_len ) @@ -82,11 +83,13 @@ sess *sman::create_session( ) sess* p_sess = new sess( s_tmpid ); + pthread_mutex_lock( &mut_i_session_count ); i_session_count++; wrap::system_message(string(SESSIOC) + "(" + - tool::int2string(++i_continous_session_count) + "," + - tool::long2string((long)p_sess) + ")" ); + tool::int2string(++i_continous_session_count) + "," + + tool::int2string(reinterpret_cast<int>(p_sess)) + ")" ); + pthread_mutex_unlock( &mut_i_session_count ); //???? add_elem( p_sess, s_tmpid ); @@ -104,12 +107,14 @@ sman::destroy_session( string s_id ) { sess* p_sess = get_elem(s_id); + pthread_mutex_lock( &mut_i_session_count ); i_session_count--; wrap::system_message(string(SESSIOD) + "(" + - tool::int2string(i_continous_session_count) + "," + - tool::long2string((long)p_sess) + ")" ); + tool::int2string(i_continous_session_count) + "," + + tool::int2string(reinterpret_cast<int>(p_sess)) + ")" ); + pthread_mutex_unlock( &mut_i_session_count ); del_elem(s_id); delete p_sess; @@ -118,14 +123,16 @@ sman::destroy_session( string s_id ) int sman::get_session_count() { + pthread_mutex_lock( &mut_i_session_count ); int i_ret = i_session_count; + pthread_mutex_unlock( &mut_i_session_count ); return i_ret; } /* void sman::dump() { - shashmap<sess*>::dump(); + shashmap<sess*>::dump(); cout << "BLA" << endl; } */ diff --git a/src/chat/sman.h b/src/chat/sman.h index b8aff57..4526ade 100644 --- a/src/chat/sman.h +++ b/src/chat/sman.h @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/sman.h *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -43,6 +42,7 @@ private: int i_session_count; int i_continous_session_count; + pthread_mutex_t mut_i_session_count; public: sman(); diff --git a/src/chat/user.cpp b/src/chat/user.cpp index 80f4c65..93dd672 100644 --- a/src/chat/user.cpp +++ b/src/chat/user.cpp @@ -1,12 +1,11 @@ /*:* *: File: ./src/chat/user.cpp *: - *: yChat; Homepage: ychat.buetow.org; Version 0.9.0-CURRENT + *: yChat; Homepage: www.yChat.org; Version 0.8.3-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 @@ -31,8 +30,6 @@ using namespace std; -#include <errno.h> - user::user() : name( "" ) { initialize(); @@ -44,7 +41,27 @@ user::user( string s_name ) : name( s_name ) } user::~user() -{} +{ + // pthread_mutex_destroy( & mut_map_mods ); + pthread_mutex_destroy( & mut_away ); + pthread_mutex_destroy( & mut_b_online ); + pthread_mutex_destroy( & mut_b_fake ); + 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 ); + pthread_mutex_destroy( & mut_s_col1 ); + pthread_mutex_destroy( & mut_s_col2 ); + pthread_mutex_destroy( & mut_s_email ); + pthread_mutex_destroy( & mut_s_tmpid ); + pthread_mutex_destroy( & mut_i_status ); + pthread_mutex_destroy( & mut_map_changed_data ); + pthread_cond_destroy ( &cond_message ); + pthread_mutex_destroy( &mut_message ); +} void user::initialize() @@ -54,10 +71,7 @@ user::initialize() init_ints(wrap::CONF->get_vector("chat.fields.userints")); init_bools(wrap::CONF->get_vector("chat.fields.userbools")); - this -> l_messages_recv = 0; - this -> p_sock = NULL; this -> p_room = NULL; - this -> s_msg = ""; this -> b_is_reg = false; this -> b_is_gag = false; this -> b_set_changed_data = false; @@ -67,6 +81,25 @@ user::initialize() this -> s_col1 = wrap::CONF->get_elem( "chat.html.user.color1" ); this -> s_col2 = wrap::CONF->get_elem( "chat.html.user.color2" ); + // pthread_mutex_init( & mut_map_mods , NULL ); + pthread_mutex_init( & mut_away , NULL ); + pthread_mutex_init( & mut_b_online , NULL ); + pthread_mutex_init( & mut_b_fake , NULL ); + 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 ); + pthread_mutex_init( & mut_s_col1 , NULL ); + pthread_mutex_init( & mut_s_col2 , NULL ); + pthread_mutex_init( & mut_s_email , NULL ); + pthread_mutex_init( & mut_s_tmpid , NULL ); + pthread_mutex_init( & mut_i_status , NULL ); + pthread_mutex_init( & mut_map_changed_data , NULL ); + pthread_cond_init ( &cond_message, NULL); + pthread_mutex_init( &mut_message , NULL); renew_timeout(); } @@ -74,10 +107,9 @@ void user::clean() { destroy_session(); - set_fake(false); - set_invisible(false); - set_away(false, ""); - set_sock(NULL); + set_fake( false ); + set_invisible( false ); + set_away( false, "" ); } void @@ -89,8 +121,8 @@ user::destroy_session() #ifdef DATABASE // Store all changed data into the mysql table if this user is registered: if ( b_is_reg ) - wrap::DATA->update_user_data( get_name(), "savechangednick", - map_changed_data ); + wrap::DATA->update_user_data( get_name(), "savechangednick", + map_changed_data ); #endif set_has_sess(false); @@ -115,46 +147,78 @@ user::get_data( map<string,string> *p_map_data ) (*p_map_data)[get_name()] = get_col1(); } +string +user::get_mess( ) +{ + pthread_mutex_lock ( &mut_s_mess ); + string s_ret = s_mess; + s_mess = ""; + pthread_mutex_unlock( &mut_s_mess ); + return s_ret; +} + bool user::get_online( ) { - return b_online; + bool b_ret; + pthread_mutex_lock ( &mut_b_online ); + b_ret = b_online; + pthread_mutex_unlock( &mut_b_online ); + return b_ret; } - bool user::get_fake( ) { - return b_fake; + bool b_ret; + pthread_mutex_lock ( &mut_b_fake ); + b_ret = b_fake; + pthread_mutex_unlock( &mut_b_fake ); + return b_ret; } - bool user::get_invisible( ) { - return b_invisible; + bool b_ret; + pthread_mutex_lock ( &mut_b_invisible ); + b_ret = b_invisible; + pthread_mutex_unlock( &mut_b_invisible ); + return b_ret; } bool user::get_has_sess( ) { - return b_has_sess; + bool b_ret; + pthread_mutex_lock ( &mut_b_has_sess ); + b_ret = b_has_sess; + pthread_mutex_unlock( &mut_b_has_sess ); + return b_ret; } void -user::set_has_sess(bool b_has_sess) +user::set_has_sess( bool b_has_sess ) { + pthread_mutex_lock ( &mut_b_has_sess ); this->b_has_sess = b_has_sess; + pthread_mutex_unlock( &mut_b_has_sess ); } bool user::get_is_reg( ) { - return b_is_reg; + bool b_ret; + b_ret = b_is_reg; + return b_ret; } bool user::get_is_gag( ) { - return b_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 @@ -166,60 +230,42 @@ 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 ) { - if (this->b_online == b_online) - return; - + pthread_mutex_lock ( &mut_b_online ); this -> b_online = b_online; - if (!b_online) - { - cout << "SETTING OFFLINE" << endl; - // remove the user from its room. - string s_user(get_name()); - string s_user_lowercase(get_lowercase_name()); - - room* p_room = get_room(); - p_room->del_elem(s_user_lowercase); - - // post the room that the user has left the chat. - string s_msg = wrap::TIMR->get_time() + " " - + get_colored_bold_name() - + wrap::CONF->get_elem( "chat.msgs.userleaveschat" ) - + "<br>\n"; - - p_room->msg_post( &s_msg ); - p_room->reload_onlineframe(); - -#ifdef VERBOSE - cout << REMUSER << s_user << endl; -#endif - - wrap::GCOL->add_user_to_garbage(this); - } + pthread_mutex_unlock( &mut_b_online ); } void user::set_fake( bool b_fake ) { + pthread_mutex_lock ( &mut_b_fake ); this -> b_fake = b_fake; + pthread_mutex_unlock( &mut_b_fake ); } void user::set_invisible( bool b_invisible ) { + pthread_mutex_lock ( &mut_b_invisible ); this -> b_invisible = b_invisible; + pthread_mutex_unlock( &mut_b_invisible ); } bool user::get_away() { bool b_ret; + pthread_mutex_lock ( &mut_away ); b_ret = b_away; + pthread_mutex_unlock( &mut_away ); return b_ret; } @@ -227,35 +273,45 @@ string user::get_away_msg() { string s_ret; + pthread_mutex |
