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 ➜ MUSHclient ➜ General ➜ Exactly how bad is it to call Simulate instead of ColourNote anyway?

Exactly how bad is it to call Simulate instead of ColourNote anyway?

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


Pages: 1  2 

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #15 on Wed 04 May 2011 08:52 AM (UTC)
Message
Fiendish said:
Wait, do we get to pick how it should work?

I do, I'm writing a client. ~_^

'Soludra' on Achaea

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

Posted by Fiendish   USA  (2,555 posts)  Bio   Global Moderator
Date Reply #16 on Wed 04 May 2011 08:53 AM (UTC)
Message
Twisol said:

Fiendish said:
Wait, do we get to pick how it should work?

I do, I'm writing a client. ~_^
Will it be compatible with MUSHclient scripts? :P
I kid, Nick! I kid!

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Fiendish   USA  (2,555 posts)  Bio   Global Moderator
Date Reply #17 on Wed 04 May 2011 09:12 AM (UTC)

Amended on Wed 04 May 2011 09:13 AM (UTC) by Fiendish

Message
So hold on...Back to what you said earlier:

Quote:
And I think Simulate() will put the line on the very end of the input stream, so your line will actually be out of order. Quite possibly bisecting another line if not all of it made it into the current packet.

So I've been playing around, and I've gone and replaced the series of ColourTell/ColourNote calls with

Simulate(stylesToANSI(styles))

where stylesToANSI does what its name implies. And it appears to be working great for me. Everything is in the right place, and I'm not splitting lines down the middle. Granted I have a fast connection and a fast computer. Are you saying that this will work differently for other people on the same MUD, or is it server dependent, or what? I'm not at all familiar with the packet level of MUD transmission.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #18 on Wed 04 May 2011 09:27 AM (UTC)
Message
Fiendish said:

So hold on...Back to what you said earlier:

Quote:
And I think Simulate() will put the line on the very end of the input stream, so your line will actually be out of order. Quite possibly bisecting another line if not all of it made it into the current packet.

So I've been playing around, and I've gone and replaced the series of ColourTell/ColourNote calls with

Simulate(stylesToANSI(styles))

where stylesToANSI does what its name implies. And it appears to be working great for me. Everything is in the right place, and I'm not splitting lines down the middle. Granted I have a fast connection and a fast computer. Are you saying that this will work differently for other people on the same MUD, or is it server dependent, or what? I'm not at all familiar with the packet level of MUD transmission.


Nick will be able to confirm or deny the inner workings of Simulate, but I'll explain the whole packet transmission thing.

You probably know that MUDs communicate using the Telnet protocol. Hower, Telnet sits on top of TCP, which is a "reliable, stream-based protocol". Stream-based means that you as a user do not deal with packets, you deal with a stream of data. Data you pass to a TCP socket is buffered up, and some/all of that data is sent as a packet. On the other end, incoming packets are buffered up, and you request chunks of data in whatever size you want. This means that if the server sends "Take me to your leader", a variety of things can cause the client to process "Take me to" and " your leader" in separate passes.

Compare this to UDP, which is an unreliable datagram protocol. It doesn't guarantee that data will be received in order, or even at all, and you deal directly with discrete packets of data. However, a datagram is never split up.

When I mentioned bisecting a line, I was talking about part of a line getting processed separately from the rest. If Simulate() appends data to the buffer of data currently being processed, it effectively wedges inbetween two chunks of incoming data. This kills kittens.

When I talked about a Simulate()d line being displayed out of order, I meant that it's very likely that one chunk of data will contain multiple lines. By appending the Simulate()d data to the end of the chunk, you're moving that line past the others.


It's possible that Simulate() has its own, separate buffer that's only processed when there's no more data available, but the vagaries of the 'net makes that an unreliable technique. (Better than the alternative, though - at least it works most of the time.)

'Soludra' on Achaea

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #19 on Wed 04 May 2011 10:29 AM (UTC)

Amended on Wed 04 May 2011 10:30 AM (UTC) by Nick Gammon

Message
Twisol said:

When I talked about a Simulate()d line being displayed out of order, I meant that it's very likely that one chunk of data will contain multiple lines.


I agree with Twisol here.

As a thought experiment, imagine that each character from the MUD arrives separately, possibly separated by minutes of delay. Now in practice it isn't that bad, but when you propose design changes, make sure they are compatible with that model.

- Nick Gammon

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

Posted by Fiendish   USA  (2,555 posts)  Bio   Global Moderator
Date Reply #20 on Wed 04 May 2011 06:46 PM (UTC)

Amended on Wed 04 May 2011 06:48 PM (UTC) by Fiendish

Message
So this all seems very unfortunate for me. I'm reading that it means I can't do what I want to do here.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #21 on Wed 04 May 2011 06:51 PM (UTC)

Amended on Wed 04 May 2011 06:52 PM (UTC) by Twisol

