Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Sending Telnet Group Information

Sending Telnet Group Information

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Orik   USA  (182 posts)  Bio
Date Mon 11 Apr 2011 10:16 PM (UTC)
Message
Using Nick's Telnet Negotiation
http://mushclient.com/forum/bbshowpost.php?id=10043&page=11

Last post of the page.

I've been trying to add group information to send to a plugin that will show the miniwindows like the Group Information sent in the post above.

Here's my code:



void
show_group (CHAR_DATA * ch)
{
  char buf[MAX_STRING_LENGTH];

      CHAR_DATA *gch;
      int GroupNum = 0;

   if (WANT_TELNET_INFO (ch))
     {
      for (gch = char_list; gch; gch = gch->next)
        {
          if (gch->deleted)
            continue;
          if (is_same_group (gch, ch))
            {
                GroupNum += 1;
              sprintf (buf, sizeof (buf),
                "\xFF\xFA\x66"
                "tt=\"Tel_Group\";"
                "GroupNum=%d;"
                "name=%s;"
                "hp=%d;"
                "maxhp=%d;"
                "move=%d;"
                "maxmove=%d;",

                       GroupNum,
                       capitalize (PERS (gch, ch)),
                       gch->hit, gch->max_hit,
                       gch->move, gch->max_move
                ); <----LINE 1892

                //finish telnet negotiation after the combat info
                strncpy(&buf [strlen (buf)], "\xFF\xF0", sizeof (buf) - strlen (buf));  // IAC SE
                send_to_char( buf, ch );
            }
        }
        return;
     }
}


And I'm getting this error:


act_comm.c:1892: warning: passing argument 2 of 'sprintf' makes pointer from integer without a cast


I'm not sure if it's the GroupNum causing the warning or the name trying to be sent.

