From a7822331f8e5e8080c24210518056d5aa523ffe3 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Wed, 16 May 2018 19:09:01 +0200 Subject: [PATCH] Hopefully handle the "event overflow exploit" There was an exploit where a keyboard would fire events quicker then they could be consumed. This would lock the main game loop in the SDL_PollEvent loop and block rendering until the key in this case was released. Combning this with an attack meant that you could "farm" one NPC for multiple kills and massive XP gains. Leaving the player at level 8+ on dungeon level 1. This fix should mitigate such shenanigans. --- src/main.c | 13 +++++++++++-- src/player.c | 6 ++++++ src/player.h | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 797a91c..8dc4ac6 100644 --- a/src/main.c +++ b/src/main.c @@ -396,6 +396,7 @@ handle_events(void) { static SDL_Event event; bool quit = false; + int handleCount = 0; while (SDL_PollEvent(&event) != 0) { if (event.type == SDL_QUIT) { @@ -407,7 +408,7 @@ handle_events(void) continue; if (gGameState == PLAYING) { - if (currentTurn == PLAYER) + if (currentTurn == PLAYER && !player_turn_over(gPlayer)) gPlayer->handle_event(gPlayer, gRoomMatrix, &event); @@ -421,6 +422,14 @@ handle_events(void) menu_handle_event(inGameMenu, &event); } pointer_handle_event(gPointer, &event); + + handleCount++; + if (handleCount >= 5) { + debug("Flushing event queue"); + SDL_PumpEvents(); + SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); + break; + } } return quit; @@ -492,7 +501,7 @@ run_game(void) roommatrix_update_with_player(gRoomMatrix, gPlayer); if (currentTurn == PLAYER) { - if (gPlayer->stat_data.steps >= gPlayer->stats.speed) { + if (player_turn_over(gPlayer)) { currentTurn = MONSTER; player_reset_steps(gPlayer); } diff --git a/src/player.c b/src/player.c index 9d7ab86..3ce629e 100644 --- a/src/player.c +++ b/src/player.c @@ -533,3 +533,9 @@ player_destroy(Player *player) free(player); } + +bool +player_turn_over(Player *player) +{ + return player->stat_data.steps >= player->stats.speed; +} diff --git a/src/player.h b/src/player.h index 88c58a8..68d22c7 100644 --- a/src/player.h +++ b/src/player.h @@ -93,4 +93,7 @@ player_render(Player*, Camera*); void player_destroy(Player*); +bool +player_turn_over(Player*); + #endif // PLAYER_H_