I'm making an anti-spam addon and I was trying to implement a logging system that is viewable from my GUI. I can't figure out how to make the logging system store the logs in a way that I can "net" them to the GUI. I'm a beginner to all glua net functions. Any and all help is appreciated.
Well, how are they stored at the moment? Also, [URL="https://wiki.garrysmod.com/page/Net_Library_Usage"]this tutorial might help a bit[/URL]
[QUOTE=MPan1;49967752]Well, how are they stored at the moment? Also, [URL="https://wiki.garrysmod.com/page/Net_Library_Usage"]this tutorial might help a bit[/URL][/QUOTE]
At the moment it's stored in a file, but I think I should store it in a table so I could send it through net easily.
If they're in a file, you could probably do something like this:
[CODE]
-- serverside
util.AddNetworkString( 'Send_File_Contents' ) -- add a new network string thing you can use to send net messages
-- call this stuff below when a client requests to get the file's contents
local filecontents = file.Read( 'somefile', 'somefilepath' ) -- read your file's contents
net.Start( 'Send_File_Contents' ) -- start a new net message using the network thing that you added earlier
net.WriteString( filecontents ) -- write the file's contents to the net message (THIS HAS A LIMIT OF 65533 CHARACTERS - if you want to send more than that you'll have to split the string up)
net.Send( someplayer ) -- send it to some player
-- clientside
net.Receive( 'Send_File_Contents', function() -- this gets called once the player receives the message sent from before
local filecontents = net.ReadString() -- read the file's contents that got written before
-- do stuff with the contents
end )
[/CODE]
[QUOTE=MPan1;49967912]If they're in a file, you could probably do something like this:
[CODE]
-- serverside
util.AddNetworkString( 'Send_File_Contents' ) -- add a new network string thing you can use to send net messages
-- call this stuff below when a client requests to get the file's contents
local filecontents = file.Read( 'somefile', 'somefilepath' ) -- read your file's contents
net.Start( 'Send_File_Contents' ) -- start a new net message using the network thing that you added earlier
net.WriteString( filecontents ) -- write the file's contents to the net message (THIS HAS A LIMIT OF 65533 CHARACTERS - if you want to send more than that you'll have to split the string up)
net.Send( someplayer ) -- send it to some player
-- clientside
net.Receive( 'Send_File_Contents', function() -- this gets called once the player receives the message sent from before
local filecontents = net.ReadString() -- read the file's contents that got written before
-- do stuff with the contents
end )
[/CODE][/QUOTE]
So how could I check if the file has reached the character limit and if it has then split it into multiple sends?
When something you want to log happens, store it in a table - send that table to the client when they request to open the menu?
It'd be pretty easy if you were using a database.
You'd have a table for your logs:
log_num | log_timestamp | < any other fields >
log_num would be an autonumber, log_timestamp would be the current time and date when the log event occurs, and you'd have any other fields needed, like a player's id, the model, etc.
Then, you would be able to query the results:
If just paging through all logs since forever:
[code]data = sql.Query( string.format( "SELECT * FROM antispam_log ORDER BY log_num WHERE log_num > %d LIMIT %d;", num_per_page * ( page_number - 1 ), num_per_page ) )[/code]
If looking at all logs between two times:
[code]data = sql.Query( string.format( "SELECT * FROM antispam_log ORDER BY log_num WHERE log_timestamp BETWEEN %s AND %s AND log_num > %d LIMIT %d;", SqlStr( mindate ), SqlStr( maxdate ), num_per_page * ( page_number - 1 ), num_per_page ) )[/code]
You have to then deal with using time in a [url=https://www.sqlite.org/lang_datefunc.html]form that sqlite understands[/url]
The big thing is that you are paginating the data so the player only sees N records at once - this means you can tailor your net message to ensure it will always fit inside:
[code]
data = sql.Query( "query between dates here", ... )
net.Start( "message name" )
net.WriteUInt( #data, 16 ) --0 to 65535 rows
for k, v in ipairs( data ) do
net.WriteUInt( v.log_num, 32 )
net.WriteString( v.log_timestamp )
--Any other fields you want to send
end
net.Send( requester )
--On the client:
net.Receive( "message name", function( )
local data = { }
local t
for k = 1, net.ReadUInt( 32 )
t = { }
t.RowNumber = net.ReadUInt( 32 )
t.TimeStamp = net.ReadString( )
...
data[ k ] = t
end
DoSomethingWithData( data ) --Fill a listview, etc
end )[/code]
[QUOTE=Kogitsune;49967970]It'd be pretty easy if you were using a database.
You'd have a table for your logs:
log_num | log_timestamp | < any other fields >
log_num would be an autonumber, log_timestamp would be the current time and date when the log event occurs, and you'd have any other fields needed, like a player's id, the model, etc.
Then, you would be able to query the results:
If just paging through all logs since forever:
[code]data = sql.Query( string.format( "SELECT * FROM antispam_log ORDER BY log_num WHERE log_num > %d LIMIT %d;", num_per_page * ( page_number - 1 ), num_per_page ) )[/code]
If looking at all logs between two times:
[code]data = sql.Query( string.format( "SELECT * FROM antispam_log ORDER BY log_num WHERE log_timestamp BETWEEN %s AND %s AND log_num > %d LIMIT %d;", SqlStr( mindate ), SqlStr( maxdate ), num_per_page * ( page_number - 1 ), num_per_page ) )[/code]
You have to then deal with using time in a [url=https://www.sqlite.org/lang_datefunc.html]form that sqlite understands[/url]
The big thing is that you are paginating the data so the player only sees N records at once - this means you can tailor your net message to ensure it will always fit inside:
[code]
data = sql.Query( "query between dates here", ... )
net.Start( "message name" )
net.WriteUInt( #data, 16 ) --0 to 65535 rows
for k, v in ipairs( data ) do
net.WriteUInt( v.log_num, 32 )
net.WriteString( v.log_timestamp )
--Any other fields you want to send
end
net.Send( requester )
--On the client:
net.Receive( "message name", function( )
local data = { }
local t
for k = 1, net.ReadUInt( 32 )
t = { }
t.RowNumber = net.ReadUInt( 32 )
t.TimeStamp = net.ReadString( )
...
data[ k ] = t
end
DoSomethingWithData( data ) --Fill a listview, etc
end )[/code][/QUOTE]
This would be nice to have my addon work with a database but I'm what you could call, "Database challenged." I can make a website but if databases are required I'm useless.
Sorry, you need to Log In to post a reply to this thread.