summaryrefslogtreecommitdiff
path: root/src/chat
diff options
context:
space:
mode:
Diffstat (limited to 'src/chat')
-rwxr-xr-xsrc/chat/base.h158
-rwxr-xr-xsrc/chat/base.tmpl49
-rwxr-xr-xsrc/chat/chat.cpp499
-rwxr-xr-xsrc/chat/chat.h72
-rwxr-xr-xsrc/chat/gcol.cpp161
-rwxr-xr-xsrc/chat/gcol.h31
-rwxr-xr-xsrc/chat/perm.cpp69
-rwxr-xr-xsrc/chat/perm.h45
-rwxr-xr-xsrc/chat/room.cpp108
-rwxr-xr-xsrc/chat/room.h117
-rwxr-xr-xsrc/chat/sess.cpp39
-rwxr-xr-xsrc/chat/sess.h21
-rwxr-xr-xsrc/chat/sman.cpp127
-rwxr-xr-xsrc/chat/sman.h30
-rwxr-xr-xsrc/chat/user.cpp767
-rwxr-xr-xsrc/chat/user.h252
16 files changed, 1120 insertions, 1425 deletions
diff --git a/src/chat/base.h b/src/chat/base.h
index b995c5c..ae2e926 100755
--- a/src/chat/base.h
+++ b/src/chat/base.h
@@ -1,93 +1,89 @@
+// template class data declaration;
#include "../incl.h"
#ifndef BASE_H
#define BASE_H
-#include <map>
-#include "../maps/nhashmap.h"
+#include "../maps/smap.h"
template<class type>
-class base : public nhashmap<type*>
+class base : public smap<type*,string>
{
-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 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<type*>::run_func( &base<type>::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<type*>::run_func( &base<type>::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<type*>::run_func( &base<type>::reconf_ );
- }
-
- static void reconf_ ( type* type_obj )
- {
- type_obj -> reconf ();
- }
-
- void get_data( map<string,string> *p_map_string )
- {
- nhashmap<type*>::run_func( &base<type>::get_data_ , (void*)p_map_string );
- }
-
- static void get_data_( type* type_obj, void* v_arg )
- {
- type_obj -> get_data ( (map<string,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 <font color="usercolor">username</font>seperator
- void get_user_list( string &s_list )
- {
- container c;
- c.elem[0] = (void*) &s_list;
-
- nhashmap<type*>::run_func( &base<type>::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 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<type*,string>::run_func( &base<type>::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<type*,string>::run_func( &base<type>::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<type*,string>::run_func( &base<type>::reconf_ );
+ }
+
+ static void reconf_ ( type* type_obj )
+ {
+ type_obj -> reconf ();
+ }
+
+ void get_data( map_string *p_map_string )
+ {
+ smap<type*,string>::run_func( &base<type>::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 <font color="usercolor">username</font>seperator
+ void get_user_list( string &s_list )
+ {
+ container c;
+ c.elem[0] = (void*) &s_list;
+
+ smap<type*,string>::run_func( &base<type>::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
index 73d8835..53b609f 100755
--- a/src/chat/base.tmpl
+++ b/src/chat/base.tmpl
@@ -4,61 +4,30 @@
#include "base.h"
template<class type>
-base<type>::base()
-{}
+base<type>::base() : smap<type*,string>::smap(HMAPOCC)
+{
+}
template<class type>
base<type>::~base( )
-{}
-
-template<class type>
-type*
-base<type>::get_elem( string s_name, bool &b_found )
{
- s_name = to_lower(s_name);
- type* p_type = nhashmap<type*>::get_elem( s_name );
- b_found = p_type == NULL ? false : true;
- return p_type;
}
template<class type>
type*
-base<type>::get_elem( string s_name)
+base<type>::get_elem( string s_name, bool &b_found )
{
- bool b;
- return get_elem(s_name, b);
+ s_name = to_lower(s_name);
+ type* p_type = smap<type*,string>::get_elem( s_name );
+ b_found = p_type == NULL ? false : true;
+ return p_type;
}
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;
+ smap<type*,string>::add_elem(p_type, p_type->get_lowercase_name());
}
#endif
diff --git a/src/chat/chat.cpp b/src/chat/chat.cpp
index d890d70..86bc140 100755
--- a/src/chat/chat.cpp
+++ b/src/chat/chat.cpp
@@ -12,370 +12,327 @@ using namespace std;
chat::chat( )
{
- { // 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++ )
- {
- if ( iter->length() >= 24 && iter->compare( 0, 22, "chat.html.replace.from" ) == 0 )
+ { // 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++ )
{
+ 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);
- }
- }
+ vec_replace_keys.push_back(s_from);
+ }
+ }
- sort(vec_replace_keys.begin(), vec_replace_keys.end());
- delete p_vec_keys;
- }
+ sort(vec_replace_keys.begin(), vec_replace_keys.end());
+ delete p_vec_keys;
+ }
}
chat::~chat( )
{
- // Delete all room objects!
- run_func( mtools<room*>::delete_obj );
+ // Delete all room objects!
+ run_func( mtools<room*>::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;
- base<room>::run_func( get_user_, (void*)&param );
+ smap<room*,string>::run_func( get_user_, (void*)&param );
- 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,string> &map_params )
+chat::login( map_string &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 ) )
- {
- 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"] )
+ 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;
+ }
+
+ 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_user(p_user);
- map_params["tmpid"] = p_sess->get_tmpid();
+ //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_user->set_tmpid( map_params["tmpid"] );
p_user->set_has_sess( true );
- wrap::system_message("New tmpid: " + map_params["tmpid"] );
+ }
}
- }
- else // if ( p_user == NULL ) // If not in garbage create a new user!
- {
- p_user = new user( s_user );
- // prove if nick is registered, else create a guest chatter.
-#ifdef DATABASE
+ else // if ( p_user == NULL ) // If not in garbage create a new user!
+ {
+ p_user = new user( s_user );
- hashmap<string> map_results = wrap::DATA->select_user_data( tool::to_lower(s_user), "selectlogin");
+ // prove if nick is registered
+#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 );
+ 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 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
+ { // If not registered 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_user(p_user);
- map_params["tmpid"] = p_sess->get_tmpid();
- wrap::system_message("New tmpid: " + map_params["tmpid"] );
- p_user->set_tmpid( map_params["tmpid"] );
- p_user->set_col1( map_params["color1"] );
- p_user->set_col2( map_params["color2"] );
- p_user->set_status( tool::string2int(map_params["status"]));
+ }
+
+ 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);
- }
+ }
- 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 ( p_room )
+ // if room does not exist add room to list!
+ if ( ! b_flag )
{
+ p_room = wrap::GCOL->get_room_from_garbage();
+
+ 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_elem( p_room );
+ }
- // add user to the room.
- p_room->add_user( p_user );
+ // add user to the room.
+ p_room->add_user( p_user );
- wrap::system_message( NEWUSER + s_user );
+ wrap::system_message( NEWUSER + s_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" ) + "<br>\n";
+ // 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" ) + "<br>\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 );
+ // 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,string> &map_params )
+chat::post( user* p_user, map_string &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 = "<font color=\"" + wrap::CONF->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 = "<font color=\"" + wrap::CONF->get_elem( "chat.html.errorcolor" ) + "\">"
+ wrap::CONF->get_elem( "chat.msgs.err.messagelength" ) + "</font><br>\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<string> list_msg = tool::split_string( s_msg, " ");
- list<string>::iterator iter = list_msg.begin();
+ // Check max word length
+ list<string> list_msg = tool::split_string( s_msg, " ");
+ list<string>::iterator iter = list_msg.begin();
- for ( s_msg = ""; iter != list_msg.end(); ++iter )
- {
- if ( iter->length() > i_max_word_length )
+ for ( s_msg = ""; iter != list_msg.end(); ++iter )
{
+ 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 + " ");
+ }
}
- else
- {
- s_msg.append(*iter + " ");
- }
- }
-
- if ( wrap::CONF->get_elem( "chat.html.tagsallow" ) != "true" )
- tool::strip_html( &s_msg );
-
- unsigned i_pos = s_msg.find( "/" );
- if ( i_pos == 0 )
- return p_user->command( s_msg );
-
- if (p_user->get_is_gag())
- {
- p_user->msg_post(wrap::CONF->colored_error_msg("chat.msgs.err.gagged"));
- return;
- }
+
+ if ( wrap::CONF->get_elem( "chat.html.tagsallow" ) != "true" )
+ tool::strip_html( &s_msg );
+ auto 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( "<font color=\"#" )
- .append( p_user->get_col1() )
- .append( "\">" )
- .append( p_user->get_name() )
- .append( ":</font> <font color=\"#")
- .append( p_user->get_col2() )
- .append( "\">" )
- .append( s_msg )
- .append( "</font><br>\n" );
-
- p_user->get_room()->msg_post( &s_post );
+ if ( wrap::CONF->get_elem( "chat.html.replace.activate" ) == "true" )
+ {
+ for (vector<string>::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( "<font color=\"#" )
+ .append( p_user->get_col1() )
+ .append( "\">" )
+ .append( p_user->get_name() )
+ .append( ":</font> <font color=\"#")
+ .append( p_user->get_col2() )
+ .append( "\">" )
+ .append( s_msg )
+ .append( "</font><br>\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<string>::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<room>::dumpit();
}
#endif
diff --git a/src/chat/chat.h b/src/chat/chat.h
index bb087d5..c37bebc 100755
--- a/src/chat/chat.h
+++ b/src/chat/chat.h
@@ -13,51 +13,49 @@ 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<room>, public perm
{
private:
- map<string,string> map_replace_strings;
- vector<string> vec_replace_keys;
- void dumpit();
+ map_string map_replace_strings;
+ vector<string> vec_replace_keys;
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<room*>( 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,string> &map_params );
-
- // will be called if a user posts a message.
- void post ( user* u_user, map<string,string> &map_params );
-
- void del_elem( string s_name )
- {
- base<room>::del_elem( s_name );
- }
-
- void reconf();
- void string_replacer(string *p_msg);
+ 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<room*>( 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<room*,string>::del_elem( s_name );
+ }
+
+ void reconf();
};
#endif
diff --git a/src/chat/gcol.cpp b/src/chat/gcol.cpp
index d4c9416..2500b91 100755
--- a/src/chat/gcol.cpp
+++ b/src/chat/gcol.cpp
@@ -7,141 +7,130 @@ using namespace std;
gcol::gcol()
{
- pthread_mutex_init( &mut_vec_rooms , NULL);
+ pthread_mutex_init( &mut_vec_rooms , NULL);
- p_map_users = new shashmap<user*>;
- wrap::system_message( GARBAGE );
+ p_map_users = new smap<user*,string>(HMAPOCC);
+ 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->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() );
#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->size() == 0);
- pthread_mutex_unlock( &mut_vec_rooms );
+ pthread_mutex_lock ( &mut_vec_rooms );
+ b_empty = ( vec_rooms.empty() && p_map_users->get_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<room*>::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<room*>::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->clear();
+ p_map_users->run_func( delete_users_ );
+ p_map_users->make_empty();
#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;
@@ -150,34 +139,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->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->get_size() + vec_rooms.size() );
+ pthread_mutex_unlock( &mut_vec_rooms );
+ refresh();
+ }
}
#endif
diff --git a/src/chat/gcol.h b/src/chat/gcol.h
index d1fcde3..4936ded 100755
--- a/src/chat/gcol.h
+++ b/src/chat/gcol.h
@@ -1,43 +1,42 @@
-// garbage collector
+// garbage collector
#include "../incl.h"
#ifndef GCOL_H
#define GCOL_H
-#include <vector>
+#include <vector>
#include "room.h"
#include "user.h"
-#include "../maps/shashmap.h"
+#include "../maps/smap.h"
using namespace std;
class gcol
{
-private:
- vector<room*> vec_rooms;
- shashmap<user*>* p_map_users;
+ private:
+ vector<room*> vec_rooms;
+ smap<user*,string>* 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
index 2de3031..b862d43 100755
--- a/src/chat/perm.cpp
+++ b/src/chat/perm.cpp
@@ -8,76 +8,73 @@ using namespace std;
perm::perm()
{
- p_command_status = new shashmap< valwrap<int>* >;
- p_command_disabled = new shashmap< valwrap<bool>* >;
+ p_command_status = new smap< valwrap<int>*, string>(HMAPOCC);
+ p_command_disabled = new smap< valwrap<bool>*, string>(HMAPOCC);
- set_standard_command_permissions();
+ set_standard_command_permissions();
}
perm::~perm()
{
- p_command_status->run_func( &mtools< valwrap<int>* >::delete_obj );
- p_command_disabled->run_func( &mtools< valwrap<bool>* >::delete_obj );
+ p_command_status->run_func( &mtools< valwrap<int>* >::delete_obj );
+ p_command_disabled->run_func( &mtools< valwrap<bool>* >::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->exists( s_command ) )
- return p_command_status->get_elem( s_command )->val;
+ if ( p_command_status->is_avail( 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<int>* p_val = p_command_status->get_set_elem( new valwrap<int>(i_int), s_command );
+ valwrap<int>* p_val = p_command_status->set_elem( new valwrap<int>(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->exists( s_command ) )
- return p_command_disabled->get_elem( s_command )->val;
- return 0;
+ if ( p_command_disabled->is_avail( 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<bool>* p_val = p_command_disabled->get_set_elem( new valwrap<bool>(b_bool), s_command );
+ valwrap<bool>* p_val = p_command_disabled->set_elem( new valwrap<bool>(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<string>* p_vec_keys = wrap::CONF->get_key_vector();
-
- for (vector<string>::iterator iter = p_vec_keys->
- begin();
- iter != p_vec_keys->end();
- iter++ )
- {
- if ( iter->length() > 17 && iter->compare( 0, 16, "chat.permissions" ) == 0 )
- {
- valwrap<int>* p_val = new valwrap<int>( 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<string>* p_vec_keys = wrap::CONF->get_key_vector();
+
+ for (vector<string>::iterator iter = p_vec_keys->begin(); iter != p_vec_keys->end(); iter++ )
+ {
+ if ( iter->length() > 17 && iter->compare( 0, 16, "chat.permissions" ) == 0 )
+ {
+ valwrap<int>* p_val = new valwrap<int>( 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
index fca019f..8e08ba2 100755
--- a/src/chat/perm.h
+++ b/src/chat/perm.h
@@ -1,5 +1,5 @@
#include "../incl.h"
-#include "../maps/shashmap.h"
+#include "../maps/smap.h"
#ifndef PERM_H
#define PERM_H
@@ -7,36 +7,35 @@
using namespace std;
template<class type_>
-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:
- shashmap< valwrap<int>* >* p_command_status;
- shashmap< valwrap<bool>* >* p_command_disabled;
-
- void set_standard_command_permissions();
+ smap< valwrap<int>*, string>* p_command_status;
+ smap< valwrap<bool>*, string>* p_command_disabled;
+ 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
index e1352f4..527e444 100755
--- a/src/chat/room.cpp
+++ b/src/chat/room.cpp
@@ -8,110 +8,86 @@ 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(),
- wrap::CONF->get_elem("chat.logging.roomloglines") );
-#endif
-
- wrap::STAT->increment_num_rooms();
+ 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();
}
room::~room()
{
- wrap::STAT->decrement_num_rooms();
-
- // Delete all user objects
- run_func( mtools<user*>::delete_obj );
+ wrap::STAT->decrement_num_rooms();
-#ifdef LOGGING
+ // Delete all user objects
+ run_func( mtools<user*>::delete_obj );
- delete p_logd;
-#endif
+ delete p_logd;
- pthread_mutex_destroy( &mut_s_topic );
- pthread_mutex_destroy( &mut_s_name );
+ 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 + "<br><br>";
- 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 + "<br><br>";
+ pthread_mutex_unlock( &mut_s_topic );
+ reload_onlineframe();
}
void
room::set_topic( string s_topic, string s_color )
{
- set_topic( "<font color=\"#" + s_color + "\">" + s_topic + "</font>");
+ set_topic( "<font color=\"#" + s_color + "\">" + s_topic + "</font>");
}
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()
{
- javascript_post("parent.online.location.reload();");
+ string s_msg = "<script language=\"JavaScript\"> parent.online.location.reload(); </script>\n";
+ msg_post( &s_msg );
}
-void
+void
room::set_name( string s_name )
{
- 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;
+ if ( tool::to_lower(s_name) == get_lowercase_name() )
+ {
+ name::set_name( s_name );
+ return;
+ }
- name::set_name( s_name );
-#ifdef LOGGING
-
- p_logd->set_logfile( wrap::CONF->get_elem("chat.logging.roomlogdir"), get_lowercase_name() );
-#endif
-}
+ p_logd->flush_logs();
-void
-room::dumpit()
-{
- dumpable::add
- ("[room]");
- dumpable::add
- ("Name: "+get_name());
- dumpable::add
- ("Topic: "+get_topic());
- base<user>::dumpit();
-}
+ if ( s_name == "" )
+ return;
+ 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/room.h b/src/chat/room.h
index 1e4482f..9d8dd45 100755
--- a/src/chat/room.h
+++ b/src/chat/room.h
@@ -17,76 +17,59 @@ using namespace std;
class room : public base<user>, public name
{
private:
- string s_topic;
- pthread_mutex_t mut_s_topic;
-#ifdef LOGGING
-
- logd* p_logd;
-#endif
-
- void dumpit();
+ string s_topic;
+ pthread_mutex_t mut_s_topic;
+ logd* p_logd;
public:
- room( string s_name );
- ~room();
-
- virtual void reload_onlineframe();
-
- void add_user( user* p_user )
- {
- add_elem( p_user );
- p_user->set_p_room( this );
- reload_onlineframe();
- }
-
- user* get_user( string &s_name, bool &b_found )
- {
- return static_cast<user*>( get_elem( s_name, b_found ) );
- }
-
- void del_elem( string &s_name )
- {
- base<user>::del_elem( s_name );
-
- if ( base<user>::size() == 0 )
+ room( string s_name );
+ ~room();
+
+ virtual void reload_onlineframe();
+
+ void add_user( user* p_user )
+ {
+ add_elem( p_user );
+ p_user->set_p_room( this );
+ reload_onlineframe();
+ }
+
+ user* get_user( string &s_name, bool &b_found )
+ {
+ return static_cast<user*>( get_elem( s_name, b_found ) );
+ }
+
+ void del_elem( string &s_name )
+ {
+ smap<user*,string>::del_elem( s_name );
+ if ( smap<user*,string>::get_size() == 0 )
clean_room();
-
- else
- reload_onlineframe();
- }
-
- void msg_post( string s_msg )
- {
- msg_post( &s_msg );
- }
-
- void msg_post( string *p_msg )
- {
-#ifdef LOGGING
- p_logd->log_simple_line( logd::remove_html_tags(*p_msg) );
-#endif
-
- base<user>::msg_post( p_msg );
- }
-
- void javascript_post( string s_msg )
- {
- string s_js = "<script language=\"JavaScript\">"+s_msg+"</script>\n";
- base<user>::msg_post( &s_js );
- }
-
- string get_bold_name()
- {
- return "<b>" + get_name() + "</b>";
- }
-
- virtual void set_name( string s_name );
- string get_topic();
- void set_topic( string s_topic );
- void set_topic( string s_topic, string s_color );
- void clean_room();
-
-
+ else
+ reload_onlineframe();
+ }
+
+ void msg_post( string s_msg )
+ {
+ msg_post( &s_msg );
+ }
+ void msg_post( string *p_msg )
+ {
+ p_logd->log_simple_line( logd::remove_html_tags(*p_msg) );
+ base<user>::msg_post( p_msg );
+ }
+
+ string get_bold_name()
+ {
+ return "<b>" + get_name() + "</b>";
+ }
+
+ virtual void set_name( string s_name );
+ string get_topic();
+ void set_topic( string s_topic );
+ void set_topic( string s_topic, string s_color );
+ void clean_room();
+
+
};
diff --git a/src/chat/sess.cpp b/src/chat/sess.cpp
index dc9ba9b..b41c8ce 100755
--- a/src/chat/sess.cpp
+++ b/src/chat/sess.cpp
@@ -3,54 +3,27 @@
#include "sess.h"
-sess::sess( string s_tmpid )
+sess::sess( string s_id )
{
- this->p_user = NULL;
- this->s_tmpid = s_tmpid;
+ this->sess_id=s_id;
}
sess::~sess()
-{}
-
-string
-sess::get_tmpid()
{
- return s_tmpid;
+
}
string
-sess::get_name()
-{
- if ( p_user = NULL )
- return "";
-
- return p_user->get_name();
-}
-
-void
-sess::set_name(string s_name)
-{
- if ( p_user != NULL )
- p_user->set_name(s_name);
-}
-
-user*
-sess::get_user()
-{
- return p_user;
-}
-
-void
-sess::set_user(user* p_user)
+sess::get_id()
{
- this->p_user = p_user;
+ return this->sess_id;
}
void
sess::invalidate()
{
- this->s_tmpid = "0";
+ this->sess_id = "0";
}
#endif
diff --git a/src/chat/sess.h b/src/chat/sess.h
index 17d9cfe..717564a 100755
--- a/src/chat/sess.h
+++ b/src/chat/sess.h
@@ -3,29 +3,24 @@
#ifndef SESS_H
#define SESS_H
+#include <map>
#include <string>
-#include "user.h"
class cont;
using namespace std;
-class sess
+class sess : public name
{
+
private:
- string s_tmpid;
- user *p_user;
+ string sess_id;
public:
- sess(string s_tmpid);
- ~sess();
-
- string get_tmpid();
+ sess(string s_id);
+ ~sess();
- void set_user(user* p_user);
- user* get_user();
- void set_name(string s_name);
- string get_name();
- void invalidate();
+ string get_id();
+ void invalidate();
};
#endif
diff --git a/src/chat/sman.cpp b/src/chat/sman.cpp
index 8246853..464bf24 100755
--- a/src/chat/sman.cpp
+++ b/src/chat/sman.cpp
@@ -6,123 +6,108 @@
#include "../maps/mtools.h"
#include "../contrib/crypt/md5.h"
-sman::sman()
+sman::sman() : smap<sess*,string>::smap(HMAPOCC)
{
- i_session_count = 0;
- pthread_mutex_init( &mut_i_session_count, NULL );
+ 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 );
+ // Delete each session object of the smap!
+ smap<sess*,string>::run_func( mtools<sess*>::delete_obj );
+ pthread_mutex_destroy( &mut_i_session_count );
}
-string sman::generate_id( int i_len )
+string sman::generate_id( int len )
{
- 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() % 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");
- 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;
+ string valid_chars = 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 < len; i++)
+ {
+ i_char = rand() % 64;
+ s_ret += valid_chars[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);
+ }
+
+ return s_ret;
}
sess *sman::create_session( )
{
- string s_tmpid = generate_id( tool::string2int( wrap::CONF->get_elem( "chat.session.length" ) ) );
+ string s_id = generate_id( tool::string2int( wrap::CONF->get_elem( "chat.session.length" ) ) );
- sess* p_sess = new sess( s_tmpid );
+ sess* p_sess = new sess( s_id );
- pthread_mutex_lock( &mut_i_session_count );
- i_session_count++;
+ pthread_mutex_lock( &mut_i_session_count );
+ i_session_count++;
#ifdef NCURSES
-
- print_sessions();
+ print_sessions();
#endif
+ pthread_mutex_unlock( &mut_i_session_count );
- pthread_mutex_unlock( &mut_i_session_count );
-
- //????
- add_elem( p_sess, s_tmpid );
+ add_elem( p_sess, s_id );
- return p_sess;
+ return p_sess;
}
sess *sman::get_session( string s_id )
{
- return get_elem( s_id );
+ return get_elem( s_id );
}
void
sman::destroy_session( string s_id )
{
- pthread_mutex_lock( &mut_i_session_count );
- i_session_count--;
+ pthread_mutex_lock( &mut_i_session_count );
+ i_session_count--;
#ifdef NCURSES
-
- print_sessions();
+ print_sessions();
#endif
+ pthread_mutex_unlock( &mut_i_session_count );
- pthread_mutex_unlock( &mut_i_session_count );
-
- sess* p_sess = get_elem( s_id );
- del_elem( s_id );
- delete p_sess;
+ sess* p_sess = get_elem( s_id );
+ del_elem( s_id );
+ delete p_sess;
}
#ifdef NCURSES
void sman::print_sessions()
{
- if ( wrap::NCUR->is_ready() )
- {
- mvprintw( NCUR_SESSION_X,NCUR_SESSION_Y, "Sessions: %d ", i_session_count);
- refresh();
- }
+ if ( wrap::NCUR->is_ready() )
+ {
+ mvprintw( NCUR_SESSION_X,NCUR_SESSION_Y, "Sessions: %d ", i_session_count);
+ refresh();
+ }
}
#ifdef NCURSES
void sman::print_init_ncurses()
{
- pthread_mutex_lock( &mut_i_session_count );
- print_sessions();
- pthread_mutex_unlock( &mut_i_session_count );
+ pthread_mutex_lock( &mut_i_session_count );
+ print_sessions();
+ pthread_mutex_unlock( &mut_i_session_count );
}
#endif
int
sman::get_session_count()
{
- int i_ret;
- pthread_mutex_lock( &mut_i_session_count );
- i_ret = i_session_count;
- pthread_mutex_unlock( &mut_i_session_count );
- return i_ret;
+ int i_ret;
+ pthread_mutex_lock( &mut_i_session_count );
+ i_ret = i_session_count;
+ pthread_mutex_unlock( &mut_i_session_count );
+ return i_ret;
}
#endif
diff --git a/src/chat/sman.h b/src/chat/sman.h
index 13fc45a..1843aec 100755
--- a/src/chat/sman.h
+++ b/src/chat/sman.h
@@ -6,35 +6,31 @@
#include <cstdlib>
#include "sess.h"
-#include "../maps/shashmap.h"
-#include "../monitor/dump.h"
+#include "../maps/smap.h"
using namespace std;
-class sman : public shashmap<sess*>
+class sman : private smap<sess*,string>
{
private:
- string generate_id( int i_len );
- int i_session_count;
+ string generate_id( int len );
+ int i_session_count;
- pthread_mutex_t mut_i_session_count;
+ pthread_mutex_t mut_i_session_count;
#ifdef NCURSES
-
- void print_sessions();
+ void print_sessions();
#endif
public:
- sman();
- ~sman();
- sess *get_session( string s_tmpid );
- int get_session_count( );
- sess *create_session( );
- void destroy_session( string s_tmpid );
+ sman();
+ ~sman();
+ sess *get_session( string s_id );
+ int get_session_count( );
+ sess *create_session( );
+ void destroy_session( string s_id );
#ifdef NCURSES
-
- void print_init_ncurses();
+ void print_init_ncurses();
#endif
-
};
diff --git a/src/chat/user.cpp b/src/chat/user.cpp
index eb49f8c..40dbee8 100755
--- a/src/chat/user.cpp
+++ b/src/chat/user.cpp
@@ -8,669 +8,572 @@ using namespace std;
user::user() : name( "" )
{
- initialize();
+ initialize();
}
user::user( string s_name ) : name( s_name )
{
- initialize();
+ initialize();
}
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 );
+// 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_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()
{
- time(&t_flood_time);
- init_strings(wrap::CONF->get_vector("chat.fields.userstrings"));
- init_ints(wrap::CONF->get_vector("chat.fields.userints"));
- init_bools(wrap::CONF->get_vector("chat.fields.userbools"));
-
- this -> p_room = 0;
- this -> b_is_reg = false;
- this -> b_is_gag = false;
- this -> b_set_changed_data = false;
- this -> b_away = false;
- this -> b_fake = false;
- this -> b_invisible = false;
- 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();
+ this -> b_is_reg = false;
+ this -> b_set_changed_data = false;
+ this -> b_away = false;
+ this -> b_fake = false;
+ this -> b_invisible = false;
+ this -> s_col1 = wrap::CONF->get_elem( "chat.html.user.color1" );
+ this -> s_col2 = wrap::CONF->get_elem( "chat.html.user.color2" );
+ //map_mods = new smap<dynmod*,string>(HMAPOCC);
+
+ // 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_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();
}
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 );
+ wrap::SMAN->destroy_session( get_tmpid() );
#endif
+ // wrap::system_message( SESSION + tool::int2string( wrap::SMAN->get_session_count() ) );
+ }
- set_has_sess(false);
- wrap::SMAN->destroy_session(get_tmpid());
- set_tmpid("");
+ set_fake( false );
+ set_invisible( false );
}
string
user::get_colored_name()
{
- return "<font color=\"#" + get_col1() + "\">" + get_name() + "</font>";
+ return "<font color=\"#" + get_col1() + "\">" + get_name() + "</font>";
}
void
-user::get_data( map<string,string> *p_map_data )
+user::get_data( map_string *p_map_data )
{
- string s_req = (*p_map_data)["!get"];
+ string s_req = (*p_map_data)["!get"];
- // get the nick and the color of the user.
- if ( s_req == "nick" )
- (*p_map_data)[get_name()] = get_col1();
+ // get the nick and the color of the user.
+ if ( s_req == "nick" )
+ (*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;
+ 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( )
{
- bool b_ret;
- pthread_mutex_lock ( &mut_b_online );
- b_ret = b_online;
- pthread_mutex_unlock( &mut_b_online );
- return b_ret;
+ 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( )
{
- bool b_ret;
- pthread_mutex_lock ( &mut_b_fake );
- b_ret = b_fake;
- pthread_mutex_unlock( &mut_b_fake );
- return b_ret;
+ 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( )
{
- bool b_ret;
- pthread_mutex_lock ( &mut_b_invisible );
- b_ret = b_invisible;
- pthread_mutex_unlock( &mut_b_invisible );
- return b_ret;
+ 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( )
{
- 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;
+ 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 )
{
- pthread_mutex_lock ( &mut_b_has_sess );
- this->b_has_sess = b_has_sess;
- pthread_mutex_unlock( &mut_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( )
{
- bool b_ret;
- b_ret = b_is_reg;
- return b_ret;
-}
-
-bool
-user::get_is_gag( )
-{
- bool b_ret;
- pthread_mutex_lock ( &mut_b_is_gag );
- b_ret = b_is_gag;
- pthread_mutex_unlock( &mut_b_is_gag );
- return b_ret;
+ bool b_ret;
+ b_ret = b_is_reg;
+ return b_ret;
}
void
user::set_is_reg( bool b_is_reg )
{
- this -> b_is_reg = 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 );
+ this -> b_is_reg = b_is_reg;
}
void
user::set_online( bool b_online )
{
- pthread_mutex_lock ( &mut_b_online );
- this -> b_online = b_online;
- pthread_mutex_unlock( &mut_b_online );
+ pthread_mutex_lock ( &mut_b_online );
+ this -> b_online = b_online;
+ 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 );
+ 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 );
+ 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;
+ bool b_ret;
+ pthread_mutex_lock ( &mut_away );
+ b_ret = b_away;
+ pthread_mutex_unlock( &mut_away );
+ return b_ret;
}
string
user::get_away_msg()
{
- string s_ret;
- pthread_mutex_lock ( &mut_away );
- s_ret = s_away;
- pthread_mutex_unlock( &mut_away );
- return s_ret;
+ string s_ret;
+ pthread_mutex_lock ( &mut_away );
+ s_ret = s_away;
+ pthread_mutex_unlock( &mut_away );
+ return s_ret;
}
void
user::set_away( bool b_away, string s_away )
{
- pthread_mutex_lock ( &mut_away );
- this -> b_away = b_away;
- this -> s_away = s_away;
- pthread_mutex_unlock( &mut_away );
+ pthread_mutex_lock ( &mut_away );
+ this -> b_away = b_away;
+ this -> s_away = s_away;
+ pthread_mutex_unlock( &mut_away );
}
void
user::set_away( bool b_away )
{
- pthread_mutex_lock ( &mut_away );
- this -> b_away = b_away;
- pthread_mutex_unlock( &mut_away );
+ pthread_mutex_lock ( &mut_away );
+ this -> b_away = b_away;
+ pthread_mutex_unlock( &mut_away );
}
room*
user::get_room( )
{
- room* p_return;
- pthread_mutex_lock ( &mut_p_room );
- p_return = p_room;
- pthread_mutex_unlock( &mut_p_room );
- return p_return;
+ room* p_return;
+ pthread_mutex_lock ( &mut_p_room );
+ p_return = p_room;
+ pthread_mutex_unlock( &mut_p_room );
+ return p_return;
}
void
user::set_p_room( room* p_room )
{
- pthread_mutex_lock ( &mut_p_room );
- this -> p_room = p_room;
- pthread_mutex_unlock( &mut_p_room );
+ pthread_mutex_lock ( &mut_p_room );
+ this -> p_room = p_room;
+ pthread_mutex_unlock( &mut_p_room );
}
string
user::get_pass()
{
- string s_ret;
- pthread_mutex_lock ( &mut_s_pass );
- s_ret = s_pass;
- pthread_mutex_unlock( &mut_s_pass );
- return s_ret;
+ string s_ret;
+ pthread_mutex_lock ( &mut_s_pass );
+ s_ret = s_pass;
+ pthread_mutex_unlock( &mut_s_pass );
+ return s_ret;
}
string
user::get_col1()
{
- string s_ret;
- pthread_mutex_lock ( &mut_s_col1 );
- s_ret = s_col1;
- pthread_mutex_unlock( &mut_s_col1 );
- return s_ret;
+ string s_ret;
+ pthread_mutex_lock ( &mut_s_col1 );
+ s_ret = s_col1;
+ pthread_mutex_unlock( &mut_s_col1 );
+ return s_ret;
}
string
user::get_col2()
{
- string s_ret;
- pthread_mutex_lock ( &mut_s_col2 );
- s_ret = s_col2;
- pthread_mutex_unlock( &mut_s_col2 );
- return s_ret;
+ string s_ret;
+ pthread_mutex_lock ( &mut_s_col2 );
+ s_ret = s_col2;
+ pthread_mutex_unlock( &mut_s_col2 );
+ return s_ret;
}
string
user::get_email()
{
- string s_ret;
- pthread_mutex_lock ( &mut_s_email );
- s_ret = s_email;
- pthread_mutex_unlock( &mut_s_email );
- return s_ret;
+ string s_ret;
+ pthread_mutex_lock ( &mut_s_email );
+ s_ret = s_email;
+ pthread_mutex_unlock( &mut_s_email );
+ return s_ret;
}
string
user::get_tmpid()
{
- string s_ret;
- pthread_mutex_lock ( &mut_s_tmpid );
- s_ret = s_tmpid;
- pthread_mutex_unlock( &mut_s_tmpid );
- return s_ret;
+ string s_ret;
+ pthread_mutex_lock ( &mut_s_tmpid );
+ s_ret = s_tmpid;
+ pthread_mutex_unlock( &mut_s_tmpid );
+ return s_ret;
}
void
user::set_tmpid ( string s_tmpid )
{
- pthread_mutex_lock ( &mut_s_tmpid );
- this -> s_tmpid = s_tmpid;
- pthread_mutex_unlock( &mut_s_tmpid );
+ pthread_mutex_lock ( &mut_s_tmpid );
+ this -> s_tmpid = s_tmpid;
+ pthread_mutex_unlock( &mut_s_tmpid );
}
void
user::set_pass ( string s_pass )
{
- set_changed_data( "password", s_pass );
- pthread_mutex_lock ( &mut_s_pass );
- this -> s_pass = s_pass;
- pthread_mutex_unlock( &mut_s_pass );
+ set_changed_data( "password", s_pass );
+ pthread_mutex_lock ( &mut_s_pass );
+ this -> s_pass = s_pass;
+ pthread_mutex_unlock( &mut_s_pass );
}
void
user::set_col1 ( string s_col1 )
{
- set_changed_data( "color1", s_col1 );
- pthread_mutex_lock ( &mut_s_col1 );
- this -> s_col1 = s_col1;
- pthread_mutex_unlock( &mut_s_col1 );
+ set_changed_data( "color1", s_col1 );
+ pthread_mutex_lock ( &mut_s_col1 );
+ this -> s_col1 = s_col1;
+ pthread_mutex_unlock( &mut_s_col1 );
}
void
user::set_col2 ( string s_col2 )
{
- set_changed_data( "color2", s_col2 );
- pthread_mutex_lock ( &mut_s_col2 );
- this -> s_col2 = s_col2;
- pthread_mutex_unlock( &mut_s_col2 );
+ set_changed_data( "color2", s_col2 );
+ pthread_mutex_lock ( &mut_s_col2 );
+ this -> s_col2 = s_col2;
+ pthread_mutex_unlock( &mut_s_col2 );
}
void
user::set_email ( string s_email )
{
- set_changed_data( "email", s_email );
- pthread_mutex_lock ( &mut_s_email );
- this -> s_email = s_email;
- pthread_mutex_unlock( &mut_s_email );
+ set_changed_data( "email", s_email );
+ pthread_mutex_lock ( &mut_s_email );
+ this -> s_email = s_email;
+ pthread_mutex_unlock( &mut_s_email );
}
int
user::get_status ( )
{
- int r_ret;
- pthread_mutex_lock ( &mut_i_status );
- r_ret = i_status;
- pthread_mutex_unlock(&mut_i_status );
- return r_ret;
+ int r_ret;
+ pthread_mutex_lock ( &mut_i_status );
+ r_ret = i_status;
+ pthread_mutex_unlock(&mut_i_status );
+ return r_ret;
}
void
user::set_status ( int i_status )
{
- set_changed_data( "status", tool::int2string(i_status));
- pthread_mutex_lock ( &mut_i_status );
- i_old_status = this -> i_status;
- this -> i_status = i_status;
- pthread_mutex_unlock( &mut_i_status );
+ set_changed_data( "status", tool::int2string(i_status));
+ pthread_mutex_lock ( &mut_i_status );
+ i_old_status = this -> i_status;
+ this -> i_status = i_status;
+ pthread_mutex_unlock( &mut_i_status );
}
void
user::set_changed_data( string s_varname, string s_value )
{
- if ( b_set_changed_data )
- {
- pthread_mutex_lock ( &mut_map_changed_data );
- map_changed_data[s_varname] = s_value;
- pthread_mutex_unlock( &mut_map_changed_data );
- }
+ if ( b_set_changed_data )
+ {
+ pthread_mutex_lock ( &mut_map_changed_data );
+ map_changed_data[s_varname] = s_value;
+ pthread_mutex_unlock( &mut_map_changed_data );
+ }
}
bool
user::new_msgs ( )
{
- pthread_mutex_lock ( &mut_s_mess );
- return s_mess.empty();
- pthread_mutex_unlock( &mut_s_mess );
+ pthread_mutex_lock ( &mut_s_mess );
+ return s_mess.empty();
+ pthread_mutex_unlock( &mut_s_mess );
}
void
user::command( string &s_command )
{
- check_restore_away();
-
- unsigned pos = s_command.find( "/" );
- unsigned pos2 = s_command.find( " " );
- if( pos != string::npos )
- {
- s_command.replace( pos, 1, "" );
- }
- else
- return;
-
- if (pos2 == string::npos)
- pos2 = s_command.size() + 1;
-
- string s_mod( wrap::CONF->get_elem("httpd.modules.commandsdir") + "yc_" );
- string s_command2 = s_command.substr(0, pos2-1);
- s_mod.append( s_command2 ).append( ".so" );
-
- dynmod *mod = wrap::MODL->get_module( s_mod, get_name() );
-
- if ( mod == NULL ||
- wrap::CHAT->get_command_disabled( s_command2 ) ||
- get_status() > wrap::CHAT->get_command_status( s_command2 ) )
- {
- string s_msg = "<font color=\"" + wrap::CONF->get_elem("chat.html.errorcolor") + "\">"
- + wrap::CONF->get_elem( "chat.msgs.err.findingcommand" )
- + "</font>\n";
- msg_post( &s_msg );
- return;
- }
-
- vector<string> params;
-
- // execute the module.
- if (s_command.find(" ") != string::npos)
- {
- s_command = s_command.substr(s_command2.size()+1);
- pos = s_command.find(" ");
- pos2 = 0;
-
- while (pos != string::npos)
+ check_restore_away();
+
+ unsigned pos = s_command.find( "/" );
+ unsigned pos2 = s_command.find( " " );
+ if( pos != string::npos )
{
- string sParam = s_command.substr(pos2, pos - pos2);
- params.push_back(sParam);
- pos2 = pos + 1;
- pos = s_command.find(" ", pos2);
+ s_command.replace( pos, 1, "" );
}
+ else
+ return;
- if (pos2 < s_command.size())
- {
- params.push_back(s_command.substr(pos2, s_command.size()-pos2));
+ if (pos2 == string::npos)
+ pos2 = s_command.size() + 1;
+
+ string s_mod( wrap::CONF->get_elem("httpd.modules.commandsdir") + "yc_" );
+ string s_command2 = s_command.substr(0, pos2-1);
+ s_mod.append( s_command2 ).append( ".so" );
+
+ dynmod *mod = wrap::MODL->get_module( s_mod );
+
+ if ( mod == NULL ||
+ wrap::CHAT->get_command_disabled( s_command2 ) ||
+ get_status() > wrap::CHAT->get_command_status( s_command2 ) )
+ {
+ string s_msg = "<font color=\"" + wrap::CONF->get_elem("chat.html.errorcolor") + "\">"
+ + wrap::CONF->get_elem( "chat.msgs.err.findingcommand" )
+ + "</font>\n";
+ msg_post( &s_msg );
+ return;
}
- }
+ vector<string> params;
- container* c = new container;
- //c->elem[0]=(void*) unreserved
- c->elem[1] = (void*) this;
- c->elem[2] = (void*) &params;
- c->elem[3] = (void*) wrap::WRAP;
+ // execute the module.
+ if (s_command.find(" ") != string::npos)
+ {
+ s_command = s_command.substr(s_command2.size()+1);
+ pos = s_command.find(" ");
+ pos2 = 0;
+
+ while (pos != string::npos)
+ {
+ string sParam = s_command.substr(pos2, pos - pos2);
+ params.push_back(sParam);
+ pos2 = pos + 1;
+ pos = s_command.find(" ", pos2);
+ }
+
+ if (pos2 < s_command.size())
+ {
+ params.push_back(s_command.substr(pos2, s_command.size()-pos2));
+ }
+
+ }
+
+ container* c = new container;
+ //c->elem[0]=(void*) unreserved
+ c->elem[1] = (void*) this;
+ c->elem[2] = (void*) &params;
+ c->elem[3] = (void*) wrap::WRAP;
- ( *(mod->the_func) ) ( static_cast<void*>(c) );
+ ( *(mod->the_func) ) ( (void*) c );
- delete c;
+ delete c;
}
void
user::s_mess_delete( )
{
- pthread_mutex_lock ( &mut_s_mess );
- s_mess = "";
- pthread_mutex_unlock( &mut_s_mess );
+ pthread_mutex_lock ( &mut_s_mess );
+ s_mess = "";
+ pthread_mutex_unlock( &mut_s_mess );
}
void
user::msg_post( string *p_msg )
{
- pthread_mutex_lock ( &mut_s_mess );
- s_mess.append( *p_msg );
- pthread_mutex_unlock( &mut_s_mess );
+ pthread_mutex_lock ( &mut_s_mess );
+ s_mess.append( *p_msg );
+ pthread_mutex_unlock( &mut_s_mess );
- pthread_cond_signal( &cond_message );
+ pthread_cond_signal( &cond_message );
}
void
-user::post_action_msg(string s_msgkey)
+user::check_timeout( int* i_idle_timeout )
{
- get_room()->msg_post(wrap::TIMR->get_time()+" "+get_colored_bold_name()+wrap::CONF->get_elem(s_msgkey)+"<br>\n");
+ int i_user_timeout = (int) get_last_activity();
+
+ if ( get_away() ? i_idle_timeout[1] <= i_user_timeout : i_idle_timeout[0] <= i_user_timeout )
+ {
+ wrap::system_message( string(TIMERTO) + "(" + get_name() + "," + tool::int2string(i_user_timeout) + ")");
+ string s_quit = "<script language=JavaScript>top.location.href='/"
+ + wrap::CONF->get_elem("httpd.startsite")
+ + "';</script>";
+ msg_post( &s_quit );
+ set_online( false );
+ }
+
+ else if ( ! get_away() && i_idle_timeout[2] <= i_user_timeout )
+ {
+ wrap::system_message( string(TIMERAT) + "(" + get_name() + "," + tool::int2string(i_user_timeout) + ")");
+ string s_msg = wrap::CONF->get_elem("chat.msgs.userautoawaytimeout");
+ set_away( true, s_msg );
+ string s_msg2 = wrap::TIMR->get_time() + " <b>" + get_colored_name()+ "</b>" + s_msg + "<br>\n";
+ get_room()->msg_post( &s_msg2 );
+ get_room()->reload_onlineframe();
+ }
}
void
-user::renew_timeout()
+user::get_user_list( string &s_list )
{
- timo::renew_timeout();
- double d_time_diff = wrap::TIMR->get_time_diff(t_flood_time);
+ if ( get_invisible() )
+ return;
- if (d_time_diff < static_cast<double>(wrap::CONF->get_int("chat.floodprotection.seconds")))
- {
- if (++i_flood_messages > static_cast<double>(wrap::CONF->get_int("chat.floodprotection.messages")))
- {
- room* p_room = get_room();
- if (p_room == 0)
- {
- i_flood_messages = 0;
- return;
- }
-
- wrap::system_message(CHATFLO+get_name()+","+p_room->get_name()+","+tool::int2string(i_flood_messages)+")");
- msg_post(wrap::CONF->colored_error_msg("chat.msgs.err.flooding"));
- if (!get_is_gag())
- {
- set_is_gag(true);
- post_action_msg("chat.msgs.floodgag");
- }
- }
- }
-
- else
- {
- time(&t_flood_time);
- i_flood_messages = 0;
- }
-}
-
-void
-user::check_timeout( int* i_idle_timeout )
-{
- double d_user_timeout = get_last_activity();
- if ( get_away() ? i_idle_timeout[1] <= d_user_timeout : i_idle_timeout[0] <= d_user_timeout )
- {
- wrap::system_message( string(TIMERTO) + "(" + get_name() + "," + tool::int2string((int)d_user_timeout) + ")");
- string s_quit = "<script language=JavaScript>top.location.href='/"
- + wrap::CONF->get_elem("httpd.startsite")
- + "';</script>";
- msg_post( &s_quit );
- set_online( false );
+ s_list.append( wrap::CONF->get_elem("chat.html.onlinebefore") );
+
+ if ( get_away() )
+ {
+ s_list.append("<img src=\"" + wrap::CONF->get_elem("chat.html.rangimages.location")+ "away.gif\"" )
+ .append( " alt='" )
+ .append( get_away_msg() )
+ .append( "' title='" )
+ .append( get_away_msg() )
+ .append( "'" + wrap::CONF->get_elem("chat.html.rangimages.options") + "> " );
+ }
+ else if ( ! get_is_reg() )
+ {
+ string s_msgs = wrap::CONF->get_elem("chat.msgs.guest");
+ s_list.append("<img src=\"" + wrap::CONF->get_elem("chat.html.rangimages.location")+ "guest.png\"" )
+ .append( " alt='" )
+ .append( s_msgs )
+ .append( "' title='" )
+ .append( s_msgs )
+ .append( "'" + wrap::CONF->get_elem("chat.html.rangimages.options") + "> " );
+ }
+ else if ( get_status() != tool::string2int( wrap::CONF->get_elem("chat.defaultrang") ) && ! get_fake() )
+ {
+ string s_status = "RANG" + tool::int2string( get_status() );
+ string s_msgs = wrap::CONF->get_elem( "chat.msgs." + s_status );
+ s_list.append("<img src=\"" + wrap::CONF->get_elem("chat.html.rangimages.location") + tool::to_lower(s_status) + ".png\"" )
+ .append( " alt='" )
+ .append( s_msgs )
+ .append( "' title='" )
+ .append( s_msgs )
+ .append( "'" + wrap::CONF->get_elem("chat.html.rangimages.options") + "> " );
+ }
- pthread_cond_signal( &cond_message );
- }
- else if ( ! get_away() && i_idle_timeout[2] <= d_user_timeout )
- {
- wrap::system_message( string(TIMERAT) + "(" + get_name() + "," + tool::int2string((int)d_user_timeout) + ")");
- string s_msg = wrap::CONF->get_elem("chat.msgs.userautoawaytimeout");
- set_away( true, s_msg );
- string s_msg2 = wrap::TIMR->get_time() + " <b>" + get_colored_name()+ "</b>" + s_msg + "<br>\n";
- get_room()->msg_post( &s_msg2 );
- get_room()->reload_onlineframe();
- }
-}
+ else
+ {
+ s_list.append("<img src=\"images/blank.gif\"" + wrap::CONF->get_elem("chat.html.rangimages.options") + "> ");
+ }
-void
-user::get_user_list( string &s_list )
-{
- if ( get_invisible() )
- return;
-
- s_list.append( wrap::CONF->get_elem("chat.html.onlinebefore") );
-
- if ( get_away() )
- {
- s_list.append("<img src=\"" + wrap::CONF->get_elem("chat.html.rangimages.location")+ "away.gif\"" )
- .append( " alt='" )
- .append( get_away_msg() )
- .append( "' title='" )
- .append( get_away_msg() )
- .append( "'" + wrap::CONF->get_elem("chat.html.rangimages.options") + "> " );
- }
- else if ( ! get_is_reg() )
- {
- string s_msgs = wrap::CONF->get_elem("chat.msgs.guest");
- s_list.append("<img src=\"" + wrap::CONF->get_elem("chat.html.rangimages.location")+ "guest.png\"" )
- .append( " alt='" )
- .append( s_msgs )
- .append( "' title='" )
- .append( s_msgs )
- .append( "'" + wrap::CONF->get_elem("chat.html.rangimages.options") + "> " );
- }
- else if ( get_status() != tool::string2int( wrap::CONF->get_elem("chat.defaultrang") ) && ! get_fake() )
- {
- string s_status = "rang" + tool::int2string( get_status() );
- string s_msgs = wrap::CONF->get_elem( "chat.msgs." + s_status );
- s_list.append("<img src=\"" + wrap::CONF->get_elem("chat.html.rangimages.location") + tool::to_lower(s_status) + ".png\"" )
- .append( " alt='" )
- .append( s_msgs )
- .append( "' title='" )
- .append( s_msgs )
- .append( "'" + wrap::CONF->get_elem("chat.html.rangimages.options") + "> " );
- }
- else
- {
- s_list.append("<img src=\"images/blank.gif\"" + wrap::CONF->get_elem("chat.html.rangimages.options") + "> ");
- }
-
- s_list.append( get_colored_name() );
- s_list.append( wrap::CONF->get_elem("chat.html.onlinebehind") );
- s_list.append( "\n" );
+ s_list.append( get_colored_name() );
+ s_list.append( wrap::CONF->get_elem("chat.html.onlinebehind") );
+ s_list.append( "\n" );
}
void
user::check_restore_away()
{
- if ( get_away() )
- {
- get_room()->msg_post(
- new string(
- wrap::TIMR->get_time()
- + " <b>" + get_colored_name()
- + "</b> " + wrap::CONF->get_elem( "chat.msgs.unsetmodeaway" )
- + "( <font color=" + get_col2() + ">"
- + get_away_msg() + "</font>)<br>\n"
- )
- );
- set_away( false );
- get_room()->reload_onlineframe();
- }
+ if ( get_away() )
+ {
+ get_room()->msg_post(
+ new string(
+ wrap::TIMR->get_time()
+ + " <b>" + get_colored_name()
+ + "</b> " + wrap::CONF->get_elem( "chat.msgs.unsetmodeaway" )
+ + "( <font color=" + get_col2() + ">"
+ + get_away_msg() + "</font>)<br>\n"
+ )
+ );
+ set_away( false );
+ get_room()->reload_onlineframe();
+ }
}
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());
-}
-
-bool
-user::same_rooms(user *p_user)
-{
- return p_user->get_room()->get_lowercase_name()
- .compare(this->get_room()->get_lowercase_name()) == 0;
-}
-
-string
-user::make_colors(string s_msg)
{
- return "<font color=\"#" + get_col1() + "\">" + s_msg + "</font>";
}
#endif
diff --git a/src/chat/user.h b/src/chat/user.h
index 06310ca..a88aea7 100755
--- a/src/chat/user.h
+++ b/src/chat/user.h
@@ -3,152 +3,132 @@
#ifndef USER_H
#define USER_H
+#include "../maps/smap.h"
#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 dumpable,
- public memb_base
+class user : public name, public timo
{
private:
- // private members:
- string s_mess; // message string which has to be sent to the user.
-
- bool b_online; // true if user is online.
- bool b_has_sess; // true if user already has a session!
- bool b_is_reg; // true if user is registered
- bool b_is_gag; // true if user is gagged
- bool b_away; // true if user is away.
- bool b_fake; // true if user hides his status logo (does not work for guest)
- bool b_invisible; // true if user hides his status logo (does not work for guest)
- bool b_set_changed_data; // Only set change data if required!
-
- int i_status; // user's rang ( see enum rang @ globals.h ).
- int i_old_status; // user's previous status.
- int i_flood_messages; // user's message posts (needed for flood protection, does not need to be syncronized)
- time_t t_flood_time; // user's time count (needed for flood protection, does not need to be syncronized)
-
- string s_tmpid;
- string s_agnt; // user's http user agent.
- string s_away; // user's last away message.
- string s_col1; // user's nick color.
- string s_col2; // user's text color.
- string s_email; // user's email addres
- string s_pass; // password
- room* p_room; // pointer to the user's room.
-
- hashmap<string> map_changed_data; // Needed to tell yChat which data to change after user is removed!
- pthread_mutex_t mut_map_changed_data;
- pthread_mutex_t mut_s_mess;
-
- // Modules which are allowed to be executed by the user.
-
- pthread_mutex_t mut_away;
- pthread_mutex_t mut_b_online;
- pthread_mutex_t mut_b_fake;
- pthread_mutex_t mut_b_invisible;
- pthread_mutex_t mut_b_has_sess;
- pthread_mutex_t mut_b_is_reg;
- pthread_mutex_t mut_b_is_gag;
- pthread_mutex_t mut_s_pass;
- pthread_mutex_t mut_p_room;
- pthread_mutex_t mut_s_col1;
- pthread_mutex_t mut_s_col2;
- pthread_mutex_t mut_s_email;
- pthread_mutex_t mut_s_tmpid;
- pthread_mutex_t mut_i_status;
-
- void initialize();
- void set_changed_data( string s_varname, string s_value );
- void dumpit();
-
-public:
- pthread_cond_t cond_message;
- pthread_mutex_t mut_message;
-
- user();
- user(string s_name);
- ~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
- // every time data has to be got from every user of a room
- // or even of the system.
- void get_data( map<string,string> *p_map_data );
-
- string get_colored_name();
- string get_colored_bold_name()
- {
- return "<b>" + get_colored_name() + "</b>";
- }
- bool get_online();
- bool get_fake();
- bool get_invisible();
- bool get_has_sess();
- bool get_is_reg();
- bool get_is_gag();
- void set_online( bool b_online );
- void set_fake( bool b_fake );
- void set_invisible( bool b_invisible );
- void set_has_sess( bool b_has_sess );
- void set_is_reg( bool b_is_reg );
- void set_is_gag( bool b_is_gag );
- void set_changed_data_on() { b_set_changed_data = 1; }
- bool get_away( );
- string get_away_msg( );
- void set_away( bool b_away, string s_away );
- void set_away( bool b_away );
- room* get_room();
- void set_p_room( room* p_room );
- string get_pass();
- string get_col1();
- string get_col2();
- string get_email();
- string get_tmpid();
- void set_tmpid( string s_tmpid );
- void set_pass( string s_col1 );
- void set_col1( string s_col1 );
- void set_col2( string s_col2 );
- void set_email( string s_email );
- int get_status( );
- void set_status( int i_status );
- bool new_msgs ( );
- void post_action_msg(string s_msgkey);
- void check_timeout( int* i_idle_timeout );
- void renew_timeout();
-
- // executes a command.
- void command( string &s_command );
-
- // gets the message and clears s_mess;
- string get_mess();
-
-
- // Here are starting methods which are mainly needed by the data<type> class.
- // appends a string to s_mess including br.
- void msg_post( string s_msg )
- {
- msg_post( &s_msg );
- }
- void msg_post( string *p_msg );
- void s_mess_delete( );
- void get_user_list( string &s_list );
- void check_restore_away();
- void reconf();
- bool same_rooms(user *p_user);
- string make_colors(string s_msg);
+ // private members:
+ bool b_online; // true if user is online.
+ bool b_has_sess; // true if user already has a session!
+ bool b_is_reg; // true if user is registered
+ bool b_away; // true if user is away.
+ bool b_fake; // true if user hides his status logo (does not work for guest)
+ bool b_invisible; // true if user hides his status logo (does not work for guest)
+ int i_status; // user's rang ( see enum rang @ globals.h ).
+ int i_old_status; // user's previous status.
+ string s_tmpid;
+ string s_agnt; // user's http user agent.
+ string s_away; // user's last away message.
+ string s_col1; // user's nick color.
+ string s_col2; // user's text color.
+ string s_email; // user's email addres
+ string s_mess; // message string which has to be sent to the user.
+ string s_pass; // password
+ room* p_room; // pointer to the user's room.
+
+ map_string map_changed_data; // Needed to tell yChat which data to change after user is removed!
+ bool b_set_changed_data; // Only set change data if required!
+
+ // Modules which are allowed to be executed by the user.
+
+ // smap<dynmod*,string>* map_mods;
+
+ // pthread_mutex_t mut_map_mods;
+ pthread_mutex_t mut_away;
+ pthread_mutex_t mut_b_online;
+ pthread_mutex_t mut_b_fake;
+ pthread_mutex_t mut_b_invisible;
+ pthread_mutex_t mut_b_has_sess;
+ pthread_mutex_t mut_b_is_reg;
+ pthread_mutex_t mut_s_mess;
+ pthread_mutex_t mut_s_pass;
+ pthread_mutex_t mut_p_room;
+ pthread_mutex_t mut_s_col1;
+ pthread_mutex_t mut_s_col2;
+ pthread_mutex_t mut_s_email;
+ pthread_mutex_t mut_s_tmpid;
+ pthread_mutex_t mut_i_status;
+ pthread_mutex_t mut_map_changed_data;
+
+ void initialize();
+ void set_changed_data( string s_varname, string s_value );
+
+ public:
+ pthread_cond_t cond_message;
+ pthread_mutex_t mut_message;
+
+ user();
+ user(string s_name);
+ ~user();
+
+ void clean();
+
+ // gets specific data of this user und stores it in
+ // (*p_map_string)["nick"]. this method will be used
+ // every time data has to be got from every user of a room
+ // or even of the system.
+ void get_data( map_string *p_map_data );
+
+ string get_colored_name();
+ string get_colored_bold_name()
+ {
+ return "<b>" + get_colored_name() + "</b>";
+ }
+ bool get_online();
+ bool get_fake();
+ bool get_invisible();
+ bool get_has_sess();
+ bool get_is_reg();
+ void set_online( bool b_online );
+ void set_fake( bool b_fake );
+ void set_invisible( bool b_invisible );
+ void set_has_sess( bool b_has_sess );
+ void set_is_reg( bool b_is_reg );
+ void set_changed_data_on() { b_set_changed_data = 1; }
+ bool get_away( );
+ string get_away_msg( );
+ void set_away( bool b_away, string s_away );
+ void set_away( bool b_away );
+ room* get_room();
+ void set_p_room( room* p_room );
+ string get_pass();
+ string get_col1();
+ string get_col2();
+ string get_email();
+ string get_tmpid();
+ void set_tmpid( string s_tmpid );
+ void set_pass( string s_col1 );
+ void set_col1( string s_col1 );
+ void set_col2( string s_col2 );
+ void set_email( string s_email );
+ int get_status( );
+ void set_status( int i_status );
+ bool new_msgs ( );
+ void check_timeout( int* i_idle_timeout );
+
+ // executes a command.
+ void command( string &s_command );
+
+ // gets the message and clears s_mess;
+ string get_mess();
+
+
+ // Here are starting methods which are mainly needed by the data<type> class.
+ // appends a string to s_mess including br.
+ void msg_post( string s_msg ) { msg_post( &s_msg ); }
+ void msg_post( string *p_msg );
+ void s_mess_delete( );
+ void get_user_list( string &s_list );
+ void check_restore_away();
+ void reconf();
};
#endif