hedgewars/uCommands.pas
changeset 5352 7f57d0c7816a
parent 4976 088d40d8aba2
child 5554 b27ed6c6f538
equal deleted inserted replaced
5349:ce527b35d063 5352:7f57d0c7816a
    31 procedure RegisterVariable(Name: shortstring; VType: TVariableType; p: pointer; Trusted: boolean);
    31 procedure RegisterVariable(Name: shortstring; VType: TVariableType; p: pointer; Trusted: boolean);
    32 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
    32 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
    33 procedure StopMessages(Message: Longword);
    33 procedure StopMessages(Message: Longword);
    34 
    34 
    35 implementation
    35 implementation
    36 uses Types, uConsts, uVariables, uConsole, uUtils, uDebug;
    36 uses Types, uConsts, uVariables, uConsole, uUtils, uDebug, uScript;
    37 
    37 
    38 type  PVariable = ^TVariable;
    38 type  PVariable = ^TVariable;
    39       TVariable = record
    39       TVariable = record
    40                      Next: PVariable;
    40                      Next: PVariable;
    41                      Name: string[15];
    41                      Name: string[15];
    66 end;
    66 end;
    67 
    67 
    68 
    68 
    69 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
    69 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
    70 var ii: LongInt;
    70 var ii: LongInt;
    71     s: shortstring;
    71     s, i, o: shortstring;
    72     t: PVariable;
    72     t: PVariable;
    73     c: char;
    73     c: char;
    74 begin
    74 begin
    75 //WriteLnToConsole(CmdStr);
    75 //WriteLnToConsole(CmdStr);
    76 if CmdStr[0]=#0 then exit;
    76 if CmdStr[0]=#0 then exit;
    83 while t <> nil do
    83 while t <> nil do
    84       begin
    84       begin
    85       if t^.Name = CmdStr then
    85       if t^.Name = CmdStr then
    86          begin
    86          begin
    87          if TrustedSource or t^.Trusted then
    87          if TrustedSource or t^.Trusted then
       
    88             begin
       
    89             if (c <> '$') or (s[0] <> #0) then s:= ParseCommandOverride(CmdStr, s);
    88             case t^.VType of
    90             case t^.VType of
    89               vtCommand: if c='/' then
    91               vtCommand: if c='/' then
    90                          begin
    92                          begin
    91                          TCommandHandler(t^.Handler)(s);
    93                          TCommandHandler(t^.Handler)(s);
    92                          end;
    94                          end;
    93               vtLongInt: if c='$' then
    95               vtLongInt: if c='$' then
    94                          if s[0]=#0 then
    96                          if s[0]=#0 then
    95                             begin
    97                             begin
    96                             str(PLongInt(t^.Handler)^, s);
    98                             str(PLongInt(t^.Handler)^, s);
    97                             WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
    99                             i:= inttostr(PLongInt(t^.Handler)^);
    98                             end else val(s, PLongInt(t^.Handler)^);
   100                             o:= ParseCommandOverride(CmdStr, i);
       
   101                             if i <> o then val(o, PLongInt(t^.Handler)^) 
       
   102                             else WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
       
   103                             end 
       
   104                          else val(s, PLongInt(t^.Handler)^);
    99               vthwFloat: if c='$' then
   105               vthwFloat: if c='$' then
   100                          if s[0]=#0 then
   106                          if s[0]=#0 then
   101                             begin
   107                             begin
   102                             //str(PhwFloat(t^.Handler)^:4:6, s);
   108                             //str(PhwFloat(t^.Handler)^:4:6, s);
   103                             WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
   109                             WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
   104                             end else; //val(s, PhwFloat(t^.Handler)^, i);
   110                             end else; //val(s, PhwFloat(t^.Handler)^, i);
   105              vtBoolean: if c='$' then
   111              vtBoolean: if c='$' then
   106                          if s[0]=#0 then
   112                          if s[0]=#0 then
   107                             begin
   113                             begin
   108                             str(ord(boolean(t^.Handler^)), s);
   114                             str(ord(boolean(t^.Handler^)), s);
   109                             WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
   115                             if boolean(t^.Handler^) then i:= '1'
   110                             end else
   116                             else i:= '0';
       
   117                             o:= ParseCommandOverride(CmdStr, i);
       
   118                             if i <> o then 
       
   119                                 begin
       
   120                                 val(o, ii);
       
   121                                 boolean(t^.Handler^):= not (ii = 0)
       
   122                                 end
       
   123                             else WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
       
   124                             end 
       
   125                          else
   111                             begin
   126                             begin
   112                             val(s, ii);
   127                             val(s, ii);
   113                             boolean(t^.Handler^):= not (ii = 0)
   128                             boolean(t^.Handler^):= not (ii = 0)
   114                             end;
   129                             end;
       
   130               end;
   115               end;
   131               end;
   116          exit
   132          exit
   117          end else t:= t^.Next
   133          end else t:= t^.Next
   118       end;
   134       end;
   119 case c of
   135 case c of