// Constructeur // argument 1 : adresse du serveur // argument 2 : port du serveur // argument 3 : nickname du bot // argument 4 : nom du bot // argument 5 : mot de passe nickserv // argument 6 : tableau des fonctions utilisateurs ConnexionIRC::ConnexionIRC(string arg_host,int arg_port,string arg_nick, string arg_ident, string arg_name, string arg_pass,Fonction *listFonctions) : Connexion(arg_host,arg_port) { string requete; nick=arg_nick; ident=arg_ident; name=arg_name; pass=arg_pass; listFonction= listFonctions; requete = receiveServer(); while (requete.find(" NOTICE ") == string::npos) // On attend une réponse à la connexion au serveur { requete = receiveServer(); } cout << "On est connecté\n"; requete=string("NICK "); requete += string(nick.data()); requete += string("\n"); sendServer(requete); // On envoie notre nickname requete = string("USER ") + ident + string(" localhost ") + host + string(" :") + name + string("\n"); sendServer(requete); // On envoie notre commande d'identification }
int ConnexionIRC::sendIdent() { string buf; buf = "PRIVMSG nickserv :identify " + pass + "\n"; sendServer(buf); // On envoie la commande d'identification auprès du nickserv buf.erase(); return 0; }
void Network::checkTime() { unsigned int time; std::stringstream ss; if ((time =_safeEvents->getTimeToSet()) != 0) { _safeEvents->setTimeToSet(0); ss << "sst " << time << '\n'; sendServer(ss.str()); } }
void neb::app::__net::sendServer(sp::shared_ptr< neb::message::OBase > message) { assert(message); /** @todo wtf */ //neb::std::wrapper wrapper(message); auto buffer = sp::make_shared<gal::net::omessage>(); /** @todo boost serial warning */ //buffer->ar_ << wrapper; sendServer(buffer); }
void THIS::sendServer(std::shared_ptr<neb::fnd::net::msg::Base> m) { assert(m); /** @todo wtf */ gal::stl::wrapper<T> wrapper(std::move(m)); auto buffer = S_MSG(new gal::net::message); buffer->init_output(); /** @todo boost serial warning */ *buffer->get_oar() << wrapper; sendServer(buffer); }
string ConnexionIRC::receiveServer() // Réception des messages { string buf=""; buf.erase(); buf = Connexion::receiveServer(); if (buf==string("")) return string(""); if (buf.substr(0,4)==string("PING")) // Si c'est un message PING on y répond et on boucle sur l'écoute { buf[1]='O'; sendServer(buf); buf.erase(); buf = receiveServer(); } return buf; }
void Network::initConnection() { std::string error; if (!(_pe = getprotobyname(PROTOCOL))) throw ZappyError::SystemError(errno, "Error : GetProto"); if ((_socket = socket(AF_INET, SOCK_STREAM, _pe->p_proto)) == FAIL) throw ZappyError::SystemError(errno, "Error : Socket"); _sockIn.sin_family = AF_INET; _sockIn.sin_port = htons(_port); _sockIn.sin_addr.s_addr = inet_addr(_ip.c_str()); if (connect(_socket, (const struct sockaddr *)&_sockIn, sizeof(_sockIn)) == FAIL) { if (close(_socket) == FAIL) throw ZappyError::SystemError(errno, "Error : Close"); throw ZappyError::SystemError(errno, "Error : Connect"); } _ip = inet_ntoa(_sockIn.sin_addr); sendServer("GRAPHIC\n"); }
/* Ask for all server if they have some thing asked by the msg * and return the result from the first server to have*/ string GerenciadorServidores::askToServers (string msg){ try{ int size = 3; int serverChecked[3] = {1,1,1}; while(size!=0){ int serverId = rand() % 3; if(serverChecked[serverId] == 1){ string res = sendServer(msg,8870+serverId); if(res != "null"){ return res; } serverChecked[serverId] = 0; size--; } } }catch (std::exception& e){ std::cerr << "Exception: askToServers: " << e.what() << "\n"; } return string("null"); }