Advertisement
Guest User

Untitled

a guest
May 28th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. def try_login(username, password)
  2. # find this user
  3. check = RMXOS.server.sql.query("SELECT user_id, usergroup, banned FROM users WHERE username = " +
  4. "'#{RMXOS.fix_string(username)}' AND password = '#{password}'")
  5. # either username or password is incorrect
  6. return RMXOS::RESULT_FAIL if check.num_rows == 0
  7. hash = check.fetch_hash
  8. # this user is banned
  9. return RMXOS::RESULT_DENIED if hash['banned'] != '0'
  10. user_id = hash['user_id'].to_i
  11. # this user is already logged in
  12. return RMXOS::RESULT_ALTFAIL if $clients.any? {|client| client.player.user_id == user_id}
  13. # get user main data
  14. @client.player.user_id = user_id
  15. @client.player.username = username
  16. @client.player.usergroup = hash['usergroup'].to_i
  17. # log last login time
  18. RMXOS.server.sql.query("UPDATE user_data SET lastlogin = '#{RMXOS.get_sqltime(Time.now.getutc)}' WHERE user_id = #{@client.player.user_id}")
  19. # find all buddies
  20. self.setup_buddies
  21. # get other user data
  22. check = RMXOS.server.sql.query("SELECT guild_id FROM user_data WHERE user_id = #{user_id}")
  23. hash = check.fetch_hash
  24. # set all guild related data if player is in a guild
  25. self.setup_guild_data(hash['guild_id'].to_i) if hash['guild_id'] != nil
  26. # notify if new PMs in the inbox
  27. check = RMXOS.server.sql.query("SELECT COUNT(*) AS count FROM inbox WHERE recipient_id = #{@client.player.user_id} AND unread = 1")
  28. hash = check.fetch_hash
  29. @client.send("CHT#{RMXOS::Data::ColorInfo}\t0\t#{RMXOS::Data::NewPMs}") if hash['count'].to_i > 0
  30. # notify if inbox is full
  31. check = RMXOS.server.sql.query("SELECT COUNT(*) AS count FROM inbox WHERE recipient_id = #{@client.player.user_id}")
  32. hash = check.fetch_hash
  33. if hash['count'].to_i >= INBOX_SIZE
  34. @client.send("CHT#{RMXOS::Data::ColorInfo}\t0\t#{RMXOS::Data::InboxFull}")
  35. end
  36. return RMXOS::RESULT_SUCCESS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement