Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Commit

Permalink
Add number of online observers to server list
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Noah committed Aug 6, 2019
1 parent 934fe72 commit 7b6013f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/components/servers/servers.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div *ngIf="ready && serversService.servers" class="container">
<h2>{{serversService.servers.length + " Public Server" | autoPlural}} Online</h2>
<small>{{serversService.playerCount + " player" | autoPlural}} online. Last update was {{serversService.lastUpdate | timeAgo}}.</small>
<small>{{serversService.playerCount + " player" | autoPlural}} and {{serversService.observerCount + " observer" | autoPlural}} online. Last update was {{serversService.lastUpdate | timeAgo}}.</small>
</div>
<div *ngIf="ready && serversService.servers">
<app-servers-table *ngIf="!settingsService.gridView" [servers]="serversService.servers" (rowClick)="showServerDetails($event)"></app-servers-table>
Expand Down
8 changes: 8 additions & 0 deletions src/app/services/servers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ServersService{

lastUpdate = -1;
playerCount = 0;
observerCount = 0;

constructor(@Inject(PLATFORM_ID) platformId: string,
private afs: AngularFirestore){
Expand All @@ -32,11 +33,18 @@ export class ServersService{

private setServers(servers: Server[]): void{
this.playerCount = 0;
this.observerCount = 0;

let timestamp = 0;
for(let i = 0; i < servers.length; i++){
this.playerCount += servers[i].playersCount;

const observerTeam = servers[i].teams.find((team) => team.name === "Observer");
if(observerTeam){
this.observerCount += observerTeam.players;
this.playerCount -= observerTeam.players;
}

if(servers[i].timestamp > timestamp){
timestamp = servers[i].timestamp;
}
Expand Down

0 comments on commit 7b6013f

Please sign in to comment.