Skip to content
Snippets Groups Projects
Commit 5baa5d96 authored by Atanamo's avatar Atanamo
Browse files

Refactored query to fetch player identity

* Database relations have changed: Multiple players can have same ingame identity now.
* Simplified config for game tables by using id placeholder instead of prefix and postfix.
parent 45670efc
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -77,8 +77,8 @@ module.exports =
 
SQL_TABLES:
GAMES_LIST: 'game_worlds' # The name of the table in common db, which contains the list of game worlds
PREFIX_GAME_TABLE: 'game_' # The name prefix of tables in game db, which contain data of a game world's contents
POSTFIX_GAME_PLAYERS: '_players' # The name postfix of the game table, which contains the list of a game world's players
PLAYER_GAMES: 'player_games' # The name of the table in common db, which maps a player to a game world (and an identity)
GAME_PLAYER_IDENTITIES: 'game_<id>_identities' # The name of the table in game db, which contains the player identities of a related game (With <id> as a placeholder for the game ID)
 
CHANNEL_LIST: 'chat - channels' # The name of the table for storing non-game/custom channels (Must be created, see database_setup.sql)
CHANNEL_JOININGS: 'chat - channeljoins' # The name of the table for storing user joins to custom channels (Must be created, see database_setup.sql)
Loading
Loading
Loading
Loading
@@ -134,8 +134,8 @@ class Database
_getGameDatabaseName: (gameMetaData) ->
return "#{Config.SQL_DATABASE_PREFIX_GAME}#{gameMetaData.database_id}"
 
_getGameTableName: (gameMetaData, tablePostfix) ->
return "#{Config.SQL_TABLES.PREFIX_GAME_TABLE}#{gameMetaData.game_id}#{tablePostfix}"
_getGameTableName: (gameMetaData, tableNameSkeleton) ->
return tableNameSkeleton.replace('<id>', gameMetaData.game_id)
 
# Returns the current security token for the given player. This token must be send on auth request by the client.
_getSecurityToken: (idUser, playerData) ->
Loading
Loading
@@ -389,11 +389,14 @@ class Database
# Read data of given player in given game
promise = promise.then (gameData) =>
gameDatabase = @_getGameDatabaseName(gameData)
playersTable = @_getGameTableName(gameData, Config.SQL_TABLES.POSTFIX_GAME_PLAYERS)
playerIdentitiesTable = @_getGameTableName(gameData, Config.SQL_TABLES.GAME_PLAYER_IDENTITIES)
sql = "
SELECT `ID` AS `game_identity_id`, `Folkname` AS `game_identity_name`, `LastActivityStamp` AS `activity_stamp`
FROM `#{gameDatabase}`.`#{playersTable}`
WHERE `UserID`=#{@_toQuery(idUser)}
SELECT `I`.`ID` AS `game_identity_id`, `I`.`Folkname` AS `game_identity_name`, `I`.`LastActivityStamp` AS `activity_stamp`
FROM `#{Config.SQL_TABLES.PLAYER_GAMES}` AS `PG`
JOIN `#{gameDatabase}`.`#{playerIdentitiesTable}` AS `I`
ON `I`.`ID`=`PG`.`FolkID`
WHERE `PG`.`GalaxyID`=#{@_toQuery(idGame)}
AND `PG`.`UserID`=#{@_toQuery(idUser)}
"
return @_readSimpleData(sql, true)
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment