Changeset 438
- Timestamp:
- May 18, 2022, 11:12:29 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CmdList.pas
r355 r438 5 5 6 6 uses 7 Classes ;7 Classes, SysUtils, Math; 8 8 9 9 const 10 10 MaxDataSize = 1024; 11 CommandDataElementSize = 4; 12 CommandDataElementCountMask = $f; 13 CommandDataMaxSize = CommandDataElementSize * CommandDataElementCountMask; 11 14 12 15 type … … 44 47 end; 45 48 49 function CommandWithData(Command: Integer; DataSize: Byte): Integer; 50 51 resourcestring 52 SCommandDataSizeError = 'Command data size %d out of range (0-%d).'; 53 54 46 55 implementation 47 56 … … 55 64 TData = array [0 .. MaxDataSize - 1] of Cardinal; 56 65 PData = ^TData; 66 67 function CommandWithData(Command: Integer; DataSize: Byte): Integer; 68 var 69 DataElementCount: Byte; 70 begin 71 if DataSize > CommandDataMaxSize then 72 raise Exception.Create(Format(SCommandDataSizeError, [DataSize, CommandDataMaxSize])); 73 DataElementCount := Ceil(DataSize / CommandDataElementSize); 74 Result := Command or (DataElementCount and CommandDataElementCountMask); 75 end; 57 76 58 77 constructor TCmdList.Create; … … 139 158 end; 140 159 141 if Command and $F= 0 then160 if Command and CommandDataElementCountMask = 0 then 142 161 Data := nil 143 162 else 144 163 begin 145 164 Data := @LogData[FState.LoadPos]; 146 inc(FState.LoadPos, Command and $F * 4);165 inc(FState.LoadPos, Command and CommandDataElementCountMask * CommandDataElementSize); 147 166 end; 148 167 end; … … 232 251 end; 233 252 end; 234 if Command and $F<> 0 then235 PutData(Data, Command and $F * 4);253 if Command and CommandDataElementCountMask <> 0 then 254 PutData(Data, Command and CommandDataElementCountMask * CommandDataElementSize); 236 255 end; 237 256 -
trunk/LocalPlayer/MessgEx.pas
r429 r438 64 64 uses 65 65 ClientTools, BaseWin, Term, Help, UnitStat, Tribes, UPixelPointer, 66 IsoEngine,Diagram, Sound;66 Diagram, Sound; 67 67 68 68 {$R *.lfm} -
trunk/LocalPlayer/Select.pas
r435 r438 5 5 6 6 uses 7 Protocol, ClientTools, Term, ScreenTools, IsoEngine,PVSB, BaseWin,7 Protocol, ClientTools, Term, ScreenTools, PVSB, BaseWin, 8 8 LCLIntf, LCLType, Messages, SysUtils, Classes, Graphics, Controls, Forms, 9 9 ExtCtrls, ButtonB, ButtonBase, Menus, Types; … … 99 99 100 100 uses 101 CityScreen, Help, UnitStat, Tribes, Inp ;101 CityScreen, Help, UnitStat, Tribes, Inp, CmdList; 102 102 103 103 {$R *.lfm} … … 865 865 CityNameInfo.ID := MyCity[cix].ID; 866 866 CityNameInfo.NewName := InputDlg.EInput.Text; 867 Server(cSetCityName, me, 0, CityNameInfo); 867 if CityNameInfo.GetCommandDataSize > CommandDataMaxSize then 868 Delete(CityNameInfo.NewName, Length(CityNameInfo.NewName) - 869 (CityNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt); 870 Server(CommandWithData(cSetCityName, CityNameInfo.GetCommandDataSize), 871 me, 0, CityNameInfo); 868 872 if CityDlg.Visible then 869 873 begin … … 871 875 CityDlg.Invalidate; 872 876 end; 873 result := true;877 Result := True; 874 878 end 875 879 else 876 result := false;880 Result := False; 877 881 end; 878 882 … … 890 894 ModelNameInfo.mix := mix; 891 895 ModelNameInfo.NewName := InputDlg.EInput.Text; 892 Server(cSetModelName, me, 0, ModelNameInfo); 896 if ModelNameInfo.GetCommandDataSize > CommandDataMaxSize then 897 Delete(ModelNameInfo.NewName, Length(ModelNameInfo.NewName) - 898 (ModelNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt); 899 Server(CommandWithData(cSetModelName, ModelNameInfo.GetCommandDataSize), 900 me, 0, ModelNameInfo); 893 901 if UnitStatDlg.Visible then 894 902 begin -
trunk/LocalPlayer/Term.pas
r435 r438 403 403 404 404 type 405 406 { TTribeInfo } 407 405 408 TTribeInfo = record 406 409 trix: integer; 407 410 FileName: ShortString; 408 end; 411 function GetCommandDataSize: Byte; 412 end; 413 414 { TCityNameInfo } 409 415 410 416 TCityNameInfo = record 411 417 ID: integer; 412 418 NewName: ShortString; 413 end; 419 function GetCommandDataSize: Byte; 420 end; 421 422 { TModelNameInfo } 414 423 415 424 TModelNameInfo = record 416 425 mix: integer; 417 426 NewName: ShortString; 427 function GetCommandDataSize: Byte; 418 428 end; 419 429 … … 574 584 IsControl: boolean = false); 575 585 procedure HelpOnTerrain(Loc: Integer; NewMode: TWindowMode); 586 function AlignUp(Value, Alignment: Integer): Integer; 576 587 577 588 … … 581 592 Directories, CityScreen, Draft, MessgEx, Select, CityType, Help, 582 593 UnitStat, Log, Diagram, NatStat, Wonders, Enhance, Nego, UPixelPointer, Sound, 583 Battle, Rates, TechTree, Registry, Global, UKeyBindings ;594 Battle, Rates, TechTree, Registry, Global, UKeyBindings, CmdList; 584 595 585 596 {$R *.lfm} … … 760 771 end; 761 772 773 function AlignUp(Value, Alignment: Integer): Integer; 774 begin 775 Result := Value or (Alignment - 1); 776 end; 777 762 778 { *** tribe management procedures *** } 763 779 … … 812 828 Tribe[p].SetModelPicture(Picture, IsNew) 813 829 else if IsNew then 814 Server(cSetNewModelPicture, 0, 0, Picture) 830 Server(CommandWithData(cSetNewModelPicture, Picture.GetCommandDataSize), 831 0, 0, Picture) 815 832 else 816 Server(cSetModelPicture, 0, 0, Picture) 833 Server(CommandWithData(cSetModelPicture, Picture.GetCommandDataSize), 834 0, 0, Picture) 817 835 else 818 836 with Tribe[p].ModelPicture[mix] do … … 961 979 ModelNameInfo.mix := MyData.ToldModels; 962 980 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); 964 986 end; 965 987 end; … … 972 994 inc(MyData.ToldModels); 973 995 end; 996 end; 997 998 { TTribeInfo } 999 1000 function TTribeInfo.GetCommandDataSize: Byte; 1001 begin 1002 Result := SizeOf(trix) + 1 + Length(FileName) 1003 end; 1004 1005 { TModelNameInfo } 1006 1007 function TModelNameInfo.GetCommandDataSize: Byte; 1008 begin 1009 Result := SizeOf(mix) + 1 + Length(NewName); 1010 end; 1011 1012 { TCityNameInfo } 1013 1014 function TCityNameInfo.GetCommandDataSize: Byte; 1015 begin 1016 Result := SizeOf(ID) + 1 + Length(NewName); 974 1017 end; 975 1018 … … 2731 2774 CreateTribe(TribeInfo.trix, TribeInfo.FileName, false) 2732 2775 else 2733 Server(cSetTribe, 0, 0, TribeInfo); 2776 Server(CommandWithData(cSetTribe, TribeInfo.GetCommandDataSize), 2777 0, 0, TribeInfo); 2734 2778 end; 2735 2779 … … 2745 2789 CreateTribe(TribeInfo.trix, TribeInfo.FileName, false) 2746 2790 else 2747 Server(cSetTribe, 0, 0, TribeInfo); 2791 Server(CommandWithData(cSetTribe, TribeInfo.GetCommandDataSize), 2792 0, 0, TribeInfo); 2748 2793 end; 2749 2794 end; … … 3445 3490 else 3446 3491 if Command >= cClientEx then 3447 case Command of3492 case Command and (not Integer(CommandDataElementCountMask)) of 3448 3493 cSetTribe: 3449 3494 with TTribeInfo(Data) do begin -
trunk/LocalPlayer/Tribes.pas
r417 r438 20 20 yShield: Integer; 21 21 end; 22 23 { TModelPictureInfo } 22 24 23 25 TModelPictureInfo = record … … 27 29 Hash: Integer; 28 30 GrName: ShortString; 31 function GetCommandDataSize: Byte; 29 32 end; 30 33 … … 283 286 end; 284 287 288 { TModelPictureInfo } 289 290 function TModelPictureInfo.GetCommandDataSize: Byte; 291 begin 292 Result := SizeOf(trix) + SizeOf(mix) + SizeOf(pix) + SizeOf(Hash) + 1 + 293 Length(GrName); 294 end; 295 285 296 constructor TTribe.Create(FileName: string); 286 297 var -
trunk/Log.pas
r183 r438 5 5 6 6 uses 7 LCLIntf, LCLType, LMessages,Messages, SysUtils, Classes, Graphics, Controls, Forms,7 LCLIntf, LCLType, Messages, SysUtils, Classes, Graphics, Controls, Forms, 8 8 StdCtrls, Menus; 9 9
Note:
See TracChangeset
for help on using the changeset viewer.