Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance add multi presence support #11

Merged
merged 57 commits into from
Aug 28, 2018

Conversation

SlySven
Copy link

@SlySven SlySven commented Jul 8, 2018

Amalgamation of @SlySven's and @vadi2's work that allow the game to use their own application ID for the rich presence. Adds Lua getters/setters for all Discord functionality.


Changes the following things in the GMCP spec (spec already updated):

  • adds application field to External.Discord.Info
  • if using a custom presenceid in External.Discord.Info, the server SHALL upload an icon of their logo named server-icon in their art assets

The include files are identical and the OSes know which libraries to load
so no need to keep completely separate file-trees for each one's files.

Signed-off-by: Stephen Lyons <[email protected]>
Also adds WoTMUD to the registered MUDs so that it's icon is used
if "wotmud" is the game set.

Signed-off-by: Stephen Lyons <[email protected]>
There is an alternative Discord_Initialize function that does not
have a SteamID which is better suited to Mudlet's use. (We are not
a Steam game)

Signed-off-by: Stephen Lyons <[email protected]>
Slightly incomplete, loading/saving of the presence with the profile needs
clean-up but the lua command to set it and use it works...

Signed-off-by: Stephen Lyons <[email protected]>
@SlySven
Copy link
Author

SlySven commented Jul 8, 2018

I've subsequently found that it won't now compile cleanly on my FreeBSD machine so I will have to add another commit to exclude bits for x86-Linux and FreeBSD platforms...

static int getDiscordLargeIcon(lua_State*);
static int getDiscordLargeIconText(lua_State*);
static int getDiscordSmallIcon(lua_State*);
static int getDiscordSmallIconText(lua_State*);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these functions duplicate the API I've already got?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setXxxx ones work directly on the Rich Presence entry directly and will work with any Presence Id - whereas your fancy 😄 ones can only work with the Mudlet one (which requires, for instance, that there is an icon with the same name as the MUD and that is what is used for the Large icon) - and now throw an nil+error message if that is not the one in use for the given profile.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some more commits pending that:

  • adds the needed conditional compilation for those cases where Discord is not available (32-bit Linux - e.g. x86 Debian; FreeBSD)
  • MIT license entry in the About Dialog
  • fix a bug where I'd forgotten to save the entered Presence Id to the profile
  • fix a bug where the initial opening of the profile when another Presence Id was to be used for that profile was not initializing the remote Discord RP with that Id until the first change was made to any contents.

I have to run them past a Linux platform as well as the Windows one that I was using and check that FreeBSD still works - the last two are okay right now but I hit something late last night and need to resolve it but have some RL stuff I MUST do this morning.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't have two APIs that duplicate each other, that'll be confusing for users and not really smart on our part.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have to merge them somehow - make the existing API work with any presence ID and add the getters.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll busy today so I can't think on a solution for this, could you think of one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your solution is predicated - not unreasonably BTW - on a single large icon for each Mud that Mudlet knows about and has entered into the QMap<Host*, QString>mGamesNames and which is selected when the lua function setDiscordGame is used - however should a MUD want to have a range of icons they cannot do that within your API. Also reporting Playing Mudname in the detail text is not useful when the line above that will already say Mudname in bold - whilst I have tentatively changed it to say via Mudlet (connection state) that is entirely usable to say something else (of course we hope that a Mud Server Discord package might at least mention us but they would not have to...)

💡 It might be possible to replace your four C++ coded functions to ones in lua that call the lower level ones that I have produced - indeed that would mean I could simplify mine... how would that work with the gmcp and other OOB protocols that you are looking to tie into this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would work fine, the game would just transmit the Discord ID as well.

I also think that it's more intuitive to use setDiscordCharacterIcon as a name than setDiscordSmallIcon, it makes more sense no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if you are using the Small Icon for that purpose! Me and Austin (an Immortal of the MUD Server + the Discord Guild owner) on WoTMUD are planning to use the Small Icon to show the Clan affiliation of the character - which would be not used for unclanned and those going incognito. Other MUDs might want to use it to represent what the character is currently doing...

On the whole, for a generic (raw) interface I think a neutral (in this case descriptive) term is a better bet. OTOH For a lua script wrapper that handles things for a specific setup and calls the raw functions, like I think we can convert your API work so far to, it would not be unreasonable to call your function that as part of a cooked interface.

"It would work fine, the game would just transmit the Discord ID as well." - I think I left a commented out suggestion for that in the GMCP code - but I do not know the intricacies of those OOB protocols so cannot be certain it is correct.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you can still use setDiscordCharacterIcon for any icon, it's not like Mudlet is going to validate that the image represents a character 🤣

