diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-10-16 04:23:52 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-10-16 04:23:52 -0300 |
| commit | 01a6e8dbe42fb6571ad846bee5e1d8cc7c9fba5e (patch) | |
| tree | cccdd754cb6c428ab0e3c3b6a8d0cd1003ff43b0 | |
| parent | 9825f08f2b46b147faa48e4d127c93694522e6d6 (diff) | |
| download | querymanager-01a6e8dbe42fb6571ad846bee5e1d8cc7c9fba5e.tar.gz querymanager-01a6e8dbe42fb6571ad846bee5e1d8cc7c9fba5e.zip | |
move ResolveHostName outside of GetCharacterEndpoints
| -rw-r--r-- | postgres/init.sql | 2 | ||||
| -rw-r--r-- | postgres/schema.sql | 18 | ||||
| -rw-r--r-- | src/database_postgres.cc | 17 | ||||
| -rw-r--r-- | src/database_sqlite.cc | 16 | ||||
| -rw-r--r-- | src/hostcache.cc | 5 | ||||
| -rw-r--r-- | src/query.cc | 14 | ||||
| -rw-r--r-- | src/querymanager.hh | 2 |
7 files changed, 34 insertions, 40 deletions
diff --git a/postgres/init.sql b/postgres/init.sql index 5fec2ca..e3907bd 100644 --- a/postgres/init.sql +++ b/postgres/init.sql @@ -10,7 +10,7 @@ INSERT INTO Accounts (AccountID, Email, Auth) -- PostgreSQL handles unique auto increment columns makes so manually inserted -- values end up colliding with generated values at some point. -- On a real scenario, we'd never have manually assigned ids unless we're --- restoring some database dump, in which case it would already have saved +-- restoring some database dump, in which case it would also have saved -- sequences. WITH WorldIns AS ( diff --git a/postgres/schema.sql b/postgres/schema.sql index 548e43c..bbc670f 100644 --- a/postgres/schema.sql +++ b/postgres/schema.sql @@ -6,11 +6,13 @@ BEGIN; -- IMPORTANT(fusion): PosgreSQL doesn't have a defined `NOCASE` collation like -- SQLite and doesn't use a default case-insensitive collation like MySQL. The --- simplest alternative is to create a custom collation. --- This is only supported with PostgreSQL 10+ but it should safe to assume that --- it's widely supported, given that it's almost 10 years old and well past its --- end-of-life. --- For more information see: +-- simplest alternative is to create a custom non-deterministic ICU collation. +-- ICU as a collation provider is supported with PostgreSQL 10+, while +-- non-deterministic collations are supported with PostgreSQL 12+. Either way, +-- it should be safe to assume that it's widely supported, given that version +-- 12 is roughly 6 years old and well past its end-of-life. +-- There are also drawbacks from using these types of collations but I won't +-- go into details. For more information see: -- https://www.postgresql.org/docs/current/collation.html CREATE COLLATION NOCASE ( provider = icu, @@ -18,10 +20,10 @@ CREATE COLLATION NOCASE ( locale = 'und-u-ks-level2' ); --- IMPORTANT(fusion): Since we're already assuming PostgreSQL 10+ for collations, +-- IMPORTANT(fusion): Since we're already assuming PostgreSQL 12+ for collations, -- it's probably a good idea to use IDENTITY columns instead of SERIAL. They're --- also supported with PostgreSQL 10+ and are supposed so fix some shortcommings --- of SERIAL. +-- supported with PostgreSQL 10+ and are supposed so fix some shortcommings of +-- SERIAL. -- TODO(fusion): SQLite tables didn't use foreign key constraints so I'm also not -- using them here. It might be a good idea for consistency, but it's not a hard diff --git a/src/database_postgres.cc b/src/database_postgres.cc index bcadcea..7a676e2 100644 --- a/src/database_postgres.cc +++ b/src/database_postgres.cc @@ -1634,23 +1634,12 @@ bool GetCharacterEndpoints(TDatabase *Database, int AccountID, DynamicArray<TCha int NumRows = PQntuples(Result); for(int Row = 0; Row < NumRows; Row += 1){ - int WorldAddress; - const char *CharacterName = GetResultText(Result, Row, 0); - const char *WorldName = GetResultText(Result, Row, 1); - const char *HostName = GetResultText(Result, Row, 2); - if(HostName == NULL || !ResolveHostName(HostName, &WorldAddress)){ - LOG_ERR("Failed to resolve world \"%s\" host name \"%s\" for character \"%s\"", - WorldName, HostName, CharacterName); - continue; - } - TCharacterEndpoint Character = {}; - StringBufCopy(Character.Name, CharacterName); - StringBufCopy(Character.WorldName, WorldName); - Character.WorldAddress = WorldAddress; + StringBufCopy(Character.Name, GetResultText(Result, Row, 0)); + StringBufCopy(Character.WorldName, GetResultText(Result, Row, 1)); + StringBufCopy(Character.WorldHost, GetResultText(Result, Row, 2)); Character.WorldPort = GetResultInt(Result, Row, 3); Characters->Push(Character); - } return true; diff --git a/src/database_sqlite.cc b/src/database_sqlite.cc index 35581a4..8523854 100644 --- a/src/database_sqlite.cc +++ b/src/database_sqlite.cc @@ -780,20 +780,10 @@ bool GetCharacterEndpoints(TDatabase *Database, int AccountID, DynamicArray<TCha } while(sqlite3_step(Stmt) == SQLITE_ROW){ - int WorldAddress; - const char *CharacterName = (const char*)sqlite3_column_text(Stmt, 0); - const char *WorldName = (const char*)sqlite3_column_text(Stmt, 1); - const char *HostName = (const char*)sqlite3_column_text(Stmt, 2); - if(HostName == NULL || !ResolveHostName(HostName, &WorldAddress)){ - LOG_ERR("Failed to resolve world \"%s\" host name \"%s\" for character \"%s\"", - WorldName, HostName, CharacterName); - continue; - } - TCharacterEndpoint Character = {}; - StringBufCopy(Character.Name, CharacterName); - StringBufCopy(Character.WorldName, WorldName); - Character.WorldAddress = WorldAddress; + StringBufCopy(Character.Name, (const char*)sqlite3_column_text(Stmt, 0)); + StringBufCopy(Character.WorldName, (const char*)sqlite3_column_text(Stmt, 1)); + StringBufCopy(Character.WorldHost, (const char*)sqlite3_column_text(Stmt, 2)); Character.WorldPort = sqlite3_column_int(Stmt, 3); Characters->Push(Character); } diff --git a/src/hostcache.cc b/src/hostcache.cc index 23be08f..9fda094 100644 --- a/src/hostcache.cc +++ b/src/hostcache.cc @@ -58,7 +58,10 @@ static bool DoResolveHostName(const char *HostName, int *OutAddr){ } bool ResolveHostName(const char *HostName, int *OutAddr){ - ASSERT(HostName != NULL && !StringEmpty(HostName)); + if(HostName == NULL || StringEmpty(HostName)){ + return false; + } + THostCacheEntry *Entry = NULL; int LeastRecentlyUsedIndex = 0; int LeastRecentlyUsedTime = g_CachedHostNames[0].ResolveTime; diff --git a/src/query.cc b/src/query.cc index b9484c6..c4d81a1 100644 --- a/src/query.cc +++ b/src/query.cc @@ -587,8 +587,18 @@ static void LoginAccountTx(TDatabase *Database, TQuery *Query, for(int i = 0; i < NumCharacters; i += 1){ Response->WriteString(Characters[i].Name); Response->WriteString(Characters[i].WorldName); - Response->Write32BE((uint32)Characters[i].WorldAddress); - Response->Write16((uint16)Characters[i].WorldPort); + + int WorldAddress; + if(ResolveHostName(Characters[i].WorldHost, &WorldAddress)){ + Response->Write32BE(WorldAddress); + Response->Write16(Characters[i].WorldPort); + }else{ + LOG_ERR("Failed to resolve world \"%s\" host name \"%s\" for character \"%s\"", + Characters[i].WorldName, Characters[i].WorldHost, Characters[i].Name); + + Response->Write32BE(0); + Response->Write16(0); + } } Response->Write16((uint16)(Account.PremiumDays + Account.PendingPremiumDays)); QueryFinishResponse(Query); diff --git a/src/querymanager.hh b/src/querymanager.hh index 1d4b36b..1b90a0d 100644 --- a/src/querymanager.hh +++ b/src/querymanager.hh @@ -801,7 +801,7 @@ struct TAccountBuddy{ struct TCharacterEndpoint{ char Name[30]; char WorldName[30]; - int WorldAddress; + char WorldHost[100]; int WorldPort; }; |
