User Logger for RMX-OS
Authors: Blizzard
Version: 1.2
Type: RMX-OS Plugin
Key Term: RMX-OS Plugin
IntroductionThis script adds a logging feature to the RMX-OS server. It displays users that connect and the current number of users online.
This script is to be distributed under the same terms and conditions like the script it was created for: RMX-OS.
Features
- logs client connections and disconnections
- can display log in command prompt window
- can write log to file
- can write online users list to file (users are separated with commas)
Screenshots(http://img171.imageshack.us/img171/2564/snap055.th.png) (http://img171.imageshack.us/img171/2564/snap055.png)
DemoN/A
ScriptMake a new file with an
.rb extension in the
Extensions folder of RMX-OS and copy-paste this script into it.
module RMXOS
def self.load_current_extension
return UserLogger
end
module Data
CurrentUsersOnline = 'Users currently online: NOW / ALL'
ClientConnected = 'Client \'CLIENT\' has connected.'
ClientDisconnected = 'Client \'CLIENT\' has disconnected.'
OnlineListNotCreated = 'Warning: Online list could not be created this time!'
end
end
#======================================================================
# module UserLogger
#======================================================================
module UserLogger
VERSION = 1.2
RMXOS_VERSION = 2.0
SERVER_THREAD = true
IDENTIFIER = 'User Logger'
# START Configuration
SERVER_DISPLAY = true # show log in command prompt screen
LOG_FILENAME = 'logs/users.log' # leave empty if no log file should be created
ONLINELIST_FILENAME = 'online.txt' # leave empty if no online user list should be generated
DELETE_LOG_ON_START = false
# END Configuration
def self.initialize
@mutex = Mutex.new
@clients = []
if LOG_FILENAME != ''
File.delete(LOG_FILENAME) if DELETE_LOG_ON_START && FileTest.exist?(LOG_FILENAME)
end
RMXOS::Logs[IDENTIFIER] = LOG_FILENAME
end
def self.mutex
return @mutex
end
def self.main
while RMXOS.server.running
@mutex.synchronize {
self.server_update
}
sleep(0.1)
end
end
def self.server_update
logged_in_clients = RMXOS.clients.get
new_clients = logged_in_clients - @clients
old_clients = @clients - logged_in_clients
if new_clients.size > 0 || old_clients.size > 0
@clients = logged_in_clients
time = Time.now.getutc.to_s
displays = []
new_clients.each {|client|
displays.push(RMXOS::Data.args(RMXOS::Data::ClientConnected, {'CLIENT' => client.player.username}))
}
old_clients.each {|client|
displays.push(RMXOS::Data.args(RMXOS::Data::ClientDisconnected, {'CLIENT' => client.player.username}))
}
displays.push(RMXOS::Data.args(RMXOS::Data::CurrentUsersOnline, {'NOW' => @clients.size.to_s, 'ALL' => MAXIMUM_CONNECTIONS.to_s}))
displays = displays.join("\n") + "\n"
self.log(displays)
end
end
def self.log(message)
puts (Time.now.getutc.to_s + ': ' + message) if SERVER_DISPLAY
RMXOS.log('Log', IDENTIFIER, message)
return if ONLINELIST_FILENAME == ''
begin
usernames = []
@clients.each {|client| usernames.push(client.player.username)}
usernames = usernames.join(',')
file = File.open(ONLINELIST_FILENAME, 'w')
file.write(usernames)
file.close
rescue
puts RMXOS::Data::OnlineListNotCreated
end
end
def self.client_update(client)
return false
end
end
InstructionsIn the script in the first comment.
CompatibilityRequires RMX-OS to work.
Credits and Thanks
Author's NotesRemember to activate the server extension by adding the server extension filename to the list in the configuration.
If you find any bugs, please report them here:
http://forum.chaos-project.com
That's it! N-Joy! =D
kool keep up the good work blizzzard :haha:
hear have a little php code that you can use with this scrpt to
tell how many users are online on a web page
<html>
<body>
<?php readfile// (comment out)("/home/e/edwardthefma/RMX-OS Server/logs/users.log"); ?>
<?php $data = file('/home/e/edwardthefma/RMX-OS Server/logs/users.log');
echo end($data);
?>
</body>
</html>
JC asked for this the other day and I thought it would be a useful tool. Since it was relatively simple, I said I'd do it. I think it took me about half an hour.
kool
im getting a No extensions found.
:) thout id try it out even tho i have no use for it
The way I want to have it work is so that a php code could read the log, and then display on the forum 3 things....
1. Server is: (Online/Offline) [This is custom, has nothing to do with log]
2. Number of pLayers Online : #
3 Players Online: jcsnider, ect, ect, ect....
Not sure how to do it though, also low priority.
(Not useless to me XD )
Quoteim getting a No extensions found.
getting the same problem
Quote from: Blizzard on December 02, 2009, 09:12:00 am
Remember to activate the server extension by adding the server extension filename to the list in the configuration.
*finds a wall to bash his head against*
JC, I'll change it so it works for you (only thing that needs to be done is the people who are online). I'll explain how you will get the other information.
EDIT: Ok, done. v1.1 is up.
Blizzard could you give us a exampal of exatly the way it should be typed out
place the code in a file called 'logger.rb'
then go into cfg.ini and in the extensions add this 'logger' then it'll work when you start the server
it workes but i would advise agnsed using this add on with a linux shell it causes your server to eat memory like like a a kid addicted to candy
Then something's wrong with Linux. Sure, it does take a certain amount of memory, but only until the garbage collector kicks in. It works fine on Windows.
im going to have to think of a diffrent way i can do this perhaps with php maby
v1.11 is out. It works properly with RMX-OS v1.08.
i added some php to the second post
can you make in the new version of this whare it inputs the just the names
of the online users in to a text or a mysql table and then it removes the names
as the users log off
No.
He don't write in the users.log file.
onlinelist works fine. only users.log not.
:S
Extension is in cfg.ini
Users are showen in the Command Box
but no Loggs will created or writed.
maybe someone know how to fix it ?
Whoops, my bad. There, I fixed it.
Updated for RMX-OS 2.0.