<config>


//////////////
//
//  Dynamic Room Adder v0.3 by Pri (26th of May 2012)
//  This script requires Metis v2.82 or Higher & RoboMX v2.08 http://bit.ly/ldk6C3
//  Website: http://www.renmx.com
//  Forum: http://www.mxpulse.com/board
//
///////  COMMANDS
//
//  !ListRoom - Foribly re-send your room to the WPNLister (The script will keep you listed automatically so you shouldn't need to use this)
//  !SetTopic [Topic] - Set your room topic that will appear on the WPNLister
//  !SetUsers [#] - Set the amount of users who are in your room that will appear on the WPNLister
//
///////  SERVER SUPPORT
//
//  WCS, RCS, ZCS, RSWCS, FXServer and Ouka are all supported out of the box
//  Technically this should work with all servers including WinMX
//
//////////////


<command type="script">
<in>!listroom</in>
<in>!botlistroom</in>
<in>!updatetopiclistroom</in>
<in>!updateuserslistroom</in>
// Check that the scripts folder and settings files have been setup. If they haven't then do so.
<out type="push" extdata="DRA_Setup_Check"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Dynamic.Room.Adder.Install.Signature.ini" lvalue="l" rvalue="1"/></out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="" type="exec" extdata="1">cmd.exe /c MD C:\Pri.Script.Dependencies\Dynamic.Room.Adder</out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="" type="sleep" extdata="3000"></out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Dynamic.Room.Adder.Install.Signature.ini" mode="t">1</out>
// Check if the user has supplied their Topic and Users yet, and if not tell them to do it.
<out type="push" extdata="DRA_Setup_Check_Topic"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Topic.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="DRA_Setup_Check_Users"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Users.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="DRA_Setup_Check" condition="==" lvalue="$DRA_Setup_Check_Topic$" rvalue=""></out>
<out type="push" extdata="DRA_Setup_Check" condition="==" lvalue="$DRA_Setup_Check_Users$" rvalue=""></out>
// If this is the first time the script has been run then inform the admins what steps they have to take to make the script function
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#This script has not yet been configured.</out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c4#1. #c9#You need to edit the #c62#Dynamic.Room.Adder.by.Pri.xml #c9#file to add your username so that you can edit settings</out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c4#2. #c9#You then need to type #c62#!SetTopic [Topic] #c9#and tell the bot what your rooms topic is</out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c4#3. #c9#You then need to type #c62#!SetUsers [#] #c9#and tell the bot how many users you want to be shown on the WPNList Page</out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c4#4. #c9#Once the three above steps are done the script will automatically begin listing your room for you, so check the website!</out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c4#5. #c9#Check this page to see if your rooms been listed#c63#: #c62#http://winmxunlimited.net/tools/chat-room-list/winmx-chat-manager/</out>
// Check that the user has the correct version of Metis to run this script by querying my server and checking for a file, if this file doesn't display right tell the user to update
// The reason this code has Pulse in it is because it's just copy and pasted from the Pulse script and it uses less web queries to share the same variable name this way
<out type="push" extdata="Pulse_Metis_Check" condition="==" lvalue="%USERVAR[Pulse_Metis_Check]%" rvalue=""><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/metis.check.ini" lvalue="l" rvalue="1"/></out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#You appear to be running an outdated version of Metis.</out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#You can download the latest one here#c63#: #c62#http://bit.ly/ldk6C3</out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#To install this file replace your old Metis.r2x file located in your script plugins folder</out>
<out type="break" condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849"></out>
// Perform an online check to see if this version of Metis is supported by this script or not
<out type="push" extdata="DynRoomAdr_Script_Compatability_Check" condition="==" lvalue="%USERVAR[DynRoomAdr_Script_Compatability_Check]%" rvalue=""><operator type="readweb" nvalue="http://metis.mxpulse.com/script.compatibility.ini" lvalue="l" rvalue="7"/></out>
// The Dynamic Room Adder requires version 2.82 of Metis at a minimum, if the user is not using this or a higher version tell the admins and break
<out condition="!?" lvalue="%USERVAR[DynRoomAdr_Script_Compatability_Check]%" rvalue="%VERSION%">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#This script requires Metis v2.82 minimum, please upgrade from v%VERSION%#c63#: #c62#http://bit.ly/ldk6C3</out>
<out type="break" condition="!?" lvalue="%USERVAR[DynRoomAdr_Script_Compatability_Check]%" rvalue="%VERSION%"></out>
// Check for an updated version of this script
<out type="push" extdata="Version_Info">v0.3</out>
<out type="pop" extdata="Version_Release_Message"/>
<out type="push" extdata="Version_Check_Date"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.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://dynamic.room.adder.mxpulse.com/version.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Version_Release_Message" condition="!=" lvalue="%USERVAR[Version_Info]%" rvalue="v0.3"><operator type="readweb" nvalue="http://dynamic.room.adder.mxpulse.com/version.ini" lvalue="l" rvalue="2"/></out>
<out condition="!=" lvalue="%USERVAR[Version_Release_Message]%" rvalue="">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#%USERVAR[Version_Release_Message]%</out>
<out condition="!=" lvalue="%USERVAR[Version_Release_Message]%" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Version.Check.Date.txt" mode="t">%DATE%</out>
// Read in the rooms Topic and User Count from files in the Database
<out type="push" extdata="ROOMTOPIC"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Topic.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="ROOMCOUNT"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Users.ini" lvalue="l" rvalue="1"/></out>
<out condition="_?" lvalue="%TRIGGER%" rvalue="!updatetopiclistroom">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c1#Your rooms topic has been updated</out>
<out condition="_?" lvalue="%TRIGGER%" rvalue="!updateuserslistroom">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c1#Your rooms user count has been updated</out>
// Check if the data required to add a room has been supplied by the rooms Admins, if it hasn't break
<out type="break" condition="==" lvalue="$ROOMTOPIC$" rvalue=""></out>
<out type="break" condition="==" lvalue="$ROOMCOUNT$" rvalue=""></out>
// Query mxpulse.com so the site can take your IP Address and encode it for your room name
<out type="push" extdata="Hashcode"><operator type="readweb" nvalue="http://dynamic.room.adder.mxpulse.com/" lvalue="l" rvalue="1"/></out>
<out condition="!_?" lvalue="$Hashcode$" rvalue="[ON]">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#Your room couldn't be added at this time because the Dynamic Room Adder online service is currently offline</out>
<out type="break" condition="!_?" lvalue="$Hashcode$" rvalue="[ON]"></out>
<out type="push" extdata="Hashcode"><operator type="strrem" lvalue="$Hashcode$" rvalue="[ON]"/></out>
// Locate and take the Port Number from the roomname
<out type="push" extdata="String_Length"><operator type="strlen" lvalue="%ROOMNAME%"/></out>
<out type="push" extdata="String_Length_Deduction"><operator type="-" lvalue="%USERVAR[String_Length]%" rvalue="4"/></out>
<out type="push" extdata="Port_Number"><operator type="strright" lvalue="%ROOMNAME%" rvalue="%USERVAR[String_Length_Deduction]%"/></out>
// Remove the entire Hash from the room name
<out type="push" extdata="String_Length_Deduction"><operator type="-" lvalue="%USERVAR[String_Length]%" rvalue="12"/></out>
<out type="push" extdata="Room_Name_Hash"><operator type="strright" lvalue="%ROOMNAME%" rvalue="%USERVAR[String_Length_Deduction]%"/></out>
<out type="push" extdata="Room_Name_Without_Hash"><operator type="strrem" lvalue="%ROOMNAME%" rvalue="$Room_Name_Hash$"/></out>
// Create the final encoding
<out type="push" extdata="ROOMNAME">%USERVAR[Room_Name_Without_Hash]%%USERVAR[Hashcode]%%USERVAR[Port_Number]%</out>
// Replace some characters that are not http friendly
<out type="push" extdata="ROOMNAME"><operator type="strrep" nvalue="%USERVAR[ROOMNAME]%" lvalue="&amp;" rvalue="%26"/></out>
<out type="push" extdata="ROOMNAME"><operator type="strrep" nvalue="%USERVAR[ROOMNAME]%" lvalue="#" rvalue="%23"/></out>
// Send the room to the WPN List
<out type="push" extdata="ReadRequestResult"><operator type="readweb" nvalue="http://winmxunlimited.net/tools/chat-room-list/winmx-chat-manager?roomname=%USERVAR[ROOMNAME]%&amp;usercount=%USERVAR[ROOMCOUNT]%&amp;userlimit=600&amp;topic=%USERVAR[ROOMTOPIC]%&amp;action=add" lvalue="l" rvalue="1"/></out>
// Tell the admin that their room was foribly sent to the WPNList server (or skip if the bot requested the listing)
<out type="goto" extdata="3" condition="_?" lvalue="%TRIGGER%" rvalue="!botlistroom"></out>
<out condition="_?" lvalue="%TRIGGER%" rvalue="!listroom">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c1#Your room has been sent to the WPNLister</out>
<out>/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c62#http://winmxunlimited.net/tools/chat-room-list/</out>
// Push the current hour in to a variable so that we wait a maximum of 60 minutes before trying to relist this room
<out type="push" extdata="Previous_Room_Add_Time">%HOUR%</out>
</command>

