PDA

View Full Version : Gameserver Chat to Browser


mazdarx8
07-15-2016, 08:38
Hello,

I need a plugin where the chat shows on homepage.

Example:

[SERVER XYZ] NICKNAME: Text1 Text2
[SERVER XYZ] NICKNAME: Text1 Text2
[SERVER XYZ2] NICKNAME: Text1 Text2

Etc,.

Can anyone help me? :)

Arkarr
07-15-2016, 14:27
What ?

ddhoward
07-15-2016, 18:27
What ?

He wants a plugin that publishes the in-game chat onto a page on his website, probably updating in real time.

Arkarr
07-16-2016, 02:40
He wants a plugin that publishes the in-game chat onto a page on his website, probably updating in real time.
MMmmmMm sockets :D ! I'll try to do it.

EDIT: Sh*t. I don't think there is anyway to do that with only sockets, since PHP is not asynch and NodeJS require a PC to install (so it won't be web-only). Any idea ?

Toastbrot_290
07-17-2016, 03:53
NodeJS and PHP need to be installed, but PHP is allready installed on the most webservers. PHP can do sockets too, but nodejs fits better for that usecase. Although you can use simple HTTP requests and PHP based API.

Arkarr
07-17-2016, 07:32
NodeJS and PHP need to be installed, but PHP is allready installed on the most webservers. PHP can do sockets too, but nodejs fits better for that usecase. Although you can use simple HTTP requests and PHP based API.
I didn't wanted to do it using NodeJs since you can't install it Everywhere. Any exemple about how you would do it only using PHP ?

MFS
07-17-2016, 19:18
Use API GameMe, if TS uses it.

Toastbrot_290
07-18-2016, 17:35
I would set up a REST api using PHP. It wouldn't need many commands. You could call that api within your sourcemod plugin using http requests by curl ext.

