Skip to content
Browse files

Accomodate servers that lie about player counts.

- Now, the database can be updated to describe linked server sets
  via the game_server_groups table.  The global_user_counts field,
  if set to true, indicates that member servers in the server group
  lie about player counts (and so only one such server contributes
  player counts to the unique player listing).
  • Loading branch information...
1 parent d484052 commit f77ee8a29b458762c73b5c04b4bbaa0c4f4b651d @SkywingvL committed Dec 30, 2012
Showing with 53 additions and 8 deletions.
  1. +15 −2 NWNMasterServer/NWServerTracker.cs
  2. +38 −6 NWNMasterServerAPI/App_Code/NWNMasterServerAPI.cs
View
17 NWNMasterServer/NWServerTracker.cs
@@ -239,12 +239,24 @@ private void InitializeDatabase()
`ilr_enforced` bool NOT NULL,
`pwc_url` varchar(256) NOT NULL,
`server_description` varchar(256) NOT NULL,
+ `game_server_group_id` int(10) UNSIGNED,
PRIMARY KEY (`game_server_id`),
UNIQUE KEY (`product_id`, `server_address`),
INDEX (`product_id`, `online`),
INDEX (`product_id`, `online`, `server_name`),
INDEX (`product_id`, `online`, `module_name`),
- INDEX (`product_id`, `online`, `game_type`)
+ INDEX (`product_id`, `online`, `game_type`),
+ INDEX (`product_id`, `online`, `game_server_group_id`)
+ )");
+
+ MasterServer.ExecuteQueryNoReader(
+@"CREATE TABLE IF NOT EXISTS `game_server_groups` (
+ `game_server_group_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `product_id` int(10) UNSIGNED NOT NULL,
+ `group_name` varchar(128) NOT NULL,
+ `global_user_counts` bool NOT NULL,
+ PRIMARY KEY (`game_server_group_id`),
+ UNIQUE KEY (`product_id`, `group_name`)
)");
MasterServer.ExecuteQueryNoReader(
@@ -278,10 +290,11 @@ PRIMARY KEY (`stat_counter_name`)
MasterServer.ExecuteQueryNoReader(
@"CREATE TABLE IF NOT EXISTS `blacklist_entries` (
+ `blacklist_entry_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`product_id` int(10) UNSIGNED NOT NULL,
`blacklist_entry_type` int(10) UNSIGNED NOT NULL,
`blacklist_entry_match` varchar(128) NOT NULL,
- PRIMARY KEY (`product_id`, `blacklist_entry_type`, `blacklist_entry_match`)
+ PRIMARY KEY (`blacklist_entry_id`)
)");
string Query = String.Format(
View
44 NWNMasterServerAPI/App_Code/NWNMasterServerAPI.cs
@@ -140,13 +140,45 @@ public IList<NWGameServer> GetOnlineServerList(string Product)
/// given product.</returns>
public uint GetOnlineUserCount(string Product)
{
+ //
+ // Return a list of actual, unique players while accomodating
+ // linked server groups that forge the player count query response
+ // to indicate the global player count for the linked server group.
+ //
+ // The count of players from servers that return authentic player
+ // counts is first determined, and then the count of players from
+ // each linked server group that forges player counts is computed
+ // by simply taking the first available online server in the linked
+ // server group.
+ //
+
string Query = String.Format(
- @"SELECT
- SUM(active_player_count)
- FROM
- `game_servers`
- WHERE `product_id` = {0}
- AND `online` = true
+ @"SELECT
+ SUM(`unique_player_count`)
+ FROM
+ (
+ SELECT
+ SUM(`active_player_count`) AS 'unique_player_count'
+ FROM
+ `game_servers`
+ LEFT OUTER JOIN `game_server_groups` ON `game_server_groups`.`game_server_group_id` = `game_servers`.`game_server_group_id`
+ WHERE `game_servers`.`product_id` = {0}
+ AND `game_servers`.`online` = true
+ AND (`game_server_groups`.`game_server_group_id` IS NULL
+ OR `game_server_groups`.`global_user_counts` = 0)
+
+ UNION
+
+ SELECT
+ `game_servers`.`active_player_count` AS 'unique_player_count'
+ FROM
+ `game_server_groups`
+ INNER JOIN `game_servers` ON `game_server_groups`.`global_user_counts` = 1
+ AND `game_servers`.`game_server_group_id` = `game_server_groups`.`game_server_group_id`
+ AND `game_servers`.`product_id` = {0}
+ AND `game_servers`.`online` = true
+ GROUP BY (`game_servers`.`game_server_group_id`)
+ ) AS `unique_player_count_subquery`
",
ProductNameToId(Product));

0 comments on commit f77ee8a

Please sign in to comment.
Something went wrong with that request. Please try again.