Skip to content

Commit

Permalink
Update PixelCanvas.io API
Browse files Browse the repository at this point in the history
- `https://pixelcanvas.io/api/ws` doesn't exist anymore
- `pixelcanvas.io/api` is now `europe-west1-pixelcanvasv2.cloudfunctions.net` or similar
- Update pixelcanvas.io.md
  • Loading branch information
Dadido3 committed Jun 14, 2019
1 parent 9441473 commit e2ef03e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 41 deletions.
25 changes: 7 additions & 18 deletions docs/pixelcanvas.io.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Palette(15)\R = 130 : Palette(15)\G = 000 : Palette(15)\B = 128
## HTTPS Post methods

- Draw pixel:
- URL: `https://pixelcanvas.io/api/pixel`
- URL: `https://europe-west1-pixelcanvasv2.cloudfunctions.net/pixel`

- Body: JSON Object:

Expand Down Expand Up @@ -60,7 +60,7 @@ Palette(15)\R = 130 : Palette(15)\G = 000 : Palette(15)\B = 128
| `You must wait` | Wait you must <(-_-)> |

- Me authentication
- URL: `https://pixelcanvas.io/api/me`
- URL: `https://europe-west1-pixelcanvasv2.cloudfunctions.net/me`

- Body: JSON Object:

Expand Down Expand Up @@ -89,9 +89,9 @@ Palette(15)\R = 130 : Palette(15)\G = 000 : Palette(15)\B = 128

- Download chunk collection (15x15 chunks):

- URL: `https://pixelcanvas.io/api/bigchunk/ccx.ccy.bmp`
- URL: `https://europe-west1-pixelcanvasv2.cloudfunctions.net/bigchunk/ccx.ccy.bmp`
With `ccx` and `ccy` being the offset of the chunk collection.
Example: `https://pixelcanvas.io/api/bigchunk/-10.5.bmp`
Example: `https://europe-west1-pixelcanvasv2.cloudfunctions.net/bigchunk/-10.5.bmp`
Make sure to disable any caching for this request.

- Result: Raw image data, 4 bit per pixel:
Expand Down Expand Up @@ -138,30 +138,19 @@ Palette(15)\R = 130 : Palette(15)\G = 000 : Palette(15)\B = 128
- Get online player number:
- URL: `https://pixelcanvas.io/api/online`
- URL: `https://europe-west1-pixelcanvasv2.cloudfunctions.net/online`
- Result:JSON Object:
| Key | Type | Description | Example |
| --- | ---- | ----------- | ------- |
| online | int
- Get websocket URL:
- URL: `https://pixelcanvas.io/api/ws`
- Result:JSON Object:
| Key | Type | Description | Example |
| --- | ---- | ----------- | ------- |
| url | string
## Websocket protocol
### Connect to server
1. Make "Get websocket URL" HTTPS request
2. Connect to WS server: `URL + "/?fingerprint=" + fingerprint`
1. Connect to WS server: `wss://ws.pixelcanvas.io:8443 + "/?fingerprint=" + fingerprint`
The fingerprint doesn't need to be same as sent in the me request. But it needs to be a valid hexadecimal, 32 nibbles long.
The connection will be terminated by the server after half an hour, to get rid of old connections.
Expand Down Expand Up @@ -214,4 +203,4 @@ Idea (Using headless browser with custom page showing a recaptcha):
1. Create some valid fingerprint on start
2. Authenticate with that fingerprint
3. If server requests token, run recaptcha in headless browser (Using the `RECAPTCHA_SITEKEY`)
4. On success, send pixel post request with token
4. On success, send pixel post request with token
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func init() {
log.Fatalf("Can't get working directory")
}

version, err = semver.NewVersion("0.1.0")
version, err = semver.NewVersion("0.1.1")
if err != nil {
fmt.Println(err.Error())
}
Expand Down
27 changes: 5 additions & 22 deletions pixelcanvas.io.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func newPixelcanvasio() (connection, *canvas) {
response := &struct {
Online int `json:"online"`
}{}
if err := getJSON("https://pixelcanvas.io/api/online", response); err == nil {
if err := getJSON("https://europe-west1-pixelcanvasv2.cloudfunctions.net/online", response); err == nil {
atomic.StoreUint32(&con.OnlinePlayers, uint32(response.Online))
log.Debugf("Player amount: %v", response.Online)
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func newPixelcanvasio() (connection, *canvas) {
startTime := time.Now()
log.Tracef("Download at %v started", cc)

r, err := myClient.Get(fmt.Sprintf("https://pixelcanvas.io/api/bigchunk/%v.%v.bmp", cc.X, cc.Y))
r, err := myClient.Get(fmt.Sprintf("https://europe-west1-pixelcanvasv2.cloudfunctions.net/bigchunk/%v.%v.bmp", cc.X, cc.Y))
if err != nil {
log.Errorf("Can't get bigchunk at %v: %v", cc, err)
return
Expand Down Expand Up @@ -252,10 +252,9 @@ func newPixelcanvasio() (connection, *canvas) {
// Any following connection attempt should be delayed a few seconds
waitTime = 5 * time.Second

// Get websocket URL
u, err := con.getWebsocketURL()
u, err := url.Parse("wss://ws.pixelcanvas.io:8443")
if err != nil {
log.Errorf("Failed to connect to websocket server: %v", err)
log.Errorf("Invalid websocket URL: %v", err)
continue
}

Expand Down Expand Up @@ -364,22 +363,6 @@ func (con *connectionPixelcanvasio) getOnlinePlayers() int {
return int(atomic.LoadUint32(&con.OnlinePlayers))
}

func (con *connectionPixelcanvasio) getWebsocketURL() (u *url.URL, err error) {
response := &struct {
URL string `json:"url"`
}{}
if err := getJSON("https://pixelcanvas.io/api/ws", response); err != nil {
return nil, fmt.Errorf("Couldn't retrieve websocket URL: %v", err)
}

u, err = url.Parse(response.URL)
if err != nil {
return nil, fmt.Errorf("Retrieved invalid websocket URL: %v", err)
}

return u, nil
}

func (con *connectionPixelcanvasio) authenticateMe() error {
// TODO: Make threadsafe
request := struct {
Expand All @@ -388,7 +371,7 @@ func (con *connectionPixelcanvasio) authenticateMe() error {
Fingerprint: con.Fingerprint,
}

statusCode, _, body, err := postJSON("https://pixelcanvas.io/api/me", "https://pixelcanvas.io/", request)
statusCode, _, body, err := postJSON("https://europe-west1-pixelcanvasv2.cloudfunctions.net/me", "https://pixelcanvas.io/", request)
if err != nil {
return err
}
Expand Down

0 comments on commit e2ef03e

Please sign in to comment.