I would like to ask whether it is possible to make a list of online users of the server, without direct access to the server and only knowing the IP?
You could always listen for join/disconnect events and add/remove players to (for example) an āonline_usersā table, then just grab that information to display on your website.
AFAIK, thereās a JSON file that is exposed to the internet that already holds this information.
It should be at ip:port/players.json
so, if the server is on your local machine (and is using the default ports) it should be available at 127.0.0.1:30120/players.json
Hmm, unreachable for me in a local environment.
I believe @Havoc made a typo. The port 3020 doesnāt work for me either, although the port 30120 (my server port) does work.
facepalm That would explain why that port didnāt look right for some reason. I guess that makes things simple, just read from that file for displaying on the website. Haha
The other way you could get a the players online on a server is to filter through another json file. This file doesnāt get updated instantly when players join or quit though, but it updates quite often.
I use that json file on my own serverlist. Using some jQuery and simple javascript you can easilly filter a json file from that URL. This one is especially nice because you get a lot more info about a server than just the players online. (things like max players, resources, variables like scripthook etc.)
Just tried accessing that players.json file. It works, but only when you go to it in a browser. If you try to use javascript to get the json file you get a no Access-Control-Allow-Origin header error. This wonāt be a problem if youāre hosting the site on the same machine as your server is hosted on. However this will be a problem if you host your site on another machine. Because your scripts wonāt have access to the json fileā¦ Any possibility that the FiveM team changes this and allows for anyone to access the json files form the http server @Havoc ?
Hmmā¦
Well, Iāve had a look at the source code on Github and havenāt found that theyāre explicitly setting the Access-Control-Origin-Allow
header. So, I can only assume youāre getting this error because of browser security (yeah, they have security ). Thereās a StackOverflow question which may be better suited to answer your question on doing cross-domain requests.
All in all, if you do it right, you should be able to access the information on a separate server.
If not, thereās a new native which should be useful to be able to create your own player list (you should be able to add more information to it).
Alright thanks for the reply. It must be something with Google Chrome then. The runtime server list works just fine so thatās all I need anyway. But I wonāt go off topic any furtherā¦
Wow, Iām opening an old can of worms here. Iāve been trying everything but I am running into the same CORS error when in my app (Reason: CORS header āAccess-Control-Allow-Originā missing). It works fine in Postman and fine in the browser. I also setup a resource that returns a playercount when going to or calling http://IP:PORT/resourcename/playercount.
Again, it works fine both in postman and in browser, but trying to call it using angulars HttpClient is no good.
EDIT: Itās just an issue when running in dev mode - once the app is packed up it works fine. Iām guessing itās a webpack thing but Iām not exploring it further.