<command type="script">
<in>!SetTopic %PARAM%</in>
<in>!SetUsers %PARAM%</in>
// Check if the command was typed at the start of a sentence, if not break
<out type="push" extdata="CMD_REQ">%TRIGGER%</out>
<out type="push" extdata="CMD_REQ"><operator type="strleft" lvalue="$CMD_REQ$" rvalue="4"/></out>
<out type="break" condition="!_?" lvalue="$CMD_REQ$" rvalue="!Set"></out>
// Check if the Metis version is below v2.83 so we know that %USERMODE% works
<out type="push" extdata="Supports_Usermode">1</out>
<out type="push" extdata="Supports_Usermode" condition="?" lvalue="%VERSION%" rvalue="2.80">0</out>
<out type="push" extdata="Supports_Usermode" condition="==" lvalue="%VERSION%" rvalue="2.81">0</out>
<out type="push" extdata="Supports_Usermode" condition="==" lvalue="%VERSION%" rvalue="2.82">0</out>
<out type="goto" extdata="3" condition="!=" lvalue="%USERVAR[Supports_Usermode]%" rvalue="1"></out>
// If the user doesn't have an @ in the User List, tell them they need to login to use this command and break
<out condition="!=" lvalue="%USERMODE%" rvalue="@">#c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#Login and show an #c62#@ #c9#in the userlist to use this command.</out>
<out type="break" condition="!=" lvalue="%USERMODE%" rvalue="@"></out>
// Check that the scripts folder and settings files have been setup. If they haven't then do so.
<out type="push" extdata="DRA_Setup_Check"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Dynamic.Room.Adder.Install.Signature.ini" lvalue="l" rvalue="1"/></out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="" type="exec" extdata="1">cmd.exe /c MD C:\Pri.Script.Dependencies\Dynamic.Room.Adder</out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="" type="sleep" extdata="3000"></out>
<out condition="==" lvalue="$DRA_Setup_Check$" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Dynamic.Room.Adder.Install.Signature.ini" mode="t">1</out>
// Check that the user has the correct version of Metis to run this script by querying my server and checking for a file, if this file doesn't display right tell the user to update
// The reason this code has Pulse in it is because it's just copy and pasted from the Pulse script and it uses less web queries to share the same variable name this way
<out type="push" extdata="Pulse_Metis_Check" condition="==" lvalue="%USERVAR[Pulse_Metis_Check]%" rvalue=""><operator type="readweb" nvalue="http://pulse.protection.mxpulse.com/metis.check.ini" lvalue="l" rvalue="1"/></out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#You appear to be running an outdated version of Metis.</out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#You can download the latest one here#c63#: #c62#http://bit.ly/ldk6C3</out>
<out condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#To install this file replace your old Metis.r2x file located in your script plugins folder</out>
<out type="break" condition="!=" lvalue="$Pulse_Metis_Check$" rvalue="6042117849"></out>
// Perform an online check to see if this version of Metis is supported by this script or not
<out type="push" extdata="DynRoomAdr_Script_Compatability_Check" condition="==" lvalue="%USERVAR[Find_Room_Script_Compatability_Check]%" rvalue=""><operator type="readweb" nvalue="http://metis.mxpulse.com/script.compatibility.ini" lvalue="l" rvalue="7"/></out>
// The Dynamic Room Adder requires version 2.82 of Metis at a minimum, if the user is not using this or a higher version tell the admins and break
<out condition="!?" lvalue="%USERVAR[DynRoomAdr_Script_Compatability_Check]%" rvalue="%VERSION%">/opmsg #c4#Dynamic Room Adder #c63#(#c62#v0.3#c63#): #c9#This script requires Metis v2.82 minimum, please upgrade from v%VERSION%#c63#: #c62#http://bit.ly/ldk6C3</out>
<out type="break" condition="!?" lvalue="%USERVAR[DynRoomAdr_Script_Compatability_Check]%" rvalue="%VERSION%"></out>
// Save the setting that the admin set
<out type="file" mode="t" condition="_?" lvalue="%TRIGGER%" rvalue="!SetTopic " extdata="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Topic.ini">%PARAM%\n</out>
<out type="file" mode="t" condition="_?" lvalue="%TRIGGER%" rvalue="!SetUsers " extdata="C:\Pri.Script.Dependencies\Dynamic.Room.Adder\.Users.ini">%PARAM%\n</out>
// Send a self command activating the service
<out type="self" condition="_?" lvalue="%TRIGGER%" rvalue="!SetTopic ">!updatetopiclistroom</out>
<out type="self" condition="_?" lvalue="%TRIGGER%" rvalue="!SetUsers ">!updateuserslistroom</out>
</command>


<OnLeave type="script">
// Break here if the room has already been sent this hour (Limited to 24 queries per day this way)
<out type="break" condition="==" lvalue="%HOUR%" rvalue="%USERVAR[Previous_Room_Add_Time]%"></out>
<out type="self">!botlistroom</out>
// Push the current hour in to a variable so that we wait a maximum of 60 minutes before trying to relist this room
<out type="push" extdata="Previous_Room_Add_Time">%HOUR%</out>
</OnLeave>


</config>