# Geoguessr Self-Hosted Reimplementation

[![Build Status](https://drone.hiram.services/api/badges/kirkleon/terrassumptions/status.svg)](https://drone.hiram.services/kirkleon/terrassumptions)

## API

```
API Endpoints
GET /health
    Returns 200 and {
        "version": string,
        "status": string
    }
POST /score
    Accepts {
        "point1": {
            "lat": number,
            "lng": number
        },
        "point2": {
            "lat": number,
            "lng": number
        }
    }
    Returns 400 or 200 and {
        "score": number,
        "distance": number
    }
GET /caches
    Returns 200 and {
        "caches": [
            {
                "generationMethod": string,
                "countryLock": string || null,
                "size": number
            }, ...
        ]
    }
GET /generators
    Returns 404 vs 200 and {
        "generators": [
            {
                "generationMethod": string,
                "countryLocks": [ string ],
            }
        ]
    }
PUT /game
    Accepts {
        "timer": number,
        "rounds": number,
        "countryLock": string || null (default: null),
        "generationMethod": string (default: "RANDOMSTREETVIEW"),
        "ruleSet": string (default: "NORMAL")
    }
    Returns 501 vs 200 and {
        "gameId": string
    }
GET /game/{game_id}/config
    Returns 404 vs 200 and {
        "timer": number,
        "rounds": number,
        "countryLock": string || null,
        "generationMethod": string,
        "ruleSet": string
    }
GET /game/{game_id}/coords
    Returns 404 vs 200 and {
        "1": {
            "lat": number,
            "lng": number,
            "country": string || null,
        }, ...
    }
POST /game/{game_id}/join
    Accepts {
        "playerName": string
    }
    Returns (404, 409) vs 201 and {
        "playerId": string
    }
GET /game/{game_id}/players
    Returns 404 vs 200 and {
        "players": [
            {
                "name": string,
                "currentRound": string || null,
                "totalScore": number,
                "guesses": {
                    "1": {
                        "lat": number,
                        "lng": number,
                        "country": string || null,
                        "score": number || null,
                        "timeRemaining": number
                    }, ...
                }
            }, ...
        ]
    }
GET /game/{game_id}/players/{player_id}/current
    Returns 404 vs 200 and {
        "currentRound": string || null,
        "coord": {
            "lat": number,
            "lng": number,
            "country": string || null,
        } || null,
        "timer": number || null
    }
GET /game/{game_id}/linked
    Returns 404 vs 200 and {
        "linkedGame": string || null
    }
PUT /game/{game_id}/linked
    Accepts {
        "linkedGame": string
    }
    Returns (401, 404) vs 201
GET /game/{game_id}/round/{round}/first
    Returns 200 and {
        "first": string || null
    }
POST /game/{game_id}/round/{round}/guess/{player_id}
    Accepts {
        "timeRemaining": number,
        "lat": number,
        "lng": number,
        "country": string || null (default: null),
    }
    Returns (404, 409) vs 201 and {
        "totalScore": number,
        "score": number,
        "distance": number
    }
POST /game/{game_id}/round/{round}/timeout/{player_id}
    Returns (404, 409) vs 201 and {
        "totalScore": number
    }
```

## Next Steps

### Planned Game Modes

None currently! Submit ideas!

### Code/Design Improvements

#### UI/UX

- Rotation in Frozen mode
- Improved alert of cut off in Race mode
- Improve error handling in UI
- Override google controls in streetview, make custom divs

#### Server
- Convert back-end to use a real db (persistence between deployments not necessary for now)
- Use alembic to manage db migrations in real persistent db
- Timestamps/hashes in info responses so checks can be faster
- Convert to a socket-based api, to allow timing to be server-side

## Attributions

Urban game data is based on the [World Cities Database](https://simplemaps.com/data/world-cities)
