Ignore:
Timestamp:
May 18, 2022, 11:12:29 AM (2 years ago)
Author:
chronos
Message:
  • Fixed: Data size was not correctly stored in server commands. Introduced in rev 435.
  • Fixed: Check data size for its maximum. Limit maximum length of unit and city name so it can fit into data block.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Term.pas

    r435 r438  
    403403
    404404type
     405
     406  { TTribeInfo }
     407
    405408  TTribeInfo = record
    406409    trix: integer;
    407410    FileName: ShortString;
    408   end;
     411    function GetCommandDataSize: Byte;
     412  end;
     413
     414  { TCityNameInfo }
    409415
    410416  TCityNameInfo = record
    411417    ID: integer;
    412418    NewName: ShortString;
    413   end;
     419    function GetCommandDataSize: Byte;
     420  end;
     421
     422  { TModelNameInfo }
    414423
    415424  TModelNameInfo = record
    416425    mix: integer;
    417426    NewName: ShortString;
     427    function GetCommandDataSize: Byte;
    418428  end;
    419429
     
    574584  IsControl: boolean = false);
    575585procedure HelpOnTerrain(Loc: Integer; NewMode: TWindowMode);
     586function AlignUp(Value, Alignment: Integer): Integer;
    576587
    577588
     
    581592  Directories, CityScreen, Draft, MessgEx, Select, CityType, Help,
    582593  UnitStat, Log, Diagram, NatStat, Wonders, Enhance, Nego, UPixelPointer, Sound,
    583   Battle, Rates, TechTree, Registry, Global, UKeyBindings;
     594  Battle, Rates, TechTree, Registry, Global, UKeyBindings, CmdList;
    584595
    585596{$R *.lfm}
     
    760771end;
    761772
     773function AlignUp(Value, Alignment: Integer): Integer;
     774begin
     775  Result := Value or (Alignment - 1);
     776end;
     777
    762778{ *** tribe management procedures *** }
    763779
     
    812828      Tribe[p].SetModelPicture(Picture, IsNew)
    813829    else if IsNew then
    814       Server(cSetNewModelPicture, 0, 0, Picture)
     830      Server(CommandWithData(cSetNewModelPicture, Picture.GetCommandDataSize),
     831        0, 0, Picture)
    815832    else
    816       Server(cSetModelPicture, 0, 0, Picture)
     833      Server(CommandWithData(cSetModelPicture, Picture.GetCommandDataSize),
     834        0, 0, Picture)
    817835  else
    818836    with Tribe[p].ModelPicture[mix] do
     
    961979          ModelNameInfo.mix := MyData.ToldModels;
    962980          ModelNameInfo.NewName := EInput.Text;
    963           Server(cSetModelName, me, 0, ModelNameInfo);
     981          if ModelNameInfo.GetCommandDataSize > CommandDataMaxSize then
     982            Delete(ModelNameInfo.NewName, Length(ModelNameInfo.NewName) -
     983             (ModelNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt);
     984          Server(CommandWithData(cSetModelName, ModelNameInfo.GetCommandDataSize),
     985            me, 0, ModelNameInfo);
    964986        end;
    965987      end;
     
    972994      inc(MyData.ToldModels);
    973995    end;
     996end;
     997
     998{ TTribeInfo }
     999
     1000function TTribeInfo.GetCommandDataSize: Byte;
     1001begin
     1002  Result := SizeOf(trix) + 1 + Length(FileName)
     1003end;
     1004
     1005{ TModelNameInfo }
     1006
     1007function TModelNameInfo.GetCommandDataSize: Byte;
     1008begin
     1009  Result := SizeOf(mix) + 1 + Length(NewName);
     1010end;
     1011
     1012{ TCityNameInfo }
     1013
     1014function TCityNameInfo.GetCommandDataSize: Byte;
     1015begin
     1016  Result := SizeOf(ID) + 1 + Length(NewName);
    9741017end;
    9751018
     
    27312774                CreateTribe(TribeInfo.trix, TribeInfo.FileName, false)
    27322775              else
    2733                 Server(cSetTribe, 0, 0, TribeInfo);
     2776                Server(CommandWithData(cSetTribe, TribeInfo.GetCommandDataSize),
     2777                  0, 0, TribeInfo);
    27342778            end;
    27352779
     
    27452789                CreateTribe(TribeInfo.trix, TribeInfo.FileName, false)
    27462790              else
    2747                 Server(cSetTribe, 0, 0, TribeInfo);
     2791                Server(CommandWithData(cSetTribe, TribeInfo.GetCommandDataSize),
     2792                  0, 0, TribeInfo);
    27482793            end;
    27492794        end;
     
    34453490  else
    34463491    if Command >= cClientEx then
    3447       case Command of
     3492      case Command and (not Integer(CommandDataElementCountMask)) of
    34483493        cSetTribe:
    34493494          with TTribeInfo(Data) do begin
Note: See TracChangeset for help on using the changeset viewer.