-
Create WebSocket and set binaryType =
"arraybuffer"
; -
Registration:
/** Think about cool participant name and then send a registration message **/ { "name":"SuperHero", "command": "challenge accepted" }
-
The server will respond with:
/** Message contains an authentication token which you will attach to your messages for identification and the next task name. **/ {"message":"You successfully accept challenge","next":"arithmetic","token":"eae34860c6f507f2"}
-
Request the next task with:
{ "token": my_saved_token, "command": saved_next_task_name }
There are 3 simple tasks:
{"name":"arithmetic","task":{"sign": OPERATION ,"values": ARRAY}} /** where: ARRAY {Array} numbers array, length = 4; OPERATION {String} random operator (+, -, *) which corresponds to an arithmetic operation you have to perform with ARRAY values and then send answer with: **/ { "token": my_saved_token, "command": "arithmetic", "answer": RESULT }
/** if answer is correct, server will respond with: **/ { "message":"You solve task","nextTask":"function_evaluation" } /** request the next task with: **/ { "token": my_saved_token, "command": saved_next_task_name }
2nd task:
/** Server will send you the following message **/ { "name":"function_evaluation","task": { "fn": STRING } } /** where STRING is String representation of function. --------------------------------------------- you have to somehow execute this function and send it's result **/ { "token": my_saved_token, "command": "function_evaluation", "answer": RESULT }
/** if RESULT is correct, server will respond with **/ { "message": "You solve task", "nextTask": "binary_arithmetic" }
3nd task:
/** Server will send you the following message **/ { "name":"binary_arithmetic","task": { "bits": BITS} } /** where BITS is either 8 or 16. --------------------------------------------- Immediately after that you should receive a binary message (16 bytes) which you should treat as a Uint8Array or Uint16Array depending on the bits field. Your task is to sum the resulting array's elements and send the result: **/ { "token": my_saved_token, "command": "binary_arithmetic", "answer": RESULT }
/** if RESULT is correct, server will respond with **/ { "message": "You solve task", "nextTask":"win" }
And finish the challenge!
/** Request the win! **/ { "token": my_saved_token, "command": "win" }
igor-provotorov / wsc Goto Github PK
View Code? Open in Web Editor NEWThis project forked from 21-23/wsc
WebSocket Challenge
License: MIT License