[XP] User Logger for RMX-OS

Started by Blizzard, December 02, 2009, 09:12:00 am

Previous topic - Next topic

Blizzard

December 02, 2009, 09:12:00 am Last Edit: March 23, 2019, 11:32:33 am by Blizzard
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


  • 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




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


  • Boris "Blizzard" Mikić



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
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

edwardthefma

December 03, 2009, 10:53:37 am #1 Last Edit: January 11, 2010, 11:06:09 pm by edwardthefma
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>
i am the lead dev for the shellium mmorpg project
http://wiki.shellium.org/w/Mmorpg
shellium.org :) free linux shells pm me and i will gladly
help you get 1

Blizzard

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.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

edwardthefma

i am the lead dev for the shellium mmorpg project
http://wiki.shellium.org/w/Mmorpg
shellium.org :) free linux shells pm me and i will gladly
help you get 1

edwardthefma

im getting a No extensions found.
:) thout id try it out even tho i have no use for it
i am the lead dev for the shellium mmorpg project
http://wiki.shellium.org/w/Mmorpg
shellium.org :) free linux shells pm me and i will gladly
help you get 1

jcsnider

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 )

Jackolas

Quoteim getting a No extensions found.

getting the same problem

Blizzard

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.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Jackolas

*finds a wall to bash his head against*

Blizzard

December 05, 2009, 07:03:49 am #9 Last Edit: December 06, 2009, 01:42:40 pm by Blizzard
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.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

edwardthefma

Blizzard could you give us a exampal  of exatly the way it should be typed out
i am the lead dev for the shellium mmorpg project
http://wiki.shellium.org/w/Mmorpg
shellium.org :) free linux shells pm me and i will gladly
help you get 1

G_G

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

edwardthefma

December 18, 2009, 11:04:03 pm #12 Last Edit: December 19, 2009, 05:43:34 pm by edwardthefma
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
i am the lead dev for the shellium mmorpg project
http://wiki.shellium.org/w/Mmorpg
shellium.org :) free linux shells pm me and i will gladly
help you get 1

Blizzard

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.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

edwardthefma

im going to have to think of a diffrent way i can do this perhaps with php maby
i am the lead dev for the shellium mmorpg project
http://wiki.shellium.org/w/Mmorpg
shellium.org :) free linux shells pm me and i will gladly
help you get 1

Blizzard

v1.11 is out. It works properly with RMX-OS v1.08.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

edwardthefma

i added some php to the second post
i am the lead dev for the shellium mmorpg project
http://wiki.shellium.org/w/Mmorpg
shellium.org :) free linux shells pm me and i will gladly
help you get 1

edwardthefma

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
i am the lead dev for the shellium mmorpg project
http://wiki.shellium.org/w/Mmorpg
shellium.org :) free linux shells pm me and i will gladly
help you get 1

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Midako

March 29, 2013, 01:48:48 pm #19 Last Edit: March 29, 2013, 01:56:38 pm by Midako
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 ?

Blizzard

Whoops, my bad. There, I fixed it.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.