Okay, let's drop that API though, we'll also have to change the privacy settings to reflect it. Lets go with small icon / large icon and so on.

…atforms

In order to isolate the code from Platforms that do not support Discord
(currently FreeBSD and 32-Bit Linux) I needed to be able to exclude some
parts of the code - and it then made sense to use the same system as has
been adopted for the Ubuntu (and other) fonts and the Updater.

This will prevent inclusion of the Discord code if the Environmental
variable WITH_DISCORD is set to a case insensitive "no" during compilation.

Attempts to make CMake work in this manner was initially tried on Windows but it
seems that the CMake project file is defective in other areas.

Signed-off-by: Stephen Lyons <[email protected]>
This is needed because we distribute the run-time libraries ourselves as
part of the source tarballs.

Signed-off-by: Stephen Lyons <[email protected]>
Also:
* Add/revise tool-tips for Discord controls on Preferences.
* Trim leading/trailing spaces from Discord Presence Id input points.
* Ensure that starting a profile with a non-default Discord Presence Id
  causes that data to be sent to the Discord class to be used before any
  Lua Mudlet events that might include Discord RP code is run.
* Clean up some odds and ends: e.g. some comments and blank lines.

Signed-off-by: Stephen Lyons <[email protected]>
@SlySven
Copy link
Author

SlySven commented Jul 10, 2018

I think this is largely functional now - i.e. if you are willing to merge it in so that others can consider the whole thing back in the main Mudlet#1716.

CMakeLists.txt Outdated
# WITH_DISCORD is an environmental value/variable (so could be a number, a
# string, something else or not even exist).
set(DISCORD_TEST $ENV{WITH_DISCORD})
if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME STREQUAL "Windows") OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want this additional complication in the Makefile and everywhere in the code, I made the Discord support be automatically picked up for this reason - if it works, it'll work, and if it doesn't work, it gets turned off.

Copy link
Author

@SlySven SlySven Jul 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What header file should a FreeBSD build include? Forgive that error - of course it will be the same as every other one as it is a single common file now.

OK, I'll take another look to see if I can get back to just the dynamic loading, and have a look as to why it wasn't working for me on that OS.

To better cope on those platforms where the Discord API will not be
functional the lua functions now report that it is not available whereas
in former version the error message passed to the caller was:
"Discord API is disabled in settings for privacy" which is now only used
when that is indeed the case.

Signed-off-by: Stephen Lyons <[email protected]>
@SlySven
Copy link
Author

SlySven commented Jul 10, 2018

OK, have undone all that conditional compilation. And it still works. 😌 now on FreeBSD. One thing that was confusing was that I was getting lua error messages "Discord API is disabled in settings for privacy" which, of course, is 🐄 💩 in the case where the library cannot be loaded - so I had to insert an additional check of (bool) discord::libraryLoaded() first and instead return "Discord API is not available" in those cases.

So this is now functional...

@vadi2
Copy link
Owner

vadi2 commented Jul 11, 2018

Awesome. Okay lets figure out the new API then, a single one, and how it can relate to the GMCP/MSDP integration as well.

MUDs having their own icons is more complicated, but a superior experience in the end so I think we can cut out the setGame stuff and so on. Will do more thinking on it.

@vadi2
Copy link
Owner

vadi2 commented Jul 11, 2018

See #11 (comment)

@SlySven
Copy link
Author

SlySven commented Jul 11, 2018

You know I am getting more attracted to Discord as we go on, and remember how reticent I was about it at first! 🤷‍♂️

@SlySven
Copy link
Author

SlySven commented Jul 11, 2018

"Awesome. Okay lets figure out the new API then, a single one, and how it can relate to the GMCP/MSDP integration as well."

Would you be willing to pull this into your PR as it is now then we will have a test-bed (and CI builds) to compare and contrast a further PRs onto it as I pull out your C++ API and make the bits I put in simpler and somehow we put together a dicord.lua module to implement the same stuff that your parts did?

@SlySven
Copy link
Author

SlySven commented Jul 12, 2018

DO you want to merge this into your PR - and I can submit new stuff (sans your TLuaInterpreter API functions and with a simplified Discord infrastructure) - or shall we close that and I could squash down all the work so far and open a new PR on the Main Repo working on it?

@vadi2
Copy link
Owner

vadi2 commented Jul 12, 2018

I don't see a need for a discord.lua and I'm confused by the duplication that was added in this PR, so I don't want to merge it, and I definitely don't want another duplicate PR in the main repository either.

A little bit of upfront communication would have helped avoid this problem...

