From 984332369750292f13bb1a5703003166287ce959 Mon Sep 17 00:00:00 2001 From: yvt Date: Mon, 9 Dec 2013 02:49:57 +0900 Subject: [PATCH 1/3] Fixed some crashes on certain 0.76 push server --- Sources/Client/NetClient.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/Client/NetClient.cpp b/Sources/Client/NetClient.cpp index 3808e7e1..385158ff 100644 --- a/Sources/Client/NetClient.cpp +++ b/Sources/Client/NetClient.cpp @@ -1278,6 +1278,7 @@ namespace spades { int state = reader.ReadByte(); IGameMode* mode = GetWorld()->GetMode(); + if(mode == NULL) break; if( mode->ModeType() != IGameMode::m_TC ) { SPRaise("Received PacketTypeTerritoryCapture in non-TC gamemode"); } @@ -1310,6 +1311,7 @@ namespace spades { float progress = reader.ReadFloat(); IGameMode* mode = GetWorld()->GetMode(); + if(mode == NULL) break; if( mode->ModeType() != IGameMode::m_TC ) { SPRaise("Received PacketTypeProgressBar in non-TC gamemode"); } @@ -1335,6 +1337,7 @@ namespace spades { { if(!GetWorld()) SPRaise("No world"); IGameMode* mode = GetWorld()->GetMode(); + if(mode == NULL) break; if( mode->ModeType() != IGameMode::m_CTF ) { SPRaise("Received PacketTypeIntelCapture in non-TC gamemode"); } @@ -1354,6 +1357,7 @@ namespace spades { { Player *p = GetPlayer(reader.ReadByte()); IGameMode* mode = GetWorld()->GetMode(); + if(mode == NULL) break; if( mode->ModeType() != IGameMode::m_CTF ) { SPRaise("Received PacketTypeIntelPickup in non-TC gamemode"); } @@ -1368,6 +1372,7 @@ namespace spades { { Player *p = GetPlayer(reader.ReadByte()); IGameMode* mode = GetWorld()->GetMode(); + if(mode == NULL) break; if( mode->ModeType() != IGameMode::m_CTF ) { SPRaise("Received PacketTypeIntelPickup in non-TC gamemode"); } From d6aad574d2b8e2be0c9a15696b7214394bcaa09d Mon Sep 17 00:00:00 2001 From: yvt Date: Mon, 9 Dec 2013 02:52:56 +0900 Subject: [PATCH 2/3] Now player cannot aim down the sight while reloading --- Sources/Client/Client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Client/Client.cpp b/Sources/Client/Client.cpp index aa22888c..d19d9a91 100644 --- a/Sources/Client/Client.cpp +++ b/Sources/Client/Client.cpp @@ -1075,7 +1075,7 @@ namespace spades { weapInput.primary = down; }else if(CheckKey(cg_keyAltAttack, name)){ if(world->GetLocalPlayer()->IsToolWeapon() && (!cg_holdAimDownSight)){ - if(down && !playerInput.sprint){ + if(down && !playerInput.sprint && !world->GetLocalPlayer()->GetWeapon()->IsReloading()){ weapInput.secondary = !weapInput.secondary; } }else{ From 132b37986226ea7bf2f2acd3e3df8045a282ac8f Mon Sep 17 00:00:00 2001 From: yvt Date: Mon, 9 Dec 2013 03:27:06 +0900 Subject: [PATCH 3/3] Fixed a problem that reloading sometimes fails on 0.76 server --- Sources/Client/Client.cpp | 23 ++++++++++++++++++++--- Sources/Client/Client.h | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Sources/Client/Client.cpp b/Sources/Client/Client.cpp index d19d9a91..ffd84b23 100644 --- a/Sources/Client/Client.cpp +++ b/Sources/Client/Client.cpp @@ -125,7 +125,8 @@ namespace spades { Client::Client(IRenderer *r, IAudioDevice *audioDev, const ServerAddress& host, std::string playerName): - renderer(r), audioDevice(audioDev), playerName(playerName) { + renderer(r), audioDevice(audioDev), playerName(playerName) , + hasDelayedReload(false) { SPADES_MARK_FUNCTION(); SPLog("Initializing..."); @@ -635,6 +636,12 @@ namespace spades { // FIXME: send only there are any changed net->SendPlayerInput(inp); net->SendWeaponInput(weapInput); + + if(hasDelayedReload) { + world->GetLocalPlayer()->Reload(); + net->SendReload(); + hasDelayedReload = false; + } //PlayerInput actualInput = player->GetInput(); WeaponInput actualWeapInput = player->GetWeaponInput(); @@ -842,6 +849,9 @@ namespace spades { // Well done! renderer->FrameDone(); renderer->Flip(); + + // reset all "delayed actions" (in case we forget to reset these) + hasDelayedReload = false; time += dt; } @@ -1092,10 +1102,17 @@ namespace spades { (!world->GetLocalPlayer()->IsAwaitingReloadCompletion()) && (!w->IsReloading()) && world->GetLocalPlayer()->GetTool() == Player::ToolWeapon){ - world->GetLocalPlayer()->Reload(); if(world->GetLocalPlayer()->IsToolWeapon()){ - weapInput.secondary = false; + if(weapInput.secondary) { + // if we send WeaponInput after sending Reload, + // server might cancel the reload. + // https://github.com/infogulch/pyspades/blob/895879ed14ddee47bb278a77be86d62c7580f8b7/pyspades/server.py#343 + hasDelayedReload = true; + weapInput.secondary = false; + return; + } } + world->GetLocalPlayer()->Reload(); net->SendReload(); } }else if(CheckKey(cg_keyToolSpade, name) && down){ diff --git a/Sources/Client/Client.h b/Sources/Client/Client.h index 59f90cc2..2a838485 100644 --- a/Sources/Client/Client.h +++ b/Sources/Client/Client.h @@ -128,6 +128,7 @@ namespace spades { float lastAliveTime; int lastKills; float worldSetTime; + bool hasDelayedReload; struct HurtSprite { float angle; float horzShift;