Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: Blizzard on December 02, 2009, 09:12:00 am

Title: [XP] User Logger for RMX-OS
Post by: Blizzard on December 02, 2009, 09:12:00 am
User Logger for RMX-OS
Authors: Blizzard
Version: 1.2
Type: RMX-OS Plugin
Key Term: RMX-OS Plugin



Introduction

This 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




Screenshots

(http://img171.imageshack.us/img171/2564/snap055.th.png) (http://img171.imageshack.us/img171/2564/snap055.png)


Demo

N/A


Script

Make a new file with an .rb extension in the Extensions folder of RMX-OS and copy-paste this script into it.
Spoiler: ShowHide
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




Instructions

In the script in the first comment.


Compatibility

Requires RMX-OS to work.


Credits and Thanks




Author's Notes

Remember 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
Title: Re: [XP] User Logger for RMX-OS
Post by: edwardthefma on December 03, 2009, 10:53:37 am
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>
Title: Re: [XP] User Logger for RMX-OS
Post by: Blizzard on December 03, 2009, 02:59:54 pm
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.
Title: Re: [XP] User Logger for RMX-OS
Post by: edwardthefma on December 03, 2009, 03:07:20 pm
kool
Title: Re: [XP] User Logger for RMX-OS
Post by: edwardthefma on December 04, 2009, 10:05:09 pm
im getting a No extensions found.
:) thout id try it out even tho i have no use for it
Title: Re: [XP] User Logger for RMX-OS
Post by: jcsnider on December 04, 2009, 10:49:55 pm
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 )
Title: Re: [XP] User Logger for RMX-OS
Post by: Jackolas on December 05, 2009, 04:01:41 am
Quoteim getting a No extensions found.

getting the same problem
Title: Re: [XP] User Logger for RMX-OS
Post by: Blizzard on December 05, 2009, 05:12:16 am
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.
Title: Re: [XP] User Logger for RMX-OS
Post by: Jackolas on December 05, 2009, 06:06:02 am
*finds a wall to bash his head against*
Title: Re: [XP] User Logger for RMX-OS
Post by: Blizzard on December 05, 2009, 07:03:49 am
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.
Title: Re: [XP] User Logger for RMX-OS
Post by: edwardthefma on December 18, 2009, 10:00:55 pm
Blizzard could you give us a exampal  of exatly the way it should be typed out
Title: Re: [XP] User Logger for RMX-OS
Post by: G_G on December 18, 2009, 10:05:31 pm
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
Title: Re: [XP] User Logger for RMX-OS
Post by: edwardthefma on December 18, 2009, 11:04:03 pm
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
Title: Re: [XP] User Logger for RMX-OS
Post by: Blizzard on December 20, 2009, 09:29:53 am
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.
Title: Re: [XP] User Logger for RMX-OS
Post by: edwardthefma on December 21, 2009, 12:56:31 pm
im going to have to think of a diffrent way i can do this perhaps with php maby
Title: Re: [XP] User Logger for RMX-OS
Post by: Blizzard on January 03, 2010, 10:07:39 am
v1.11 is out. It works properly with RMX-OS v1.08.
Title: Re: [XP] User Logger for RMX-OS
Post by: edwardthefma on January 11, 2010, 11:07:40 pm
i added some php to the second post
Title: Re: [XP] User Logger for RMX-OS
Post by: edwardthefma on January 16, 2010, 03:05:11 pm
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
Title: Re: [XP] User Logger for RMX-OS
Post by: Blizzard on January 16, 2010, 06:52:47 pm
No.
Title: Re: [XP] User Logger for RMX-OS
Post by: Midako on March 29, 2013, 01:48:48 pm
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 ?
Title: Re: [XP] User Logger for RMX-OS
Post by: Blizzard on March 29, 2013, 06:15:14 pm
Whoops, my bad. There, I fixed it.
Title: Re: [XP] User Logger for RMX-OS
Post by: Blizzard on June 12, 2013, 01:04:01 pm
Updated for RMX-OS 2.0.