ZAGOR
07-19-2016, 16:37
U can see it here (http://www.saigns.de) is there anyone who can?

Deathknife
07-19-2016, 19:09
Why not insert messages into MySQL(either directly or http requests) and then just load the messages on web page with auto-refresh using jquery/ajax?

Arkarr
07-19-2016, 20:09
Why not insert messages into MySQL(either directly or http requests) and then just load the messages on web page with auto-refresh using jquery/ajax?
Bad practice I guess.

Deathknife
07-19-2016, 21:06
Bad practice I guess.
Storing messages in mysql? A lot of shoutboxes work that way, otherwise you could really only see messages from the time you opened it.

DarkDeviL
07-20-2016, 01:00
Why not insert messages into MySQL(either directly or http requests) and then just load the messages on web page with auto-refresh using jquery/ajax?Bad practice I guess.

Well, I'm also very curious about this one...

You seriously have to explain your "bad practice"!

It would be the most obvious way to do it:

- SourceMod plugin inserting data (e.g. steamid, message, playername, etc) into SQL.
- PHP (API) fetching directly from the database
- Some sort of jquery/ajax can indeed be used to update things, by selecting stuff that's newer than what's in the browser already.

Arkarr
07-20-2016, 05:24
Storing message that should be seen only once (it's a chat after all) and query the database every X miliseconds to get those message is bad, I guess.

Socket allow us to send temporary array of bytes, wich is exactly what a chat is doing. For exemple :

PlayerX send "test"
SERVER receive "test"
SERVER send to all other Player "test"

There is no database involved.

Plus, the database will be quickly slower and slower (speaking of miliseconds, wich also mean, more resources and time consumed.) since there will be ALOT of messages / day. Then you might say :
"Well, we could always limit the database to a certain ammount of data, for exemple 10 last messages."
That sound ridiculus, doesn't it ? Database is definitly not the best solution to handle the problem.

Also, using a database just for that require more things to install take more ressources and definitly slower then socket.

But that's my point of view, I don't mean to start any war or anything like that. I might be wrong, and if I am, please point it so I can learn.

Anyway I can't find a way of doing it using sockets and without NodeJS, so I might be definitly wrong.

mazdarx8
07-20-2016, 05:27
Yes like here:
https://www.saigns.de/

I dont have experience in that, I am using xenForo.

DarkDeviL
07-20-2016, 06:54
Storing message that should be seen only once (it's a chat after all) and query the database every X miliseconds to get those message is bad, I guess.

It appears to be "I guess" to everything. Are you sure? :p

Plus, the database will be quickly slower and slower (speaking of miliseconds, wich also mean, more resources and time consumed.) since there will be ALOT of messages / day. Then you might say :
"Well, we could always limit the database to a certain ammount of data, for exemple 10 last messages."
That sound ridiculus, doesn't it ? Database is definitly not the best solution to handle the problem.

Also, using a database just for that require more things to install take more ressources and definitly slower then socket.

I can't seem to figure out the reasons to your claims about being slower either.

Assuming everything goes well, the database will be updated almost insantly with the SQL queries from the SourceMod plugin.

How you choose to update your website is another thing, but you can make jquery/ajax calls do it every second if you like. As quite a few javascripts uses setTimeout(), which are in miliseconds, you can probably do it way faster if you like... It's your call.

But that's my point of view, I don't mean to start any war or anything like that. I might be wrong, and if I am, please point it so I can learn.

Anyway I can't find a way of doing it using sockets and without NodeJS, so I might be definitly wrong.

We all have different point of views, sharing them for each other makes sense, as we can learn from each other that way.

Arkarr
07-20-2016, 07:01
It appears to be "I guess" to everything. Are you sure? :p
Absoluty not. But I'm diggging the subject right now.

EDIT : Using database in this case just doesn't sounds right to me.

DarkDeviL
07-20-2016, 07:04
Yes like here:
https://www.saigns.de/

I dont have experience in that, I am using xenForo.

That one queries https://www.saigns.de/api_serverlog.php every 1.5 second (1500 ms), that outputs the content the "chat" area will be replaced with on success.

If it fails the query for some reason, it will wait for 5 seconds (5000 ms) before next query.

The whole system at http://serverlog.saigns.de/ seems in my opinion to confirm even more that they are most likely selecting their data from a database.

Are you running HLstatsX:CE, or anything similar? HLstatsX.CE keeps the past 28 days of chat logs per default, so if you do, you might already have the chat logging that you could simply fetch out from that database.

Arkarr
07-20-2016, 07:16
@arne1288
Still doesn't mean it's the best solution.

DarkDeviL
07-20-2016, 07:30
Still doesn't mean it's the best solution.

I never said it was the best solution:

But including a million different things to accomplish a very simple goal doesn't sound to be the best solution either, especially when this simple goal just requires 3 out of the 1 million things that your suggestion would requires.

How on earth can that be the best solution?

A car that normally has 4 tyres doesn't necessarily drive better because you manage to fit 8 tyres onto it.

Arkarr
07-20-2016, 07:39
Wait... I thought my solution was simple haha. I think I missunderstood something. Mine solution just require a sourcemod plugin with the extension Socket and a website wich query the server, that's it.

DarkDeviL
07-20-2016, 07:41
Wait... I thought my solution was simple haha. I think I missunderstood something. Mine solution just require a sourcemod plugin with the extension Socket and a website wich query the server, that's it.

And let me guess, you're opening TCP 12345 with the Socket extension at the SourceMod plugin, so the other end ("website") connects to GAME_SERVER_IP at port 12345 whenever it requests the data? (Port 12345 is just an example)

Arkarr
07-20-2016, 08:03
And let me guess, you're opening TCP 12345 with the Socket extension at the SourceMod plugin, so the other end ("website") connects to GAME_SERVER_IP at port 12345 whenever it requests the data? (Port 12345 is just an example)
Yeah. That should do the trick. Correct me if I'm wrong, but that's how Socket work.

DarkDeviL
07-20-2016, 09:14
Yeah ? That should do the trick.

And then someone F5 spamming on your site leads to spamming the game server, leads to server lagging and/or crashes in the end. Just like if someone is flooding your RCON port.

Serious deals are done game servers one place, mysql/website at another place, and done the database way, visitors will only have the ability to flood and possibly affect the performance of your SQL and website servers, not the game server as they will have with your Socket solution.

For people just renting game servers (not virtual servers/machines or dedicated servers), they don't have access to put up firewalls and other things to protect their servers from such stuff.

I see (possible) vulnerabilities the way you want to do it, that won't be there (in the same kind of way, at least) with the database solution.

Arkarr
07-20-2016, 09:36
[...]For people just renting game servers (not virtual servers/machines or dedicated servers), they don't have access to put up firewalls and other things to protect their servers from such stuff.[..]
That's the only real problem. Concerning the spam problem, you simply check wich IP try to connect too much in a specific time span, then you ban or kick it for X seconds.

Deathknife
07-20-2016, 10:25
Storing message that should be seen only once (it's a chat after all) and query the database every X miliseconds to get those message is bad, I guess.

Socket allow us to send temporary array of bytes, wich is exactly what a chat is doing. For exemple :

PlayerX send "test"
SERVER receive "test"
SERVER send to all other Player "test"

There is no database involved.

Plus, the database will be quickly slower and slower (speaking of miliseconds, wich also mean, more resources and time consumed.) since there will be ALOT of messages / day. Then you might say :
"Well, we could always limit the database to a certain ammount of data, for exemple 10 last messages."
That sound ridiculus, doesn't it ? Database is definitly not the best solution to handle the problem.

Also, using a database just for that require more things to install take more ressources and definitly slower then socket.

But that's my point of view, I don't mean to start any war or anything like that. I might be wrong, and if I am, please point it so I can learn.

Anyway I can't find a way of doing it using sockets and without NodeJS, so I might be definitly wrong.

WebSocket might be worth looking into if you want to do it that way. https://forums.alliedmods.net/showthread.php?t=182615

I still think using database would be the way to go. Refreshing once a second is enough, a simple query to select from chat where timestamp is greater than the last. You can purge the chat logs older than 7 days or whatever you wish if you want to keep the table size small.

MySQL is not slow, it can easily handle thousands of queries a second. Speed isn't really a concern here.

With the system you are thinking of, you would only be able to see the messages from the time you connect(i.e open the page), unless you store the messages somehow. Which will look ugly when there isn't enough messages from the time you opened it.


Also, using a database just for that require more things to install take more ressources and definitly slower then socket.If you have a website, you probably already have MySQL and PHP installed, which is probably as much as you need.

When I was playing around with sockets, it only did roughly 4/5 requests a second. (If it can handle more, please correct me) Establishing connection from client directly to server would be definite no in that case, so you would need some sort of server that the gameserver connects to, and any clients. Which would require more things to install.

DarkDeviL
07-20-2016, 10:35
That's the only real problem. Concerning the spam problem, you simply check wich IP try to connect too much in a specific time span, then you ban or kick it for X seconds.

Yes, and you will waste your game server's precious CPU and memory resources, on processing things that are technically irrelevant for the game server to process, meaning that there will be fewer resources available to provide quality servers to your gamers.

Resource hogging things like that aren't on the game server when going the database way, as the end users then won't interfere directly with the game server at all; and you won't waste the resources there.

If they are spamming on the database way, they can only affect your web server and eventually the SQL server, depending on how hefty they are spamming it. The game server won't be affected like it would be otherwise.

Arkarr
07-20-2016, 11:23
Alright, you bought me. I give up.

Yeradon
07-21-2016, 04:56
I like your discussion guys, but i guess you got way to much into detail.

Limiting a port to a certain ip isn't to hard. It also wont cost you a lot of ressources. Sending a database query for each chat entry will. If i would like to dos attack your server, i would just spam the chat (You have Anti-Spam for the chat).

Never mind, there is another reason for using an api instead. Normally you want one centralized input flow into your database. This way you can change authorization, authentification and input rules easier and faster. If you use http, sockets or something different to communicate with that api, is another question. Sockets might be the best way for a realtime application, but i don't know about the sourcemod implementation.

You also can put them directly into the database. It probably will work without any noticeable lags. But it's definitely not the best way to do it. Although it's the easiest.

There two things left to say about the saigns website. First, you don't know how they are getting their logs into that database. Second, there is the problem with the private data. I know that America isn't really worrying about it, but saving the chat log and publishing it (without the usere's permission) is illegal here in Europe.

JM2C.

Arkarr
07-21-2016, 05:02
@Yeradon
Sockets might be the best way for a realtime application
Amen.

I know how to do the sourcemod part, but I have found nothing usefull for the PHP socket part, mind to teach me how you would do it ?

DarkDeviL
07-21-2016, 05:08
I like your discussion guys, but i guess you got way to much into detail.

I also like your participating in the discussion:

But it's definitely not the best way to do it.

Claiming some things are not the best, are "bad practice", ... - but still, you don't explain exactly how you would do it, assuming that you should do it (even though you mention a few ways)...

Interesting.

There two things left to say about the saigns website. First, you don't know how they are getting their logs into that database. Second, there is the problem with the private data. I know that America isn't really worrying about it, but saving the chat log and publishing it (without the usere's permission) is illegal here in Europe.

If you are posting your phone numbers, your name, your address in a Facebook group or page, which everyone can access, then it is your own problem.

Same goes with the game server's "chat", as that is public and everyone can read it in-game. Only kind of privacy setting you have there would be to switch team.

Neither Facebook groups/pages nor the game server chat's are "private messaging".

If you are posting your stuff at public places, and expect things to remain private - then something must be wrong with you.

Yeradon
07-21-2016, 06:19
@Arkaar
If you want to use sockets, I recommend using an async runtime such as nodejs. If you want to use PHP there is a good documentation at php.net.

@arne
I told you why it is a bad practice and what would be good practice. What you want to use is up to you.

Also I am not intrested in a discussion about data privacy, because youre clearly not into that. But there is one hint: A game chat is definitly not a public chat. There was a intresting discussion about privacy at Glizer. Its a global ban system for Minecraft. I don`t want to explain the details, but google will help you with that.

DarkDeviL
07-21-2016, 07:50
@arne
I told you why it is a bad practice and what would be good practice. What you want to use is up to you.

Well, your text didn't clearly state which exact way you would be using.

Also I am not intrested in a discussion about data privacy, because youre clearly not into that. But there is one hint: A game chat is definitly not a public chat. There was a intresting discussion about privacy at Glizer. Its a global ban system for Minecraft. I don`t want to explain the details, but google will help you with that.

I'm not interested in a such discussion either.

We all have opinions about different things, and you are more than welcome to have yours.

But honestly, if you are shouting at a place where there are several other people, even people you don't know and you're still expecting the things you shout out about to remain private, then something is definitely wrong with you.

Deathknife
07-21-2016, 07:58
Limiting a port to a certain ip isn't to hard. It also wont cost you a lot of ressources. Sending a database query for each chat entry will. If i would like to dos attack your server, i would just spam the chat (You have Anti-Spam for the chat).
Sending a database query for each chat entry won't cost you a lot of resources. I think sourcemod has about ~50queries/second limitation, which is more than enough. I'm pretty sure sourcemod has anti spam in chat built in, so that really isn't an issue.


Correct me if I'm wrong here, but with PHP, you can only create a socket and it only lasts when it's getting executed(before sending the content of the page), so that wouldn't really work for chat.

Arkarr
07-21-2016, 08:35
[...] Correct me if I'm wrong here, but with PHP, you can only create a socket and it only lasts when it's getting executed(before sending the content of the page), so that wouldn't really work for chat.
Incorrect. Socket work exactly the same way as in any language. It will wait for a data to be received. BUT in other languages (C# for exemple) you can do multi thread and keep listening for data in a specific thread, that's why it doesn't freeze your program. I don't think PHP handle mutlti threading. That's why it can't be done (smoothly) with PHP only. NodeJS is required and this bother me a lot.

EDIT : Just noticed pthreads

Yeradon
07-21-2016, 08:42
No I didn`t cause that wasn't my intention. I just wanted to point out why this might feel to be a 'bad practice' for arkarr. As I said the `best practice` way would be a centralized api the gameservers could query. This api could save the logs into a database and update the chat client. That has nothing to do with how I would do it.

Its not a point about if something is wrong with me or not. I would not declare a gameserver chat as save for privacy. It is simply the law which is restricting this. Thats why I said its illegal. Short example: You give your bank account details to a stranger. He publishes them. Another stranger takes your money. Now the first stranger can call you a retard for giving him this information. But still he was not allowed to publish them and will get sued for that. I hope you got my point now.

No it doesn't cost a lot of ressources in practice, but compared to a socket request it is more. Yes sourcemod got this limitations. I mentioned that because of arnes comment:
Yes, and you will waste your game server's precious CPU and memory resources, on processing things that are technically irrelevant for the game server to process, meaning that there will be fewer resources available to provide quality servers to your gamers.

Yes you can listen to sockets using php. But since php isn't async you can not react to requests directly. Here is a quote from php.net:
A maximum of backlog incoming connections will be queued for processing. If a connection request arrives with the queue full the client may receive an error with an indication of ECONNREFUSED, or, if the underlying protocol supports retransmission, the request may be ignored so that retries may succeed.

Yeradon
07-21-2016, 08:43
Arkarr what bothers you about nodejs?

Arkarr
07-21-2016, 08:56
Arkarr what bothers you about nodejs?
Not everybody is able to install NodeJS because they don't have a dedicated machine for them, but just gameserver.

Yeradon
07-21-2016, 09:05
Nor will everyone have a socket and thread able php installation (This features are deactivated by many webhosts). I as a private programmer wouldn't give a shit. Don't use php for smth it isn't made for. If people want to use certain features they will find a way. It really isn't to hard to setup a nodejs env and it can be done for free.

Arkarr
07-21-2016, 09:13
Nor will anyone have a socket and thread able php installation (This features are deactivated by many webhosts). I as a private programmer wouldn't give a shit. Don't use php for smth it isn't made for. If people want to use certain features they will find a way. It really isn't to hard to setup a nodejs env and it can be done for free.
Oh well... if you think so. I'll do it the NodeJS way then.

DarkDeviL
07-21-2016, 10:13
No it doesn't cost a lot of ressources in practice, but compared to a socket request it is more. Yes sourcemod got this limitations. I mentioned that because of arnes comment:

That comment might require further explanation to you:

Yes you can listen to sockets using php. But since php isn't async you can not react to requests directly. Here is a quote from php.net:

Wait... I thought my solution was simple haha. I think I missunderstood something. Mine solution just require a sourcemod plugin with the extension Socket and a website wich query the server, that's it.And let me guess, you're opening TCP 12345 with the Socket extension at the SourceMod plugin, so the other end ("website") connects to GAME_SERVER_IP at port 12345 whenever it requests the data? (Port 12345 is just an example)

Yeah. That should do the trick. Correct me if I'm wrong, but that's how Socket work.

There Arkarr confirmed that the listening socket would be in the SourceMod plugin, and that SourceMod plugin would be listening, for example on TCP 12345, and the website would query that.

Even if you build in restrictions on the SourceMod plugin, like limiting the queries to specific IP addresses, the game server will have to process each individual thing that way, just like it has been the cause with flooding the game server's RCON port.

Last time I checked, GSP's did not provide access to make firewall restrictions. Therefore, that way would possibly expose the server to new attacks by overloading that port with crap.

However, if the SourceMod plugin is connecting in outbound direction (e.g. to a TCP port opened in PHP, or something), then what Arkarr confirmed above, isn't correct, and there would somehow be less to worry about.


Another thing to consider would also be the fact that SourceMod is shipped with MySQL support, and that the Socket extension is a third party extension, you are more likely to receive fixes for the MySQL support in case anything would break. There is no guarantee the author of third party extensions will keep them updated, it has been seen with quite a lot of plugins already...

Arkarr
07-21-2016, 10:21
[...]
There Arkarr confirmed that the listening socket would be in the SourceMod plugin, and that SourceMod plugin would be listening, for example on TCP 12345, and the website would query that.
[...]

Correct. But since I'll do it with NodeJS now, the server (the one wich will process the messages) won't be the game server but NodeJS, and indeed that's better, like you said above.


[...]
Another thing to consider would also be the fact that SourceMod is shipped with MySQL support, and that the Socket extension is a third party extension, you are more likely to receive fixes for the MySQL support in case anything would break. There is no guarantee the author of third party extensions will keep them updated, it has been seen with quite a lot of plugins already...
[...]

Then, I guess, I'll do my own socket extension.

KissLick
07-21-2016, 14:04
I guess you can use this (https://forums.alliedmods.net/showthread.php?t=270962) and make AJAX loading it into some box.

asherkin
07-21-2016, 16:26
Or just have SM serve the websockets. (https://forums.alliedmods.net/showthread.php?t=182615)

Sneak peak:
I have an almost completed extension (PoC done and heavily tested, production front-end done, need to finish the production backend) that does this and voice chat and more.
The funding for it disappeared so it's on the back burner as work is busy.

Arkarr
07-21-2016, 17:33
@Asherkin
Oh wow I didn't know this extension ! That's freaking cool ! But I don't think my version would any better then yours, I'll wait until you release it.

asherkin
07-21-2016, 17:37
Please don't, I don't know when it'll be done and it's good to have a plugin-only option for people!

Arkarr
07-21-2016, 17:46
Please don't, I don't know when it'll be done and it's good to have a plugin-only option for people!
I'll try then.

mazdarx8
08-17-2016, 04:58
Any news on this ?? : )

Arkarr
08-17-2016, 05:54
ETA:
Created index.php (file size: 0 octect)

In other words, I did nothing. Mostly because I totally forgot it. I'll try something this week.

mazdarx8
08-17-2016, 05:57
ETA:
Created index.php (file size: 0 octect)

In other words, I did nothing. Mostly because I totally forgot it. I'll try something this week.

No rush. Thank you.

Arkarr
08-17-2016, 07:57
No rush. Thank you.
Finished the connection. Doing a nice (I suck at design) user interface.

mazdarx8
08-18-2016, 08:41
Finished the connection. Doing a nice (I suck at design) user interface.

I am excited :)
I would integrate this in my xenforo, but I really dont know how to do that lol

mazdarx8
08-18-2016, 08:47
And it would be nice if it looks like this:

[SERVERNAME] [NICKNAME | STEAMID] : CHAT TEXT [12:00:00 >> TIME]

and if someone join / left server:

NICKNAME | STEAMID joined SERVERNAME.


And if admins (when they have a special flag or rcon password, dont know whats easier?) can choose a server (or write in ALL servers) and can type there too..
like:
(ADMIN) TEXT

in a colour.

Thanks.

Arkarr
08-18-2016, 09:28
That's some detail you ask there, sure I will do some of them, but for now...
Let's say it looks like a car... with out windows... without colors.... without tires.

EDIT: Take a look (changes happening live) : http://tf2serverofarkarr.ddns.net/websocket/

mazdarx8
08-18-2016, 09:53
Didnt work for me? (Login with my account)

Arkarr
08-18-2016, 10:02
Didnt work for me? (Login with my account)
I told ya, I'm doing live modification. It works fine.... for now.

mazdarx8
08-18-2016, 11:16
No problem, I will try later again.