Logo
~Sockets~
~Examples~
~Contact~


ServidorSAM Class Reference

#include <ServidorSAM.h>

Collaboration diagram for ServidorSAM:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ServidorSAM (SocketHandler &)
 ~ServidorSAM ()
void OnLine (const string &)
void OnDelete (void)
void OnConnectFailed (void)
void OnException (void)
void OnEvent (int)

Static Public Member Functions

static void SetEstado (string est)
static void SetPuerto (int p)
static string GetEstado (void)
static int GetPuerto (void)
static int GetClientes (void)
static int GetCanales (void)
static void SetPass (string p)
static string GetPass (void)
static void SetIpEscucha (string i)
static string GetIpEscucha (void)
static list< string > GetBaneados (void)
static void PonerBan (string b)
static void QuitarBan (string b)

Private Attributes

Cliente c

Static Private Attributes

static list< Clienteclientes = list<Cliente>()
static list< Canalcanales = list<Canal>()
static hash_map< string, ServidorSAM *,
stringhasher
clt_socket = hash_map<string,ServidorSAM*,stringhasher>()
static hash_map< string, int,
stringhasher
ips = hash_map<string,int,stringhasher>()
static list< string > baneados = list<string>()
static string estado = ""
static int puerto = 6667
static string pass = ""
static string ipEscucha = ""

Detailed Description

Definition at line 86 of file ServidorSAM.h.


Constructor & Destructor Documentation

ServidorSAM::ServidorSAM SocketHandler &   ) 
 

Definition at line 21 of file ServidorSAM.cpp.

References c, Cliente::canal, and canales.

00022 :TcpSocket(h),IEventOwner(static_cast<MyEventHandler&>(h))
00023 {
00024         SetLineProtocol();
00025         c.canal=ServidorSAM::canales.end();
00026         static_cast<MyEventHandler&>(Handler()).AddEvent(this,180,0);
00027 }

ServidorSAM::~ServidorSAM  ) 
 

Definition at line 30 of file ServidorSAM.cpp.

00031 {
00032         static_cast<MyEventHandler&>(Handler()).ClearEvents(this);
00033         this->SetFlushBeforeClose();
00034         this->Close();
00035 }


Member Function Documentation

static list<string> ServidorSAM::GetBaneados void   )  [inline, static]
 

Definition at line 119 of file ServidorSAM.h.

References baneados.

Referenced by Comando().

00119 {  return baneados; }

static int ServidorSAM::GetCanales void   )  [inline, static]
 

Definition at line 114 of file ServidorSAM.h.

References canales.

Referenced by Comando().

00114 { return (int)canales.size(); }

static int ServidorSAM::GetClientes void   )  [inline, static]
 

Definition at line 113 of file ServidorSAM.h.

References clientes.

Referenced by Comando().

00113 { return (int)clientes.size(); }

static string ServidorSAM::GetEstado void   )  [inline, static]
 

Definition at line 111 of file ServidorSAM.h.

References estado.

Referenced by Comando().

00111 { return estado; }

static string ServidorSAM::GetIpEscucha void   )  [inline, static]
 

Definition at line 118 of file ServidorSAM.h.

References ipEscucha.

Referenced by Comando(), and main().

00118 { return ipEscucha; }

static string ServidorSAM::GetPass void   )  [inline, static]
 

Definition at line 116 of file ServidorSAM.h.

References pass.

Referenced by Comando().

00116 { return pass; }

static int ServidorSAM::GetPuerto void   )  [inline, static]
 

Definition at line 112 of file ServidorSAM.h.

References puerto.

Referenced by Comando(), and main().

00112 { return puerto; }

void ServidorSAM::OnConnectFailed void   ) 
 

Definition at line 116 of file ServidorSAM.cpp.

References OnDelete().

00117 {
00118         OnDelete();
00119 }

void ServidorSAM::OnDelete void   ) 
 

Definition at line 74 of file ServidorSAM.cpp.

References c, Cliente::canal, canales, clientes, clt_socket, Cliente::ip, ips, and Cliente::nick.

Referenced by OnConnectFailed(), and OnException().

00075 {
00076         if(c.nick.length()>0)
00077         {               
00078                 list<Cliente>::iterator r;
00079                 list<Canal>::iterator c1;
00080                 hash_map<string,int,stringhasher>::iterator ip=ServidorSAM::ips.find(c.ip);
00081                 
00082                 if(ip!=ServidorSAM::ips.end())
00083                         ip->second--;
00084 
00085                 r=find(ServidorSAM::clientes.begin(),ServidorSAM::clientes.end(),c.nick);
00086                 c1=c.canal;
00087                 ServidorSAM::clientes.erase(r);
00088 
00089                 if(c1!=ServidorSAM::canales.end())
00090                 {
00091                         for(r=c1->usuarios.begin();r!=c1->usuarios.end();r++)
00092                         {
00093                                 hash_map<string,ServidorSAM*,stringhasher>::iterator m1;
00094                                 m1=ServidorSAM::clt_socket.find(r->nick);
00095                                 if(m1!=ServidorSAM::clt_socket.end())
00096                                                                 m1->second->Send("273:" + c.nick);
00097                         }
00098                         r=find(c1->usuarios.begin(),c1->usuarios.end(),c.nick);
00099                         c1->usuarios.erase(r);
00100                         if(c1->usuarios.size()==0)
00101                                         ServidorSAM::canales.erase(c1);                                                                                     
00102                 }
00103         }
00104         
00105         hash_map<string,ServidorSAM*,stringhasher>::iterator it=ServidorSAM::clt_socket.find(c.nick);
00106         if(it!=ServidorSAM::clt_socket.end())           
00107                 ServidorSAM::clt_socket.erase(it);
00108         static_cast<MyEventHandler&>(Handler()).ClearEvents(this);
00109 }