But now that we have it lets resolve the issues in this PR, I don't want to be resolving issues in the main PR because as far as I can see that is ready to go in its current state.

@SlySven
Copy link
Author

SlySven commented Jul 12, 2018

Well, the setDiscordGame, setDiscordArea, setDiscordCharacter and setDiscordCharacterIcon could all be provided in an external lua file - like the DB.lua... TableUtils.lua are - however that would be hard to link to the controls in the "Special Options" tab in the "Preferences" in the same way.

I suppose it would be possible to prevent some features from being activated {show character name, icon, server Url} if a profile using them is copied (so that duplicating a profile to one with a different name would not copy the enabled features but instead by comparing the getProfileName() to a stored value in a discord table the script could tell they are not in the same profile any more and would want to be activated again). I guess that could sort of provide the same protection against accidentally revealing details...

@vadi2
Copy link
Owner

vadi2 commented Jul 12, 2018

But why would we have setDiscordGame, setDiscordArea, setDiscordCharacter and setDiscordCharacterIcon defined in Lua when the problem is that we have duplicate functionality for doing the same thing? Moving it out to Lua would still give the users duplicate functionality. Let's remove it entirely, that solves the problem.

@SlySven
Copy link
Author

SlySven commented Jul 12, 2018

🤕 humm what do we do with the four functions you have put forward and coded though? Once we commit the main PR to the development branch we cannot take them away again and as things are with this PR the current line up is:

  • (1) setDiscordGame - equivalent to a call to (7), (9) and (10) with some additional glue that includes a call to (6).
  • (2) setDiscordArea - equivalent to a call to (8) with some additional glue that includes a call to (6) and a check to see that it is enabled.
  • (3) setDiscordCharacter - equivalent to a call to (12) or (10) with a call to (6) and some other checks on various permissions and the absence of a game name set by (1).
  • (4) setDiscordCharacterIcon - equivalent to a call to (11) or (9) with a call to (6) and some other checks on various permissions and the absence of a game name set by (1).

as it stands, my proposal adds:

  • (5) setDiscordPresenceId
  • (6) isUsingDefaultDiscordPresenceId

with these setters

  • (7) setDiscordDetailText
  • (8) setDiscordStateText
  • (9) setDiscordLargeIcon
  • (10) setDiscordLargeIconText
  • (11) setDiscordSmallIcon
  • (12) setDiscordSmallIconText

and getters:

  • (13) getDiscordDetailText
  • (14) getDiscordStateText
  • (15) getDiscordLargeIcon
  • (16) getDiscordLargeIconText
  • (17) getDiscordSmallIcon
  • (18) getDiscordSmallIconText

One observation is that the form of all those setters and getters is the same so we could reduce the number of functions needed back down to 8 by replacing them with a pair: setDiscordItem(<itemNameString>, <itemValueString>) and getDiscordItem(<itemValueString>). This would make the interface a little more complex but reduce the maintenance burden - and the number of functions to document - would this be acceptable to yourself?

@vadi2
Copy link
Owner

vadi2 commented Jul 12, 2018

what do we do with the four functions you have put forward and coded though?

Delete them

by replacing them with a pair

No, better this way for autocompletion and documentation.

@SlySven
Copy link
Author

SlySven commented Jul 12, 2018

In response to your last post that I didn't see until after my last one:

The issue is not quite one of duplication, your code does work but, because it does several things {and not unreasonably (I can't say they are unreasonable - I was one of those asking for them!) applies some user permissions before some of those things because they could reveal more detail than the user or the MUD they are playing would want} and is tied to one method of using the Discord RP.

The additions from me can do those things but is not tied to that model (one icon for the Mud for the Large Icon based on a list held in Mudlet if the game is a known one and putting the image otherwise destined for the Small one there if it is not; putting the Mud name and optionally the URL in the Large icon; calling the Small icon the "Character" unless it is made into the large one because the given value for that does not appear in a list).

@vadi2
Copy link
Owner

vadi2 commented Jul 12, 2018

We can't have these two different models from two different coders confusing our users and being a headache to ourselves because people are confused. Like I have been banging all along, we have to merge them together, or get rid of one. I'm not sure how to say this otherwise, I've stressed it a lot already. 😞

User permissions must be there with either model that is used.

@SlySven
Copy link
Author

SlySven commented Jul 12, 2018

🗡️ 😊 I am sorry I did not realise you were giving me permission to nuke your lua ones. What about the OOB code? Though I guess that will be up to the MUD Server operator to make sure they do not do anything stupid with the OOB data they send...

@vadi2
Copy link
Owner

vadi2 commented Jul 12, 2018

The OOB code should be translated to use your functions.

@SlySven
Copy link
Author

SlySven commented Jul 12, 2018

Okay, I'll see what I can do - I am sorry if this is causing anyone any stress, but I guess it is better to get this sorted out before we commit stuff into the wild...

@vadi2
Copy link
Owner

vadi2 commented Jul 13, 2018

Yep. The privacy toggles should also be changed to small text / large text and so on, so the user has the option of blocking OOB data (or Lua data from a 3rd party script) from being displayed against their will.

@SlySven
Copy link
Author

SlySven commented Aug 25, 2018

Re: Improve readability for the username pinning tooltip i.e. d946773

This makes the tool-tip for the discriminator (the 4 digit number appended to the user name) read:

Mudlet will only show Rich Presence information while you use this Discord username (useful if you have multiple Discord accounts). Leave empty to show it for any Discord account you log in to.

this seems confusing because the number is handled separately by Discord but the users may not realise it - the wording "this Discord username" just does not fit right here, IMHO.

Also the tooltip is a little miss-leading I think , in that: if either the username OR the discriminator are provided then as soon as Mudlet works out what is being used (it seems to happen very quickly) and finds out that there is a miss-match then it will stop any further settable actions for this profile (although the current values remain readable).

Drifting a little off-topic but IIRC from testing, having a mismatch does indeed stop the RP from being setup/used for this profile but if multi-playing then other profiles that do not have a mismatch will function as normal - indeed that is one of the goals of this, switching between two profile's one with a match and one without will show the RP for the matching Profile as if it was the only profile, though, admittedly, only when it is the active one will changes it makes be actively updated to the RP.

@SlySven
Copy link
Author

SlySven commented Aug 26, 2018

Reviewing the revisions you have made to the Profile Preferences controls which has them say "Hide Xxxx" doesn't actually match up I think to what the flags are doing currently. They do not hide the individual parts of the RP - they just prevent the MUD server controlling them, as they were (at least as I had it) still accessible (provided the Lua access control was enabled) to the Lua system and could be controlled by that means.

So, saying that they "hide" the parts of the RP actually means (or at least, I think it does) "hides from control over GMCP" currently.

The checkbox "Disable game Discord Info" is still a master control but because it has been demoted from a groupbox around the other controls it is not at all obvious that if it is checked then the other controls have no effect... 🙁

@vadi2
Copy link
Owner

vadi2 commented Aug 26, 2018

leave a blank line after the conditions and before the first line of code in the then block

Could you make a PR for .clang-format to discuss that separately?

@vadi2
Copy link
Owner

vadi2 commented Aug 26, 2018

There are two straight-forward ways to do that as I see it:

  1. is complicated, especially since we don't and can't track what is third party and what isn't. If someone copy/pastes an alias from forums into Mudlet, is it third party? Complicated to answer and not workable.
  2. honour system for privacy is a no-go.

I'll go with my original solution: per-option privacy toggles apply to both server and Lua side.

@vadi2
Copy link
Owner

vadi2 commented Aug 26, 2018

So, saying that they "hide" the parts of the RP actually means (or at least, I think it does) "hides from control over GMCP" currently.

I intend them to be a hide from everything, including Lua.

@vadi2
Copy link
Owner

vadi2 commented Aug 28, 2018

These were two different things - the first, controlled by a checkbox on the connection enable/disable all Discord functionaluity for the profile concerned; the second was a master control of whether the MUD Server could via GMCP

That's not true - as the name implies (mDiscordDisableServerSide), the first is also for the server functionality only. I'll remove the flag duplicate.

@vadi2 vadi2 force-pushed the Enhance_addMultiPresenceSupport branch from d6e375d to 0437f06 Compare August 28, 2018 05:56
We don't chat in Discord presences but in Discord servers
What you register in Discord is an application, not a presence. Application is also a much more intuitive name.
Detail and state can't be anything other than text.
@vadi2
Copy link
Owner

vadi2 commented Aug 28, 2018

While working on this, I realised we can have a privacy leak where the user has disabled a certain server function (like the detail) but the Lua API can still read it - so scripts have access to this info. I'll expand the privacy options to cover the get* functions.

@vadi2
Copy link
Owner

vadi2 commented Aug 28, 2018

What is the idea behind all of the complex engineering in deduceGameName()?

@vadi2 vadi2 merged commit 8a025d9 into vadi2:add-basic-gamekit Aug 28, 2018
@vadi2
Copy link
Owner

vadi2 commented Aug 28, 2018

Please direct all future discussion to Mudlet#1716.

@SlySven SlySven deleted the Enhance_addMultiPresenceSupport branch August 30, 2018 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants