Server Help

Bot Questions - mervbot and .40

Cheese - Sat Jun 28, 2008 9:35 pm
Post subject: mervbot and .40
if i recall correctly, mervbot uses the old vie subspace protocol, and requires vip to remain connected to a zone...
is there a way to write a plugin/recompile it so it can connect to a .40-required zone without vip?

ive seen some chatnet bots being used in zones like hyperspace, but they only have limited functionality...

also, making a simple prize mod last night, i encountered 2 problems:
Code: Show/Hide

signed int temp6 = 0;
sscanf(c->final, "%d", &temp6);

^if -6 is entered, the default 0 is used... why cant %d handle signed numbers?
result: incapability to prize -greens

Code: Show/Hide

void whatever(int greennum, string playername)
...
//sendPrivate(playername,"*prize #" + (String)greennum); <--didnt work, not p
      sendPublic("priv green");
      _listnode <Player> *parse = playerlist->head;
      while (parse)
      {
         Player *p = parse->item;
   
         if (p->name==playername)
         {
            sendPrivate(p,"*prize #" + (String)greennum);
            sendPrivate(p,"green pm");
            sendPublic("priv green sent");
         }
   
         parse = parse->next;
      }

only sends 'priv green', after the delay, only AFTER someone else has pub'd...
'green pm' or 'priv green sent' is never recieved, nor the prize, even if the name is case sensitive...

everything else about the plugin works flawlessly.

to anyone that cares: i have begun to make merv plugins again...
even though i cant remember anything =)
L.C. - Sat Jun 28, 2008 11:33 pm
Post subject:
For this matter, MERVBot should be rewritten under Snrub's documents (and Starlight, for example). Though I cannot think of any benefits of doing this at the moment.
Cheese - Sun Jun 29, 2008 12:49 am
Post subject:
i was figuring the whole core would need to be modified...

i also found one of the problems:
if (p->name==playername)

even if Cheese was both pname and playername, it wasnt equal. any ideas?
Bak - Sun Jun 29, 2008 12:52 am
Post subject:
you're comparing the address of p->name and the address stored in player name... perhaps you should compare the contents?
Purge - Sun Jun 29, 2008 2:33 am
Post subject:
Use the function strcmp() to compare the contents of both strings.
Cheese - Sun Jun 29, 2008 2:57 am
Post subject:
well, i just fixed it before i read your posts X_x
i ghetto-fix'd it by:
if ((String)p->name==playername)

^_^


but i still cant figure out why sscanf() isnt returning negative numbers...
works well with positive, but does nothing with negatives.
Samapico - Sun Jun 29, 2008 11:42 pm
Post subject:
You should use

if (strcmp(p->name, playername) == 0)

instead.

Also, try not to use both 'string' and 'String' stuff... In MervBot, I usually only use the 'String' class.
Cheese - Mon Jun 30, 2008 3:44 am
Post subject:
well, what if you could somehow spawn a bot into another ip/port using a dll plugin, which would have the cont .40 protocol,and somehow link the two bots together?

i always use 'String', the code here wasnt real, only for effect and demonstrative purposes.
i never really use strcmp, does it compare arrays to strings correctly?
and is it case sensitive?

'but i still cant figure out why sscanf() isnt returning negative numbers...
works well with positive, but does nothing with negatives.'
^this is still true, ive made 3 plugins in 3 nights, and this is the only glaring error to my otherwise spotless plugins...
Samapico - Mon Jun 30, 2008 9:51 am
Post subject:
http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html
All your questions answered tongue.gif
Yes it is case sensitive (just like using == between 2 Strings)

I have a function that might be useful for you; I made it especially to search for a player in the player list, so it ignores case, and can work for partial matches:


Code: Show/Hide

Player* FindPlayerByName(char *name, bool exactmatch, _linkedlist <Player>* list)
{
   _listnode <Player> *parse = list->head;   //set to first link of the player linked list
   Player* bestmatchplayer = NULL;
   int bestmatchlength = 0;
   
   String nametofind = name;
   nametofind.lcase();

   while (parse)   //parse will be NULL when we reach the last link
   {
      Player *p = parse->item;   //item is the actual data stored in the link
      String pname = (String) p->name;
      pname.lcase();

      if (pname == nametofind)
         return p;
      if (!exactmatch)
      {
         int firstdifferent = FirstDifferentCharacter(nametofind, pname);
         if (bestmatchlength < firstdifferent)
         {
            bestmatchlength = firstdifferent;
            bestmatchplayer = p;
         }
      }
      parse = parse->next;   //set parse to the next link
   }
   
   return bestmatchplayer;
}


The playerlist is passed as parameter, but if you use this function inside the botInfo class, you could use playerlist and get rid of that parameter.

Your function would become something like:
Code: Show/Hide

void whatever(int greennum, String playername)
{
   //Find the target player; use 'true' as 2nd parameter if you don't want partial matches (i.e.  "sam" can return the player "Samapico")
   Player * target = FindPlayerByName(playername, false, playerlist);

   if (target != NULL)
   {
        sendPrivate(target, "*prize #" + String(greennum));
   }

}

Cheese - Mon Jun 30, 2008 3:43 pm
Post subject:
but where is FirstDifferentCharacter()? =S
k0zy - Mon Jun 30, 2008 4:07 pm
Post subject:
Cheese wrote:
but where is FirstDifferentCharacter()? =S

http://forums.minegoboom.com/viewtopic.php?p=74429#74429
Samapico - Mon Jun 30, 2008 4:22 pm
Post subject:
doh

lol

what he said
Cheese - Mon Jun 30, 2008 5:01 pm
Post subject:
ill copy it here for future reference =D

Code: Show/Hide

int FirstDifferentCharacter(const char *string1, const char *string2)
{
   int i;
   for (i = 0 ; *string1 != '\0' && *string2 != '\0' && tolower(*string1) == tolower(*string2) ; i++, string1++, string2++)
   {
   }
   return i;
}

All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group