Skip to content

Commit

Permalink
Merge pull request ddnet#9401 from Pioooooo/match-over-case
Browse files Browse the repository at this point in the history
Ignore case when map voting with full match
  • Loading branch information
def- authored Dec 19, 2024
2 parents 01d72e9 + f401fc2 commit 0662eb7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/game/server/scoreworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ bool CScoreWorker::MapVote(IDbConnection *pSqlServer, const ISqlData *pGameData,
"FROM %s_maps "
"WHERE Map LIKE %s "
"ORDER BY "
" CASE WHEN Map = ? THEN 0 ELSE 1 END, "
" CASE WHEN LOWER(Map) = LOWER(?) THEN 0 ELSE 1 END, "
" CASE WHEN Map LIKE ? THEN 0 ELSE 1 END, "
" LENGTH(Map), Map "
"LIMIT 1",
Expand Down Expand Up @@ -395,7 +395,7 @@ bool CScoreWorker::MapInfo(IDbConnection *pSqlServer, const ISqlData *pGameData,
" SELECT * FROM %s_maps "
" WHERE Map LIKE %s "
" ORDER BY "
" CASE WHEN Map = ? THEN 0 ELSE 1 END, "
" CASE WHEN LOWER(Map) = LOWER(?) THEN 0 ELSE 1 END, "
" CASE WHEN Map LIKE ? THEN 0 ELSE 1 END, "
" LENGTH(Map), "
" Map "
Expand Down
35 changes: 31 additions & 4 deletions src/test/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct Score : public testing::TestWithParam<IDbConnection *>
{
Connect();
LoadBestTime();
InsertMap();
InsertMap("Kobra 3", "Zerodin", "Novice", 5, 5);
}

~Score()
Expand Down Expand Up @@ -75,15 +75,15 @@ struct Score : public testing::TestWithParam<IDbConnection *>
ASSERT_FALSE(CScoreWorker::LoadBestTime(m_pConn, &loadBestTimeReq, m_aError, sizeof(m_aError))) << m_aError;
}

void InsertMap()
void InsertMap(const char *pName, const char *pMapper, const char *pServer, int Points, int Stars)
{
char aTimestamp[32];
str_timestamp_format(aTimestamp, sizeof(aTimestamp), FORMAT_SPACE);
char aBuf[512];
str_format(aBuf, sizeof(aBuf),
"%s into %s_maps(Map, Server, Mapper, Points, Stars, Timestamp) "
"VALUES (\"Kobra 3\", \"Novice\", \"Zerodin\", 5, 5, %s)",
m_pConn->InsertIgnore(), m_pConn->GetPrefix(), m_pConn->InsertTimestampAsUtc());
"VALUES (\"%s\", \"%s\", \"%s\", %d, %d, %s)",
m_pConn->InsertIgnore(), m_pConn->GetPrefix(), pName, pServer, pMapper, Points, Stars, m_pConn->InsertTimestampAsUtc());
ASSERT_FALSE(m_pConn->PrepareStatement(aBuf, m_aError, sizeof(m_aError))) << m_aError;
m_pConn->BindString(1, aTimestamp);
int NumInserted = 0;
Expand Down Expand Up @@ -418,6 +418,21 @@ TEST_P(MapInfo, Fuzzy)
}
}

TEST_P(MapInfo, FuzzyCase)
{
InsertMap("Reflect", "DarkOort", "Dummy", 20, 3);
InsertMap("reflects", "Ninjed & Pipou", "Solo", 16, 4);
str_copy(m_PlayerRequest.m_aName, "reflect", sizeof(m_PlayerRequest.m_aName));
ASSERT_FALSE(CScoreWorker::MapInfo(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError;

EXPECT_EQ(m_pPlayerResult->m_MessageKind, CScorePlayerResult::DIRECT);
EXPECT_THAT(m_pPlayerResult->m_Data.m_aaMessages[0], testing::MatchesRegex("\"Reflect\" by DarkOort on Dummy, ★★★✰✰, 20 points, released .* ago, 0 finishes by 0 tees"));
for(int i = 1; i < CScorePlayerResult::MAX_MESSAGES; i++)
{
EXPECT_STREQ(m_pPlayerResult->m_Data.m_aaMessages[i], "");
}
}

TEST_P(MapInfo, DoesntExit)
{
str_copy(m_PlayerRequest.m_aName, "f", sizeof(m_PlayerRequest.m_aName));
Expand Down Expand Up @@ -453,6 +468,18 @@ TEST_P(MapVote, Fuzzy)
EXPECT_STREQ(m_pPlayerResult->m_Data.m_MapVote.m_aServer, "novice");
}

TEST_P(MapVote, FuzzyCase)
{
InsertMap("Reflect", "DarkOort", "Dummy", 20, 3);
InsertMap("reflects", "Ninjed & Pipou", "Solo", 16, 4);
str_copy(m_PlayerRequest.m_aName, "reflect", sizeof(m_PlayerRequest.m_aName));
ASSERT_FALSE(CScoreWorker::MapVote(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError;
EXPECT_EQ(m_pPlayerResult->m_MessageKind, CScorePlayerResult::MAP_VOTE);
EXPECT_STREQ(m_pPlayerResult->m_Data.m_MapVote.m_aMap, "Reflect");
EXPECT_STREQ(m_pPlayerResult->m_Data.m_MapVote.m_aReason, "/map");
EXPECT_STREQ(m_pPlayerResult->m_Data.m_MapVote.m_aServer, "dummy");
}

TEST_P(MapVote, DoesntExist)
{
str_copy(m_PlayerRequest.m_aName, "f", sizeof(m_PlayerRequest.m_aName));
Expand Down

0 comments on commit 0662eb7

Please sign in to comment.