<config>


//////////////
//
//  Pulse Protection v0.7a by Pri (23rd of Jan 2011)
//
//////////////
//
//  Commands Included that you can use:
//  None
//
//////////////
//
//  In this version only multi-room alias tracking is included
//  What this script basically does is report your users IP and current Username to my Server
//  Once my Server has that data it reports back to you all the usernames known to be in use by that IP
//  If it has not seen the username your user has used before it will add that name to the list
//
//  Version 0.7a: Fixes a bug where if a user had a # symbol in their name their data would not be sent to the Pulse Server correctly
//                This bug could have resulted in incorrect usernames being reported for users who had a # in their name
//
//  Version 0.6a: Includes Passwords which enables you to secure the data you are reporting to the server
//                What this means is the IPs and Usernames of your users will only be accessible to rooms using the same password as you
//                Which means if you want you can use it just in your own room and not share data with anyone or you can share with your friends
//
//////////////


<OnEnter type="script" mode="thread">
// Clear variable "Private_IP_Detected" for a clean run
<out type="pop" extdata="Private_IP_Detected"/>
// Break if the IP is private (127.0.0.1, 192.168.x.x, 10.0.x.x and so on)
<out type="push" extdata="Joined_IP">:%IP%</out>
<out type="push" extdata="Private_IP_Detected" condition="==" lvalue="%IP%" rvalue="127.0.0.1">1</out>
<out type="push" extdata="Private_IP_Detected" condition="==" lvalue="%IP%" rvalue="0.0.0.0">1</out>
<out type="push" extdata="Private_IP_Detected" condition="==" lvalue="%IP%" rvalue="">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":169.254.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.16.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.17.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.18.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.19.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.20.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.21.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.22.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.23.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.24.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.25.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.26.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.27.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.28.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.29.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.30.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":172.31.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":192.168.">1</out>
<out type="push" extdata="Private_IP_Detected" condition="?" lvalue="%USERVAR[Joined_IP]%" rvalue=":10.">1</out>
<out type="break" condition="==" lvalue="%USERVAR[Private_IP_Detected]%" rvalue="1"></out>
// Check that the scripts folder and settings file has been setup. If it hasn't do it.
<out type="push" extdata="Pulse_Setup_Check"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Pulse.Protection\.Pulse.Protection.ini" lvalue="l" rvalue="1"/></out>
<out condition="==" lvalue="$Pulse_Setup_Check$" rvalue="" type="exec" extdata="1">cmd.exe /c MD C:\Pri.Script.Dependencies\Pulse.Protection</out>
<out condition="==" lvalue="$Pulse_Setup_Check$" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Pulse.Protection\.Pulse.Protection.ini" mode="t">1</out>
// Download some special characters required for this to function (Metis by itself doesn't allow these characters inside the code so they have to be loaded as varibles)
<out type="push" extdata="Special_1" condition="==" lvalue="%USERVAR[Special_1]%" rvalue=""><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/metis.assistant.txt" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Special_3" condition="==" lvalue="%USERVAR[Special_3]%" rvalue=""><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/metis.assistant.txt" lvalue="l" rvalue="3"/></out>
// Check for an updated version of this script
<out type="push" extdata="Version_Info">v0.7a</out>
<out type="pop" extdata="Version_Release_Message"/>
<out type="push" extdata="Version_Check_Date"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Pulse.Protection\.Version.Check.Date.txt" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Version_Info" condition="!=" lvalue="%USERVAR[Version_Check_Date]%" rvalue="%DATE%"><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/version.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Version_Release_Message" condition="!=" lvalue="%USERVAR[Version_Info]%" rvalue="v0.7a"><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/version.ini" lvalue="l" rvalue="2"/></out>
<out condition="!=" lvalue="%USERVAR[Version_Release_Message]%" rvalue="">/opmsg #c4#Pulse Protection #c63#(#c62#v0.7a#c63#): #c9#%USERVAR[Version_Release_Message]%</out>
<out condition="!=" lvalue="%USERVAR[Version_Release_Message]%" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Pulse.Protection\.Version.Check.Date.txt" mode="t">%DATE%\n%USERVAR[Version_Info]%</out>
// Check if a custom Password has been set by the admins of the room for use with Pulse Protections authentication system
<out type="push" extdata="Pulse_Prot_Password"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Pulse.Protection\.password.ini" lvalue="l" rvalue="1"/></out>
// If no password was found use the default
<out type="push" extdata="Pass_generator" condition="==" lvalue="$Pulse_Prot_Password$" rvalue="">%RANDOMNUM[255]%%RANDOMNUM[254]%%RANDOMNUM[253]%%RANDOMNUM[252]%%RANDOMNUM[251]%</out>
// If a random password was generated let the user know what it is
<out condition="==" lvalue="$Pulse_Prot_Password$" rvalue="">/opmsg #c4#Pulse Protection #c63#(#c62#v0.7a#c63#): #c9#A Random Password has been generated for the data you supply to the Server</out>
<out condition="==" lvalue="$Pulse_Prot_Password$" rvalue="">/opmsg #c4#Pulse Protection #c63#(#c62#v0.7a#c63#): #c9#Generated Password#c63#: #c62#%USERVAR[Pass_generator]%</out>
<out condition="==" lvalue="$Pulse_Prot_Password$" rvalue="">/opmsg #c4#Pulse Protection #c63#(#c62#v0.7a#c63#): #c9#Saved in#c63#: #c62#C:\Pri.Script.Dependencies\Pulse.Protection\.password.ini</out>
<out condition="==" lvalue="$Pulse_Prot_Password$" rvalue="">/opmsg #c4#Pulse Protection #c63#(#c62#v0.7a#c63#): #c9#You and your friends can use the same password to share the same database</out>
// Save the Random Password (But of course only if a password isn't present already)
<out condition="==" lvalue="$Pulse_Prot_Password$" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Pulse.Protection\.password.ini" mode="t">%USERVAR[Pass_generator]%\nWhen making a password you can use uppercase and lowercase letters and also numbers, for example H1b0A9sD8mSd8 is an acceptible password.\nTo change your password simply erase the code at the top of this file, change it to something else, and save it.</out>
<out type="push" extdata="Pulse_Prot_Password" condition="==" lvalue="$Pulse_Prot_Password$" rvalue="">%USERVAR[Pass_generator]%</out>
// Sometimes the creation of the Folder for the Setup Check is to slow causing the install check file to not save, so let's just re-attempt that if this is a first time install
<out condition="==" lvalue="$Pulse_Setup_Check$" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Pulse.Protection\.Pulse.Protection.ini" mode="t">1</out>
// Remove colour codes from username
<out type="push" extdata="Cleaned_Name">%NAME%</out>
<out type="push" extdata="Cleaned_Name"><operator type="strrem" lvalue="%USERVAR[Cleaned_Name]%" rvalue="#c?#"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrem" lvalue="%USERVAR[Cleaned_Name]%" rvalue="#c!#"/></out>
<out type="push" extdata="Cleaned_Name_LINE">0</out>
<out type="push" extdata="Cleaned_Name_LINE"><operator type="+" lvalue="$Cleaned_Name_LINE$" rvalue="1"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrem" lvalue="%USERVAR[Cleaned_Name]%" rvalue="#c%USERVAR[Cleaned_Name_LINE]%#"/></out>
<out type="goto" extdata="3" condition="==" lvalue="$Cleaned_Name_LINE$" rvalue="255"></out> 
<out type="goto" extdata="2" condition="!?" lvalue="%USERVAR[Cleaned_Name]%" rvalue="#c"></out> 
<out type="goto" extdata="-4" condition="?" lvalue="%USERVAR[Cleaned_Name]%" rvalue="#c"></out>
// Replace some symbols from the name that just don't work in a httpget request to the web server, and other characters we just don't want saved
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="%USERVAR[Special_1]%lowast;" rvalue="[star]"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="%USERVAR[Special_1]%" rvalue="[and]"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="\" rvalue="[bslash]"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="/" rvalue="[fslash]"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="%USERVAR[Special_3]%" rvalue="[dollar]"/></out>
<out type="push" extdata="Cleaned_Name"><operator type="strrep" nvalue="%USERVAR[Cleaned_Name]%" lvalue="#" rvalue="[hash]"/></out>
// Create a query for checking what usernames this IP is matched to and query mxpulse
<out type="push" extdata="Result"><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/v06/?ip=%IP%%USERVAR[Special_1]%name=%USERVAR[Cleaned_Name]%%USERVAR[Special_1]%pass=%USERVAR[Pulse_Prot_Password]%" lvalue="l" rvalue="2"/></out>
// If the users current name is present remove it
<out type="push" extdata="Result"><operator type="strrem" lvalue="$Result$" rvalue="%USERVAR[Cleaned_Name]%[:@:]"/></out>
// Make the output a little nicer to read / Put some symbols back that were removed for HTTPGET to server
<out type="push" extdata="Result"><operator type="strrem" lvalue="$Result$" rvalue="\"/></out>
<out type="push" extdata="Result"><operator type="strrem" lvalue="$Result$" rvalue="/"/></out>
<out type="push" extdata="Result"><operator type="strrep" nvalue="$Result$" lvalue="[:@:]" rvalue="#c63#,#c62# "/></out>
<out type="push" extdata="Result"><operator type="strrep" nvalue="$Result$" lvalue="[star]" rvalue="%USERVAR[Special_1]%lowast;"/></out>
<out type="push" extdata="Result"><operator type="strrep" nvalue="$Result$" lvalue="[and]" rvalue="%USERVAR[Special_1]%"/></out>
<out type="push" extdata="Result"><operator type="strrep" nvalue="$Result$" lvalue="[bslash]" rvalue="\"/></out>
<out type="push" extdata="Result"><operator type="strrep" nvalue="$Result$" lvalue="[fslash]" rvalue="/"/></out>
<out type="push" extdata="Result"><operator type="strrep" nvalue="$Result$" lvalue="[dollar]" rvalue="%USERVAR[Special_3]%"/></out>
<out type="push" extdata="Result"><operator type="strrep" nvalue="$Result$" lvalue="[hash]" rvalue="#"/></out>
// Output to the room the users aliases unless they don't have any
<out condition="!=" lvalue="$Result$" rvalue="">/opmsg #c4#Pulse Protection #c63#(#c62#v0.7a#c63#): #c9#Also known as#c63#: #c62#%USERVAR[Result]%</out>
</OnEnter>


</config>