diff --git a/app/controllers/plugin_controller.rb b/app/controllers/plugin_controller.rb new file mode 100644 index 0000000..76a2885 --- /dev/null +++ b/app/controllers/plugin_controller.rb @@ -0,0 +1,58 @@ +class PluginController < ApplicationController + def user + buffer = [] + out = [] + + if ban = Ban.first(:conditions => ["expiry > UTC_TIMESTAMP() AND steamid = ? AND ban_type = ?", params[:id], Ban::TYPE_SERVER]) + out << "#USER#" + out << "BANNED" + out << ban.expiry.utc.to_i + out << ban.reason + out << "\r\r\r\r\r\r\r" + elsif user = User.first(:conditions => {:steamid => params[:id]}) + teamer = (user.team ? user.teamers.active.of_team(user.team).first : nil) + icon = 0 + rank = "User" + if Group.find(Group::DONORS).users.exists?(user) + rank = "Donor" + icon = icon | 1 + end + if Group.find(Group::CHAMPIONS).users.exists?(user) + icon = icon | 2 + end + if user.ref? + rank = "Referee" + icon = icon | 4 + end + if user.admin? + rank = "Admin" + icon = icon | 8 + end + + buffer << user.steamid + buffer << user.username + buffer << user.lastip + buffer << (user.team ? Verification.uncrap(user.team.to_s) : "No Team") + buffer << user.id + buffer << user.team_id + buffer << rank + buffer << (teamer ? teamer.ranks[teamer.rank] : "") + buffer << icon + buffer << params[:ch] ? params[:ch] : "" + buffer << (user.can_play? ? "1" : "0") + + out << "#USER#" + out << Verification.verify(buffer.join) + out << buffer.join("\r") + else + out << "#FAIL#" + end + + render_out out + end + + def render_out out + @text = out.join("\r") + render :layout => false + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9aaca00..483f9d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,6 +111,8 @@ Ensl::Application.routes.draw do match 'movies/preview' match 'movies/snapshot' + match 'plugin/user' + match 'users/forgot' match 'users/recover' match 'users/agenda' diff --git a/lib/verification.rb b/lib/verification.rb index 9611585..1820152 100644 --- a/lib/verification.rb +++ b/lib/verification.rb @@ -1,4 +1,45 @@ module Verification + def Verification.verify input + md5 = Digest::MD5.hexdigest("9WvcZ9hX" + input + "KF7L4luQ").upcase.split(//) + chars = ["A", "B", "C", "D", "E", "F"] + nums = [] + lastPos = md5[31].to_i + result = "" + + for i in 0..9 + pos = md5[i].to_i + + if pos == 0 + pos = lastPos ** (i % 4) + elsif (pos % 4) == 0 + pos = pos * lastPos + i + elsif (pos % 3) == 0 + pos = pos ** (i % 4) + elsif (pos % 2) == 0 + pos = pos * i + pos + end + + pos = (pos > 31) ? (pos % 32) : pos + curChar = md5[31 - pos] + curNum = curChar.to_i + + if nums.include? curNum + if curNum == 0 + curChar = chars[pos % 6] + else + curChar = (pos % 10).to_s + end + curNum = curChar.to_i + end + + nums << curNum + result << curChar + lastPos = pos + end + + return result + end + def Verification.uncrap str str.to_s.gsub(/[^A-Za-z0-9_\-]/, "") end