From: DeaDDooMER Date: Fri, 4 Jan 2019 19:58:37 +0000 (+0300) Subject: Revert "network: changed weapon forcing logic; should be more reliable (i hope)" X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=2587eb5662fe075d616c89950be655d15fee15d6;p=d2df-sdl.git Revert "network: changed weapon forcing logic; should be more reliable (i hope)" This reverts commit c97b4f7894fd3d797ecea3de574b58499c43aa85. --- diff --git a/src/game/g_net.pas b/src/game/g_net.pas index c672da6..4eeeede 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -22,7 +22,7 @@ uses e_log, e_msg, ENet, Classes, MAPDEF{$IFDEF USE_MINIUPNPC}, miniupnpc;{$ELSE};{$ENDIF} const - NET_PROTOCOL_VER = 176; + NET_PROTOCOL_VER = 175; NET_MAXCLIENTS = 24; NET_CHANS = 11; diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index 7cd1a7c..e9cc68c 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -437,7 +437,7 @@ var PID: Word; kByte: Word; Pl: TPlayer; - GT, wctr: LongWord; + GT: LongWord; newweapon: Byte; begin Result := 0; @@ -456,18 +456,15 @@ begin NetTime := GT; kByte := M.ReadWord(); Dir := M.ReadByte(); - wctr := M.ReadLongWord(); + //WeaponSelect := M.ReadWord(); newweapon := M.ReadByte(); - if (wctr > Pl.NetWeapCtr) then + if (newweapon <> CurrWeap) then begin - if (newweapon <> CurrWeap) then - begin {$IFDEF K8_XXX_WEAPON_DEBUG} - writeln('HOST PLRPOS: got: currweap=', CurrWeap, '; curfrm=', gTime, '; netweap=', newweapon, '; oldweap=', CurrWeap); + writeln('HOST PLRPOS: got: currweap=', CurrWeap, '; curfrm=', gTime, '; netweap=', newweapon, '; oldweap=', CurrWeap); {$ENDIF} - SetWeaponHost(newweapon); - end; - Pl.NetWeapCtr := wctr; + //NetForceWeap := newweapon; + SetWeaponHost(newweapon); end; //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING); if Direction <> TDirection(Dir) then @@ -1012,9 +1009,7 @@ begin NetOut.Write(FPing); NetOut.Write(FLoss); if IsKeyPressed(KEY_CHAT) then - begin - kByte := NET_KEY_CHAT; - end + kByte := NET_KEY_CHAT else begin if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT; @@ -1027,10 +1022,6 @@ begin NetOut.Write(kByte); if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1)); - - NetOut.Write(LongWord(Pl.NetWeapCtr)); - NetOut.Write(Byte(Pl.CurrWeap)); - NetOut.Write(GameX); NetOut.Write(GameY); NetOut.Write(GameVelX); @@ -1091,7 +1082,7 @@ begin NetOut.Write(Frags); NetOut.Write(Death); - NetOut.Write(LongWord(NetWeapCtr)); + //NetOut.Write(CurrWeap); NetOut.Write(Byte(CurrWeap)); // other flags @@ -2036,11 +2027,11 @@ end; function MC_RECV_PlayerPos(var M: TMsg): Word; var - GT, wctr: LongWord; + GT: LongWord; PID: Word; kByte: Word; Pl: TPlayer; - Dir, weapon: Byte; + Dir: Byte; TmpX, TmpY: Integer; begin Result := 0; @@ -2052,6 +2043,8 @@ begin Exit; end; gTime := GT; + if g_Game_IsClient and (gPlayer1 <> nil) and (gPlayer1.NetForceWeapFIdx >= gTime+15) then gPlayer1.NetForceWeapFIdx := 0; + if g_Game_IsClient and (gPlayer2 <> nil) and (gPlayer2.NetForceWeapFIdx >= gTime+15) then gPlayer2.NetForceWeapFIdx := 0; PID := M.ReadWord(); Pl := g_Player_Get(PID); @@ -2067,24 +2060,13 @@ begin kByte := M.ReadWord(); Dir := M.ReadByte(); - wctr := M.ReadLongWord(); - weapon := M.ReadByte(); - // `>=`, so server is still the authority - if (wctr >= Pl.NetWeapCtr) then - begin - Pl.CurrWeap := weapon; - Pl.NetWeapCtr := wctr; - end; - TmpX := M.ReadLongInt(); TmpY := M.ReadLongInt(); ReleaseKeysNoWeapon; if (kByte = NET_KEY_CHAT) then - begin - PressKey(KEY_CHAT, 10000); - end + PressKey(KEY_CHAT, 10000) else begin if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000); @@ -2115,7 +2097,6 @@ var NewTeam: Byte; ww: Word; newweapon: Byte; - wctr: LongWord; begin PID := M.ReadWord(); Pl := g_Player_Get(PID); @@ -2162,17 +2143,16 @@ begin Frags := M.ReadLongInt(); Death := M.ReadLongInt(); - wctr := M.ReadLongWord(); newweapon := M.ReadByte(); {$IFDEF K8_XXX_WEAPON_DEBUG} writeln('CLIENT PLRSTATS: got: currweap=', CurrWeap, '; curfrm=', gTime, '; netweap=', newweapon, '; lastnwfrm=', NetForceWeapFIdx); {$ENDIF} - // `>=`, so server is still the authority - if (wctr >= NetWeapCtr) then + if (gTime >= NetForceWeapFIdx) then begin + //NetForceWeap := newweapon; SetWeaponHost(newweapon); - NetWeapCtr := wctr; end; + //SetWeapon(M.ReadByte()); // other flags ww := M.ReadByte(); @@ -2886,7 +2866,6 @@ begin NetOut.Write(gTime); NetOut.Write(kByte); NetOut.Write(Byte(gPlayer1.Direction)); - NetOut.Write(LongWord(gPlayer1.NetWeapCtr)); NetOut.Write(Byte(gPlayer1.CurrWeap)); {$IFDEF K8_XXX_WEAPON_DEBUG} if (kByte and NET_KEY_FIRE) <> 0 then writeln('FIRE: CurrWeap=', gPlayer1.CurrWeap); @@ -2896,6 +2875,9 @@ begin //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING); g_Net_Client_Send(True, NET_CHAN_PLAYERPOS); + // force player weapon + //{if (gPlayer1.NetForceWeapFIdx < gTime) then} gPlayer1.SetWeapon(gPlayer1.NetForceWeap); + //kBytePrev := kByte; //kDirPrev := gPlayer1.Direction; end; diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 6abe742..9351a9d 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -162,7 +162,9 @@ type FFlag: Byte; FSecrets: Integer; FCurrWeap: Byte; - FNetWeapCtr: LongWord; // spam server with our current weapon until we'll receive this in plrpos packet + //FNetForceWeap: Byte; // spam server with this -- this is new weapon we want to use + FNetForceWeapFIdx: LongWord; // frame index; ignore weapon change if it is lesser than this + //FCurrFrameIdx: LongWord; // increased in each `Update()` FNextWeap: WORD; FNextWeapDelay: Byte; // frames (unused) FBFGFireCounter: SmallInt; @@ -268,7 +270,6 @@ type viewPortX, viewPortY, viewPortW, viewPortH: Integer; function isValidViewPort (): Boolean; inline; - procedure SetCurrWeapProp (newweap: Byte); constructor Create(); virtual; destructor Destroy(); override; @@ -359,8 +360,10 @@ type property Frags: Integer read FFrags write FFrags; property Death: Integer read FDeath write FDeath; property Kills: Integer read FKills write FKills; - property CurrWeap: Byte read FCurrWeap write SetCurrWeapProp; - property NetWeapCtr: LongWord read FNetWeapCtr write FNetWeapCtr; + property CurrWeap: Byte read FCurrWeap write FCurrWeap; + //property NetForceWeap: Byte read FNetForceWeap write FNetForceWeap; + property NetForceWeapFIdx: LongWord read FNetForceWeapFIdx write FNetForceWeapFIdx; + //property CurrFrameIdx: LongWord read FCurrFrameIdx write FCurrFrameIdx; property MonsterKills: Integer read FMonsterKills write FMonsterKills; property Secrets: Integer read FSecrets; property GodMode: Boolean read FGodMode write FGodMode; @@ -391,7 +394,7 @@ type property eFrags: Integer read FFrags write FFrags; property eDeath: Integer read FDeath write FDeath; property eKills: Integer read FKills write FKills; - property eCurrWeap: Byte read FCurrWeap write SetCurrWeapProp; + property eCurrWeap: Byte read FCurrWeap write FCurrWeap; property eMonsterKills: Integer read FMonsterKills write FMonsterKills; property eSecrets: Integer read FSecrets write FSecrets; property eGodMode: Boolean read FGodMode write FGodMode; @@ -915,7 +918,7 @@ begin gPlayers[a].FSecrets := utils.readLongInt(st); // Òåêóùåå îðóæèå gPlayers[a].FCurrWeap := utils.readByte(st); - gPlayers[a].FNetWeapCtr := 0; + //gPlayers[a].FNetForceWeap := gPlayers[a].FCurrWeap; // Ñëåäóþùåå æåëàåìîå îðóæèå gPlayers[a].FNextWeap := utils.readWord(st); // ...è ïàóçà @@ -1369,7 +1372,9 @@ begin begin if gPlayers[i] is TPlayer then begin + //if (gPlayers[i].NetForceWeapFIdx > gTime) then writeln('*** PLAYER #', i, '; gTime=', gTime, '; nfwf=', gPlayers[i].NetForceWeapFIdx); gPlayers[i].Update(); + if (not gPlayers[i].alive) or (gPlayers[i].NetForceWeapFIdx >= gTime+15) then gPlayers[i].NetForceWeapFIdx := 0; // just in case gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`! end else @@ -1954,19 +1959,6 @@ end; function TPlayer.isValidViewPort (): Boolean; inline; begin result := (viewPortW > 0) and (viewPortH > 0); end; -procedure TPlayer.SetCurrWeapProp (newweap: Byte); -begin - if (newweap > High(FWeapon)) then exit; - if (not FWeapon[newweap]) then exit; - if not g_Game_IsClient then Inc(FNetWeapCtr, 2); // just in case, to really override client's counter - if (FCurrWeap <> newweap) then - begin - if (newweap = WEAPON_SAW) then FSawSoundSelect.PlayAt(FObj.X, FObj.Y); - end; - FCurrWeap := newweap; - FModel.SetWeapon(newweap); -end; - procedure TPlayer.BFGHit(); begin g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2), @@ -2155,7 +2147,9 @@ begin FJustTeleported := False; FNetTime := 0; - FNetWeapCtr := 0; + //FNetForceWeap := FCurrWeap; + FNetForceWeapFIdx := 0; + //FCurrFrameIdx := 0; resetWeaponQueue(); releaseAllWeaponSwitchKeys(); @@ -3868,6 +3862,8 @@ begin exit; end; + if (FNetForceWeapFIdx >= gTime+15) then FNetForceWeapFIdx := 0; + nw := getNextWeaponIndex(); if nw = 255 then exit; // don't reset anything here if nw > High(FWeapon) then @@ -3881,12 +3877,22 @@ begin if FWeapon[nw] then begin //k8: emulate this on client immediately, or wait for server confirmation? - Inc(FNetWeapCtr); + { + if g_Game_IsClient then + begin + FNetForceWeap := nw; + //FNetForceWeapFIdx := FCurrFrameIdx+5; // force for ~5 frames + FNetForceWeapFIdx := gTime+5; // force for ~5 frames + writeln('NETWEAPONSWITCH: fw=', NetForceWeap, '; fwfidx=', NetForceWeapFIdx, '; cfrm=', gTime); + end; + } + FNetForceWeapFIdx := gTime+5; // force for ~5 frames FCurrWeap := nw; - if (nw = WEAPON_SAW) then FSawSoundSelect.PlayAt(FObj.X, FObj.Y); + if nw = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y); FModel.SetWeapon(nw); FTime[T_SWITCH] := gTime+156; if g_Game_IsNet then MH_SEND_PlayerStats(FUID); + //if g_Game_IsNet and g_Game_IsClient then end; end; @@ -3909,12 +3915,11 @@ begin if (not FWeapon[W]) then exit; // server is authority! if FCurrWeap <> W then - begin - if (W = WEAPON_SAW) then FSawSoundSelect.PlayAt(FObj.X, FObj.Y); - end; + if (W = WEAPON_SAW) then + FSawSoundSelect.PlayAt(FObj.X, FObj.Y); FCurrWeap := W; - FModel.SetWeapon(W); + FModel.SetWeapon(CurrWeap); //if g_Game_IsClient then resetWeaponQueue(); end; @@ -4273,7 +4278,8 @@ begin Include(FRulez, R_BERSERK); if allowBerserkSwitching then begin - CurrWeap := WEAPON_KASTET; + FCurrWeap := WEAPON_KASTET; + //FNetForceWeap := FCurrWeap; resetWeaponQueue(); FModel.SetWeapon(WEAPON_KASTET); end; @@ -4389,7 +4395,9 @@ begin FMonsterKills := 0; FDeath := 0; FSecrets := 0; - if g_Game_IsClient then FNetWeapCtr := 0 else Inc(FNetWeapCtr, 2); + //FCurrFrameIdx := 0; + //FNetForceWeap := FCurrWeap; + FNetForceWeapFIdx := 0; resetWeaponQueue(); if FNoRespawn then begin @@ -4422,7 +4430,7 @@ begin FLastHit := 0; FLastFrag := 0; FComboEvnt := -1; - if g_Game_IsClient then FNetWeapCtr := 0 else Inc(FNetWeapCtr, 2); + FNetForceWeapFIdx := 0; resetWeaponQueue(); FBFGFireCounter := -1; @@ -4595,7 +4603,8 @@ begin FShellTimer := -1; FPain := 0; FLastHit := 0; - if g_Game_IsClient then FNetWeapCtr := 0 else Inc(FNetWeapCtr, 2); + //FNetForceWeap := FCurrWeap; + FNetForceWeapFIdx := 0; resetWeaponQueue(); FBFGFireCounter := -1; @@ -4663,10 +4672,13 @@ begin FWeapon[WEAPON_PISTOL] := True; FWeapon[WEAPON_KASTET] := True; - CurrWeap := WEAPON_PISTOL; - if g_Game_IsClient then FNetWeapCtr := 0 else Inc(FNetWeapCtr, 2); + FCurrWeap := WEAPON_PISTOL; + //FNetForceWeap := FCurrWeap; + FNetForceWeapFIdx := 0; resetWeaponQueue(); + FModel.SetWeapon(FCurrWeap); + for b := A_BULLETS to A_HIGH do FAmmo[b] := 0; @@ -4742,6 +4754,8 @@ begin if (gPlayer2 = nil) and (gLMSPID2 = FUID) then gPlayer2 := self; + //FNetForceWeap := FCurrWeap; + if g_Game_IsNet then begin MH_SEND_PlayerPos(True, FUID, NET_EVERYONE); @@ -5034,6 +5048,8 @@ var AnyServer: Boolean; SetSpect: Boolean; begin + //Inc(FCurrFrameIdx); + NetServer := g_Game_IsNet and g_Game_IsServer; AnyServer := g_Game_IsServer; @@ -5964,7 +5980,7 @@ begin FAir := FSavedState.Air; FJetFuel := FSavedState.JetFuel; FCurrWeap := FSavedState.CurrWeap; - FModel.SetWeapon(FCurrWeap); + //FNetForceWeap := FCurrWeap; FNextWeap := FSavedState.NextWeap; FNextWeapDelay := FSavedState.NextWeapDelay; @@ -6135,7 +6151,7 @@ begin FSecrets := utils.readLongInt(st); // Òåêóùåå îðóæèå FCurrWeap := utils.readByte(st); - if not g_Game_IsClient then Inc(FNetWeapCtr, 2); + //FNetForceWeap := FCurrWeap; // Æåëàåìîå îðóæèå FNextWeap := utils.readWord(st); // ...è ïàóçà @@ -6270,7 +6286,9 @@ begin Include(FRulez, R_BERSERK); if FBFGFireCounter < 1 then begin - CurrWeap := WEAPON_KASTET; + FCurrWeap := WEAPON_KASTET; + //FNetForceWeap := FCurrWeap; + FNetForceWeapFIdx := 0; resetWeaponQueue(); FModel.SetWeapon(WEAPON_KASTET); end; @@ -6699,7 +6717,7 @@ begin FAIFlags := nil; FSelectedWeapon := FCurrWeap; - FNetWeapCtr := 0; + FNetForceWeapFIdx := 0; resetWeaponQueue(); FTargetUID := 0; end;