Class: IONIS::Netsoul
- Inherits:
-
Object
- Object
- IONIS::Netsoul
- Defined in:
- lib/ionisnetsoul.rb
Instance Method Summary collapse
-
#getAllOnlineUsers ⇒ Hash
Get informations about all connected user.
-
#getUser(login) ⇒ Hash
Get informations about given connected user.
-
#initialize ⇒ Netsoul
constructor
Instance of Netsoul.
-
#online?(login) ⇒ Boolean
Check if user is connected.
-
#size ⇒ fixnum
Get number of connected user(s).
Constructor Details
#initialize ⇒ Netsoul
Instance of Netsoul
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ionisnetsoul.rb', line 13 def initialize @tmpDir = File.join Dir.tmpdir, 'ionis_auth' Dir.mkdir @tmpDir if !File.directory? @tmpDir @tmpDir = File.join Dir.tmpdir, 'ionis_auth/nsUser' if !File.exist? @tmpDir or (File.mtime(@tmpDir).to_i + 300) < Time.now.to_i begin hSock = TCPSocket.open('ns-server.epita.fr', 4242) line = hSock.gets if /salut (.*)/.match(line) hSock.write "list_users\n" @usrData = Hash.new while line = hSock.gets line.strip! break if line == 'rep 002 -- cmd end' line = line.split ' ' @usrData[line[1]] = Hash.new @usrData[line[1]]['login'] = line[1] @usrData[line[1]]['ip'] = line[2] line[10] = line[10].split ':' @usrData[line[1]]['state'] = line[10][0] @usrData[line[1]]['since'] = line[10][1] end end hSock.close rescue SocketError raise IONIS::Exception::HostNotFound.new 405, "Can't resolve ns-server.epita.fr" rescue Errno::ECONNREFUSED raise IONIS::Exception::ConnectionRefused.new 403, "Connection refused to ns-server.epita.fr" end File.open(@tmpDir, "wb") {|f| Marshal.dump(@usrData, f)} else @usrData = File.open(@tmpDir, "rb") {|f| Marshal.load(f)} end end |
Instance Method Details
#getAllOnlineUsers ⇒ Hash
Get informations about all connected user
64 65 66 67 |
# File 'lib/ionisnetsoul.rb', line 64 def getAllOnlineUsers return false if !@usrData @usrData[login] end |
#getUser(login) ⇒ Hash
Get informations about given connected user
51 52 53 54 |
# File 'lib/ionisnetsoul.rb', line 51 def getUser login return false if !@usrData @usrData[login] end |
#online?(login) ⇒ Boolean
Check if user is connected
72 73 74 75 76 |
# File 'lib/ionisnetsoul.rb', line 72 def online? login return false if !@usrData return true if @usrData[login] false end |
#size ⇒ fixnum
Get number of connected user(s)
58 59 60 |
# File 'lib/ionisnetsoul.rb', line 58 def size return @usrData.size end |