summaryrefslogtreecommitdiff
path: root/src/chat
diff options
context:
space:
mode:
Diffstat (limited to 'src/chat')
-rwxr-xr-xsrc/chat/base.h4
-rwxr-xr-xsrc/chat/chat.cpp75
-rwxr-xr-xsrc/chat/chat.h7
-rwxr-xr-xsrc/chat/room.cpp21
-rwxr-xr-xsrc/chat/room.h11
-rwxr-xr-xsrc/chat/sess.cpp40
-rwxr-xr-xsrc/chat/sess.h17
-rwxr-xr-xsrc/chat/sman.cpp11
-rwxr-xr-xsrc/chat/sman.h6
-rwxr-xr-xsrc/chat/user.cpp12
-rwxr-xr-xsrc/chat/user.h6
11 files changed, 57 insertions, 153 deletions
diff --git a/src/chat/base.h b/src/chat/base.h
index dc44c69..ae2e926 100755
--- a/src/chat/base.h
+++ b/src/chat/base.h
@@ -57,14 +57,14 @@ public:
type_obj -> reconf ();
}
- void get_data( map<string,string> *p_map_string )
+ 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,string>*) v_arg );
+ type_obj -> get_data ( (map_string*) v_arg );
}
diff --git a/src/chat/chat.cpp b/src/chat/chat.cpp
index 493c2a5..56e9189 100755
--- a/src/chat/chat.cpp
+++ b/src/chat/chat.cpp
@@ -6,7 +6,6 @@
#include "chat.h"
#include "../tool/tool.h"
#include "../maps/mtools.h"
-#include <list>
using namespace std;
@@ -65,15 +64,13 @@ 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]) );
}
void
-chat::login( map<string,string> &map_params )
+chat::login( map_string &map_params )
{
string s_user = map_params["nick"];
@@ -156,8 +153,8 @@ chat::login( map<string,string> &map_params )
{
sess* p_sess = wrap::SMAN->create_session();
//p_sess->set_value( string("nick"), (void *) new string(s_user) );
- p_sess->set_user(p_user);
- map_params["tmpid"] = p_sess->get_tmpid();
+ p_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 );
}
@@ -167,9 +164,9 @@ chat::login( map<string,string> &map_params )
{
p_user = new user( s_user );
- // prove if nick is registered, else create a guest chatter.
+ // prove if nick is registered
#ifdef DATABASE
- map<string,string> map_results = wrap::DATA->select_user_data( tool::to_lower(s_user), "selectlogin");
+ map_string map_results = wrap::DATA->select_user_data( tool::to_lower(s_user), "selectlogin");
if ( map_results["nick"] == tool::to_lower(s_user) )
{
@@ -194,23 +191,15 @@ chat::login( map<string,string> &map_params )
}
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();
+ 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"] );
@@ -267,7 +256,7 @@ chat::login( map<string,string> &map_params )
}
void
-chat::post( user* p_user, map<string,string> &map_params )
+chat::post( user* p_user, map_string &map_params )
{
p_user->renew_timeout();
@@ -284,37 +273,22 @@ chat::post( user* p_user, map<string,string> &map_params )
+ 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" ));
-
- // 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 )
- {
- string s_tmp[] = { iter->substr(0, i_max_word_length ), iter->substr(i_max_word_length) };
- 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 );
- unsigned i_pos = s_msg.find( "/" );
+ auto unsigned i_pos = s_msg.find( "/" );
if ( i_pos == 0 )
return p_user->command( s_msg );
- string_replacer(&s_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-- )
+ 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" )
@@ -338,15 +312,4 @@ 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]) );
- }
-}
-
#endif
diff --git a/src/chat/chat.h b/src/chat/chat.h
index 86b7c0b..c37bebc 100755
--- a/src/chat/chat.h
+++ b/src/chat/chat.h
@@ -21,7 +21,7 @@ using namespace std;
class chat : public base<room>, public perm
{
private:
- map<string,string> map_replace_strings;
+ map_string map_replace_strings;
vector<string> vec_replace_keys;
public:
@@ -46,10 +46,10 @@ public:
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 );
+ void login( map_string &map_params );
// will be called if a user posts a message.
- void post ( user* u_user, map<string,string> &map_params );
+ void post ( user* u_user, map_string &map_params );
void del_elem( string s_name )
{
@@ -57,6 +57,5 @@ public:
}
void reconf();
- void string_replacer(string *p_msg);
};
#endif
diff --git a/src/chat/room.cpp b/src/chat/room.cpp
index c21639a..b2f17f8 100755
--- a/src/chat/room.cpp
+++ b/src/chat/room.cpp
@@ -9,10 +9,8 @@ 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();
}
@@ -23,9 +21,7 @@ room::~room()
// Delete all user objects
run_func( mtools<user*>::delete_obj );
-#ifdef LOGGING
delete p_logd;
-#endif
pthread_mutex_destroy( &mut_s_topic );
pthread_mutex_destroy( &mut_s_name );
@@ -42,24 +38,15 @@ room::get_topic()
}
void
-room::set_topic( string s_topic )
+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>";
+ 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( "<font color=\"#" + s_color + "\">" + s_topic + "</font>");
-}
-
-void
room::clean_room()
{
pthread_mutex_lock ( &mut_s_topic );
@@ -85,17 +72,13 @@ room::set_name( string s_name )
return;
}
-#ifdef LOGGING
p_logd->flush_logs();
-#endif
if ( 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
}
#endif
diff --git a/src/chat/room.h b/src/chat/room.h
index 255f90e..cc59424 100755
--- a/src/chat/room.h
+++ b/src/chat/room.h
@@ -19,9 +19,7 @@ class room : public base<user>, public name
private:
string s_topic;
pthread_mutex_t mut_s_topic;
-#ifdef LOGGING
logd* p_logd;
-#endif
public:
room( string s_name );
@@ -56,9 +54,7 @@ public:
}
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 );
}
@@ -68,10 +64,9 @@ public:
}
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();
+ virtual string get_topic();
+ virtual void set_topic( string s_topic );
+ virtual void clean_room();
diff --git a/src/chat/sess.cpp b/src/chat/sess.cpp
index 801a6bf..b41c8ce 100755
--- a/src/chat/sess.cpp
+++ b/src/chat/sess.cpp
@@ -3,55 +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()
+sess::get_id()
{
- 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)
-{
- 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 033e954..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 s_id);
~sess();
- string get_tmpid();
-
- void set_user(user* p_user);
- user* get_user();
- void set_name(string s_name);
- string get_name();
+ string get_id();
void invalidate();
};
#endif
diff --git a/src/chat/sman.cpp b/src/chat/sman.cpp
index 6ae665f..464bf24 100755
--- a/src/chat/sman.cpp
+++ b/src/chat/sman.cpp
@@ -19,7 +19,7 @@ sman::~sman()
pthread_mutex_destroy( &mut_i_session_count );
}
-string sman::generate_id( int i_len )
+string sman::generate_id( int len )
{
string valid_chars = wrap::CONF->get_elem("chat.session.validchars");
string s_ret = "";
@@ -27,7 +27,7 @@ string sman::generate_id( int i_len )
srand(time(0)+tool::string2int(wrap::CONF->get_elem("chat.session.kloakkey")));
int i_char;
- for (int i = 0; i < i_len; i++)
+ for (int i = 0; i < len; i++)
{
i_char = rand() % 64;
s_ret += valid_chars[i_char];
@@ -45,9 +45,9 @@ string sman::generate_id( int i_len )
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++;
@@ -56,8 +56,7 @@ sess *sman::create_session( )
#endif
pthread_mutex_unlock( &mut_i_session_count );
- //????
- add_elem( p_sess, s_tmpid );
+ add_elem( p_sess, s_id );
return p_sess;
}
diff --git a/src/chat/sman.h b/src/chat/sman.h
index 20b1a76..1843aec 100755
--- a/src/chat/sman.h
+++ b/src/chat/sman.h
@@ -13,7 +13,7 @@ using namespace std;
class sman : private smap<sess*,string>
{
private:
- string generate_id( int i_len );
+ string generate_id( int len );
int i_session_count;
pthread_mutex_t mut_i_session_count;
@@ -24,10 +24,10 @@ private:
public:
sman();
~sman();
- sess *get_session( string s_tmpid );
+ sess *get_session( string s_id );
int get_session_count( );
sess *create_session( );
- void destroy_session( string s_tmpid );
+ void destroy_session( string s_id );
#ifdef NCURSES
void print_init_ncurses();
#endif
diff --git a/src/chat/user.cpp b/src/chat/user.cpp
index b292a11..a8b48dc 100755
--- a/src/chat/user.cpp
+++ b/src/chat/user.cpp
@@ -97,7 +97,7 @@ user::get_colored_name()
}
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"];
@@ -393,8 +393,8 @@ user::command( string &s_command )
{
check_restore_away();
- unsigned pos = s_command.find( "/" );
- unsigned pos2 = s_command.find( " " );
+ auto unsigned int pos = s_command.find( "/" );
+ auto unsigned int pos2 = s_command.find( " " );
if( pos != string::npos )
{
s_command.replace( pos, 1, "" );
@@ -490,8 +490,6 @@ user::check_timeout( int* i_idle_timeout )
+ "';</script>";
msg_post( &s_quit );
set_online( false );
-
- pthread_cond_signal( &cond_message );
}
else if ( ! get_away() && i_idle_timeout[2] <= i_user_timeout )
@@ -500,7 +498,7 @@ user::check_timeout( int* i_idle_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 );
+ msg_post( &s_msg2 );
get_room()->reload_onlineframe();
}
}
@@ -534,7 +532,7 @@ user::get_user_list( string &s_list )
}
else if ( get_status() != tool::string2int( wrap::CONF->get_elem("chat.defaultrang") ) && ! get_fake() )
{
- string s_status = "rang" + tool::int2string( get_status() );
+ 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='" )
diff --git a/src/chat/user.h b/src/chat/user.h
index 4acb8f0..a88aea7 100755
--- a/src/chat/user.h
+++ b/src/chat/user.h
@@ -34,7 +34,7 @@ private:
string s_pass; // password
room* p_room; // pointer to the user's room.
- map<string,string> map_changed_data; // Needed to tell yChat which data to change after user is removed!
+ 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.
@@ -72,10 +72,10 @@ private:
void clean();
// gets specific data of this user und stores it in
- // (*p_map<string,string>)["nick"]. this method will be used
+ // (*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,string> *p_map_data );
+ void get_data( map_string *p_map_data );
string get_colored_name();
string get_colored_bold_name()