Skip to content

Instantly share code, notes, and snippets.

@youngershen
Created August 28, 2012 06:49
Show Gist options
  • Save youngershen/3495633 to your computer and use it in GitHub Desktop.
Save youngershen/3495633 to your computer and use it in GitHub Desktop.
lol match leader
-- project : LolMatchLeader
-- author : younger.shen
-- filename : LolMatchLeader.lua
-- filepath : /C/Users/Administrator/Desktop/LolMatchLeader.lua
[[
该程序用来确定某一个lol队伍的leader.
请求格式:
/?gameid=xxx&server=xxx&teamid=xxx&player=xxx
返回格式:
<?xml version="1.0" encoding="UTF-8"?>
<result>true</result>
lol_match_dict 是在ngx里配置好的全局table
]]
module("LolMatchLeader", package.seeall)
--conf
local expired_time = 10000000
local lol_match_dict = ngx.shared.lol_match_dict
--conf over
function make_xml(val)
local flag = val or "false"
return [[<?xml version="1.0" encoding="UTF-8"?><result>]] .. flag ..[[</result>]]
end
function process_request()
local args = ngx.req.get_uri_args()
ngx.req.set_header("Content-Type", "application/xml")
local gameid = args.gameid
local server = args.server
local teamid = args.teamid
local player = args.player
if check_args_invaild(gameid, server, teamid, player) then
local key = string.lower(server) .. '_' .. string.lower(gameid) .. '_' .. string.lower(teamid)
player = string.lower(player)
local val = lol_match_dict:get(key)
if val then
if val == player then
local ret = make_xml("true")
ngx.say(ret)
return
else
local ret = make_xml()
ngx.say(ret)
return
end
-- already cached in the table
else
local success, err, _ = lol_match_dict:set(key, player, expired_time)
if success then
local ret = make_xml("true")
ngx.say(ret)
return
else
ngx.say("stored failed check log please")
return
end
-- no really cached in the table
--endif
end
--endif
else
ngx.say("bad get args")
end
end
-- utils function
function check_args_invaild(...)
local len = select('#', ...)
for i=1, len do
local val = select(i, ...)
if not val or val == '' then
return false
end
end
return true
end
-- main method
process_request()
@t3rryw1
Copy link

t3rryw1 commented Aug 28, 2012

40: 考虑大小写

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment