![]() |
Main Page | Namespace List | Alphabetical List | Class List | File List | Class Members | File Members
ServidorSAM.hGo to the documentation of this file.00001 #ifndef _SERVIDORSAM_H 00002 #define _SERVIDORSAM_H 00003 00004 #define MAX_CON_IP 5000 00005 #define MAX_USUARIOS 5000 00006 00007 #include <TcpSocket.h> 00008 #include <IEventOwner.h> 00009 #include <EventHandler.h> 00010 #include <string> 00011 #include <list> 00012 #include <ext/hash_map> 00013 #include <algorithm> 00014 00015 00016 using namespace std; 00017 using namespace __gnu_cxx; 00018 00019 struct Canal; 00020 00021 struct Cliente 00022 { 00023 string nick; 00024 string ip; 00025 bool ping; 00026 int act; 00027 bool adm; 00028 list<Canal>::iterator canal; 00029 00030 bool operator==(const string& c) 00031 { 00032 if(c==this->nick) 00033 return true; 00034 else 00035 return false; 00036 } 00037 }; 00038 00039 struct Canal 00040 { 00041 string nombre; 00042 list<Cliente> usuarios; 00043 00044 bool operator==(const string& nombre) 00045 { 00046 if(nombre==this->nombre) 00047 return true; 00048 else 00049 return false; 00050 } 00051 }; 00052 00053 class MyEventHandler:public EventHandler 00054 { 00055 public: 00056 MyEventHandler(void):EventHandler() 00057 { 00058 } 00059 ~MyEventHandler(void) 00060 { 00061 } 00062 }; 00063 00064 class stringhasher 00065 { 00066 public: 00067 size_t operator() (const string& str) const 00068 { 00069 unsigned int hash = 0; 00070 00071 for(std::size_t i = 0; i < str.length(); i++) 00072 { 00073 hash ^= ((i & 1) == 0) ? ( (hash << 7) ^ str[i] ^ (hash >> 3)) : 00074 (~((hash << 11) ^ str[i] ^ (hash >> 5))); 00075 } 00076 00077 return (hash & 0x7FFFFFFF); 00078 } 00079 00080 bool operator() (const string& s1, const string& s2) const 00081 { 00082 return s1 < s2; 00083 } 00084 }; 00085 00086 class ServidorSAM : public TcpSocket,public IEventOwner 00087 { 00088 private: 00089 static list<Cliente> clientes; 00090 static list<Canal> canales; 00091 static hash_map<string,ServidorSAM*, stringhasher> clt_socket; 00092 static hash_map<string,int,stringhasher> ips; 00093 static list<string> baneados; 00094 static string estado; 00095 static int puerto; 00096 static string pass; 00097 static string ipEscucha; 00098 Cliente c; 00099 public: 00100 ServidorSAM(SocketHandler&); 00101 ~ServidorSAM(); 00102 00103 void OnLine(const string&); 00104 void OnDelete(void); 00105 void OnConnectFailed(void); 00106 void OnException(void); 00107 void OnEvent(int); 00108 00109 static void SetEstado(string est){ estado=est; } 00110 static void SetPuerto(int p){ puerto=p; } 00111 static string GetEstado(void){ return estado; } 00112 static int GetPuerto(void){ return puerto; } 00113 static int GetClientes(void){ return (int)clientes.size(); } 00114 static int GetCanales(void){ return (int)canales.size(); } 00115 static void SetPass(string p){ pass=p; } 00116 static string GetPass(void){ return pass; } 00117 static void SetIpEscucha(string i){ ipEscucha=i; } 00118 static string GetIpEscucha(void){ return ipEscucha; } 00119 static list<string> GetBaneados(void) { return baneados; } 00120 static void PonerBan(string b) { baneados.push_back(b); } 00121 static void QuitarBan(string b) 00122 { 00123 list<string>::iterator r=find(baneados.begin(),baneados.end(),b); 00124 if(r!=baneados.end()) 00125 baneados.erase(r); 00126 } 00127 }; 00128 00129 #endif |