Character Vault
Any Concept / Any System
Compendium
Your System Come To Life
Roll20 for Android
Streamlined for your Tablet
Roll20 for iPad
Streamlined for your Tablet

Personal tools

Difference between revisions of "Script:IsGM Auth Module"

From Roll20 Wiki

Jump to: navigation, search
m (Examples)
(tagged as "discontinued API")
(28 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{script author|104025}}
+
{{deprecated|prod|name=IsGM Auth Module}}
 +
{{script overview
 +
|name=IsGM Auth Module
 +
|author={{user profile|104025|Aaron C. M.}}
 +
|version=0.7
 +
|code=IsGM
 +
|lastmodified=2014-06-14}}
  
This script creates a function, <code>isGM(id)</code>, which is accessible by other scripts to differentiate GM users from non-GM users. GM status is determined by comparing the <code>msg.who</code> from non-API messages to the <code>player._displayname</code>. Since non-API chat messages append " (GM)" to GMs in <code>msg.who</code>, comparing the two will only be equal if a player is NOT a gm. ''(This works regardless of if the player adds '(GM)' to their name.)''
+
'''IsGM Auth Module''' creates a function, <code>isGM(id)</code>, which is accessible by other scripts to differentiate GM users from non-GM users. GM status is determined by comparing the <code>msg.who</code> from non-API messages to the <code>player._displayname</code>. Since non-API chat messages append " (GM)" to GMs in <code>msg.who</code>, comparing the two will only be equal if a player is NOT a gm. ''(This works regardless of if the player adds '(GM)' to their name.)''
  
 
Additionally, the command <code>!reset-isgm</code> is provided, allowing the reset of the GM-status cache, for example if someone is promoted to GM status who had previously been identified as a player.
 
Additionally, the command <code>!reset-isgm</code> is provided, allowing the reset of the GM-status cache, for example if someone is promoted to GM status who had previously been identified as a player.
Line 7: Line 13:
 
=== Syntax ===
 
=== Syntax ===
  
{{syntaxbox top}}
+
{{syntaxbox top|formal=true|IsGM Auth Module}}
 
{{API command|reset-isgm}} {{API parameter|name=password|optional=true}}
 
{{API command|reset-isgm}} {{API parameter|name=password|optional=true}}
 +
{{Formal API command|
 +
{{token|S}} {{rarr}} {{API command|reset-isgm}} {{token|password|-}}
 +
{{token|password}} {{rarr}} {{epsilon}}
 +
{{token|password}} {{rarr}} {{string}}
 +
}}
 
{{syntaxbox end}}
 
{{syntaxbox end}}
  
Line 14: Line 25:
 
{{param description|name=password|value=Password to use when resetting the detected GM status of all players. This parameter is only necessary when calling <code>!reset-isgm</code> as a non-GM user.}}
 
{{param description|name=password|value=Password to use when resetting the detected GM status of all players. This parameter is only necessary when calling <code>!reset-isgm</code> as a non-GM user.}}
 
{{param description bottom}}
 
{{param description bottom}}
 +
 +
{{syntaxbox top|nocat=true}}
 +
isGM(''playerid'')
 +
{{syntaxbox end}}
 +
 +
==== Parameters ====
 +
;playerid
 +
:The id of the player object to check
  
 
==== Examples ====
 
==== Examples ====
Line 31: Line 50:
 
     sendChat('','/w '+msg.who+' you are NOT GM!');
 
     sendChat('','/w '+msg.who+' you are NOT GM!');
 
}</pre>
 
}</pre>
 
