Guest User

Untitled

a guest
Apr 21st, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. #include "bot.hpp"
  2.  
  3. #include <vector>
  4.  
  5. #include <SFML/Network.hpp>
  6.  
  7.  
  8. irc::InternetRelayChat() {}
  9.  
  10. irc irc::setServer  (std::string                        server)      { this->Server   = server; }
  11. irc irc::setChannels(std::initializer_list<std::string> ChannelList) { this->Channels = ChannelList; }
  12. irc irc::setNick    (std::string                        nick)        { this->Nick     = nick; }
  13. irc irc::setIdent   (std::string                        ident)       { this->Ident    = ident; }
  14. irc irc::setRealname(std::string                        realname)    { this->Realname = realname; }
  15. irc irc::setPort    (     int                           port)        { this->Port     = port; }
  16.  
  17. std::string              irc::getServer  () { return this->Server; }
  18. std::vector<std::string> irc::getChannels() { return this->Channels; }
  19. std::string              irc::getNick    () { return this->Nick; }
  20. std::string              irc::getIdent   () { return this->Ident; }
  21. std::string              irc::getRealname() { return this->Realname; }
  22.      int                 irc::getPort    () { return this->Port; }
  23. std::string              irc::getBuffer  () { return this->Buffer; }
  24. std::size_t              irc::getBytes   () { return this->BytesReceived; }
  25.  
  26. bool irc::connect()
  27. {
  28.     this->Status = this->Socket.connect(this->Server, this->Port);
  29.     return (this->Status != sf::Socket::Done) ? false : true;
  30. }
  31.  
  32. void irc::ircregister()
  33. {
  34.     this->send("NICK " + this->Nick);
  35.     this->send("USER " + this->Ident + this->Server + "bla :" + this->Realname);
  36. }
  37.  
  38. void irc::receive()
  39. {
  40.     char Response[1024];
  41.     this->Socket.receive(Response, 1024, this->BytesReceived);
  42.     this->Buffer = std::string(Response, this->BytesReceived);
  43. }
  44.  
  45. void irc::send   (std::string Command)                      { this->Socket.send(std::string(Command + "\r\n").c_str(), 100); }
  46. void irc::sendMsg(std::string Channel, std::string Message) { this->send("PRIVMSG " + Channel + " :" + Message); }
  47.  
  48. void irc::pong()
  49. {
  50.     std::vector<std::string> ParsedResponse = this->split(this->Buffer, "\r\n");
  51.  
  52.     for(auto Iterator : ParsedResponse)
  53.     {
  54.         std::size_t Position = Iterator.find("PING ", 0);
  55.  
  56.         if(Position != std::string::npos && Position < Iterator.find(':', 1))
  57.             this->send("PONG " + Iterator.substr(Position, Iterator.size() - Position));
  58.     }
  59. }
  60.  
  61. void irc::join()
  62. {
  63. }  
  64.  
  65. std::vector<std::string> irc::split(std::string Content, std::string Delimiter)
  66. {
  67.     std::size_t              Begin = 0;
  68.     std::size_t              End   = Begin;
  69.     std::vector<std::string> Split;
  70.  
  71.     while(End != std::string::npos)
  72.     {
  73.         End = Content.find(Delimiter, Begin);
  74.         Split.push_back(Content.substr(Begin, End - Begin));
  75.         Begin = End + Delimiter.length();
  76.     }
  77.  
  78.     return Split;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment