diff options
| author | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:48 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:48 +0200 |
| commit | 5a019f435eb0068b524566d9babf172d58d0e96e (patch) | |
| tree | b083dccdfbec4335a5967d50c4294f7501c77345 /src/chat | |
| parent | 4ecbf33fae730bc79c4a47e6efda615b104754ad (diff) | |
tagging ychat-0.7.9.2ychat-0.7.9.2
Diffstat (limited to 'src/chat')
| -rwxr-xr-x | src/chat/base.h | 4 | ||||
| -rwxr-xr-x | src/chat/base.tmpl | 30 | ||||
| -rwxr-xr-x | src/chat/chat.cpp | 8 | ||||
| -rwxr-xr-x | src/chat/chat.h | 1 | ||||
| -rwxr-xr-x | src/chat/gcol.cpp | 2 | ||||
| -rwxr-xr-x | src/chat/room.cpp | 10 | ||||
| -rwxr-xr-x | src/chat/room.h | 2 | ||||
| -rwxr-xr-x | src/chat/sman.cpp | 20 | ||||
| -rwxr-xr-x | src/chat/sman.h | 3 | ||||
| -rwxr-xr-x | src/chat/user.cpp | 43 | ||||
| -rwxr-xr-x | src/chat/user.h | 7 |
11 files changed, 107 insertions, 23 deletions
diff --git a/src/chat/base.h b/src/chat/base.h index 9da4304..b995c5c 100755 --- a/src/chat/base.h +++ b/src/chat/base.h @@ -9,6 +9,9 @@ template<class type> class base : public nhashmap<type*> { +protected: + void dumpit(); + public: base(); ~base(); @@ -22,6 +25,7 @@ public: } virtual type* get_elem( string s_name, bool &b_found ); // get a element. + virtual type* get_elem( string s_name ); virtual void add_elem( type* p_type ); // add a element. // chat::msg_post sends to all users of the system a message. diff --git a/src/chat/base.tmpl b/src/chat/base.tmpl index 0be21aa..5b0fceb 100755 --- a/src/chat/base.tmpl +++ b/src/chat/base.tmpl @@ -22,10 +22,40 @@ base<type>::get_elem( string s_name, bool &b_found ) } template<class type> +type* +base<type>::get_elem( string s_name) +{ + bool b; + return get_elem(s_name, b); +} + +template<class type> void base<type>::add_elem( type* p_type ) { nhashmap<type*>::add_elem(p_type, p_type->get_lowercase_name()); } +template<class type> +void +base<type>::dumpit() +{ + dumpable::add("[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); + type* p_elem = get_elem(*iter); + if (p_elem) + { + dumpable::next_no_newline(); + dumpable::add(p_elem->dump(dumpable::get_level())); + } + } + + delete p_vec; +} + #endif diff --git a/src/chat/chat.cpp b/src/chat/chat.cpp index 0839261..e4cbaac 100755 --- a/src/chat/chat.cpp +++ b/src/chat/chat.cpp @@ -165,7 +165,6 @@ chat::login( map<string,string> &map_params ) else { sess* p_sess = wrap::SMAN->create_session(); - //p_sess->set_value( string("nick"), (void *) new string(s_user) ); p_sess->set_user(p_user); map_params["tmpid"] = p_sess->get_tmpid(); p_user->set_tmpid( map_params["tmpid"] ); @@ -361,4 +360,11 @@ chat::string_replacer(string *p_msg) } } +void +chat::dumpit() +{ + dumpable::add("[chat]"); + base<room>::dumpit(); +} + #endif diff --git a/src/chat/chat.h b/src/chat/chat.h index 47645c3..bb087d5 100755 --- a/src/chat/chat.h +++ b/src/chat/chat.h @@ -23,6 +23,7 @@ class chat : public base<room>, public perm private: map<string,string> map_replace_strings; vector<string> vec_replace_keys; + void dumpit(); public: virtual room* get_room( string s_name ) diff --git a/src/chat/gcol.cpp b/src/chat/gcol.cpp index 7df111d..d4c9416 100755 --- a/src/chat/gcol.cpp +++ b/src/chat/gcol.cpp @@ -44,6 +44,8 @@ gcol::add_user_to_garbage( user* p_user ) 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(); + #ifdef NCURSES print_garbage(); diff --git a/src/chat/room.cpp b/src/chat/room.cpp index b927d40..0e28c84 100755 --- a/src/chat/room.cpp +++ b/src/chat/room.cpp @@ -101,4 +101,14 @@ room::set_name( string s_name ) #endif } +void +room::dumpit() +{ + dumpable::add("[room]"); + dumpable::add("Name: "+get_name()); + dumpable::add("Topic: "+get_topic()); + base<user>::dumpit(); +} + + #endif diff --git a/src/chat/room.h b/src/chat/room.h index 06b0a9a..4c5fac6 100755 --- a/src/chat/room.h +++ b/src/chat/room.h @@ -23,6 +23,8 @@ private: logd* p_logd; #endif + + void dumpit(); public: room( string s_name ); diff --git a/src/chat/sman.cpp b/src/chat/sman.cpp index d80d421..530aa17 100755 --- a/src/chat/sman.cpp +++ b/src/chat/sman.cpp @@ -21,23 +21,33 @@ sman::~sman() string sman::generate_id( int i_len ) { - string valid_chars = wrap::CONF->get_elem("chat.session.validchars"); + string s_valid = wrap::CONF->get_elem("chat.session.validchars"); string s_ret = ""; srand(time(0)+tool::string2int(wrap::CONF->get_elem("chat.session.kloakkey"))); int i_char; + for (int i = 0; i < i_len; i++) { - i_char = rand() % 64; - s_ret += valid_chars[i_char]; + i_char = rand() % s_valid.length(); + s_ret += s_valid[i_char]; } if ( wrap::CONF->get_elem("chat.session.md5hash") == "true" ) { string s_salt = wrap::CONF->get_elem("chat.session.md5salt"); - s_ret = string(md5::MD5Crypt(s_ret.c_str(), s_salt.c_str())); - return s_ret.substr(s_ret.find(s_salt) + s_salt.length() + 3); + string s_hash(md5::MD5Crypt(s_ret.c_str(), s_salt.c_str())); + s_ret.append(s_hash.substr(s_ret.find(s_salt) + s_salt.length() + 3)); + } + + // Prove, if the TempID already exists + sess* p_sess = get_elem(s_ret); + + if (p_sess) + { + wrap::system_message(SESSEXI); + return generate_id(i_len); } return s_ret; diff --git a/src/chat/sman.h b/src/chat/sman.h index 992fc64..13fc45a 100755 --- a/src/chat/sman.h +++ b/src/chat/sman.h @@ -7,10 +7,11 @@ #include "sess.h" #include "../maps/shashmap.h" +#include "../monitor/dump.h" using namespace std; -class sman : private shashmap<sess*> +class sman : public shashmap<sess*> { private: string generate_id( int i_len ); diff --git a/src/chat/user.cpp b/src/chat/user.cpp index 4f1646b..bac8b7e 100755 --- a/src/chat/user.cpp +++ b/src/chat/user.cpp @@ -73,23 +73,27 @@ user::initialize() void user::clean() { + destroy_session(); + set_fake( false ); + set_invisible( false ); + set_away( false, "" ); +} + +void +user::destroy_session() +{ + if ( !get_has_sess() ) + return; - // If this user has a session - if ( get_has_sess() ) - { #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 ); + // 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 ); #endif - wrap::SMAN->destroy_session( get_tmpid() ); - // wrap::system_message( SESSION + tool::int2string( wrap::SMAN->get_session_count() ) ); - } - - set_fake( false ); - set_invisible( false ); - set_away( false, "" ); + set_has_sess(false); + wrap::SMAN->destroy_session(get_tmpid()); + set_tmpid(""); } string @@ -411,7 +415,7 @@ user::command( string &s_command ) string s_command2 = s_command.substr(0, pos2-1); s_mod.append( s_command2 ).append( ".so" ); - dynmod *mod = wrap::MODL->get_module( s_mod ); + dynmod *mod = wrap::MODL->get_module( s_mod, get_name() ); if ( mod == NULL || wrap::CHAT->get_command_disabled( s_command2 ) || @@ -577,4 +581,15 @@ void user::reconf() {} +void +user::dumpit() +{ + dumpable::add("[user]"); + dumpable::add("Name: " + get_name() + + "; Room: " + get_room()->get_name() + + "; Status: " + tool::int2string(get_status())); + dumpable::add("TempID: " + get_tmpid()); +} + + #endif diff --git a/src/chat/user.h b/src/chat/user.h index 443eef6..1d16695 100755 --- a/src/chat/user.h +++ b/src/chat/user.h @@ -5,13 +5,14 @@ #include "../name.h" #include "../time/timo.h" +#include "../monitor/dump.h" //#include "../memb/memb.h" class room; using namespace std; -class user : public name, public timo//, public memb<string> +class user : public name, public timo, public dumpable //, public memb<string> { private: @@ -56,7 +57,8 @@ private: pthread_mutex_t mut_map_changed_data; void initialize(); - void set_changed_data( string s_varname, string s_value ); + void set_changed_data( string s_varname, string s_value ); + void dumpit(); public: pthread_cond_t cond_message; @@ -67,6 +69,7 @@ public: ~user(); void clean(); + void destroy_session(); // gets specific data of this user und stores it in // (*p_map<string,string>)["nick"]. this method will be used |