=== Code ===
 
 
<pre>var IsGMModule = IsGMModule || {
 
    version: 0.6,
 
    active: true,
 
    reset_password: "swordfish",
 
 
 
    CheckInstall: function() {
 
        var players = findObjs({_type:"player"});
 
 
        if( ! _.has(state,'IsGM') || ! _.has(state.IsGM,'version') || state.IsGM.version != IsGMModule.version )
 
        {
 
            state.IsGM={
 
                version: IsGMModule.version,
 
                gms: [],
 
                players: [],
 
                unknown: []               
 
            };
 
        }
 
        state.IsGM.unknown=_.difference(
 
            _.pluck(players,'id'),
 
            state.IsGM.gms,
 
            state.IsGM.players
 
        );
 
        IsGMModule.active = (state.IsGM.unknown.length>0);
 
    },
 
    IsGM: function(id) {
 
        return _.contains(state.IsGM.gms,id);
 
    },
 
    HandleMessages: function(msg)
 
    {
 
        if(msg.type != "api")
 
        {
 
            if(IsGMModule.active && msg.playerid != 'API')
 
            {
 
                if(_.contains(state.IsGM.unknown, msg.playerid))
 
                {
 
                    var player=getObj('player',msg.playerid);
 
                    if("" == player.get('speakingas') || 'player|'+msg.playerid == player.get('speakingas'))
 
                    {
 
                        if(msg.who == player.get('_displayname'))
 
                        {
 
                            state.IsGM.players.push(msg.playerid);
 
                        }
 
                        else
 
                        {
 
                            state.IsGM.gms.push(msg.playerid);
 
                            sendChat('IsGM','/w gm '+player.get('_displayname')+' is now flagged as a GM.')
 
                        }
 
                        state.IsGM.unknown=_.without(state.IsGM.unknown,msg.playerid);
 
                        IsGMModule.active = (state.IsGM.unknown.length>0);
 
                    }
 
                }
 
            }
 
        }
 
        else
 
        {
 
            var tokenized = msg.content.split(" ");
 
            var command = tokenized[0];
 
            switch(command)
 
            {
 
                case '!reset-isgm':
 
                    if(isGM(msg.playerid) || (tokenized.length>1 && tokenized[1] == isGMModule.reset_password))
 
                    {
 
                        delete state.IsGM;
 
                        IsGMModule.CheckInstall();
 
                        sendChat('IsGM','/w gm IsGM data reset.');
 
                    }
 
                    else
 
                    {
 
                        var who=getObj('player',msg.playerid).get('_displayname').split(' ')[0];
 
                        sendChat('IsGM','/w '+who+' ('+who+')Only GMs may reset the isGM data.'
 
                        +'If you are a GM you can reset by specifying the reset password from'
 
                        +'the top of the IsGM script as an argument to !reset-isgm')
 
                    }
 
                    break;
 
            }
 
        }
 
    },
 
    RegisterEventHandlers: function(){
 
        on('chat:message',IsGMModule.HandleMessages);
 
    },
 
   
 
};
 
 
on('ready',function(){
 
    IsGMModule.CheckInstall();
 
    IsGMModule.RegisterEventHandlers();
 
});
 
     
 
var isGM = isGM || function(id) {
 
    return IsGMModule.IsGM(id);
 
};</pre>
 
  
 
=== Configuration ===
 
=== Configuration ===
Line 130: Line 55:
 
<code>reset_password</code> should be changed from the default. No further customization is required. Do note that the campaign's GM should remember to say something in the chat out of character after installing this script (or running the <code>reset-isgm</code> command) and before making use of any scripts which make use of <code>isGM</code>.
 
<code>reset_password</code> should be changed from the default. No further customization is required. Do note that the campaign's GM should remember to say something in the chat out of character after installing this script (or running the <code>reset-isgm</code> command) and before making use of any scripts which make use of <code>isGM</code>.
  
=== See Also ===
+
=== Changelog ===
 
+
{{changelog version|0.7|2014-06-14|* Release}}
* [https://gist.github.com/shdwjk/8d5bb062abab18463625 GitHub Gist for this script]
+
[[Category:Discontinued API Scripts]]
 
+
[[Category:User API Scripts|IsGM Auth Module]]
+
[[Category:API Commands|reset-isgm]]
+

Revision as of 15:26, 17 June 2020

API ScriptAuthor: Aaron C. M.
Version: 0.7
Last Modified: 2014-06-14
Code: IsGM
Dependencies: None
Conflicts: None

IsGM Auth Module creates a function, isGM(id), which is accessible by other scripts to differentiate GM users from non-GM users. GM status is determined by comparing the msg.who from non-API messages to the player._displayname. Since non-API chat messages append " (GM)" to GMs in msg.who, comparing the two will only be equal if a player is NOT a gm. (This works regardless of if the player adds '(GM)' to their name.)

Additionally, the command !reset-isgm is provided, allowing the reset of the GM-status cache, for example if someone is promoted to GM status who had previously been identified as a player.

Contents

Syntax

!reset-isgm [password]
Formally:

S

→ !reset-isgm password


password

→ ε

password

string
Parameter Values
password Password to use when resetting the detected GM status of all players. This parameter is only necessary when calling !reset-isgm as a non-GM user.
isGM(playerid)

Parameters

playerid
The id of the player object to check

Examples

If you have already been identified as a GM in the campaign, simply using !reset-isgm is enough to reset everyone's GM status. Anyone who knows the password may supply the password as an argument to force the reset regardless of their GM status. For example:

!reset-isgm swordfish

The main feature of the script, however, is the isGm function. This can be called from other scripts to validate users. For example:

if(isGM(msg.playerid))
{
    sendChat('','/w '+msg.who+' you are a GM!');
}
else
{
    sendChat('','/w '+msg.who+' you are NOT GM!');
}

Configuration

reset_password should be changed from the default. No further customization is required. Do note that the campaign's GM should remember to say something in the chat out of character after installing this script (or running the reset-isgm command) and before making use of any scripts which make use of isGM.

Changelog

v0.7 (2014-06-14)

  • Release