Multiplayer (Controlling multiple session)

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Multiplayer (Controlling multiple session)

Post by SlySven »

You've included a receive side function. Is pasting it sufficient, or does it also need a registered event handler?
It needs an event handler - it is an event; which can happen at (almost) any-time.
...Put it in a script, and k,error = raiseInterProfileEvent() returned

"raiseInterProfileEvent: missing at least one argument (a string, number, boolean, or nil
expected, got nothing!)..."
I'm trying to update the Lua system functions give meaningful error messages as I have occasion to work on each one...! :)
I changed it to raiseInterProfileEvent("teststring"), and it's now returning 1,nil....
Yes, as it takes a variable (non-zero as you have discovered) number of arguments so the primary return value on success is the number of arguments it processed and sent.
...and modified the script event (example: profileInterLink.received or for that matter profileInterLink are never defined in it.
Um, yes, I cut and pasted and neglected to tweak the code snippet to not include variables declared in a higher level table (profileInterLink) that I was using to count the messages sent and received and the last message.

As Vadi pointed out this event was created separately to the raiseEvent one, because unlike that one that the user / scripter can generate from a profile (and pretty much all the ones that Mudlet sends to to a profile) it is sent (and that is its design intention obviously) between profiles. raiseGlobalEvent is a little shorter I suppose - but it perhaps doesn't obviously suggest (to me, at least) why it is such a different function. OTOH I'm looking at it from an application coding environment where there are a number of events and most are confined to one Host(profile) instance whereas the user/scripter is most likely only looking at sending and receiving the results of raiseEvent with various arguments and the reception of other system events.

For the record the other events that are global or sent to all profiles are the sysIrcMessage and, effectively the sysExitEvent when the Mudlet application is shutdown (although in the case when it asks about whether to save each profile in turn, each profile gets that event before the question is asked so there can be seconds between each profile receiving the event!)

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Multiplayer (Controlling multiple session)

Post by Nyyrazzilyss »

I'd noticed some comment on it on Gitter, so just to mention: That the raising profile also receives the event after all other profiles isn't an error. In a properly designed multiuser system, all profiles (including the raising profile) will need to process the event. It can't however be processed inside the 'raise' code, since it has to be processed after all other profiles have received it.

An individual profile will never -DO- anything directly related to multi-user actions - It raises the event, and does something in response to receiving the event. This allows all profiles to complete the desired result of the event, not just the originating profile.

This is to be able to handle events that only one user (profile) can complete, but two (or more) users attempt to complete -at the exact same time-. Profile A can only complete the event when it receives the event notification it initiated. Profile B also initiates the exact same event request at the exact same time, but it receives notification that profile A wants to complete the event PRIOR to it receiving it's own confirmation of the event = Profile B can't complete (discards) the event

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Multiplayer (Controlling multiple session)

Post by Nyyrazzilyss »

Messy, however to give another example:

5 profiles exist. A+B are both clerics, C,D,E are warriors (that all need to be healed)
A+B are both able to cast.

A+B both raise event to cast heal on C. The events sent out are

A->B, A->C, A->D, A->E, A->A, B->A, B->C, B->D, B->E, B->B

A receives notification to heal C from A. A casts heal on C, and marks C as no longer needing heal.
B receives notification from B to heal C. An event however was previously received indicating A is healing C, so B doesn't. Instead, since C no longer needs heal, it initiates an event to heal D.

C, D, and E would all ignore the event since it's not an action they can take.

Setting up the above would be complex in the lua code, yes, but very much doable.

Saros
Posts: 12
Joined: Sat Oct 15, 2016 10:10 pm

Re: Multiplayer (Controlling multiple session)

Post by Saros »

I wanted to say THANK YOU for this addition, it really makes Mudlet a viable option for us multiplayers!

Using pr337 I've been able to do almost everything... The last piece of this puzzle for me is the ability to change host (profile/session) window focus via code. Is there any chance for this being added as well? From what I gather, 'ctrl-tab' or clicking on the tab is the only way to change window focus.

Again, thank you soooooo much!

Saros
Posts: 12
Joined: Sat Oct 15, 2016 10:10 pm

Re: Multiplayer (Controlling multiple session)

Post by Saros »

Numbers passed through this addition seem to be rounding.
Code: [show] | [select all] lua
function test(...)
	echo("Passed: ")
	display(select(3,...))
end

registerAnonymousEventHandler("sysInterProfileEvent","test")
results in..
lua raiseInterProfileEvent(99999)
Passed: 99999

lua raiseInterProfileEvent(999999)
Passed: 999999

lua raiseInterProfileEvent("1000001")
Passed: 1000000

lua raiseInterProfileEvent("1000009")
Passed: 1000010

lua raiseInterProfileEvent(9999999)
Passed: 10000000

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Multiplayer (Controlling multiple session)

Post by SlySven »

Curious, I recall that the numbers are converted to QStrings to pass them around between profiles, I wonder if we need to explicitly convert them back to doubles rather than allowing whatever conversion happens automagically to do it...?

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Multiplayer (Controlling multiple session)

Post by SlySven »

The proposal has been hacked around a bit and now will likely be called raiseGlobalEvent(...) which will send its arguments to other active profiles but not the sending one. It is much closer to the existing raiseEvent and is no longer tied to a specific event "name". Instead it uses the first argument as the event name (as does raiseEvent), all the subsequent nil/boolean/number or string arguments are passed to the receiver AND THE NAME OF THE SENDER IS APPENDED TO THE END OF THE ARGUMENTS.

This proposed change does mean that one profile can send any event to any other - even if that is not wise - and the receiving profiles' handlers can only tell the difference between an internal, self generated event and one from another profile by the name on the end. If you are planning to use this system (or install a package or module that does) then you will have to ensure that your existing systems and their event handlers can accommodate whatever events that the new module might fire out - you may wish to ensure that all your event generating scripts tag a "self" string argument onto the end of any events that they make and test for this before processing the event in handlers...!

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Multiplayer (Controlling multiple session)

Post by Vadi »

Mudlet now supports multiplaying - see http://www.mudlet.org/2017/05/mudlet-3-1-0. Enjoy!

keythii
Posts: 1
Joined: Tue Aug 22, 2017 9:57 pm
Location: Georgia, USA

Re: Multiplayer (Controlling multiple session)

Post by keythii »

I just tackled this issue personally. I might be an hour done with it. I am sure it could be cleaned up some, or there is a better way of doing it. Here goes
----------------------------------------------------------------
I started with creating an alias ^#(\w+) (.*)$

I coded it with

raiseGlobalEvent("sessionsend", matches[2], matches[3])
--------------------------------------------------------------------------

I then created a script SessionSend() and registered the event sessionsend to it.
the code is:

function SessionSend(arg1, arg2, arg3)

if arg2 == getProfileName() then
send(arg3)
end

end
-- NOTE arg1 is the event raised, arg2 is matches[2] and
-- arg3 is matches[3]
--------------------------------------------------------------------------

this is the simplest form.

An issue I have found with raiseGlobalEvent() is that the sending session does not register the global event (as of 3.4.0) and if one wanted to add an "all" they would need to address this issue in the activating alais.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Multiplayer (Controlling multiple session)

Post by Vadi »

That is intended - you can use raiseEvent() as a follow-up if you want to sending session to get the event as well.

Post Reply