From c65ff70faf9530717dfe1dfafb281ec4ff3f2dd7 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sun, 10 Mar 2019 18:09:15 -0500 Subject: [PATCH] Deduplicate character shifting code --- src/console.c | 16 ++++++++++++++++ src/console.h | 2 ++ src/d_clisrv.c | 18 +----------------- src/hu_stuff.c | 13 +------------ 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/console.c b/src/console.c index 2b3ee0e2..44bb03a3 100644 --- a/src/console.c +++ b/src/console.c @@ -544,6 +544,22 @@ static void CON_MoveConsole(void) } } +INT32 CON_ShiftChar(INT32 ch) +{ + if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) + { + if (shiftdown ^ capslock) + ch = shiftxform[ch]; + } + else // if we're holding shift we should still shift non letter symbols + { + if (shiftdown) + ch = shiftxform[ch]; + } + + return ch; +} + // Clear time of console heads up messages // void CON_ClearHUD(void) diff --git a/src/console.h b/src/console.h index 98df6ee2..11621746 100644 --- a/src/console.h +++ b/src/console.h @@ -44,6 +44,8 @@ extern UINT8 *yellowmap, *purplemap, *greenmap, *bluemap, *graymap, *redmap, *or // Console bg color (auto updated to match) extern UINT8 *consolebgmap; +INT32 CON_ShiftChar(INT32 ch); + void CON_SetupBackColormap(void); void CON_ClearHUD(void); // clear heads up messages diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 0202ff6f..5fe378e0 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2228,24 +2228,8 @@ boolean CL_Responder(event_t *ev) len = strlen(cl_challengepassword); if (len < 64) { - - // shifting code stolen from lat by fickle, thx :) - - // I know this looks very messy but this works. If it ain't broke, don't fix it! - // shift LETTERS to uppercase if we have capslock or are holding shift - if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) - { - if (shiftdown ^ capslock) - ch = shiftxform[ch]; - } - else // if we're holding shift we should still shift non letter symbols - { - if (shiftdown) - ch = shiftxform[ch]; - } - cl_challengepassword[len+1] = 0; - cl_challengepassword[len] = ch; + cl_challengepassword[len] = CON_ShiftChar(ch); } cl_challengeattempted = 0; diff --git a/src/hu_stuff.c b/src/hu_stuff.c index a540e0a1..b4357073 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1293,18 +1293,7 @@ boolean HU_Responder(event_t *ev) && ev->data1 != gamecontrol[gc_talkkey][1])) return false; - // I know this looks very messy but this works. If it ain't broke, don't fix it! - // shift LETTERS to uppercase if we have capslock or are holding shift - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) - { - if (shiftdown ^ capslock) - c = shiftxform[c]; - } - else // if we're holding shift we should still shift non letter symbols - { - if (shiftdown) - c = shiftxform[c]; - } + c = CON_ShiftChar(c); // pasting. pasting is cool. chat is a bit limited, though :( if (((c == 'v' || c == 'V') && ctrldown) && !CHAT_MUTE)