Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def try_login(username, password)
- # find this user
- check = RMXOS.server.sql.query("SELECT user_id, usergroup, banned FROM users WHERE username = " +
- "'#{RMXOS.fix_string(username)}' AND password = '#{password}'")
- # either username or password is incorrect
- return RMXOS::RESULT_FAIL if check.num_rows == 0
- hash = check.fetch_hash
- # this user is banned
- return RMXOS::RESULT_DENIED if hash['banned'] != '0'
- user_id = hash['user_id'].to_i
- # this user is already logged in
- return RMXOS::RESULT_ALTFAIL if $clients.any? {|client| client.player.user_id == user_id}
- # get user main data
- @client.player.user_id = user_id
- @client.player.username = username
- @client.player.usergroup = hash['usergroup'].to_i
- # log last login time
- RMXOS.server.sql.query("UPDATE user_data SET lastlogin = '#{RMXOS.get_sqltime(Time.now.getutc)}' WHERE user_id = #{@client.player.user_id}")
- # find all buddies
- self.setup_buddies
- # get other user data
- check = RMXOS.server.sql.query("SELECT guild_id FROM user_data WHERE user_id = #{user_id}")
- hash = check.fetch_hash
- # set all guild related data if player is in a guild
- self.setup_guild_data(hash['guild_id'].to_i) if hash['guild_id'] != nil
- # notify if new PMs in the inbox
- check = RMXOS.server.sql.query("SELECT COUNT(*) AS count FROM inbox WHERE recipient_id = #{@client.player.user_id} AND unread = 1")
- hash = check.fetch_hash
- @client.send("CHT#{RMXOS::Data::ColorInfo}\t0\t#{RMXOS::Data::NewPMs}") if hash['count'].to_i > 0
- # notify if inbox is full
- check = RMXOS.server.sql.query("SELECT COUNT(*) AS count FROM inbox WHERE recipient_id = #{@client.player.user_id}")
- hash = check.fetch_hash
- if hash['count'].to_i >= INBOX_SIZE
- @client.send("CHT#{RMXOS::Data::ColorInfo}\t0\t#{RMXOS::Data::InboxFull}")
- end
- return RMXOS::RESULT_SUCCESS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement