How do i get all the data passing in WebSocket - javascript

I want to know how to get all the data passed on the WebSocket
I alredy tryied using FireFox to see but all the data are strange unicode text and symbols (game link is https://sploop.io) is there an way to maybe decrypt it?
I also tryied using
var data= new WebSocket("usa1.sploop.io/ws")
data.onmessage = (sa)=>{console.log(sa)}
And after some actions in the game the code logged an object that didnt have any of the data...

You're already getting all the data the WebSocket is receiving. The problem is that the data is "encoded" binary data using the game's protocol. The scripts in Sploop.io know how to decode this data (and encode new data to be sent back), but since you don't "speak" that protocol, it looks like gibberish to you.
Problem aside, you can have fun and all, but trying to cheat or so isn't nice towards other players.

Related

The use of json.parse in the JS part of wechat applet

Development tools: wechat developer tools Windows 10 system.
Function Description: This is a part of the code that uploads a picture to the server and returns the image ID and URL. I print out the result of the process and put it in the second picture.
Problem Description: I don't understand why the return value of successful upload needs to be processed with json.parse. I can't get the data directly through res.data.data.id. the developer tool will report an undefined error.
Specific introduction: according to my query data, JSON. Parse () method is generally a string when receiving server data, and converts the data into JavaScript objects. My own understanding is that according to the print result of line 861 in my second picture, I think the res.data I get is a string of data, which needs to be converted into a JSON object through json.parse before I can get data through the converted JSON object.
If my understanding is correct, I would like to ask if the back-end development can encapsulate res.data.data as a JSON object at the beginning, so that the front-end does not need the transformation steps( Because I used to get data through res.data.data, I was not sure about my understanding when I encountered this kind of error information for the first time. Thank you!

Is it good to store data in JSON files

I have a Discord bot that has about 50,000 users, but the question here is, is it good if I store data by Json file or not Because I'm currently doing this, but sometimes everything in JSON automatically deleted and The file becomes empty. i I don't know why, is JSON not dedicated to the huge amount of data Some examples of data that I store Like the ID of the server members, and also servers id
The problem with JSON file, is when multiple users try to edit the same information at the same time... you have to think about which update will persist... all except for one will get overwritten by the update that was last submitted.
JSON is basically used to send and receive data from user and server, it is seldom used to store data, sometimes it does but not often.
For a dataset of 50k user consider using MySQL, it would be much easier to handle data.

How to send binary data back to client using GraphQL

I have a GraphQL server, hosted on express. I want to return images to the client by sending back nodejs buffer objects. How can i config graphql server, to return bytes, instead of json? I don't wish to do this through base64, as the image are large in size.
You have to return JSON, but there's still a way. We're using GraphQL to return images stored in Blob fields in a legacy sql database. We're using sequelize, graphql-sequelize, and graphql-js.
We've defined the Blob fields to be String types in our graphql schema and so they come through in the json reply just fine.
Then we convert to a buffer before delivering, like
const imgBuffer = new Buffer.from(imgObj.data, 'ascii');
The only problem is we're now having trouble saving image data back to the database via the graphql interface. Our mutation function gives us a syntax error when it finds certain bad unicode characters in the strings, like \U0000 and whatnot (so I found your question looking for a solution to that).
There's a way, but it's complicated, and very manual, and I'm only going to give you an overview of what I've done in ApolloServer, but I think it should be enough.
First, you need to use the "Accept" header in your request to send a binary mime type, and send a matching "Content-Type" in your response. This is nessisary to be efficient, but not nessisary to work, as you'll see (with EJSON).
To serialize and deserialize respecting the headers you may need to write an express middleware, and you'll need to handle base64 encoding with a {$data: "..."} encapsulating object (as EJSON does) or just (strangely) returning null, if someone makes a request for binary data using "application/json" for their "accept" header. You'll also want to choose what binary formats that you'll support. I only use 1: "application/x-msgpack", but I hear that "application/cbor" is becoming more popular. You can use a library for EJSON, MessagePack, and CBOR to do your serialization, so this isn't as hard as it sounds.
I would then strongly recommend using the #defer on any images. See this post for more information on #defer: https://www.apollographql.com/blog/introducing-defer-in-apollo-server-f6797c4e9d6e/
I've done it. It wasn't easy, and it would be better if ApolloServer worked this way "out of the box".
It's better to send a hashed & temporary link to download it
The URL can be hashed to be non-accessible by other users.
Backend can expire the link or remove the binary file on the static server.
There might be an answer to your question by using the node module found here.

Passing JSON Through URL

I have two html files, and the task for us is to pass data between the two. Then I came up with the idea of sending the data through the URL using the hash, and parsing this link something like JSON.parse(window.location.hash.slice(1)); and assigning it to a local variable. It seems to work for the couple try. But when I populated my JS files with codes error occurs. Can you tell what alternative can I do.? Here's the console errors. I'm using jquery by the way ..
The Console Error
Thank you!
JSON contains a number of characters that are not legal in urls.
A simple way around this could be to simply encode the JSON data using Base64.
You can use the latest way of accessing the data from one page to another:
//1st page
storage["key"]=data;
//2nd page
var value= storage["key"];
I think jQuery.param is what you need it converts a Json into a URL String
http://www.sourcecodemart.com/convert-json-object-to-url-query-string/
This won't work in the long run. urls are limited to about 2000 characters. What is the maximum length of a URL in different browsers?
You have to base64 encode the json to have it live in the URL. This eats up a lot of the available characters.
You don't get the same limitations when doing POST requests but a HTML page can't access post requests.
You might want to look at postMessage and embedding one page in the other in an iframe to do cross communication.
Also if the urls are on the same domain, just use local or session storage.

Get data from URL, or possibly ajax?

I was wondering how I can get data from the server side that is being passed to my page via encrypted url using java script? Let say I have this in visual basic in my code behind,
lnkToAPage.NavigateUrl = RelativePagePaths.ThePage + "?"+ QueryStringModule.Encrypt("PageMode=" + pageMode ...
I need to extract a piece of that data, which I get from an object on the server, to do something with it on the client side using javascript. I understand I can get the data from the url like it says here
but the data in the url is encrypted so the data I get from there is useless, I can send it without the encryption but that exposes to much. So is there a way I can use ajax to retrieve that data or object, or maybe there's another way? Or is it not possible at all?
I am not aware of what encryption protocol you are using, but if you get an encrypted version of your attributes, you need to decrypt it using the same protocol with javascript.
On the web, it is common practice (and a good one) to encrypt the connection using HTTPS. it protects anyone from seeing the parameters as explained here.
This does not seem to be an ajax related problem (from what I understood of the question).

Categories