mIRC Home    About    Download    Register    News    Help

Print Thread
Identifiers in Commands #256636 05/02/16 02:42 PM
Joined: Jun 2015
Posts: 84
F
Fonic_Artes Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: Jun 2015
Posts: 84
While I know hard coding commands you can write how the identifiers work, but my question is related to using ini files.

To clarify, is it possible to use custom identifiers
Example: !edge <thing, person, item>
$2 has appeared. It is the killer. Do not die.

So my question is, with inifiles is it possible to do that, while not giving the potential of malicious code, I could do the np and let | be considered new lines, but it also leave it open for malicious code still.

I'm guessing it wouldn't without a large amount of extra code, but I thought I'd ask.

My commands code:

Code:
on *:text:!addcom*:#: {
  var %file = data\Commands\commands_ [ $+ [ $mid(#,2) ] ] $+ .ini
  var %opList = $read(data\Operators_List\Op_List_ [ $+ [ $mid(#,2) ] ] $+ .txt, nw, $nick)
  var %head = $mid($2,2)
  if (!%opList) { msg # /me - Only moderators are allowed to add commands. | halt }
  if ($2 == $null) { msg # /me - I can't add a command if there's nothing to add. Syntax to add commands. !addcom <!commandname> -<User Level(mod,owner,blank for all) <response> | halt }
  if (!opList && $3 == -mod) { 
    var %level = Moderator
    writeini -n %file %head command $4-
    writeini -n %file %head level %level
    msg # /me - The command $2 has been added. Level permission - %level
  }

  if (%opList && $3 == -owner) { 
    var %level = Owner
    writeini -n %file %head command $4-
    writeini -n %file %head level %level
    msg # /me - The command $2 has been added. Level permission - %level
  }
  if (%opList && ($3 != -owner) && ($3 != -mod)) {
    var %level = Everyone
    writeini -n %file %head command $3-
    writeini -n %file %head level %level
    msg # /me - The command $2 has been added. Level permission - %level

  }
}
on $*:text:/^!(delcom|remcom)/iS:#: { 
  var %file = data\Commands\commands_ [ $+ [ $mid(#,2) ] ] $+ .ini
  var %command = $mid($2,2)
  var %section = $ini(%file,%command)
  var %opList = $read(data\Operators_List\Op_List_ [ $+ [ $mid(#,2) ] ] $+ .txt, nw, $nick)
  if (!%opList) { msg # /me - You cannot remove commands. | halt }
  if (%opList && (%section == $null)) { msg # /me - This command cannot be removed, as it doesn't exist. | halt }
  if (%opList && (%section != $null)) {
    remini %file %command
    msg # /me - The command $2 has been removed.
  }
}

on *:text:!editcom*:#: {
  var %file = data\Commands\commands_ [ $+ [ $mid(#,2) ] ] $+ .ini
  var %command = $mid($2,2)
  var %returned = $ini(%file,%command)
  var %opList = $read(data\Operators_List\Op_List_ [ $+ [ $mid(#,2) ] ] $+ .txt, nw, $nick)
  var %section = $ini(data\Commands\commands_ [ $+ [ $mid(#,2) ] ] $+ .ini,%returned)
  if (!%opList) { msg # /me - You cannot edit commands. | halt }
  if (%opList && (%returned == $null)) { msg # /me - You cannot this command, it doesn't exist. | halt }
  if (%opList && (%returned != $null)) {
    if (%opList && $3 == -mod) { 
      var %level = Moderator
      writeini -n %file %section command $4-
      writeini -n %file %section level %level
      msg # /me - The command $2 has been updated. Level permission - %level
    }

    if (%opList && $3 == -owner) { 
      var %level = Owner
      writeini -n %file %section command $4-
      writeini -n %file %section level %level
      msg # /me - The command $2 has been edited. Level permission - %level
    }
    if (%opList && ($3 != -owner) && ($3 != -mod)) {
      var %level = $readini(%file,n,%section,level)
      writeini -n %file %section command $3-
      msg # /me - The command $2 has been edited. Level permission - %level
    }
  }
}

on $*:text:/^!.*/iS:#: {
  var %file = data\Commands\commands_ [ $+ [ $mid(#,2) ] ] $+ .ini
  var %command = $mid($1,2)
  var %opList = $read(data\Operators_List\Op_List_ [ $+ [ $mid(#,2) ] ] $+ .txt, nw, $nick)
  var %rCommand = $readini(%file, n,%command,command)
  var %head = $ini(%file,%command)
  var %level = $readini(%file, n,%command,level)
  if ((%level == Moderator || %level == Owner) && !%opList) { .timer 1 1 msg # /me - You cannot use this command. | halt }
  if (%level == Moderator && !%opList) { msg # /me - Only moderators and higher can use this command. | halt }
  if (%level == Owner && $nick != $mid(#,2)) { msg # /me - Only $follow($mid(#,2)) can use this command. | halt }
  if (%level == Moderator && %opList) { msg # %rCommand }
  if (%level == Owner && $nick == $mid(#,2)) { msg # %rCommand }
  if (%level == Everyone) { msg # %rCommand }

}

Re: Identifiers in Commands [Re: Fonic_Artes] #256749 12/02/16 11:59 PM
Joined: Jun 2015
Posts: 84
F
Fonic_Artes Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: Jun 2015
Posts: 84
Re-reading over my question. It seems I didn't specify as much as I thought when I originally posted.

I was wondering if it was possible when reading from a commands inifile that uses the n switch to have identifiers like $2 or $nick actively work without making it compromise the code?

I'm guessing that when it reads I could make it parse the code as a variable and if $2 or $nick or things like that appear do a $replace(%rCommand, $chr(50), $2).

As an example
Code:
if (($chr(50) isin %rCommand)) {
var %xCommand = $replace(%rCommand, $chr(50), $2)
msg # %xCommand
}


Would this example be the closest thing to do it as?

Re: Identifiers in Commands [Re: Fonic_Artes] #256750 13/02/16 12:34 AM
Joined: Dec 2015
Posts: 140
Dazuz Offline
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 140
First of all, I'd recommend using a hash table to store the commands and whatever information that needs to be accessed often.

Secondly, you could always make custom identifiers and use $replace. Let's say you want to use $2 and and $nick, you could do:
Code:
$replacex(my special command that has <2> and <nick>,<2>,$2,<nick>,$nick)

That way you could guarantee that they can only use the identifiers you want them to be able to use, but you'd also have to list all of them. For more complex things you'd have to do some tricks, but at least it would be safer.

You could also try to check all of the $ tokens when adding/editing commands, but something bad could slip through.

Re: Identifiers in Commands [Re: Dazuz] #256751 13/02/16 01:13 AM
Joined: Jan 2004
Posts: 1,282
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,282

Re: Identifiers in Commands [Re: Dazuz] #256756 13/02/16 01:59 PM
Joined: Jun 2015
Posts: 84
F
Fonic_Artes Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: Jun 2015
Posts: 84
Originally Posted By: Dazuz
First of all, I'd recommend using a hash table to store the commands and whatever information that needs to be accessed often.


I haven't learned how to use hash tables entirely yet, but I'll take this advice and keep it in mind for when I get to it and start learning it.