Server Help

Bot Questions - Am I doing this right? My first plugin

Quan Chi2 - Sat Aug 06, 2005 8:36 pm
Post subject: Am I doing this right? My first plugin
Im making a plugin of my own. Its nothing too great. Just records staff data, staff updates and stuff.

Code: Show/Hide
   if (c->check("sysop"))
      sendPublic("*getfile sysop.txt");
      ifstream file("sysop.txt");
      char line[256];
      while (file.getline(line, 256))
      {
              if (CMPSTART("MAXBOXES=", line))
              {
                                           MAXBOXES = atoi(&(line[9]));
                                           break;
                                           }
                                           }
                                           
                                           file.close();
             
      }
      if (c->check("mods"))
      sendPublic("*getfile moderator.txt");
      ifstream file("moderator.txt");
      char line[256];
      while (file.getline(line, 256))
      {
              if (CMPSTART("MAXBOXES=", line))
              {
                                        MAXBOXES = atoi(&(line[9]));
                                        break;
                                        }
                                        }
                                       
                                        file.close();
  }
  if (c->("smods"))
  sendPublic("*getfile smod.txt");
  ifstream file("smod.txt");
  char line[256];
  while (file.getline(line 256))
  {
        if (CMPSTART("MATCHBOXES=", line))
                                    MAXBOXES = atoi(&(line[9]));
                                    break;
                                    }
                                    }
                                   
                                    file.close();
}
if (c->check("news"))
sendPublic("?getnews");
}
}
if (c->check("time"))
char u[100];
time_t t=time(NULL);
tm *tmp = localtime(&t);
strftime(u,99,"%c",tmp);
sendPublic("Current date and time: " + u);
}
}



I also made a part that tells the times.. I figured it would be cool. I got it from that wiki site.
lol I wasn't sure of the command for getting the news text. Just correct me if Im wrong please...
Im also now sure how to seperate commands. please help.
Thanx guys!
Underlord - Sat Aug 06, 2005 10:00 pm
Post subject:
1) Downloaded files are put into the \get\ folder *EDITED*

2) You have to wait for them to be downloaded before opening the file. Bot should get a "File received: sysop.txt" when it's sent. You can detect that in spawns.cpp under case EVENT_Chat:, the MSG_Arena case.

3) file.close(); needs to be outside the while () loop.

4) The "if (CMPSTART("MATCHBOXES=", line))" and "MAXBOXES = atoi(&(line[9])); " code obviously isn't applicable to what you are doing.

5) (c->("smods")) should be c->check. } { 's are missing or reversed in several spots.

6) Here's how to seperate commands:
Code: Show/Hide

if (c->check("news"))
{
sendPublic("?getnews");
}

if (c->check("time"))
{
char u[100];
time_t t=time(NULL);
tm *tmp = localtime(&t);
strftime(u,99,"%c",tmp);
sendPublic("Current date and time: " + u);
}

7) You are obviously just copy/pasting things from the tutorial. Creating a bot requires basic programming knowledge.
CypherJF - Sat Aug 06, 2005 10:42 pm
Post subject:
actually, files are uploaded/downloaded to /get/.

LVL files are downloaded to /lvl/.
Quan Chi2 - Sat Aug 06, 2005 10:45 pm
Post subject:
i didnt copy paste... purge helped me..
Purge - Sat Aug 06, 2005 10:46 pm
Post subject:
Not really. I just linked you to the MGB Wiki on that.
50% Packetloss - Sun Aug 07, 2005 12:50 am
Post subject:
Ok, give up now if you don't wish to put in the work to learn the language. That is a pathetic attempt at C++.

Along with all the errors Underlord found,

8) You have not checked if the file was even actually opened by the open() member function (sometimes it fails).

9) Commands are usually seperated by if(...){}else if(...){} statements.

10) char u[100]; sendPublic("Current date and time: " + u); is the fucking stupidest thing I've ever seen. Here is the function prototype, someone who actually understands C will know exactly why you are a retard.
void sendPublic(char *msg);


I suggest you give up now, and preform a post-pregnancy abortion on yourself to save you the trouble of reading anything else I have to say.
Bak - Sun Aug 07, 2005 4:02 am
Post subject:
yeah you want sendPublic("Current date and time: " + (String)u);

instead of sendPublic("Current date and time: " + u);
Maverick - Sun Aug 07, 2005 4:56 am
Post subject:
what im seeing is some attempt to get ahold of the staff files (sysop.txt, smod.txt, etc) with one command. But for the rest, 50% was 100% right icon_smile.gif
Quan Chi2 - Sun Aug 07, 2005 7:32 pm
Post subject:
AH FUCK YOU!

The nerve of you people. Yea, I don't know C++, but I'll be damned if thats going to stop me
Quan Chi2 - Sun Aug 07, 2005 7:33 pm
Post subject:
I'm going to learn C++ from a book. I just haven't brought the book yet from the store. I thought it would be fun to try and code my own bot. SO FUCK YOU FLAMMERS
Bak - Sun Aug 07, 2005 9:35 pm
Post subject:
Don't start with something that elaborate. Start with a message bot, then a warp bot, maybe lvz bot.
50% Packetloss - Sun Aug 07, 2005 9:37 pm
Post subject:
Ok, quan, you are officially crazy. Have a nice day.
Mine GO BOOM - Mon Aug 08, 2005 2:29 am
Post subject:
Bak wrote:
Don't start with something that elaborate. Start with a message bot, then a warp bot, maybe lvz bot.

My first real project, beyond editing the Pro League bot and making a recorder bot, was to create my own bot core, from scratch, and figuring out almost all the packets by printing out packet logs and figuring out what each packet did. Only later when I got to some of the checksums/timers did I need assistance from Ekted.

If you have the time and determined, you can learn and create things pretty fast.
Bak - Mon Aug 08, 2005 3:59 am
Post subject:
you did that without knowing c++ / c / what packets are?
Contempt+ - Mon Aug 08, 2005 12:01 pm
Post subject:
I've been editing catid's biller without knowing C++.

I just looked at the other code, and learn from that.
Mine GO BOOM - Mon Aug 08, 2005 12:05 pm
Post subject:
Bak wrote:
you did that without knowing c++ / c / what packets are?

I learned C++ by trial and error. Seriously. I knew perl, Ghost Ship sent me the source code for the Pro League bots, and I randomly tried things that looked right, and saw if it compiled. As for packets, I had an idea how they are and how big-endian systems stored bytes.

Of course, all this comes back when Ekted yells at me for my coding system, which was learned from random other people's styles.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group