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