Did I miss something obvious here?
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #1 on Mon 11 Apr 2011 11:11 PM (UTC)
Message
Orik said:
sprintf (buf, sizeof (buf),

sprintf takes a buffer, a format string, and arguments. You are passing it a buffer, a buffer size, a format string, and arguments. Unsurprisingly, gcc complains about passing a size where it expects a format string.

I think you want to use sprintf_s, which is a "safe" version of sprintf() which does accept the buffer size as the second parameter.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #2 on Mon 11 Apr 2011 11:17 PM (UTC)
Message
I used snprintf which is what Nick's show_status function uses in the above linked post. I had made a mistake with the copying of what it said.

I'm sure I'll have more questions later as now I'll start creating the plugin.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #3 on Mon 11 Apr 2011 11:17 PM (UTC)

Amended on Mon 11 Apr 2011 11:19 PM (UTC) by Nick Gammon

Message
Twisol said:

I think you want to use sprintf_s, which is a "safe" version of sprintf() ...


Yeah or snprintf:


    int snprintf(char *str, size_t size, const char *format, ...);



Quote:

Safe version of sprintf(3) of that doesn't suffer from buffer overruns.

int snprintf(char *str, size_t size, const char *format, ...)

Writes output to the string str, under control of the format string format, that specifies how subsequent arguments are converted for output. It is similar to sprintf(3), except that size specifies the maximum number of characters to produce. The trailing nul character is counted towards this limit, so you must allocate at least size characters for str.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #4 on Tue 12 Apr 2011 12:59 AM (UTC)
Message
For some reason this:



   if (WANT_TELNET_INFO (ch))
     {
      for (gch = char_list; gch; gch = gch->next)
        {
          if (gch->deleted)
            continue;
          if (is_same_group (gch, ch))
            {
                GroupNum += 1;
              snprintf (buf, sizeof (buf),
                "\xFF\xFA\x66"
                "tt=\"Tel_Group\";"
                "GroupNum=%d;"
                "name=%s;"
                "hp=%d;"
                "maxhp=%d;"
                "move=%d;"
                "maxmove=%d;",

                       GroupNum,
                       capitalize (PERS (gch, ch)),
                       gch->hit, gch->max_hit,
                       gch->move, gch->max_move
                );


Is not sending the name of the person. It sends everything else but the name. I'm not really sure how else to send the name. Is there a better way to send gch's name?

I tried instead of


capitalize (PERS (gch, ch)),


I used


gch->name


And it still did not work.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #5 on Tue 12 Apr 2011 01:24 AM (UTC)

Amended on Tue 12 Apr 2011 01:25 AM (UTC) by Twisol

Message
This:
"name=%s;"
Should be this:
"name='%s';"


What you are sending is effectively a Lua script. You're interpolating the name into the script. So if the name is Twisol, your script would have name = Twisol. But that's wrong - it treats Twisol as a variable (which most likely has no value). You want name = 'Twisol', so it knows it's a string.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #6 on Tue 12 Apr 2011 01:27 AM (UTC)
Message
Ok, Thanks,

That did it. Now onto the plugin.
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #7 on Tue 12 Apr 2011 12:14 PM (UTC)

Amended on Tue 12 Apr 2011 12:20 PM (UTC) by Orik

Message
Ok, so I'm erroring out on my plugin when I am grouped. It started out as saying I was trying to send a string so I included the tonumber and the ==

Here is some of my plugin


  if tonumber(t.GroupNum) == 2 then
	DoGauge ("%s", t.name, ColourNameToRGB "darkred")
    WindowText (win, FONT_ID_2, string.format ("%s", t.name), 125, 0, 0, 0, ColourNameToRGB "white") 
    WindowText (win, FONT_ID_2, string.format ("%7i/%7i", t.hp, t.maxhp), 125, 11, 0, 0, ColourNameToRGB "white") 
  WindowShow (win, true)
  end --if


Error:

[string "Plugin"]:24: attempt to perform arithmetic on local 'current' (a string value)
stack traceback:
	[string "Plugin"]:24: in function 'DoGauge'
	[string "Plugin"]:146: in function <[string "Plugin"]:122>


The if line is what's breaking me as I'm looking for a number but not sure how to write the if.

GroupNum increases with the party member, so I'm trying to write the health bar per group member. I'm currently sending:


"maxmove"=1240
"chname"="Bob"
"groupname"="Joe"
"move"=1240
"GroupNum"=1
"maxhp"=2149
"hp"=2149
"tt"="Tel_Group"


So chname sends my characters name, groupname sends the group member's name. I want to be able to add in if checks to see how many bars to write out.

I won't need to write my own characters name out since I'll already have a health bar from another plugin.

How would I write out the if part to send:

if GroupNum = 1 then
send 1st group member's info
end

if Groupnum = 2 then
send 2nd group member's info
end

if GroupNum = 3 then
send 3rd Group Member's info
end

etc...

**EDIT**
As I look at it, maybe my doGauge string is messed up somehow as that's what it says in the error. Hmm.

**EDIT2**
It is my DoGauge line. I'll play around with it to see. But I'm thinking the plugin itself is going to need an overhaul to show all group members.
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #8 on Tue 12 Apr 2011 06:58 PM (UTC)
Message
So here is my plugin:


function OnPluginTelnetOption (option)

  local t = {}  -- incoming server variables will go into table t
  setfenv (assert (loadstring (option)), t) () -- compile and load into t
  
  if t.tt ~= "Tel_Group" then
    return
  end
   
   require "tprint"
   tprint (t)


  
  local background_colour = ColourNameToRGB "clear"

  
  -- fill entire box to clear it
  WindowRectOp (win, 2, 0, 0, 0, 0, background_colour)  -- fill entire box

  -- Edge around box rectangle
  WindowCircleOp (win, 3, 0, 0, 0, 0, ColourNameToRGB "clear", 0, 2, 0, 1)
--
  if t.GroupNum == 1 then
	--DoGauge ("HP: ",   t.hp,    t.maxhp,    ColourNameToRGB "darkred")

    WindowText (win, FONT_ID_2, string.format ("%s", t.name), 125, 0, 0, 0, ColourNameToRGB "white") 
    WindowText (win, FONT_ID_2, string.format ("%7i/%7i", t.hp, t.maxhp), 125, 11, 0, 0, ColourNameToRGB "white") 
    WindowShow (win, true)
  else
    WindowShow (win, false)
  end --if

  if t.GroupNum == 2 then
	--DoGauge ("HP: ",   t.hp,    t.maxhp,    ColourNameToRGB "darkred")

    WindowText (win, FONT_ID_2, string.format ("%s", t.name), 125, 0, 0, 0, ColourNameToRGB "white") 
    WindowText (win, FONT_ID_2, string.format ("%7i/%7i", t.hp, t.maxhp), 125, 11, 0, 0, ColourNameToRGB "white") 
    WindowShow (win, true)
  else
    WindowShow (win, false)
  end --if
--

end -- function OnPluginTelnetOption


It's only showing my characters stats rather then my second person in group.

Here's what is being sent:

"maxmove"=1120
"chname"="Bob"
"name"="Joe"
"move"=1120
"GroupNum"=1
"maxhp"=1337
"hp"=1337
"tt"="Tel_Group"
"maxmove"=1040
"chname"="Bob"
"name"="Bob"
"move"=1040
"GroupNum"=2
"maxhp"=2406
"hp"=2406
"tt"="Tel_Group"


And only Bob's stats are showing. It looks like it's completely bypassing the first if statement and going straight for GroupNum 2.

Any thoughts?
Top

Posted by Bast   (78 posts)  Bio
Date Reply #9 on Tue 12 Apr 2011 09:43 PM (UTC)
Message

  if t.GroupNum == 1 then
	--DoGauge ("HP: ",   t.hp,    t.maxhp,    ColourNameToRGB "darkred")

    WindowText (win, FONT_ID_2, string.format ("%s", t.name), 125, 0, 0, 0, ColourNameToRGB "white") 
    WindowText (win, FONT_ID_2, string.format ("%7i/%7i", t.hp, t.maxhp), 125, 11, 0, 0, ColourNameToRGB "white") 
    WindowShow (win, true)
  else
    WindowShow (win, false)
  end --if

  if t.GroupNum == 2 then
	--DoGauge ("HP: ",   t.hp,    t.maxhp,    ColourNameToRGB "darkred")

    WindowText (win, FONT_ID_2, string.format ("%s", t.name), 125, 0, 0, 0, ColourNameToRGB "white") 
    WindowText (win, FONT_ID_2, string.format ("%7i/%7i", t.hp, t.maxhp), 125, 11, 0, 0, ColourNameToRGB "white") 
    WindowShow (win, true)
  else
    WindowShow (win, false)
  end --if


The two WindowText calls for each if are the same.

You are drawing the text in the exact same place each time, so you are overwriting the first one and that is why only Bob shows up.

Bast

Bast

Scripts: http://github.com/endavis
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


31,499 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.