hedgewars/uCommands.pas
changeset 7407 c1ade666c124
parent 6992 b8f3d8991e92
child 7409 fd91aa100ce0
equal deleted inserted replaced
7406:1fe2c821f9bf 7407:c1ade666c124
    25 var isDeveloperMode: boolean;
    25 var isDeveloperMode: boolean;
    26 type TCommandHandler = procedure (var params: shortstring);
    26 type TCommandHandler = procedure (var params: shortstring);
    27 
    27 
    28 procedure initModule;
    28 procedure initModule;
    29 procedure freeModule;
    29 procedure freeModule;
       
    30 procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean; Synced: boolean);
    30 procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean);
    31 procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean);
    31 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
    32 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
    32 procedure ParseTeamCommand(s: shortstring);
    33 procedure ParseTeamCommand(s: shortstring);
    33 procedure StopMessages(Message: Longword);
    34 procedure StopMessages(Message: Longword);
    34 
    35 
    35 implementation
    36 implementation
    36 uses uConsts, uVariables, uConsole, uUtils, uDebug;
    37 uses uConsts, uVariables, uConsole, uUtils, uDebug, SDLh;
    37 
    38 
    38 type  PVariable = ^TVariable;
    39 type  PVariable = ^TVariable;
    39     TVariable = record
    40     TVariable = record
    40         Next: PVariable;
    41         Next: PVariable;
    41         Name: string[15];
    42         Name: string[15];
    42         Handler: TCommandHandler;
    43         Handler: TCommandHandler;
    43         Trusted: boolean;
    44         Trusted, Synced: boolean;
    44         end;
    45         end;
    45 
    46 
    46 var
    47 var
    47     Variables: PVariable;
    48     Variables: PVariable;
    48 
    49 
    49 procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean);
    50 procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean);
       
    51 begin
       
    52 RegisterVariable(Name, p, Trusted, false);
       
    53 end;
       
    54 procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean; Synced: boolean);
    50 var
    55 var
    51     value: PVariable;
    56     value: PVariable;
    52 begin
    57 begin
    53 New(value);
    58 New(value);
    54 TryDo(value <> nil, 'RegisterVariable: value = nil', true);
    59 TryDo(value <> nil, 'RegisterVariable: value = nil', true);
    55 FillChar(value^, sizeof(TVariable), 0);
    60 FillChar(value^, sizeof(TVariable), 0);
    56 value^.Name:= Name;
    61 value^.Name:= Name;
    57 value^.Handler:= p;
    62 value^.Handler:= p;
    58 value^.Trusted:= Trusted;
    63 value^.Trusted:= Trusted;
       
    64 value^.Synced:= Synced;
    59 
    65 
    60 if Variables = nil then
    66 if Variables = nil then
    61     Variables:= value
    67     Variables:= value
    62 else
    68 else
    63     begin
    69     begin
    79 if (c = '/') or (c = '$') then
    85 if (c = '/') or (c = '$') then
    80     Delete(CmdStr, 1, 1);
    86     Delete(CmdStr, 1, 1);
    81 s:= '';
    87 s:= '';
    82 SplitBySpace(CmdStr, s);
    88 SplitBySpace(CmdStr, s);
    83 AddFileLog('[Cmd] ' + CmdStr + ' (' + inttostr(length(s)) + ')');
    89 AddFileLog('[Cmd] ' + CmdStr + ' (' + inttostr(length(s)) + ')');
       
    90 
    84 t:= Variables;
    91 t:= Variables;
    85 while t <> nil do
    92 while t <> nil do
    86     begin
    93     begin
    87     if t^.Name = CmdStr then
    94     if t^.Name = CmdStr then
    88         begin
    95         begin
       
    96         if t^.Synced then CheckSum:= CheckSum xor LongWord(SDLNet_Read32(@CmdStr)) xor LongWord(s[0]) xor GameTicks;
    89         if TrustedSource or t^.Trusted then
    97         if TrustedSource or t^.Trusted then
    90             t^.Handler(s);
    98             t^.Handler(s);
    91         exit
    99         exit
    92         end
   100         end
    93     else
   101     else