Online list in site

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?

1 Like

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.

1 Like

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.

1 Like

I believe @Havoc made a typo. The port 3020 doesnā€™t work for me either, although the port 30120 (my server port) does work.

2 Likes

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

1 Like

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.)

1 Like

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 ?

1 Like

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 :wink:). 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).

1 Like

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ā€¦ :wink:

1 Like

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.

1 Like