-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCChat.cpp
More file actions
109 lines (81 loc) · 2.37 KB
/
SCChat.cpp
File metadata and controls
109 lines (81 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "SCChat.h"
#include <exception>
using namespace SocketLib;
void SCChat::Handle( string p_data )
{
string name = UserDatabase::find( m_connection )->name;
if( p_data[0] == '/' )
{
string command = BasicLib::ParseWord( p_data, 0 );
string data = BasicLib::RemoveWord( p_data, 0 );
if( command == "/who" )
{
string wholist = magenta + bold + "Who is in the room: ";
UserDatabase::iterator itr = UserDatabase::begin();
while( itr != UserDatabase::end() )
{
wholist += (*itr).name;
++itr;
if( itr != UserDatabase::end() )
{
wholist += ", ";
}
}
wholist += newline;
m_connection->Protocol().SendString( *m_connection, wholist );
}
else if( command == "/quit" )
{
CloseConnection( "has quit. Message: " + data );
m_connection->Close();
m_connection->ClearHandlers();
}
else if (command == "/leave")
{
CloseConnection("has quit. Message: " + data);
m_connection->RemoveHandler();
}
}
else
{
if( BasicLib::TrimWhitespace( p_data ).size() > 0 )
{
SendAll( green + bold + "<" + name + "> " + reset + p_data );
}
}
}
void SCChat::Enter()
{
SendAll( bold + yellow + UserDatabase::find( m_connection )->name +
" has entered the room." );
}
void SCChat::Leave()
{
SendAll(bold + yellow + UserDatabase::find(m_connection)->name +
" has leave the room.");
UserDatabase::DeleteUser( m_connection );
}
void SCChat::Hungup()
{ SendAll( bold + yellow + UserDatabase::find( m_connection )->name +
" has entered the room." );
CloseConnection( "has hung up!" );
}
void SCChat::Flooded()
{
CloseConnection( "has been kicked for flooding!" );
}
void SCChat::CloseConnection( const string& p_reason )
{
SendAll( bold + red + UserDatabase::find( m_connection )->name +
" " + p_reason );
}
void SCChat::SendAll( const string& p_message )
{
UserDatabase::iterator itr = UserDatabase::begin();
// loop through every connection and send the message.
while( itr != UserDatabase::end() )
{
itr->connection->Protocol().SendString( *itr->connection, p_message + newline );
++itr;
}
}