Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bot.hpp"
- #include <vector>
- #include <SFML/Network.hpp>
- irc::InternetRelayChat() {}
- irc irc::setServer (std::string server) { this->Server = server; }
- irc irc::setChannels(std::initializer_list<std::string> ChannelList) { this->Channels = ChannelList; }
- irc irc::setNick (std::string nick) { this->Nick = nick; }
- irc irc::setIdent (std::string ident) { this->Ident = ident; }
- irc irc::setRealname(std::string realname) { this->Realname = realname; }
- irc irc::setPort ( int port) { this->Port = port; }
- std::string irc::getServer () { return this->Server; }
- std::vector<std::string> irc::getChannels() { return this->Channels; }
- std::string irc::getNick () { return this->Nick; }
- std::string irc::getIdent () { return this->Ident; }
- std::string irc::getRealname() { return this->Realname; }
- int irc::getPort () { return this->Port; }
- std::string irc::getBuffer () { return this->Buffer; }
- std::size_t irc::getBytes () { return this->BytesReceived; }
- bool irc::connect()
- {
- this->Status = this->Socket.connect(this->Server, this->Port);
- return (this->Status != sf::Socket::Done) ? false : true;
- }
- void irc::ircregister()
- {
- this->send("NICK " + this->Nick);
- this->send("USER " + this->Ident + this->Server + "bla :" + this->Realname);
- }
- void irc::receive()
- {
- char Response[1024];
- this->Socket.receive(Response, 1024, this->BytesReceived);
- this->Buffer = std::string(Response, this->BytesReceived);
- }
- void irc::send (std::string Command) { this->Socket.send(std::string(Command + "\r\n").c_str(), 100); }
- void irc::sendMsg(std::string Channel, std::string Message) { this->send("PRIVMSG " + Channel + " :" + Message); }
- void irc::pong()
- {
- std::vector<std::string> ParsedResponse = this->split(this->Buffer, "\r\n");
- for(auto Iterator : ParsedResponse)
- {
- std::size_t Position = Iterator.find("PING ", 0);
- if(Position != std::string::npos && Position < Iterator.find(':', 1))
- this->send("PONG " + Iterator.substr(Position, Iterator.size() - Position));
- }
- }
- void irc::join()
- {
- }
- std::vector<std::string> irc::split(std::string Content, std::string Delimiter)
- {
- std::size_t Begin = 0;
- std::size_t End = Begin;
- std::vector<std::string> Split;
- while(End != std::string::npos)
- {
- End = Content.find(Delimiter, Begin);
- Split.push_back(Content.substr(Begin, End - Begin));
- Begin = End + Delimiter.length();
- }
- return Split;
- }
Advertisement
Add Comment
Please, Sign In to add comment