Advertisement
Guest User

DTSBot

a guest
Apr 16th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.09 KB | None | 0 0
  1. //compiling with g++ -std=c++11 main.cpp bot.cpp -o bot -lsfml-system -lsfml-network
  2. // main.cpp
  3. #include <iostream>
  4.  
  5. #include "bot.hpp"
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     irc Bot;
  10.  
  11.     std::cout<<"Connecting..."<< std::endl;
  12.  
  13.     if(Bot.connect())
  14.         std::cout<<"Connected."<< std::endl;
  15.  
  16.     Bot.ircregister();
  17. }
  18.  
  19. //bot.hpp
  20. #ifndef _ROOT_BOT_HPP
  21. #define _ROOT_BOT_HPP
  22.  
  23. #include           <string>
  24. #include           <vector>
  25. #include <initializer_list>
  26.  
  27. #include <SFML/Network.hpp>
  28.  
  29. class InternetRelayChat
  30. {
  31.     public:
  32.         InternetRelayChat();
  33.  
  34.         InternetRelayChat setServer  (std::string);
  35.         InternetRelayChat setChannels(std::initializer_list<std::string>);
  36.         InternetRelayChat setNick    (std::string);
  37.         InternetRelayChat setIdent   (std::string);
  38.         InternetRelayChat setRealname(std::string);#include "bot.hpp"
  39.  
  40. #include <SFML/Network.hpp>
  41.  
  42. #include <cstdarg>
  43.  
  44. irc::InternetRelayChat() { this->Socket.setBlocking(false); }
  45.  
  46. irc irc::setServer  (std::string                        server)      { this->Server   = server; }
  47. irc irc::setChannels(std::initializer_list<std::string> ChannelList) { this->Channels = ChannelList; }
  48. irc irc::setNick    (std::string                        nick)        { this->Nick     = nick; }
  49. irc irc::setIdent   (std::string                        ident)       { this->Ident    = ident; }
  50. irc irc::setRealname(std::string                        realname)    { this->Realname = realname; }
  51. irc irc::setPort    (     int                           port)        { this->Port     = port; }
  52.  
  53. std::string              irc::getServer  () { return this->Server; }
  54. std::vector<std::string> irc::getChannels() { return this->Channels; }
  55. std::string              irc::getNick    () { return this->Nick; }
  56. std::string              irc::getIdent   () { return this->Ident; }
  57. std::string              irc::getRealname() { return this->Realname; }
  58.      int                 irc::getPort    () { return this->Port; }
  59. std::string              irc::getBuffer  () { return this->Buffer; }
  60. std::size_t              irc::getBytes   () { return this->BytesRecieved; }
  61.  
  62. bool irc::connect()
  63. {
  64.     this->Status = this->Socket.connect(this->Server, this->Port);
  65.     return (this->Status != sf::Socket::Done) ? false : true;  
  66. }
  67.  
  68. void irc::ircregister()
  69. {
  70.     this->send("NICK %s", this->Nick.c_str());
  71.     this->send("USER %s %s bla :%s", this->Ident.c_str(), this->Server.c_str(), this->Realname.c_str());
  72. }
  73.  
  74. void irc::receive()
  75. {
  76.     char *buffer;
  77.     this->Socket.receive(buffer, 1024, this->BytesRecieved);
  78.     this->Buffer = (std::string)buffer;
  79. }
  80.  
  81. void irc::send(std::string Format, ...)
  82. {
  83.     va_list     Arguments;
  84.     std::string Command;
  85.    
  86.     va_start(Arguments, Format);
  87.  
  88.     for(char Iterator : Format)
  89.     {
  90.         if(Iterator != '%')
  91.         {
  92.             Command = Command + Iterator;
  93.             continue;
  94.         }
  95.  
  96.         Iterator++;
  97.         Command += (std::string)va_arg(Arguments, char*);        
  98.     }
  99.  
  100.     va_end(Arguments);
  101.  
  102.     this->Socket.send(Command.c_str(), 100);
  103. }
  104.  
  105. void irc::sendMsg(std::string Message, ...)
  106. {
  107. }
  108.  
  109. void irc::pong()
  110. {
  111. }
  112.         InternetRelayChat setPort    (int);
  113.  
  114.         std::string              getServer  ();
  115.         std::vector<std::string> getChannels();
  116.         std::string              getNick    ();
  117.         std::string              getIdent   ();
  118.         std::string              getRealname();
  119.              int                 getPort    ();
  120.         std::string              getBuffer  ();
  121.         std::size_t              getBytes   ();
  122.  
  123.         bool connect    ();
  124.         void ircregister();
  125.         void receive    ();
  126.         void send       (std::string, ...);
  127.         void sendMsg    (std::string, ...);
  128.         void pong       ();
  129.         void join       ();
  130.  
  131.     private:
  132.         std::       string              Server   = "irc.quakenet.org";
  133.         std::       vector<std::string> Channels {"#BotDevGroundZero"};
  134.         std::       string              Nick     = "DTSBot-v0.0.4";
  135.         std::       string              Ident    = "DTSBot";
  136.         std::       string              Realname = "DTSBot";
  137.                     int                 Port     = 6667;
  138.         std::       string              Buffer   = "";
  139.         sf::        TcpSocket           Socket;
  140.         sf::Socket::Status              Status;
  141.         std::       size_t              BytesRecieved;
  142. };
  143.  
  144. typedef InternetRelayChat irc;
  145.  
  146. #endif
  147.  
  148. //bot.cpp
  149. #include "bot.hpp"
  150.  
  151. #include <SFML/Network.hpp>
  152.  
  153. #include <cstdarg>
  154.  
  155. irc::InternetRelayChat() { this->Socket.setBlocking(false); }
  156.  
  157. irc irc::setServer  (std::string                        server)      { this->Server   = server; }#include "bot.hpp"
  158.  
  159. #include <SFML/Network.hpp>
  160.  
  161. #include <cstdarg>
  162.  
  163. irc::InternetRelayChat() { this->Socket.setBlocking(false); }
  164.  
  165. irc irc::setServer  (std::string                        server)      { this->Server   = server; }
  166. irc irc::setChannels(std::initializer_list<std::string> ChannelList) { this->Channels = ChannelList; }
  167. irc irc::setNick    (std::string                        nick)        { this->Nick     = nick; }
  168. irc irc::setIdent   (std::string                        ident)       { this->Ident    = ident; }
  169. irc irc::setRealname(std::string                        realname)    { this->Realname = realname; }
  170. irc irc::setPort    (     int                           port)        { this->Port     = port; }
  171.  
  172. std::string              irc::getServer  () { return this->Server; }
  173. std::vector<std::string> irc::getChannels() { return this->Channels; }
  174. std::string              irc::getNick    () { return this->Nick; }
  175. std::string              irc::getIdent   () { return this->Ident; }
  176. std::string              irc::getRealname() { return this->Realname; }
  177.      int                 irc::getPort    () { return this->Port; }
  178. std::string              irc::getBuffer  () { return this->Buffer; }
  179. std::size_t              irc::getBytes   () { return this->BytesRecieved; }
  180.  
  181. bool irc::connect()
  182. {
  183.     this->Status = this->Socket.connect(this->Server, this->Port);
  184.     return (this->Status != sf::Socket::Done) ? false : true;  
  185. }
  186.  
  187. void irc::ircregister()
  188. {
  189.     this->send("NICK %s", this->Nick.c_str());
  190.     this->send("USER %s %s bla :%s", this->Ident.c_str(), this->Server.c_str(), this->Realname.c_str());
  191. }
  192.  
  193. void irc::receive()
  194. {
  195.     char *buffer;
  196.     this->Socket.receive(buffer, 1024, this->BytesRecieved);
  197.     this->Buffer = (std::string)buffer;
  198. }
  199.  
  200. void irc::send(std::string Format, ...)
  201. {
  202.     va_list     Arguments;
  203.     std::string Command;
  204.    
  205.     va_start(Arguments, Format);
  206.  
  207.     for(char Iterator : Format)
  208.     {
  209.         if(Iterator != '%')
  210.         {
  211.             Command = Command + Iterator;
  212.             continue;
  213.         }
  214.  
  215.         Iterator++;
  216.         Command += (std::string)va_arg(Arguments, char*);        
  217.     }
  218.  
  219.     va_end(Arguments);
  220.  
  221.     this->Socket.send(Command.c_str(), 100);
  222. }
  223.  
  224. void irc::sendMsg(std::string Message, ...)
  225. {
  226. }
  227.  
  228. void irc::pong()
  229. {
  230. }
  231. irc irc::setChannels(std::initializer_list<std::string> ChannelList) { this->Channels = ChannelList; }
  232. irc irc::setNick    (std::string                        nick)        { this->Nick     = nick; }
  233. irc irc::setIdent   (std::string                        ident)       { this->Ident    = ident; }
  234. irc irc::setRealname(std::string                        realname)    { this->Realname = realname; }
  235. irc irc::setPort    (     int                           port)        { this->Port     = port; }
  236.  
  237. std::string              irc::getServer  () { return this->Server; }
  238. std::vector<std::string> irc::getChannels() { return this->Channels; }
  239. std::string              irc::getNick    () { return this->Nick; }
  240. std::string              irc::getIdent   () { return this->Ident; }
  241. std::string              irc::getRealname() { return this->Realname; }
  242.      int                 irc::getPort    () { return this->Port; }
  243. std::string              irc::getBuffer  () { return this->Buffer; }
  244. std::size_t              irc::getBytes   () { return this->BytesRecieved; }
  245.  
  246. bool irc::connect()
  247. {
  248.     this->Status = this->Socket.connect(this->Server, this->Port);
  249.     return (this->Status != sf::Socket::Done) ? false : true;  
  250. }
  251.  
  252. void irc::ircregister()
  253. {
  254.     this->send("NICK %s", this->Nick.c_str());
  255.     this->send("USER %s %s bla :%s", this->Ident.c_str(), this->Server.c_str(), this->Realname.c_str());
  256. }
  257.  
  258. void irc::receive()
  259. {
  260.     char *buffer;
  261.     this->Socket.receive(buffer, 1024, this->BytesRecieved);
  262.     this->Buffer = (std::string)buffer;
  263. }
  264.  
  265. void irc::send(std::string Format, ...)
  266. {
  267.     va_list     Arguments;
  268.     std::string Command;
  269.    
  270.     va_start(Arguments, Format);
  271.  
  272.     for(char Iterator : Format)
  273.     {
  274.         if(Iterator != '%')
  275.         {
  276.             Command = Command + Iterator;
  277.             continue;
  278.         }
  279.  
  280.         Iterator++;
  281.         Command += (std::string)va_arg(Arguments, char*);        
  282.     }
  283.  
  284.     va_end(Arguments);
  285.  
  286.     this->Socket.send(Command.c_str(), 100);
  287. }
  288.  
  289. void irc::sendMsg(std::string Message, ...)
  290. {
  291. }
  292.  
  293. void irc::pong()
  294. {
  295. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement