Server Help

Bot Questions - gotCommand does not react

Doggeti - Thu Jul 22, 2004 8:23 am
Post subject: gotCommand does not react
The bot should be able to receive commands via chat channels. I have this code in spawn.cpp:

Code: Show/Hide
case MSG_Channel:
            {
               char *colon;
               char *pointybracket;
               char name[32];
               char text[256];
               char *command = &text[1];

               colon = strstr(msg, ":");
               pointybracket = strstr(msg, ">");

               strncpy(name, colon + 1, pointybracket - colon - 1);
               strcpy(text, pointybracket + 2);

               for (int i = 0; i < strlen(text); i++)
               {
                  text[i] = tolower(text[i]);
               }

               if (strchr(text, '.'))
               {
                  if (strchr(text, '.') - text == 0)
                  {
                     Command c (command);
                     Command *cp = &c;
                     if (strcmp(c.cmd, "help") == 0)
                     {
                        gotHelp(p, cp); // I call it but nothing happens
                     }
                     else
                        gotCommand(p, cp); // I call it but nothing happens
                  }
               }
            }
            break;
         };

Solo Ace - Thu Jul 22, 2004 9:50 am
Post subject:
I'm not sure if you know but...

MERV calls gotRemoteHelp() and gotRemote() (well, depending on what the user does, of course) when a command was used on a chat channel.

It did when I worked with MERV, I doubt it has changed, maybe it's easier to use that instead of using your code. icon_razz.gif
Doggeti - Thu Jul 22, 2004 9:57 am
Post subject:
Ok, I will try it with gotRemoteHelp and gotRemote but why do these commands not react? I mean, all I do is calling the functions gotHelp and gotCommand like any other function. It seems as if spawn.cpp doesn't know these functions.
Solo Ace - Thu Jul 22, 2004 10:04 am
Post subject:
Hmm, run it through a debugger?
Doggeti - Thu Jul 22, 2004 10:24 am
Post subject:
Look what I've found in dllcore.h

Code: Show/Hide
EVENT_Chat,
      /*   Chat message has been received.

         [0] Type
         [1] Sound
         [2] Player class/UNUSED
         [3] Message
      */


UNUSED :/
==> p in gotCommand(p, c); is NULL
==> gotCommand ignores it
50% Packetloss - Thu Jul 22, 2004 10:39 am
Post subject:
Eh? Chat commands that start with a ! @ or . will be considered remote commands because the player may or may not be in the arena or even the zone. So the code does a event_remotecommand or a event_remote help then if you look at those events there is code to call the function. So you wont need to figure out the player's name, it is provided for you. But if you want to make it so your command only works over chat, then the only way to do it is the way you have setup above. The bot doesnt distiguish between remote message types in that event_remotecommand.

make char name[20]; it wont need to be longer
strstr looks for substrings, strchr looks for characters
remember that strchr will return NULL if it doesnt find the desired character, although this should never happen, you should still write code to look out for it

void botInfo::gotHelp(Player *p, Command *c)
1st this takes a Player, so the only way you are going to get a player is if they are in the same arena as the bot. If this is the case, there isnt much of a reason to use chat commands because the player could just PM the bot. Second you can pass C to the function like this, gotCommand(p, &c);

So if you cant get the Player struct for that player, you can still get the Operator_Level. You will need to open the mervbot.ini and get the location of the operators.txt or whatever the file was named. Then open that file to pull out the operators and thier lvls. Mervbot core has all of the source code for doing this. It would be more convient if the core had a function to get the op-lvl of a player, but it doesnt icon_sad.gif. Then if you wish to send a message back to the player, it will need to be sent remotly, there is a function for it in spawn.h
Anonymous - Thu Jul 22, 2004 3:38 pm
Post subject:
Briefly looking at the code I can see two improvements that can be made:
Code: Show/Hide
colon = strstr(msg, ":");
pointybracket = strstr(msg, ">");

/* becomes */
colon = strchr(msg, ':');
pointybracket = strstr(msg, "> ");

You might want to check for NULL being returned as I've seen at least one biller send messages like 'channel created by ...'.
50% Packetloss - Thu Jul 22, 2004 4:38 pm
Post subject:
50% Packetloss wrote:

strstr looks for substrings, strchr looks for characters
remember that strchr will return NULL if it doesnt find the desired character, although this should never happen, you should still write code to look out for it


<3
Anonymous - Thu Jul 22, 2004 5:50 pm
Post subject:
That's one good reason to login before posting, so you can edit your posts :/
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group