From 2860b03f00e48264ed15c132ad90b240ebe6070b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:47 +0200 Subject: tagging ychat-0.7.9.5 --- src/Makefile.in | 0 src/chat/base.h | 182 ++- src/chat/base.tmpl | 70 +- src/chat/chat.cpp | 512 ++++--- src/chat/chat.h | 96 +- src/chat/gcol.cpp | 185 ++- src/chat/gcol.h | 55 +- src/chat/perm.cpp | 93 +- src/chat/perm.h | 69 +- src/chat/room.cpp | 129 +- src/chat/room.h | 141 +- src/chat/sess.cpp | 63 +- src/chat/sess.h | 45 +- src/chat/sman.cpp | 151 +- src/chat/sman.h | 54 +- src/chat/user.cpp | 712 +++++----- src/chat/user.h | 261 ++-- src/cli/cli.cpp | 513 ++++--- src/cli/cli.h | 63 +- src/conf/conf.cpp | 225 +-- src/conf/conf.h | 45 +- src/configure | 311 +++-- src/contrib/crypt/md5.cpp | 357 ++--- src/contrib/crypt/md5.h | 39 +- src/contrib/crypt/md5crypt.cpp | 257 ++-- src/contrib/xml/tinyxml.cpp | 1703 ++++++++++++----------- src/contrib/xml/tinyxml.h | 2266 +++++++++++++++++------------- src/contrib/xml/tinyxmlerror.cpp | 68 +- src/contrib/xml/tinyxmlparser.cpp | 2708 +++++++++++++++++++----------------- src/data/con.cpp | 76 +- src/data/con.h | 32 +- src/data/con_base.cpp | 29 +- src/data/con_base.h | 28 +- src/data/data.cpp | 286 ++-- src/data/data.h | 42 +- src/data/data_base.cpp | 256 ++-- src/data/data_base.h | 47 +- src/glob.h | 203 +-- src/html.cpp | 186 +-- src/html.h | 69 +- src/incl.h | 30 +- src/logd.cpp | 216 +-- src/logd.h | 63 +- src/main.cpp | 227 +-- src/maps/hashmap.h | 38 +- src/maps/hashmap.tmpl | 24 + src/maps/mtools.h | 30 +- src/maps/mtools.tmpl | 29 +- src/maps/nhashmap.h | 32 +- src/maps/nhashmap.tmpl | 24 + src/maps/shashmap.h | 36 +- src/maps/shashmap.tmpl | 32 +- src/modl.cpp | 187 ++- src/modl.h | 58 +- src/mods/Makefile | 9 +- src/mods/commands/Makefile.in | 2 +- src/mods/commands/yc_about.cpp | 24 + src/mods/commands/yc_all.cpp | 24 + src/mods/commands/yc_away.cpp | 150 +- src/mods/commands/yc_col.cpp | 167 ++- src/mods/commands/yc_compopt.cpp | 45 +- src/mods/commands/yc_exec.cpp | 108 +- src/mods/commands/yc_fake.cpp | 67 +- src/mods/commands/yc_getroom.cpp | 94 +- src/mods/commands/yc_getrusage.cpp | 93 +- src/mods/commands/yc_help.cpp | 105 +- src/mods/commands/yc_invisible.cpp | 69 +- src/mods/commands/yc_j.cpp | 203 +-- src/mods/commands/yc_ko.cpp | 112 +- src/mods/commands/yc_m.cpp | 89 +- src/mods/commands/yc_md5.cpp | 108 +- src/mods/commands/yc_me.cpp | 77 +- src/mods/commands/yc_morph.cpp | 101 +- src/mods/commands/yc_msg.cpp | 128 +- src/mods/commands/yc_q.cpp | 51 +- src/mods/commands/yc_reload.cpp | 57 +- src/mods/commands/yc_ren.cpp | 132 +- src/mods/commands/yc_s.cpp | 105 +- src/mods/commands/yc_set.cpp | 199 +-- src/mods/commands/yc_template.cpp | 51 +- src/mods/commands/yc_time.cpp | 55 +- src/mods/commands/yc_topic.cpp | 162 ++- src/mods/commands/yc_uptime.cpp | 55 +- src/mods/commands/yc_users.cpp | 24 + src/mods/commands/yc_version.cpp | 45 +- src/mods/html/Makefile.in | 4 +- src/mods/html/yc_admin.cpp | 143 +- src/mods/html/yc_colors.cpp | 76 +- src/mods/html/yc_help.cpp | 100 +- src/mods/html/yc_loggedin.cpp | 24 + src/mods/html/yc_options.cpp | 103 +- src/mods/html/yc_register.cpp | 189 +-- src/monitor/dump.cpp | 51 +- src/monitor/dump.h | 55 +- src/monitor/stats.cpp | 24 + src/monitor/stats.h | 24 + src/msgs.h | 84 +- src/name.cpp | 56 +- src/name.h | 44 +- src/ncur/menu.cpp | 173 ++- src/ncur/menu.h | 51 +- src/ncur/ncur.cpp | 396 +++--- src/ncur/ncur.h | 75 +- src/reqp.cpp | 570 ++++---- src/reqp.h | 86 +- src/sign.cpp | 29 +- src/sign.h | 27 +- src/sock/sock.cpp | 613 +++++--- src/sock/sock.h | 127 +- src/thrd/pool.cpp | 281 ++-- src/thrd/pool.h | 106 +- src/thrd/thro.cpp | 48 +- src/thrd/thro.h | 48 +- src/time/timo.cpp | 48 +- src/time/timo.h | 36 +- src/time/timr.cpp | 226 +-- src/time/timr.h | 105 +- src/tool/dir.cpp | 68 +- src/tool/dir.h | 50 +- src/tool/tool.cpp | 273 +++- src/tool/tool.h | 120 +- src/wrap.cpp | 161 ++- src/wrap.h | 150 +- 123 files changed, 12556 insertions(+), 8652 deletions(-) mode change 100755 => 100644 src/Makefile.in mode change 100755 => 100644 src/chat/base.h mode change 100755 => 100644 src/chat/base.tmpl mode change 100755 => 100644 src/chat/chat.cpp mode change 100755 => 100644 src/chat/chat.h mode change 100755 => 100644 src/chat/gcol.cpp mode change 100755 => 100644 src/chat/gcol.h mode change 100755 => 100644 src/chat/perm.cpp mode change 100755 => 100644 src/chat/perm.h mode change 100755 => 100644 src/chat/room.cpp mode change 100755 => 100644 src/chat/room.h mode change 100755 => 100644 src/chat/sess.cpp mode change 100755 => 100644 src/chat/sess.h mode change 100755 => 100644 src/chat/sman.cpp mode change 100755 => 100644 src/chat/sman.h mode change 100755 => 100644 src/chat/user.cpp mode change 100755 => 100644 src/chat/user.h mode change 100755 => 100644 src/cli/cli.cpp mode change 100755 => 100644 src/cli/cli.h mode change 100755 => 100644 src/conf/conf.cpp mode change 100755 => 100644 src/conf/conf.h mode change 100755 => 100644 src/data/con.cpp mode change 100755 => 100644 src/data/con.h mode change 100755 => 100644 src/data/con_base.cpp mode change 100755 => 100644 src/data/con_base.h mode change 100755 => 100644 src/glob.h mode change 100755 => 100644 src/html.cpp mode change 100755 => 100644 src/html.h mode change 100755 => 100644 src/incl.h mode change 100755 => 100644 src/logd.cpp mode change 100755 => 100644 src/logd.h mode change 100755 => 100644 src/main.cpp mode change 100755 => 100644 src/modl.cpp mode change 100755 => 100644 src/modl.h mode change 100755 => 100644 src/mods/Makefile mode change 100755 => 100644 src/mods/commands/Makefile.in mode change 100755 => 100644 src/mods/commands/yc_all.cpp mode change 100755 => 100644 src/mods/commands/yc_away.cpp mode change 100755 => 100644 src/mods/commands/yc_col.cpp mode change 100755 => 100644 src/mods/commands/yc_compopt.cpp mode change 100755 => 100644 src/mods/commands/yc_exec.cpp mode change 100755 => 100644 src/mods/commands/yc_fake.cpp mode change 100755 => 100644 src/mods/commands/yc_getroom.cpp mode change 100755 => 100644 src/mods/commands/yc_getrusage.cpp mode change 100755 => 100644 src/mods/commands/yc_help.cpp mode change 100755 => 100644 src/mods/commands/yc_invisible.cpp mode change 100755 => 100644 src/mods/commands/yc_j.cpp mode change 100755 => 100644 src/mods/commands/yc_ko.cpp mode change 100755 => 100644 src/mods/commands/yc_m.cpp mode change 100755 => 100644 src/mods/commands/yc_md5.cpp mode change 100755 => 100644 src/mods/commands/yc_me.cpp mode change 100755 => 100644 src/mods/commands/yc_morph.cpp mode change 100755 => 100644 src/mods/commands/yc_msg.cpp mode change 100755 => 100644 src/mods/commands/yc_q.cpp mode change 100755 => 100644 src/mods/commands/yc_reload.cpp mode change 100755 => 100644 src/mods/commands/yc_ren.cpp mode change 100755 => 100644 src/mods/commands/yc_s.cpp mode change 100755 => 100644 src/mods/commands/yc_set.cpp mode change 100755 => 100644 src/mods/commands/yc_template.cpp mode change 100755 => 100644 src/mods/commands/yc_time.cpp mode change 100755 => 100644 src/mods/commands/yc_topic.cpp mode change 100755 => 100644 src/mods/commands/yc_uptime.cpp mode change 100755 => 100644 src/mods/commands/yc_users.cpp mode change 100755 => 100644 src/mods/commands/yc_version.cpp mode change 100755 => 100644 src/mods/html/Makefile.in mode change 100755 => 100644 src/mods/html/yc_colors.cpp mode change 100755 => 100644 src/mods/html/yc_help.cpp mode change 100755 => 100644 src/mods/html/yc_loggedin.cpp mode change 100755 => 100644 src/mods/html/yc_options.cpp mode change 100755 => 100644 src/mods/html/yc_register.cpp mode change 100755 => 100644 src/msgs.h mode change 100755 => 100644 src/name.cpp mode change 100755 => 100644 src/name.h mode change 100755 => 100644 src/ncur/menu.cpp mode change 100755 => 100644 src/ncur/menu.h mode change 100755 => 100644 src/ncur/ncur.cpp mode change 100755 => 100644 src/ncur/ncur.h mode change 100755 => 100644 src/reqp.cpp mode change 100755 => 100644 src/reqp.h mode change 100755 => 100644 src/sock/sock.cpp mode change 100755 => 100644 src/sock/sock.h mode change 100755 => 100644 src/thrd/pool.cpp mode change 100755 => 100644 src/thrd/pool.h mode change 100755 => 100644 src/time/timo.cpp mode change 100755 => 100644 src/time/timo.h mode change 100755 => 100644 src/time/timr.cpp mode change 100755 => 100644 src/time/timr.h mode change 100755 => 100644 src/wrap.cpp mode change 100755 => 100644 src/wrap.h (limited to 'src') diff --git a/src/Makefile.in b/src/Makefile.in old mode 100755 new mode 100644 diff --git a/src/chat/base.h b/src/chat/base.h old mode 100755 new mode 100644 index ae2e926..bfdd6f6 --- a/src/chat/base.h +++ b/src/chat/base.h @@ -1,89 +1,117 @@ -// template class data declaration; +/*:* + *: File: ./src/chat/base.h + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: 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 BASE_H #define BASE_H -#include "../maps/smap.h" +#include +#include "../maps/nhashmap.h" template -class base : public smap +class base : public nhashmap { +protected: + void dumpit(); + public: - base(); - ~base(); - - static string to_lower( string s ) - { - string s_tmp(""); - for(int i=0;i < s.size() ;i++) - s_tmp=s_tmp+(char)tolower(s.at(i)); - return s_tmp; - } - - virtual type* get_elem( string s_name, bool &b_found ); // get a element. - virtual void add_elem( type* p_type ); // add a element. - - // chat::msg_post sends to all users of the system a message. - // room::msg_post sends to all users of the room a message. - // user::msg_post sends to the user a message. - virtual void msg_post( string *s_msg ) - { - smap::run_func( &base::msg_post_ , (void*)s_msg ); - } - - static void msg_post_( type* type_obj, void* v_arg ) - { - type_obj -> msg_post( (string*) v_arg ); - } - - virtual void check_timeout( int* i_timeout_settings ) - { - smap::run_func( &base::check_timeout_ , (void*)i_timeout_settings ); - } - - static void check_timeout_( type* type_obj, void* v_arg ) - { - type_obj -> check_timeout( (int*) v_arg ); - } - - virtual void reconf() - { - smap::run_func( &base::reconf_ ); - } - - static void reconf_ ( type* type_obj ) - { - type_obj -> reconf (); - } - - void get_data( map_string *p_map_string ) - { - smap::run_func( &base::get_data_ , (void*)p_map_string ); - } - - static void get_data_( type* type_obj, void* v_arg ) - { - type_obj -> get_data ( (map_string*) v_arg ); - } - - - // chat::get_user_list gets a list of all users of the system. - // room::get_user_list gets a list of all users of the room. - // user::get_user_list gets a "list" of a user usernameseperator - void get_user_list( string &s_list ) - { - container c; - c.elem[0] = (void*) &s_list; - - smap::run_func( &base::get_user_list_, (void*)&c ); - } - - static void get_user_list_( type* type_obj, void* v_arg ) - { - container *c = (container*) v_arg; - type_obj -> get_user_list( *((string*)c->elem[0]) ); - } + base(); + ~base(); + + static string to_lower( string s ) + { + string s_tmp(""); + for(int i=0;i < s.size() ;i++) + s_tmp=s_tmp+(char)tolower(s.at(i)); + return s_tmp; + } + + 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. + // room::msg_post sends to all users of the room a message. + // user::msg_post sends to the user a message. + virtual void msg_post( string *s_msg ) + { + nhashmap::run_func( &base::msg_post_ , (void*)s_msg ); + } + + static void msg_post_( type* type_obj, void* v_arg ) + { + type_obj -> msg_post( (string*) v_arg ); + } + + virtual void check_timeout( int* i_timeout_settings ) + { + nhashmap::run_func( &base::check_timeout_ , (void*)i_timeout_settings ); + } + + static void check_timeout_( type* type_obj, void* v_arg ) + { + type_obj -> check_timeout( (int*) v_arg ); + } + + virtual void reconf() + { + nhashmap::run_func( &base::reconf_ ); + } + + static void reconf_ ( type* type_obj ) + { + type_obj -> reconf (); + } + + void get_data( map *p_map_string ) + { + nhashmap::run_func( &base::get_data_ , (void*)p_map_string ); + } + + static void get_data_( type* type_obj, void* v_arg ) + { + type_obj -> get_data ( (map*) v_arg ); + } + + + // chat::get_user_list gets a list of all users of the system. + // room::get_user_list gets a list of all users of the room. + // user::get_user_list gets a "list" of a user usernameseperator + void get_user_list( string &s_list ) + { + container c; + c.elem[0] = (void*) &s_list; + + nhashmap::run_func( &base::get_user_list_, (void*)&c ); + } + + static void get_user_list_( type* type_obj, void* v_arg ) + { + container *c = (container*) v_arg; + type_obj -> get_user_list( *((string*)c->elem[0]) ); + } }; #include "base.tmpl" diff --git a/src/chat/base.tmpl b/src/chat/base.tmpl old mode 100755 new mode 100644 index 53b609f..c94ed44 --- a/src/chat/base.tmpl +++ b/src/chat/base.tmpl @@ -1,33 +1,85 @@ +/*:* + *: File: ./src/chat/base.tmpl + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: 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 BASE_CPP #define BASE_CPP #include "base.h" template -base::base() : smap::smap(HMAPOCC) -{ -} +base::base() +{} template base::~base( ) +{} + +template +type* +base::get_elem( string s_name, bool &b_found ) { + s_name = to_lower(s_name); + type* p_type = nhashmap::get_elem( s_name ); + b_found = p_type == NULL ? false : true; + return p_type; } template type* -base::get_elem( string s_name, bool &b_found ) +base::get_elem( string s_name) { - s_name = to_lower(s_name); - type* p_type = smap::get_elem( s_name ); - b_found = p_type == NULL ? false : true; - return p_type; + bool b; + return get_elem(s_name, b); } template void base::add_elem( type* p_type ) { - smap::add_elem(p_type, p_type->get_lowercase_name()); + nhashmap::add_elem(p_type, p_type->get_lowercase_name()); +} + +template +void +base::dumpit() +{ + dumpable::add("[base]"); + vector* p_vec = nhashmap::get_key_vector(); + + vector::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 old mode 100755 new mode 100644 index 86bc140..764da85 --- a/src/chat/chat.cpp +++ b/src/chat/chat.cpp @@ -1,3 +1,27 @@ +/*:* + *: File: ./src/chat/chat.cpp + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: 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. + *:*/ + // class chat implementation. #ifndef CHAT_CPP @@ -12,327 +36,359 @@ using namespace std; chat::chat( ) { - { // Set up replace strings; - wrap::system_message(CHATREP); - vector* p_vec_keys = wrap::CONF->get_key_vector(); - - for (vector::iterator iter = p_vec_keys->begin(); - iter != p_vec_keys->end(); iter++ ) + { // Set up replace strings; + wrap::system_message(CHATREP); + vector* p_vec_keys = wrap::CONF->get_key_vector(); + + for (vector::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 ) { - if ( iter->length() >= 24 && iter->compare( 0, 22, "chat.html.replace.from" ) == 0 ) - { string s_from = wrap::CONF->get_elem(*iter); map_replace_strings[s_from] = "chat.html.replace.into." + s_from; - vec_replace_keys.push_back(s_from); - } - } - - sort(vec_replace_keys.begin(), vec_replace_keys.end()); - delete p_vec_keys; + vec_replace_keys.push_back(s_from); + } } + + sort(vec_replace_keys.begin(), vec_replace_keys.end()); + delete p_vec_keys; + } } chat::~chat( ) { - // Delete all room objects! - run_func( mtools::delete_obj ); + // Delete all room objects! + run_func( mtools::delete_obj ); } user* chat::get_user( string &s_user ) { - bool b_flag; - return get_user( s_user, b_flag ); + bool b_flag; + return get_user( s_user, b_flag ); } user* chat::get_user( string &s_user, bool &b_found ) { - container param; + container param; - param.elem[0] = (void*) &s_user ; - param.elem[1] = (void*) &b_found; + param.elem[0] = (void*) &s_user ; + param.elem[1] = (void*) &b_found; - b_found = false; + b_found = false; - smap::run_func( get_user_, (void*)¶m ); + base::run_func( get_user_, (void*)¶m ); - if ( *( (bool*) param.elem[1] ) ) - return (user*) param.elem[2]; + if ( *( (bool*) param.elem[1] ) ) + return (user*) param.elem[2]; } void chat::get_user_( room *room_obj, void *v_arg ) { - container* param = (container*) v_arg; - if ( *((bool*)param->elem[1]) ) - return; - param->elem[2] = (void*)room_obj->get_elem( *((string*)param->elem[0]), *((bool*)param->elem[1]) ); + container* param = (container*) v_arg; + + if ( *((bool*)param->elem[1]) ) + return; + + param->elem[2] = (void*)room_obj->get_elem( *((string*)param->elem[0]), *((bool*)param->elem[1]) ); } void -chat::login( map_string &map_params ) +chat::login( map &map_params ) { - string s_user = map_params["nick"]; - - // prove if nick is empty: - if ( s_user.empty() ) - { - map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.nonick" ); - map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. - wrap::system_message( LOGINE0 ); - return; - } - - // prove if the nick is alphanumeric: - else if ( ! tool::is_alpha_numeric( s_user ) ) + string s_user = map_params["nick"]; + + // prove if nick is empty: + if ( s_user.empty() ) + { + map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.nonick" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. + wrap::system_message( LOGINE0 ); + return; + } + + // prove if the nick is alphanumeric: + else if ( ! tool::is_alpha_numeric( s_user ) ) + { + map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.alpnum" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. + wrap::system_message( LOGINE1 + s_user ); + return; + } + + // prove if the nick is too long: + else if ( s_user.length() > tool::string2int( wrap::CONF->get_elem("chat.maxlength.username") ) ) + { + map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.nicklength" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. + wrap::system_message( LOGINE2 + s_user ); + return; + } + + // prove if the room name is too long: + else if ( map_params["room"].length() > tool::string2int( wrap::CONF->get_elem("chat.maxlength.roomname") ) ) + { + map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.roomnamelength" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. + wrap::system_message( LOGINE3 + s_user + " / " + map_params["room"] ); + return; + } + + // prove if the room name is valid + else if ( map_params["room"].length() < 1 ) + { + map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.noroom" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. + wrap::system_message( LOGINE3 + s_user + " / " + map_params["room"] ); + return; + } + + // prove if maxpoolsize (threads) allows this login + else if ( !wrap::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; + } + + bool b_flag; + + // prove if nick is already online / logged in. + get_user( s_user, b_flag ); + + if ( b_flag ) + { + map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.online" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); + + return; + } + + // Prove if user is recycleable from the garbage collector: + user *p_user = wrap::GCOL->get_user_from_garbage( s_user ); + + if ( p_user != NULL ) + { + // 1. possibility to prove the password at login! (using recycled user) + if ( p_user->get_pass() != map_params["password"] ) { - map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.alpnum" ); - map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. - wrap::system_message( LOGINE1 + s_user ); - return; - } - - // prove if the nick is too long: - else if ( s_user.length() > tool::string2int( wrap::CONF->get_elem("chat.maxlength.username") ) ) - { - map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.nicklength" ); - map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. - wrap::system_message( LOGINE2 + s_user ); - return; - } - - // prove if the room name is too long: - else if ( map_params["room"].length() > tool::string2int( wrap::CONF->get_elem("chat.maxlength.roomname") ) ) - { - map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.roomnamelength" ); - map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. - wrap::system_message( LOGINE3 + s_user + " / " + map_params["room"] ); - return; - } - - // prove if the room name is valid - else if ( map_params["room"].length() < 1 ) - { - map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.noroom" ); - map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. - wrap::system_message( LOGINE3 + s_user + " / " + map_params["room"] ); - return; - } - - bool b_flag; - - // prove if nick is already online / logged in. - get_user( s_user, b_flag ); - - if ( b_flag ) - { - map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.online" ); - map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); - - return; - } - - // Prove if user is recycleable from the garbage collector: - user *p_user = wrap::GCOL->get_user_from_garbage( s_user ); - - if ( p_user != NULL ) - { - // 1. possibility to prove the password at login! (using recycled user) - if ( p_user->get_pass() != map_params["password"] ) - { map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.wrongpassword" ); map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. wrap::system_message( LOGINER + s_user ); return; - } - if ( p_user->get_has_sess() ) - { + } + if ( p_user->get_has_sess() ) + { map_params["tmpid"] = p_user->get_tmpid(); - } - else - { + } + else + { sess* p_sess = wrap::SMAN->create_session(); - //p_sess->set_value( string("nick"), (void *) new string(s_user) ); - p_sess->set_name(s_user); - map_params["tmpid"] = p_sess->get_id(); + p_sess->set_user(p_user); + map_params["tmpid"] = p_sess->get_tmpid(); p_user->set_tmpid( map_params["tmpid"] ); p_user->set_has_sess( true ); - } } + } + else // if ( p_user == NULL ) // If not in garbage create a new user! + { + p_user = new user( s_user ); - else // if ( p_user == NULL ) // If not in garbage create a new user! - { - p_user = new user( s_user ); - - // prove if nick is registered + // prove if nick is registered, else create a guest chatter. #ifdef DATABASE - map_string map_results = wrap::DATA->select_user_data( tool::to_lower(s_user), "selectlogin"); - if ( map_results["nick"] == tool::to_lower(s_user) ) - { - p_user->set_is_reg( true ); + hashmap map_results = wrap::DATA->select_user_data( tool::to_lower(s_user), "selectlogin"); + + if ( map_results["nick"] == tool::to_lower(s_user) ) + { + p_user->set_is_reg( true ); // User exists in database, prove password: // 2. possibility to prove the password at login! (using new created user from database) if ( map_results["password"] != map_params["password"] ) { - map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.wrongpassword" ); - map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. - wrap::system_message( LOGINER + s_user ); - return; + map_params["INFO"] = wrap::CONF->get_elem( "chat.msgs.err.wrongpassword" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. + wrap::system_message( LOGINER + s_user ); + return; } else { // If registered use saved options - map_params["registered"] = "yes"; - map_params["color1"] = map_results["color1"]; - map_params["color2"] = map_results["color2"]; - map_params["email"] = map_results["email"]; - map_params["status"] = map_results["status"]; + map_params["registered"] = "yes"; + map_params["color1"] = map_results["color1"]; + map_params["color2"] = map_results["color2"]; + map_params["email"] = map_results["email"]; + map_params["status"] = map_results["status"]; } - } - else + } + else #endif - { // If not registered use standard font colors + + { // 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" ); + map_params["request"] = wrap::CONF->get_elem( "httpd.startsite" ); // redirect to the startpage. + wrap::system_message( LOGINE4 + s_user ); + return; + } + + // Guest chatter are enabled, use standard font colors map_params["color1"] = wrap::CONF->get_elem( "chat.html.user.color1" ); map_params["color2"] = wrap::CONF->get_elem( "chat.html.user.color2" ); map_params["status"] = wrap::CONF->get_elem( "chat.defaultrang" ); - } - - sess* p_sess = wrap::SMAN->create_session(); - p_sess->set_name(s_user); - map_params["tmpid"] = p_sess->get_id(); - p_user->set_tmpid( map_params["tmpid"] ); - p_user->set_col1( map_params["color1"] ); - p_user->set_col2( map_params["color2"] ); - p_user->set_status( tool::string2int(map_params["status"])); - // p_user->set_sess( p_sess ); } - // Prove if user is the default operator. - if ( tool::to_lower(wrap::CONF->get_elem("chat.defaultop")) == tool::to_lower(s_user) ) { - wrap::system_message(CHATDOP); - p_user->set_status(0); - } + sess* p_sess = wrap::SMAN->create_session(); + p_sess->set_user(p_user); + map_params["tmpid"] = p_sess->get_tmpid(); + p_user->set_tmpid( map_params["tmpid"] ); + p_user->set_col1( map_params["color1"] ); + p_user->set_col2( map_params["color2"] ); + p_user->set_status( tool::string2int(map_params["status"])); + // p_user->set_sess( p_sess ); + } - string s_room = map_params["room"]; - room* p_room = get_room( s_room , b_flag ); + // Prove if user is the default operator. + if ( tool::to_lower(wrap::CONF->get_elem("chat.defaultop")) == tool::to_lower(s_user) ) + { + wrap::system_message(CHATDOP); + p_user->set_status(0); + } - // if room does not exist add room to list! - if ( ! b_flag ) - { - p_room = wrap::GCOL->get_room_from_garbage(); + string s_room = map_params["room"]; + room* p_room = get_room( s_room , b_flag ); + + // if room does not exist add room to list! + if ( ! b_flag ) + { + p_room = wrap::GCOL->get_room_from_garbage(); - if ( p_room ) - { + if ( p_room ) + { p_room->set_name( s_room ); wrap::system_message( REUROOM + s_room ); - } - - else - { + } + else + { p_room = new room( s_room ); wrap::system_message( NEWROOM + s_room ); - } - - add_elem( p_room ); } - // add user to the room. - p_room->add_user( p_user ); + add_elem( p_room ); + } - wrap::system_message( NEWUSER + s_user ); + // add user to the room. + p_room->add_user( p_user ); - // post "username enters the chat" into the room. - string s_msg = wrap::TIMR->get_time() + " " + p_user->get_colored_bold_name() + wrap::CONF->get_elem( "chat.msgs.userenterschat" ) + "
\n"; + wrap::system_message( NEWUSER + s_user ); - // If created a new user from database while logging on (not a recycled user, they already have this set) - if ( map_params["registered"] == "yes" ) - { - p_user->set_email( map_params["email"] ); - p_user->set_pass( map_params["password"] ); - // 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 ); + // post "username enters the chat" into the room. + string s_msg = wrap::TIMR->get_time() + " " + p_user->get_colored_bold_name() + wrap::CONF->get_elem( "chat.msgs.userenterschat" ) + "
\n"; + + // If created a new user from database while logging on (not a recycled user, they already have this set) + if ( map_params["registered"] == "yes" ) + { + p_user->set_email( map_params["email"] ); + p_user->set_pass( map_params["password"] ); + // 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 ); } void -chat::post( user* p_user, map_string &map_params ) +chat::post( user* p_user, map &map_params ) { - p_user->renew_timeout(); + p_user->renew_timeout(); - string s_msg( map_params["message"] ); + string s_msg( map_params["message"] ); - if ( s_msg.empty() ) - return; + if ( s_msg.empty() ) + return; - int i_max_message_length = tool::string2int(wrap::CONF->get_elem( "chat.maxlength.message" )); - if ( s_msg.length() > i_max_message_length ) - { - s_msg = s_msg.substr( 0, i_max_message_length ); - string s_private = "get_elem( "chat.html.errorcolor" ) + "\">" + int i_max_message_length = tool::string2int(wrap::CONF->get_elem( "chat.maxlength.message" )); + if ( s_msg.length() > i_max_message_length ) + { + s_msg = s_msg.substr( 0, i_max_message_length ); + string s_private = "get_elem( "chat.html.errorcolor" ) + "\">" + wrap::CONF->get_elem( "chat.msgs.err.messagelength" ) + "
\n"; - p_user->msg_post( &s_private ); - } - - int i_max_word_length = tool::string2int(wrap::CONF->get_elem( "chat.maxlength.word" )); + p_user->msg_post( &s_private ); + } + + int i_max_word_length = tool::string2int(wrap::CONF->get_elem( "chat.maxlength.word" )); - // Check max word length - list list_msg = tool::split_string( s_msg, " "); - list::iterator iter = list_msg.begin(); + // Check max word length + list list_msg = tool::split_string( s_msg, " "); + list::iterator iter = list_msg.begin(); - for ( s_msg = ""; iter != list_msg.end(); ++iter ) + for ( s_msg = ""; iter != list_msg.end(); ++iter ) + { + if ( iter->length() > i_max_word_length ) { - if ( iter->length() > i_max_word_length ) - { string s_tmp[] = { iter->substr(0, i_max_word_length ), iter->substr(i_max_word_length) }; - iter = list_msg.erase( iter ); + iter = list_msg.erase( iter ); iter = list_msg.insert( iter, s_tmp[1] ); iter = list_msg.insert( iter, s_tmp[0] ); --iter; - } - else - { - s_msg.append(*iter + " "); - } } - - if ( wrap::CONF->get_elem( "chat.html.tagsallow" ) != "true" ) - tool::strip_html( &s_msg ); + else + { + s_msg.append(*iter + " "); + } + } - auto unsigned i_pos = s_msg.find( "/" ); - if ( i_pos == 0 ) - return p_user->command( s_msg ); + if ( wrap::CONF->get_elem( "chat.html.tagsallow" ) != "true" ) + tool::strip_html( &s_msg ); - if ( wrap::CONF->get_elem( "chat.html.replace.activate" ) == "true" ) - { - for (vector::iterator iter = vec_replace_keys.end()-1; - iter != vec_replace_keys.begin(); - iter-- ) - s_msg = tool::replace( s_msg, *iter, wrap::CONF->get_elem(map_replace_strings[*iter]) ); - } - - string s_post; - - if ( wrap::CONF->get_elem( "chat.printalwaystime" ) == "true" ) - s_post.append( wrap::TIMR->get_time() + " " ); - - s_post.append( "get_col1() ) - .append( "\">" ) - .append( p_user->get_name() ) - .append( ": get_col2() ) - .append( "\">" ) - .append( s_msg ) - .append( "
\n" ); - - p_user->get_room()->msg_post( &s_post ); + unsigned i_pos = s_msg.find( "/" ); + if ( i_pos == 0 ) + return p_user->command( s_msg ); + + string_replacer(&s_msg); + string s_post; + + if ( wrap::CONF->get_elem( "chat.printalwaystime" ) == "true" ) + s_post.append( wrap::TIMR->get_time() + " " ); + + s_post.append( "get_col1() ) + .append( "\">" ) + .append( p_user->get_name() ) + .append( ": get_col2() ) + .append( "\">" ) + .append( s_msg ) + .append( "
\n" ); + + p_user->get_room()->msg_post( &s_post ); } void chat::reconf() +{} + +void +chat::string_replacer(string *p_msg) +{ + if ( wrap::CONF->get_elem( "chat.html.replace.activate" ) == "true" ) + { + for (vector::iterator iter = vec_replace_keys.end()-1; + iter != vec_replace_keys.begin(); + iter-- ) + *p_msg = tool::replace( *p_msg, *iter, wrap::CONF->get_elem(map_replace_strings[*iter]) ); + } +} + +void +chat::dumpit() { + dumpable::add("[chat]"); + base::dumpit(); } #endif diff --git a/src/chat/chat.h b/src/chat/chat.h old mode 100755 new mode 100644 index c37bebc..b61ed95 --- a/src/chat/chat.h +++ b/src/chat/chat.h @@ -1,3 +1,27 @@ +/*:* + *: File: ./src/chat/chat.h + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: 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. + *:*/ + // class chat declaration. class chat; @@ -13,49 +37,51 @@ class chat; #include "user.h" #include "sess.h" #include "../tool/tool.h" +#include "../maps/hashmap.h" using namespace std; - #undef chat class chat : public base, public perm { private: - map_string map_replace_strings; - vector vec_replace_keys; + map map_replace_strings; + vector vec_replace_keys; + void dumpit(); public: - virtual room* get_room( string s_name ) - { - bool b_bool; - return get_room( s_name, b_bool ); - } - - virtual room* get_room( string &s_name, bool &b_found ) - { - return static_cast( get_elem( s_name, b_found ) ); - } - - // public methods: - explicit chat(); // a standard constructor. - ~chat(); // destructor. - - // get the object of a specific user. - user* get_user( string &s_nick ); - user* get_user( string &s_nick, bool &b_found ); - static void get_user_( room* room_obj, void *v_arg ); - - // will be called every time a user tries to login. - void login( map_string &map_params ); - - // will be called if a user posts a message. - void post ( user* u_user, map_string &map_params ); - - void del_elem( string s_name ) - { - smap::del_elem( s_name ); - } - - void reconf(); + virtual room* get_room( string s_name ) + { + bool b_bool; + return get_room( s_name, b_bool ); + } + + virtual room* get_room( string &s_name, bool &b_found ) + { + return static_cast( get_elem( s_name, b_found ) ); + } + + // public methods: + explicit chat(); // a standard constructor. + ~chat(); // destructor. + + // get the object of a specific user. + user* get_user( string &s_nick ); + user* get_user( string &s_nick, bool &b_found ); + static void get_user_( room* room_obj, void *v_arg ); + + // will be called every time a user tries to login. + void login( map &map_params ); + + // will be called if a user posts a message. + void post ( user* u_user, map &map_params ); + + void del_elem( string s_name ) + { + base::del_elem( s_name ); + } + + void reconf(); + void string_replacer(string *p_msg); }; #endif diff --git a/src/chat/gcol.cpp b/src/chat/gcol.cpp old mode 100755 new mode 100644 index 2500b91..099f11e --- a/src/chat/gcol.cpp +++ b/src/chat/gcol.cpp @@ -1,3 +1,27 @@ +/*:* + *: File: ./src/chat/gcol.cpp + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: 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 GCOL_CPP #define GCOL_CPP @@ -7,130 +31,141 @@ using namespace std; gcol::gcol() { - pthread_mutex_init( &mut_vec_rooms , NULL); + pthread_mutex_init( &mut_vec_rooms , NULL); - p_map_users = new smap(HMAPOCC); - wrap::system_message( GARBAGE ); + p_map_users = new shashmap; + wrap::system_message( GARBAGE ); #ifdef NCURSES - print_garbage(); + + print_garbage(); #endif } gcol::~gcol() { - remove_garbage(); - pthread_mutex_destroy( &mut_vec_rooms ); - delete p_map_users; + 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() ); +{ + 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() ); #ifdef NCURSES - print_garbage(); + + print_garbage(); #endif } void 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->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(); + + print_garbage(); #endif } bool gcol::remove_garbage() { - bool b_empty; + bool b_empty; - pthread_mutex_lock ( &mut_vec_rooms ); - b_empty = ( vec_rooms.empty() && p_map_users->get_size() == 0); - pthread_mutex_unlock( &mut_vec_rooms ); + 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; + if ( b_empty ) + return false; - wrap::system_message( GARBACT ); + wrap::system_message( GARBACT ); - pthread_mutex_lock ( &mut_vec_rooms ); - for ( vector::iterator iter = vec_rooms.begin(); - iter != vec_rooms.end(); iter++ ) - { - wrap::system_message( REMROOM + (*iter)->get_name() ); - delete *iter; - } - vec_rooms.clear(); - pthread_mutex_unlock( &mut_vec_rooms ); + pthread_mutex_lock ( &mut_vec_rooms ); + for ( vector::iterator iter = vec_rooms.begin(); + iter != vec_rooms.end(); iter++ ) + { + wrap::system_message( REMROOM + (*iter)->get_name() ); + delete *iter; + } + vec_rooms.clear(); + pthread_mutex_unlock( &mut_vec_rooms ); - p_map_users->run_func( delete_users_ ); - p_map_users->make_empty(); + p_map_users->run_func( delete_users_ ); + p_map_users->clear(); #ifdef NCURSES - print_garbage(); + + print_garbage(); #endif - return true; + + return true; } room* gcol::get_room_from_garbage() { - pthread_mutex_lock ( &mut_vec_rooms ); + pthread_mutex_lock ( &mut_vec_rooms ); - if ( vec_rooms.empty() ) - { - pthread_mutex_unlock( &mut_vec_rooms ); - return NULL; - } + 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 ); + room* p_room = vec_rooms.back(); + vec_rooms.pop_back(); + pthread_mutex_unlock( &mut_vec_rooms ); #ifdef NCURSES - print_garbage(); + + print_garbage(); #endif - return p_room; + return p_room; } room* gcol::get_room_from_garbage_or_new( string s_room ) { - room* p_room = get_room_from_garbage(); - if ( p_room == NULL ) - return new room( s_room ); - p_room->set_name( s_room ); - return p_room; + room* p_room = get_room_from_garbage(); + if ( p_room == NULL ) + return new room( s_room ); + p_room->set_name( s_room ); + return p_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 ) + 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->renew_timeout(); - wrap::system_message(GARUSE2 + p_user->get_name() ); + 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() ); #ifdef NCURSES - print_garbage(); + + print_garbage(); #endif + } return p_user; @@ -139,34 +174,34 @@ gcol::get_user_from_garbage( string s_user ) void gcol::delete_users_( user *user_obj ) { - wrap::system_message( REMUSER + user_obj->get_name() ); - user_obj->clean(); - delete user_obj; + wrap::system_message( REMUSER + user_obj->get_name() ); + user_obj->clean(); + delete user_obj; } void gcol::lock_mutex() { - pthread_mutex_lock ( &mut_vec_rooms ); + pthread_mutex_lock ( &mut_vec_rooms ); } void gcol::unlock_mutex() { - pthread_mutex_unlock ( &mut_vec_rooms ); + pthread_mutex_unlock ( &mut_vec_rooms ); } #ifdef NCURSES void gcol::print_garbage( ) { - if ( wrap::NCUR->is_ready() ) - { - pthread_mutex_lock ( &mut_vec_rooms ); - mvprintw( NCUR_GARBAGE_X,NCUR_GARBAGE_Y, "Garbage: %d ", p_map_users->get_size() + vec_rooms.size() ); - pthread_mutex_unlock( &mut_vec_rooms ); - refresh(); - } + if ( wrap::NCUR->is_ready() ) + { + pthread_mutex_lock ( &mut_vec_rooms ); + mvprintw( NCUR_GARBAGE_X,NCUR_GARBAGE_Y, "Garbage: %d ", p_map_users->size() + vec_rooms.size() ); + pthread_mutex_unlock( &mut_vec_rooms ); + refresh(); + } } #endif diff --git a/src/chat/gcol.h b/src/chat/gcol.h old mode 100755 new mode 100644 index 4936ded..ab84269 --- a/src/chat/gcol.h +++ b/src/chat/gcol.h @@ -1,42 +1,67 @@ -// garbage collector +/*:* + *: File: ./src/chat/gcol.h + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: 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. + *:*/ + +// garbage collector #include "../incl.h" #ifndef GCOL_H #define GCOL_H -#include +#include #include "room.h" #include "user.h" -#include "../maps/smap.h" +#include "../maps/shashmap.h" using namespace std; class gcol { - private: - vector vec_rooms; - smap* p_map_users; +private: + vector vec_rooms; + shashmap* p_map_users; pthread_mutex_t mut_vec_rooms; static void delete_users_( user* user_obj ); #ifdef NCURSES + void print_garbage( ); #endif - public: +public: gcol(); ~gcol(); - bool remove_garbage(); - void add_room_to_garbage( room* p_room ); - void add_user_to_garbage( user* p_user ); - virtual room* get_room_from_garbage(); - virtual room* get_room_from_garbage_or_new( string s_room ); - user* get_user_from_garbage( string s_user ); - virtual void lock_mutex(); - virtual void unlock_mutex(); + bool remove_garbage(); + void add_room_to_garbage( room* p_room ); + void add_user_to_garbage( user* p_user ); + virtual room* get_room_from_garbage(); + virtual room* get_room_from_garbage_or_new( string s_room ); + user* get_user_from_garbage( string s_user ); + virtual void lock_mutex(); + virtual void unlock_mutex(); }; #endif diff --git a/src/chat/perm.cpp b/src/chat/perm.cpp old mode 100755 new mode 100644 index b862d43..f84d4de --- a/src/chat/perm.cpp +++ b/src/chat/perm.cpp @@ -1,3 +1,27 @@ +/*:* + *: File: ./src/chat/perm.cpp + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: 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 PERM_CPP #define PERM_CPP @@ -8,73 +32,76 @@ using namespace std; perm::perm() { - p_command_status = new smap< valwrap*, string>(HMAPOCC); - p_command_disabled = new smap< valwrap*, string>(HMAPOCC); + p_command_status = new shashmap< valwrap* >; + p_command_disabled = new shashmap< valwrap* >; - set_standard_command_permissions(); + set_standard_command_permissions(); } perm::~perm() { - p_command_status->run_func( &mtools< valwrap* >::delete_obj ); - p_command_disabled->run_func( &mtools< valwrap* >::delete_obj ); + p_command_status->run_func( &mtools< valwrap* >::delete_obj ); + p_command_disabled->run_func( &mtools< valwrap* >::delete_obj ); - delete p_command_status; - delete p_command_disabled; + delete p_command_status; + delete p_command_disabled; } int perm::get_command_status( string s_command ) { - if ( p_command_status->is_avail( s_command ) ) - return p_command_status->get_elem( s_command )->val; + if ( p_command_status->exists( s_command ) ) + return p_command_status->get_elem( s_command )->val; - return 0; + return 0; } void perm::set_command_status( string s_command, int i_int ) { - valwrap* p_val = p_command_status->set_elem( new valwrap(i_int), s_command ); + valwrap* p_val = p_command_status->get_set_elem( new valwrap(i_int), s_command ); - if ( p_val ) - delete p_val; + if ( p_val ) + delete p_val; } bool perm::get_command_disabled( string s_command ) { - if ( p_command_disabled->is_avail( s_command ) ) - return p_command_disabled->get_elem( s_command )->val; - return 0; + if ( p_command_disabled->exists( s_command ) ) + return p_command_disabled->get_elem( s_command )->val; + return 0; } void perm::set_command_disabled( string s_command, bool b_bool ) { - valwrap* p_val = p_command_disabled->set_elem( new valwrap(b_bool), s_command ); + valwrap* p_val = p_command_disabled->get_set_elem( new valwrap(b_bool), s_command ); - if ( p_val ) - delete p_val; + if ( p_val ) + delete p_val; } void perm::set_standard_command_permissions() { - wrap::system_message(PERMSTD); - - vector* p_vec_keys = wrap::CONF->get_key_vector(); - - for (vector::iterator iter = p_vec_keys->begin(); iter != p_vec_keys->end(); iter++ ) - { - if ( iter->length() > 17 && iter->compare( 0, 16, "chat.permissions" ) == 0 ) - { - valwrap* p_val = new valwrap( tool::string2int( wrap::CONF->get_elem(*iter) ) ); - p_command_status->add_elem( p_val, iter->substr(17) ); - } - } - - delete p_vec_keys; + wrap::system_message(PERMSTD); + + vector* p_vec_keys = wrap::CONF->get_key_vector(); + + for (vector::iterator iter = p_vec_keys-> + begin(); + iter != p_vec_keys->end(); + iter++ ) + { + if ( iter->length() > 17 && iter->compare( 0, 16, "chat.permissions" ) == 0 ) + { + valwrap* p_val = new valwrap( tool::string2int( wrap::CONF->get_elem(*iter) ) ); + p_command_status->add_elem( p_val, iter->substr(17) ); + } + } + + delete p_vec_keys; } #endif diff --git a/src/chat/perm.h b/src/chat/perm.h old mode 100755 new mode 100644 index 8e08ba2..5fc34c3 --- a/src/chat/perm.h +++ b/src/chat/perm.h @@ -1,5 +1,29 @@ +/*:* + *: File: ./src/chat/perm.h + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: 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" -#include "../maps/smap.h" +#include "../maps/shashmap.h" #ifndef PERM_H #define PERM_H @@ -7,35 +31,36 @@ using namespace std; template -struct valwrap -{ - type_ val; - valwrap(type_ i) - { - val = i; - } - type_ get_val() - { - return val; - } +struct valwrap +{ + type_ val; + valwrap(type_ i) + { + val = i; + } + + type_ get_val() + { + return val; + } }; class perm { private: - smap< valwrap*, string>* p_command_status; - smap< valwrap*, string>* p_command_disabled; + shashmap< valwrap* >* p_command_status; + shashmap< valwrap* >* p_command_disabled; + + void set_standard_command_permissions(); - void set_standard_command_permissions(); - public: - perm( ); - ~perm( ); + perm( ); + ~perm( ); - virtual int get_command_status( string s_command ); - virtual bool get_command_disabled( string s_command ); - virtual void set_command_status( string s_command, int i_int ); - virtual void set_command_disabled( string s_command, bool b_bool ); + virtual int get_command_status( string s_command ); + virtual bool get_command_disabled( string s_command ); + virtual void set_command_status( string s_command, int i_int ); + virtual void set_command_disabled( string s_command, bool b_bool ); }; #endif diff --git a/src/chat/room.cpp b/src/chat/room.cpp old mode 100755 new mode 100644 index 527e444..9ff5517 --- a/src/chat/room.cpp +++ b/src/chat/room.cpp @@ -1,3 +1,27 @@ +/*:* + *: File: ./src/chat/room.cpp + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: 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 ROOM_CPP #define ROOM_CPP @@ -8,86 +32,107 @@ using namespace std; room::room( string s_name ) : name( s_name ) { - pthread_mutex_init( &mut_s_topic, NULL ); - p_logd = new logd( wrap::CONF->get_elem("chat.logging.roomlogdir") + get_lowercase_name(), - wrap::CONF->get_elem("chat.logging.roomloglines") ); - wrap::STAT->increment_num_rooms(); + pthread_mutex_init( &mut_s_topic, NULL ); +#ifdef LOGGING + + p_logd = new logd( wrap::CONF->get_elem("chat.logging.roomlogdir") + get_lowercase_name(), + wrap::CONF->get_elem("chat.logging.roomloglines") ); +#endif + + wrap::STAT->increment_num_rooms(); } room::~room() { - wrap::STAT->decrement_num_rooms(); + wrap::STAT->decrement_num_rooms(); - // Delete all user objects - run_func( mtools::delete_obj ); + // Delete all user objects + run_func( mtools::delete_obj ); - delete p_logd; +#ifdef LOGGING - pthread_mutex_destroy( &mut_s_topic ); - pthread_mutex_destroy( &mut_s_name ); + 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; + 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 + "

"; - pthread_mutex_unlock( &mut_s_topic ); - reload_onlineframe(); + pthread_mutex_lock ( &mut_s_topic ); + if ( s_topic == "" ) + this->s_topic = ""; + else + this->s_topic = s_topic + "

"; + pthread_mutex_unlock( &mut_s_topic ); + reload_onlineframe(); } void room::set_topic( string s_topic, string s_color ) { - set_topic( "" + s_topic + ""); + set_topic( "" + s_topic + ""); } 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 ); + 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 ); } void room::reload_onlineframe() { - string s_msg = "\n"; - msg_post( &s_msg ); + javascript_post("parent.online.location.reload();"); } -void +void room::set_name( string s_name ) { - if ( tool::to_lower(s_name) == get_lowercase_name() ) - { - name::set_name( s_name ); - return; - } + if ( tool::to_lower(s_name) == get_lowercase_name() ) + { + name::set_name( s_name ); + return; + } + +#ifdef LOGGING + p_logd->flush_logs(); +#endif + + if ( s_name == "" ) + return; - p_logd->flush_logs(); + name::set_name( s_name ); +#ifdef LOGGING + + p_logd->set_logfile( wrap::CONF->get_elem("chat.logging.roomlogdir"), get_lowercase_name() ); +#endif +} - if ( s_name == "" ) - return; +void +room::dumpit() +{ + dumpable::add("[room]"); + dumpable::add("Name: "+get_name()); + dumpable::add("Topic: "+get_topic()); + base::dumpit(); +} - name::set_name( s_name ); - p_logd->set_logfile( wrap::CONF->get_elem("chat.logging.roomlogdir"), get_lowercase_name() ); -} #endif diff --git a/src/chat/ro