Log Chat with MYSQL == Too Demanding?
#1

Is it too demanding for a server to INSERT every line of chat into a MySQL database for logging purposes?

Yes / No? Ideas?
Reply
#2

Quote:
Originally Posted by cAMo
Is it too demanding for a server to INSERT every line of chat into a MySQL database for logging purposes?

Yes / No? Ideas?
No. Inserts are not that bad, i know of 4 servers that use MySQL to log chat / other player events, and they handle it with ease. If you do add the chat logging though, i'd add a flood protection script.


EDIT:

Here's a little flood protection i whipped up, its pretty simple.

Код:
#include <a_samp>

#define MAX_WARNINGS 5 //warnings before a kick
#define CHAT_LIMIT 5 //seconds before they can send another message


enum E_FLOOD
{
	Tick,
	Warnings
}

new AntiSpam[MAX_PLAYERS][E_FLOOD], String[128];

public OnFilterScriptInit()
{
	print("\n**************************************");
	print("--------------------------------------");
	print("|   Kyoshiro's AntiSpam Loaded!!  |");
	print("--------------------------------------");
	print("**************************************\n");
}

public OnPlayerText(playerid, text[])
{
	if(GetTickCount() - AntiSpam[playerid][Tick] <= CHAT_LIMIT * 1000)
	{
		new seconds = CHAT_LIMIT-(GetTickCount() - AntiSpam[playerid][Tick])/1000;

		format(String, sizeof(String), "Please wait %d %s to talk! Warning %d of %d!!",seconds,(seconds==1)?("second"):("seconds"),AntiSpam[playerid][Warnings]+1, MAX_WARNINGS);
		SendClientMessage(playerid,0xFF0000FF,String);

		AntiSpam[playerid][Warnings]++;

		if(AntiSpam[playerid][Warnings] >= MAX_WARNINGS)
		{
			SendClientMessage(playerid, 0xFF0000FF, "You were kicked for flooding the chat!!");
			Kick(playerid);
		}
		return 0;
	}
	AntiSpam[playerid][Tick] = GetTickCount(), AntiSpam[playerid][Warnings] = 0;
	return 1;
}
Reply
#3

I'm not too familiar with GetTickCount, but I did look it up.

Would GetTickCount be better than doing something like:

OnPlayerText
{
if(String_Count < 5)
{
String_Count ++;
return 1;
}
else
{
return 0;
}
}

Then have a 1 second timer:
String_Count --;


Note: Obviously this doesn't work, but which method would you recommend? Timer or Tick?
Reply
#4

Quote:
Originally Posted by cAMo
I'm not too familiar with GetTickCount, but I did look it up.

Would GetTickCount be better than doing something like:

OnPlayerText
{
if(String_Count < 5)
{
String_Count ++;
return 1;
}
else
{
return 0;
}
}

Then have a 1 second timer:
String_Count --;


Note: Obviously this doesn't work, but which method would you recommend? Timer or Tick?
Definitely GetTickCount, or gettime.


EDIT:

I dont know what your doing with that code, when i said flood protection, i mean make it so they cant come on your server with a little VB script and spend a ton of messages.
Reply
#5

Do you do the same with OnPlayerCommandText?
Reply
#6

Quote:
Originally Posted by cAMo
Do you do the same with OnPlayerCommandText?
Yes, i use that flood control script, and also log my chat as well.
Reply
#7

If you Store Chat Text to an SQL table, its going to pack VERY fast ...

In a few days, that SQL database is going to be SOOO massive that your going to have issues, especially if your using Cron Tabs to do Auto SQL backups.

I Strongly Suggest that you use File Based Logging for Chat Recording ... you can just as easily parse a file to a website as you can stream SQL to a website.
Reply
#8

Quote:
Originally Posted by Bayler
If you Store Chat Text to an SQL table, its going to pack VERY fast ...

In a few days, that SQL database is going to be SOOO massive that your going to have issues, especially if your using Cron Tabs to do Auto SQL backups.

I Strongly Suggest that you use File Based Logging for Chat Recording ... you can just as easily parse a file to a website as you can stream SQL to a website.
MySQL and massive loads go hand and hand lol. One of the server's i used to, lets say "manage", used the native sqlite and had pretty bad issues with such load, the second they switched over to MySQL every thing was peachy. They had over a million logs which wasn't including race statistics, objects/vehicles/hidden packages, nor anything player related. It ran smooth, and saw no problems with such a massive database.

Personally my server only has about 50000 logged events, and it too is doing just fine.

The worst thing you can do is use files for storing LARGE amounts of data, writing and reading from them can be a pain. Its a lot better to use a MySQL plugin or the native sqlite for logging large amounts of information.


Reply
#9

i dont know, id have to debate that one ....

Storage in SQL is Great, so long as your not having to Load THAT large a list .... And chat is going to be Large ..probably the largest of any table hes going to be using, times about 50 billion.

Dont get me wrong, The GM im using is 99% SQL based .... and i FULLY support his use of it..

However, if hes Loggin Chat ... then chances are, hes gonna be parsing it to display it some place. I Use a Web Based Log Viewer ... and it seems Far Less Trouble to simply grab a text file from the Game Server via a CronTask every 5 mins and copy it to the web server. Now that said, i small function can be used to write the file to a unix time stamp and name the file being saved.

Your ending result is a list of files per day stored in 5 min intervals... and a PHP load time of about 0.8 sec on .txt format even if 500 players are chatting as fast as they can for 5 mins.

This solves the need for additional 'Chat Spam' precautions, as well as the ONLY stress on the Game server is a file writer. Since your running a CronTab, its what, 1 Line on AN ?? and its auto, and he can use his web server Cpanel to run it.
Reply
#10

Just use threads when inserting in log tables. MySQL server is made to go in GBs and bigger, so with proper database structure and relations it shouldn't be a problem to handle all the logs.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)