Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: C++ Bot  (Read 7301 times)

0 Members and 1 Guest are viewing this topic.

Starcloud12

  • Newbie
  • *
  • Posts: 6
    • View Profile
C++ Bot
« on: April 28, 2014, 05:29:43 pm »
Hello. I'm making a bot that will work on a chat network I hang out on. I am mostly working on my own with some help from other bot programmers on that chat network. Unfortunately, the one who knows C++ well hasn't been on recently and I would like to get this bot able to log on by Wednesday. I am not using a console in VS 2008 and can't see what the server tells me as a result and sometimes VS likes to be a pain at times >>'.

So, yeah, I'm posting here in hopes of getting some tips for bots. I'm willing to get any tips I can get since this is the first time I am truly making a bot.

Sorry if this is the wrong section to post this. I'm rusty with forums since I rarely go on them anymore.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: C++ Bot
« Reply #1 on: April 28, 2014, 05:54:23 pm »
IRC Bot? Well how is this related to SFML at all?
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Starcloud12

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: C++ Bot
« Reply #2 on: April 29, 2014, 08:28:28 pm »
IRC Bot? Well how is this related to SFML at all?
It's actually not an IRC Bot. The acronym for the type of bot actually looks like a cuss word. Pretty much, it is supposed to work on the messaging network (aka chatrooms) on an art site that has more than just chats. The bot would only join whatever chatrooms it is supposed to join.

It is related to SFML because I'm using SFML to connect the bot and possibly make the window.

I can post what I have written so far if that would help give a better explanation, though it might include a link.

Aster

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: C++ Bot
« Reply #3 on: April 29, 2014, 08:41:45 pm »
SFML's networking library really isn't suitable for using existing protocols, and writing this stuff in C++ is tedious and difficult. Use Python and its standard library for this kind of stuff. Assuming you can actually find out what the protocol is.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: C++ Bot
« Reply #4 on: April 29, 2014, 08:43:47 pm »
SFML's networking library really isn't suitable for using existing protocols, and writing this stuff in C++ is tedious and difficult. Use Python and its standard library for this kind of stuff. Assuming you can actually find out what the protocol is.

+1

Starcloud12

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: C++ Bot
« Reply #5 on: April 29, 2014, 09:51:05 pm »
I'm not making a python bot because that has been done tons of times. I'm actually using the code for a simple python bot to help me.
I'm taking a class that deals with C++ and my programming friends on the chats want me to make a C++ bot just because.
Also, there is no protocol because the chat network I'm making the bot for is straight text.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: C++ Bot
« Reply #6 on: April 29, 2014, 10:13:53 pm »
Do you have concrete questions?

Otherwise, I'm sure there are better resources than this forum to learn about simple chat bots and protocols. Yes, you do need a protocol whenever you work with networks, even if you apply it implicitly.

By the way, network programming in C++ is really nothing for beginners. If you have just begun to learn the language, that will be difficult to achieve -- at least if you want it to be robust.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Starcloud12

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: C++ Bot
« Reply #7 on: April 29, 2014, 10:26:33 pm »
I am new to SFML and networking, but not to C++. My information about the chat network comes from someone who works for the site and some bot programmers. The current active programmers that are helping me on the chat network do not know C++ that well, so they can only help me so far.
I just really need some tips on using SFML, like maybe how to make a window that does the same work as a C++ console application and then some. How to set the background color for the window. Some generic tips with creating a non-IRC bot that should work on a chat network if anyone has them.
I've posted my code below. If the link in the code is not appropriate, then I will edit it out. This code is a WIP, but does run (even if it does not have a console to cout to).

#include "SFML/Network.hpp"
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"
#include <iostream>
#include <string>
//dA privclass color (188,203,186)

int main(){
        sf::TcpSocket socket;
        sf::Socket::Status status = socket.connect("chat.deviantart.com", 3900);
        if (status != sf::Socket::Done){
                std::cout<<"Error! Socket failed!\n";
                return EXIT_FAILURE;
        }

        std::string message = "dAmnClient 0.3\nagent=Test Client\n\0";
        socket.send(message.c_str(), message.size() + 1);

        char buffer[1024];
        std::size_t recieved = 0;
        socket.receive(buffer, sizeof(buffer), recieved);
        std::cout<<"The server said: "<<buffer<<std::endl;

        sf::TcpListener listener;
        listener.listen(3900);

        listener.accept(socket);
        std::cout<<"New client connected: "<< socket.getRemoteAddress()<<std::endl;

        return 0;
}

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: C++ Bot
« Reply #8 on: April 29, 2014, 10:32:29 pm »
For the SFML part of this, first off read all the tutorials.  They're all very short and simple and you'll probably need just a little bit of each one for this.

The background color for the window is the color you pass to the window.clear() command.  If you don't pass a color it defaults to black.

To simulate a terminal, just use an sf::Text object that fills the whole window.  That class supports \n for newlines so the details should be straightforward.

I have no idea what a generic non-IRC bot would actually consist of ("bot" doesn't mean much without a specific context), so all I can say is it should probably be a class kept separate from all your other classes.  I assume it would have one method taking a string as a command which then returns a string for the terminal to print, though I don't really know your requirements.
« Last Edit: April 29, 2014, 10:35:52 pm by Ixrec »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: C++ Bot
« Reply #9 on: April 29, 2014, 10:34:20 pm »
The official tutorials should already answer many of your questions, read them carefully.

A graphical console can be done with sf::Font, of course you need to handle input and interpret it accordingly.

Networking is usually handled in separate receiver and transmitter threads, at least if you use blocking sockets. You have loops that process incoming and outgoing packets. This is not specific to SFML, by the way, sockets work the same way in many libraries and even programming languages.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Starcloud12

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: C++ Bot
« Reply #10 on: April 30, 2014, 03:26:32 am »
So I looked over the tutorials, as was decided, and decided to add a console back to help me with debugging. My incomplete code has a problem at this part:
        sf::Font font;
        if(!font.loadFromFile("arial.ttf")){
                return -1;
        }
The console complains as follows:
Quote
Failed to load font "arial.ttf" (failed to create the font face)
Press any key to continue...
I know the tutorial talks about loadFromMemory, but I can't figure out what to put for the second argument.

Cirrus Minor

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: C++ Bot
« Reply #11 on: April 30, 2014, 08:21:59 am »
Is the font file "arial.ttf" in the directory where you launch the application ?

Starcloud12

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: C++ Bot
« Reply #12 on: April 30, 2014, 09:54:34 pm »
The background color for the window is the color you pass to the window.clear() command.  If you don't pass a color it defaults to black.
Thank you for giving this tip. It didn't work the first time I tried it (before I came onto here), but your tip made me try it again. This time it was successful.

Is the font file "arial.ttf" in the directory where you launch the application ?
Yep. The tutorial even said that sometimes the loadFromFile fails for some reason.

In other news, I continued working on the bot. It works just fine, save for a few tweaks here and there.

 

anything