void ServidorSAM::OnEvent int   ) 
 

Definition at line 37 of file ServidorSAM.cpp.

References Cliente::act, baneados, c, Cliente::canal, clt_socket, Cliente::ip, Cliente::nick, and Cliente::ping.

00038 {
00039         if(c.act>150)
00040         {
00041                 list<Canal>::iterator c1;
00042                 list<Cliente>::iterator u1;
00043                 
00044                 c1=c.canal;
00045                 for(u1=c1->usuarios.begin();u1!=c1->usuarios.end();u1++)
00046                 {
00047                         hash_map<string,ServidorSAM*,stringhasher>::iterator m1;
00048                         m1=ServidorSAM::clt_socket.find(u1->nick);
00049                         if(m1!=ServidorSAM::clt_socket.end())
00050                                 m1->second->Send("276:" + c.nick);
00051                 }
00052                 ServidorSAM::baneados.push_back(c.ip);
00053                 Send("955:Demasiada actividad!!");
00054                 SetCloseAndDelete();                                    
00055         }
00056         else
00057         {
00058                 if(c.ping==true)
00059                 {
00060                         Send("955:Desconectado por falta de respuesta");                                                
00061                         SetCloseAndDelete();
00062                 }
00063                 else
00064                 if(c.act==0)
00065                 {                                                                                       
00066                         c.ping=true;
00067                         Send("285");                    
00068                 }
00069                 c.act=0;
00070                 static_cast<MyEventHandler&>(Handler()).AddEvent(this,180,0);           
00071         }
00072 }

void ServidorSAM::OnException void   ) 
 

Definition at line 111 of file ServidorSAM.cpp.

References OnDelete().

00112 {
00113         OnDelete();
00114 }

void ServidorSAM::OnLine const string &   ) 
 

static void ServidorSAM::PonerBan string  b  )  [inline, static]
 

Definition at line 120 of file ServidorSAM.h.

References baneados.

Referenced by Comando().

00120 { baneados.push_back(b); }

static void ServidorSAM::QuitarBan string  b  )  [inline, static]
 

Definition at line 121 of file ServidorSAM.h.

References baneados.

Referenced by Comando().

00122         {
00123                 list<string>::iterator r=find(baneados.begin(),baneados.end(),b);
00124                 if(r!=baneados.end())
00125                         baneados.erase(r);      
00126         }

static void ServidorSAM::SetEstado string  est  )  [inline, static]
 

Definition at line 109 of file ServidorSAM.h.

References estado.

Referenced by Comando(), and main().

00109 { estado=est; }

static void ServidorSAM::SetIpEscucha string  i  )  [inline, static]
 

Definition at line 117 of file ServidorSAM.h.

References ipEscucha.

Referenced by Comando(), and main().

00117 { ipEscucha=i; }

static void ServidorSAM::SetPass string  p  )  [inline, static]
 

Definition at line 115 of file ServidorSAM.h.

References pass.

Referenced by Comando(), and main().

00115 { pass=p; }

static void ServidorSAM::SetPuerto int  p  )  [inline, static]
 

Definition at line 110 of file ServidorSAM.h.

References puerto.

Referenced by Comando(), and main().

00110 { puerto=p; }


Member Data Documentation

list< string > ServidorSAM::baneados = list<string>() [static, private]
 

Definition at line 93 of file ServidorSAM.h.

Referenced by GetBaneados(), OnEvent(), PonerBan(), and QuitarBan().

Cliente ServidorSAM::c [private]
 

Definition at line 98 of file ServidorSAM.h.

Referenced by OnDelete(), OnEvent(), and ServidorSAM().

list< Canal > ServidorSAM::canales = list<Canal>() [static, private]
 

Definition at line 90 of file ServidorSAM.h.

Referenced by GetCanales(), OnDelete(), and ServidorSAM().

list< Cliente > ServidorSAM::clientes = list<Cliente>() [static, private]
 

Definition at line 89 of file ServidorSAM.h.

Referenced by GetClientes(), and OnDelete().

hash_map< string, ServidorSAM *, stringhasher > ServidorSAM::clt_socket = hash_map<string,ServidorSAM*,stringhasher>() [static, private]
 

Definition at line 91 of file ServidorSAM.h.

Referenced by OnDelete(), and OnEvent().

string ServidorSAM::estado = "" [static, private]
 

Definition at line 94 of file ServidorSAM.h.

Referenced by GetEstado(), and SetEstado().

string ServidorSAM::ipEscucha = "" [static, private]
 

Definition at line 97 of file ServidorSAM.h.

Referenced by GetIpEscucha(), and SetIpEscucha().

hash_map< string, int, stringhasher > ServidorSAM::ips = hash_map<string,int,stringhasher>() [static, private]
 

Definition at line 92 of file ServidorSAM.h.

Referenced by OnDelete().

string ServidorSAM::pass = "" [static, private]
 

Definition at line 96 of file ServidorSAM.h.

Referenced by GetPass(), and SetPass().

int ServidorSAM::puerto = 6667 [static, private]
 

Definition at line 95 of file ServidorSAM.h.

Referenced by GetPuerto(), and SetPuerto().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2005 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4