Message
Not built-in, and not the way you wanted to do it, no. There's still the virtualized trigger I suggested before; in fact I wrote and tested it already last night. I was going to finish my stylestring implementation before posting it, but why not:
stylestring = {}

function stylestring.new(str, styles)
  return setmetatable({
    str = str,
    styles = styles,
  }, {
    __index = stylestring,
  })
end

function stylestring.tell(self)
  local str, styles = self.str, self.styles
  local left = 1
  for _,t in pairs(styles) do
    local fg = RGBColourToName(t.textcolour)
    local bg = RGBColourToName(t.backcolour)
    ColourTell(fg, bg, str:sub(left, left + t.length - 1))
    left = left + t.length
  end
end
function stylestring.note(self)
  self:tell()
  AnsiNote() -- not sure if Note() preserves the current color, but I know this does
end

function stylestring.replace(self, match, replace)
  -- TODO: Stretch/shrink styles as needed.
  -- Until then, this is a glorified gsub.
  local str = self.str
  local match_len = match:len()
  
  local left = 1
  local mid = str:find(match)
  while mid do
    if left then
      str = str:sub(left, mid-1) .. replace .. str:sub(mid + match_len)
      left = mid + match_len
    end
    mid = str:find(match, left)
  end
  
  self.str = str
  return self
end

local subs = {}
function add_sub(match, replace)
  table.insert(subs, {
    match = match,
    replace = replace,
  });
end

function do_sub(str)
  for _,t in ipairs(subs) do
    str = str:replace(t.match, t.replace)
  end
  return str
end

function get_subs()
  return subs
end


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   keep_evaluating="y"
   match="^.*$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>local str = stylestring.new("%0", TriggerStyleRuns)
do_sub(str):note()</send>
  </trigger>
</triggers>


<aliases>
  <alias
   match="^\s*#sub\s*{((?:[^}]|\})+)}\s*{((?:[^}]|\})+)}\s*$"
   enabled="y"
   omit_from_log="y"
   regexp="y"
   send_to="12"
   omit_from_output="y"
   ignore_case="y"
   sequence="100"
  >
  <send>add_sub(("%1"):gsub("\\}", "}"), ("%2"):gsub("\\}", "}"))</send>
  </alias>
</aliases>

'Soludra' on Achaea

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #22 on Thu 05 May 2011 04:14 AM (UTC)
Message
Fiendish said:

... one of the first things they ask is "How do I do #sub in MUSHclient?"


Well that is like the people that ask where is Lua's switch statement.

If I may suggest, doing a #sub isn't all that critical. I mean, when you are fighting mobs you don't think "oh I wish I could do a #sub"!

What you *might* think is "I want better stats" or "have I seen this mob before?" or "is that one of my friends?".

So I suggest the emphasis should be pulled back from "how can we #sub?" to "how can we solve the underlying problem?".

Now one thing that springs to mind is making a generic trigger (ie. it matches "*").

Then you feed that trigger into your own matching system that might change A to B, and then C to D and so on.

- Nick Gammon

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

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #23 on Thu 05 May 2011 04:22 AM (UTC)
Message
Nick Gammon said:
Now one thing that springs to mind is making a generic trigger (ie. it matches "*").

Then you feed that trigger into your own matching system that might change A to B, and then C to D and so on.

In other words, what I just implemented. ;)

'Soludra' on Achaea

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #24 on Thu 05 May 2011 04:33 AM (UTC)
Message
Quote:

match="^.*$"


Yeah, exactly like that. :)

- Nick Gammon

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

Posted by Fiendish   USA  (2,555 posts)  Bio   Global Moderator
Date Reply #25 on Sat 07 May 2011 05:22 PM (UTC)
Message
Twisol said:

I was going to finish my stylestring implementation before...

So stylestring is just an object that also contains the non-styled string representation of a style run?

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #26 on Sat 07 May 2011 06:28 PM (UTC)
Message
Well, you could describe it that way. I think of it more as a normal string including style information. You need the whole string in one place to be able to do replacements properly, and I just kind of ignore the 'text' field in each style.

'Soludra' on Achaea

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

Posted by FenceWalker   USA  (8 posts)  Bio
Date Reply #27 on Mon 09 May 2011 05:01 AM (UTC)

Amended on Mon 09 May 2011 05:02 AM (UTC) by FenceWalker

Message
Fiendish said:

Then I think about what the zMUD documentation says about the #substitute command. It says that "Substituted strings are not processed by further triggers".


The documentation for CMUD says the same thing about #sub. However if you were to make a trigger in either CMUD or ZMUD (not sure about the free version I tested in 7.21), that took a string and substituted it with something else. Then made another trigger to fire on the substituted string, you'll see that the documentation for #sub is incorrect. Triggers WILL fire on #sub'ed lines.

Just wanted to correct that small bit of misleading information that is getting quoted from outdated help files.
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.


92,226 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

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.