repo_name
stringlengths
6
69
path
stringlengths
6
178
copies
stringclasses
278 values
size
stringlengths
4
7
content
stringlengths
671
917k
license
stringclasses
15 values
Zenny89/darkstar
scripts/zones/Ghelsba_Outpost/bcnms/toadal_recall.lua
19
1479
----------------------------------- -- Area: Ghelsba Outpost -- Name: toadal_recall BCNM30 -- @pos -162 -11 78 140 ----------------------------------- package.loaded["scripts/zones/Ghelsba_Outpost/TextIDs"] = nil; ----------------------------------- require("scripts/globals/titles"); require("scripts/globals/keyitems"); require("scripts/globals/missions"); require("scripts/zones/Ghelsba_Outpost/TextIDs"); ----------------------------------- -- After registering the BCNM via bcnmRegister(bcnmid) function onBcnmRegister(player,instance) end; -- Physically entering the BCNM via bcnmEnter(bcnmid) function onBcnmEnter(player,instance) end; -- Leaving the BCNM by every mean possible, given by the LeaveCode -- 1=Select Exit on circle -- 2=Winning the BC -- 3=Disconnected or warped out -- 4=Losing the BC -- via bcnmLeave(1) or bcnmLeave(2). LeaveCodes 3 and 4 are called -- from the core when a player disconnects or the time limit is up, etc function onBcnmLeave(player,instance,leavecode) -- print(leave code ..leavecode); if (leavecode == 2) then -- play end CS. Need time and battle id for record keeping + storage player:startEvent(0x7d01,1,1,1,instance:getTimeInside(),2,2,2); elseif (leavecode == 4) then player:startEvent(0x7d02); end end; function onEventUpdate(player,csid,option) -- print(bc update csid ..csid.. and option ..option); end; function onEventFinish(player,csid,option) -- print(bc finish csid ..csid.. and option ..option); end;
gpl-3.0
mercury233/ygopro-scripts
c96864811.lua
2
1649
--禁じられた聖衣 function c96864811.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_ATKCHANGE) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetProperty(EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_DAMAGE_STEP) e1:SetCode(EVENT_FREE_CHAIN) e1:SetHintTiming(TIMING_DAMAGE_STEP,TIMINGS_CHECK_MONSTER+TIMING_DAMAGE_STEP) e1:SetCondition(aux.dscon) e1:SetTarget(c96864811.target) e1:SetOperation(c96864811.activate) c:RegisterEffect(e1) end function c96864811.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup() end if chk==0 then return Duel.IsExistingTarget(Card.IsFaceup,tp,LOCATION_MZONE,LOCATION_MZONE,1,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FACEUP) Duel.SelectTarget(tp,Card.IsFaceup,tp,LOCATION_MZONE,LOCATION_MZONE,1,1,nil) end function c96864811.activate(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) and tc:IsFaceup() then local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetCode(EFFECT_UPDATE_ATTACK) e1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END) e1:SetValue(-600) tc:RegisterEffect(e1) local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_SINGLE) e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET) e2:SetValue(1) e2:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END) tc:RegisterEffect(e2) local e3=Effect.CreateEffect(c) e3:SetType(EFFECT_TYPE_SINGLE) e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT) e3:SetValue(1) e3:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END) tc:RegisterEffect(e3) end end
gpl-2.0
Zenny89/darkstar
scripts/zones/Throne_Room/npcs/_4l1.lua
17
2080
----------------------------------- -- Area: Throne Room -- NPC: Throne Room -- Type: Door -- @pos -111 -6 0 165 ------------------------------------- package.loaded["scripts/zones/Throne_Room/TextIDs"] = nil; ------------------------------------- require("scripts/globals/keyitems"); require("scripts/globals/bcnm"); require("scripts/globals/missions"); require("scripts/zones/Throne_Room/TextIDs"); -- events: -- 7D00 : BC menu -- Param 4 is a bitmask for the choice of battlefields in the menu: -- 0: Mission 5-2 -- 1: -- 2: -- 3: -- 4: -- 5: -- Param 8 is a flag: 0 : menu, >0 : automatically enter and exit -- 7D01 : final BC event. -- param 2: #time record for this mission -- param 3: #clear time in seconds -- param 6: #which mission (linear numbering as above) -- 7D03 : stay/run away ----------------------------------- -- onTrade Action ----------------------------------- function onTrade(player,npc,trade) if (TradeBCNM(player,player:getZoneID(),trade,npc)) then return; end end; ----------------------------------- -- onTrigger Action ----------------------------------- function onTrigger(player,npc) if (player:getCurrentMission(player:getNation()) == 15 and player:getVar("MissionStatus") == 2) then player:startEvent(0x0006); elseif (EventTriggerBCNM(player,npc)) then return 1; end end; ----------------------------------- -- onEventUpdate ----------------------------------- function onEventUpdate(player,csid,option) --printf("onUpdate CSID: %u",csid); --printf("onUpdate RESULT: %u",option); if (EventUpdateBCNM(player,csid,option)) then return; end end; ----------------------------------- -- onEventFinish Action ----------------------------------- function onEventFinish(player,csid,option) --printf("onFinish CSID: %u",csid); --printf("onFinish RESULT: %u",option); if (csid == 0x0006) then player:setVar("MissionStatus",3); elseif (EventFinishBCNM(player,csid,option)) then return; end end;
gpl-3.0
mercury233/ygopro-scripts
c26847978.lua
2
2912
--鉄獣戦線 徒花のフェリジット function c26847978.initial_effect(c) --link summon aux.AddLinkProcedure(c,aux.FilterBoolFunction(Card.IsLinkRace,RACE_BEAST+RACE_BEASTWARRIOR+RACE_WINDBEAST),2,2) c:EnableReviveLimit() --special summon local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(26847978,0)) e1:SetCategory(CATEGORY_SPECIAL_SUMMON) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetRange(LOCATION_MZONE) e1:SetCountLimit(1,26847978) e1:SetTarget(c26847978.sptg) e1:SetOperation(c26847978.spop) c:RegisterEffect(e1) --draw local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(26847978,1)) e2:SetCategory(CATEGORY_DRAW+CATEGORY_TODECK) e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e2:SetProperty(EFFECT_FLAG_DELAY) e2:SetCode(EVENT_TO_GRAVE) e2:SetCountLimit(1,26847979) e2:SetTarget(c26847978.drtg) e2:SetOperation(c26847978.drop) c:RegisterEffect(e2) end function c26847978.spfilter(c,e,tp) return c:IsRace(RACE_BEAST+RACE_BEASTWARRIOR+RACE_WINDBEAST) and c:IsLevelBelow(4) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function c26847978.sptg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingMatchingCard(c26847978.spfilter,tp,LOCATION_HAND,0,1,nil,e,tp) end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_HAND) end function c26847978.spop(e,tp,eg,ep,ev,re,r,rp) if Duel.GetLocationCount(tp,LOCATION_MZONE)>0 then Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,c26847978.spfilter,tp,LOCATION_HAND,0,1,1,nil,e,tp) if g:GetCount()>0 then Duel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP) end end local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_FIELD) e1:SetCode(EFFECT_CANNOT_BE_LINK_MATERIAL) e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE+EFFECT_FLAG_IGNORE_IMMUNE) e1:SetTargetRange(0xff,0xff) e1:SetTarget(aux.NOT(aux.TargetBoolFunction(Card.IsRace,RACE_BEAST+RACE_BEASTWARRIOR+RACE_WINDBEAST))) e1:SetValue(c26847978.sumlimit) e1:SetReset(RESET_PHASE+PHASE_END) Duel.RegisterEffect(e1,tp) end function c26847978.sumlimit(e,c) if not c then return false end return c:IsControler(e:GetHandlerPlayer()) end function c26847978.drtg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsPlayerCanDraw(tp,1) end Duel.SetTargetPlayer(tp) Duel.SetTargetParam(1) Duel.SetOperationInfo(0,CATEGORY_DRAW,nil,0,tp,1) Duel.SetOperationInfo(0,CATEGORY_TODECK,nil,0,tp,1) end function c26847978.drop(e,tp,eg,ep,ev,re,r,rp) local p,d=Duel.GetChainInfo(0,CHAININFO_TARGET_PLAYER,CHAININFO_TARGET_PARAM) if Duel.Draw(p,d,REASON_EFFECT)==0 then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TODECK) local g=Duel.SelectMatchingCard(tp,Card.IsAbleToDeck,tp,LOCATION_HAND,0,1,1,nil) if g:GetCount()>0 then Duel.BreakEffect() Duel.SendtoDeck(g,nil,SEQ_DECKBOTTOM,REASON_EFFECT) end end
gpl-2.0
mercury233/ygopro-scripts
c86170989.lua
9
2331
--ファルシオンβ function c86170989.initial_effect(c) local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(86170989,0)) e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F) e1:SetCode(EVENT_BATTLE_DESTROYING) e1:SetTarget(c86170989.target) e1:SetOperation(c86170989.operation) c:RegisterEffect(e1) end function c86170989.filter1(c) return c:IsRace(RACE_MACHINE) and c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsAttackBelow(1200) and c:IsAbleToGrave() end function c86170989.filter2(c,e,tp) return c:IsRace(RACE_MACHINE) and c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsAttackBelow(1200) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function c86170989.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and c86170989.filter2(chkc,e,tp) end if chk==0 then return true end local op=0 Duel.Hint(HINT_SELECTMSG,tp,aux.Stringid(86170989,0)) local t1=Duel.IsExistingMatchingCard(c86170989.filter1,tp,LOCATION_DECK,0,1,nil) local t2=Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingTarget(c86170989.filter2,tp,LOCATION_GRAVE,0,1,nil,e,tp) if t1 and t2 then op=Duel.SelectOption(tp,aux.Stringid(86170989,1),aux.Stringid(86170989,2))+1 elseif t1 then Duel.SelectOption(tp,aux.Stringid(86170989,1)) op=1 elseif t2 then Duel.SelectOption(tp,aux.Stringid(86170989,2)) op=2 end e:SetLabel(op) if op==2 then Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectTarget(tp,c86170989.filter2,tp,LOCATION_GRAVE,0,1,1,nil,e,tp) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,1,0,0) e:SetProperty(EFFECT_FLAG_CARD_TARGET) e:SetCategory(CATEGORY_SPECIAL_SUMMON) elseif op==1 then Duel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,1,tp,LOCATION_DECK) e:SetProperty(0) e:SetCategory(CATEGORY_TOGRAVE) else e:SetProperty(0) e:SetCategory(0) end end function c86170989.operation(e,tp,eg,ep,ev,re,r,rp) if e:GetLabel()==2 then local tc=Duel.GetFirstTarget() if tc and tc:IsRelateToEffect(e) then Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP) end elseif e:GetLabel()==1 then Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE) local g=Duel.SelectMatchingCard(tp,c86170989.filter1,tp,LOCATION_DECK,0,1,1,nil) if g:GetCount()>0 then Duel.SendtoGrave(g,REASON_EFFECT) end end end
gpl-2.0
rouing/FHLG-BW
entities/entities/ent_mad_smoke/init.lua
1
1060
AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include('shared.lua') /*--------------------------------------------------------- Name: ENT:Initialize() ---------------------------------------------------------*/ function ENT:Initialize() self.Owner = self.Entity:GetOwner() if !IsValid(self.Owner) then self:Remove() return end self.Entity:SetModel("models/weapons/w_eq_smokegrenade.mdl") self.Entity:PhysicsInit(SOLID_VPHYSICS) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) self.Entity:DrawShadow(false) self.Entity:SetCollisionGroup(COLLISION_GROUP_WEAPON) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end end /*--------------------------------------------------------- Name: ENT:Think() ---------------------------------------------------------*/ function ENT:Think() end /*--------------------------------------------------------- Name: ENT:Explosion() ---------------------------------------------------------*/ function ENT:Explode() end
unlicense
openwrt-stuff/openwrt-extra
luci/applications/luci-webshell/luasrc/controller/webshell.lua
7
1453
module("luci.controller.webshell", package.seeall) function index() luci.i18n.loadc("webshell") local i18n = luci.i18n.translate page = entry({"admin", "system", "cmd_run"}, call("cmd_run"), nil) page.leaf = true page = node("admin", "system", "WebShell") page.target = template("webshell") page.title = i18n("WebShell") page.order = 60 end function string.starts(String,Start) return string.sub(String,1,string.len(Start))==Start end function cmd_run() local re ="" local path = luci.dispatcher.context.requestpath local rv = { } local cmd = luci.http.formvalue("cmd") local path = luci.http.formvalue("path") local runcmd="cd "..path.."&&"..cmd local shellpipe = io.popen(runcmd.." 2>&1","rw") re = shellpipe:read("*a") shellpipe:close() if not re then re="" end local pwdcmd = "cd "..path.."&& pwd 2>&1" if string.starts(cmd,"cd") then pwdcmd = "cd "..path.."&&"..cmd.."&& pwd 2>&1" end local shellpipe = io.popen(pwdcmd,"rw") local newpath = shellpipe:read("*a") shellpipe:close() if not newpath then newpath=path end local pathcmd = io.popen("ls "..newpath.."2>&1","rw") local ls = pathcmd:read("*a") pathcmd:close() ls = string.gsub(ls, "\n", ",") re = string.gsub(re, "\n", "\r\n") rv[#rv+1]=re rv[#rv+1]=newpath rv[#rv+1]=ls if #rv > 0 then luci.http.prepare_content("application/json") luci.http.write_json(rv) return end luci.http.status(404, "No such device") end
gpl-2.0
mercury233/ygopro-scripts
c63223467.lua
9
1173
--RAI-MEI function c63223467.initial_effect(c) --search local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(63223467,0)) e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH) e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e1:SetCode(EVENT_BATTLE_DESTROYED) e1:SetCondition(c63223467.condition) e1:SetTarget(c63223467.target) e1:SetOperation(c63223467.operation) c:RegisterEffect(e1) end function c63223467.condition(e,tp,eg,ep,ev,re,r,rp) return e:GetHandler():IsLocation(LOCATION_GRAVE) and e:GetHandler():IsReason(REASON_BATTLE) end function c63223467.filter(c) return c:IsLevelBelow(2) and c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsAbleToHand() end function c63223467.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(c63223467.filter,tp,LOCATION_DECK,0,1,nil) end Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK) end function c63223467.operation(e,tp,eg,ep,ev,re,r,rp) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local g=Duel.SelectMatchingCard(tp,c63223467.filter,tp,LOCATION_DECK,0,1,1,nil) if g:GetCount()>0 then Duel.SendtoHand(g,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,g) end end
gpl-2.0
qq779089973/my_openwrt_mod
luci/applications/luci-polipo/luasrc/model/cbi/polipo.lua
79
5961
--[[ LuCI - Lua Configuration Interface Copyright 2008 Aleksandar Krsteski <alekrsteski@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 $Id$ ]]-- m = Map("polipo", translate("Polipo"), translate("Polipo is a small and fast caching web proxy.")) -- General section s = m:section(NamedSection, "general", "polipo", translate("Proxy")) s:tab("general", translate("General Settings")) s:tab("dns", translate("DNS and Query Settings")) s:tab("proxy", translate("Parent Proxy")) s:tab("logging", translate("Logging and RAM")) -- General settings s:taboption("general", Flag, "enabled", translate("enable")) o = s:taboption("general", Value, "proxyAddress", translate("Listen address"), translate("The interface on which Polipo will listen. To listen on all " .. "interfaces use 0.0.0.0 or :: (IPv6).")) o.placeholder = "0.0.0.0" o.datatype = "ipaddr" o = s:taboption("general", Value, "proxyPort", translate("Listen port"), translate("Port on which Polipo will listen")) o.optional = true o.placeholder = "8123" o.datatype = "port" o = s:taboption("general", DynamicList, "allowedClients", translate("Allowed clients"), translate("When listen address is set to 0.0.0.0 or :: (IPv6), you must " .. "list clients that are allowed to connect. The format is IP address " .. "or network address (192.168.1.123, 192.168.1.0/24, " .. "2001:660:116::/48 (IPv6))")) o.datatype = "ipaddr" o.placeholder = "0.0.0.0/0" -- DNS settings dns = s:taboption("dns", Value, "dnsNameServer", translate("DNS server address"), translate("Set the DNS server address to use, if you want Polipo to use " .. "different DNS server than the host system.")) dns.optional = true dns.datatype = "ipaddr" l = s:taboption("dns", ListValue, "dnsQueryIPv6", translate("Query DNS for IPv6")) l.default = "happily" l:value("true", translate("Query only IPv6")) l:value("happily", translate("Query IPv4 and IPv6, prefer IPv6")) l:value("reluctantly", translate("Query IPv4 and IPv6, prefer IPv4")) l:value("false", translate("Do not query IPv6")) l = s:taboption("dns", ListValue, "dnsUseGethostbyname", translate("Query DNS by hostname")) l.default = "reluctantly" l:value("true", translate("Always use system DNS resolver")) l:value("happily", translate("Query DNS directly, for unknown hosts fall back " .. "to system resolver")) l:value("reluctantly", translate("Query DNS directly, fallback to system resolver")) l:value("false", translate("Never use system DNS resolver")) -- Proxy settings o = s:taboption("proxy", Value, "parentProxy", translate("Parent proxy address"), translate("Parent proxy address (in host:port format), to which Polipo " .. "will forward the requests.")) o.optional = true o.datatype = "ipaddr" o = s:taboption("proxy", Value, "parentAuthCredentials", translate("Parent proxy authentication"), translate("Basic HTTP authentication supported. Provide username and " .. "password in username:password format.")) o.optional = true o.placeholder = "username:password" -- Logging s:taboption("logging", Flag, "logSyslog", translate("Log to syslog")) s:taboption("logging", Value, "logFacility", translate("Syslog facility")):depends("logSyslog", "1") v = s:taboption("logging", Value, "logFile", translate("Log file location"), translate("Use of external storage device is recommended, because the " .. "log file is written frequently and can grow considerably.")) v:depends("logSyslog", "") v.rmempty = true o = s:taboption("logging", Value, "chunkHighMark", translate("In RAM cache size (in bytes)"), translate("How much RAM should Polipo use for its cache.")) o.datatype = "uinteger" -- Disk cache section s = m:section(NamedSection, "cache", "polipo", translate("On-Disk Cache")) s:tab("general", translate("General Settings")) s:tab("advanced", translate("Advanced Settings")) -- Disk cache settings s:taboption("general", Value, "diskCacheRoot", translate("Disk cache location"), translate("Location where polipo will cache files permanently. Use of " .. "external storage devices is recommended, because the cache can " .. "grow considerably. Leave it empty to disable on-disk " .. "cache.")).rmempty = true s:taboption("general", Flag, "cacheIsShared", translate("Shared cache"), translate("Enable if cache (proxy) is shared by multiple users.")) o = s:taboption("advanced", Value, "diskCacheTruncateSize", translate("Truncate cache files size (in bytes)"), translate("Size to which cached files should be truncated")) o.optional = true o.placeholder = "1048576" o.datatype = "uinteger" o = s:taboption("advanced", Value, "diskCacheTruncateTime", translate("Truncate cache files time"), translate("Time after which cached files will be truncated")) o.optional = true o.placeholder = "4d12h" o = s:taboption("advanced", Value, "diskCacheUnlinkTime", translate("Delete cache files time"), translate("Time after which cached files will be deleted")) o.optional = true o.placeholder = "32d" -- Poor man's multiplexing section s = m:section(NamedSection, "pmm", "polipo", translate("Poor Man's Multiplexing"), translate("Poor Man's Multiplexing (PMM) is a technique that simulates " .. "multiplexing by requesting an instance in multiple segments. It " .. "tries to lower the latency caused by the weakness of HTTP " .. "protocol. NOTE: some sites may not work with PMM enabled.")) s:option(Value, "pmmSize", translate("PMM segments size (in bytes)"), translate("To enable PMM, PMM segment size must be set to some " .. "positive value.")).rmempty = true s:option(Value, "pmmFirstSize", translate("First PMM segment size (in bytes)"), translate("Size of the first PMM segment. If not defined, it defaults " .. "to twice the PMM segment size.")).rmempty = true return m
mit
MasterQ32/BrokenRemote
Templates/Trinket.lua
1
1841
------------------------------------------------------------------------------- -- -- This script provides the basic implementation for a trinket. -- The trinket will double our speed if collected. -- ------------------------------------------------------------------------------- -- Small helper that returns only true when a or b is true, but not both local function xor(a, b) return (a and not b) or (not a and b) end -- Query our item id as we can't hardcode it. local trinketId = Isaac.GetTrinketIdByName("Mod Trinket 1") if trinketId == -1 then -- We are sad, our trinket wasn't found Game():GetPlayer(0):AnimateSad() return; end function mod:MC_EVALUATE_CACHE(player, cache) if player:HasTrinket(trinketId) == false then -- Do not apply any trinket effect when the player -- does not have the trinket return end -- This checks if we should modify speed if cache == CacheFlag.CACHE_SPEED then -- Our trinket will double the speed -- Aware! player.MoveSpeed = player.MoveSpeed * 2 end -- Add more if-blocks here to modify more stats end -- Sadly, we have to do some additional logic here -- as the MC_EVALUATE_CACHE callback won't be called -- when a trinket is collected -- Store if we had the trinket in the last tick local hadTrinket = false function mod:MC_POST_UPDATE() local p = Game():GetPlayer(0) -- Check if we have the trinket now local hasTrinket = p:HasTrinket(trinketId) -- xor will now return only true if a -- change of possesion happens local change = xor(hadTrinket, hasTrinket) if change then -- Either we lost our trinket -- or we collected it, so: p:AddCacheFlags(CacheFlag.CACHE_SPEED) p:EvaluateItems() end -- Store the current status for the next tick hadTrinket = hasTrinket end -- Announce, that everything worked :) Game():GetPlayer(0):AnimateHappy()
gpl-3.0
mercury233/ygopro-scripts
c56209279.lua
2
2118
--インフェルニティ・ネクロマンサー function c56209279.initial_effect(c) --to defense local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(56209279,0)) e1:SetCategory(CATEGORY_POSITION) e1:SetType(EFFECT_TYPE_TRIGGER_F+EFFECT_TYPE_SINGLE) e1:SetCode(EVENT_SUMMON_SUCCESS) e1:SetTarget(c56209279.potg) e1:SetOperation(c56209279.poop) c:RegisterEffect(e1) --special summon local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(56209279,1)) e2:SetCategory(CATEGORY_SPECIAL_SUMMON) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetType(EFFECT_TYPE_IGNITION) e2:SetCountLimit(1) e2:SetRange(LOCATION_MZONE) e2:SetCondition(c56209279.spcon) e2:SetTarget(c56209279.sptg) e2:SetOperation(c56209279.spop) c:RegisterEffect(e2) end function c56209279.potg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chk==0 then return e:GetHandler():IsAttackPos() end Duel.SetOperationInfo(0,CATEGORY_POSITION,e:GetHandler(),1,0,0) end function c56209279.poop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if c:IsFaceup() and c:IsAttackPos() and c:IsRelateToEffect(e) then Duel.ChangePosition(c,POS_FACEUP_DEFENSE) end end function c56209279.spcon(e,tp,eg,ep,ev,re,r,rp) return not e:GetHandler():IsDisabled() and Duel.GetFieldGroupCount(tp,LOCATION_HAND,0)==0 end function c56209279.filter(c,e,tp) return c:IsSetCard(0xb) and not c:IsCode(56209279) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function c56209279.sptg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and c56209279.filter(chkc,e,tp) end if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingTarget(c56209279.filter,tp,LOCATION_GRAVE,0,1,nil,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectTarget(tp,c56209279.filter,tp,LOCATION_GRAVE,0,1,1,nil,e,tp) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,1,0,0) end function c56209279.spop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc and tc:IsRelateToEffect(e) then Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP) end end
gpl-2.0
guillaume144/jeu-rp
gamemode/modules/fadmin/fadmin/playeractions/slap/sv_init.lua
4
2160
local function ExecuteSlap(target, Amount, ply) if not IsValid(target) or not IsValid(ply) then return end local Force = Vector(math.Rand(-500, 500), math.Rand(-500, 500), math.Rand(-100, 700)) local DmgInfo = DamageInfo() DmgInfo:SetDamage(Amount) DmgInfo:SetDamageType(DMG_DROWN) DmgInfo:SetAttacker(ply) DmgInfo:SetDamageForce(Force) target:TakeDamageInfo(DmgInfo) target:SetVelocity(Force) end local function Slap(ply, cmd, args) if not args[1] then return false end local targets = FAdmin.FindPlayer(args[1]) if not targets or #targets == 1 and not IsValid(targets[1]) then FAdmin.Messages.SendMessage(ply, 1, "Player not found") return false end local Amount = tonumber(args[2]) or 10 local Repetitions = tonumber(args[3]) for _, target in pairs(targets) do if not FAdmin.Access.PlayerHasPrivilege(ply, "Slap", target) then FAdmin.Messages.SendMessage(ply, 5, "No access!") return false end if IsValid(target) then if not Repetitions or Repetitions == 1 then ExecuteSlap(target, Amount, ply) else for i = 1, Repetitions, 1 do timer.Simple(i * 0.7, function() ExecuteSlap(target, Amount, ply) end) end end end end if not Repetitions or Repetitions == 1 then FAdmin.Messages.ActionMessage(ply, targets, "Slapped %s once with " .. Amount .. " damage", "You are being slapped once with " .. Amount .. " damage by %s", "Slapped %s once with " .. Amount .. " damage") else FAdmin.Messages.ActionMessage(ply, targets, "Slapping %s " .. Repetitions .. " times with " .. Amount .. " damage", "You are being slapped " .. Repetitions .. " times with " .. Amount .. " damage by %s", "Slapped %s " .. Repetitions .. " times with " .. Amount .. " damage") end return true, targets, Amount, Repetitions end FAdmin.StartHooks["Slap"] = function() FAdmin.Commands.AddCommand("Slap", Slap) FAdmin.Access.AddPrivilege("Slap", 2) end
mit
Zenny89/darkstar
scripts/globals/spells/fire_carol.lua
18
1502
----------------------------------------- -- Spell: Fire Carol -- Increases fire resistance for party members within the area of effect. ----------------------------------------- require("scripts/globals/status"); require("scripts/globals/magic"); ----------------------------------------- -- OnSpellCast ----------------------------------------- function onMagicCastingCheck(caster,target,spell) return 0; end; function onSpellCast(caster,target,spell) local sLvl = caster:getSkillLevel(SKILL_SNG); -- Gets skill level of Singing local iLvl = caster:getWeaponSkillLevel(SLOT_RANGED); local power = 20; if (sLvl+iLvl > 200) then power = power + math.floor((sLvl+iLvl-200) / 10); end if (power >= 40) then power = 40; end local iBoost = caster:getMod(MOD_CAROL_EFFECT) + caster:getMod(MOD_ALL_SONGS_EFFECT); power = power + iBoost*5; if (caster:hasStatusEffect(EFFECT_SOUL_VOICE)) then power = power * 2; elseif (caster:hasStatusEffect(EFFECT_MARCATO)) then power = power * 1.5; end caster:delStatusEffect(EFFECT_MARCATO); local duration = 120; duration = duration * ((iBoost * 0.1) + (caster:getMod(MOD_SONG_DURATION_BONUS)/100) + 1); if (caster:hasStatusEffect(EFFECT_TROUBADOUR)) then duration = duration * 2; end if not (target:addBardSong(caster,EFFECT_CAROL,power,0,duration,caster:getID(), ELE_FIRE, 1)) then spell:setMsg(75); end return EFFECT_CAROL; end;
gpl-3.0
ZeroK-RTS/SpringRTS-Tools
SpringModEdit/include/standardSensors.lua
1
2381
-- $Id: standardSensors.lua 3444 2008-12-15 02:52:40Z licho $ local thisFile = "standardSensors" Editor.Echo("Standard \"" .. thisFile .. ".lua\" loaded.\n", "Brown") function StandardSensors(doPreviewOnly) Editor.Echo("----------------------------------------------------------------\n") Editor.Echo("Begin " .. thisFile .. "\n", "Black") Editor.Echo("----------------------------------------------------------------\n") local signatureCloak = 16 local signatureFloater = 4 local signatureDefault = 4 local minSightDistanceRange = 1.1 local minRadarDistance = 100 --units with less than this radar distance get their radar distance removed local ignore = { tinyradar = true, fakeunit_smallping = true, dughole = true, } for id, unit in pairs(Units) do if (not ignore[id]) then local unitModified = false local echoFront = unit.unitname --remove useless radar if ((ToNumber(unit.radarDistance or 0)) < minRadarDistance) then unitModified = SetTableValue(unit, "radarDistance", nil, doPreviewOnly, echoFront, "Green") or unitModified end --seismic detection if (unit.canFly) then --aircraft unitModified = SetTableValue(unit, "seismicSignature", 0, doPreviewOnly, echoFront, "Red") or unitModified elseif (GetUnitCanCloak(unit)) then --units with cloak unitModified = SetTableValue(unit, "seismicSignature", signatureCloak, doPreviewOnly, echoFront, "Blue") or unitModified elseif (unit.floater) then --floaters unitModified = SetTableValue(unit, "seismicSignature", signatureFloater, doPreviewOnly, echoFront, "Purple") or unitModified else unitModified = SetTableValue(unit, "seismicSignature", signatureDefault, doPreviewOnly, echoFront, "Green") or unitModified end if (unit.sightDistance) then local range = GetUnitRange(unit) if (range > 600) then range = 600 end if (unit.sightDistance < range * minSightDistanceRange) then unitModified = SetTableValue(unit, "sightDistance", range*minSightDistanceRange, doPreviewOnly, echoFront, "Green") or unitModified end end if (unitModified) then Editor.Echo("--------------------------------\n", "Black") end end end end
gpl-2.0
mercury233/ygopro-scripts
c30314994.lua
6
1131
--エレメント・ドラゴン function c30314994.initial_effect(c) --atk local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE) e1:SetRange(LOCATION_MZONE) e1:SetCode(EFFECT_UPDATE_ATTACK) e1:SetValue(500) e1:SetCondition(c30314994.atkcon) c:RegisterEffect(e1) --chain attack local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(30314994,0)) e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e2:SetCode(EVENT_BATTLE_DESTROYING) e2:SetCondition(c30314994.atcon) e2:SetOperation(c30314994.atop) c:RegisterEffect(e2) end function c30314994.filter(c,att) return c:IsFaceup() and c:IsAttribute(att) end function c30314994.atkcon(e) return Duel.IsExistingMatchingCard(c30314994.filter,0,LOCATION_MZONE,LOCATION_MZONE,1,nil,ATTRIBUTE_FIRE) end function c30314994.atcon(e,tp,eg,ep,ev,re,r,rp) return aux.bdocon(e,tp,eg,ep,ev,re,r,rp) and e:GetHandler():IsChainAttackable() and Duel.IsExistingMatchingCard(c30314994.filter,tp,LOCATION_MZONE,LOCATION_MZONE,1,nil,ATTRIBUTE_WIND) end function c30314994.atop(e,tp,eg,ep,ev,re,r,rp) Duel.ChainAttack() end
gpl-2.0
Zenny89/darkstar
scripts/zones/Wajaom_Woodlands/TextIDs.lua
7
1135
-- Variable TextID Description text -- General Texts ITEM_CANNOT_BE_OBTAINED = 6379; -- You cannot obtain the item <item>. Come back after sorting your inventory. ITEM_OBTAINED = 6383; -- Obtained: <item>. GIL_OBTAINED = 6384; -- Obtained <number> gil. KEYITEM_OBTAINED = 6386; -- Obtained key item: <keyitem>. FISHING_MESSAGE_OFFSET = 7040; -- You can't fish here. -- Other Texts NOTHING_HAPPENS = 119; -- Nothing happens... LEYPOINT = 7384; -- An eerie red glow emanates from this stone platform -- Harvesting HARVESTING_IS_POSSIBLE_HERE = 7392; -- Harvesting is possible here if you have -- Quest: NAVIGATING_THE_UNFRIENDLY_SEAS PLACE_HYDROGAUGE = 7328; -- You set the # in the glowing trench. ENIGMATIC_LIGHT = 7329; -- is giving off an enigmatic light. -- chocobo digging DIG_THROW_AWAY = 7053; -- You dig up ?Possible Special Code: 01??Possible Special Code: 01??Possible Special Code: 01? ?Possible Special Code: 01??Possible Special Code: 05?$?BAD CHAR: 8280??BAD CHAR: 80??BAD CHAR: 80?, but your inventory is full. FIND_NOTHING = 7055; -- You dig and you dig, but find nothing.
gpl-3.0
mercury233/ygopro-scripts
c15561463.lua
6
1238
--ガントレット・シューター function c15561463.initial_effect(c) --xyz summon aux.AddXyzProcedure(c,nil,6,2) c:EnableReviveLimit() --destroy local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_DESTROY) e1:SetDescription(aux.Stringid(15561463,0)) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetRange(LOCATION_MZONE) e1:SetCost(c15561463.descost) e1:SetTarget(c15561463.destg) e1:SetOperation(c15561463.desop) c:RegisterEffect(e1) end function c15561463.descost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():CheckRemoveOverlayCard(tp,1,REASON_COST) end e:GetHandler():RemoveOverlayCard(tp,1,1,REASON_COST) end function c15561463.destg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1-tp) end if chk==0 then return Duel.IsExistingTarget(aux.TRUE,tp,0,LOCATION_MZONE,1,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY) local g=Duel.SelectTarget(tp,aux.TRUE,tp,0,LOCATION_MZONE,1,1,nil) Duel.SetOperationInfo(0,CATEGORY_DESTROY,g,1,0,0) end function c15561463.desop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) then Duel.Destroy(tc,REASON_EFFECT) end end
gpl-2.0
mercury233/ygopro-scripts
c39719977.lua
2
1264
--デルタ・アタッカー function c39719977.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetTarget(c39719977.target) e1:SetOperation(c39719977.activate) c:RegisterEffect(e1) end function c39719977.filter(c,tp) local tpe=c:GetType() return c:IsFaceup() and bit.band(tpe,TYPE_NORMAL)~=0 and bit.band(tpe,TYPE_TOKEN)==0 and Duel.IsExistingMatchingCard(c39719977.filter2,tp,LOCATION_MZONE,0,2,c,c:GetCode()) end function c39719977.filter2(c,code) local tpe=c:GetType() return c:IsFaceup() and bit.band(tpe,TYPE_NORMAL)~=0 and bit.band(tpe,TYPE_TOKEN)==0 and c:IsCode(code) end function c39719977.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:IsHasType(EFFECT_TYPE_ACTIVATE) and Duel.IsExistingMatchingCard(c39719977.filter,tp,LOCATION_MZONE,0,3,nil,tp) end end function c39719977.activate(e,tp,eg,ep,ev,re,r,rp) local g=Duel.GetMatchingGroup(c39719977.filter,tp,LOCATION_MZONE,0,nil,tp) local tc=g:GetFirst() while tc do local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetCode(EFFECT_DIRECT_ATTACK) e1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END) tc:RegisterEffect(e1) tc=g:GetNext() end end
gpl-2.0
mercury233/ygopro-scripts
c55673611.lua
3
1353
--サイコ・トリガー function c55673611.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_REMOVE+CATEGORY_DRAW) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetCode(EVENT_FREE_CHAIN) e1:SetCondition(c55673611.condition) e1:SetTarget(c55673611.target) e1:SetOperation(c55673611.activate) c:RegisterEffect(e1) end function c55673611.condition(e,tp,eg,ep,ev,re,r,rp) return Duel.GetLP(tp)<Duel.GetLP(1-tp) end function c55673611.filter(c) return c:IsRace(RACE_PSYCHO) and c:IsAbleToRemove() end function c55673611.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and c55673611.filter(chkc) end if chk==0 then return Duel.IsExistingTarget(c55673611.filter,tp,LOCATION_GRAVE,0,2,nil) and Duel.IsPlayerCanDraw(tp,2) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE) local g=Duel.SelectTarget(tp,c55673611.filter,tp,LOCATION_GRAVE,0,2,2,nil) Duel.SetOperationInfo(0,CATEGORY_REMOVE,g,2,tp,LOCATION_GRAVE) Duel.SetOperationInfo(0,CATEGORY_DRAW,nil,0,tp,2) end function c55673611.activate(e,tp,eg,ep,ev,re,r,rp) local g=Duel.GetChainInfo(0,CHAININFO_TARGET_CARDS) local sg=g:Filter(Card.IsRelateToEffect,nil,e) if Duel.Remove(sg,POS_FACEUP,REASON_EFFECT)==2 then Duel.Draw(tp,2,REASON_EFFECT) end end
gpl-2.0
adminmagma/test2
libs/dkjson.lua
31
26560
-- Module options: local always_try_using_lpeg = true local register_global_module_table = false local global_module_name = 'json' --[==[ David Kolf's JSON module for Lua 5.1/5.2 ======================================== *Version 2.4* In the default configuration this module writes no global values, not even the module table. Import it using json = require ("dkjson") In environments where `require` or a similiar function are not available and you cannot receive the return value of the module, you can set the option `register_global_module_table` to `true`. The module table will then be saved in the global variable with the name given by the option `global_module_name`. Exported functions and values: `json.encode (object [, state])` -------------------------------- Create a string representing the object. `Object` can be a table, a string, a number, a boolean, `nil`, `json.null` or any object with a function `__tojson` in its metatable. A table can only use strings and numbers as keys and its values have to be valid objects as well. It raises an error for any invalid data types or reference cycles. `state` is an optional table with the following fields: - `indent` When `indent` (a boolean) is set, the created string will contain newlines and indentations. Otherwise it will be one long line. - `keyorder` `keyorder` is an array to specify the ordering of keys in the encoded output. If an object has keys which are not in this array they are written after the sorted keys. - `level` This is the initial level of indentation used when `indent` is set. For each level two spaces are added. When absent it is set to 0. - `buffer` `buffer` is an array to store the strings for the result so they can be concatenated at once. When it isn't given, the encode function will create it temporary and will return the concatenated result. - `bufferlen` When `bufferlen` is set, it has to be the index of the last element of `buffer`. - `tables` `tables` is a set to detect reference cycles. It is created temporary when absent. Every table that is currently processed is used as key, the value is `true`. When `state.buffer` was set, the return value will be `true` on success. Without `state.buffer` the return value will be a string. `json.decode (string [, position [, null]])` -------------------------------------------- Decode `string` starting at `position` or at 1 if `position` was omitted. `null` is an optional value to be returned for null values. The default is `nil`, but you could set it to `json.null` or any other value. The return values are the object or `nil`, the position of the next character that doesn't belong to the object, and in case of errors an error message. Two metatables are created. Every array or object that is decoded gets a metatable with the `__jsontype` field set to either `array` or `object`. If you want to provide your own metatables use the syntax json.decode (string, position, null, objectmeta, arraymeta) To prevent the assigning of metatables pass `nil`: json.decode (string, position, null, nil) `<metatable>.__jsonorder` ------------------------- `__jsonorder` can overwrite the `keyorder` for a specific table. `<metatable>.__jsontype` ------------------------ `__jsontype` can be either `"array"` or `"object"`. This value is only checked for empty tables. (The default for empty tables is `"array"`). `<metatable>.__tojson (self, state)` ------------------------------------ You can provide your own `__tojson` function in a metatable. In this function you can either add directly to the buffer and return true, or you can return a string. On errors nil and a message should be returned. `json.null` ----------- You can use this value for setting explicit `null` values. `json.version` -------------- Set to `"dkjson 2.4"`. `json.quotestring (string)` --------------------------- Quote a UTF-8 string and escape critical characters using JSON escape sequences. This function is only necessary when you build your own `__tojson` functions. `json.addnewline (state)` ------------------------- When `state.indent` is set, add a newline to `state.buffer` and spaces according to `state.level`. LPeg support ------------ When the local configuration variable `always_try_using_lpeg` is set, this module tries to load LPeg to replace the `decode` function. The speed increase is significant. You can get the LPeg module at <http://www.inf.puc-rio.br/~roberto/lpeg/>. When LPeg couldn't be loaded, the pure Lua functions stay active. In case you don't want this module to require LPeg on its own, disable the option `always_try_using_lpeg` in the options section at the top of the module. In this case you can later load LPeg support using ### `json.use_lpeg ()` Require the LPeg module and replace the functions `quotestring` and and `decode` with functions that use LPeg patterns. This function returns the module table, so you can load the module using: json = require "dkjson".use_lpeg() Alternatively you can use `pcall` so the JSON module still works when LPeg isn't found. json = require "dkjson" pcall (json.use_lpeg) ### `json.using_lpeg` This variable is set to `true` when LPeg was loaded successfully. --------------------------------------------------------------------- Contact ------- You can contact the author by sending an e-mail to 'david' at the domain 'dkolf.de'. --------------------------------------------------------------------- *Copyright (C) 2010-2013 David Heiko Kolf* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. <!-- This documentation can be parsed using Markdown to generate HTML. The source code is enclosed in a HTML comment so it won't be displayed by browsers, but it should be removed from the final HTML file as it isn't a valid HTML comment (and wastes space). --> <!--]==] -- global dependencies: local pairs, type, tostring, tonumber, getmetatable, setmetatable, rawset = pairs, type, tostring, tonumber, getmetatable, setmetatable, rawset local error, require, pcall, select = error, require, pcall, select local floor, huge = math.floor, math.huge local strrep, gsub, strsub, strbyte, strchar, strfind, strlen, strformat = string.rep, string.gsub, string.sub, string.byte, string.char, string.find, string.len, string.format local strmatch = string.match local concat = table.concat local json = { version = "dkjson 2.4" } if register_global_module_table then _G[global_module_name] = json end local _ENV = nil -- blocking globals in Lua 5.2 pcall (function() -- Enable access to blocked metatables. -- Don't worry, this module doesn't change anything in them. local debmeta = require "debug".getmetatable if debmeta then getmetatable = debmeta end end) json.null = setmetatable ({}, { __tojson = function () return "null" end }) local function isarray (tbl) local max, n, arraylen = 0, 0, 0 for k,v in pairs (tbl) do if k == 'n' and type(v) == 'number' then arraylen = v if v > max then max = v end else if type(k) ~= 'number' or k < 1 or floor(k) ~= k then return false end if k > max then max = k end n = n + 1 end end if max > 10 and max > arraylen and max > n * 2 then return false -- don't create an array with too many holes end return true, max end local escapecodes = { ["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b", ["\f"] = "\\f", ["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t" } local function escapeutf8 (uchar) local value = escapecodes[uchar] if value then return value end local a, b, c, d = strbyte (uchar, 1, 4) a, b, c, d = a or 0, b or 0, c or 0, d or 0 if a <= 0x7f then value = a elseif 0xc0 <= a and a <= 0xdf and b >= 0x80 then value = (a - 0xc0) * 0x40 + b - 0x80 elseif 0xe0 <= a and a <= 0xef and b >= 0x80 and c >= 0x80 then value = ((a - 0xe0) * 0x40 + b - 0x80) * 0x40 + c - 0x80 elseif 0xf0 <= a and a <= 0xf7 and b >= 0x80 and c >= 0x80 and d >= 0x80 then value = (((a - 0xf0) * 0x40 + b - 0x80) * 0x40 + c - 0x80) * 0x40 + d - 0x80 else return "" end if value <= 0xffff then return strformat ("\\u%.4x", value) elseif value <= 0x10ffff then -- encode as UTF-16 surrogate pair value = value - 0x10000 local highsur, lowsur = 0xD800 + floor (value/0x400), 0xDC00 + (value % 0x400) return strformat ("\\u%.4x\\u%.4x", highsur, lowsur) else return "" end end local function fsub (str, pattern, repl) -- gsub always builds a new string in a buffer, even when no match -- exists. First using find should be more efficient when most strings -- don't contain the pattern. if strfind (str, pattern) then return gsub (str, pattern, repl) else return str end end local function quotestring (value) -- based on the regexp "escapable" in https://github.com/douglascrockford/JSON-js value = fsub (value, "[%z\1-\31\"\\\127]", escapeutf8) if strfind (value, "[\194\216\220\225\226\239]") then value = fsub (value, "\194[\128-\159\173]", escapeutf8) value = fsub (value, "\216[\128-\132]", escapeutf8) value = fsub (value, "\220\143", escapeutf8) value = fsub (value, "\225\158[\180\181]", escapeutf8) value = fsub (value, "\226\128[\140-\143\168-\175]", escapeutf8) value = fsub (value, "\226\129[\160-\175]", escapeutf8) value = fsub (value, "\239\187\191", escapeutf8) value = fsub (value, "\239\191[\176-\191]", escapeutf8) end return "\"" .. value .. "\"" end json.quotestring = quotestring local function replace(str, o, n) local i, j = strfind (str, o, 1, true) if i then return strsub(str, 1, i-1) .. n .. strsub(str, j+1, -1) else return str end end -- locale independent num2str and str2num functions local decpoint, numfilter local function updatedecpoint () decpoint = strmatch(tostring(0.5), "([^05+])") -- build a filter that can be used to remove group separators numfilter = "[^0-9%-%+eE" .. gsub(decpoint, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%0") .. "]+" end updatedecpoint() local function num2str (num) return replace(fsub(tostring(num), numfilter, ""), decpoint, ".") end local function str2num (str) local num = tonumber(replace(str, ".", decpoint)) if not num then updatedecpoint() num = tonumber(replace(str, ".", decpoint)) end return num end local function addnewline2 (level, buffer, buflen) buffer[buflen+1] = "\n" buffer[buflen+2] = strrep (" ", level) buflen = buflen + 2 return buflen end function json.addnewline (state) if state.indent then state.bufferlen = addnewline2 (state.level or 0, state.buffer, state.bufferlen or #(state.buffer)) end end local encode2 -- forward declaration local function addpair (key, value, prev, indent, level, buffer, buflen, tables, globalorder) local kt = type (key) if kt ~= 'string' and kt ~= 'number' then return nil, "type '" .. kt .. "' is not supported as a key by JSON." end if prev then buflen = buflen + 1 buffer[buflen] = "," end if indent then buflen = addnewline2 (level, buffer, buflen) end buffer[buflen+1] = quotestring (key) buffer[buflen+2] = ":" return encode2 (value, indent, level, buffer, buflen + 2, tables, globalorder) end encode2 = function (value, indent, level, buffer, buflen, tables, globalorder) local valtype = type (value) local valmeta = getmetatable (value) valmeta = type (valmeta) == 'table' and valmeta -- only tables local valtojson = valmeta and valmeta.__tojson if valtojson then if tables[value] then return nil, "reference cycle" end tables[value] = true local state = { indent = indent, level = level, buffer = buffer, bufferlen = buflen, tables = tables, keyorder = globalorder } local ret, msg = valtojson (value, state) if not ret then return nil, msg end tables[value] = nil buflen = state.bufferlen if type (ret) == 'string' then buflen = buflen + 1 buffer[buflen] = ret end elseif value == nil then buflen = buflen + 1 buffer[buflen] = "null" elseif valtype == 'number' then local s if value ~= value or value >= huge or -value >= huge then -- This is the behaviour of the original JSON implementation. s = "null" else s = num2str (value) end buflen = buflen + 1 buffer[buflen] = s elseif valtype == 'boolean' then buflen = buflen + 1 buffer[buflen] = value and "true" or "false" elseif valtype == 'string' then buflen = buflen + 1 buffer[buflen] = quotestring (value) elseif valtype == 'table' then if tables[value] then return nil, "reference cycle" end tables[value] = true level = level + 1 local isa, n = isarray (value) if n == 0 and valmeta and valmeta.__jsontype == 'object' then isa = false end local msg if isa then -- JSON array buflen = buflen + 1 buffer[buflen] = "[" for i = 1, n do buflen, msg = encode2 (value[i], indent, level, buffer, buflen, tables, globalorder) if not buflen then return nil, msg end if i < n then buflen = buflen + 1 buffer[buflen] = "," end end buflen = buflen + 1 buffer[buflen] = "]" else -- JSON object local prev = false buflen = buflen + 1 buffer[buflen] = "{" local order = valmeta and valmeta.__jsonorder or globalorder if order then local used = {} n = #order for i = 1, n do local k = order[i] local v = value[k] if v then used[k] = true buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder) prev = true -- add a seperator before the next element end end for k,v in pairs (value) do if not used[k] then buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder) if not buflen then return nil, msg end prev = true -- add a seperator before the next element end end else -- unordered for k,v in pairs (value) do buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder) if not buflen then return nil, msg end prev = true -- add a seperator before the next element end end if indent then buflen = addnewline2 (level - 1, buffer, buflen) end buflen = buflen + 1 buffer[buflen] = "}" end tables[value] = nil else return nil, "type '" .. valtype .. "' is not supported by JSON." end return buflen end function json.encode (value, state) state = state or {} local oldbuffer = state.buffer local buffer = oldbuffer or {} updatedecpoint() local ret, msg = encode2 (value, state.indent, state.level or 0, buffer, state.bufferlen or 0, state.tables or {}, state.keyorder) if not ret then error (msg, 2) elseif oldbuffer then state.bufferlen = ret return true else return concat (buffer) end end local function loc (str, where) local line, pos, linepos = 1, 1, 0 while true do pos = strfind (str, "\n", pos, true) if pos and pos < where then line = line + 1 linepos = pos pos = pos + 1 else break end end return "line " .. line .. ", column " .. (where - linepos) end local function unterminated (str, what, where) return nil, strlen (str) + 1, "unterminated " .. what .. " at " .. loc (str, where) end local function scanwhite (str, pos) while true do pos = strfind (str, "%S", pos) if not pos then return nil end if strsub (str, pos, pos + 2) == "\239\187\191" then -- UTF-8 Byte Order Mark pos = pos + 3 else return pos end end end local escapechars = { ["\""] = "\"", ["\\"] = "\\", ["/"] = "/", ["b"] = "\b", ["f"] = "\f", ["n"] = "\n", ["r"] = "\r", ["t"] = "\t" } local function unichar (value) if value < 0 then return nil elseif value <= 0x007f then return strchar (value) elseif value <= 0x07ff then return strchar (0xc0 + floor(value/0x40), 0x80 + (floor(value) % 0x40)) elseif value <= 0xffff then return strchar (0xe0 + floor(value/0x1000), 0x80 + (floor(value/0x40) % 0x40), 0x80 + (floor(value) % 0x40)) elseif value <= 0x10ffff then return strchar (0xf0 + floor(value/0x40000), 0x80 + (floor(value/0x1000) % 0x40), 0x80 + (floor(value/0x40) % 0x40), 0x80 + (floor(value) % 0x40)) else return nil end end local function scanstring (str, pos) local lastpos = pos + 1 local buffer, n = {}, 0 while true do local nextpos = strfind (str, "[\"\\]", lastpos) if not nextpos then return unterminated (str, "string", pos) end if nextpos > lastpos then n = n + 1 buffer[n] = strsub (str, lastpos, nextpos - 1) end if strsub (str, nextpos, nextpos) == "\"" then lastpos = nextpos + 1 break else local escchar = strsub (str, nextpos + 1, nextpos + 1) local value if escchar == "u" then value = tonumber (strsub (str, nextpos + 2, nextpos + 5), 16) if value then local value2 if 0xD800 <= value and value <= 0xDBff then -- we have the high surrogate of UTF-16. Check if there is a -- low surrogate escaped nearby to combine them. if strsub (str, nextpos + 6, nextpos + 7) == "\\u" then value2 = tonumber (strsub (str, nextpos + 8, nextpos + 11), 16) if value2 and 0xDC00 <= value2 and value2 <= 0xDFFF then value = (value - 0xD800) * 0x400 + (value2 - 0xDC00) + 0x10000 else value2 = nil -- in case it was out of range for a low surrogate end end end value = value and unichar (value) if value then if value2 then lastpos = nextpos + 12 else lastpos = nextpos + 6 end end end end if not value then value = escapechars[escchar] or escchar lastpos = nextpos + 2 end n = n + 1 buffer[n] = value end end if n == 1 then return buffer[1], lastpos elseif n > 1 then return concat (buffer), lastpos else return "", lastpos end end local scanvalue -- forward declaration local function scantable (what, closechar, str, startpos, nullval, objectmeta, arraymeta) local len = strlen (str) local tbl, n = {}, 0 local pos = startpos + 1 if what == 'object' then setmetatable (tbl, objectmeta) else setmetatable (tbl, arraymeta) end while true do pos = scanwhite (str, pos) if not pos then return unterminated (str, what, startpos) end local char = strsub (str, pos, pos) if char == closechar then return tbl, pos + 1 end local val1, err val1, pos, err = scanvalue (str, pos, nullval, objectmeta, arraymeta) if err then return nil, pos, err end pos = scanwhite (str, pos) if not pos then return unterminated (str, what, startpos) end char = strsub (str, pos, pos) if char == ":" then if val1 == nil then return nil, pos, "cannot use nil as table index (at " .. loc (str, pos) .. ")" end pos = scanwhite (str, pos + 1) if not pos then return unterminated (str, what, startpos) end local val2 val2, pos, err = scanvalue (str, pos, nullval, objectmeta, arraymeta) if err then return nil, pos, err end tbl[val1] = val2 pos = scanwhite (str, pos) if not pos then return unterminated (str, what, startpos) end char = strsub (str, pos, pos) else n = n + 1 tbl[n] = val1 end if char == "," then pos = pos + 1 end end end scanvalue = function (str, pos, nullval, objectmeta, arraymeta) pos = pos or 1 pos = scanwhite (str, pos) if not pos then return nil, strlen (str) + 1, "no valid JSON value (reached the end)" end local char = strsub (str, pos, pos) if char == "{" then return scantable ('object', "}", str, pos, nullval, objectmeta, arraymeta) elseif char == "[" then return scantable ('array', "]", str, pos, nullval, objectmeta, arraymeta) elseif char == "\"" then return scanstring (str, pos) else local pstart, pend = strfind (str, "^%-?[%d%.]+[eE]?[%+%-]?%d*", pos) if pstart then local number = str2num (strsub (str, pstart, pend)) if number then return number, pend + 1 end end pstart, pend = strfind (str, "^%a%w*", pos) if pstart then local name = strsub (str, pstart, pend) if name == "true" then return true, pend + 1 elseif name == "false" then return false, pend + 1 elseif name == "null" then return nullval, pend + 1 end end return nil, pos, "no valid JSON value at " .. loc (str, pos) end end local function optionalmetatables(...) if select("#", ...) > 0 then return ... else return {__jsontype = 'object'}, {__jsontype = 'array'} end end function json.decode (str, pos, nullval, ...) local objectmeta, arraymeta = optionalmetatables(...) return scanvalue (str, pos, nullval, objectmeta, arraymeta) end function json.use_lpeg () local g = require ("lpeg") if g.version() == "0.11" then error "due to a bug in LPeg 0.11, it cannot be used for JSON matching" end local pegmatch = g.match local P, S, R = g.P, g.S, g.R local function ErrorCall (str, pos, msg, state) if not state.msg then state.msg = msg .. " at " .. loc (str, pos) state.pos = pos end return false end local function Err (msg) return g.Cmt (g.Cc (msg) * g.Carg (2), ErrorCall) end local Space = (S" \n\r\t" + P"\239\187\191")^0 local PlainChar = 1 - S"\"\\\n\r" local EscapeSequence = (P"\\" * g.C (S"\"\\/bfnrt" + Err "unsupported escape sequence")) / escapechars local HexDigit = R("09", "af", "AF") local function UTF16Surrogate (match, pos, high, low) high, low = tonumber (high, 16), tonumber (low, 16) if 0xD800 <= high and high <= 0xDBff and 0xDC00 <= low and low <= 0xDFFF then return true, unichar ((high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000) else return false end end local function UTF16BMP (hex) return unichar (tonumber (hex, 16)) end local U16Sequence = (P"\\u" * g.C (HexDigit * HexDigit * HexDigit * HexDigit)) local UnicodeEscape = g.Cmt (U16Sequence * U16Sequence, UTF16Surrogate) + U16Sequence/UTF16BMP local Char = UnicodeEscape + EscapeSequence + PlainChar local String = P"\"" * g.Cs (Char ^ 0) * (P"\"" + Err "unterminated string") local Integer = P"-"^(-1) * (P"0" + (R"19" * R"09"^0)) local Fractal = P"." * R"09"^0 local Exponent = (S"eE") * (S"+-")^(-1) * R"09"^1 local Number = (Integer * Fractal^(-1) * Exponent^(-1))/str2num local Constant = P"true" * g.Cc (true) + P"false" * g.Cc (false) + P"null" * g.Carg (1) local SimpleValue = Number + String + Constant local ArrayContent, ObjectContent -- The functions parsearray and parseobject parse only a single value/pair -- at a time and store them directly to avoid hitting the LPeg limits. local function parsearray (str, pos, nullval, state) local obj, cont local npos local t, nt = {}, 0 repeat obj, cont, npos = pegmatch (ArrayContent, str, pos, nullval, state) if not npos then break end pos = npos nt = nt + 1 t[nt] = obj until cont == 'last' return pos, setmetatable (t, state.arraymeta) end local function parseobject (str, pos, nullval, state) local obj, key, cont local npos local t = {} repeat key, obj, cont, npos = pegmatch (ObjectContent, str, pos, nullval, state) if not npos then break end pos = npos t[key] = obj until cont == 'last' return pos, setmetatable (t, state.objectmeta) end local Array = P"[" * g.Cmt (g.Carg(1) * g.Carg(2), parsearray) * Space * (P"]" + Err "']' expected") local Object = P"{" * g.Cmt (g.Carg(1) * g.Carg(2), parseobject) * Space * (P"}" + Err "'}' expected") local Value = Space * (Array + Object + SimpleValue) local ExpectedValue = Value + Space * Err "value expected" ArrayContent = Value * Space * (P"," * g.Cc'cont' + g.Cc'last') * g.Cp() local Pair = g.Cg (Space * String * Space * (P":" + Err "colon expected") * ExpectedValue) ObjectContent = Pair * Space * (P"," * g.Cc'cont' + g.Cc'last') * g.Cp() local DecodeValue = ExpectedValue * g.Cp () function json.decode (str, pos, nullval, ...) local state = {} state.objectmeta, state.arraymeta = optionalmetatables(...) local obj, retpos = pegmatch (DecodeValue, str, pos, nullval, state) if state.msg then return nil, state.pos, state.msg else return obj, retpos end end -- use this function only once: json.use_lpeg = function () return json end json.using_lpeg = true return json -- so you can get the module using json = require "dkjson".use_lpeg() end if always_try_using_lpeg then pcall (json.use_lpeg) end return json -->
gpl-2.0
mercury233/ygopro-scripts
c47699948.lua
2
3588
--シンクロ・ディレンマ function c47699948.initial_effect(c) --Activate local e0=Effect.CreateEffect(c) e0:SetType(EFFECT_TYPE_ACTIVATE) e0:SetCode(EVENT_FREE_CHAIN) c:RegisterEffect(e0) --special summon local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(47699948,0)) e1:SetCategory(CATEGORY_SPECIAL_SUMMON) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetRange(LOCATION_SZONE) e1:SetCountLimit(1,47699948) e1:SetCost(c47699948.spcost) e1:SetTarget(c47699948.sptg1) e1:SetOperation(c47699948.spop1) c:RegisterEffect(e1) --special summon local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(47699948,1)) e2:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_DESTROY) e2:SetType(EFFECT_TYPE_IGNITION) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetRange(LOCATION_SZONE) e2:SetCountLimit(1,47699948) e2:SetTarget(c47699948.sptg2) e2:SetOperation(c47699948.spop2) c:RegisterEffect(e2) end function c47699948.costfilter(c,e,tp) return c:IsSetCard(0x1017) and c:IsType(TYPE_MONSTER) and (c:IsFaceup() or not c:IsLocation(LOCATION_MZONE)) and c:IsAbleToGraveAsCost() and Duel.GetMZoneCount(tp,c)>0 and Duel.IsExistingMatchingCard(c47699948.spfilter,tp,LOCATION_HAND,0,1,c,e,tp) end function c47699948.spfilter(c,e,tp) return c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function c47699948.spcost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(c47699948.costfilter,tp,LOCATION_HAND+LOCATION_MZONE,0,1,nil,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE) local g=Duel.SelectMatchingCard(tp,c47699948.costfilter,tp,LOCATION_HAND+LOCATION_MZONE,0,1,1,nil,e,tp) Duel.SendtoGrave(g,REASON_COST) end function c47699948.sptg1(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return true end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_HAND) end function c47699948.spop1(e,tp,eg,ep,ev,re,r,rp) if Duel.GetLocationCount(tp,LOCATION_MZONE)<1 then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,c47699948.spfilter,tp,LOCATION_HAND,0,1,1,nil,e,tp) if g:GetCount()>0 then Duel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP) end end function c47699948.desfilter(c,e,tp) local code=c:GetOriginalCode() return Duel.GetMZoneCount(tp,c)>0 and Duel.IsExistingMatchingCard(c47699948.spfilter2,tp,LOCATION_HAND+LOCATION_GRAVE,0,1,nil,code,e,tp) end function c47699948.spfilter2(c,code,e,tp) return not c:IsCode(code) and c:IsSetCard(0x1017) and c:IsType(TYPE_MONSTER) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function c47699948.sptg2(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsOnField() and c47699948.desfilter(chkc,e,tp) end if chk==0 then return Duel.IsExistingTarget(c47699948.desfilter,tp,LOCATION_ONFIELD,0,1,e:GetHandler(),e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY) local g=Duel.SelectTarget(tp,c47699948.desfilter,tp,LOCATION_ONFIELD,0,1,1,e:GetHandler(),e,tp) Duel.SetOperationInfo(0,CATEGORY_DESTROY,g,1,0,0) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_HAND+LOCATION_GRAVE) end function c47699948.spop2(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) and Duel.Destroy(tc,REASON_EFFECT)~=0 and Duel.GetLocationCount(tp,LOCATION_MZONE)>0 then Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local sg=Duel.SelectMatchingCard(tp,aux.NecroValleyFilter(c47699948.spfilter2),tp,LOCATION_HAND+LOCATION_GRAVE,0,1,1,nil,tc:GetOriginalCode(),e,tp) if sg:GetCount()>0 then Duel.SpecialSummon(sg,0,tp,tp,false,false,POS_FACEUP) end end end
gpl-2.0
mercury233/ygopro-scripts
c68934651.lua
2
3240
--ファイアウォール・ドラゴン・ダークフルード function c68934651.initial_effect(c) c:EnableCounterPermit(0x52) --link summon aux.AddLinkProcedure(c,aux.FilterBoolFunction(Card.IsLinkType,TYPE_EFFECT),3) c:EnableReviveLimit() --counter local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(68934651,0)) e1:SetCategory(CATEGORY_COUNTER) e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e1:SetProperty(EFFECT_FLAG_DELAY) e1:SetCode(EVENT_SPSUMMON_SUCCESS) e1:SetCondition(c68934651.ctcon) e1:SetTarget(c68934651.cttg) e1:SetOperation(c68934651.ctop) c:RegisterEffect(e1) --atk up local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_SINGLE) e2:SetCode(EFFECT_UPDATE_ATTACK) e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE) e2:SetRange(LOCATION_MZONE) e2:SetCondition(c68934651.atkcon) e2:SetValue(c68934651.atkval) c:RegisterEffect(e2) --negate local e3=Effect.CreateEffect(c) e3:SetDescription(aux.Stringid(68934651,1)) e3:SetCategory(CATEGORY_NEGATE) e3:SetType(EFFECT_TYPE_QUICK_O) e3:SetCode(EVENT_CHAINING) e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DAMAGE_CAL) e3:SetRange(LOCATION_MZONE) e3:SetCondition(c68934651.discon) e3:SetCost(c68934651.discost) e3:SetTarget(c68934651.distg) e3:SetOperation(c68934651.disop) c:RegisterEffect(e3) end function c68934651.ctcon(e,tp,eg,ep,ev,re,r,rp) return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK) end function c68934651.cfilter(c,type) return c:IsRace(RACE_CYBERSE) and c:IsType(type) end function c68934651.cttg(e,tp,eg,ep,ev,re,r,rp,chk) local ct=0 for i,type in ipairs({TYPE_FUSION,TYPE_RITUAL,TYPE_SYNCHRO,TYPE_XYZ}) do if Duel.IsExistingMatchingCard(c68934651.cfilter,tp,LOCATION_GRAVE,0,1,nil,type) then ct=ct+1 end end if chk==0 then return ct>0 and e:GetHandler():IsCanAddCounter(0x52,ct) end end function c68934651.ctop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if c:IsFacedown() or not c:IsRelateToEffect(e) then return end local ct=0 for i,type in ipairs({TYPE_FUSION,TYPE_RITUAL,TYPE_SYNCHRO,TYPE_XYZ}) do if Duel.IsExistingMatchingCard(c68934651.cfilter,tp,LOCATION_GRAVE,0,1,nil,type) then ct=ct+1 end end if ct>0 then c:AddCounter(0x52,ct) end end function c68934651.atkcon(e,tp,eg,ep,ev,re,r,rp) local ph=Duel.GetCurrentPhase() return ph>=PHASE_BATTLE_START and ph<=PHASE_BATTLE end function c68934651.atkval(e,c) return c:GetCounter(0x52)*2500 end function c68934651.discon(e,tp,eg,ep,ev,re,r,rp) return rp==1-tp and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) and Duel.IsChainNegatable(ev) and re:IsActiveType(TYPE_MONSTER) end function c68934651.discost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():IsCanRemoveCounter(tp,0x52,1,REASON_COST) end e:GetHandler():RemoveCounter(tp,0x52,1,REASON_COST) end function c68934651.distg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return true end Duel.SetOperationInfo(0,CATEGORY_NEGATE,eg,1,0,0) if Duel.GetAttacker()==e:GetHandler() then e:SetLabel(1) else e:SetLabel(0) end end function c68934651.disop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() Duel.NegateActivation(ev) if e:GetLabel()==1 and c:IsRelateToEffect(e) and c:IsChainAttackable(0) then Duel.ChainAttack() end end
gpl-2.0
mercury233/ygopro-scripts
c3507053.lua
2
3080
--乾燥機塊ドライドレイク function c3507053.initial_effect(c) --link summon c:EnableReviveLimit() aux.AddLinkProcedure(c,aux.FilterBoolFunction(Card.IsLinkSetCard,0x14b),1,1) --cannot link material local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE) e1:SetCode(EFFECT_CANNOT_BE_LINK_MATERIAL) e1:SetValue(c3507053.lmlimit) c:RegisterEffect(e1) --atk local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_SINGLE) e2:SetCode(EFFECT_UPDATE_ATTACK) e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE) e2:SetRange(LOCATION_MZONE) e2:SetValue(1000) e2:SetCondition(c3507053.atkcon) c:RegisterEffect(e2) --change local e3=Effect.CreateEffect(c) e3:SetDescription(aux.Stringid(3507053,0)) e3:SetType(EFFECT_TYPE_QUICK_O) e3:SetCode(EVENT_FREE_CHAIN) e3:SetRange(LOCATION_MZONE) e3:SetHintTiming(TIMING_BATTLE_START) e3:SetCountLimit(1) e3:SetCondition(c3507053.chcon) e3:SetTarget(c3507053.chtg) e3:SetOperation(c3507053.chop) c:RegisterEffect(e3) --negate attack local e4=Effect.CreateEffect(c) e4:SetDescription(aux.Stringid(3507053,1)) e4:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e4:SetCode(EVENT_BE_BATTLE_TARGET) e4:SetCountLimit(1) e4:SetCondition(c3507053.negcon) e4:SetOperation(c3507053.negop) c:RegisterEffect(e4) end function c3507053.lmlimit(e) local c=e:GetHandler() return c:IsStatus(STATUS_SPSUMMON_TURN) and c:IsSummonType(SUMMON_TYPE_LINK) end function c3507053.atkcon(e) return e:GetHandler():IsLinkState() end function c3507053.chcon(e,tp,eg,ep,ev,re,r,rp) local ph=Duel.GetCurrentPhase() return ph>=PHASE_BATTLE_START and ph<=PHASE_BATTLE and e:GetHandler():GetMutualLinkedGroupCount()>0 and Duel.GetTurnPlayer()==tp and Duel.GetCurrentChain()==0 end function c3507053.chfilter(c) return c:IsFaceup() and c:IsSetCard(0x14b) and c:GetSequence()<5 end function c3507053.fselect(g,c) return g:IsContains(c) end function c3507053.chtg(e,tp,eg,ep,ev,re,r,rp,chk) local g=Duel.GetMatchingGroup(c3507053.chfilter,tp,LOCATION_MZONE,0,nil) if chk==0 then return g:CheckSubGroup(c3507053.fselect,2,2,e:GetHandler()) end end function c3507053.chop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if not c:IsRelateToEffect(e) then return end local g=Duel.GetMatchingGroup(c3507053.chfilter,tp,LOCATION_MZONE,0,nil) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_OPERATECARD) local sg=g:SelectSubGroup(tp,c3507053.fselect,false,2,2,c) if sg and sg:GetCount()==2 then Duel.HintSelection(sg) local tc1=sg:GetFirst() local tc2=sg:GetNext() Duel.SwapSequence(tc1,tc2) local tc=tc1 if tc==c then tc=tc2 end local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE) e1:SetCode(EFFECT_EXTRA_ATTACK) e1:SetValue(1) e1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END) tc:RegisterEffect(e1) end end function c3507053.negcon(e,tp,eg,ep,ev,re,r,rp) return e:GetHandler():GetMutualLinkedGroupCount()==0 end function c3507053.negop(e,tp,eg,ep,ev,re,r,rp) Duel.NegateAttack() end
gpl-2.0
rouing/FHLG-BW
entities/entities/item_health/init.lua
1
1227
AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include('shared.lua') function ENT:SpawnFunction( ply, tr ) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 20 local ent = ents.Create( "item_health" ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent end function ENT:Initialize() self.Entity:SetModel( "models/items/healthkit.mdl") self.Entity:PhysicsInit(SOLID_VPHYSICS) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) local phys = self.Entity:GetPhysicsObject() if(phys:IsValid()) then phys:Wake() end self.Time = CurTime() end function ENT:Use(activator,caller) if (caller:Health()<caller:GetMaxHealth()) then caller:SetHealth(caller:GetMaxHealth()) if caller:GetTable().PoisonDuration>0 && math.random()>0.5 then PoisonPlayer(caller, caller:GetTable().PoisonDuration*2, caller:GetTable().PoisonAttacker, caller:GetTable().PoisonInflictor) Notify(caller,1,3,"Bought medkits usually only make the poison worse! Find a Medic or dispenser!") end self.Entity:Remove() end end function ENT:OnRemove() local ply = self.Entity:GetNWEntity("owner") ply:GetTable().maxDrugs = ply:GetTable().maxDrugs - 1 end
unlicense
mercury233/ygopro-scripts
c17286057.lua
4
3105
--ヘリオス・トリス・メギストス function c17286057.initial_effect(c) --special summon local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_FIELD) e1:SetCode(EFFECT_SPSUMMON_PROC) e1:SetProperty(EFFECT_FLAG_UNCOPYABLE) e1:SetRange(LOCATION_HAND) e1:SetCondition(c17286057.hspcon) e1:SetOperation(c17286057.hspop) c:RegisterEffect(e1) --atk/def local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_SINGLE) e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE) e2:SetRange(LOCATION_MZONE) e2:SetCode(EFFECT_SET_ATTACK) e2:SetValue(c17286057.value) c:RegisterEffect(e2) local e3=e2:Clone() e3:SetCode(EFFECT_SET_DEFENSE) c:RegisterEffect(e3) --spsummon local e4=Effect.CreateEffect(c) e4:SetDescription(aux.Stringid(17286057,0)) e4:SetCategory(CATEGORY_SPECIAL_SUMMON) e4:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F) e4:SetCode(EVENT_PHASE+PHASE_END) e4:SetRange(LOCATION_GRAVE) e4:SetCountLimit(1) e4:SetCondition(c17286057.spcon) e4:SetTarget(c17286057.sptg) e4:SetOperation(c17286057.spop) c:RegisterEffect(e4) --chain attack local e5=Effect.CreateEffect(c) e5:SetType(EFFECT_TYPE_SINGLE) e5:SetCode(EFFECT_EXTRA_ATTACK) e5:SetValue(1) e5:SetCondition(c17286057.atcon) c:RegisterEffect(e5) end function c17286057.hspfilter(c,ft,tp) return c:IsCode(80887952) and (ft>0 or (c:IsControler(tp) and c:GetSequence()<5)) and (c:IsControler(tp) or c:IsFaceup()) end function c17286057.hspcon(e,c) if c==nil then return true end local tp=c:GetControler() local ft=Duel.GetLocationCount(tp,LOCATION_MZONE) return ft>-1 and Duel.CheckReleaseGroup(tp,c17286057.hspfilter,1,nil,ft,tp) end function c17286057.hspop(e,tp,eg,ep,ev,re,r,rp,c) local ft=Duel.GetLocationCount(tp,LOCATION_MZONE) local g=Duel.SelectReleaseGroup(tp,c17286057.hspfilter,1,1,nil,ft,tp) Duel.Release(g,REASON_COST) end function c17286057.filter(c) return c:IsFaceup() and c:IsType(TYPE_MONSTER) end function c17286057.value(e,c) return Duel.GetMatchingGroupCount(c17286057.filter,0,LOCATION_REMOVED,LOCATION_REMOVED,nil)*300 end function c17286057.spcon(e,tp,eg,ep,ev,re,r,rp) return e:GetHandler():IsReason(REASON_BATTLE) and e:GetHandler():GetTurnID()==Duel.GetTurnCount() end function c17286057.sptg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and e:GetHandler():IsCanBeSpecialSummoned(e,0,tp,false,false) end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,e:GetHandler(),1,0,0) end function c17286057.spop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if c:IsRelateToEffect(e) and Duel.SpecialSummonStep(c,0,tp,tp,false,false,POS_FACEUP) then local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE) e1:SetRange(LOCATION_MZONE) e1:SetCode(EFFECT_UPDATE_ATTACK) e1:SetValue(500) e1:SetReset(RESET_EVENT+RESETS_STANDARD) c:RegisterEffect(e1) local e2=e1:Clone() e2:SetCode(EFFECT_UPDATE_DEFENSE) c:RegisterEffect(e2) end Duel.SpecialSummonComplete() end function c17286057.atcon(e) return Duel.GetFieldGroupCount(e:GetHandlerPlayer(),0,LOCATION_MZONE)>0 end
gpl-2.0
mercury233/ygopro-scripts
c26435595.lua
2
2095
--聖菓使クーベル function c26435595.initial_effect(c) c:EnableReviveLimit() aux.AddFusionProcFunRep(c,aux.FilterBoolFunction(Card.IsFusionType,TYPE_PENDULUM),2,true) aux.EnablePendulumAttribute(c,false) --pendulum set local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(26435595,0)) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetRange(LOCATION_PZONE) e1:SetCountLimit(1,26435595) e1:SetTarget(c26435595.pctg) e1:SetOperation(c26435595.pcop) c:RegisterEffect(e1) --pendulum local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(26435595,1)) e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e2:SetCode(EVENT_DESTROYED) e2:SetProperty(EFFECT_FLAG_DELAY) e2:SetCondition(c26435595.pencon) e2:SetTarget(c26435595.pentg) e2:SetOperation(c26435595.penop) c:RegisterEffect(e2) end function c26435595.pcfilter(c,tp) return c:IsFaceup() and c:IsType(TYPE_PENDULUM) and not c:IsForbidden() and c:CheckUniqueOnField(tp,LOCATION_SZONE) end function c26435595.pctg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return (Duel.CheckLocation(tp,LOCATION_PZONE,0) or Duel.CheckLocation(tp,LOCATION_PZONE,1)) and Duel.IsExistingMatchingCard(c26435595.pcfilter,tp,LOCATION_EXTRA,0,1,nil,tp) end end function c26435595.pcop(e,tp,eg,ep,ev,re,r,rp) if not Duel.CheckLocation(tp,LOCATION_PZONE,0) and not Duel.CheckLocation(tp,LOCATION_PZONE,1) then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOFIELD) local g=Duel.SelectMatchingCard(tp,c26435595.pcfilter,tp,LOCATION_EXTRA,0,1,1,nil,tp) if g:GetCount()>0 then Duel.MoveToField(g:GetFirst(),tp,tp,LOCATION_PZONE,POS_FACEUP,true) end end function c26435595.pencon(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() return c:IsPreviousLocation(LOCATION_MZONE) and c:IsFaceup() end function c26435595.pentg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.CheckLocation(tp,LOCATION_PZONE,0) or Duel.CheckLocation(tp,LOCATION_PZONE,1) end end function c26435595.penop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if c:IsRelateToEffect(e) then Duel.MoveToField(c,tp,tp,LOCATION_PZONE,POS_FACEUP,true) end end
gpl-2.0
linushsao/marsu_game-linus-v0.2
mods/deprecated/mymonths/months.lua
1
3453
local timechange = 0 local gm = 0 local gn = 0 -- Set holidays local hol = { {"12", 14, "It is New Years Eve!"}, {"1", 1, "It is New Years Day!"}, {"3", 12, "It is Friendship Day!"}, {"6", 5, "It is Minetest Day!"}, {"4", 10, "It is Miners Day!"}, {"8", 12, "It is Builders Day!"}, {"10", 8, "It is Harvest Day!"}, } -- Set days local days = { {1, 8, "Monday"}, {2, 9, "Tuesday"}, {3, 10, "Wednesday"}, {4, 11, "Thursday"}, {5, 12, "Friday"}, {6, 13, "Saturday"}, {7, 14, "Sunday"}, } -- this stops undeclared variable errors local t1, t2, t3, t4, t5 = 0, 0, 0, 0, 0 -- Set months local mon = { {1, "January", t5, t1, .9}, {2, "February", t5, t1, .9}, {3, "March", t4, t2, 1}, {4, "April", t4, t2, 1}, {5, "May", t3, t3, 1}, {6, "June", t3, t3, 1.1}, {7, "July", t1, t5, 1.2}, {8, "August", t1, t5, 1.5}, {9, "September",t3, t3, 1}, {10, "October", t3, t3, 1}, {11, "November", t4, t2, .9}, {12, "December", t4, t2, .9}, } -- Sets Month and length of day local timer = 0 minetest.register_globalstep(function(dtime) -- Checks every X seconds timer = timer + dtime --do not change because it will effect other values if timer < 3 then return end timer = 0 --Day Night Speeds (Thanks to sofar for this) local dc = tonumber(mymonths.day_counter) local mc = tonumber(mymonths.month_counter) local x = ((mc-1)*14)+dc local ratio = ((math.cos((x / 168) * 2 * math.pi) * 0.8) / 2.0) + 0.5 local nightratio = math.floor(72*(ratio+0.5)) local dayratio = math.floor(72/(ratio+0.5)) --Checks for morning local time_in_seconds = minetest.get_timeofday() * 24000 if time_in_seconds >= 12001 and timechange == 0 then timechange = 1 gm = 1 end if time_in_seconds <= 12000 and timechange == 1 then timechange = 0 mymonths.day_counter = mymonths.day_counter + 1 end if mymonths.day_counter >= 15 then mymonths.month_counter = mymonths.month_counter + 1 mymonths.day_counter = 1 end if tonumber(mymonths.month_counter) == nil then mymonths.monthcounter = 6 elseif tonumber(mymonths.month_counter) >= 13 then mymonths.month_counter = 1 mymonths.day_counter = 1 end -- Sets time speed in the morning if time_in_seconds >= 6000 and time_in_seconds <= 12000 and gm == 1 then minetest.setting_set("time_speed", dayratio) minetest.chat_send_all("Good Morning! It is "..mymonths.day_name.." "..mymonths.month.." "..mymonths.day_counter) --minetest.chat_send_all("Time speed is "..dayratio.." and "..nightratio) ---Holidays for i in ipairs(hol) do local h1 = hol[i][1] local h2 = hol[i][2] local h3 = hol[i][3] if mymonths.month_counter == h1 and mymonths.day_counter == h2 then minetest.chat_send_all(h3) end end gm = 0 gn = 1 end --Months for i in ipairs(mon) do local m1 = mon[i][1] local m2 = mon[i][2] local m3 = mon[i][3] local m4 = mon[i][4] local m5 = mon[i][5] if mymonths.month_counter == m1 then mymonths.month = m2 mymonths.day_speed = m3 mymonths.night_speed = m4 end end if time_in_seconds >= 22000 and time_in_seconds <= 24000 and gn == 1 then minetest.setting_set("time_speed", nightratio) gn = 0 end -- Set the name of the day for i in ipairs(days) do local w1 = days[i][1] local w2 = days[i][2] local dy = days[i][3] if mymonths.day_counter == w1 or mymonths.day_counter == w2 then mymonths.day_name = dy end end end)
gpl-3.0
mercury233/ygopro-scripts
c66994718.lua
6
1133
--ラプターズ・ガスト function c66994718.initial_effect(c) --activate local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_NEGATE+CATEGORY_DESTROY) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_CHAINING) e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DAMAGE_CAL) e1:SetCondition(c66994718.condition) e1:SetTarget(c66994718.target) e1:SetOperation(c66994718.activate) c:RegisterEffect(e1) end function c66994718.cfilter(c) return c:IsFaceup() and c:IsSetCard(0xba) end function c66994718.condition(e,tp,eg,ep,ev,re,r,rp) return re:IsHasType(EFFECT_TYPE_ACTIVATE) and Duel.IsChainNegatable(ev) and Duel.IsExistingMatchingCard(c66994718.cfilter,tp,LOCATION_ONFIELD,0,1,nil) end function c66994718.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return true end if re:GetHandler():IsRelateToEffect(re) and re:GetHandler():IsDestructable() then Duel.SetOperationInfo(0,CATEGORY_DESTROY,re:GetHandler(),1,0,0) end end function c66994718.activate(e,tp,eg,ep,ev,re,r,rp) if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then Duel.Destroy(re:GetHandler(),REASON_EFFECT) end end
gpl-2.0
mercury233/ygopro-scripts
c48636108.lua
2
2006
--U.A.マン・オブ・ザ・マッチ function c48636108.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(48636108,0)) e1:SetCategory(CATEGORY_SPECIAL_SUMMON) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_BATTLED) e1:SetCountLimit(1,48636108+EFFECT_COUNT_CODE_OATH) e1:SetCondition(c48636108.spcon) e1:SetTarget(c48636108.sptg) e1:SetOperation(c48636108.spop) c:RegisterEffect(e1) local e2=e1:Clone() e2:SetDescription(aux.Stringid(48636108,1)) e2:SetCondition(c48636108.spcon2) e2:SetCode(EVENT_BATTLE_DAMAGE) c:RegisterEffect(e2) end function c48636108.filter(c) return c:IsSetCard(0xb2,0x107) and c:IsType(TYPE_MONSTER) end function c48636108.spfilter(c,e,tp) return c48636108.filter(c) and c:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP_DEFENSE) end function c48636108.spcon(e,tp,eg,ep,ev,re,r,rp) local a=Duel.GetAttacker() local d=Duel.GetAttackTarget() if not d then return false end if d:IsControler(tp) then a,d=d,a end return c48636108.filter(a) and d:IsStatus(STATUS_BATTLE_DESTROYED) end function c48636108.spcon2(e,tp,eg,ep,ev,re,r,rp) local tc=eg:GetFirst() return ep~=tp and tc:IsControler(tp) and c48636108.filter(tc) end function c48636108.sptg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingMatchingCard(c48636108.spfilter,tp,LOCATION_HAND+LOCATION_GRAVE,0,1,nil,e,tp) end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_DECK) end function c48636108.spop(e,tp,eg,ep,ev,re,r,rp) local ft=Duel.GetLocationCount(tp,LOCATION_MZONE) local g=Duel.GetMatchingGroup(aux.NecroValleyFilter(c48636108.spfilter),tp,LOCATION_HAND+LOCATION_GRAVE,0,nil,e,tp) if ft<=0 or g:GetCount()==0 then return end if Duel.IsPlayerAffectedByEffect(tp,59822133) then ft=1 end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local sg=g:SelectSubGroup(tp,aux.dncheck,false,1,ft) Duel.SpecialSummon(sg,0,tp,tp,false,false,POS_FACEUP_DEFENSE) end
gpl-2.0
valhallaGaming/uno
branches/2_0_3_STABLE/realism-system/s_indicators.lua
1
8462
function resStart(res) if (res==getThisResource()) then for key, veh in ipairs(exports.pool:getPoolElementsByType("vehicle")) do removeElementData(veh, "rightmarker1") removeElementData(veh, "rightobject1") removeElementData(veh, "rightmarker2") removeElementData(veh, "rightobject2") end end end addEventHandler("onResourceStart", getRootElement(), resStart) function flashIndicator(marker1, marker2, vehicle, left) if (left) then local leftmarker = getElementData(vehicle, "leftmarker1") if not (leftmarker) then marker1 = nil marker2 = nil local rightmarker = getElementData(vehicle, "rightmarker1") local disablingright = getElementData(vehicle, "disablingright") if (rightmarker) and not (disablingright) then local rightmarker = getElementData(vehicle, "rightmarker1") local rightobject = getElementData(vehicle, "rightobject1") local rightmarker2 = getElementData(vehicle, "rightmarker2") local rightobject2 = getElementData(vehicle, "rightobject2") destroyElement(rightmarker) destroyElement(rightobject) destroyElement(rightmarker2) destroyElement(rightobject2) removeElementData(vehicle, "rightmarker1") removeElementData(vehicle, "rightobject1") removeElementData(vehicle, "rightmarker2") removeElementData(vehicle, "rightobject2") setElementData(vehicle, "disablingleft", false) setElementData(vehicle, "disablingright", true) else setElementData(vehicle, "disablingright", false) end end else local rightmarker = getElementData(vehicle, "rightmarker1") if not (rightmarker) then marker1 = nil marker2 = nil end local leftmarker = getElementData(vehicle, "leftmarker1") local disablingleft = getElementData(vehicle, "disablingleft") if (leftmarker) and not (disablingleft) then local leftmarker = getElementData(vehicle, "leftmarker1") local leftobject = getElementData(vehicle, "leftobject1") local leftmarker2 = getElementData(vehicle, "leftmarker2") local leftobject2 = getElementData(vehicle, "leftobject2") destroyElement(leftmarker) destroyElement(leftobject) destroyElement(leftmarker2) destroyElement(leftobject2) removeElementData(vehicle, "leftmarker1") removeElementData(vehicle, "leftobject1") removeElementData(vehicle, "leftmarker2") removeElementData(vehicle, "leftobject2") setElementData(vehicle, "disablingright", false) setElementData(vehicle, "disablingleft", true) else setElementData(vehicle, "disablingleft", false) end end if (marker1) and (marker2) then if (isElementVisibleTo(marker1, getRootElement())) then setElementVisibleTo(marker1, getRootElement(), false) setElementVisibleTo(marker2, getRootElement(), false) else setElementVisibleTo(marker1, getRootElement(), true) setElementVisibleTo(marker2, getRootElement(), true) end for i = 0, 3 do local occupant = getVehicleOccupant(vehicle, i) if (occupant) then playSoundFrontEnd(occupant, 41) end end setTimer(flashIndicator, 500, 1, marker1, marker2, vehicle, left) end end function disableIndicatorsOnBlowup() local leftmarker = getElementData(source, "leftmarker1") local leftobject = getElementData(source, "leftobject1") local leftmarker2 = getElementData(source, "leftmarker2") local leftobject2 = getElementData(source, "leftobject2") if (leftmarker) then destroyElement(leftmarker) end if (leftobject) then destroyElement(leftobject) end if (leftmarker2) then destroyElement(leftmarker2) end if (leftobject2) then destroyElement(leftobject2) end removeElementData(source, "leftmarker1") removeElementData(source, "leftobject1") removeElementData(source, "leftmarker2") removeElementData(source, "leftobject2") local rightmarker = getElementData(source, "rightmarker1") local rightobject = getElementData(source, "rightobject1") local rightmarker2 = getElementData(source, "rightmarker2") local rightobject2 = getElementData(source, "rightobject2") if (rightmarker) then destroyElement(rightmarker) end if (rightobject) then destroyElement(rightobject) end if (rightmarker2) then destroyElement(rightmarker2) end if (rightobject2) then destroyElement(rightobject2) end removeElementData(source, "rightmarker1") removeElementData(source, "rightobject1") removeElementData(source, "rightmarker2") removeElementData(source, "rightobject2") end addEventHandler("onVehicleExplode", getRootElement(), disableIndicatorsOnBlowup) addEventHandler("onVehicleStartExit", getRootElement(), disableIndicatorsOnBlowup) function toggleLeftIndicator(x1, y1, z1, x2, y2, z2) local veh = getPedOccupiedVehicle(source) if (veh) then local leftmarker = getElementData(veh, "leftmarker1") if not (leftmarker) then object = createObject(1489, x1, y1, z1) exports.pool:allocateElement(object) marker = createMarker(x1, y1, z1, "corona", 1, 255, 194, 14, 200) exports.pool:allocateElement(marker) attachElements(object, veh, x1+0.1, y1+0.5, z1+0.7) attachElements(marker, object, 0, 0, 0) setElementAlpha(object, 0) object2 = createObject(1489, x1, y1, z1) exports.pool:allocateElement(object2) marker2 = createMarker(x1, y1, z1, "corona", 1, 255, 194, 14, 200) exports.pool:allocateElement(marker2) attachElements(object2, veh, x1+0.1, y2, z1+0.7) attachElements(marker2, object2, 0, 0, 0) setElementAlpha(object2, 0) setElementData(veh, "leftmarker1", marker) setElementData(veh, "leftobject1", object) setElementData(veh, "leftmarker2", marker2) setElementData(veh, "leftobject2", object2) setTimer(flashIndicator, 500, 1, marker, marker2, veh, true) else local leftmarker = getElementData(veh, "leftmarker1") local leftobject = getElementData(veh, "leftobject1") local leftmarker2 = getElementData(veh, "leftmarker2") local leftobject2 = getElementData(veh, "leftobject2") destroyElement(leftmarker) destroyElement(leftobject) destroyElement(leftmarker2) destroyElement(leftobject2) removeElementData(veh, "leftmarker1") removeElementData(veh, "leftobject1") removeElementData(veh, "leftmarker2") removeElementData(veh, "leftobject2") end end end addEvent("toggleLeftIndicators", true) addEventHandler("toggleLeftIndicators", getRootElement(), toggleLeftIndicator) function toggleRightIndicator(x1, y1, z1, x2, y2, z2) local veh = getPedOccupiedVehicle(source) if (veh) then local rightmarker = getElementData(veh, "rightmarker1") if not (rightmarker) then -- top right cornor object = createObject(1489, x1, y1, z1) exports.pool:allocateElement(object) marker = createMarker(x1, y1, z1, "corona", 1, 255, 194, 14, 200) exports.pool:allocateElement(marker) attachElements(object, veh, x2-0.3, y1+0.4, z1+0.7) attachElements(marker, object, 0, 0, 0) setElementAlpha(object, 0) -- top right cornor object2 = createObject(1489, x1, y1, z1) exports.pool:allocateElement(object2) marker2 = createMarker(x1, y1, z1, "corona", 1, 255, 194, 14, 200) exports.pool:allocateElement(marker2) attachElements(object2, veh, x2-0.3, y2-0.1, z1+0.7) attachElements(marker2, object2, 0, 0, 0) setElementAlpha(object2, 0) setElementData(veh, "rightmarker1", marker) setElementData(veh, "rightobject1", object) setElementData(veh, "rightmarker2", marker2) setElementData(veh, "rightobject2", object2) setTimer(flashIndicator, 500, 1, marker, marker2, veh, false) else local rightmarker = getElementData(veh, "rightmarker1") local rightobject = getElementData(veh, "rightobject1") local rightmarker2 = getElementData(veh, "rightmarker2") local rightobject2 = getElementData(veh, "rightobject2") destroyElement(rightmarker) destroyElement(rightobject) destroyElement(rightmarker2) destroyElement(rightobject2) removeElementData(veh, "rightmarker1") removeElementData(veh, "rightobject1") removeElementData(veh, "rightmarker2") removeElementData(veh, "rightobject2") end end end addEvent("toggleRightIndicators", true) addEventHandler("toggleRightIndicators", getRootElement(), toggleRightIndicator)
bsd-3-clause
mercury233/ygopro-scripts
c28151978.lua
2
2921
--SRドミノバタフライ function c28151978.initial_effect(c) --pendulum summon aux.EnablePendulumAttribute(c) --splimit local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_FIELD) e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_CANNOT_NEGATE) e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON) e1:SetRange(LOCATION_PZONE) e1:SetTargetRange(1,0) e1:SetTarget(c28151978.splimit) c:RegisterEffect(e1) --tohand local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(28151978,0)) e2:SetCategory(CATEGORY_TOHAND) e2:SetType(EFFECT_TYPE_IGNITION) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetRange(LOCATION_PZONE) e2:SetCountLimit(1,28151978) e2:SetCost(c28151978.thcost) e2:SetTarget(c28151978.thtg) e2:SetOperation(c28151978.thop) c:RegisterEffect(e2) --synchro limit local e3=Effect.CreateEffect(c) e3:SetType(EFFECT_TYPE_SINGLE) e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE) e3:SetCode(EFFECT_CANNOT_BE_SYNCHRO_MATERIAL) e3:SetValue(c28151978.synlimit) c:RegisterEffect(e3) --synchro material local e4=Effect.CreateEffect(c) e4:SetType(EFFECT_TYPE_SINGLE) e4:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE) e4:SetCode(EFFECT_TO_GRAVE_REDIRECT) e4:SetValue(LOCATION_REMOVED) e4:SetCondition(c28151978.rmcon) c:RegisterEffect(e4) end function c28151978.splimit(e,c,sump,sumtype,sumpos,targetp) return not c:IsAttribute(ATTRIBUTE_WIND) and bit.band(sumtype,SUMMON_TYPE_PENDULUM)==SUMMON_TYPE_PENDULUM end function c28151978.cfilter(c) return c:IsAttribute(ATTRIBUTE_WIND) and c:IsDiscardable() end function c28151978.thcost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(c28151978.cfilter,tp,LOCATION_HAND,0,1,nil) end Duel.DiscardHand(tp,c28151978.cfilter,1,1,REASON_COST+REASON_DISCARD) end function c28151978.thfilter(c) return c:IsFaceup() and c:IsAttribute(ATTRIBUTE_WIND) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand() end function c28151978.thtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_REMOVED) and c28151978.thfilter(chkc) end if chk==0 then return Duel.IsExistingTarget(c28151978.thfilter,tp,LOCATION_REMOVED,0,1,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local g=Duel.SelectTarget(tp,c28151978.thfilter,tp,LOCATION_REMOVED,0,1,1,nil) Duel.SetOperationInfo(0,CATEGORY_TOHAND,g,1,0,0) end function c28151978.thop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) then Duel.SendtoHand(tc,nil,REASON_EFFECT) end end function c28151978.synlimit(e,c) if not c then return false end return not c:IsAttribute(ATTRIBUTE_WIND) or not c:IsRace(RACE_DRAGON+RACE_MACHINE) end function c28151978.rmcon(e) local c=e:GetHandler() return c:IsSummonLocation(LOCATION_EXTRA) and bit.band(c:GetReason(),REASON_MATERIAL+REASON_SYNCHRO)==REASON_MATERIAL+REASON_SYNCHRO end
gpl-2.0
mjssw/cuberite
lib/tolua++/src/bin/lua/feature.lua
15
2882
-- tolua: abstract feature class -- Written by Waldemar Celes -- TeCGraf/PUC-Rio -- Jul 1998 -- $Id: $ -- This code is free software; you can redistribute it and/or modify it. -- The software provided hereunder is on an "as is" basis, and -- the author has no obligation to provide maintenance, support, updates, -- enhancements, or modifications. -- Feature class -- Represents the base class of all mapped feature. classFeature = { } classFeature.__index = classFeature -- write support code function classFeature:supcode () end -- output tag function classFeature:decltype () end -- register feature function classFeature:register (pre) end -- translate verbatim function classFeature:preamble () end -- check if it is a variable function classFeature:isvariable () return false end -- check if it requires collection function classFeature:requirecollection (t) return false end -- build names function classFeature:buildnames () if self.name and self.name~='' then local n = split(self.name,'@') self.name = n[1] self.name = string.gsub(self.name, ":%d*$", "") if not n[2] then n[2] = applyrenaming(n[1]) end self.lname = n[2] or gsub(n[1],"%[.-%]","") self.lname = string.gsub(self.lname, ":%d*$", "") self.original_name = self.name self.lname = clean_template(self.lname) end if not self.is_parameter then self.name = getonlynamespace() .. self.name end local parent = classContainer.curr if parent then self.access = parent.curr_member_access self.global_access = self:check_public_access() else end end function classFeature:check_public_access() if type(self.global_access) == "boolean" then return self.global_access end if self.access and self.access ~= 0 then return false end local parent = classContainer.curr while parent do if parent.access and parent.access ~= 0 then return false end parent = parent.prox end return true end function clean_template(t) return string.gsub(t, "[<>:, %*]", "_") end -- check if feature is inside a container definition -- it returns the container class name or nil. function classFeature:incontainer (which) if self.parent then local parent = self.parent while parent do if parent.classtype == which then return parent.name end parent = parent.parent end end return nil end function classFeature:inclass () return self:incontainer('class') end function classFeature:inmodule () return self:incontainer('module') end function classFeature:innamespace () return self:incontainer('namespace') end -- return C binding function name based on name -- the client specifies a prefix function classFeature:cfuncname (n) if self.parent then n = self.parent:cfuncname(n) end local fname = self.lname if not fname or fname == '' then fname = self.name end n = string.gsub(n..'_'.. (fname), "[<>:, %.%*&]", "_") return n end
apache-2.0
mercury233/ygopro-scripts
c92182447.lua
3
2270
--時の女神の悪戯 function c92182447.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetHintTiming(TIMING_BATTLE_END) e1:SetCondition(c92182447.condition) e1:SetTarget(c92182447.target) e1:SetOperation(c92182447.activate) c:RegisterEffect(e1) end function c92182447.cfilter(c) return c:IsFaceup() and c:IsSetCard(0x122) end function c92182447.condition(e,tp,eg,ep,ev,re,r,rp) if Duel.GetCurrentChain()>0 or Duel.GetCurrentPhase()~=PHASE_BATTLE or Duel.GetTurnPlayer()~=tp then return false end local g=Duel.GetFieldGroup(tp,LOCATION_MZONE,0) return g:GetCount()>0 and g:FilterCount(c92182447.cfilter,nil)==g:GetCount() end function c92182447.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return true end if e:IsHasType(EFFECT_TYPE_ACTIVATE) then Duel.SetChainLimit(aux.FALSE) end end function c92182447.activate(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if c:IsRelateToEffect(e) then Duel.SendtoGrave(c,REASON_EFFECT) end -- Duel.SkipPhase(tp,PHASE_BATTLE,RESET_PHASE+PHASE_END,1) Duel.SkipPhase(tp,PHASE_MAIN2,RESET_PHASE+PHASE_END,1) Duel.SkipPhase(tp,PHASE_END,RESET_PHASE+PHASE_END,1) local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_FIELD) e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET) e1:SetCode(EFFECT_SKIP_TURN) e1:SetTargetRange(0,1) e1:SetReset(RESET_PHASE+PHASE_END+RESET_OPPO_TURN) Duel.RegisterEffect(e1,tp) Duel.SkipPhase(tp,PHASE_DRAW,RESET_PHASE+PHASE_END,2) Duel.SkipPhase(tp,PHASE_STANDBY,RESET_PHASE+PHASE_END,2) Duel.SkipPhase(tp,PHASE_MAIN1,RESET_PHASE+PHASE_END,2) local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_FIELD) e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET) e2:SetCode(EFFECT_CANNOT_EP) e2:SetTargetRange(1,0) e2:SetReset(RESET_PHASE+PHASE_MAIN1+RESET_SELF_TURN) Duel.RegisterEffect(e2,tp) -- local e3=Effect.CreateEffect(c) e3:SetType(EFFECT_TYPE_FIELD) e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH) e3:SetCode(EFFECT_CANNOT_ACTIVATE) e3:SetTargetRange(1,0) e3:SetValue(c92182447.aclimit) e3:SetReset(RESET_PHASE+PHASE_END,3) Duel.RegisterEffect(e3,tp) end function c92182447.aclimit(e,re,tp) return re:IsHasType(EFFECT_TYPE_ACTIVATE) and re:GetHandler():IsCode(92182447) end
gpl-2.0
mercury233/ygopro-scripts
c65331686.lua
2
3889
--ファーニマル・オウル function c65331686.initial_effect(c) --search local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(65331686,0)) e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH) e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e1:SetCode(EVENT_SUMMON_SUCCESS) e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP) e1:SetCountLimit(1,65331686) e1:SetCondition(c65331686.thcon) e1:SetTarget(c65331686.thtg) e1:SetOperation(c65331686.thop) c:RegisterEffect(e1) local e2=e1:Clone() e2:SetCode(EVENT_SPSUMMON_SUCCESS) c:RegisterEffect(e2) --spsummon local e3=Effect.CreateEffect(c) e3:SetDescription(aux.Stringid(65331686,1)) e3:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_FUSION_SUMMON) e3:SetType(EFFECT_TYPE_IGNITION) e3:SetRange(LOCATION_MZONE) e3:SetCountLimit(1,65331686) e3:SetCost(c65331686.cost) e3:SetTarget(c65331686.target) e3:SetOperation(c65331686.operation) c:RegisterEffect(e3) end function c65331686.thcon(e,tp,eg,ep,ev,re,r,rp) return e:GetHandler():IsPreviousLocation(LOCATION_HAND) end function c65331686.thfilter(c) return c:IsCode(24094653) and c:IsAbleToHand() end function c65331686.thtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chk==0 then return Duel.IsExistingMatchingCard(c65331686.thfilter,tp,LOCATION_DECK,0,1,nil) end Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK) end function c65331686.thop(e,tp,eg,ep,ev,re,r,rp) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local g=Duel.SelectMatchingCard(tp,c65331686.thfilter,tp,LOCATION_DECK,0,1,1,nil) if g:GetCount()>0 then Duel.SendtoHand(g,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,g) end end function c65331686.cost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.CheckLPCost(tp,500) end Duel.PayLPCost(tp,500) end function c65331686.filter1(c,e) return not c:IsImmuneToEffect(e) end function c65331686.filter2(c,e,tp,m,f,chkf) return c:IsType(TYPE_FUSION) and c:IsSetCard(0xad) and (not f or f(c)) and c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_FUSION,tp,false,false) and c:CheckFusionMaterial(m,nil,chkf) end function c65331686.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then local chkf=tp local mg1=Duel.GetFusionMaterial(tp) local res=Duel.IsExistingMatchingCard(c65331686.filter2,tp,LOCATION_EXTRA,0,1,nil,e,tp,mg1,nil,chkf) if not res then local ce=Duel.GetChainMaterial(tp) if ce~=nil then local fgroup=ce:GetTarget() local mg2=fgroup(ce,e,tp) local mf=ce:GetValue() res=Duel.IsExistingMatchingCard(c65331686.filter2,tp,LOCATION_EXTRA,0,1,nil,e,tp,mg2,mf,chkf) end end return res end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_EXTRA) end function c65331686.operation(e,tp,eg,ep,ev,re,r,rp) local chkf=tp local mg1=Duel.GetFusionMaterial(tp):Filter(c65331686.filter1,nil,e) local sg1=Duel.GetMatchingGroup(c65331686.filter2,tp,LOCATION_EXTRA,0,nil,e,tp,mg1,nil,chkf) local mg2=nil local sg2=nil local ce=Duel.GetChainMaterial(tp) if ce~=nil then local fgroup=ce:GetTarget() mg2=fgroup(ce,e,tp) local mf=ce:GetValue() sg2=Duel.GetMatchingGroup(c65331686.filter2,tp,LOCATION_EXTRA,0,nil,e,tp,mg2,mf,chkf) end if sg1:GetCount()>0 or (sg2~=nil and sg2:GetCount()>0) then local sg=sg1:Clone() if sg2 then sg:Merge(sg2) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local tg=sg:Select(tp,1,1,nil) local tc=tg:GetFirst() if sg1:IsContains(tc) and (sg2==nil or not sg2:IsContains(tc) or not Duel.SelectYesNo(tp,ce:GetDescription())) then local mat1=Duel.SelectFusionMaterial(tp,tc,mg1,nil,chkf) tc:SetMaterial(mat1) Duel.SendtoGrave(mat1,REASON_EFFECT+REASON_MATERIAL+REASON_FUSION) Duel.BreakEffect() Duel.SpecialSummon(tc,SUMMON_TYPE_FUSION,tp,tp,false,false,POS_FACEUP) else local mat2=Duel.SelectFusionMaterial(tp,tc,mg2,nil,chkf) local fop=ce:GetOperation() fop(ce,e,tp,tc,mat2) end tc:CompleteProcedure() end end
gpl-2.0
Zenny89/darkstar
scripts/zones/Upper_Jeuno/npcs/Rouliette.lua
17
2208
----------------------------------- -- Area: Upper Jeuno -- NPC: Rouliette -- Starts and Finishes Quest: Candle-making -- @zone 244 -- @pos -24 -2 11 ----------------------------------- package.loaded["scripts/zones/Upper_Jeuno/TextIDs"] = nil; package.loaded["scripts/globals/settings"] = nil; ----------------------------------- require("scripts/globals/settings"); require("scripts/globals/titles"); require("scripts/globals/keyitems"); require("scripts/globals/shop"); require("scripts/globals/quests"); require("scripts/zones/Upper_Jeuno/TextIDs"); ----------------------------------- -- onTrade Action ----------------------------------- function onTrade(player,npc,trade) if (player:getQuestStatus(JEUNO,CANDLE_MAKING) == QUEST_ACCEPTED and trade:hasItemQty(531,1) == true and trade:getItemCount() == 1) then player:startEvent(0x0025); end end; ----------------------------------- -- onTrigger Action ----------------------------------- function onTrigger(player,npc) --Prerequisites for this quest : A_CANDLELIGHT_VIGIL ACCEPTED if (player:getQuestStatus(JEUNO,CANDLE_MAKING) ~= QUEST_COMPLETED and player:getQuestStatus(JEUNO,A_CANDLELIGHT_VIGIL) == QUEST_ACCEPTED) then player:startEvent(0x0024); -- Start Quest Candle-making else player:startEvent(0x001e); --Standard dialog end end; ----------------------------------- -- onEventUpdate ----------------------------------- function onEventUpdate(player,csid,option) --printf("CSID: %u",csid); --printf("RESULT: %u",option); end; ----------------------------------- -- onEventFinish ----------------------------------- function onEventFinish(player,csid,option) --printf("CSID: %u",csid); --printf("RESULT: %u",option); if (csid == 0x0024 and player:getQuestStatus(JEUNO,CANDLE_MAKING) == QUEST_AVAILABLE) then player:addQuest(JEUNO,CANDLE_MAKING); elseif (csid == 0x0025) then player:addTitle(BELIEVER_OF_ALTANA); player:addKeyItem(HOLY_CANDLE); player:messageSpecial(KEYITEM_OBTAINED,HOLY_CANDLE); player:addFame(JEUNO, JEUNO_FAME*30); player:tradeComplete(trade); player:completeQuest(JEUNO,CANDLE_MAKING); end end;
gpl-3.0
mercury233/ygopro-scripts
c24725825.lua
6
1387
--エレクトリック・ワーム function c24725825.initial_effect(c) --control local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(24725825,0)) e1:SetCategory(CATEGORY_CONTROL) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetRange(LOCATION_HAND) e1:SetCost(c24725825.cost) e1:SetTarget(c24725825.target) e1:SetOperation(c24725825.operation) c:RegisterEffect(e1) end function c24725825.cost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():IsAbleToGraveAsCost() end Duel.SendtoGrave(e:GetHandler(),REASON_COST+REASON_DISCARD) end function c24725825.filter(c) return c:IsFaceup() and c:IsRace(RACE_MACHINE+RACE_DRAGON) and c:IsControlerCanBeChanged() end function c24725825.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1-tp) and c24725825.filter(chkc) end if chk==0 then return Duel.IsExistingTarget(c24725825.filter,tp,0,LOCATION_MZONE,1,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_CONTROL) local g=Duel.SelectTarget(tp,c24725825.filter,tp,0,LOCATION_MZONE,1,1,nil) Duel.SetOperationInfo(0,CATEGORY_CONTROL,g,1,0,0) end function c24725825.operation(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRace(RACE_MACHINE+RACE_DRAGON) then Duel.GetControl(tc,tp,PHASE_END,1) end end
gpl-2.0
mercury233/ygopro-scripts
c9753964.lua
2
3565
--琰魔竜 レッド・デーモン・アビス function c9753964.initial_effect(c) --synchro summon aux.AddSynchroProcedure(c,nil,aux.NonTuner(c9753964.sfilter),1,1) c:EnableReviveLimit() --negate local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(9753964,0)) e1:SetCategory(CATEGORY_DISABLE) e1:SetType(EFFECT_TYPE_QUICK_O) e1:SetCode(EVENT_FREE_CHAIN) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetRange(LOCATION_MZONE) e1:SetHintTiming(0,TIMINGS_CHECK_MONSTER) e1:SetCountLimit(1,9753964) e1:SetTarget(c9753964.target) e1:SetOperation(c9753964.operation) c:RegisterEffect(e1) --spsummon local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(9753964,1)) e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e2:SetCategory(CATEGORY_SPECIAL_SUMMON) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetCode(EVENT_BATTLE_DAMAGE) e2:SetCountLimit(1,9753965) e2:SetCondition(c9753964.spcon) e2:SetTarget(c9753964.sptg) e2:SetOperation(c9753964.spop) c:RegisterEffect(e2) end c9753964.material_type=TYPE_SYNCHRO function c9753964.sfilter(c) return c:IsRace(RACE_DRAGON) and c:IsAttribute(ATTRIBUTE_DARK) and c:IsType(TYPE_SYNCHRO) end function c9753964.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(1-tp) and chkc:IsOnField() and aux.NegateAnyFilter(chkc) end if chk==0 then return Duel.IsExistingTarget(aux.NegateAnyFilter,tp,0,LOCATION_ONFIELD,1,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_DISABLE) local g=Duel.SelectTarget(tp,aux.NegateAnyFilter,tp,0,LOCATION_ONFIELD,1,1,nil) Duel.SetOperationInfo(0,CATEGORY_DISABLE,g,1,0,0) end function c9753964.operation(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() local tc=Duel.GetFirstTarget() if ((tc:IsFaceup() and not tc:IsDisabled()) or tc:IsType(TYPE_TRAPMONSTER)) and tc:IsRelateToEffect(e) then Duel.NegateRelatedChain(tc,RESET_TURN_SET) local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE) e1:SetCode(EFFECT_DISABLE) e1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END) tc:RegisterEffect(e1) local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_SINGLE) e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE) e2:SetCode(EFFECT_DISABLE_EFFECT) e2:SetValue(RESET_TURN_SET) e2:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END) tc:RegisterEffect(e2) if tc:IsType(TYPE_TRAPMONSTER) then local e3=Effect.CreateEffect(c) e3:SetType(EFFECT_TYPE_SINGLE) e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE) e3:SetCode(EFFECT_DISABLE_TRAPMONSTER) e3:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END) tc:RegisterEffect(e3) end end end function c9753964.spcon(e,tp,eg,ep,ev,re,r,rp) return ep~=tp end function c9753964.spfilter(c,e,tp) return c:IsType(TYPE_TUNER) and c:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP_DEFENSE) end function c9753964.sptg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and c9753964.spfilter(chkc,e,tp) end if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingTarget(c9753964.spfilter,tp,LOCATION_GRAVE,0,1,nil,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectTarget(tp,c9753964.spfilter,tp,LOCATION_GRAVE,0,1,1,nil,e,tp) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,1,0,0) end function c9753964.spop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) then Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP_DEFENSE) end end
gpl-2.0
Zenny89/darkstar
scripts/globals/items/bowl_of_sprightly_soup.lua
36
1326
----------------------------------------- -- ID: 5930 -- Item: Bowl of Sprightly Soup -- Food Effect: 3 Hrs, All Races ----------------------------------------- -- MP 30 -- Mind 4 -- HP Recovered While Healing 4 -- Enmity -4 ----------------------------------------- require("scripts/globals/status"); ----------------------------------------- -- OnItemCheck ----------------------------------------- function onItemCheck(target) result = 0; if (target:hasStatusEffect(EFFECT_FOOD) == true or target:hasStatusEffect(EFFECT_FIELD_SUPPORT_FOOD) == true) then result = 246; end return result; end; ----------------------------------------- -- OnItemUse ----------------------------------------- function onItemUse(target) target:addStatusEffect(EFFECT_FOOD,0,0,10800,5930); end; ----------------------------------------- -- onEffectGain Action ----------------------------------------- function onEffectGain(target,effect) target:addMod(MOD_MP, 30); target:addMod(MOD_MND, 4); target:addMod(MOD_HPHEAL, 4); target:addMod(MOD_ENMITY, -4); end; ----------------------------------------- -- onEffectLose Action ----------------------------------------- function onEffectLose(target,effect) target:delMod(MOD_MP, 30); target:delMod(MOD_MND, 4); target:delMod(MOD_HPHEAL, 4); target:delMod(MOD_ENMITY, -4); end;
gpl-3.0
Zenny89/darkstar
scripts/zones/Crawlers_Nest/npcs/Treasure_Coffer.lua
17
3973
----------------------------------- -- Area: Crawler Nest -- NPC: Treasure Coffer -- @zone 197 -- @pos -94 0 207 ----------------------------------- package.loaded["scripts/zones/Crawlers_Nest/TextIDs"] = nil; ----------------------------------- require("scripts/globals/settings"); require("scripts/globals/keyitems"); require("scripts/globals/treasure"); require("scripts/globals/quests"); require("scripts/zones/Crawlers_Nest/TextIDs"); local TreasureType = "Coffer"; local TreasureLvL = 53; local TreasureMinLvL = 43; ----------------------------------- -- onTrade Action ----------------------------------- function onTrade(player,npc,trade) -- trade:hasItemQty(1045,1); -- Treasure Key -- trade:hasItemQty(1115,1); -- Skeleton Key -- trade:hasItemQty(1023,1); -- Living Key -- trade:hasItemQty(1022,1); -- Thief's Tools local questItemNeeded = 0; -- Player traded a key. if ((trade:hasItemQty(1045,1) or trade:hasItemQty(1115,1) or trade:hasItemQty(1023,1) or trade:hasItemQty(1022,1)) and trade:getItemCount() == 1) then -- IMPORTANT ITEM: AF Keyitems, AF Items, & Map ----------- local mJob = player:getMainJob(); local zone = player:getZoneID(); local AFHandsActivated = player:getVar("BorghertzAlreadyActiveWithJob"); local listAF = getAFbyZone(zone); if ((AFHandsActivated == 2 or AFHandsActivated == 9) and player:hasKeyItem(OLD_GAUNTLETS) == false) then questItemNeeded = 1; else for nb = 1,table.getn(listAF),3 do if (player:getQuestStatus(JEUNO,listAF[nb + 1]) ~= QUEST_AVAILABLE and mJob == listAF[nb] and player:hasItem(listAF[nb + 2]) == false) then questItemNeeded = 2; break end end end -------------------------------------- local pack = openChance(player,npc,trade,TreasureType,TreasureLvL,TreasureMinLvL,questItemNeeded); local success = 0; if (pack[2] ~= nil) then player:messageSpecial(pack[2]); end success = pack[1]; if (success ~= -2) then player:tradeComplete(); if (math.random() <= success) then -- Succeded to open the coffer player:messageSpecial(CHEST_UNLOCKED); if (questItemNeeded == 1) then player:addKeyItem(OLD_GAUNTLETS); player:messageSpecial(KEYITEM_OBTAINED,OLD_GAUNTLETS); -- Old Gauntlets (KI) elseif (questItemNeeded == 2) then for nb = 1,table.getn(listAF),3 do if (mJob == listAF[nb]) then player:addItem(listAF[nb + 2]); player:messageSpecial(ITEM_OBTAINED,listAF[nb + 2]); break end end else player:setVar("["..zone.."]".."Treasure_"..TreasureType,os.time() + math.random(CHEST_MIN_ILLUSION_TIME,CHEST_MAX_ILLUSION_TIME)); local loot = cofferLoot(zone,npc); -- print("loot array: "); -- debug -- print("[1]", loot[1]); -- debug -- print("[2]", loot[2]); -- debug if (loot[1]=="gil") then player:addGil(loot[2]*GIL_RATE); player:messageSpecial(GIL_OBTAINED,loot[2]*GIL_RATE); else -- Item player:addItem(loot[2]); player:messageSpecial(ITEM_OBTAINED,loot[2]); end end UpdateTreasureSpawnPoint(npc:getID()); else player:messageSpecial(CHEST_MIMIC); spawnMimic(zone,npc,player); UpdateTreasureSpawnPoint(npc:getID(), true); end end end end; ----------------------------------- -- onTrigger Action ----------------------------------- function onTrigger(player,npc) player:messageSpecial(CHEST_LOCKED,1045); end; ----------------------------------- -- onEventUpdate ----------------------------------- function onEventUpdate(player,csid,option) --printf("CSID: %u",csid); --printf("RESULT: %u",option); end; ----------------------------------- -- onEventFinish ----------------------------------- function onEventFinish(player,csid,option) --printf("CSID: %u",csid); --printf("RESULT: %u",option); end;
gpl-3.0
wenhuizhang/MoonGen
lua/include/lpm.lua
8
5893
--------------------------------- --- @file lpm.lua --- @brief Longest Prefix Matching ... --- @todo TODO docu --------------------------------- local ffi = require "ffi" --require "utils" local band, lshift, rshift = bit.band, bit.lshift, bit.rshift local dpdkc = require "dpdkc" local dpdk = require "dpdk" local serpent = require "Serpent" local log = require "log" require "memory" --local burst = require "burst" ffi.cdef [[ struct rte_table_lpm_params { uint32_t n_rules; uint32_t entry_unique_size; uint32_t offset; }; void * mg_table_lpm_create(void *params, int socket_id, uint32_t entry_size); int mg_table_lpm_free(void *table); int mg_table_entry_add_simple( void *table, uint32_t ip, uint8_t depth, void *entry); int mg_table_lpm_entry_add( void *table, uint32_t ip, uint8_t depth, void *entry, int *key_found, void **entry_ptr); int mg_table_lpm_lookup( void *table, struct rte_mbuf **pkts, uint64_t pkts_mask, uint64_t *lookup_hit_mask, void **entries); int mg_table_lpm_lookup_big_burst( void *table, struct rte_mbuf **pkts, struct mg_bitmask* pkts_mask, struct mg_bitmask* lookup_hit_mask, void **entries); int mg_table_lpm_entry_delete( void *table, uint32_t ip, uint8_t depth, int *key_found, void *entry); void ** mg_lpm_table_allocate_entry_prts(uint16_t n_entries); int printf(const char *fmt, ...); int mg_table_lpm_apply_route( struct rte_mbuf **pkts, struct mg_bitmask* pkts_mask, void **entries, uint16_t offset_entry, uint16_t offset_pkt, uint16_t size); ]] local mod = {} local mg_lpm4Table = {} mod.mg_lpm4Table = mg_lpm4Table mg_lpm4Table.__index = mg_lpm4Table --- Create a new LPM lookup table. --- @param socket optional (default = socket of the calling thread), CPU socket, where memory for the table should be allocated. --- @return the table handler function mod.createLpm4Table(socket, table, entry_ctype) socket = socket or select(2, dpdk.getCore()) -- configure parameters for the LPM table local params = ffi.new("struct rte_table_lpm_params") params.n_rules = 1000 params.entry_unique_size = 5 --params.offset = 128 + 27+4 params.offset = 128+ 14 + 12+4 return setmetatable({ table = table or ffi.gc(ffi.C.mg_table_lpm_create(params, socket, ffi.sizeof(entry_ctype)), function(self) -- FIXME: why is destructor never called? log:debug("lpm garbage") ffi.C.mg_table_lpm_free(self) end), entry_ctype = entry_ctype }, mg_lpm4Table) end -- --- Free the LPM Table -- --- @return 0 on success, error code otherwise -- function mg_lpm4Table:destruct() -- return ffi.C.mg_table_lpm_free(self.table) -- end --- Add an entry to a Table --- @param addr IPv4 network address of the destination network. --- @param depth number of significant bits of the destination network address --- @param entry routing table entry (will be copied) --- @return true if entry was added without error function mg_lpm4Table:addEntry(addr, depth, entry) return 0 == ffi.C.mg_table_entry_add_simple(self.table, addr, depth, entry) end --- Perform IPv4 route lookup for a burst of packets --- This should not be used for single packet lookup, as ist brings --- a significant penalty for bursts <<64 --- @param packets Array of mbufs (bufArray), for which the lookup will be performed --- @param mask optional (default = all packets), bitmask, for which packets the lookup should be performed --- @param hitMask Bitmask, where the routed packets are flagged --- with one. This may be the same Bitmask as passed in the mask --- parameter, in this case not routed packets will be cleared in --- the bitmask. --- @param entries Preallocated routing entry Pointers function mg_lpm4Table:lookupBurst(packets, mask, hitMask, entries) -- FIXME: I feel uneasy about this cast, should this cast not be -- done implicitly? return ffi.C.mg_table_lpm_lookup_big_burst(self.table, packets.array, mask.bitmask, hitMask.bitmask, ffi.cast("void **",entries.array)) end function mg_lpm4Table:__serialize() return "require 'lpm'; return " .. serpent.addMt(serpent.dumpRaw(self), "require('lpm').mg_lpm4Table"), true end --- Allocates an LPM table entry --- @return The newly allocated entry function mg_lpm4Table:allocateEntry() return ffi.new(self.entry_ctype) end local mg_lpm4EntryPtrs = {} --- Allocates an array of pointers to routing table entries --- This is used during burst lookup, to store references to the --- result entries. --- @param n Number of entry pointers --- @return Wrapper table around the allocated array function mg_lpm4Table:allocateEntryPtrs(n) -- return ffi.C.mg_lpm_table_allocate_entry_prts(n) return setmetatable({ array = ffi.new(self.entry_ctype .. "*[?]", n) }, mg_lpm4EntryPtrs) end function mg_lpm4EntryPtrs:__index(k) if type(k) == "number" then return self.array[k - 1] else return mg_lpm4EntryPtrs[k] end end function mod.applyRoute(pkts, mask, entries, entryOffset) entryOffset = entryOffset or 1 return ffi.C.mg_table_lpm_apply_route(pkts.array, mask.bitmask, ffi.cast("void **", entries.array), entryOffset, 128, 6) end --- FIXME: this should not be in LPM module. but where? --- Decrements the IP TTL field of all masked packets by one. --- out_mask masks the successfully decremented packets (TTL did not reach zero). function mod.decrementTTL(pkts, in_mask, out_mask, ipv4) ipv4 = ipv4 == nil or ipv4 if ipv4 then -- TODO: C implementation might be faster... for i, pkt in ipairs(pkts) do if in_mask[i] then local ipkt = pkt:getIPPacket() local ttl = ipkt.ip4:getTTL() ttl = ttl - 1; ipkt.ip4:setTTL(ttl) if(ttl ~= 0)then out_mask[i] = 1 else out_mask[i] = 0 end else out_mask[i] = 0 end end else log:fatal("TTL decrement for ipv6 not yet implemented") end end return mod
mit
mercury233/ygopro-scripts
c70284332.lua
2
2217
--調律師の陰謀 function c70284332.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_CONTROL) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_SPSUMMON_SUCCESS) e1:SetProperty(EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_CONTINUOUS_TARGET) e1:SetTarget(c70284332.target) e1:SetOperation(c70284332.operation) c:RegisterEffect(e1) --Destroy local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_CONTINUOUS+EFFECT_TYPE_FIELD) e2:SetRange(LOCATION_SZONE) e2:SetCode(EVENT_LEAVE_FIELD) e2:SetCondition(c70284332.descon) e2:SetOperation(c70284332.desop) c:RegisterEffect(e2) --control local e3=Effect.CreateEffect(c) e3:SetType(EFFECT_TYPE_TARGET) e3:SetCode(EFFECT_SET_CONTROL) e3:SetRange(LOCATION_SZONE) e3:SetValue(c70284332.ctval) c:RegisterEffect(e3) end function c70284332.filter(c,e,tp) return c:IsFaceup() and c:IsControler(tp) and c:IsType(TYPE_SYNCHRO) and c:IsCanBeEffectTarget(e) and c:IsControlerCanBeChanged() end function c70284332.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return eg:IsContains(chkc) and c70284332.filter(chkc,e,1-tp) end if chk==0 then return eg:IsExists(c70284332.filter,1,nil,e,1-tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_CONTROL) local g=eg:FilterSelect(tp,c70284332.filter,1,1,nil,e,1-tp) Duel.SetTargetCard(g) Duel.SetOperationInfo(0,CATEGORY_CONTROL,g,1,0,0) end function c70284332.operation(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() local tc=Duel.GetFirstTarget() if c:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) then c:SetCardTarget(tc) --redirect local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_SINGLE) e2:SetCode(EFFECT_LEAVE_FIELD_REDIRECT) e2:SetCondition(c70284332.dircon) e2:SetValue(LOCATION_REMOVED) e2:SetReset(RESET_EVENT+RESETS_STANDARD) tc:RegisterEffect(e2) end end function c70284332.ctval(e,c) return e:GetHandlerPlayer() end function c70284332.dircon(e) return e:GetHandler():IsReason(REASON_DESTROY) end function c70284332.descon(e,tp,eg,ep,ev,re,r,rp) local tc=e:GetHandler():GetFirstCardTarget() return tc and eg:IsContains(tc) end function c70284332.desop(e,tp,eg,ep,ev,re,r,rp) Duel.Destroy(e:GetHandler(),REASON_EFFECT) end
gpl-2.0
mercury233/ygopro-scripts
c47474172.lua
3
1177
--魔筒覗ベイオネーター function c47474172.initial_effect(c) --atkdown local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(47474172,0)) e1:SetCategory(CATEGORY_ATKCHANGE) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetRange(LOCATION_MZONE) e1:SetCountLimit(1) e1:SetTarget(c47474172.atktg) e1:SetOperation(c47474172.atkop) c:RegisterEffect(e1) end function c47474172.atktg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1-tp) and chkc:IsFaceup() end if chk==0 then return Duel.IsExistingTarget(Card.IsFaceup,tp,0,LOCATION_MZONE,1,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FACEUP) Duel.SelectTarget(tp,Card.IsFaceup,tp,0,LOCATION_MZONE,1,1,nil) end function c47474172.atkop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsFaceup() and tc:IsRelateToEffect(e) then local ct=Duel.GetFieldGroupCount(tp,0,LOCATION_MZONE) local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetCode(EFFECT_UPDATE_ATTACK) e1:SetValue(ct*-1000) e1:SetReset(RESET_EVENT+RESETS_STANDARD) tc:RegisterEffect(e1) end end
gpl-2.0
mercury233/ygopro-scripts
c59071624.lua
1
3984
--アロメルスの蟲惑魔 function c59071624.initial_effect(c) --xyz summon aux.AddXyzProcedure(c,nil,4,2,nil,nil,99) c:EnableReviveLimit() --immune local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE) e1:SetRange(LOCATION_MZONE) e1:SetCode(EFFECT_IMMUNE_EFFECT) e1:SetCondition(c59071624.imcon) e1:SetValue(c59071624.efilter) c:RegisterEffect(e1) --spsummon1 local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(59071624,0)) e2:SetCategory(CATEGORY_SPECIAL_SUMMON) e2:SetType(EFFECT_TYPE_IGNITION) e2:SetRange(LOCATION_MZONE) e2:SetCountLimit(1,59071624) e2:SetCost(c59071624.spcost1) e2:SetTarget(c59071624.sptg1) e2:SetOperation(c59071624.spop1) c:RegisterEffect(e2) --spsummon2 local e3=Effect.CreateEffect(c) e3:SetDescription(aux.Stringid(59071624,1)) e3:SetCategory(CATEGORY_SPECIAL_SUMMON) e3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O) e3:SetCode(EVENT_TO_GRAVE) e3:SetProperty(EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_DELAY) e3:SetRange(LOCATION_MZONE) e3:SetCountLimit(1,59071625) e3:SetCondition(c59071624.spcon2) e3:SetCost(c59071624.spcost2) e3:SetTarget(c59071624.sptg2) e3:SetOperation(c59071624.spop2) c:RegisterEffect(e3) local e4=e3:Clone() e4:SetCode(EVENT_REMOVE) c:RegisterEffect(e4) end function c59071624.imcon(e) return e:GetHandler():GetOverlayCount()>0 end function c59071624.efilter(e,te) return te:IsActiveType(TYPE_TRAP) end function c59071624.spcost1(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():CheckRemoveOverlayCard(tp,2,REASON_COST) end e:GetHandler():RemoveOverlayCard(tp,2,2,REASON_COST) end function c59071624.spfilter1(c,e,tp) return c:IsLevel(4) and c:IsRace(RACE_INSECT+RACE_PLANT) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function c59071624.sptg1(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingMatchingCard(c59071624.spfilter1,tp,LOCATION_GRAVE,0,1,nil,e,tp) end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_GRAVE) end function c59071624.spop1(e,tp,eg,ep,ev,re,r,rp) if Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,aux.NecroValleyFilter(c59071624.spfilter1),tp,LOCATION_GRAVE,0,1,1,nil,e,tp) if g:GetCount()>0 then Duel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP) end end function c59071624.cfilter(c,tp) return c:IsPreviousLocation(LOCATION_MZONE) and (c:IsLocation(LOCATION_GRAVE) or (c:IsLocation(LOCATION_REMOVED) and c:IsFaceup())) and c:IsReason(REASON_EFFECT) and c:GetReasonPlayer()==tp and c:IsPreviousControler(1-tp) end function c59071624.spcon2(e,tp,eg,ep,ev,re,r,rp) return eg:IsExists(c59071624.cfilter,1,nil,tp) and not eg:IsContains(e:GetHandler()) end function c59071624.spcost2(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():CheckRemoveOverlayCard(tp,1,REASON_COST) end e:GetHandler():RemoveOverlayCard(tp,1,1,REASON_COST) end function c59071624.spfilter2(c,e,tp,g) return g:IsContains(c) and c59071624.cfilter(c,tp) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function c59071624.sptg2(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_GRAVE+LOCATION_REMOVED) and c59071624.spfilter2(chkc,e,tp,eg) end if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingTarget(c59071624.spfilter2,tp,LOCATION_GRAVE+LOCATION_REMOVED,LOCATION_GRAVE+LOCATION_REMOVED,1,nil,e,tp,eg) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectTarget(tp,c59071624.spfilter2,tp,LOCATION_GRAVE+LOCATION_REMOVED,LOCATION_GRAVE+LOCATION_REMOVED,1,1,nil,e,tp,eg) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,1,0,0) end function c59071624.spop2(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) then Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP) end end
gpl-2.0
m4h4n/telegram-bot
plugins/gnuplot.lua
622
1813
--[[ * Gnuplot plugin by psykomantis * dependencies: * - gnuplot 5.00 * - libgd2-xpm-dev (on Debian distr) for more info visit: https://libgd.github.io/pages/faq.html * ]] -- Gnuplot needs absolute path for the plot, so i run some commands to find where we are local outputFile = io.popen("pwd","r") io.input(outputFile) local _pwd = io.read("*line") io.close(outputFile) local _absolutePlotPath = _pwd .. "/data/plot.png" local _scriptPath = "./data/gnuplotScript.gpl" do local function gnuplot(msg, fun) local receiver = get_receiver(msg) -- We generate the plot commands local formattedString = [[ set grid set terminal png set output "]] .. _absolutePlotPath .. [[" plot ]] .. fun local file = io.open(_scriptPath,"w"); file:write(formattedString) file:close() os.execute("gnuplot " .. _scriptPath) os.remove (_scriptPath) return _send_photo(receiver, _absolutePlotPath) end -- Check all dependencies before executing local function checkDependencies() local status = os.execute("gnuplot -h") if(status==true) then status = os.execute("gnuplot -e 'set terminal png'") if(status == true) then return 0 -- OK ready to go! else return 1 -- missing libgd2-xpm-dev end else return 2 -- missing gnuplot end end local function run(msg, matches) local status = checkDependencies() if(status == 0) then return gnuplot(msg,matches[1]) elseif(status == 1) then return "It seems that this bot miss a dependency :/" else return "It seems that this bot doesn't have gnuplot :/" end end return { description = "use gnuplot through telegram, only plot single variable function", usage = "!gnuplot [single variable function]", patterns = {"^!gnuplot (.+)$"}, run = run } end
gpl-2.0
alfred-bot/mer2phm
plugins/gnuplot.lua
622
1813
--[[ * Gnuplot plugin by psykomantis * dependencies: * - gnuplot 5.00 * - libgd2-xpm-dev (on Debian distr) for more info visit: https://libgd.github.io/pages/faq.html * ]] -- Gnuplot needs absolute path for the plot, so i run some commands to find where we are local outputFile = io.popen("pwd","r") io.input(outputFile) local _pwd = io.read("*line") io.close(outputFile) local _absolutePlotPath = _pwd .. "/data/plot.png" local _scriptPath = "./data/gnuplotScript.gpl" do local function gnuplot(msg, fun) local receiver = get_receiver(msg) -- We generate the plot commands local formattedString = [[ set grid set terminal png set output "]] .. _absolutePlotPath .. [[" plot ]] .. fun local file = io.open(_scriptPath,"w"); file:write(formattedString) file:close() os.execute("gnuplot " .. _scriptPath) os.remove (_scriptPath) return _send_photo(receiver, _absolutePlotPath) end -- Check all dependencies before executing local function checkDependencies() local status = os.execute("gnuplot -h") if(status==true) then status = os.execute("gnuplot -e 'set terminal png'") if(status == true) then return 0 -- OK ready to go! else return 1 -- missing libgd2-xpm-dev end else return 2 -- missing gnuplot end end local function run(msg, matches) local status = checkDependencies() if(status == 0) then return gnuplot(msg,matches[1]) elseif(status == 1) then return "It seems that this bot miss a dependency :/" else return "It seems that this bot doesn't have gnuplot :/" end end return { description = "use gnuplot through telegram, only plot single variable function", usage = "!gnuplot [single variable function]", patterns = {"^!gnuplot (.+)$"}, run = run } end
gpl-2.0
mercury233/ygopro-scripts
c49479374.lua
2
1126
--急速充電器 function c49479374.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_TOHAND) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetTarget(c49479374.target) e1:SetOperation(c49479374.activate) c:RegisterEffect(e1) end function c49479374.filter(c) return c:IsSetCard(0x28) and c:IsLevelBelow(4) and c:IsAbleToHand() end function c49479374.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and c49479374.filter(chkc) end if chk==0 then return Duel.IsExistingTarget(c49479374.filter,tp,LOCATION_GRAVE,0,2,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local g=Duel.SelectTarget(tp,c49479374.filter,tp,LOCATION_GRAVE,0,2,2,nil) Duel.SetOperationInfo(0,CATEGORY_TOHAND,g,2,0,0) end function c49479374.activate(e,tp,eg,ep,ev,re,r,rp) local g=Duel.GetChainInfo(0,CHAININFO_TARGET_CARDS) local sg=g:Filter(Card.IsRelateToEffect,nil,e) if sg:GetCount()>0 then Duel.SendtoHand(sg,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,sg) end end
gpl-2.0
Cavitt/vanilla-ot
data/npc/REFERENCETHESE/Mehkesh.lua
5
2400
local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end function onThink() npcHandler:onThink() end local shopModule = ShopModule:new() npcHandler:addModule(shopModule) shopModule:addBuyableItem({'health potion'}, 7618, 45, 1, 'health potion') shopModule:addBuyableItem({'mana potion'}, 7620, 50, 1, 'mana potion') shopModule:addBuyableItem({'strong health'}, 7588, 100, 1, 'strong health potion') shopModule:addBuyableItem({'strong mana'}, 7589, 80, 1, 'strong mana potion') shopModule:addBuyableItem({'great health'}, 7591, 190, 1, 'great health potion') shopModule:addBuyableItem({'great mana'}, 7590, 120, 1, 'great mana potion') shopModule:addBuyableItem({'great spirit'}, 8472, 190, 1, 'great spirit potion') shopModule:addBuyableItem({'ultimate health'}, 8473, 310, 1, 'ultimate health potion') shopModule:addSellableItem({'normal potion flask', 'normal flask'}, 7636, 5, 'empty small potion flask') shopModule:addSellableItem({'strong potion flask', 'strong flask'}, 7634, 10, 'empty strong potion flask') shopModule:addSellableItem({'great potion flask', 'great flask'}, 7635, 15, 'empty great potion flask') shopModule:addBuyableItemContainer({'bp hp'}, 2000, 7618, 900, 1, 'backpack of health potions') shopModule:addBuyableItemContainer({'bp mp'}, 2001, 7620, 1000, 1, 'backpack of mana potions') shopModule:addBuyableItemContainer({'bp shp'}, 2000, 7588, 2000, 1, 'backpack of strong health potions') shopModule:addBuyableItemContainer({'bp smp'}, 2001, 7589, 1600, 1, 'backpack of strong mana potions') shopModule:addBuyableItemContainer({'bp ghp'}, 2000, 7591, 3800, 1, 'backpack of great health potions') shopModule:addBuyableItemContainer({'bp gmp'}, 2001, 7590, 2400, 1, 'backpack of great mana potions') shopModule:addBuyableItemContainer({'bp gsp'}, 1999, 8472, 3820, 1, 'backpack of great spirit potions') shopModule:addBuyableItemContainer({'bp uhp'}, 2000, 8473, 6200, 1, 'backpack of ultimate health potions') npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())
agpl-3.0
Zenny89/darkstar
scripts/zones/Throne_Room/npcs/_4l2.lua
51
1172
----------------------------------- -- Area: Throne Room -- NPC: Ore Door ------------------------------------- require("scripts/globals/bcnm"); ----------------------------------- -- onTrade Action ----------------------------------- function onTrade(player,npc,trade) if (TradeBCNM(player,player:getZoneID(),trade,npc)) then return; end end; ----------------------------------- -- onTrigger Action ----------------------------------- function onTrigger(player,npc) if (EventTriggerBCNM(player,npc)) then return 1; end end; ----------------------------------- -- onEventUpdate ----------------------------------- function onEventUpdate(player,csid,option) --printf("onUpdate CSID: %u",csid); --printf("onUpdate RESULT: %u",option); if (EventUpdateBCNM(player,csid,option)) then return; end end; ----------------------------------- -- onEventFinish Action ----------------------------------- function onEventFinish(player,csid,option) --printf("onFinish CSID: %u",csid); --printf("onFinish RESULT: %u",option); if (EventFinishBCNM(player,csid,option)) then return; end end;
gpl-3.0
noname007/koreader
frontend/device/kindle/device.lua
1
10234
local Generic = require("device/generic/device") local DEBUG = require("dbg") local function yes() return true end local Kindle = Generic:new{ model = "Kindle", isKindle = yes, } local Kindle2 = Kindle:new{ model = "Kindle2", hasKeyboard = yes, hasKeys = yes, } local KindleDXG = Kindle:new{ model = "KindleDXG", hasKeyboard = yes, hasKeys = yes, } local Kindle3 = Kindle:new{ model = "Kindle3", hasKeyboard = yes, hasKeys = yes, } local Kindle4 = Kindle:new{ model = "Kindle4", hasKeys = yes, } local KindleTouch = Kindle:new{ model = "KindleTouch", isTouchDevice = yes, hasKeys = yes, touch_dev = "/dev/input/event3", } local KindlePaperWhite = Kindle:new{ model = "KindlePaperWhite", isTouchDevice = yes, hasFrontlight = yes, display_dpi = 212, touch_dev = "/dev/input/event0", } local KindlePaperWhite2 = Kindle:new{ model = "KindlePaperWhite2", isTouchDevice = yes, hasFrontlight = yes, display_dpi = 212, touch_dev = "/dev/input/event1", } local KindleBasic = Kindle:new{ model = "KindleBasic", isTouchDevice = yes, touch_dev = "/dev/input/event1", } local KindleVoyage = Kindle:new{ model = "KindleVoyage", isTouchDevice = yes, hasFrontlight = yes, hasKeys = yes, display_dpi = 300, touch_dev = "/dev/input/event1", } local KindlePaperWhite3 = Kindle:new{ model = "KindlePaperWhite3", isTouchDevice = yes, hasFrontlight = yes, display_dpi = 300, touch_dev = "/dev/input/event1", } function Kindle2:init() self.screen = require("ffi/framebuffer_einkfb"):new{device = self, debug = DEBUG} self.input = require("device/input"):new{ device = self, event_map = require("device/kindle/event_map_keyboard"), } self.input.open("/dev/input/event1") Kindle.init(self) end function KindleDXG:init() self.screen = require("ffi/framebuffer_einkfb"):new{device = self, debug = DEBUG} self.input = require("device/input"):new{ device = self, event_map = require("device/kindle/event_map_keyboard"), } self.input.open("/dev/input/event0") self.input.open("/dev/input/event1") Kindle.init(self) end function Kindle3:init() self.screen = require("ffi/framebuffer_einkfb"):new{device = self, debug = DEBUG} self.input = require("device/input"):new{ device = self, event_map = require("device/kindle/event_map_keyboard"), } self.input.open("/dev/input/event0") self.input.open("/dev/input/event1") Kindle.init(self) end function Kindle4:init() self.screen = require("ffi/framebuffer_einkfb"):new{device = self, debug = DEBUG} self.input = require("device/input"):new{ device = self, event_map = require("device/kindle/event_map_kindle4"), } self.input.open("/dev/input/event1") Kindle.init(self) end local ABS_MT_POSITION_X = 53 local ABS_MT_POSITION_Y = 54 function KindleTouch:init() self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = DEBUG} self.powerd = require("device/kindle/powerd"):new{ device = self, batt_capacity_file = "/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity", is_charging_file = "/sys/devices/platform/fsl-usb2-udc/charging", } self.input = require("device/input"):new{ device = self, -- Kindle Touch has a single button event_map = { [102] = "Home" }, } -- Kindle Touch needs event modification for proper coordinates self.input:registerEventAdjustHook(self.input.adjustTouchScale, {x=600/4095, y=800/4095}) -- event0 in KindleTouch is "WM8962 Beep Generator" (useless) -- event1 in KindleTouch is "imx-yoshi Headset" (useless) self.input.open("/dev/input/event2") -- Home button self.input.open("/dev/input/event3") -- touchscreen self.input.open("fake_events") Kindle.init(self) end function KindlePaperWhite:init() self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = DEBUG} self.powerd = require("device/kindle/powerd"):new{ device = self, fl_intensity_file = "/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity", batt_capacity_file = "/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity", is_charging_file = "/sys/devices/platform/aplite_charger.0/charging", } Kindle.init(self) self.input.open("/dev/input/event0") self.input.open("fake_events") end function KindlePaperWhite2:init() self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = DEBUG} self.powerd = require("device/kindle/powerd"):new{ device = self, fl_intensity_file = "/sys/class/backlight/max77696-bl/brightness", batt_capacity_file = "/sys/devices/system/wario_battery/wario_battery0/battery_capacity", is_charging_file = "/sys/devices/system/wario_charger/wario_charger0/charging", } Kindle.init(self) self.input.open("/dev/input/event1") self.input.open("fake_events") end function KindleBasic:init() self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = DEBUG} self.powerd = require("device/kindle/powerd"):new{ device = self, batt_capacity_file = "/sys/devices/system/wario_battery/wario_battery0/battery_capacity", is_charging_file = "/sys/devices/system/wario_charger/wario_charger0/charging", } Kindle.init(self) self.input.open("/dev/input/event1") self.input.open("fake_events") end function KindleVoyage:init() self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = DEBUG} self.powerd = require("device/kindle/powerd"):new{ device = self, fl_intensity_file = "/sys/class/backlight/max77696-bl/brightness", batt_capacity_file = "/sys/devices/system/wario_battery/wario_battery0/battery_capacity", is_charging_file = "/sys/devices/system/wario_charger/wario_charger0/charging", } self.input = require("device/input"):new{ device = self, event_map = { [104] = "LPgBack", [109] = "LPgFwd", }, } Kindle.init(self) self.input.open("/dev/input/event1") self.input.open("/dev/input/event2") self.input.open("fake_events") end function KindlePaperWhite3:init() self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = DEBUG} self.powerd = require("device/kindle/powerd"):new{ device = self, fl_intensity_file = "/sys/class/backlight/max77696-bl/brightness", batt_capacity_file = "/sys/devices/system/wario_battery/wario_battery0/battery_capacity", is_charging_file = "/sys/devices/system/wario_charger/wario_charger0/charging", } Kindle.init(self) self.input.open("/dev/input/event1") self.input.open("fake_events") end --[[ Test if a kindle device has Special Offers --]] local function isSpecialOffers() -- Look at the current blanket modules to see if the SO screensavers are enabled... local lipc = require("liblipclua") if not lipc then DEBUG("could not load liblibclua") return false end local lipc_handle = lipc.init("com.github.koreader.device") if not lipc_handle then DEBUG("could not get lipc handle") return false end local so = false local loaded_blanket_modules = lipc_handle:get_string_property("com.lab126.blanket", "load") if string.find(loaded_blanket_modules, "ad_screensaver") then so = true end lipc_handle:close() return so end function KindleTouch:exit() if isSpecialOffers() then -- fake a touch event if self.touch_dev then local width, height = self.screen:getScreenWidth(), self.screen:getScreenHeight() require("ffi/input").fakeTapInput(self.touch_dev, math.min(width, height)/2, math.max(width, height)-30 ) end end Generic.exit(self) end KindlePaperWhite.exit = KindleTouch.exit KindlePaperWhite2.exit = KindleTouch.exit KindleBasic.exit = KindleTouch.exit KindleVoyage.exit = KindleTouch.exit KindlePaperWhite3.exit = KindleTouch.exit function Kindle3:exit() -- send double menu key press events to trigger screen refresh os.execute("echo 'send 139' > /proc/keypad;echo 'send 139' > /proc/keypad") Generic.exit(self) end KindleDXG.exit = Kindle3.exit ----------------- device recognition: ------------------- local function Set(list) local set = {} for _, l in ipairs(list) do set[l] = true end return set end local kindle_sn = io.open("/proc/usid", "r") if not kindle_sn then return end local kindle_devcode = string.sub(kindle_sn:read(),3,4) kindle_sn:seek("set") local kindle_devcode_v2 = string.sub(kindle_sn:read(),4,6) kindle_sn:close() -- NOTE: Update me when new devices come out :) local k2_set = Set { "02", "03" } local dx_set = Set { "04", "05" } local dxg_set = Set { "09" } local k3_set = Set { "08", "06", "0A" } local k4_set = Set { "0E", "23" } local touch_set = Set { "0F", "11", "10", "12" } local pw_set = Set { "24", "1B", "1D", "1F", "1C", "20" } local pw2_set = Set { "D4", "5A", "D5", "D6", "D7", "D8", "F2", "17", "60", "F4", "F9", "62", "61", "5F" } local kt2_set = Set { "C6", "DD" } local kv_set = Set { "13", "54", "2A", "4F", "52", "53" } local pw3_set = Set { "0G1", "0G2", "0G4", "0G5", "0G6", "0G7" } if k2_set[kindle_devcode] then return Kindle2 elseif dx_set[kindle_devcode] then return Kindle2 elseif dxg_set[kindle_devcode] then return KindleDXG elseif k3_set[kindle_devcode] then return Kindle3 elseif k4_set[kindle_devcode] then return Kindle4 elseif touch_set[kindle_devcode] then return KindleTouch elseif pw_set[kindle_devcode] then return KindlePaperWhite elseif pw2_set[kindle_devcode] then return KindlePaperWhite2 elseif kt2_set[kindle_devcode] then return KindleBasic elseif kv_set[kindle_devcode] then return KindleVoyage elseif pw3_set[kindle_devcode_v2] then return KindlePaperWhite3 end error("unknown Kindle model "..kindle_devcode)
agpl-3.0
alfred-bot/mer2phm
plugins/quotes.lua
651
1630
local quotes_file = './data/quotes.lua' local quotes_table function read_quotes_file() local f = io.open(quotes_file, "r+") if f == nil then print ('Created a new quotes file on '..quotes_file) serialize_to_file({}, quotes_file) else print ('Quotes loaded: '..quotes_file) f:close() end return loadfile (quotes_file)() end function save_quote(msg) local to_id = tostring(msg.to.id) if msg.text:sub(11):isempty() then return "Usage: !addquote quote" end if quotes_table == nil then quotes_table = {} end if quotes_table[to_id] == nil then print ('New quote key to_id: '..to_id) quotes_table[to_id] = {} end local quotes = quotes_table[to_id] quotes[#quotes+1] = msg.text:sub(11) serialize_to_file(quotes_table, quotes_file) return "done!" end function get_quote(msg) local to_id = tostring(msg.to.id) local quotes_phrases quotes_table = read_quotes_file() quotes_phrases = quotes_table[to_id] return quotes_phrases[math.random(1,#quotes_phrases)] end function run(msg, matches) if string.match(msg.text, "!quote$") then return get_quote(msg) elseif string.match(msg.text, "!addquote (.+)$") then quotes_table = read_quotes_file() return save_quote(msg) end end return { description = "Save quote", description = "Quote plugin, you can create and retrieve random quotes", usage = { "!addquote [msg]", "!quote", }, patterns = { "^!addquote (.+)$", "^!quote$", }, run = run }
gpl-2.0
mercury233/ygopro-scripts
c5130393.lua
2
3009
--千年の血族 function c5130393.initial_effect(c) --special summon local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(5130393,0)) e1:SetCategory(CATEGORY_SPECIAL_SUMMON) e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O) e1:SetRange(LOCATION_HAND) e1:SetCode(EVENT_DAMAGE) e1:SetCountLimit(1,5130393) e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DAMAGE_CAL) e1:SetCondition(c5130393.spcon) e1:SetTarget(c5130393.sptg) e1:SetOperation(c5130393.spop) c:RegisterEffect(e1) --special summon or todeck local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(5130393,1)) e2:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_SEARCH) e2:SetType(EFFECT_TYPE_IGNITION) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetRange(LOCATION_MZONE) e2:SetCountLimit(1,5130394) e2:SetTarget(c5130393.tdtg) e2:SetOperation(c5130393.tdop) c:RegisterEffect(e2) end function c5130393.spcon(e,tp,eg,ep,ev,re,r,rp) return ep==tp and ev>=1000 and bit.band(r,REASON_BATTLE+REASON_EFFECT)~=0 end function c5130393.sptg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and e:GetHandler():IsCanBeSpecialSummoned(e,0,tp,false,false) end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,e:GetHandler(),1,0,0) end function c5130393.spop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if c:IsRelateToEffect(e) then Duel.SpecialSummon(c,0,tp,tp,false,false,POS_FACEUP) end end function c5130393.filter(c,e,tp) return c:GetTextAttack()>=0 and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function c5130393.thfilter(c) return c:GetTextAttack()>=0 and c:IsType(TYPE_MONSTER) and c:IsAbleToHand() end function c5130393.tdtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_GRAVE) and c5130393.filter(chkc,e,tp) end if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingTarget(c5130393.filter,tp,0,LOCATION_GRAVE,1,nil,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectTarget(tp,c5130393.filter,tp,0,LOCATION_GRAVE,1,1,nil,e,tp) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,1,0,0) end function c5130393.tdop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if not tc:IsRelateToEffect(e) then return end local vc=tc:GetTextAttack() local sel=1 local g=Duel.GetMatchingGroup(c5130393.thfilter,tp,0,LOCATION_DECK,nil) Duel.Hint(HINT_SELECTMSG,1-tp,aux.Stringid(5130393,2)) if g:GetCount()>0 then sel=Duel.SelectOption(1-tp,1213,1214) else sel=Duel.SelectOption(1-tp,1214)+1 end if sel==0 then Duel.Hint(HINT_SELECTMSG,1-tp,HINTMSG_CONFIRM) local sg=Duel.SelectMatchingCard(1-tp,c5130393.thfilter,tp,0,LOCATION_DECK,1,1,nil) Duel.ConfirmCards(tp,sg) if sg:GetFirst():GetTextAttack()<vc then Duel.ShuffleDeck(1-tp) Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP) else Duel.SendtoHand(sg,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,sg) end else Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP) end end
gpl-2.0
mercury233/ygopro-scripts
c44891812.lua
2
3372
--超重武者オタス-K function c44891812.initial_effect(c) --def up local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(44891812,0)) e1:SetCategory(CATEGORY_DEFCHANGE) e1:SetType(EFFECT_TYPE_QUICK_O) e1:SetCode(EVENT_PRE_DAMAGE_CALCULATE) e1:SetRange(LOCATION_HAND) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetCondition(c44891812.defcon) e1:SetCost(c44891812.defcost) e1:SetTarget(c44891812.deftg) e1:SetOperation(c44891812.defop) c:RegisterEffect(e1) --special summon local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(44891812,1)) e2:SetCategory(CATEGORY_SPECIAL_SUMMON) e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O) e2:SetCode(EVENT_ATTACK_ANNOUNCE) e2:SetRange(LOCATION_GRAVE) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetCondition(c44891812.spcon) e2:SetCost(aux.bfgcost) e2:SetTarget(c44891812.sptg) e2:SetOperation(c44891812.spop) c:RegisterEffect(e2) end function c44891812.defcon(e,tp,eg,ep,ev,re,r,rp) return Duel.GetMatchingGroupCount(Card.IsType,tp,LOCATION_GRAVE,0,nil,TYPE_SPELL+TYPE_TRAP)==0 end function c44891812.defcost(e,tp,eg,ep,ev,re,r,rp,chk) local c=e:GetHandler() if chk==0 then return c:IsDiscardable() end Duel.SendtoGrave(c,REASON_COST+REASON_DISCARD) end function c44891812.deffilter(c) return c:IsFaceup() and c:IsSetCard(0x9a) and aux.nzdef(c) end function c44891812.deftg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) local a=Duel.GetAttacker() local d=a:GetBattleTarget() if a:IsControler(1-tp) then a,d=d,a end if chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and c44891812.deffilter(chkc) and chkc~=e:GetLabelObject() end if chk==0 then return a and a:IsDefensePos() and d and d:IsControler(1-tp) and Duel.IsExistingTarget(c44891812.deffilter,tp,LOCATION_MZONE,0,1,a) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FACEUP) Duel.SelectTarget(tp,c44891812.deffilter,tp,LOCATION_MZONE,0,1,1,a) e:SetLabelObject(a) end function c44891812.defop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() local ac=e:GetLabelObject() if ac:IsRelateToBattle() and ac:IsFaceup() and tc:IsRelateToEffect(e) and tc:IsFaceup() then local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetCode(EFFECT_UPDATE_DEFENSE) e1:SetValue(tc:GetDefense()) e1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_DAMAGE_CAL) ac:RegisterEffect(e1) end end function c44891812.spcon(e,tp,eg,ep,ev,re,r,rp) local at=Duel.GetAttacker() return at:IsControler(1-tp) and Duel.GetAttackTarget()==nil end function c44891812.spfilter(c,e,tp) return c:IsSetCard(0x9a) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function c44891812.sptg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) local c=e:GetHandler() if chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and c44891812.spfilter(chkc,e,tp) and chkc~=c end if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingTarget(c44891812.spfilter,tp,LOCATION_GRAVE,0,1,c,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectTarget(tp,c44891812.spfilter,tp,LOCATION_GRAVE,0,1,1,c,e,tp) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,1,0,0) end function c44891812.spop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) then Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP) end end
gpl-2.0
Zenny89/darkstar
scripts/zones/Port_San_dOria/npcs/Diraulate.lua
36
1375
----------------------------------- -- Area: Port San d'Oria -- NPC: Diraulate -- Standard Info NPC ----------------------------------- package.loaded["scripts/zones/Port_San_dOria/TextIDs"] = nil; ----------------------------------- require("scripts/globals/quests"); require("scripts/zones/Port_San_dOria/TextIDs"); ----------------------------------- -- onTrade Action ----------------------------------- function onTrade(player,npc,trade) -- "Flyers for Regine" conditional script FlyerForRegine = player:getQuestStatus(SANDORIA,FLYERS_FOR_REGINE); if (FlyerForRegine == 1) then count = trade:getItemCount(); MagicFlyer = trade:hasItemQty(532,1); if (MagicFlyer == true and count == 1) then player:messageSpecial(FLYER_REFUSED); end end end; ----------------------------------- -- onTrigger Action ----------------------------------- function onTrigger(player,npc) player:startEvent(0x245); end; ----------------------------------- -- onEventUpdate ----------------------------------- function onEventUpdate(player,csid,option) --printf("CSID: %u",csid); --printf("RESULT: %u",option); end; ----------------------------------- -- onEventFinish ----------------------------------- function onEventFinish(player,csid,option) --printf("CSID: %u",csid); --printf("RESULT: %u",option); end;
gpl-3.0
dani-sj/nod32
plugins/chatbot.lua
21
2121
local function run(msg) if msg.text == "یاقی" then return "کی اسم سازندمو صدا زد؟" end if msg.text == "Umbrella" then return "کیر نود32 هم نی" end if msg.text == "umbrella" then return "کیر نود32 هم نی" end if msg.text == "نود32" then return "hum?" end if msg.text == "اسپم" then return "کس ننت میذارم بخای اسپم کنی" end if msg.text == "زتا" then return "کس ننش بگو مرسی" end if msg.text == "ایکس ایگرگ" then return "ایکس ایگرگو همرا ننت گاییدم ابمم ریختم روش" end if msg.text == "spam" then return "تو اگه تخم داشتی اسپم کنی الان اینجا بودی" end if msg.text == "ایکس" then return "ایکس ایگرگ گاییدم ابمم کس ننته" end if msg.text == "ایگرگ" then return "ایکس ایگرگ گاییدم ابمم کس ننته" end if msg.text == "x" then return "ایکس ایگرگ گاییدم ابمم کس ننته" end if msg.text == "start" then return "تو اگه تخم داشتی گروهو خراب کنی بیا پیش خودم ننتومیگام @behroozyaghi" end if msg.text == "y" then return "ایکس ایگرگ گاییدم ابمم کس ننته" end if msg.text == "Bot" then return "چی کس میگی؟" end if msg.text == "?" then return "Hum??" end if msg.text == "بای" then return "برو به سلامت سیکتیرکن" end if msg.text == "XY" then return "کس ننت میگام سیکتیر اوبی" end if msg.text == "Xy" then return "Bye Bye" end end return { description = "Chat With Robot Server", usage = "chat with robot", patterns = { "^یاقی$", "^[Bb]ot$", "^[Uu]mbrella$", "^بای$", "^x$", "^y$", "^ایکس$", "^ایگرگ$", "^اسپم$", "^زتا$", "^spam$", "^start$", "^بای$", "^Xy$", "^XY$", "^?$", "^نود32$" }, run = run, --privileged = true, pre_process = pre_process } --Copyright; @behroozyaghi --Persian Translate; @behroozyaghi --ch : @nod32team --کپی بدون ذکر منبع حرام است
gpl-2.0
UnluckyNinja/PathOfBuilding
Data/3_0/Bases/ring.lua
3
4280
-- This file is automatically generated, do not edit! -- Item data (c) Grinding Gear Games local itemBases = ... itemBases["Iron Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "Adds 1 to 4 Physical Damage to Attacks", req = { }, } itemBases["Coral Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "+(20-30) to maximum Life", req = { }, } itemBases["Paua Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "+(20-25) to maximum Mana", req = { }, } itemBases["Gold Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "(6-15)% increased Rarity of Items found", req = { level = 20, }, } itemBases["Topaz Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "+(20-30)% to Lightning Resistance", req = { level = 12, }, } itemBases["Sapphire Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "+(20-30)% to Cold Resistance", req = { level = 8, }, } itemBases["Ruby Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "+(20-30)% to Fire Resistance", req = { level = 16, }, } itemBases["Prismatic Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "+(8-10)% to all Elemental Resistances", req = { level = 30, }, } itemBases["Moonstone Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "+(15-25) to maximum Energy Shield", req = { level = 20, }, } itemBases["Amethyst Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "+(9-13)% to Chaos Resistance", req = { level = 30, }, } itemBases["Diamond Ring"] = { type = "Ring", tags = { default = true, ring = true, }, implicit = "(20-30)% increased Global Critical Strike Chance", req = { level = 20, }, } itemBases["Two-Stone Ring"] = { type = "Ring", tags = { default = true, ring = true, twostonering = true, }, implicit = "+(12-16)% to Fire and Lightning Resistances", req = { level = 20, }, } itemBases["Two-Stone Ring"] = { type = "Ring", hidden = true, tags = { default = true, ring = true, twostonering = true, }, implicit = "+(12-16)% to Cold and Lightning Resistances", req = { level = 20, }, } itemBases["Two-Stone Ring"] = { type = "Ring", hidden = true, tags = { default = true, ring = true, twostonering = true, }, implicit = "+(12-16)% to Fire and Cold Resistances", req = { level = 20, }, } itemBases["Unset Ring"] = { type = "Ring", tags = { default = true, ring = true, unset_ring = true, }, implicit = "Has 1 Socket", req = { level = 5, }, } itemBases["Two-Stone Ring (Fire/Lightning)"] = { type = "Ring", tags = { default = true, ring = true, twostonering = true, }, implicit = "+(12-16)% to Fire and Lightning Resistances", req = { level = 20, }, } itemBases["Two-Stone Ring (Cold/Lightning)"] = { type = "Ring", tags = { default = true, ring = true, twostonering = true, }, implicit = "+(12-16)% to Cold and Lightning Resistances", req = { level = 20, }, } itemBases["Two-Stone Ring (Fire/Cold)"] = { type = "Ring", tags = { default = true, ring = true, twostonering = true, }, implicit = "+(12-16)% to Fire and Cold Resistances", req = { level = 20, }, } itemBases["Steel Ring"] = { type = "Ring", tags = { default = true, ring = true, not_for_sale = true, atlas_base_type = true, ringatlas1 = true, }, implicit = "Adds (3-4) to (10-14) Physical Damage to Attacks", req = { level = 80, }, } itemBases["Opal Ring"] = { type = "Ring", tags = { default = true, ring = true, not_for_sale = true, atlas_base_type = true, ringatlas2 = true, }, implicit = "(15-25)% increased Elemental Damage", req = { level = 80, }, } itemBases["Breach Ring"] = { type = "Ring", tags = { default = true, ring = true, not_for_sale = true, }, implicit = "Properties are doubled while in a Breach", req = { }, } itemBases["Golden Hoop"] = { type = "Ring", hidden = true, tags = { default = true, ring = true, not_for_sale = true, }, implicit = "+(8-12) to all Attributes", req = { level = 12, }, } itemBases["Jet Ring"] = { type = "Ring", hidden = true, tags = { default = true, ring = true, not_for_sale = true, }, implicit = "(5-10)% increased Global Defences", req = { }, }
mit
hhsaez/crimild
examples/RocketLaunch/assets/prefabs/fire_exhaust.lua
1
2177
function buildFireExhaustFX( transformation ) local MAX_PARTICLES = 300 return { type = 'crimild::Group', components = { { type = 'crimild::ParticleSystemComponent', particles = { type = 'crimild::ParticleData', maxParticles = MAX_PARTICLES, computeInWorldSpace = true, }, emitRate = 0.5 * MAX_PARTICLES, generators = { { type = 'crimild::BoxPositionParticleGenerator', origin = { 0.0, 0.0, 0.0 }, size = { 0.5, 0.0, 0.5 }, }, { type = 'crimild::RandomVector3fParticleGenerator', attrib = 'velocity', minValue = { 0.0, -3.0, 0.0 }, maxValue = { 2.0, -1.0, 2.0 }, }, { type = 'crimild::DefaultVector3fParticleGenerator', attrib = 'acceleration', value = { 0.0, 0.0, 0.0 }, }, { type = 'crimild::ColorParticleGenerator', minStartColor = { 1.0, 1.0, 1.0, 1.0 }, maxStartColor = { 1.0, 1.0, 1.0, 1.0 }, minEndColor = { 1.0, 0.0, 0.0, 0.0 }, maxEndColor = { 1.0, 0.0, 0.0, 0.0 }, }, { type = 'crimild::RandomReal32ParticleGenerator', attrib = 'uniformScale', minValue = 0.1, maxValue = 1.0, }, { type = 'crimild::TimeParticleGenerator', minTime = 1.0, maxTime = 1.5, }, }, updaters = { { type = 'crimild::EulerParticleUpdater', }, { type = 'crimild::TimeParticleUpdater', }, { type = 'crimild::FloorParticleUpdater', }, { type = 'crimild::CameraSortParticleUpdater', }, { type = 'crimild::ColorParticleUpdater', }, }, renderers = { { type = 'crimild::AnimatedSpriteParticleRenderer', spriteSheetSize = { 4.0, 4.0 }, material = { type = 'crimild::Material', colorMap = { type = 'crimild::Texture', image = { type = 'crimild::ImageTGA', imageFileName = 'assets/textures/flames.tga', }, }, }, blendMode = 'additive', cullFaceEnabled = false, depthStateEnabled = false, }, }, }, }, transformation = transformation, } end
bsd-3-clause
5620g/pp
plugins/bin.lua
12
1554
function run_sh(msg, matches) local receiver = get_receiver(msg) name = get_name(msg) text = '' if is_sudo(msg) then bash = msg.text:sub(4,-1) text = run_bash(bash) else text = name .. ' you have no power here!' end send_large_msg(receiver, 'In Process...', ok_cb, false) return text end function run_bash(str) local cmd = io.popen(str) local result = cmd:read('*all') cmd:close() return result end function on_getting_dialogs(cb_extra,success,result) if success then local dialogs={} for key,value in pairs(result) do for chatkey, chat in pairs(value.peer) do print(chatkey,chat) if chatkey=="id" then table.insert(dialogs,chat.."\n") end if chatkey=="print_name" then table.insert(dialogs,chat..": ") end end end send_msg(cb_extra[1],table.concat(dialogs),ok_cb,false) end end function run(msg, matches) if not is_admin1(msg) then return "شما دسترسی کنترل سرور را ندارید" end local receiver = get_receiver(msg) if string.match then text = run_bash(matches[1]) send_large_msg(receiver, text, ok_cb, false) return end end return { description = "return cmd in trm", usage = "دسترسی به مستقیم به ترمینال .برای استفاده دستور $ را تایپ و عبارت مورد نظر را با یک فاصله بعد از ان تایپ کنید", patterns = {"^[$](.*)$"}, run = run }
gpl-2.0
LucentW/s-uzzbot
plugins/get.lua
3
1151
local function get_variables_hash(msg) if msg.to.type == 'chat' then return 'chat:'..msg.to.id..':variables' end if msg.to.type == 'channel' then return 'channel:'..msg.to.id..':variables' end if msg.to.type == 'user' then return 'user:'..msg.from.id..':variables' end end local function list_variables(msg) local hash = get_variables_hash(msg) if hash then local names = redis:hkeys(hash) local text = '' for i=1, #names do text = text..names[i]..'\n' end return text end end local function get_value(msg, var_name) local hash = get_variables_hash(msg) if hash then local value = redis:hget(hash, var_name) if not value then return'Not found, use "!get" to list variables' else return var_name..' => '..value end end end local function run(msg, matches) if matches[2] then return get_value(msg, matches[2]) else return list_variables(msg) end end return { description = "Retrieves variables saved with !set", usage = "!get (value_name): Returns the value_name value.", patterns = { "^(!get) (.+)$", "^!get$" }, run = run }
gpl-2.0
chtyim/infrastructure-puppet
modules/kibana_asf/files/frombrowser.lua
3
2780
#!/usr/bin/env lua package.path = package.path .. ";/usr/local/etc/logproxy/?.lua" local JSON = require "JSON" -- function for injecting strings into each 'query' element in the JSON function inject(tbl, what) for k, v in pairs(tbl) do if type(v) == "table" then inject(v, what) elseif k == "query" then tbl[k] = tbl[k] .. what end end end -- The main filter -- Get which user has authed this request local user = os.getenv('REMOTE_USER') local kint = os.getenv('REQUEST_URI'):match("^/kibana-int/") and true or false local rm = os.getenv('REQUEST_METHOD') -- Query LDAP for host records local hosts = {} -- If auth is broken/circumvented, return nothing if not user then print("{}") os.exit() end -- Validate user id, just in case user = user:gsub("[^-a-zA-Z0-9_.]+", "") -- Construct a list of valid hosts to retain data for local hosts = {} local allHosts = false local p = io.popen("ldapsearch -x -LLL uid="..user .. " host log-access-host log-access-vhost", "r") if p then local data = p:read("*a") p:close() for host in data:gmatch("host: ([^\r\n]+)") do host = host:gsub("%.apache%.org", "") if host ~= "minotaur" then table.insert(hosts, ([[@node:"%s.apache.org"]]):format(host)) end if host == "*" then allHosts = true end end for host in data:gmatch("log%-access%-host: ([^\r\n]+)") do host = host:gsub("%.apache%.org", "") table.insert(hosts, ([[@node:"%s.apache.org"]]):format(host)) if host == "*" then allHosts = true end end for host in data:gmatch("log%-access%-vhost: ([^\r\n]+)") do host = host:gsub("%.apache%.org", "") table.insert(hosts, ([[(vhost:"%s.apache.org" AND logtype:"httpd_access")]]):format(host)) if host == "*" then table.insert(hosts, ([[logtype:"httpd_access"]]):format(host)) end end end -- only allow put/delete for allHost accessers if not allHosts and (rm == "PUT" or rm == "DELETE") then print("{}") else -- Read JSON data from stdin local data = io.stdin:read("*a") local valid, json = pcall(function() return JSON:decode(data) end) -- If the input contains a query, then mangle it... if valid and json then -- If user doesn't have access to "*", then inject a host requirement into the query if not (allHosts or kint) then local what = " AND (" .. table.concat(hosts, " OR ") .. ")" inject(json, what) end local output = JSON:encode(json) print(output) -- Send converted data down the chain -- If there's no query, just return what was sent else print(data) end end
apache-2.0
amir1213/aa
plugins/all.lua
54
4746
do data = load_data(_config.moderation.data) local function get_msgs_user_chat(user_id, chat_id) local user_info = {} local uhash = 'user:'..user_id local user = redis:hgetall(uhash) local um_hash = 'msgs:'..user_id..':'..chat_id user_info.msgs = tonumber(redis:get(um_hash) or 0) user_info.name = user_print_name(user)..' ['..user_id..']' return user_info end local function chat_stats(chat_id) local hash = 'chat:'..chat_id..':users' local users = redis:smembers(hash) local users_info = {} for i = 1, #users do local user_id = users[i] local user_info = get_msgs_user_chat(user_id, chat_id) table.insert(users_info, user_info) end table.sort(users_info, function(a, b) if a.msgs and b.msgs then return a.msgs > b.msgs end end) local text = 'Chat stats:\n' for k,user in pairs(users_info) do text = text..user.name..' = '..user.msgs..'\n' end return text end local function get_group_type(target) local data = load_data(_config.moderation.data) local group_type = data[tostring(target)]['group_type'] if not group_type or group_type == nil then return 'No group type available.' end return group_type end local function show_group_settings(target) local data = load_data(_config.moderation.data) if data[tostring(target)] then if data[tostring(target)]['settings']['flood_msg_max'] then NUM_MSG_MAX = tonumber(data[tostring(target)]['settings']['flood_msg_max']) print('custom'..NUM_MSG_MAX) else NUM_MSG_MAX = 5 end end local settings = data[tostring(target)]['settings'] local text = "Lock group name : "..settings.lock_name.."\nLock group photo : "..settings.lock_photo.."\nLock group member : "..settings.lock_member.."\nflood sensitivity : "..NUM_MSG_MAX return text end local function get_description(target) local data = load_data(_config.moderation.data) local data_cat = 'description' if not data[tostring(target)][data_cat] then return 'No description available.' end local about = data[tostring(target)][data_cat] return about end local function get_rules(target) local data = load_data(_config.moderation.data) local data_cat = 'rules' if not data[tostring(target)][data_cat] then return 'No rules available.' end local rules = data[tostring(target)][data_cat] return rules end local function modlist(target) local data = load_data(_config.moderation.data) local groups = 'groups' if not data[tostring(groups)] or not data[tostring(groups)][tostring(target)] then return 'Group is not added or is Realm.' end if next(data[tostring(target)]['moderators']) == nil then return 'No moderator in this group.' end local i = 1 local message = '\nList of moderators :\n' for k,v in pairs(data[tostring(target)]['moderators']) do message = message ..i..' - @'..v..' [' ..k.. '] \n' i = i + 1 end return message end local function get_link(target) local data = load_data(_config.moderation.data) local group_link = data[tostring(target)]['settings']['set_link'] if not group_link or group_link == nil then return "No link" end return "Group link:\n"..group_link end local function all(target, receiver) local text = "All the things I know about this group\n\n" local group_type = get_group_type(target) text = text.."Group Type: \n"..group_type local settings = show_group_settings(target) text = text.."\n\nGroup settings: \n"..settings local rules = get_rules(target) text = text.."\n\nRules: \n"..rules local description = get_description(target) text = text.."\n\nAbout: \n"..description local modlist = modlist(target) text = text.."\n\nMods: \n"..modlist local link = get_link(target) text = text.."\n\nLink: \n"..link local stats = chat_stats(target) text = text.."\n\n"..stats local ban_list = ban_list(target) text = text.."\n\n"..ban_list local file = io.open("./groups/all/"..target.."all.txt", "w") file:write(text) file:flush() file:close() send_document(receiver,"./groups/all/"..target.."all.txt", ok_cb, false) return end function run(msg, matches) if matches[1] == "all" and matches[2] and is_owner2(msg.from.id, matches[2]) then local receiver = get_receiver(msg) local target = matches[2] return all(target, receiver) end if not is_owner(msg) then return end if matches[1] == "all" and not matches[2] then local receiver = get_receiver(msg) if not is_owner(msg) then return end return all(msg.to.id, receiver) end end return { usage = { "all: All Actions In Group.", "all [id]: All Actions From [id].", }, patterns = { "^(all)$", "^(all) (%d+)$" }, run = run } end
gpl-2.0
dmccuskey/dmc-wamp
examples/dmc-wamp-rpc-callee/dmc_corona/lib/dmc_lua/lua_objects.lua
44
4827
--====================================================================-- -- dmc_lua/lua_objects.lua -- -- Documentation: http://docs.davidmccuskey.com/ --====================================================================-- --[[ The MIT License (MIT) Copyright (c) 2011-2015 David McCuskey Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --]] --====================================================================-- --== DMC Lua Library : Lua Objects --====================================================================-- -- Semantic Versioning Specification: http://semver.org/ local VERSION = "1.3.0" --====================================================================-- --== Lua Objects --====================================================================-- --====================================================================-- --== Imports local Class = test local Objects = require 'lua_class' local EventsMixModule = require 'lua_events_mix' --====================================================================-- --== Setup, Constants local Class = Objects.Class local registerCtorName = Objects.registerCtorName local registerDtorName = Objects.registerDtorName local EventsMix = EventsMixModule.EventsMix -- Add new Dtor name (function references) registerDtorName( 'removeSelf', Class ) --====================================================================-- --== Object Base Class --====================================================================-- local ObjectBase = newClass( { Class, EventsMix }, { name="Object Base" } ) --======================================================-- --== Constructor / Destructor -- __new__() -- this method drives the construction flow for DMC-style objects -- typically, you won't override this -- function ObjectBase:__new__( ... ) --== Do setup sequence ==-- self:__init__( ... ) -- skip these if a Class object (ie, NOT an instance) if rawget( self, '__is_class' ) == false then self:__initComplete__() end return self end -- __destroy__() -- this method drives the destruction flow for DMC-style objects -- typically, you won't override this -- function ObjectBase:__destroy__() --== Do teardown sequence ==-- -- skip these if a Class object (ie, NOT an instance) if rawget( self, '__is_class' ) == false then self:__undoInitComplete__() end self:__undoInit__() end --======================================================-- -- Start: Setup Lua Objects -- __init__ -- initialize the object -- function ObjectBase:__init__( ... ) --[[ there is no __init__ on Class -- self:superCall( Class, '__init__', ... ) --]] self:superCall( EventsMix, '__init__', ... ) --==-- end -- __undoInit__ -- remove items added during __init__ -- function ObjectBase:__undoInit__() self:superCall( EventsMix, '__undoInit__' ) --[[ there is no __undoInit__ on Class -- self:superCall( Class, '__undoInit__' ) --]] end -- __initComplete__ -- any setup after object is done with __init__ -- function ObjectBase:__initComplete__() end -- __undoInitComplete__() -- remove any items added during __initComplete__ -- function ObjectBase:__undoInitComplete__() end -- END: Setup Lua Objects --======================================================-- --====================================================================-- --== Public Methods -- none --====================================================================-- --== Private Methods -- none --====================================================================-- --== Event Handlers -- none --====================================================================-- --== Lua Objects Exports --====================================================================-- -- simply add to current exports Objects.ObjectBase = ObjectBase return Objects
mit
dmccuskey/dmc-wamp
examples/dmc-wamp-rpc-caller/dmc_corona/lib/dmc_lua/lua_objects.lua
44
4827
--====================================================================-- -- dmc_lua/lua_objects.lua -- -- Documentation: http://docs.davidmccuskey.com/ --====================================================================-- --[[ The MIT License (MIT) Copyright (c) 2011-2015 David McCuskey Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --]] --====================================================================-- --== DMC Lua Library : Lua Objects --====================================================================-- -- Semantic Versioning Specification: http://semver.org/ local VERSION = "1.3.0" --====================================================================-- --== Lua Objects --====================================================================-- --====================================================================-- --== Imports local Class = test local Objects = require 'lua_class' local EventsMixModule = require 'lua_events_mix' --====================================================================-- --== Setup, Constants local Class = Objects.Class local registerCtorName = Objects.registerCtorName local registerDtorName = Objects.registerDtorName local EventsMix = EventsMixModule.EventsMix -- Add new Dtor name (function references) registerDtorName( 'removeSelf', Class ) --====================================================================-- --== Object Base Class --====================================================================-- local ObjectBase = newClass( { Class, EventsMix }, { name="Object Base" } ) --======================================================-- --== Constructor / Destructor -- __new__() -- this method drives the construction flow for DMC-style objects -- typically, you won't override this -- function ObjectBase:__new__( ... ) --== Do setup sequence ==-- self:__init__( ... ) -- skip these if a Class object (ie, NOT an instance) if rawget( self, '__is_class' ) == false then self:__initComplete__() end return self end -- __destroy__() -- this method drives the destruction flow for DMC-style objects -- typically, you won't override this -- function ObjectBase:__destroy__() --== Do teardown sequence ==-- -- skip these if a Class object (ie, NOT an instance) if rawget( self, '__is_class' ) == false then self:__undoInitComplete__() end self:__undoInit__() end --======================================================-- -- Start: Setup Lua Objects -- __init__ -- initialize the object -- function ObjectBase:__init__( ... ) --[[ there is no __init__ on Class -- self:superCall( Class, '__init__', ... ) --]] self:superCall( EventsMix, '__init__', ... ) --==-- end -- __undoInit__ -- remove items added during __init__ -- function ObjectBase:__undoInit__() self:superCall( EventsMix, '__undoInit__' ) --[[ there is no __undoInit__ on Class -- self:superCall( Class, '__undoInit__' ) --]] end -- __initComplete__ -- any setup after object is done with __init__ -- function ObjectBase:__initComplete__() end -- __undoInitComplete__() -- remove any items added during __initComplete__ -- function ObjectBase:__undoInitComplete__() end -- END: Setup Lua Objects --======================================================-- --====================================================================-- --== Public Methods -- none --====================================================================-- --== Private Methods -- none --====================================================================-- --== Event Handlers -- none --====================================================================-- --== Lua Objects Exports --====================================================================-- -- simply add to current exports Objects.ObjectBase = ObjectBase return Objects
mit
UnluckyNinja/PathOfBuilding
Data/Uniques/staff.lua
1
9479
-- Item data (c) Grinding Gear Games return { -- Weapon: Staff [[ Agnerod East Imperial Staff Variant: Pre 2.6.0 Variant: Current Requires Level 66, 158 Str, 113 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block {variant:1}+1 to Level of Socketed Lightning Gems {variant:2}+2 to Level of Socketed Lightning Gems +(80-120) to Intelligence (30-50)% increased Lightning Damage 100% increased Shock Duration on Enemies 40% increased Strength Requirement Damage Penetrates 20% Lightning Resistance ]],[[ Agnerod North Imperial Staff Variant: Pre 2.6.0 Variant: Current Requires Level 66, 158 Str, 113 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block {variant:1}+1 to Level of Socketed Lightning Gems {variant:2}+2 to Level of Socketed Lightning Gems +(80-120) to Intelligence (30-50)% increased Lightning Damage 15% chance to Shock 40% increased Strength Requirement Damage Penetrates 20% Lightning Resistance ]],[[ Agnerod South Imperial Staff Variant: Pre 2.6.0 Variant: Current Requires Level 66, 158 Str, 113 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block {variant:1}+1 to Level of Socketed Lightning Gems {variant:2}+2 to Level of Socketed Lightning Gems +(80-120) to Intelligence (30-50)% increased Lightning Damage +5% to Maximum Lightning Resistance 40% increased Strength Requirement Damage Penetrates 20% Lightning Resistance ]],[[ Agnerod West Imperial Staff Variant: Pre 2.6.0 Variant: Current Requires Level 66, 158 Str, 113 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block {variant:1}+1 to Level of Socketed Lightning Gems {variant:2}+2 to Level of Socketed Lightning Gems +(80-120) to Intelligence (30-50)% increased Lightning Damage Adds (5-15) to (100-140) Lightning Damage to Spells 40% increased Strength Requirement Damage Penetrates 20% Lightning Resistance ]],[[ The Blood Thorn Gnarled Branch Variant: Pre 2.6.0 Variant: Current Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block 12% Chance to Block 100% increased Physical Damage (5-10)% increased Attack Speed Reflects (22-44) Physical Damage to Attackers on Block Curse Enemies with level 5 Vulnerability on Block ]],[[ Duskdawn Maelström Staff Variant: Pre 2.6.0 Variant: Current Requires Level 64, 113 Str, 113 Int Implicits: 2 {variant:1}18% Chance to Block {variant:2}20% Chance to Block 4% Chance to Block (60-80)% increased Critical Strike Chance for Spells Gain (10-20)% of Elemental Damage as Extra Chaos Damage +1% to Critical Strike Multiplier per 1% Block Chance +60% to Critical Strike Multiplier if you've dealt a Non-Critical Strike Recently 120% increased Spell Damage if you've dealt a Critical Strike Recently ]],[[ Dying Breath Coiled Staff Variant: Pre 2.6.0 Variant: Current Requires Level 23, 43 Str, 43 Int Implicits: 2 {variant:1}18% Chance to Block {variant:2}20% Chance to Block 18% increased Cast Speed 18% increased maximum Mana 18% increased Area of Effect of Aura Skills 18% increased Area of Effect of Curse Skills Nearby Enemies have 18% increased Effect of Curses on them Nearby allies gain 18% increased Damage 18% increased effect of Non-Curse Auras you Cast ]],[[ Femurs of the Saints Primordial Staff Variant: Pre 2.6.0 Variant: Current Requires Level 58, 99 Str, 99 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block +2 to Level of Socketed Minion Gems Minions Regenerate (1.5-2.5)% Life per Second 2% increased Minion Attack and Cast Speed per Skeleton you own 2% increased Minion Duration per Zombie you own (8-12)% increased Minion Damage per Spectre you own ]],[[ Fencoil Gnarled Branch Variant: Pre 2.6.0 Variant: Current Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block Socketed Gems are Supported by level 8 Trap (40-50)% increased Damage (10-20)% increased maximum Life (10-20)% increased maximum Mana ]],[[ Hegemony's Era Judgement Staff Variant: Pre 2.6.0 Variant: Current Requires Level 68, 113 Str, 113 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block 6% Chance to Block Adds (180-190) to (190-220) Physical Damage (12-16)% increased Attack Speed (20-30)% increased Critical Strike Chance +1 to Maximum Power Charges 10% chance to gain a Power Charge if you Knock an Enemy Back with Melee Damage ]],[[ Martyr of Innocence Highborn Staff Requires Level 52, 89 Str, 89 Int 18% Chance to Block (12-16)% Chance to Block Adds (350-400) to (500-600) Fire Damage Adds (130-150) to (200-250) Fire Damage to Spells Grants level 15 Vengeance Skill 100% increased Fire Damage if you have been Hit Recently Immune to Freeze and Chill while Ignited Damage Penetrates 15% of Fire Resistance if you have Blocked Recently ]],[[ Pillar of the Caged God Long Staff Variant: Pre 2.6.0 Variant: Current Requires Level 13, 27 Str, 27 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block 1% increased Area of Effect of Area Skills per 20 Intelligence 1% increased Attack Speed per 10 Dexterity 16% increased Physical Weapon Damage per 10 Strength ]],[[ Pledge of Hands Judgement Staff Variant: Pre 2.6.0 Variant: Current Requires Level 68, 113 Str, 113 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block Socketed Gems are Supported by level 30 Spell Echo (120-160)% increased Spell Damage 100% increased maximum Mana ]],[[ Realm Ender Iron Staff Variant: Pre 2.6.0 Variant: Current Requires Level 40, 35 Str, 35 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block +1 to Level of Socketed Fire Gems +1 to Level of Socketed Cold Gems +2 to Level of Socketed Elemental Gems Socketed Gems are Supported by level 5 Cold to Fire Adds (10-15) to (20-25) Fire Damage Adds (10-15) to (20-25) Cold Damage (30-50)% increased Elemental Damage ]],[[ Realmshaper Iron Staff Variant: Pre 2.6.0 Variant: Current Requires Level 18, 35 Str, 35 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block +1 to Level of Socketed Fire Gems +1 to Level of Socketed Cold Gems Socketed Gems are Supported by level 5 Cold to Fire Adds (10-15) to (20-25) Fire Damage Adds (10-15) to (20-25) Cold Damage (30-50)% increased Elemental Damage ]],[[ The Searing Touch Lathi Variant: Pre 2.6.0 Variant: {2_6}Pre 3.0.0 Variant: Current Requires Level 60, 113 Str, 113 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2,3}18% Chance to Block +2 to Level of Socketed Fire Gems {variant:1,2}(30-50)% increased Spell Damage {variant:1,2}(20-40)% increased Fire Damage {variant:3}(70–90)% increased Fire Damage 10% increased Cast Speed 70% increased Burning Damage ]],[[ The Searing Touch Long Staff Variant: Pre 2.0.0 Requires Level 60, 113 Str, 113 Int 12% Chance to Block +2 to Level of Socketed Fire Gems (30-50)% increased Spell Damage (20-40)% increased Fire Damage 10% increased Cast Speed 70% increased Burning Damage ]],[[ Sire of Shards Serpentine Staff Variant: Pre 2.6.0 Variant: Current Requires Level 49, 85 Str, 85 Int Implicits: 2 {variant:1}18% Chance to Block {variant:2}20% Chance to Block +(15-20) to All Attributes +(5-7)% to All Elemental Resistances (60-100)% increased Projectile Damage 20% increased Light Radius Socketed Gems fire 4 additional Projectiles Socketed Gems fire Projectiles in a Nova ]],[[ The Stormheart Royal Staff Variant: Pre 2.6.0 Variant: Current Requires Level 28, 51 Str, 51 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block (80-100)% increased Physical Damage Adds (25-35) to (45-60) Cold Damage Adds (1-10) to (70-90) Lightning Damage (20-35)% increased Critical Strike Chance {variant:1}You Cannot Be Shocked While Frozen {variant:2}You Cannot Be Shocked While Chilled {variant:2}50% chance to Shock Chilled Enemies ]],[[ Taryn's Shiver Maelström Staff Variant: Pre 2.0.0 Variant: Pre 2.6.0 Variant: Current Requires Level 64, 113 Str, 113 Int Implicits: 2 {variant:1,2}18% Chance to Block {variant:3}20% Chance to Block {variant:1,2}+1 to Level of Socketed Cold Gems {variant:3}+2 to Level of Socketed Cold Gems {variant:1}(40-50)% increased Spell Damage {variant:2,3}(50-60)% increased Spell Damage (40-50)% increased Cold Damage (10-20)% increased Cast Speed 8% chance to Freeze Enemies Frozen by you take 20% increased Damage ]],[[ Tremor Rod Military Staff Variant: Pre 2.6.0 Variant: Current Requires Level 45, 78 Str, 78 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block Socketed Gems are Supported by level 10 Remote Mine 35% less Mine Damage (40-60)% increased Spell Damage (15-20)% reduced Enemy Stun Threshold (40-60)% increased Mine Laying Speed Mines can be Detonated an additional time ]],[[ The Whispering Ice Vile Staff Variant: Pre 2.6.0 Variant: Current Requires Level 33, 59 Str, 59 Int Implicits: 2 {variant:1}12% Chance to Block {variant:2}18% Chance to Block +1 to Level of Socketed Support Gems Grants level 1 Icestorm Skill (8-12)% increased Cast Speed 1% increased Spell Damage per 10 Intelligence (14-18)% increased Intelligence ]],[[ Xirgil's Crank Coiled Staff Variant: Pre 2.6.0 Variant: Current Requires Level 28, 43 Str, 43 Int Implicits: 2 {variant:1}18% Chance to Block {variant:2}20% Chance to Block +1 to Level of Socketed Gems 15% Chance to Block (60-80)% increased Spell Damage +(70-100) to Maximum Energy Shield Reflects 1 to 150 Lightning Damage to Melee Attackers 20% Chance for Energy Shield Recharge to Start when you Block ]], }
mit
SatoshiNXSimudrone/sl4a-damon-clone
lua/luasocket/src/ltn12.lua
127
8177
----------------------------------------------------------------------------- -- LTN12 - Filters, sources, sinks and pumps. -- LuaSocket toolkit. -- Author: Diego Nehab -- RCS ID: $Id: ltn12.lua,v 1.31 2006/04/03 04:45:42 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- -- Declare module ----------------------------------------------------------------------------- local string = require("string") local table = require("table") local base = _G module("ltn12") filter = {} source = {} sink = {} pump = {} -- 2048 seems to be better in windows... BLOCKSIZE = 2048 _VERSION = "LTN12 1.0.1" ----------------------------------------------------------------------------- -- Filter stuff ----------------------------------------------------------------------------- -- returns a high level filter that cycles a low-level filter function filter.cycle(low, ctx, extra) base.assert(low) return function(chunk) local ret ret, ctx = low(ctx, chunk, extra) return ret end end -- chains a bunch of filters together -- (thanks to Wim Couwenberg) function filter.chain(...) local n = table.getn(arg) local top, index = 1, 1 local retry = "" return function(chunk) retry = chunk and retry while true do if index == top then chunk = arg[index](chunk) if chunk == "" or top == n then return chunk elseif chunk then index = index + 1 else top = top+1 index = top end else chunk = arg[index](chunk or "") if chunk == "" then index = index - 1 chunk = retry elseif chunk then if index == n then return chunk else index = index + 1 end else base.error("filter returned inappropriate nil") end end end end end ----------------------------------------------------------------------------- -- Source stuff ----------------------------------------------------------------------------- -- create an empty source local function empty() return nil end function source.empty() return empty end -- returns a source that just outputs an error function source.error(err) return function() return nil, err end end -- creates a file source function source.file(handle, io_err) if handle then return function() local chunk = handle:read(BLOCKSIZE) if not chunk then handle:close() end return chunk end else return source.error(io_err or "unable to open file") end end -- turns a fancy source into a simple source function source.simplify(src) base.assert(src) return function() local chunk, err_or_new = src() src = err_or_new or src if not chunk then return nil, err_or_new else return chunk end end end -- creates string source function source.string(s) if s then local i = 1 return function() local chunk = string.sub(s, i, i+BLOCKSIZE-1) i = i + BLOCKSIZE if chunk ~= "" then return chunk else return nil end end else return source.empty() end end -- creates rewindable source function source.rewind(src) base.assert(src) local t = {} return function(chunk) if not chunk then chunk = table.remove(t) if not chunk then return src() else return chunk end else table.insert(t, chunk) end end end function source.chain(src, f) base.assert(src and f) local last_in, last_out = "", "" local state = "feeding" local err return function() if not last_out then base.error('source is empty!', 2) end while true do if state == "feeding" then last_in, err = src() if err then return nil, err end last_out = f(last_in) if not last_out then if last_in then base.error('filter returned inappropriate nil') else return nil end elseif last_out ~= "" then state = "eating" if last_in then last_in = "" end return last_out end else last_out = f(last_in) if last_out == "" then if last_in == "" then state = "feeding" else base.error('filter returned ""') end elseif not last_out then if last_in then base.error('filter returned inappropriate nil') else return nil end else return last_out end end end end end -- creates a source that produces contents of several sources, one after the -- other, as if they were concatenated -- (thanks to Wim Couwenberg) function source.cat(...) local src = table.remove(arg, 1) return function() while src do local chunk, err = src() if chunk then return chunk end if err then return nil, err end src = table.remove(arg, 1) end end end ----------------------------------------------------------------------------- -- Sink stuff ----------------------------------------------------------------------------- -- creates a sink that stores into a table function sink.table(t) t = t or {} local f = function(chunk, err) if chunk then table.insert(t, chunk) end return 1 end return f, t end -- turns a fancy sink into a simple sink function sink.simplify(snk) base.assert(snk) return function(chunk, err) local ret, err_or_new = snk(chunk, err) if not ret then return nil, err_or_new end snk = err_or_new or snk return 1 end end -- creates a file sink function sink.file(handle, io_err) if handle then return function(chunk, err) if not chunk then handle:close() return 1 else return handle:write(chunk) end end else return sink.error(io_err or "unable to open file") end end -- creates a sink that discards data local function null() return 1 end function sink.null() return null end -- creates a sink that just returns an error function sink.error(err) return function() return nil, err end end -- chains a sink with a filter function sink.chain(f, snk) base.assert(f and snk) return function(chunk, err) if chunk ~= "" then local filtered = f(chunk) local done = chunk and "" while true do local ret, snkerr = snk(filtered, err) if not ret then return nil, snkerr end if filtered == done then return 1 end filtered = f(done) end else return 1 end end end ----------------------------------------------------------------------------- -- Pump stuff ----------------------------------------------------------------------------- -- pumps one chunk from the source to the sink function pump.step(src, snk) local chunk, src_err = src() local ret, snk_err = snk(chunk, src_err) if chunk and ret then return 1 else return nil, src_err or snk_err end end -- pumps all data from a source to a sink, using a step function function pump.all(src, snk, step) base.assert(src and snk) step = step or pump.step while true do local ret, err = step(src, snk) if not ret then if err then return nil, err else return 1 end end end end
apache-2.0
sebastianlis/DesignPatterns-in-Lua-Using-CoronaSDK
State/PatternCraftState/classes/SiegeTank.lua
1
2575
require "classes.constants.screen" require "classes.TankState" require "classes.SiegeState" require "classes.SpeedState" SiegeTank={} function SiegeTank:new() local this = display.newGroup() local public = this local private = {} local body = display.newRect(0, 0, 300, 100) local lastState this.messageTextField = display.newText("", 0, 0, native.systemFont, 12) this.moveTextField = display.newText("", 0, 0, native.systemFont, 12) this.attackTextField = display.newText("", 0, 0, native.systemFont, 12) this.state = nil this.tankState = nil this.siegeState = nil this.speedState = nil function private.SiegeTank() this.messageTextField.x = 0 this.messageTextField.y = -30 this.moveTextField.x = 0 this.moveTextField.y = -5 this.attackTextField.x = 0 this.attackTextField.y = 20 this:insert(body) this:insert(this.messageTextField) this:insert(this.moveTextField) this:insert(this.attackTextField) this.tankState = TankState:new(this) this.siegeState = SiegeState:new(this) this.speedState = SpeedState:new(this) this.state = this.tankState private.applyState() lastState = this.tankState.current end function public.toTankMode() this.state.toTankMode() if lastState ~= this.state.current then private.applyState() lastState = this.state.current end end function public.toSiegeMode() this.state.toSiegeMode() if lastState ~= this.state.current then private.applyState() lastState = this.state.current end end function public.toSpeedMode() this.state.toSpeedMode() if lastState ~= this.state.current then private.applyState() lastState = this.state.current end end function private.applyState() this.messageTextField.text = "Status: damage: "..this.state.damage.." canMove: "..tostring(this.state.canMove) this.moveTextField.text = "" this.attackTextField.text = "" body:setFillColor(this.state.color[1]/255, this.state.color[2]/255, this.state.color[3]/255) end function public.attack() this.state.attack() end function public.move(targetX, targetY) this.state.move(targetX, targetY) end function public:destroy() this:removeSelf() this = nil end private.SiegeTank() return this end return SiegeTank
mit
Ialong/shogun
examples/undocumented/lua_modular/evaluation_contingencytableevaluation_modular.lua
21
1809
require 'modshogun' require 'load' ground_truth = load_labels('../data/label_train_twoclass.dat') math.randomseed(17) predicted = {} for i = 1, #ground_truth do table.insert(predicted, math.random()) end parameter_list = {{ground_truth,predicted}} function evaluation_contingencytableevaluation_modular(ground_truth, predicted) ground_truth_labels = modshogun.BinaryLabels(ground_truth) predicted_labels = modshogun.BinaryLabels(predicted) base_evaluator = modshogun.ContingencyTableEvaluation() base_evaluator:evaluate(predicted_labels,ground_truth_labels) evaluator = modshogun.AccuracyMeasure() accuracy = evaluator:evaluate(predicted_labels,ground_truth_labels) evaluator = modshogun.ErrorRateMeasure() errorrate = evaluator:evaluate(predicted_labels,ground_truth_labels) evaluator = modshogun.BALMeasure() bal = evaluator:evaluate(predicted_labels,ground_truth_labels) evaluator = modshogun.WRACCMeasure() wracc = evaluator:evaluate(predicted_labels,ground_truth_labels) evaluator = modshogun.F1Measure() f1 = evaluator:evaluate(predicted_labels,ground_truth_labels) evaluator = modshogun.CrossCorrelationMeasure() crosscorrelation = evaluator:evaluate(predicted_labels,ground_truth_labels) evaluator = modshogun.RecallMeasure() recall = evaluator:evaluate(predicted_labels,ground_truth_labels) evaluator = modshogun.PrecisionMeasure() precision = evaluator:evaluate(predicted_labels,ground_truth_labels) evaluator = modshogun.SpecificityMeasure() specificity = evaluator:evaluate(predicted_labels,ground_truth_labels) return accuracy, errorrate, bal, wracc, f1, crosscorrelation, recall, precision, specificity end if debug.getinfo(3) == nill then print 'ContingencyTableEvaluation' evaluation_contingencytableevaluation_modular(unpack(parameter_list[1])) end
gpl-3.0
codyroux/lean0.1
tests/lua/sexpr2.lua
6
1108
s = sexpr(1, 2, 3) print(s) s = sexpr(1, 2, 3, nil) print(s) s = sexpr(sexpr(1, 2), sexpr(3, 4), nil) print(s) s = sexpr(mpz("100000000000000"), mpq(3)/2, sexpr(1, 2, 3, nil), nil) print(s) print(sexpr():is_nil()) print(sexpr(1):is_nil()) print(sexpr(true):is_bool()) print(sexpr(true):to_bool()) print(sexpr(false):to_bool()) check_error(function() sexpr(10):to_bool() end) print(sexpr(name("foo",1)):to_name()) check_error(function () print(sexpr(10):to_name()) end) print(sexpr(mpq(10)/3):to_mpq()) print(sexpr(mpz("10000000000000000000000000000000000")):to_mpz()) print(sexpr(10, 20, 30, 40, nil):length()) print(sexpr(10, 20, nil):head()) print(sexpr(10, 20, nil):tail()) print(sexpr(10, 20):head()) print(sexpr(10, 20):tail()) check_error(function () sexpr(10):head() end) check_error(function () sexpr(10):tail() end) check_error(function () sexpr(10):to_mpz() end) check_error(function () sexpr(10):to_mpq() end) check_error(function () sexpr(10):to_string() end) check_error(function () sexpr(10):to_bool() end) check_error(function () sexpr(10):to_double() end) print(sexpr("hello"):to_string())
apache-2.0
UnluckyNinja/PathOfBuilding
Data/2_6/ModJewel.lua
1
54290
-- This file is automatically generated, do not edit! -- Item data (c) Grinding Gear Games return { ["MaceDamageJewel"] = { type = "Prefix", affix = "Brutal", "(14-16)% increased Physical Damage with Maces", statOrderKey = "289", statOrder = { 289 }, level = 1, group = "SpecificWeaponDamage", weightKey = { "mace", "specific_weapon", "not_str", "default", }, weightVal = { 500, 0, 0, 500, }, tags = { "mace", "specific_weapon", "melee_mod", }, }, ["AxeDamageJewel"] = { type = "Prefix", affix = "Sinister", "(14-16)% increased Physical Damage with Axes", statOrderKey = "277", statOrder = { 277 }, level = 1, group = "SpecificWeaponDamage", weightKey = { "axe", "specific_weapon", "not_int", "default", }, weightVal = { 500, 0, 500, 0, }, tags = { "axe", "specific_weapon", "melee_mod", }, }, ["SwordDamageJewel"] = { type = "Prefix", affix = "Vicious", "(14-16)% increased Physical Damage with Swords", statOrderKey = "297", statOrder = { 297 }, level = 1, group = "SpecificWeaponDamage", weightKey = { "sword", "specific_weapon", "not_int", "default", }, weightVal = { 500, 0, 500, 0, }, tags = { "sword", "specific_weapon", "melee_mod", }, }, ["BowDamageJewel"] = { type = "Prefix", affix = "Fierce", "(14-16)% increased Physical Damage with Bows", statOrderKey = "292", statOrder = { 292 }, level = 1, group = "SpecificWeaponDamage", weightKey = { "one_handed_mod", "melee_mod", "dual_wielding_mod", "shield_mod", "bow", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 0, 0, 0, 500, 0, 0, 500, }, tags = { "bow", "specific_weapon", "two_handed_mod", }, }, ["ClawDamageJewel"] = { type = "Prefix", affix = "Savage", "(14-16)% increased Physical Damage with Claws", statOrderKey = "283", statOrder = { 283 }, level = 1, group = "SpecificWeaponDamage", weightKey = { "two_handed_mod", "claw", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 500, 0, 0, 500, }, tags = { "claw", "specific_weapon", "one_handed_mod", "melee_mod", }, }, ["DaggerDamageJewel"] = { type = "Prefix", affix = "Lethal", "(14-16)% increased Physical Damage with Daggers", statOrderKey = "286", statOrder = { 286 }, level = 1, group = "SpecificWeaponDamage", weightKey = { "two_handed_mod", "dagger", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 500, 0, 0, 500, }, tags = { "dagger", "specific_weapon", "one_handed_mod", "melee_mod", }, }, ["WandDamageJewel"] = { type = "Prefix", affix = "Cruel", "(14-16)% increased Physical Damage with Wands", statOrderKey = "300", statOrder = { 300 }, level = 1, group = "SpecificWeaponDamage", weightKey = { "melee_mod", "two_handed_mod", "wand", "specific_weapon", "not_int", "default", }, weightVal = { 0, 0, 500, 0, 0, 500, }, tags = { "wand", "specific_weapon", "one_handed_mod", }, }, ["StaffDamageJewel"] = { type = "Prefix", affix = "Judging", "(14-16)% increased Physical Damage with Staves", statOrderKey = "280", statOrder = { 280 }, level = 1, group = "SpecificWeaponDamage", weightKey = { "one_handed_mod", "dual_wielding_mod", "shield_mod", "staff", "specific_weapon", "not_str", "default", }, weightVal = { 0, 0, 0, 500, 0, 0, 500, }, tags = { "staff", "specific_weapon", "two_handed_mod", "melee_mod", }, }, ["OneHandedMeleeDamageJewel"] = { type = "Prefix", affix = "Soldier's", "(12-14)% increased Physical Damage with One Handed Melee Weapons", statOrderKey = "270", statOrder = { 270 }, level = 1, group = "MeleeTypeDamage", weightKey = { "two_handed_mod", "wand", "not_int", "default", }, weightVal = { 0, 0, 500, 0, }, tags = { "one_handed_mod", "melee_mod", }, }, ["TwoHandedMeleeDamageJewel"] = { type = "Prefix", affix = "Champion's", "(12-14)% increased Physical Damage with Two Handed Melee Weapons", statOrderKey = "273", statOrder = { 273 }, level = 1, group = "MeleeTypeDamage", weightKey = { "bow", "wand", "one_handed_mod", "dual_wielding_mod", "shield_mod", "not_int", "default", }, weightVal = { 0, 0, 0, 0, 0, 500, 0, }, tags = { "two_handed_mod", "melee_mod", }, }, ["DualWieldingMeleeDamageJewel"] = { type = "Prefix", affix = "Gladiator's", "(12-14)% increased Physical Weapon Damage while Dual Wielding", statOrderKey = "266", statOrder = { 266 }, level = 1, group = "MeleeTypeDamage", weightKey = { "shield_mod", "two_handed_mod", "not_int", "default", }, weightVal = { 0, 0, 500, 0, }, tags = { "dual_wielding_mod", }, }, ["UnarmedMeleeDamageJewel"] = { type = "Prefix", affix = "Brawling", "(14-16)% increased Melee Physical Damage while Unarmed", statOrderKey = "276", statOrder = { 276 }, level = 1, group = "MeleeTypeDamage", weightKey = { "not_int", "default", }, weightVal = { 0, 0, }, }, ["MeleeDamageJewel_"] = { type = "Suffix", affix = "of Combat", "(10-12)% increased Melee Damage", statOrderKey = "817", statOrder = { 817 }, level = 1, group = "DamageForm", weightKey = { "bow", "wand", "not_int", "default", }, weightVal = { 0, 0, 500, 0, }, tags = { "melee_mod", }, }, ["ProjectileDamageJewel"] = { type = "Suffix", affix = "of Archery", "(10-12)% increased Projectile Damage", statOrderKey = "830", statOrder = { 830 }, level = 1, group = "DamageForm", weightKey = { "not_dex", "default", }, weightVal = { 400, 500, }, }, ["SpellDamageJewel"] = { type = "Suffix", affix = "of Mysticism", "(10-12)% increased Spell Damage", statOrderKey = "242", statOrder = { 242 }, level = 1, group = "DamageForm", weightKey = { "not_int", "default", }, weightVal = { 0, 500, }, }, ["StaffSpellDamageJewel"] = { type = "Prefix", affix = "Wizard's", "(14-16)% increased Spell Damage while wielding a Staff", statOrderKey = "245", statOrder = { 245 }, level = 1, group = "SpellTypeDamage", weightKey = { "one_handed_mod", "staff", "specific_weapon", "shield_mod", "dual_wielding_mod", "not_int", "default", }, weightVal = { 0, 500, 0, 0, 0, 0, 500, }, tags = { "staff", "specific_weapon", "two_handed_mod", }, }, ["DualWieldingSpellDamageJewel_"] = { type = "Prefix", affix = "Sorcerer's", "(14-16)% increased Spell Damage while Dual Wielding", statOrderKey = "247", statOrder = { 247 }, level = 1, group = "SpellTypeDamage", weightKey = { "shield_mod", "two_handed_mod", "not_int", "default", }, weightVal = { 0, 0, 0, 500, }, tags = { "dual_wielding_mod", }, }, ["ShieldSpellDamageJewel"] = { type = "Prefix", affix = "Battlemage's", "(14-16)% increased Spell Damage while holding a Shield", statOrderKey = "246", statOrder = { 246 }, level = 1, group = "SpellTypeDamage", weightKey = { "two_handed_mod", "dual_wielding_mod", "bow", "staff", "not_int", "default", }, weightVal = { 0, 0, 0, 0, 0, 500, }, tags = { "shield_mod", }, }, ["TrapDamageJewel"] = { type = "Prefix", affix = "Trapping", "(14-16)% increased Trap Damage", statOrderKey = "220", statOrder = { 220 }, level = 1, group = "DamageForm", weightKey = { "not_str", "default", }, weightVal = { 500, 0, }, }, ["MineDamageJewel"] = { type = "Prefix", affix = "Sabotage", "(14-16)% increased Mine Damage", statOrderKey = "221", statOrder = { 221 }, level = 1, group = "DamageForm", weightKey = { "not_str", "default", }, weightVal = { 500, 0, }, }, ["DamageJewel"] = { type = "Suffix", affix = "of Wounding", "(8-10)% increased Damage", statOrderKey = "218", statOrder = { 218 }, level = 1, group = "DamageForm", weightKey = { "default", }, weightVal = { 350, }, }, ["MinionDamageJewel"] = { type = "Prefix", affix = "Leadership", "Minions deal (14-16)% increased Damage", statOrderKey = "809", statOrder = { 809 }, level = 1, group = "DamageForm", weightKey = { "not_int", "default", }, weightVal = { 0, 500, }, }, ["FireDamageJewel"] = { type = "Prefix", affix = "Flaming", "(14-16)% increased Fire Damage", statOrderKey = "308", statOrder = { 308 }, level = 1, group = "FireDamagePercentage", weightKey = { "not_str", "default", }, weightVal = { 400, 500, }, }, ["ColdDamageJewel"] = { type = "Prefix", affix = "Chilling", "(14-16)% increased Cold Damage", statOrderKey = "315", statOrder = { 315 }, level = 1, group = "ColdDamagePercentage", weightKey = { "not_dex", "default", }, weightVal = { 400, 500, }, }, ["LightningDamageJewel"] = { type = "Prefix", affix = "Humming", "(14-16)% increased Lightning Damage", statOrderKey = "323", statOrder = { 323 }, level = 1, group = "LightningDamagePercentage", weightKey = { "not_int", "default", }, weightVal = { 400, 500, }, }, ["PhysicalDamageJewel"] = { type = "Prefix", affix = "Sharpened", "(14-16)% increased Physical Damage", statOrderKey = "248", statOrder = { 248 }, level = 1, group = "PhysicalDamagePercent", weightKey = { "default", }, weightVal = { 500, }, }, ["DamageOverTimeJewel"] = { type = "Suffix", affix = "of Entropy", "(10-12)% increased Damage over Time", statOrderKey = "233", statOrder = { 233 }, level = 1, group = "DegenerationDamage", weightKey = { "default", }, weightVal = { 500, }, }, ["ChaosDamageJewel"] = { type = "Prefix", affix = "Chaotic", "(9-13)% increased Chaos Damage", statOrderKey = "329", statOrder = { 329 }, level = 1, group = "ChaosDamage", weightKey = { "default", }, weightVal = { 200, }, }, ["AreaDamageJewel"] = { type = "Suffix", affix = "of Blasting", "(10-12)% increased Area Damage", statOrderKey = "859", statOrder = { 859 }, level = 1, group = "AreaDamage", weightKey = { "default", }, weightVal = { 500, }, }, ["MaceAttackSpeedJewel"] = { type = "Prefix", affix = "Beating", "(6-8)% increased Attack Speed with Maces", statOrderKey = "366", statOrder = { 366 }, level = 1, group = "SpecificWeaponSpeed", weightKey = { "mace", "specific_weapon", "not_str", "default", }, weightVal = { 500, 0, 0, 500, }, tags = { "mace", "specific_weapon", "melee_mod", }, }, ["AxeAttackSpeedJewel"] = { type = "Prefix", affix = "Cleaving", "(6-8)% increased Attack Speed with Axes", statOrderKey = "362", statOrder = { 362 }, level = 1, group = "SpecificWeaponSpeed", weightKey = { "axe", "specific_weapon", "not_int", "default", }, weightVal = { 500, 0, 500, 0, }, tags = { "axe", "specific_weapon", "melee_mod", }, }, ["SwordAttackSpeedJewel"] = { type = "Prefix", affix = "Fencing", "(6-8)% increased Attack Speed with Swords", statOrderKey = "368", statOrder = { 368 }, level = 1, group = "SpecificWeaponSpeed", weightKey = { "sword", "specific_weapon", "not_int", "default", }, weightVal = { 500, 0, 500, 0, }, tags = { "sword", "specific_weapon", "melee_mod", }, }, ["BowAttackSpeedJewel"] = { type = "Prefix", affix = "Volleying", "(6-8)% increased Attack Speed with Bows", statOrderKey = "367", statOrder = { 367 }, level = 1, group = "SpecificWeaponSpeed", weightKey = { "one_handed_mod", "melee_mod", "dual_wielding_mod", "shield_mod", "bow", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 0, 0, 0, 500, 0, 0, 500, }, tags = { "bow", "specific_weapon", "two_handed_mod", }, }, ["ClawAttackSpeedJewel"] = { type = "Prefix", affix = "Ripping", "(6-8)% increased Attack Speed with Claws", statOrderKey = "364", statOrder = { 364 }, level = 1, group = "SpecificWeaponSpeed", weightKey = { "two_handed_mod", "claw", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 500, 0, 0, 500, }, tags = { "claw", "specific_weapon", "one_handed_mod", "melee_mod", }, }, ["DaggerAttackSpeedJewel"] = { type = "Prefix", affix = "Slicing", "(6-8)% increased Attack Speed with Daggers", statOrderKey = "365", statOrder = { 365 }, level = 1, group = "SpecificWeaponSpeed", weightKey = { "two_handed_mod", "dagger", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 500, 0, 0, 500, }, tags = { "dagger", "specific_weapon", "one_handed_mod", "melee_mod", }, }, ["WandAttackSpeedJewel"] = { type = "Prefix", affix = "Jinxing", "(6-8)% increased Attack Speed with Wands", statOrderKey = "369", statOrder = { 369 }, level = 1, group = "SpecificWeaponSpeed", weightKey = { "melee_mod", "two_handed_mod", "wand", "specific_weapon", "not_int", "default", }, weightVal = { 0, 0, 500, 0, 0, 500, }, tags = { "wand", "specific_weapon", "one_handed_mod", }, }, ["StaffAttackSpeedJewel"] = { type = "Prefix", affix = "Blunt", "(6-8)% increased Attack Speed with Staves", statOrderKey = "363", statOrder = { 363 }, level = 1, group = "SpecificWeaponSpeed", weightKey = { "one_handed_mod", "dual_wielding_mod", "shield_mod", "staff", "specific_weapon", "not_str", "default", }, weightVal = { 0, 0, 0, 500, 0, 0, 500, }, tags = { "staff", "specific_weapon", "two_handed_mod", "melee_mod", }, }, ["OneHandedMeleeAttackSpeedJewel"] = { type = "Prefix", affix = "Bandit's", "(4-6)% increased Attack Speed with One Handed Melee Weapons", statOrderKey = "361", statOrder = { 361 }, level = 1, group = "MeleeTypeSpeed", weightKey = { "two_handed_mod", "wand", "not_int", "default", }, weightVal = { 0, 0, 500, 0, }, tags = { "one_handed_mod", "melee_mod", }, }, ["TwoHandedMeleeAttackSpeedJewel"] = { type = "Prefix", affix = "Warrior's", "(4-6)% increased Attack Speed with Two Handed Melee Weapons", statOrderKey = "360", statOrder = { 360 }, level = 1, group = "MeleeTypeSpeed", weightKey = { "one_handed_mod", "dual_wielding_mod", "shield_mod", "bow", "not_int", "default", }, weightVal = { 0, 0, 0, 0, 500, 0, }, tags = { "two_handed_mod", "melee_mod", }, }, ["DualWieldingAttackSpeedJewel"] = { type = "Prefix", affix = "Harmonic", "(4-6)% increased Attack Speed while Dual Wielding", statOrderKey = "357", statOrder = { 357 }, level = 1, group = "MeleeTypeSpeed", weightKey = { "shield_mod", "two_handed_mod", "default", }, weightVal = { 0, 0, 500, }, tags = { "dual_wielding_mod", }, }, ["DualWieldingCastSpeedJewel"] = { type = "Prefix", affix = "Resonant", "(3-5)% increased Cast Speed while Dual Wielding", statOrderKey = "389", statOrder = { 389 }, level = 1, group = "MeleeTypeSpeed", weightKey = { "shield_mod", "two_handed_mod", "not_int", "default", }, weightVal = { 0, 0, 0, 500, }, tags = { "dual_wielding_mod", }, }, ["ShieldAttackSpeedJewel"] = { type = "Prefix", affix = "Charging", "(4-6)% increased Attack Speed while holding a Shield", statOrderKey = "359", statOrder = { 359 }, level = 1, group = "MeleeTypeSpeed", weightKey = { "two_handed_mod", "dual_wielding_mod", "not_int", "default", }, weightVal = { 0, 0, 500, 400, }, tags = { "shield_mod", }, }, ["ShieldCastSpeedJewel"] = { type = "Prefix", affix = "Warding", "(3-5)% increased Cast Speed while holding a Shield", statOrderKey = "390", statOrder = { 390 }, level = 1, group = "MeleeTypeSpeed", weightKey = { "two_handed_mod", "dual_wielding_mod", "not_int", "default", }, weightVal = { 0, 0, 0, 500, }, tags = { "shield_mod", }, }, ["StaffCastSpeedJewel"] = { type = "Prefix", affix = "Wright's", "(3-5)% increased Cast Speed while wielding a Staff", statOrderKey = "391", statOrder = { 391 }, level = 1, group = "MeleeTypeSpeed", weightKey = { "one_handed_mod", "dual_wielding_mod", "shield_mod", "staff", "specific_weapon", "not_int", "default", }, weightVal = { 0, 0, 0, 500, 0, 0, 500, }, tags = { "staff", "specific_weapon", "two_handed_mod", }, }, ["UnarmedAttackSpeedJewel"] = { type = "Prefix", affix = "Furious", "(6-8)% increased Attack Speed while Unarmed", statOrderKey = "371", statOrder = { 371 }, level = 1, group = "MeleeTypeSpeed", weightKey = { "not_int", "default", }, weightVal = { 0, 0, }, }, ["AttackSpeedJewel"] = { type = "Suffix", affix = "of Berserking", "(3-5)% increased Attack Speed", statOrderKey = "352", statOrder = { 352 }, level = 1, group = "IncreasedAttackSpeed", weightKey = { "default", }, weightVal = { 500, }, }, ["ProjectileSpeedJewel"] = { type = "Suffix", affix = "of Soaring", "(6-8)% increased Projectile Speed", statOrderKey = "648", statOrder = { 648 }, level = 1, group = "ProjectileSpeed", weightKey = { "not_dex", "default", }, weightVal = { 300, 500, }, }, ["CastSpeedJewel"] = { type = "Suffix", affix = "of Enchanting", "(2-4)% increased Cast Speed", statOrderKey = "388", statOrder = { 388 }, level = 1, group = "IncreasedCastSpeed", weightKey = { "not_int", "default", }, weightVal = { 0, 500, }, }, ["TrapThrowSpeedJewel"] = { type = "Prefix", affix = "Honed", "(6-8)% increased Trap Throwing Speed", statOrderKey = "756", statOrder = { 756 }, level = 1, group = "TrapThrowSpeed", weightKey = { "not_str", "default", }, weightVal = { 250, 0, }, }, ["MineLaySpeedJewel"] = { type = "Prefix", affix = "Arming", "(6-8)% increased Mine Laying Speed", statOrderKey = "757", statOrder = { 757 }, level = 1, group = "MineLaySpeed", weightKey = { "not_str", "default", }, weightVal = { 250, 0, }, }, ["AttackAndCastSpeedJewel"] = { type = "Suffix", affix = "of Zeal", "(2-4)% increased Attack and Cast Speed", statOrderKey = "872", statOrder = { 872 }, level = 1, group = "AttackCastSpeed", weightKey = { "default", }, weightVal = { 350, }, }, ["PhysicalDamageWhileHoldingAShield"] = { type = "Prefix", affix = "Flanking", "(12-14)% increased Melee Physical Damage while holding a Shield", statOrderKey = "821", statOrder = { 821 }, level = 1, group = "MeleeTypeDamage", weightKey = { "bow", "wand", "dual_wielding_mod", "two_handed_mod", "not_int", "default", }, weightVal = { 0, 0, 0, 0, 500, 0, }, tags = { "shield_mod", "melee_mod", }, }, ["FireGemCastSpeedJewel"] = { type = "Prefix", affix = "Pyromantic", "(3-5)% increased Cast Speed with Fire Skills", statOrderKey = "314", statOrder = { 314 }, level = 1, group = "FireCastSpeed", weightKey = { "not_int", "default", }, weightVal = { 0, 500, }, }, ["ColdGemCastSpeedJewel"] = { type = "Prefix", affix = "Cryomantic", "(3-5)% increased Cast Speed with Cold Skills", statOrderKey = "322", statOrder = { 322 }, level = 1, group = "ColdCastSpeed", weightKey = { "not_int", "default", }, weightVal = { 0, 500, }, }, ["LightningGemCastSpeedJewel_"] = { type = "Prefix", affix = "Electromantic", "(3-5)% increased Cast Speed with Lightning Skills", statOrderKey = "328", statOrder = { 328 }, level = 1, group = "LightningCastSpeed", weightKey = { "not_int", "default", }, weightVal = { 0, 500, }, }, ["ChaosGemCastSpeedJewel"] = { type = "Prefix", affix = "Withering", "(3-5)% increased Cast Speed with Chaos Skills", statOrderKey = "334", statOrder = { 334 }, level = 1, group = "ChaosCastSpeed", weightKey = { "default", }, weightVal = { 0, }, }, ["CurseCastSpeedJewel_"] = { type = "Suffix", affix = "of Blasphemy", "(5-10)% increased Cast Speed for Curses", statOrderKey = "990", statOrder = { 990 }, level = 1, group = "CurseCastSpeed", weightKey = { "default", }, weightVal = { 0, }, }, ["StrengthJewel"] = { type = "Suffix", affix = "of Strength", "+(12-16) to Strength", statOrderKey = "304", statOrder = { 304 }, level = 1, group = "Strength", weightKey = { "not_str", "default", }, weightVal = { 300, 500, }, }, ["DexterityJewel"] = { type = "Suffix", affix = "of Dexterity", "+(12-16) to Dexterity", statOrderKey = "305", statOrder = { 305 }, level = 1, group = "Dexterity", weightKey = { "not_dex", "default", }, weightVal = { 300, 500, }, }, ["IntelligenceJewel"] = { type = "Suffix", affix = "of Intelligence", "+(12-16) to Intelligence", statOrderKey = "306", statOrder = { 306 }, level = 1, group = "Intelligence", weightKey = { "not_int", "default", }, weightVal = { 300, 500, }, }, ["StrengthDexterityJewel"] = { type = "Suffix", affix = "of Athletics", "+(8-10) to Strength and Dexterity", statOrderKey = "1285", statOrder = { 1285 }, level = 1, group = "StrengthDexterity", weightKey = { "not_int", "default", }, weightVal = { 450, 250, }, }, ["StrengthIntelligenceJewel"] = { type = "Suffix", affix = "of Spirit", "+(8-10) to Strength and Intelligence", statOrderKey = "1284", statOrder = { 1284 }, level = 1, group = "StrengthIntelligence", weightKey = { "not_dex", "default", }, weightVal = { 450, 250, }, }, ["DexterityIntelligenceJewel"] = { type = "Suffix", affix = "of Cunning", "+(8-10) to Dexterity and Intelligence", statOrderKey = "1286", statOrder = { 1286 }, level = 1, group = "DexterityIntelligence", weightKey = { "not_str", "default", }, weightVal = { 450, 250, }, }, ["AllAttributesJewel"] = { type = "Suffix", affix = "of Adaption", "+(6-8) to all Attributes", statOrderKey = "307", statOrder = { 307 }, level = 1, group = "AllAttributes", weightKey = { "default", }, weightVal = { 300, }, }, ["IncreasedLifeJewel"] = { type = "Prefix", affix = "Healthy", "+(8-12) to maximum Life", statOrderKey = "483", statOrder = { 483 }, level = 1, group = "IncreasedLife", weightKey = { "default", }, weightVal = { 0, }, }, ["PercentIncreasedLifeJewel"] = { type = "Prefix", affix = "Vivid", "(5-7)% increased maximum Life", statOrderKey = "484", statOrder = { 484 }, level = 1, group = "MaximumLifeIncreasePercent", weightKey = { "not_str", "default", }, weightVal = { 350, 500, }, }, ["IncreasedManaJewel"] = { type = "Prefix", affix = "Learned", "+(8-12) to maximum Mana", statOrderKey = "489", statOrder = { 489 }, level = 1, group = "IncreasedMana", weightKey = { "default", }, weightVal = { 0, }, }, ["PercentIncreasedManaJewel"] = { type = "Prefix", affix = "Enlightened", "(6-8)% increased maximum Mana", statOrderKey = "490", statOrder = { 490 }, level = 1, group = "MaximumManaIncreasePercent", weightKey = { "not_str", "default", }, weightVal = { 500, 250, }, }, ["IncreasedManaRegenJewel"] = { type = "Prefix", affix = "Energetic", "(12-15)% increased Mana Regeneration Rate", statOrderKey = "493", statOrder = { 493 }, level = 1, group = "ManaRegeneration", weightKey = { "not_int", "default", }, weightVal = { 250, 500, }, }, ["IncreasedEnergyShieldJewel_"] = { type = "Prefix", affix = "Glowing", "+(8-12) to maximum Energy Shield", statOrderKey = "495", statOrder = { 495 }, level = 1, group = "IncreasedEnergyShield", weightKey = { "default", }, weightVal = { 0, }, }, ["EnergyShieldJewel"] = { type = "Prefix", affix = "Shimmering", "(6-8)% increased maximum Energy Shield", statOrderKey = "496", statOrder = { 496 }, level = 1, group = "EnergyShieldPercent", weightKey = { "not_int", "default", }, weightVal = { 0, 500, }, }, ["IncreasedLifeAndManaJewel"] = { type = "Prefix", affix = "Determined", "+(4-6) to maximum Life", "+(4-6) to maximum Mana", statOrderKey = "483,489", statOrder = { 483, 489 }, level = 1, group = "IncreasedLifeAndMana", weightKey = { "default", }, weightVal = { 0, }, }, ["PercentIncreasedLifeAndManaJewel"] = { type = "Prefix", affix = "Passionate", "(2-4)% increased maximum Life", "(4-6)% increased maximum Mana", statOrderKey = "484,490", statOrder = { 484, 490 }, level = 1, group = "PercentageIncreasedLifeAndMana", weightKey = { "default", }, weightVal = { 0, }, }, ["EnergyShieldAndManaJewel"] = { type = "Prefix", affix = "Wise", "(4-6)% increased maximum Mana", "(2-4)% increased maximum Energy Shield", statOrderKey = "490,496", statOrder = { 490, 496 }, level = 1, group = "IncreasedEnergyShieldAndMana", weightKey = { "default", }, weightVal = { 0, }, }, ["LifeAndEnergyShieldJewel"] = { type = "Prefix", affix = "Faithful", "(2-4)% increased maximum Life", "(2-4)% increased maximum Energy Shield", statOrderKey = "484,496", statOrder = { 484, 496 }, level = 1, group = "IncreasedLifeAndEnergyShield", weightKey = { "default", }, weightVal = { 0, }, }, ["LifeLeechPermyriadJewel"] = { type = "Prefix", affix = "Hungering", "(0.2-0.4)% of Physical Attack Damage Leeched as Life", statOrderKey = "542", statOrder = { 542 }, level = 1, group = "LifeLeech", weightKey = { "not_str", "default", }, weightVal = { 0, 500, }, }, ["ManaLeechPermyriadJewel"] = { type = "Prefix", affix = "Thirsting", "(0.2-0.4)% of Physical Attack Damage Leeched as Mana", statOrderKey = "578", statOrder = { 578 }, level = 1, group = "ManaLeech", weightKey = { "not_dex", "default", }, weightVal = { 0, 500, }, }, ["SpellLifeLeechPermyriadJewel"] = { type = "Prefix", affix = "Transfusing", "0.2% of Spell Damage Leeched as Life", statOrderKey = "555", statOrder = { 555 }, level = 1, group = "LifeLeech", weightKey = { "default", }, weightVal = { 0, }, }, ["SpellManaLeechPermyriadJewel"] = { type = "Prefix", affix = "Siphoning", "0.2% of Spell Damage Leeched as Mana", statOrderKey = "583", statOrder = { 583 }, level = 1, group = "ManaLeech", weightKey = { "default", }, weightVal = { 0, }, }, ["LifeOnHitJewel"] = { type = "Suffix", affix = "of Rejuvenation", "+(2-3) Life gained for each Enemy hit by your Attacks", statOrderKey = "601", statOrder = { 601 }, level = 1, group = "LifeGainPerTarget", weightKey = { "not_str", "default", }, weightVal = { 0, 500, }, }, ["ManaOnHitJewel"] = { type = "Suffix", affix = "of Absorption", "+(1-2) Mana gained for each Enemy hit by your Attacks", statOrderKey = "605", statOrder = { 605 }, level = 1, group = "ManaGainPerTarget", weightKey = { "not_dex", "default", }, weightVal = { 0, 500, }, }, ["EnergyShieldOnHitJewel"] = { type = "Suffix", affix = "of Focus", "+(2-3) Energy Shield gained for each Enemy hit by your Attacks", statOrderKey = "608", statOrder = { 608 }, level = 1, group = "EnergyShieldGainPerTarget", weightKey = { "not_int", "default", }, weightVal = { 0, 500, }, }, ["IncreasedArmourJewel"] = { type = "Prefix", affix = "Armoured", "(14-18)% increased Armour", statOrderKey = "467", statOrder = { 467 }, level = 1, group = "IncreasedPhysicalDamageReductionRatingPercent", weightKey = { "not_str", "default", }, weightVal = { 0, 500, }, }, ["IncreasedEvasionJewel"] = { type = "Prefix", affix = "Evasive", "(14-18)% increased Evasion Rating", statOrderKey = "475", statOrder = { 475 }, level = 1, group = "EvasionRatingPercent", weightKey = { "not_dex", "default", }, weightVal = { 0, 500, }, }, ["ArmourEvasionJewel"] = { type = "Prefix", affix = "Fighter's", "(6-12)% increased Armour", "(6-12)% increased Evasion Rating", statOrderKey = "467,475", statOrder = { 467, 475 }, level = 1, group = "ArmourEvasion", weightKey = { "default", }, weightVal = { 0, }, }, ["ArmourEnergyShieldJewel"] = { type = "Prefix", affix = "Paladin's", "(6-12)% increased Armour", "(2-4)% increased maximum Energy Shield", statOrderKey = "467,496", statOrder = { 467, 496 }, level = 1, group = "ArmourEnergyShield", weightKey = { "default", }, weightVal = { 0, }, }, ["EvasionEnergyShieldJewel"] = { type = "Prefix", affix = "Rogue's", "(6-12)% increased Evasion Rating", "(2-4)% increased maximum Energy Shield", statOrderKey = "475,496", statOrder = { 475, 496 }, level = 1, group = "EvasionEnergyShield", weightKey = { "default", }, weightVal = { 0, }, }, ["IncreasedDefensesJewel"] = { type = "Prefix", affix = "Defensive", "(4-6)% increased Global Defences", statOrderKey = "1489", statOrder = { 1489 }, level = 1, group = "AllDefences", weightKey = { "default", }, weightVal = { 0, }, }, ["ItemRarityJewel"] = { type = "Suffix", affix = "of Raiding", "(4-6)% increased Rarity of Items found", statOrderKey = "509", statOrder = { 509 }, level = 1, group = "ItemFoundRarityIncrease", weightKey = { "default", }, weightVal = { 150, }, }, ["IncreasedAccuracyJewel"] = { type = "Suffix", affix = "of Accuracy", "+(20-40) to Accuracy Rating", statOrderKey = "375", statOrder = { 375 }, level = 1, group = "IncreasedAccuracy", weightKey = { "default", }, weightVal = { 0, }, }, ["PercentIncreasedAccuracyJewel"] = { type = "Suffix", affix = "of Precision", "(10-14)% increased Accuracy Rating", statOrderKey = "376", statOrder = { 376 }, level = 1, group = "IncreasedAccuracyPercent", weightKey = { "not_dex", "default", }, weightVal = { 0, 500, }, }, ["AccuracyAndCritsJewel"] = { type = "Suffix", affix = "of Deadliness", "(6-10)% increased Accuracy Rating", "(6-10)% increased Global Critical Strike Chance", statOrderKey = "376,399", statOrder = { 376, 399 }, level = 1, group = "AccuracyAndCrits", weightKey = { "not_dex", "default", }, weightVal = { 0, 150, }, }, ["CriticalStrikeChanceJewel"] = { type = "Suffix", affix = "of Menace", "(8-12)% increased Global Critical Strike Chance", statOrderKey = "399", statOrder = { 399 }, level = 1, group = "CriticalStrikeChanceIncrease", weightKey = { "default", }, weightVal = { 250, }, }, ["CriticalStrikeMultiplierJewel"] = { type = "Suffix", affix = "of Potency", "+(9-12)% to Global Critical Strike Multiplier", statOrderKey = "427", statOrder = { 427 }, level = 1, group = "CriticalStrikeMultiplier", weightKey = { "default", }, weightVal = { 250, }, }, ["CritChanceWithMaceJewel"] = { type = "Prefix", affix = "of Striking FIX ME", "(12-16)% increased Critical Strike Chance with Maces", statOrderKey = "408", statOrder = { 408 }, level = 1, group = "SpecificWeaponCritChance", weightKey = { "mace", "specific_weapon", "not_str", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "mace", "specific_weapon", }, }, ["CritChanceWithAxeJewel"] = { type = "Prefix", affix = "of Biting FIX ME", "(12-16)% increased Critical Strike Chance with Axes", statOrderKey = "411", statOrder = { 411 }, level = 1, group = "SpecificWeaponCritChance", weightKey = { "axe", "specific_weapon", "not_int", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "axe", "specific_weapon", }, }, ["CritChanceWithSwordJewel"] = { type = "Prefix", affix = "of Stinging FIX ME", "(12-16)% increased Critical Strike Chance with Swords", statOrderKey = "407", statOrder = { 407 }, level = 1, group = "SpecificWeaponCritChance", weightKey = { "sword", "specific_weapon", "not_int", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "sword", "specific_weapon", }, }, ["CritChanceWithBowJewel"] = { type = "Prefix", affix = "of the Sniper FIX ME", "(12-16)% increased Critical Strike Chance with Bows", statOrderKey = "404", statOrder = { 404 }, level = 1, group = "SpecificWeaponCritChance", weightKey = { "bow", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "bow", "specific_weapon", "two_handed_mod", }, }, ["CritChanceWithClawJewel"] = { type = "Prefix", affix = "of the Eagle FIX ME", "(12-16)% increased Critical Strike Chance with Claws", statOrderKey = "405", statOrder = { 405 }, level = 1, group = "SpecificWeaponCritChance", weightKey = { "claw", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "claw", "specific_weapon", "one_handed_mod", }, }, ["CritChanceWithDaggerJewel"] = { type = "Prefix", affix = "of Needling FIX ME", "(12-16)% increased Critical Strike Chance with Daggers", statOrderKey = "406", statOrder = { 406 }, level = 1, group = "SpecificWeaponCritChance", weightKey = { "dagger", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "dagger", "specific_weapon", "one_handed_mod", }, }, ["CritChanceWithWandJewel"] = { type = "Prefix", affix = "of Divination FIX ME", "(12-16)% increased Critical Strike Chance with Wands", statOrderKey = "410", statOrder = { 410 }, level = 1, group = "SpecificWeaponCritChance", weightKey = { "wand", "specific_weapon", "not_int", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "wand", "specific_weapon", "one_handed_mod", }, }, ["CritChanceWithStaffJewel"] = { type = "Prefix", affix = "of Tyranny FIX ME", "(12-16)% increased Critical Strike Chance with Staves", statOrderKey = "409", statOrder = { 409 }, level = 1, group = "SpecificWeaponCritChance", weightKey = { "staff", "specific_weapon", "not_str", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "staff", "specific_weapon", "two_handed_mod", }, }, ["CritMultiplierWithMaceJewel"] = { type = "Prefix", affix = "of Crushing FIX ME", "+(8-10)% to Critical Strike Multiplier with Maces", statOrderKey = "432", statOrder = { 432 }, level = 1, group = "SpecificWeaponCritMultiplier", weightKey = { "mace", "specific_weapon", "not_str", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "mace", "specific_weapon", }, }, ["CritMultiplierWithAxeJewel"] = { type = "Prefix", affix = "of Execution FIX ME", "+(8-10)% to Critical Strike Multiplier with Axes", statOrderKey = "433", statOrder = { 433 }, level = 1, group = "SpecificWeaponCritMultiplier", weightKey = { "axe", "specific_weapon", "not_int", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "axe", "specific_weapon", }, }, ["CritMultiplierWithSwordJewel"] = { type = "Prefix", affix = "of Severing FIX ME", "+(8-10)% to Critical Strike Multiplier with Swords", statOrderKey = "435", statOrder = { 435 }, level = 1, group = "SpecificWeaponCritMultiplier", weightKey = { "sword", "specific_weapon", "not_int", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "sword", "specific_weapon", }, }, ["CritMultiplierWithBowJewel"] = { type = "Prefix", affix = "of the Hunter FIX ME", "+(8-10)% to Critical Strike Multiplier with Bows", statOrderKey = "434", statOrder = { 434 }, level = 1, group = "SpecificWeaponCritMultiplier", weightKey = { "bow", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "bow", "specific_weapon", "two_handed_mod", }, }, ["CritMultiplierWithClawJewel"] = { type = "Prefix", affix = "of the Bear FIX ME", "+(8-10)% to Critical Strike Multiplier with Claws", statOrderKey = "437", statOrder = { 437 }, level = 1, group = "SpecificWeaponCritMultiplier", weightKey = { "claw", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "claw", "specific_weapon", "one_handed_mod", }, }, ["CritMultiplierWithDaggerJewel"] = { type = "Prefix", affix = "of Assassination FIX ME", "+(8-10)% to Critical Strike Multiplier with Daggers", statOrderKey = "431", statOrder = { 431 }, level = 1, group = "SpecificWeaponCritMultiplier", weightKey = { "dagger", "specific_weapon", "not_dex", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "dagger", "specific_weapon", "one_handed_mod", }, }, ["CritMultiplierWithWandJewel_"] = { type = "Prefix", affix = "of Evocation FIX ME", "+(8-10)% to Critical Strike Multiplier with Wands", statOrderKey = "436", statOrder = { 436 }, level = 1, group = "SpecificWeaponCritMultiplier", weightKey = { "wand", "specific_weapon", "not_int", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "wand", "specific_weapon", "one_handed_mod", }, }, ["CritMultiplierWithStaffJewel"] = { type = "Prefix", affix = "of Trauma FIX ME", "+(8-10)% to Critical Strike Multiplier with Staves", statOrderKey = "438", statOrder = { 438 }, level = 1, group = "SpecificWeaponCritMultiplier", weightKey = { "staff", "specific_weapon", "not_str", "default", }, weightVal = { 0, 0, 0, 0, }, tags = { "staff", "specific_weapon", "two_handed_mod", }, }, ["OneHandedCritChanceJewel"] = { type = "Prefix", affix = "Harming", "(14-18)% increased Critical Strike Chance with One Handed Melee Weapons", statOrderKey = "417", statOrder = { 417 }, level = 1, group = "MeleeTypeCritChance", weightKey = { "wand", "two_handed_mod", "not_int", "default", }, weightVal = { 0, 0, 250, 0, }, tags = { "one_handed_mod", "melee_mod", }, }, ["TwoHandedCritChanceJewel"] = { type = "Prefix", affix = "Sundering", "(14-18)% increased Critical Strike Chance with Two Handed Melee Weapons", statOrderKey = "415", statOrder = { 415 }, level = 1, group = "MeleeTypeCritChance", weightKey = { "bow", "one_handed_mod", "shield_mod", "dual_wielding_mod", "not_int", "default", }, weightVal = { 0, 0, 0, 0, 250, 0, }, tags = { "two_handed_mod", "melee_mod", }, }, ["DualWieldingCritChanceJewel"] = { type = "Prefix", affix = "Technical", "(14-18)% increased Weapon Critical Strike Chance while Dual Wielding", statOrderKey = "419", statOrder = { 419 }, level = 1, group = "MeleeTypeCritChance", weightKey = { "shield_mod", "two_handed_mod", "not_int", "default", }, weightVal = { 0, 0, 250, 0, }, tags = { "dual_wielding_mod", }, }, ["ShieldCritChanceJewel"] = { type = "Prefix", affix = "", "(10-14)% increased Critical Strike Chance while holding a Shield", statOrderKey = "412", statOrder = { 412 }, level = 1, group = "MeleeTypeCritChance", weightKey = { "default", }, weightVal = { 0, }, tags = { "shield_mod", }, }, ["MeleeCritChanceJewel"] = { type = "Suffix", affix = "of Weight", "(10-14)% increased Melee Critical Strike Chance", statOrderKey = "418", statOrder = { 418 }, level = 1, group = "FormCritChance", weightKey = { "bow", "wand", "not_int", "default", }, weightVal = { 0, 0, 250, 0, }, tags = { "melee_mod", }, }, ["SpellCritChanceJewel"] = { type = "Suffix", affix = "of Annihilation", "(10-14)% increased Critical Strike Chance for Spells", statOrderKey = "398", statOrder = { 398 }, level = 1, group = "FormCritChance", weightKey = { "not_int", "default", }, weightVal = { 0, 250, }, }, ["TrapCritChanceJewel_"] = { type = "Prefix", affix = "Inescapable", "(12-16)% increased Critical Strike Chance with Traps", statOrderKey = "413", statOrder = { 413 }, level = 1, group = "FormCritChance", weightKey = { "default", }, weightVal = { 0, }, }, ["MineCritChanceJewel"] = { type = "Prefix", affix = "Crippling", "(12-16)% increased Critical Strike Chance with Mines", statOrderKey = "414", statOrder = { 414 }, level = 1, group = "FormCritChance", weightKey = { "default", }, weightVal = { 0, }, }, ["FireCritChanceJewel"] = { type = "Prefix", affix = "Incinerating", "(14-18)% increased Critical Strike Chance with Fire Skills", statOrderKey = "420", statOrder = { 420 }, level = 1, group = "FireCritChance", weightKey = { "not_str", "default", }, weightVal = { 200, 250, }, }, ["ColdCritChanceJewel"] = { type = "Prefix", affix = "Avalanching", "(14-18)% increased Critical Strike Chance with Cold Skills", statOrderKey = "422", statOrder = { 422 }, level = 1, group = "ColdCritChance", weightKey = { "not_dex", "default", }, weightVal = { 200, 250, }, }, ["LightningCritChanceJewel"] = { type = "Prefix", affix = "Thundering", "(14-18)% increased Critical Strike Chance with Lightning Skills", statOrderKey = "421", statOrder = { 421 }, level = 1, group = "LightningCritChance", weightKey = { "not_int", "default", }, weightVal = { 200, 250, }, }, ["ElementalCritChanceJewel"] = { type = "Suffix", affix = "of the Apocalypse", "(10-14)% increased Critical Strike Chance with Elemental Skills", statOrderKey = "423", statOrder = { 423 }, level = 1, group = "ElementalCritChance", weightKey = { "default", }, weightVal = { 100, }, }, ["ChaosCritChanceJewel"] = { type = "Prefix", affix = "Obliterating", "(12-16)% increased Critical Strike Chance with Chaos Skills", statOrderKey = "424", statOrder = { 424 }, level = 1, group = "ChaosCritChance", weightKey = { "default", }, weightVal = { 0, }, }, ["OneHandCritMultiplierJewel_"] = { type = "Prefix", affix = "Piercing", "+(15-18)% to Critical Strike Multiplier with One Handed Melee Weapons", statOrderKey = "439", statOrder = { 439 }, level = 1, group = "MeleeTypeCritMultiplier", weightKey = { "wand", "two_handed_mod", "not_int", "default", }, weightVal = { 0, 0, 250, 0, }, tags = { "melee_mod", "one_handed_mod", }, }, ["TwoHandCritMultiplierJewel"] = { type = "Prefix", affix = "Rupturing", "+(15-18)% to Critical Strike Multiplier with Two Handed Melee Weapons", statOrderKey = "416", statOrder = { 416 }, level = 1, group = "MeleeTypeCritMultiplier", weightKey = { "bow", "one_handed_mod", "shield_mod", "dual_wielding_mod", "not_int", "default", }, weightVal = { 0, 0, 0, 0, 250, 0, }, tags = { "two_handed_mod", "melee_mod", }, }, ["DualWieldingCritMultiplierJewel"] = { type = "Prefix", affix = "Puncturing", "+(15-18)% to Critical Strike Multiplier while Dual Wielding", statOrderKey = "2818", statOrder = { 2818 }, level = 1, group = "MeleeTypeCritMultiplier", weightKey = { "shield_mod", "two_handed_mod", "not_int", "default", }, weightVal = { 0, 0, 250, 0, }, tags = { "dual_wielding_mod", }, }, ["ShieldCritMultiplierJewel"] = { type = "Prefix", affix = "", "+(6-8)% to Melee Critical Strike Multiplier while holding a Shield", statOrderKey = "442", statOrder = { 442 }, level = 1, group = "MeleeTypeCritMultiplier", weightKey = { "default", }, weightVal = { 0, }, tags = { "shield_mod", }, }, ["MeleeCritMultiplier"] = { type = "Suffix", affix = "of Demolishing", "+(12-15)% to Melee Critical Strike Multiplier", statOrderKey = "440", statOrder = { 440 }, level = 1, group = "FormCritMultiplier", weightKey = { "bow", "wand", "not_int", "default", }, weightVal = { 0, 0, 250, 0, }, tags = { "melee_mod", }, }, ["SpellCritMultiplier"] = { type = "Suffix", affix = "of Unmaking", "+(12-15)% to Critical Strike Multiplier for Spells", statOrderKey = "430", statOrder = { 430 }, level = 1, group = "FormCritMultiplier", weightKey = { "not_int", "default", }, weightVal = { 0, 250, }, }, ["TrapCritMultiplier"] = { type = "Prefix", affix = "Debilitating", "+(8-10)% to Critical Strike Multiplier with Traps", statOrderKey = "443", statOrder = { 443 }, level = 1, group = "FormCritMultiplier", weightKey = { "default", }, weightVal = { 0, }, }, ["MineCritMultiplier"] = { type = "Prefix", affix = "Incapacitating", "+(8-10)% to Critical Strike Multiplier with Mines", statOrderKey = "444", statOrder = { 444 }, level = 1, group = "FormCritMultiplier", weightKey = { "default", }, weightVal = { 0, }, }, ["FireCritMultiplier"] = { type = "Prefix", affix = "Infernal", "+(15-18)% to Critical Strike Multiplier with Fire Skills", statOrderKey = "445", statOrder = { 445 }, level = 1, group = "FireCritMultiplier", weightKey = { "not_str", "default", }, weightVal = { 200, 250, }, }, ["ColdCritMultiplier"] = { type = "Prefix", affix = "Arctic", "+(15-18)% to Critical Strike Multiplier with Cold Skills", statOrderKey = "447", statOrder = { 447 }, level = 1, group = "ColdCritMultiplier", weightKey = { "not_dex", "default", }, weightVal = { 200, 250, }, }, ["LightningCritMultiplier"] = { type = "Prefix", affix = "Surging", "+(15-18)% to Critical Strike Multiplier with Lightning Skills", statOrderKey = "446", statOrder = { 446 }, level = 1, group = "LightningCritMultiplier", weightKey = { "not_int", "default", }, weightVal = { 200, 250, }, }, ["ElementalCritMultiplier"] = { type = "Suffix", affix = "of the Elements", "+(12-15)% to Critical Strike Multiplier with Elemental Skills", statOrderKey = "448", statOrder = { 448 }, level = 1, group = "ElementalCritMultiplier", weightKey = { "default", }, weightVal = { 100, }, }, ["ChaosCritMultiplier"] = { type = "Prefix", affix = "", "+(8-10)% to Critical Strike Multiplier with Chaos Skills", statOrderKey = "449", statOrder = { 449 }, level = 1, group = "ChaosCritMultiplier", weightKey = { "default", }, weightVal = { 0, }, }, ["FireResistanceJewel"] = { type = "Suffix", affix = "of the Dragon", "+(12-15)% to Fire Resistance", statOrderKey = "525", statOrder = { 525 }, level = 1, group = "FireResistance", weightKey = { "not_str", "default", }, weightVal = { 300, 500, }, }, ["ColdResistanceJewel"] = { type = "Suffix", affix = "of the Beast", "+(12-15)% to Cold Resistance", statOrderKey = "529", statOrder = { 529 }, level = 1, group = "ColdResistance", weightKey = { "not_dex", "default", }, weightVal = { 300, 500, }, }, ["LightningResistanceJewel"] = { type = "Suffix", affix = "of Grounding", "+(12-15)% to Lightning Resistance", statOrderKey = "532", statOrder = { 532 }, level = 1, group = "LightningResistance", weightKey = { "not_int", "default", }, weightVal = { 300, 500, }, }, ["FireColdResistanceJewel"] = { type = "Suffix", affix = "of the Hearth", "+(10-12)% to Fire and Cold Resistances", statOrderKey = "1452", statOrder = { 1452 }, level = 1, group = "FireAndColdResistance", weightKey = { "not_int", "default", }, weightVal = { 450, 250, }, }, ["FireLightningResistanceJewel"] = { type = "Suffix", affix = "of Insulation", "+(10-12)% to Fire and Lightning Resistances", statOrderKey = "1453", statOrder = { 1453 }, level = 1, group = "FireAndLightningResistance", weightKey = { "not_dex", "default", }, weightVal = { 450, 250, }, }, ["ColdLightningResistanceJewel"] = { type = "Suffix", affix = "of Shelter", "+(10-12)% to Cold and Lightning Resistances", statOrderKey = "1454", statOrder = { 1454 }, level = 1, group = "ColdAndLightningResistance", weightKey = { "not_str", "default", }, weightVal = { 450, 250, }, }, ["AllResistancesJewel"] = { type = "Suffix", affix = "of Resistance", "+(8-10)% to all Elemental Resistances", statOrderKey = "520", statOrder = { 520 }, level = 1, group = "AllResistances", weightKey = { "default", }, weightVal = { 300, }, }, ["ChaosResistanceJewel"] = { type = "Suffix", affix = "of Order", "+(7-13)% to Chaos Resistance", statOrderKey = "535", statOrder = { 535 }, level = 1, group = "ChaosResistance", weightKey = { "default", }, weightVal = { 100, }, }, ["StunDurationJewel"] = { type = "Suffix", affix = "of Stunning", "(10-14)% increased Stun Duration on Enemies", statOrderKey = "697", statOrder = { 697 }, level = 1, group = "StunDurationIncreasePercent", weightKey = { "not_str", "default", }, weightVal = { 200, 400, }, }, ["StunRecoveryJewel"] = { type = "Suffix", affix = "of Recovery", "(10-14)% increased Stun and Block Recovery", statOrderKey = "728", statOrder = { 728 }, level = 1, group = "StunRecovery", weightKey = { "not_str", "default", }, weightVal = { 200, 400, }, }, ["ManaCostReductionJewel"] = { type = "Suffix", affix = "of Efficiency", "(3-5)% reduced Mana Cost of Skills", statOrderKey = "715", statOrder = { 715 }, level = 1, group = "ManaCostReduction", weightKey = { "default", }, weightVal = { 500, }, }, ["AuraRadiusJewel"] = { type = "Suffix", affix = "Hero's FIX ME", "(10-15)% increased Area of Effect of Aura Skills", statOrderKey = "993", statOrder = { 993 }, level = 1, group = "AuraIncreasedIncreasedAreaOfEffect", weightKey = { "default", }, weightVal = { 0, }, }, ["CurseRadiusJewel"] = { type = "Suffix", affix = "Hexing FIX ME", "(8-10)% increased Area of Effect of Curse Skills", statOrderKey = "994", statOrder = { 994 }, level = 1, group = "CurseAreaOfEffect", weightKey = { "default", }, weightVal = { 0, }, }, ["AvoidIgniteJewel"] = { type = "Suffix", affix = "Dousing FIX ME", "(6-8)% chance to Avoid being Ignited", statOrderKey = "684", statOrder = { 684 }, level = 1, group = "AvoidIgnite", weightKey = { "default", }, weightVal = { 0, }, }, ["AvoidShockJewel"] = { type = "Suffix", affix = "Insulating FIX ME", "(6-8)% chance to Avoid being Shocked", statOrderKey = "686", statOrder = { 686 }, level = 1, group = "ReducedShockChance", weightKey = { "default", }, weightVal = { 0, }, }, ["AvoidFreezeJewel"] = { type = "Suffix", affix = "Thawing FIX ME", "(6-8)% chance to Avoid being Frozen", statOrderKey = "683", statOrder = { 683 }, level = 1, group = "AvoidFreeze", weightKey = { "default", }, weightVal = { 0, }, }, ["AvoidChillJewel"] = { type = "Suffix", affix = "Heating FIX ME", "(6-8)% chance to Avoid being Chilled", statOrderKey = "682", statOrder = { 682 }, level = 1, group = "AvoidChill", weightKey = { "default", }, weightVal = { 0, }, }, ["AvoidStunJewel"] = { type = "Suffix", affix = "FIX ME", "(6-8)% chance to Avoid being Stunned", statOrderKey = "687", statOrder = { 687 }, level = 1, group = "AvoidStun", weightKey = { "default", }, weightVal = { 0, }, }, ["ChanceToFreezeJewel"] = { type = "Suffix", affix = "FIX ME", "(2-3)% chance to Freeze", statOrderKey = "854", statOrder = { 854 }, level = 1, group = "ChanceToFreeze", weightKey = { "default", }, weightVal = { 0, }, }, ["ChanceToIgniteJewel_"] = { type = "Suffix", affix = "FIX ME", "(2-3)% chance to Ignite", statOrderKey = "857", statOrder = { 857 }, level = 1, group = "ChanceToIgnite", weightKey = { "default", }, weightVal = { 0, }, }, ["ChanceToShockJewel"] = { type = "Suffix", affix = "FIX ME", "(2-3)% chance to Shock", statOrderKey = "858", statOrder = { 858 }, level = 1, group = "ChanceToShock", weightKey = { "default", }, weightVal = { 0, }, }, ["EnduranceChargeDurationJewel"] = { type = "Suffix", affix = "of Endurance", "(10-14)% increased Endurance Charge Duration", statOrderKey = "898", statOrder = { 898 }, level = 1, group = "EnduranceChargeDuration", weightKey = { "not_str", "default", }, weightVal = { 0, 0, }, }, ["FrenzyChargeDurationJewel"] = { type = "Suffix", affix = "of Frenzy", "(10-14)% increased Frenzy Charge Duration", statOrderKey = "900", statOrder = { 900 }, level = 1, group = "FrenzyChargeDuration", weightKey = { "not_dex", "default", }, weightVal = { 0, 0, }, }, ["PowerChargeDurationJewel_"] = { type = "Suffix", affix = "of Power", "(10-14)% increased Power Charge Duration", statOrderKey = "909", statOrder = { 909 }, level = 1, group = "IncreasedPowerChargeDuration", weightKey = { "not_int", "default", }, weightVal = { 0, 0, }, }, ["KnockbackChanceJewel_"] = { type = "Suffix", affix = "of Fending", "(4-6)% chance to Knock Enemies Back on hit", statOrderKey = "829", statOrder = { 829 }, level = 1, group = "Knockback", weightKey = { "default", }, weightVal = { 250, }, }, ["BlockDualWieldingJewel"] = { type = "Prefix", affix = "Parrying", "1% additional Block Chance while Dual Wielding", statOrderKey = "210", statOrder = { 210 }, level = 1, group = "FormBlock", weightKey = { "staff", "two_handed_mod", "shield_mod", "default", }, weightVal = { 0, 0, 0, 350, }, tags = { "dual_wielding_mod", }, }, ["BlockShieldJewel"] = { type = "Prefix", affix = "Shielding", "+1% Chance to Block with Shields", statOrderKey = "203", statOrder = { 203 }, level = 1, group = "FormBlock", weightKey = { "two_handed_mod", "dual_wielding_mod", "default", }, weightVal = { 0, 0, 350, }, tags = { "shield_mod", }, }, ["BlockStaffJewel"] = { type = "Prefix", affix = "Deflecting", "1% additional Chance to Block with Staves", statOrderKey = "208", statOrder = { 208 }, level = 1, group = "FormBlock", weightKey = { "one_handed_mod", "staff", "specific_weapon", "shield_mod", "dual_wielding_mod", "not_dex", "default", }, weightVal = { 0, 350, 0, 0, 0, 350, 0, }, tags = { "staff", "specific_weapon", "two_handed_mod", }, }, ["DualWieldingSpellBlockForJewel"] = { type = "Prefix", affix = "Dissipating", "1% additional Chance to Block Spells while Dual Wielding", statOrderKey = "205", statOrder = { 205 }, level = 1, group = "FormSpellBlock", weightKey = { "two_handed_mod", "shield_mod", "default", }, weightVal = { 0, 0, 350, }, tags = { "dual_wielding_mod", }, }, ["ShieldSpellBlockJewel"] = { type = "Prefix", affix = "Thwarting", "1% additional Chance to Block Spells with Shields", statOrderKey = "204", statOrder = { 204 }, level = 1, group = "FormSpellBlock", weightKey = { "two_handed_mod", "dual_wielding_mod", "default", }, weightVal = { 0, 0, 350, }, tags = { "shield_mod", }, }, ["StaffSpellBlockJewel"] = { type = "Prefix", affix = "Halting", "1% additional Chance to Block Spells with Staves", statOrderKey = "206", statOrder = { 206 }, level = 1, group = "FormSpellBlock", weightKey = { "one_handed_mod", "staff", "specific_weapon", "shield_mod", "dual_wielding_mod", "not_dex", "default", }, weightVal = { 0, 350, 0, 0, 0, 350, 0, }, tags = { "staff", "specific_weapon", "two_handed_mod", }, }, ["FreezeDurationJewel"] = { type = "Suffix", affix = "of the Glacier", "(12-16)% increased Freeze Duration on Enemies", statOrderKey = "693", statOrder = { 693 }, level = 1, group = "FreezeDuration", weightKey = { "default", }, weightVal = { 0, }, }, ["ShockDurationJewel"] = { type = "Suffix", affix = "of the Storm", "(12-16)% increased Shock Duration on Enemies", statOrderKey = "692", statOrder = { 692 }, level = 1, group = "ShockDuration", weightKey = { "default", }, weightVal = { 0, }, }, ["IgniteDurationJewel"] = { type = "Suffix", affix = "of Immolation", "(3-5)% increased Ignite Duration on Enemies", statOrderKey = "694", statOrder = { 694 }, level = 1, group = "BurnDuration", weightKey = { "default", }, weightVal = { 0, }, }, ["FreezeChanceAndDurationJewel"] = { type = "Suffix", affix = "of Freezing", "(12-16)% increased Freeze Duration on Enemies", "(2-3)% chance to Freeze", statOrderKey = "693,854", statOrder = { 693, 854 }, level = 1, group = "AilmentChanceAndDuration", weightKey = { "not_dex", "default", }, weightVal = { 250, 350, }, }, ["ShockChanceAndDurationJewel"] = { type = "Suffix", affix = "of Shocking", "(12-16)% increased Shock Duration on Enemies", "(2-3)% chance to Shock", statOrderKey = "692,858", statOrder = { 692, 858 }, level = 1, group = "AilmentChanceAndDuration", weightKey = { "not_int", "default", }, weightVal = { 250, 350, }, }, ["IgniteChanceAndDurationJewel"] = { type = "Suffix", affix = "of Burning", "(3-5)% increased Ignite Duration on Enemies", "(2-3)% chance to Ignite", statOrderKey = "694,857", statOrder = { 694, 857 }, level = 1, group = "AilmentChanceAndDuration", weightKey = { "not_str", "default", }, weightVal = { 250, 350, }, }, ["EnergyShieldDelayJewel"] = { type = "Prefix", affix = "Serene", "(4-6)% faster start of Energy Shield Recharge", statOrderKey = "501", statOrder = { 501 }, level = 1, group = "EnergyShieldDelay", weightKey = { "not_int", "default", }, weightVal = { 0, 500, }, }, ["EnergyShieldRateJewel"] = { type = "Prefix", affix = "Fevered", "(6-8)% increased Energy Shield Recharge Rate", statOrderKey = "500", statOrder = { 500 }, level = 1, group = "EnergyShieldRegeneration", weightKey = { "not_int", "default", }, weightVal = { 0, 500, }, }, ["MinionBlockJewel"] = { type = "Suffix", affix = "of the Wall", "Minions have (2-4)% Chance to Block", statOrderKey = "1539", statOrder = { 1539 }, level = 1, group = "MinionBlockChance", weightKey = { "not_int", "default", }, weightVal = { 0, 350, }, }, ["MinionLifeJewel"] = { type = "Prefix", affix = "Master's", "Minions have (8-12)% increased maximum Life", statOrderKey = "619", statOrder = { 619 }, level = 1, group = "MinionLife", weightKey = { "not_int", "default", }, weightVal = { 0, 350, }, }, ["MinionElementalResistancesJewel"] = { type = "Suffix", affix = "of Resilience", "Minions have +(6-10)% to all Elemental Resistances", statOrderKey = "1547", statOrder = { 1547 }, level = 1, group = "MinionElementalResistances", weightKey = { "not_int", "default", }, weightVal = { 0, 350, }, }, ["TotemDamageJewel"] = { type = "Prefix", affix = "Shaman's", "(12-16)% increased Totem Damage", statOrderKey = "219", statOrder = { 219 }, level = 1, group = "TotemDamage", weightKey = { "not_str", "default", }, weightVal = { 250, 350, }, }, ["TotemLifeJewel"] = { type = "Prefix", affix = "Carved", "(8-12)% increased Totem Life", statOrderKey = "627", statOrder = { 627 }, level = 1, group = "IncreasedTotemLife", weightKey = { "not_str", "default", }, weightVal = { 250, 350, }, }, ["TotemElementalResistancesJewel"] = { type = "Suffix", affix = "of Runes", "Totems gain +(6-10)% to all Elemental Resistances", statOrderKey = "1443", statOrder = { 1443 }, level = 1, group = "TotemElementalResistances", weightKey = { "not_str", "default", }, weightVal = { 250, 350, }, }, }
mit
spoconnor/ElixirMessagingServer
EclipseWorkspace/LuaClient/runtime/linux/Resources/DrawPrimitives.lua
57
12038
local dp_initialized = false local dp_shader = nil local dp_colorLocation = -1 local dp_color = { 1.0, 1.0, 1.0, 1.0 } local dp_pointSizeLocation = -1 local dp_pointSize = 1.0 local SHADER_NAME_POSITION_U_COLOR = "ShaderPosition_uColor" local targetPlatform = CCApplication:getInstance():getTargetPlatform() local function lazy_init() if not dp_initialized then dp_shader = CCShaderCache:getInstance():getProgram(SHADER_NAME_POSITION_U_COLOR) --dp_shader:retain() if nil ~= dp_shader then dp_colorLocation = gl.getUniformLocation( dp_shader:getProgram(), "u_color") dp_pointSizeLocation = gl.getUniformLocation( dp_shader:getProgram(), "u_pointSize") dp_Initialized = true end end if nil == dp_shader then print("Error:dp_shader is nil!") return false end return true end local function setDrawProperty() gl.glEnableVertexAttribs( CCConstants.VERTEX_ATTRIB_FLAG_POSITION ) dp_shader:use() dp_shader:setUniformsForBuiltins() dp_shader:setUniformLocationWith4fv(dp_colorLocation, dp_color, 1) end function ccDrawInit() lazy_init() end function ccDrawFree() dp_initialized = false end function ccDrawColor4f(r,g,b,a) dp_color[1] = r dp_color[2] = g dp_color[3] = b dp_color[4] = a end function ccPointSize(pointSize) dp_pointSize = pointSize * CCDirector:getInstance():getContentScaleFactor() end function ccDrawColor4B(r,g,b,a) dp_color[1] = r / 255.0 dp_color[2] = g / 255.0 dp_color[3] = b / 255.0 dp_color[4] = a / 255.0 end function ccDrawPoint(point) if not lazy_init() then return end local vertexBuffer = { } local function initBuffer() vertexBuffer.buffer_id = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer.buffer_id) local vertices = { point.x,point.y} gl.bufferData(gl.ARRAY_BUFFER,2,vertices,gl.STATIC_DRAW) gl.bindBuffer(gl.ARRAY_BUFFER, 0) end initBuffer() setDrawProperty() dp_shader:setUniformLocationWith1f(dp_pointSizeLocation, dp_pointSize) gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer.buffer_id) gl.vertexAttribPointer(CCConstants.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0) gl.drawArrays(gl.POINTS,0,1) gl.bindBuffer(gl.ARRAY_BUFFER,0) end function ccDrawPoints(points,numOfPoint) if not lazy_init() then return end local vertexBuffer = {} local i = 1 local function initBuffer() vertexBuffer.buffer_id = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer.buffer_id) local vertices = {} for i = 1, numOfPoint do vertices[2 * i - 1] = points[i].x vertices[2 * i] = points[i].y end gl.bufferData(gl.ARRAY_BUFFER, numOfPoint * 2, vertices, gl.STATIC_DRAW) gl.bindBuffer(gl.ARRAY_BUFFER, 0) end initBuffer() setDrawProperty() dp_shader:setUniformLocationWith1f(dp_pointSizeLocation, dp_pointSize) gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer.buffer_id) gl.vertexAttribPointer(CCConstants.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0) gl.drawArrays(gl.POINTS,0,numOfPoint) gl.bindBuffer(gl.ARRAY_BUFFER,0) end function ccDrawLine(origin,destination) if not lazy_init() then return end local vertexBuffer = {} local function initBuffer() vertexBuffer.buffer_id = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer.buffer_id) local vertices = { origin.x, origin.y, destination.x, destination.y} gl.bufferData(gl.ARRAY_BUFFER,4,vertices,gl.STATIC_DRAW) gl.bindBuffer(gl.ARRAY_BUFFER, 0) end initBuffer() setDrawProperty() gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer.buffer_id) gl.vertexAttribPointer(CCConstants.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0) gl.drawArrays(gl.LINES ,0,2) gl.bindBuffer(gl.ARRAY_BUFFER,0) end function ccDrawPoly(points,numOfPoints,closePolygon) if not lazy_init() then return end local vertexBuffer = {} local i = 1 local function initBuffer() vertexBuffer.buffer_id = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer.buffer_id) local vertices = {} for i = 1, numOfPoints do vertices[2 * i - 1] = points[i].x vertices[2 * i] = points[i].y end gl.bufferData(gl.ARRAY_BUFFER, numOfPoints * 2, vertices, gl.STATIC_DRAW) gl.bindBuffer(gl.ARRAY_BUFFER, 0) end initBuffer() setDrawProperty() gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer.buffer_id) gl.vertexAttribPointer(CCConstants.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0) if closePolygon then gl.drawArrays(gl.LINE_LOOP , 0, numOfPoints) else gl.drawArrays(gl.LINE_STRIP, 0, numOfPoints) end gl.bindBuffer(gl.ARRAY_BUFFER,0) end function ccDrawSolidPoly(points,numOfPoints,color) if not lazy_init() then return end local vertexBuffer = {} local i = 1 local function initBuffer() vertexBuffer.buffer_id = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer.buffer_id) local vertices = {} for i = 1, numOfPoints do vertices[2 * i - 1] = points[i].x vertices[2 * i] = points[i].y end gl.bufferData(gl.ARRAY_BUFFER, numOfPoints * 2, vertices, gl.STATIC_DRAW) gl.bindBuffer(gl.ARRAY_BUFFER, 0) end initBuffer() gl.glEnableVertexAttribs( CCConstants.VERTEX_ATTRIB_FLAG_POSITION ) dp_shader:use() dp_shader:setUniformsForBuiltins() dp_shader:setUniformLocationWith4fv(dp_colorLocation, color, 1) gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer.buffer_id) gl.vertexAttribPointer(CCConstants.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0) gl.drawArrays(gl.TRIANGLE_FAN , 0, numOfPoints) gl.bindBuffer(gl.ARRAY_BUFFER,0) end function ccDrawRect(origin,destination) ccDrawLine(CCPoint:__call(origin.x, origin.y), CCPoint:__call(destination.x, origin.y)) ccDrawLine(CCPoint:__call(destination.x, origin.y), CCPoint:__call(destination.x, destination.y)) ccDrawLine(CCPoint:__call(destination.x, destination.y), CCPoint:__call(origin.x, destination.y)) ccDrawLine(CCPoint:__call(origin.x, destination.y), CCPoint:__call(origin.x, origin.y)) end function ccDrawSolidRect( origin,destination,color ) local vertices = { origin, CCPoint:__call(destination.x, origin.y) , destination, CCPoint:__call(origin.x, destination.y) } ccDrawSolidPoly(vertices,4,color) end function ccDrawCircleScale( center, radius, angle, segments,drawLineToCenter,scaleX,scaleY) if not lazy_init() then return end local additionalSegment = 1 if drawLineToCenter then additionalSegment = additionalSegment + 1 end local vertexBuffer = { } local function initBuffer() local coef = 2.0 * math.pi / segments local i = 1 local vertices = {} vertexBuffer.buffer_id = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer.buffer_id) for i = 1, segments + 1 do local rads = (i - 1) * coef local j = radius * math.cos(rads + angle) * scaleX + center.x local k = radius * math.sin(rads + angle) * scaleY + center.y vertices[i * 2 - 1] = j vertices[i * 2] = k end vertices[(segments + 2) * 2 - 1] = center.x vertices[(segments + 2) * 2] = center.y gl.bufferData(gl.ARRAY_BUFFER, (segments + 2) * 2, vertices, gl.STATIC_DRAW) gl.bindBuffer(gl.ARRAY_BUFFER, 0) end initBuffer() setDrawProperty() gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer.buffer_id) gl.vertexAttribPointer(CCConstants.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0) gl.drawArrays(gl.LINE_STRIP , 0, segments + additionalSegment) gl.bindBuffer(gl.ARRAY_BUFFER,0) end function ccDrawCircle(center, radius, angle, segments, drawLineToCenter) ccDrawCircleScale(center, radius, angle, segments, drawLineToCenter, 1.0, 1.0) end function ccDrawSolidCircle(center, radius, angle, segments,scaleX,scaleY) if not lazy_init() then return end local vertexBuffer = { } local function initBuffer() local coef = 2.0 * math.pi / segments local i = 1 local vertices = {} vertexBuffer.buffer_id = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer.buffer_id) for i = 1, segments + 1 do local rads = (i - 1) * coef local j = radius * math.cos(rads + angle) * scaleX + center.x local k = radius * math.sin(rads + angle) * scaleY + center.y vertices[i * 2 - 1] = j vertices[i * 2] = k end vertices[(segments + 2) * 2 - 1] = center.x vertices[(segments + 2) * 2] = center.y gl.bufferData(gl.ARRAY_BUFFER, (segments + 2) * 2, vertices, gl.STATIC_DRAW) gl.bindBuffer(gl.ARRAY_BUFFER, 0) end initBuffer() setDrawProperty() gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer.buffer_id) gl.vertexAttribPointer(CCConstants.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0) gl.drawArrays(gl.TRIANGLE_FAN , 0, segments + 1) gl.bindBuffer(gl.ARRAY_BUFFER,0) end function ccDrawQuadBezier(origin, control, destination, segments) if not lazy_init() then return end local vertexBuffer = { } local function initBuffer() local vertices = { } local i = 1 local t = 0.0 for i = 1, segments do vertices[2 * i - 1] = math.pow(1 - t,2) * origin.x + 2.0 * (1 - t) * t * control.x + t * t * destination.x vertices[2 * i] = math.pow(1 - t,2) * origin.y + 2.0 * (1 - t) * t * control.y + t * t * destination.y t = t + 1.0 / segments end vertices[2 * (segments + 1) - 1] = destination.x vertices[2 * (segments + 1)] = destination.y vertexBuffer.buffer_id = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer.buffer_id) gl.bufferData(gl.ARRAY_BUFFER, (segments + 1) * 2, vertices, gl.STATIC_DRAW) gl.bindBuffer(gl.ARRAY_BUFFER, 0) end initBuffer() setDrawProperty() gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer.buffer_id) gl.vertexAttribPointer(CCConstants.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0) gl.drawArrays(gl.LINE_STRIP , 0, segments + 1) gl.bindBuffer(gl.ARRAY_BUFFER,0) end function ccDrawCubicBezier(origin, control1, control2, destination, segments) if not lazy_init then return end local vertexBuffer = { } local function initBuffer() local vertices = { } local t = 0 local i = 1 for i = 1, segments do vertices[2 * i - 1] = math.pow(1 - t,3) * origin.x + 3.0 * math.pow(1 - t, 2) * t * control1.x + 3.0 * (1 - t) * t * t * control2.x + t * t * t * destination.x vertices[2 * i] = math.pow(1 - t,3) * origin.y + 3.0 * math.pow(1 - t, 2) * t * control1.y + 3.0 * (1 - t) * t * t * control2.y + t * t * t * destination.y t = t + 1.0 / segments end vertices[2 * (segments + 1) - 1] = destination.x vertices[2 * (segments + 1)] = destination.y vertexBuffer.buffer_id = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer.buffer_id) gl.bufferData(gl.ARRAY_BUFFER, (segments + 1) * 2, vertices, gl.STATIC_DRAW) gl.bindBuffer(gl.ARRAY_BUFFER, 0) end initBuffer() setDrawProperty() gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer.buffer_id) gl.vertexAttribPointer(CCConstants.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0) gl.drawArrays(gl.LINE_STRIP , 0, segments + 1) gl.bindBuffer(gl.ARRAY_BUFFER,0) end
mit
stephank/luci
applications/luci-asterisk/luasrc/model/cbi/asterisk-mod-res.lua
80
3097
--[[ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth <steven@midlink.org> Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 $Id$ ]]-- cbimap = Map("asterisk", "asterisk", "") module = cbimap:section(TypedSection, "module", "Modules", "") module.anonymous = true res_config_mysql = module:option(ListValue, "res_config_mysql", "MySQL Config Resource", "") res_config_mysql:value("yes", "Load") res_config_mysql:value("no", "Do Not Load") res_config_mysql:value("auto", "Load as Required") res_config_mysql.rmempty = true res_config_odbc = module:option(ListValue, "res_config_odbc", "ODBC Config Resource", "") res_config_odbc:value("yes", "Load") res_config_odbc:value("no", "Do Not Load") res_config_odbc:value("auto", "Load as Required") res_config_odbc.rmempty = true res_config_pgsql = module:option(ListValue, "res_config_pgsql", "PGSQL Module", "") res_config_pgsql:value("yes", "Load") res_config_pgsql:value("no", "Do Not Load") res_config_pgsql:value("auto", "Load as Required") res_config_pgsql.rmempty = true res_crypto = module:option(ListValue, "res_crypto", "Cryptographic Digital Signatures", "") res_crypto:value("yes", "Load") res_crypto:value("no", "Do Not Load") res_crypto:value("auto", "Load as Required") res_crypto.rmempty = true res_features = module:option(ListValue, "res_features", "Call Parking Resource", "") res_features:value("yes", "Load") res_features:value("no", "Do Not Load") res_features:value("auto", "Load as Required") res_features.rmempty = true res_indications = module:option(ListValue, "res_indications", "Indications Configuration", "") res_indications:value("yes", "Load") res_indications:value("no", "Do Not Load") res_indications:value("auto", "Load as Required") res_indications.rmempty = true res_monitor = module:option(ListValue, "res_monitor", "Call Monitoring Resource", "") res_monitor:value("yes", "Load") res_monitor:value("no", "Do Not Load") res_monitor:value("auto", "Load as Required") res_monitor.rmempty = true res_musiconhold = module:option(ListValue, "res_musiconhold", "Music On Hold Resource", "") res_musiconhold:value("yes", "Load") res_musiconhold:value("no", "Do Not Load") res_musiconhold:value("auto", "Load as Required") res_musiconhold.rmempty = true res_odbc = module:option(ListValue, "res_odbc", "ODBC Resource", "") res_odbc:value("yes", "Load") res_odbc:value("no", "Do Not Load") res_odbc:value("auto", "Load as Required") res_odbc.rmempty = true res_smdi = module:option(ListValue, "res_smdi", "SMDI Module", "") res_smdi:value("yes", "Load") res_smdi:value("no", "Do Not Load") res_smdi:value("auto", "Load as Required") res_smdi.rmempty = true res_snmp = module:option(ListValue, "res_snmp", "SNMP Module", "") res_snmp:value("yes", "Load") res_snmp:value("no", "Do Not Load") res_snmp:value("auto", "Load as Required") res_snmp.rmempty = true return cbimap
apache-2.0
stephank/luci
applications/luci-asterisk/luasrc/model/cbi/asterisk-iax-connections.lua
80
2000
--[[ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth <steven@midlink.org> Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 $Id$ ]]-- cbimap = Map("asterisk", "asterisk", "") iax = cbimap:section(TypedSection, "iax", "IAX Connection", "") iax.addremove = true alwaysinternational = iax:option(Flag, "alwaysinternational", "Always Dial International", "") alwaysinternational.optional = true context = iax:option(ListValue, "context", "Context to use", "") context.titleref = luci.dispatcher.build_url( "admin", "services", "asterisk", "dialplans" ) cbimap.uci:foreach( "asterisk", "dialplan", function(s) context:value(s['.name']) end ) cbimap.uci:foreach( "asterisk", "dialzone", function(s) context:value(s['.name']) end ) countrycode = iax:option(Value, "countrycode", "Country Code for connection", "") countrycode.optional = true extension = iax:option(Value, "extension", "Add as Extension", "") extension.optional = true host = iax:option(Value, "host", "Host name (or blank)", "") host.optional = true internationalprefix = iax:option(Value, "internationalprefix", "International Dial Prefix", "") internationalprefix.optional = true prefix = iax:option(Value, "prefix", "Dial Prefix (for external line)", "") prefix.optional = true secret = iax:option(Value, "secret", "Secret", "") secret.optional = true timeout = iax:option(Value, "timeout", "Dial Timeout (sec)", "") timeout.optional = true type = iax:option(ListValue, "type", "Option type", "") type:value("friend", "Friend (outbound/inbound)") type:value("user", "User (inbound - authenticate by \"from\")") type:value("peer", "Peer (outbound - match by host)") type.optional = true username = iax:option(Value, "username", "User name", "") username.optional = true return cbimap
apache-2.0
Alexx-G/openface
training/train.lua
8
7852
-- Copyright 2015-2016 Carnegie Mellon University -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- 2015-08-09: [Brandon Amos] Initial implementation. -- 2016-01-04: [Bartosz Ludwiczuk] Substantial improvements at -- https://github.com/melgor/Triplet-Learning require 'optim' require 'image' require 'torchx' --for concetration the table of tensors local optnet_loaded, optnet = pcall(require,'optnet') local models = require 'model' local openFaceOptim = require 'OpenFaceOptim' local optimMethod = optim.adam local optimState = {} -- Use for other algorithms like SGD local optimator = nil trainLogger = optim.Logger(paths.concat(opt.save, 'train.log')) local batchNumber local triplet_loss function train() print('==> doing epoch on training data:') print("==> online epoch # " .. epoch) batchNumber = 0 model,criterion = models.modelSetup(model) optimator = openFaceOptim:__init(model, optimState) if opt.cuda then cutorch.synchronize() end model:training() local tm = torch.Timer() triplet_loss = 0 local i = 1 while batchNumber < opt.epochSize do -- queue jobs to data-workers donkeys:addjob( -- the job callback (runs in data-worker thread) function() local inputs, numPerClass = trainLoader:samplePeople(opt.peoplePerBatch, opt.imagesPerPerson) inputs = inputs:float() numPerClass = numPerClass:float() return sendTensor(inputs), sendTensor(numPerClass) end, -- the end callback (runs in the main thread) trainBatch ) if i % 5 == 0 then donkeys:synchronize() end i = i + 1 end donkeys:synchronize() if opt.cuda then cutorch.synchronize() end triplet_loss = triplet_loss / batchNumber trainLogger:add{ ['avg triplet loss (train set)'] = triplet_loss, } print(string.format('Epoch: [%d][TRAINING SUMMARY] Total Time(s): %.2f\t' .. 'average triplet loss (per batch): %.2f', epoch, tm:time().real, triplet_loss)) print('\n') collectgarbage() end -- of train() function saveModel(model) -- Check for nans from https://github.com/cmusatyalab/openface/issues/127 local function checkNans(x, tag) local I = torch.ne(x,x) if torch.any(I) then print("train.lua: Error: NaNs found in: ", tag) os.exit(-1) -- x[I] = 0.0 end end for j, mod in ipairs(model:listModules()) do if torch.typename(mod) == 'nn.SpatialBatchNormalization' then checkNans(mod.running_mean, string.format("%d-%s-%s", j, mod, 'running_mean')) checkNans(mod.running_var, string.format("%d-%s-%s", j, mod, 'running_var')) end end if opt.cuda then if opt.cudnn then cudnn.convert(model, nn) end end local dpt if torch.type(model) == 'nn.DataParallelTable' then dpt = model model = model:get(1) end if optnet_loaded then optnet.removeOptimization(model) end torch.save(paths.concat(opt.save, 'model_' .. epoch .. '.t7'), model:float():clearState()) torch.save(paths.concat(opt.save, 'optimState_' .. epoch .. '.t7'), optimState) if dpt then -- OOM without this dpt:clearState() end collectgarbage() return model end local inputsCPU = torch.FloatTensor() local numPerClass = torch.FloatTensor() local timer = torch.Timer() function trainBatch(inputsThread, numPerClassThread) collectgarbage() if batchNumber >= opt.epochSize then return end if opt.cuda then cutorch.synchronize() end timer:reset() receiveTensor(inputsThread, inputsCPU) receiveTensor(numPerClassThread, numPerClass) local inputs if opt.cuda then inputs = inputsCPU:cuda() else inputs = inputsCPU end local numImages = inputs:size(1) local embeddings = model:forward(inputs):float() local as_table = {} local ps_table = {} local ns_table = {} local triplet_idx = {} local num_example_per_idx = torch.Tensor(embeddings:size(1)) num_example_per_idx:zero() local tripIdx = 1 local embStartIdx = 1 local numTrips = 0 for i = 1,opt.peoplePerBatch do local n = numPerClass[i] for j = 1,n-1 do -- For every image in the batch. local aIdx = embStartIdx + j - 1 local diff = embeddings - embeddings[{ {aIdx} }]:expandAs(embeddings) local norms = diff:norm(2, 2):pow(2):squeeze() for pair = j, n-1 do -- For every possible positive pair. local pIdx = embStartIdx + pair local fff = (embeddings[aIdx]-embeddings[pIdx]):norm(2) local normsP = norms - torch.Tensor(embeddings:size(1)):fill(fff*fff) -- Set the indices of the same class to the max so they are ignored. normsP[{{embStartIdx,embStartIdx +n-1}}] = normsP:max() -- Get indices of images within the margin. local in_margin = normsP:lt(opt.alpha) local allNeg = torch.find(in_margin, 1) -- Use only non-random triplets. -- Random triples (which are beyond the margin) will just produce gradient = 0, -- so the average gradient will decrease. if table.getn(allNeg) ~= 0 then selNegIdx = allNeg[math.random (table.getn(allNeg))] -- Add the embeding of each example. table.insert(as_table,embeddings[aIdx]) table.insert(ps_table,embeddings[pIdx]) table.insert(ns_table,embeddings[selNegIdx]) -- Add the original index of triplets. table.insert(triplet_idx, {aIdx,pIdx,selNegIdx}) -- Increase the number of times of using each example. num_example_per_idx[aIdx] = num_example_per_idx[aIdx] + 1 num_example_per_idx[pIdx] = num_example_per_idx[pIdx] + 1 num_example_per_idx[selNegIdx] = num_example_per_idx[selNegIdx] + 1 tripIdx = tripIdx + 1 end numTrips = numTrips + 1 end end embStartIdx = embStartIdx + n end assert(embStartIdx - 1 == numImages) local nTripsFound = table.getn(as_table) print((' + (nTrips, nTripsFound) = (%d, %d)'):format(numTrips, nTripsFound)) if nTripsFound == 0 then print("Warning: nTripsFound == 0. Skipping batch.") return end local as = torch.concat(as_table):view(table.getn(as_table), opt.embSize) local ps = torch.concat(ps_table):view(table.getn(ps_table), opt.embSize) local ns = torch.concat(ns_table):view(table.getn(ns_table), opt.embSize) local apn if opt.cuda then local asCuda = torch.CudaTensor() local psCuda = torch.CudaTensor() local nsCuda = torch.CudaTensor() local sz = as:size() asCuda:resize(sz):copy(as) psCuda:resize(sz):copy(ps) nsCuda:resize(sz):copy(ns) apn = {asCuda, psCuda, nsCuda} else apn = {as, ps, ns} end local err, _ = optimator:optimizeTriplet( optimMethod, inputs, apn, criterion, triplet_idx -- , num_example_per_idx ) if opt.cuda then cutorch.synchronize() end batchNumber = batchNumber + 1 print(('Epoch: [%d][%d/%d]\tTime %.3f\ttripErr %.2e'):format( epoch, batchNumber, opt.epochSize, timer:time().real, err)) timer:reset() triplet_loss = triplet_loss + err end
apache-2.0
Sponk/NeoEditor
Documentation/LuaDocs/General.lua
1
1092
/** * @brief Creates a 3D vector. * @param x The X value * @param y The Y value * @param z The Z value * @return The newly created 3D vector */ vec3(float x, float y, float z); /** * @brief Calculates the length of a 3D vector. * @param vec3 The 3D vector to use. * @return The length of the vector. */ length(vec3); /** * @brief Normalizes a vector * * This function takes the input vector and transforms it * to a new vector with the length 1.0f. * * @param vec3 The vector to normalize. * @return The normalized vec3. */ normalize(vec3); /** * @brief This function calculates the dot product of two vectors. * * @param vecA The first vector. * @param vecB The second vector. * @return The one dimensional scalar product. */ dot(vecA, vecB); /** * @brief This function calculates the cross product of two vectors. * @param vecA The first vector. * @param vecB The second vector. * @return The calculated vector. */ cross(vecA, vecB); getBehaviorVariable(object, behaviorId, "variableName"); setBehaviorVariable(object, behaviorId, "variableName", value);
gpl-2.0
DeadSocks/trajopt
ext/bullet/Demos/OpenCLClothDemo/NVidia/premake4.lua
14
1192
hasCL = findOpenCL_NVIDIA() if (hasCL) then project "AppOpenCLClothDemo_NVIDIA" defines { "USE_NVIDIA_OPENCL","CL_PLATFORM_NVIDIA"} initOpenCL_NVIDIA() language "C++" kind "ConsoleApp" targetdir "../../.." libdirs {"../../../Glut"} links { "LinearMath", "BulletCollision", "BulletDynamics", "BulletSoftBody", "BulletSoftBodySolvers_OpenCL_NVIDIA", "opengl32" } configuration { "Windows" } defines { "GLEW_STATIC"} configuration "x64" links { "glut64", "glew64s" } configuration "x32" links { "glut32", "glew32s" } configuration{} includedirs { "../../../src", "../../../Glut", "../../SharedOpenCL", "../../OpenGL" } files { "../cl_cloth_demo.cpp", "../../SharedOpenCL/btOpenCLUtils.cpp", "../../SharedOpenCL/btOpenCLUtils.h", "../../SharedOpenCL/btOpenCLInclude.h", "../../OpenGL/GLDebugDrawer.cpp", "../../OpenGL/stb_image.cpp", "../../OpenGL/stb_image.h", "../gl_win.cpp", "../clstuff.cpp", "../clstuff.h", "../gl_win.h", "../cloth.h" } end
bsd-2-clause
aqasaeed/mamad
plugins/gnuplot.lua
622
1813
--[[ * Gnuplot plugin by psykomantis * dependencies: * - gnuplot 5.00 * - libgd2-xpm-dev (on Debian distr) for more info visit: https://libgd.github.io/pages/faq.html * ]] -- Gnuplot needs absolute path for the plot, so i run some commands to find where we are local outputFile = io.popen("pwd","r") io.input(outputFile) local _pwd = io.read("*line") io.close(outputFile) local _absolutePlotPath = _pwd .. "/data/plot.png" local _scriptPath = "./data/gnuplotScript.gpl" do local function gnuplot(msg, fun) local receiver = get_receiver(msg) -- We generate the plot commands local formattedString = [[ set grid set terminal png set output "]] .. _absolutePlotPath .. [[" plot ]] .. fun local file = io.open(_scriptPath,"w"); file:write(formattedString) file:close() os.execute("gnuplot " .. _scriptPath) os.remove (_scriptPath) return _send_photo(receiver, _absolutePlotPath) end -- Check all dependencies before executing local function checkDependencies() local status = os.execute("gnuplot -h") if(status==true) then status = os.execute("gnuplot -e 'set terminal png'") if(status == true) then return 0 -- OK ready to go! else return 1 -- missing libgd2-xpm-dev end else return 2 -- missing gnuplot end end local function run(msg, matches) local status = checkDependencies() if(status == 0) then return gnuplot(msg,matches[1]) elseif(status == 1) then return "It seems that this bot miss a dependency :/" else return "It seems that this bot doesn't have gnuplot :/" end end return { description = "use gnuplot through telegram, only plot single variable function", usage = "!gnuplot [single variable function]", patterns = {"^!gnuplot (.+)$"}, run = run } end
gpl-2.0
Sponk/NeoEditor
Neo/NeoEditor/Plugins/ImagesAsPlanes.lua
1
1912
setPluginName("Images as Planes") setPluginAuthor("Yannick Pflanzer") setPluginDescription("A plugin that allows you to load a 2D image into a 3D scene.") addEditorMenu("Import image", "load_callback") require("plugins.libs.misc") -- Finds the last occurance of fmt in the given string. -- -- str: The string to search in -- fmt: The pattern to search for -- function find_last_of(str, fmt) local rev = str:reverse() -- Add one because Lua indices start at one and not at zero return str:len() - rev:find(fmt) + 1 end -- This function is called, when the menu item gets clicked. -- It creates a meshfile and assigns the image as texture to it. -- Then it loads the new mesh into the scene. -- -- TODO: Scale the mesh to fit the w/h ratio of the texture! function load_callback() local projectDir = getProjectDir() if projectDir:len() == 0 then messagebox("You have to load a project first!") return end -- Find all required filenames local filename = openFileDlg("Choose a file", getProjectDir() .. "maps", "*.png") local texture = createSprite(0,0,0,0,filename, "") local dimensions = getSpriteSize(texture) debugLog("Texture has dimensions of " .. dimensions[1] .. "x" .. dimensions[2]) filename = relpath(filename, projectDir .. "meshs") debugLog("Loading image file: " .. filename) local idx = find_last_of(filename, "/") local meshname = projectDir .. "meshs" .. filename:sub(idx, filename:len()) .. ".mesh" debugLog("Saving to: " .. meshname) -- Generate the .mesh file local templateFile = io.open("plugins/template.mesh", "r") local data = templateFile:read("*all") data = data:gsub("$IMAGE_FILENAME", filename) data = data:gsub("$IMAGE_WIDTH", dimensions[1]) data = data:gsub("$IMAGE_HEIGHT", dimensions[2]) local meshfile = io.open(meshname, "w") meshfile:write(data) meshfile:flush() meshfile:close() loadMesh(meshname) updateEditorView() end
gpl-2.0
kickinrad/healerhealer
manual.lua
1
15502
-- manual.lua manual = { buttons = {}, introRead = false, pageNumberMax = 14, pageNumber = 1, dps = { { -- 1 left = { title = "Grimoire of Solomon", description = "\tAn account of ailments and disease of strange and unnatural character.\n\tThe blind many seem undeterred by the many grave and terrible spirits who dwell beneath the hallowed ground.\n\tThey come in pilgrammage, they come for refuge, they come for trade.\n\tWeak souls and strong souls alike, they come, they sicken, they wretch, they go mad, they fall.\n\tYou may, in your time, have heard talk of the medicine man Solomon, the great Witch Doctor of Ludistan. I am he, but I am not so great as they would have you think." }, right = { title = "", description = "\tMany a patient of mine have died after my best efforts, my most exhaustive treatment. Nothing you will find in these pages will surely cure yours. Treatment and prayer are the best you can do.\n\tI have documented within every illness I have thus encountered, and the most suitable treatments I have discovered for each.\n\tYou will not save many. You may not even save most. The sooner you come to terms with that, the sooner you will master your craft." } }, { -- 2 left = { title = "", description = "\n\n\n\n\tDo not be afraid. Keep your will strong and your heart stronger yet." }, right = { title = "", description = "\n\n\n\n\tLest you join the carcasses and cadavers..." } }, { -- 3 table of contents left = { title = "Table of Contents\nS", description = "\n\t ymptoms:\n\n\t- Greyed Skin\n\n\t- Hot Blood\n\n\t- Sweating\n\n\t- Bloodshot Eyes\n\n\t- Sunken Eyes\n\n\t- Welts\n\n\t- Pox\n" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "\n\nT", description = "\n\t reatments:\n\n\t- Balm of Vigor\n\n\t- Balm of Soothing\n\n\t- Cooling Tincture\n\n\t- Mesmer's Medicine\n\n\t- Enlivening Tincture\n\n\t- Blemishing Balm\n\n\t- Solomon's Tincture" } }, { -- 4 left = { title = "Greyed Skin", description = "\n\tCured by: Balm of Vigor" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "", description = "" } }, { -- 5 left = { title = "Hot Blood", description = "\n\tCured by: Balm of Soothing" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "", description = "" } }, { -- 6 left = { title = "Sweating", description = "\n\tCured by: Cooling Tincture" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "", description = "" } }, { -- 7 left = { title = "Bloodshot Eyes", description = "\n\tCured by: Mesmer's Medicine" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "", description = "" } }, { -- 8 left = { title = "Sunken Eyes", description = "\n\tCured by: Enlivening Tincture" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "", description = "" } }, { -- 9 left = { title = "Welts", description = "\n\tCured by: Blemishing Balm" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "", description = "" } }, { -- 10 left = { title = "Pox", description = "\n\tCured by: Solomon's Tincture" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "", description = "" } }, { -- 11 left = { title = "Balm of Vigor", description = "\t- Aloe\n\n\t- Dragonfly Wing\n\n\t- Fox's Tail\n\n\t- Cat's Paw x 2" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "Balm of Soothing", description = "\n\t- Aloe\n\n\t- Olive Twin\n\n\t- Dove's Wing\n\n\t- Rosemary\n\n\t- Sow's Milk" } }, { -- 12 left = { title = "Cooling Tincture", description = "\n\t- Salt\n\n\t- Vinegar\n\n\t- Ash\n\n\t- Bog Water\n\n\t- Rosemary" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "Mesmer s Medicine", description = "\n\t- Sage's Eye\n\n\t- Witch's Hair\n\n\t- Mandrake Root\n\n\t- Toad's Tongue\n\n\t- Wheat" } }, { -- 13 left = { title = "Enlivening Tincture", description = "\n\t- Wolf's Fang\n\n\t- Vinegar x 2\n\n\t- Fox's Tail\n\n\t- Quail Egg" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "Blemishing Balm", description = "\n\t- Newt Tongue\n\n\t- Croc Scales\n\n\t- Rat's Tail\n\n\t- Frog\n\n\t- Mandrake Root" } }, { -- 14 left = { title = "Solomon s Tincture", description = "\n\t- Familiar's Blood\n\n\t- Wolf's Fang x 2\n\n\t- Dahlia\n\n\t- Cat's Paw" -- coughing, shivers, lost hair, rashes, gaunt features }, right = { title = "", description = "" } } } } local buttonTimerMax = 0.2 local buttonTimer = 0 function addButton(xPos, yPos, width, height, textName) newButton = {x = xPos, y = yPos, w = width, h = height, text = textName, backgroundDraw = false} table.insert(manual.buttons, newButton) end function loadManual() soundPageTurn = love.audio.newSource("assets/sounds/pageturn.wav") soundPageTurn:setVolume(.3) manualImage = love.graphics.newImage("assets/book.png") addButton(575, 345, 200, 255, "right") -- right page button addButton(690, 319, 110, 10, "toc") -- table of contents greySkinI = love.graphics.newImage("assets/gImages/greyboy.png") redSkinI = love.graphics.newImage("assets/gImages/redboy.png") sweatI = love.graphics.newImage("assets/gImages/wet.png") bloodshotI = love.graphics.newImage("assets/gImages/bs.png") sunkenI = love.graphics.newImage("assets/gImages/sink.png") weltsI = love.graphics.newImage("assets/gImages/weltboy.png") spotsI = love.graphics.newImage("assets/gImages/spotboy.png") end function updateManual(dt) -- key presses left and right -- manual.pageNumber = manual.pageNumber + 1 (cant go over pageNumberMax, and cant be less than 1) -- manual.pageNumber = manual.pageNumber - 1 for _, button in ipairs(manual.buttons) do if love.mouse.getX() > button.x and love.mouse.getX() < button.x + button.w and love.mouse.getY() > button.y and love.mouse.getY() < button.y + button.h and love.mouse.isDown(1) and buttonTimer <= 0 then if button.text == "right" then manual.pageNumber = manual.pageNumber + 1 love.audio.play(soundPageTurn) elseif button.text == "left" then manual.pageNumber = manual.pageNumber - 1 love.audio.play(soundPageTurn) elseif button.text == "grey" then love.audio.play(soundClick) manual.pageNumber = 4 elseif button.text == "redskin" then love.audio.play(soundClick) manual.pageNumber = 5 elseif button.text == "sweat" then manual.pageNumber = 6 love.audio.play(soundClick) elseif button.text == "bloodshot" then manual.pageNumber = 7 love.audio.play(soundClick) elseif button.text == "sunken" then manual.pageNumber = 8 love.audio.play(soundClick) elseif button.text == "welts" then manual.pageNumber = 9 love.audio.play(soundClick) elseif button.text == "redspots" then manual.pageNumber = 10 love.audio.play(soundClick) elseif button.text == "vigor" or button.text == "soothing" then manual.pageNumber = 11 love.audio.play(soundClick) elseif button.text == "cooling" or button.text == "mesmer" then manual.pageNumber = 12 love.audio.play(soundClick) elseif button.text == "enlivening" or button.text == "blemish" then manual.pageNumber = 13 love.audio.play(soundClick) elseif button.text == "whip" then manual.pageNumber = 14 love.audio.play(soundClick) elseif button.text == "toc" then manual.pageNumber = 3 love.audio.play(soundClick) end buttonTimer = buttonTimerMax manual.buttons = {} addButton(690, 319, 110, 10, "toc") if manual.pageNumber == 1 then addButton(575, 345, 200, 255, "right") -- right page button elseif manual.pageNumber == 2 then addButton(575, 345, 200, 255, "right") -- right page button addButton(375, 345, 200, 255, "left") -- left page button elseif manual.pageNumber == 3 then -- table of contents -- add a ton of buttons addButton(730, 345, 40, 255, "right") -- right page button addButton(375, 345, 35, 255, "left") -- left page button -- symptoms addButton(410, 444, 135, 10, "grey") -- grey skin 22 difference in pixels on the y axis addButton(410, 466, 135, 10, "redskin") -- hot blood... previously known as red skin addButton(410, 488, 135, 10, "sweat") -- sweating addButton(410, 510, 135, 10, "bloodshot") -- bloodshot eyes addButton(410, 532, 135, 10, "sunken") -- sunken eyes addButton(410, 554, 135, 10, "welts") -- welts addButton(410, 576, 135, 10, "redspots") -- red spots addButton(590, 444, 135, 10, "vigor") -- grey skin 22 difference in pixels on the y axis addButton(590, 466, 135, 10, "soothing") addButton(590, 488, 135, 10, "cooling") addButton(590, 510, 135, 10, "mesmer") addButton(590, 532, 135, 10, "enlivening") addButton(590, 554, 135, 10, "blemish") addButton(590, 576, 135, 10, "whip") elseif manual.pageNumber >= 4 and manual.pageNumber <= 13 then addButton(575, 345, 200, 255, "right") -- right page button addButton(375, 345, 200, 255, "left") -- left page button elseif manual.pageNumber == 14 then -- !!!last page!!! addButton(375, 345, 200, 255, "left") -- left page button end end if love.mouse.getX() > button.x and love.mouse.getX() < button.x + button.w and love.mouse.getY() > button.y and love.mouse.getY() < button.y + button.h then button.backgroundDraw = true else button.backgroundDraw = false end end -- decrement button Timer if buttonTimer > 0 then buttonTimer = buttonTimer - (1 * dt) end end function drawManual() love.graphics.setColor(255, 255, 255, 255) love.graphics.draw(manualImage, 451, 400, 0, 1, 1, 100, 100) love.graphics.setFont(blokk) blokk:setLineHeight(2) -- default is 1 if manual.pageNumber == 4 then love.graphics.draw(greySkinI, 680, 480, 0, 1, 1, 100, 100) love.graphics.setColor(0, 0, 0, 200) love.graphics.printf("\tLorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class ", 398, 450, 150) love.graphics.setColor(255, 255, 255, 255) end if manual.pageNumber == 5 then love.graphics.draw(redSkinI, 680, 480, 0, 1, 1, 100, 100) love.graphics.setColor(0, 0, 0, 200) love.graphics.printf("\tCurabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, lipsummm", 398, 450, 150) love.graphics.setColor(255, 255, 255, 255) end if manual.pageNumber == 6 then love.graphics.draw(sweatI, 680, 480, 0, 1, 1, 100, 100) love.graphics.setColor(0, 0, 0, 200) love.graphics.printf("\tNam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imp", 398, 450, 150) love.graphics.setColor(255, 255, 255, 255) end if manual.pageNumber == 7 then love.graphics.draw(bloodshotI, 680, 480, 0, 1, 1, 100, 100) love.graphics.setColor(0, 0, 0, 200) love.graphics.printf("\tLorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class ", 398, 450, 150) love.graphics.setColor(255, 255, 255, 255) end if manual.pageNumber == 8 then love.graphics.draw(sunkenI, 680, 480, 0, 1, 1, 100, 100) love.graphics.setColor(0, 0, 0, 200) love.graphics.printf("\tNam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imp", 398, 450, 150) love.graphics.setColor(255, 255, 255, 255) end if manual.pageNumber == 9 then love.graphics.draw(weltsI, 680, 480, 0, 1, 1, 100, 100) love.graphics.setColor(0, 0, 0, 200) love.graphics.printf("\tLorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class ", 398, 450, 150) love.graphics.setColor(255, 255, 255, 255) end if manual.pageNumber == 10 then love.graphics.draw(spotsI, 680, 480, 0, 1, 1, 100, 100) love.graphics.setColor(0, 0, 0, 200) love.graphics.printf("\tNam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imp", 398, 450, 150) love.graphics.setColor(255, 255, 255, 255) end for _, button in ipairs(manual.buttons) do if button.backgroundDraw then love.graphics.setColor(0, 0, 0, 15) -- light grey love.graphics.rectangle("fill", button.x, button.y, button.w, button.h) end if button.backgroundDraw and button.text == "toc" then love.graphics.setColor(255, 0, 0, 150) -- red love.graphics.rectangle("fill", button.x, button.y, button.w, button.h) end end love.graphics.setColor(255, 255, 255, 255) love.graphics.setFont(big_gothic) love.graphics.setColor(0, 0, 0, 255) love.graphics.printf(manual.dps[manual.pageNumber].left.title, 398, 360, 150) love.graphics.printf(manual.dps[manual.pageNumber].right.title, 600, 360, 150) love.graphics.setFont(thin) love.graphics.printf(manual.dps[manual.pageNumber].left.description, 398, 410, 150) love.graphics.printf(manual.dps[manual.pageNumber].right.description, 600, 410, 150) love.graphics.setColor(255, 255, 255, 255) love.graphics.printf("Table of Contents", 695, 318, 150) end
mit
dmccuskey/dmc-wamp
examples/dmc-wamp-rpc-callee/dmc_corona/lib/sha1.lua
11
110178
-- -- SHA-1 secure hash computation, and HMAC-SHA1 signature computation, -- in pure Lua (tested on Lua 5.1) -- -- Latest version always at: http://regex.info/blog/lua/sha1 -- -- Copyright 2009 Jeffrey Friedl -- jfriedl@yahoo.com -- http://regex.info/blog/ -- -- -- Version 1 [May 28, 2009] -- -- -- Lua is a pathetic, horrid, turd of a language. Not only doesn't it have -- bitwise integer operators like OR and AND, it doesn't even have integers -- (and those, relatively speaking, are its good points). Yet, this -- implements the SHA-1 digest hash in pure Lua. While coding it, I felt as -- if I were chiseling NAND gates out of rough blocks of silicon. Those not -- already familiar with this woeful language may, upon seeing this code, -- throw up in their own mouth. -- -- It's not super fast.... a 10k-byte message takes about 2 seconds on a -- circa-2008 mid-level server, but it should be plenty adequate for short -- messages, such as is often needed during authentication handshaking. -- -- Algorithm: http://www.itl.nist.gov/fipspubs/fip180-1.htm -- -- This file creates four entries in the global namespace: -- -- local hash_as_hex = sha1(message) -- returns a hex string -- local hash_as_data = sha1_binary(message) -- returns raw bytes -- -- local hmac_as_hex = hmac_sha1(key, message) -- hex string -- local hmac_as_data = hmac_sha1_binary(key, message) -- raw bytes -- -- Pass sha1() a string, and it returns a hash as a 40-character hex string. -- For example, the call -- -- local hash = sha1 "http://regex.info/blog/" -- -- puts the 40-character string -- -- "7f103bf600de51dfe91062300c14738b32725db5" -- -- into the variable 'hash' -- -- Pass sha1_hmac() a key and a message, and it returns the signature as a -- 40-byte hex string. -- -- -- The two "_binary" versions do the same, but return the 20-byte string of raw data -- that the 40-byte hex strings represent. -- ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ local M = {} -- -- Return a W32 object for the number zero -- local function ZERO() return { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, } end local hex_to_bits = { ["0"] = { false, false, false, false }, ["1"] = { false, false, false, true }, ["2"] = { false, false, true, false }, ["3"] = { false, false, true, true }, ["4"] = { false, true, false, false }, ["5"] = { false, true, false, true }, ["6"] = { false, true, true, false }, ["7"] = { false, true, true, true }, ["8"] = { true, false, false, false }, ["9"] = { true, false, false, true }, ["A"] = { true, false, true, false }, ["B"] = { true, false, true, true }, ["C"] = { true, true, false, false }, ["D"] = { true, true, false, true }, ["E"] = { true, true, true, false }, ["F"] = { true, true, true, true }, ["a"] = { true, false, true, false }, ["b"] = { true, false, true, true }, ["c"] = { true, true, false, false }, ["d"] = { true, true, false, true }, ["e"] = { true, true, true, false }, ["f"] = { true, true, true, true }, } -- -- Given a string of 8 hex digits, return a W32 object representing that number -- local function from_hex(hex) assert(type(hex) == 'string') assert(hex:match('^[0123456789abcdefABCDEF]+$')) assert(#hex == 8) local W32 = { } for letter in hex:gmatch('.') do local b = hex_to_bits[letter] assert(b) table.insert(W32, 1, b[1]) table.insert(W32, 1, b[2]) table.insert(W32, 1, b[3]) table.insert(W32, 1, b[4]) end return W32 end local function COPY(old) local W32 = { } for k,v in pairs(old) do W32[k] = v end return W32 end local function ADD(first, ...) local a = COPY(first) local C, b, sum for v = 1, select('#', ...) do b = select(v, ...) C = 0 for i = 1, #a do sum = (a[i] and 1 or 0) + (b[i] and 1 or 0) + C if sum == 0 then a[i] = false C = 0 elseif sum == 1 then a[i] = true C = 0 elseif sum == 2 then a[i] = false C = 1 else a[i] = true C = 1 end end -- we drop any ending carry end return a end local function XOR(first, ...) local a = COPY(first) local b for v = 1, select('#', ...) do b = select(v, ...) for i = 1, #a do a[i] = a[i] ~= b[i] end end return a end local function AND(a, b) local c = ZERO() for i = 1, #a do -- only need to set true bits; other bits remain false if a[i] and b[i] then c[i] = true end end return c end local function OR(a, b) local c = ZERO() for i = 1, #a do -- only need to set true bits; other bits remain false if a[i] or b[i] then c[i] = true end end return c end local function OR3(a, b, c) local d = ZERO() for i = 1, #a do -- only need to set true bits; other bits remain false if a[i] or b[i] or c[i] then d[i] = true end end return d end local function NOT(a) local b = ZERO() for i = 1, #a do -- only need to set true bits; other bits remain false if not a[i] then b[i] = true end end return b end local function ROTATE(bits, a) local b = COPY(a) while bits > 0 do bits = bits - 1 table.insert(b, 1, table.remove(b)) end return b end local binary_to_hex = { ["0000"] = "0", ["0001"] = "1", ["0010"] = "2", ["0011"] = "3", ["0100"] = "4", ["0101"] = "5", ["0110"] = "6", ["0111"] = "7", ["1000"] = "8", ["1001"] = "9", ["1010"] = "a", ["1011"] = "b", ["1100"] = "c", ["1101"] = "d", ["1110"] = "e", ["1111"] = "f", } local function asHEX(a) local hex = "" local i = 1 while i < #a do local binary = (a[i + 3] and '1' or '0') .. (a[i + 2] and '1' or '0') .. (a[i + 1] and '1' or '0') .. (a[i + 0] and '1' or '0') hex = binary_to_hex[binary] .. hex i = i + 4 end return hex end local x67452301 = from_hex("67452301") local xEFCDAB89 = from_hex("EFCDAB89") local x98BADCFE = from_hex("98BADCFE") local x10325476 = from_hex("10325476") local xC3D2E1F0 = from_hex("C3D2E1F0") local x5A827999 = from_hex("5A827999") local x6ED9EBA1 = from_hex("6ED9EBA1") local x8F1BBCDC = from_hex("8F1BBCDC") local xCA62C1D6 = from_hex("CA62C1D6") function M.sha1(msg) assert(type(msg) == 'string') assert(#msg < 0x7FFFFFFF) -- have no idea what would happen if it were large local H0 = x67452301 local H1 = xEFCDAB89 local H2 = x98BADCFE local H3 = x10325476 local H4 = xC3D2E1F0 local msg_len_in_bits = #msg * 8 local first_append = string.char(0x80) -- append a '1' bit plus seven '0' bits local non_zero_message_bytes = #msg +1 +8 -- the +1 is the appended bit 1, the +8 are for the final appended length local current_mod = non_zero_message_bytes % 64 local second_append = "" if current_mod ~= 0 then second_append = string.rep(string.char(0), 64 - current_mod) end -- now to append the length as a 64-bit number. local B1, R1 = math.modf(msg_len_in_bits / 0x01000000) local B2, R2 = math.modf( 0x01000000 * R1 / 0x00010000) local B3, R3 = math.modf( 0x00010000 * R2 / 0x00000100) local B4 = 0x00000100 * R3 local L64 = string.char( 0) .. string.char( 0) .. string.char( 0) .. string.char( 0) -- high 32 bits .. string.char(B1) .. string.char(B2) .. string.char(B3) .. string.char(B4) -- low 32 bits msg = msg .. first_append .. second_append .. L64 assert(#msg % 64 == 0) --local fd = io.open("/tmp/msg", "wb") --fd:write(msg) --fd:close() local chunks = #msg / 64 local W = { } local start, A, B, C, D, E, f, K, TEMP local chunk = 0 while chunk < chunks do -- -- break chunk up into W[0] through W[15] -- start = chunk * 64 + 1 chunk = chunk + 1 for t = 0, 15 do W[t] = from_hex(string.format("%02x%02x%02x%02x", msg:byte(start, start + 3))) start = start + 4 end -- -- build W[16] through W[79] -- for t = 16, 79 do -- For t = 16 to 79 let Wt = S1(Wt-3 XOR Wt-8 XOR Wt-14 XOR Wt-16). W[t] = ROTATE(1, XOR(W[t-3], W[t-8], W[t-14], W[t-16])) end A = H0 B = H1 C = H2 D = H3 E = H4 for t = 0, 79 do if t <= 19 then -- (B AND C) OR ((NOT B) AND D) f = OR(AND(B, C), AND(NOT(B), D)) K = x5A827999 elseif t <= 39 then -- B XOR C XOR D f = XOR(B, C, D) K = x6ED9EBA1 elseif t <= 59 then -- (B AND C) OR (B AND D) OR (C AND D f = OR3(AND(B, C), AND(B, D), AND(C, D)) K = x8F1BBCDC else -- B XOR C XOR D f = XOR(B, C, D) K = xCA62C1D6 end -- TEMP = S5(A) + ft(B,C,D) + E + Wt + Kt; TEMP = ADD(ROTATE(5, A), f, E, W[t], K) --E = D;   D = C;    C = S30(B);   B = A;   A = TEMP; E = D D = C C = ROTATE(30, B) B = A A = TEMP --printf("t = %2d: %s %s %s %s %s", t, A:HEX(), B:HEX(), C:HEX(), D:HEX(), E:HEX()) end -- Let H0 = H0 + A, H1 = H1 + B, H2 = H2 + C, H3 = H3 + D, H4 = H4 + E. H0 = ADD(H0, A) H1 = ADD(H1, B) H2 = ADD(H2, C) H3 = ADD(H3, D) H4 = ADD(H4, E) end return asHEX(H0) .. asHEX(H1) .. asHEX(H2) .. asHEX(H3) .. asHEX(H4) end local function hex_to_binary(hex) return hex:gsub('..', function(hexval) return string.char(tonumber(hexval, 16)) end) end function M.sha1_binary(msg) return hex_to_binary(M.sha1(msg)) end local xor_with_0x5c = { [string.char( 0)] = string.char( 92), [string.char( 1)] = string.char( 93), [string.char( 2)] = string.char( 94), [string.char( 3)] = string.char( 95), [string.char( 4)] = string.char( 88), [string.char( 5)] = string.char( 89), [string.char( 6)] = string.char( 90), [string.char( 7)] = string.char( 91), [string.char( 8)] = string.char( 84), [string.char( 9)] = string.char( 85), [string.char( 10)] = string.char( 86), [string.char( 11)] = string.char( 87), [string.char( 12)] = string.char( 80), [string.char( 13)] = string.char( 81), [string.char( 14)] = string.char( 82), [string.char( 15)] = string.char( 83), [string.char( 16)] = string.char( 76), [string.char( 17)] = string.char( 77), [string.char( 18)] = string.char( 78), [string.char( 19)] = string.char( 79), [string.char( 20)] = string.char( 72), [string.char( 21)] = string.char( 73), [string.char( 22)] = string.char( 74), [string.char( 23)] = string.char( 75), [string.char( 24)] = string.char( 68), [string.char( 25)] = string.char( 69), [string.char( 26)] = string.char( 70), [string.char( 27)] = string.char( 71), [string.char( 28)] = string.char( 64), [string.char( 29)] = string.char( 65), [string.char( 30)] = string.char( 66), [string.char( 31)] = string.char( 67), [string.char( 32)] = string.char(124), [string.char( 33)] = string.char(125), [string.char( 34)] = string.char(126), [string.char( 35)] = string.char(127), [string.char( 36)] = string.char(120), [string.char( 37)] = string.char(121), [string.char( 38)] = string.char(122), [string.char( 39)] = string.char(123), [string.char( 40)] = string.char(116), [string.char( 41)] = string.char(117), [string.char( 42)] = string.char(118), [string.char( 43)] = string.char(119), [string.char( 44)] = string.char(112), [string.char( 45)] = string.char(113), [string.char( 46)] = string.char(114), [string.char( 47)] = string.char(115), [string.char( 48)] = string.char(108), [string.char( 49)] = string.char(109), [string.char( 50)] = string.char(110), [string.char( 51)] = string.char(111), [string.char( 52)] = string.char(104), [string.char( 53)] = string.char(105), [string.char( 54)] = string.char(106), [string.char( 55)] = string.char(107), [string.char( 56)] = string.char(100), [string.char( 57)] = string.char(101), [string.char( 58)] = string.char(102), [string.char( 59)] = string.char(103), [string.char( 60)] = string.char( 96), [string.char( 61)] = string.char( 97), [string.char( 62)] = string.char( 98), [string.char( 63)] = string.char( 99), [string.char( 64)] = string.char( 28), [string.char( 65)] = string.char( 29), [string.char( 66)] = string.char( 30), [string.char( 67)] = string.char( 31), [string.char( 68)] = string.char( 24), [string.char( 69)] = string.char( 25), [string.char( 70)] = string.char( 26), [string.char( 71)] = string.char( 27), [string.char( 72)] = string.char( 20), [string.char( 73)] = string.char( 21), [string.char( 74)] = string.char( 22), [string.char( 75)] = string.char( 23), [string.char( 76)] = string.char( 16), [string.char( 77)] = string.char( 17), [string.char( 78)] = string.char( 18), [string.char( 79)] = string.char( 19), [string.char( 80)] = string.char( 12), [string.char( 81)] = string.char( 13), [string.char( 82)] = string.char( 14), [string.char( 83)] = string.char( 15), [string.char( 84)] = string.char( 8), [string.char( 85)] = string.char( 9), [string.char( 86)] = string.char( 10), [string.char( 87)] = string.char( 11), [string.char( 88)] = string.char( 4), [string.char( 89)] = string.char( 5), [string.char( 90)] = string.char( 6), [string.char( 91)] = string.char( 7), [string.char( 92)] = string.char( 0), [string.char( 93)] = string.char( 1), [string.char( 94)] = string.char( 2), [string.char( 95)] = string.char( 3), [string.char( 96)] = string.char( 60), [string.char( 97)] = string.char( 61), [string.char( 98)] = string.char( 62), [string.char( 99)] = string.char( 63), [string.char(100)] = string.char( 56), [string.char(101)] = string.char( 57), [string.char(102)] = string.char( 58), [string.char(103)] = string.char( 59), [string.char(104)] = string.char( 52), [string.char(105)] = string.char( 53), [string.char(106)] = string.char( 54), [string.char(107)] = string.char( 55), [string.char(108)] = string.char( 48), [string.char(109)] = string.char( 49), [string.char(110)] = string.char( 50), [string.char(111)] = string.char( 51), [string.char(112)] = string.char( 44), [string.char(113)] = string.char( 45), [string.char(114)] = string.char( 46), [string.char(115)] = string.char( 47), [string.char(116)] = string.char( 40), [string.char(117)] = string.char( 41), [string.char(118)] = string.char( 42), [string.char(119)] = string.char( 43), [string.char(120)] = string.char( 36), [string.char(121)] = string.char( 37), [string.char(122)] = string.char( 38), [string.char(123)] = string.char( 39), [string.char(124)] = string.char( 32), [string.char(125)] = string.char( 33), [string.char(126)] = string.char( 34), [string.char(127)] = string.char( 35), [string.char(128)] = string.char(220), [string.char(129)] = string.char(221), [string.char(130)] = string.char(222), [string.char(131)] = string.char(223), [string.char(132)] = string.char(216), [string.char(133)] = string.char(217), [string.char(134)] = string.char(218), [string.char(135)] = string.char(219), [string.char(136)] = string.char(212), [string.char(137)] = string.char(213), [string.char(138)] = string.char(214), [string.char(139)] = string.char(215), [string.char(140)] = string.char(208), [string.char(141)] = string.char(209), [string.char(142)] = string.char(210), [string.char(143)] = string.char(211), [string.char(144)] = string.char(204), [string.char(145)] = string.char(205), [string.char(146)] = string.char(206), [string.char(147)] = string.char(207), [string.char(148)] = string.char(200), [string.char(149)] = string.char(201), [string.char(150)] = string.char(202), [string.char(151)] = string.char(203), [string.char(152)] = string.char(196), [string.char(153)] = string.char(197), [string.char(154)] = string.char(198), [string.char(155)] = string.char(199), [string.char(156)] = string.char(192), [string.char(157)] = string.char(193), [string.char(158)] = string.char(194), [string.char(159)] = string.char(195), [string.char(160)] = string.char(252), [string.char(161)] = string.char(253), [string.char(162)] = string.char(254), [string.char(163)] = string.char(255), [string.char(164)] = string.char(248), [string.char(165)] = string.char(249), [string.char(166)] = string.char(250), [string.char(167)] = string.char(251), [string.char(168)] = string.char(244), [string.char(169)] = string.char(245), [string.char(170)] = string.char(246), [string.char(171)] = string.char(247), [string.char(172)] = string.char(240), [string.char(173)] = string.char(241), [string.char(174)] = string.char(242), [string.char(175)] = string.char(243), [string.char(176)] = string.char(236), [string.char(177)] = string.char(237), [string.char(178)] = string.char(238), [string.char(179)] = string.char(239), [string.char(180)] = string.char(232), [string.char(181)] = string.char(233), [string.char(182)] = string.char(234), [string.char(183)] = string.char(235), [string.char(184)] = string.char(228), [string.char(185)] = string.char(229), [string.char(186)] = string.char(230), [string.char(187)] = string.char(231), [string.char(188)] = string.char(224), [string.char(189)] = string.char(225), [string.char(190)] = string.char(226), [string.char(191)] = string.char(227), [string.char(192)] = string.char(156), [string.char(193)] = string.char(157), [string.char(194)] = string.char(158), [string.char(195)] = string.char(159), [string.char(196)] = string.char(152), [string.char(197)] = string.char(153), [string.char(198)] = string.char(154), [string.char(199)] = string.char(155), [string.char(200)] = string.char(148), [string.char(201)] = string.char(149), [string.char(202)] = string.char(150), [string.char(203)] = string.char(151), [string.char(204)] = string.char(144), [string.char(205)] = string.char(145), [string.char(206)] = string.char(146), [string.char(207)] = string.char(147), [string.char(208)] = string.char(140), [string.char(209)] = string.char(141), [string.char(210)] = string.char(142), [string.char(211)] = string.char(143), [string.char(212)] = string.char(136), [string.char(213)] = string.char(137), [string.char(214)] = string.char(138), [string.char(215)] = string.char(139), [string.char(216)] = string.char(132), [string.char(217)] = string.char(133), [string.char(218)] = string.char(134), [string.char(219)] = string.char(135), [string.char(220)] = string.char(128), [string.char(221)] = string.char(129), [string.char(222)] = string.char(130), [string.char(223)] = string.char(131), [string.char(224)] = string.char(188), [string.char(225)] = string.char(189), [string.char(226)] = string.char(190), [string.char(227)] = string.char(191), [string.char(228)] = string.char(184), [string.char(229)] = string.char(185), [string.char(230)] = string.char(186), [string.char(231)] = string.char(187), [string.char(232)] = string.char(180), [string.char(233)] = string.char(181), [string.char(234)] = string.char(182), [string.char(235)] = string.char(183), [string.char(236)] = string.char(176), [string.char(237)] = string.char(177), [string.char(238)] = string.char(178), [string.char(239)] = string.char(179), [string.char(240)] = string.char(172), [string.char(241)] = string.char(173), [string.char(242)] = string.char(174), [string.char(243)] = string.char(175), [string.char(244)] = string.char(168), [string.char(245)] = string.char(169), [string.char(246)] = string.char(170), [string.char(247)] = string.char(171), [string.char(248)] = string.char(164), [string.char(249)] = string.char(165), [string.char(250)] = string.char(166), [string.char(251)] = string.char(167), [string.char(252)] = string.char(160), [string.char(253)] = string.char(161), [string.char(254)] = string.char(162), [string.char(255)] = string.char(163), } local xor_with_0x36 = { [string.char( 0)] = string.char( 54), [string.char( 1)] = string.char( 55), [string.char( 2)] = string.char( 52), [string.char( 3)] = string.char( 53), [string.char( 4)] = string.char( 50), [string.char( 5)] = string.char( 51), [string.char( 6)] = string.char( 48), [string.char( 7)] = string.char( 49), [string.char( 8)] = string.char( 62), [string.char( 9)] = string.char( 63), [string.char( 10)] = string.char( 60), [string.char( 11)] = string.char( 61), [string.char( 12)] = string.char( 58), [string.char( 13)] = string.char( 59), [string.char( 14)] = string.char( 56), [string.char( 15)] = string.char( 57), [string.char( 16)] = string.char( 38), [string.char( 17)] = string.char( 39), [string.char( 18)] = string.char( 36), [string.char( 19)] = string.char( 37), [string.char( 20)] = string.char( 34), [string.char( 21)] = string.char( 35), [string.char( 22)] = string.char( 32), [string.char( 23)] = string.char( 33), [string.char( 24)] = string.char( 46), [string.char( 25)] = string.char( 47), [string.char( 26)] = string.char( 44), [string.char( 27)] = string.char( 45), [string.char( 28)] = string.char( 42), [string.char( 29)] = string.char( 43), [string.char( 30)] = string.char( 40), [string.char( 31)] = string.char( 41), [string.char( 32)] = string.char( 22), [string.char( 33)] = string.char( 23), [string.char( 34)] = string.char( 20), [string.char( 35)] = string.char( 21), [string.char( 36)] = string.char( 18), [string.char( 37)] = string.char( 19), [string.char( 38)] = string.char( 16), [string.char( 39)] = string.char( 17), [string.char( 40)] = string.char( 30), [string.char( 41)] = string.char( 31), [string.char( 42)] = string.char( 28), [string.char( 43)] = string.char( 29), [string.char( 44)] = string.char( 26), [string.char( 45)] = string.char( 27), [string.char( 46)] = string.char( 24), [string.char( 47)] = string.char( 25), [string.char( 48)] = string.char( 6), [string.char( 49)] = string.char( 7), [string.char( 50)] = string.char( 4), [string.char( 51)] = string.char( 5), [string.char( 52)] = string.char( 2), [string.char( 53)] = string.char( 3), [string.char( 54)] = string.char( 0), [string.char( 55)] = string.char( 1), [string.char( 56)] = string.char( 14), [string.char( 57)] = string.char( 15), [string.char( 58)] = string.char( 12), [string.char( 59)] = string.char( 13), [string.char( 60)] = string.char( 10), [string.char( 61)] = string.char( 11), [string.char( 62)] = string.char( 8), [string.char( 63)] = string.char( 9), [string.char( 64)] = string.char(118), [string.char( 65)] = string.char(119), [string.char( 66)] = string.char(116), [string.char( 67)] = string.char(117), [string.char( 68)] = string.char(114), [string.char( 69)] = string.char(115), [string.char( 70)] = string.char(112), [string.char( 71)] = string.char(113), [string.char( 72)] = string.char(126), [string.char( 73)] = string.char(127), [string.char( 74)] = string.char(124), [string.char( 75)] = string.char(125), [string.char( 76)] = string.char(122), [string.char( 77)] = string.char(123), [string.char( 78)] = string.char(120), [string.char( 79)] = string.char(121), [string.char( 80)] = string.char(102), [string.char( 81)] = string.char(103), [string.char( 82)] = string.char(100), [string.char( 83)] = string.char(101), [string.char( 84)] = string.char( 98), [string.char( 85)] = string.char( 99), [string.char( 86)] = string.char( 96), [string.char( 87)] = string.char( 97), [string.char( 88)] = string.char(110), [string.char( 89)] = string.char(111), [string.char( 90)] = string.char(108), [string.char( 91)] = string.char(109), [string.char( 92)] = string.char(106), [string.char( 93)] = string.char(107), [string.char( 94)] = string.char(104), [string.char( 95)] = string.char(105), [string.char( 96)] = string.char( 86), [string.char( 97)] = string.char( 87), [string.char( 98)] = string.char( 84), [string.char( 99)] = string.char( 85), [string.char(100)] = string.char( 82), [string.char(101)] = string.char( 83), [string.char(102)] = string.char( 80), [string.char(103)] = string.char( 81), [string.char(104)] = string.char( 94), [string.char(105)] = string.char( 95), [string.char(106)] = string.char( 92), [string.char(107)] = string.char( 93), [string.char(108)] = string.char( 90), [string.char(109)] = string.char( 91), [string.char(110)] = string.char( 88), [string.char(111)] = string.char( 89), [string.char(112)] = string.char( 70), [string.char(113)] = string.char( 71), [string.char(114)] = string.char( 68), [string.char(115)] = string.char( 69), [string.char(116)] = string.char( 66), [string.char(117)] = string.char( 67), [string.char(118)] = string.char( 64), [string.char(119)] = string.char( 65), [string.char(120)] = string.char( 78), [string.char(121)] = string.char( 79), [string.char(122)] = string.char( 76), [string.char(123)] = string.char( 77), [string.char(124)] = string.char( 74), [string.char(125)] = string.char( 75), [string.char(126)] = string.char( 72), [string.char(127)] = string.char( 73), [string.char(128)] = string.char(182), [string.char(129)] = string.char(183), [string.char(130)] = string.char(180), [string.char(131)] = string.char(181), [string.char(132)] = string.char(178), [string.char(133)] = string.char(179), [string.char(134)] = string.char(176), [string.char(135)] = string.char(177), [string.char(136)] = string.char(190), [string.char(137)] = string.char(191), [string.char(138)] = string.char(188), [string.char(139)] = string.char(189), [string.char(140)] = string.char(186), [string.char(141)] = string.char(187), [string.char(142)] = string.char(184), [string.char(143)] = string.char(185), [string.char(144)] = string.char(166), [string.char(145)] = string.char(167), [string.char(146)] = string.char(164), [string.char(147)] = string.char(165), [string.char(148)] = string.char(162), [string.char(149)] = string.char(163), [string.char(150)] = string.char(160), [string.char(151)] = string.char(161), [string.char(152)] = string.char(174), [string.char(153)] = string.char(175), [string.char(154)] = string.char(172), [string.char(155)] = string.char(173), [string.char(156)] = string.char(170), [string.char(157)] = string.char(171), [string.char(158)] = string.char(168), [string.char(159)] = string.char(169), [string.char(160)] = string.char(150), [string.char(161)] = string.char(151), [string.char(162)] = string.char(148), [string.char(163)] = string.char(149), [string.char(164)] = string.char(146), [string.char(165)] = string.char(147), [string.char(166)] = string.char(144), [string.char(167)] = string.char(145), [string.char(168)] = string.char(158), [string.char(169)] = string.char(159), [string.char(170)] = string.char(156), [string.char(171)] = string.char(157), [string.char(172)] = string.char(154), [string.char(173)] = string.char(155), [string.char(174)] = string.char(152), [string.char(175)] = string.char(153), [string.char(176)] = string.char(134), [string.char(177)] = string.char(135), [string.char(178)] = string.char(132), [string.char(179)] = string.char(133), [string.char(180)] = string.char(130), [string.char(181)] = string.char(131), [string.char(182)] = string.char(128), [string.char(183)] = string.char(129), [string.char(184)] = string.char(142), [string.char(185)] = string.char(143), [string.char(186)] = string.char(140), [string.char(187)] = string.char(141), [string.char(188)] = string.char(138), [string.char(189)] = string.char(139), [string.char(190)] = string.char(136), [string.char(191)] = string.char(137), [string.char(192)] = string.char(246), [string.char(193)] = string.char(247), [string.char(194)] = string.char(244), [string.char(195)] = string.char(245), [string.char(196)] = string.char(242), [string.char(197)] = string.char(243), [string.char(198)] = string.char(240), [string.char(199)] = string.char(241), [string.char(200)] = string.char(254), [string.char(201)] = string.char(255), [string.char(202)] = string.char(252), [string.char(203)] = string.char(253), [string.char(204)] = string.char(250), [string.char(205)] = string.char(251), [string.char(206)] = string.char(248), [string.char(207)] = string.char(249), [string.char(208)] = string.char(230), [string.char(209)] = string.char(231), [string.char(210)] = string.char(228), [string.char(211)] = string.char(229), [string.char(212)] = string.char(226), [string.char(213)] = string.char(227), [string.char(214)] = string.char(224), [string.char(215)] = string.char(225), [string.char(216)] = string.char(238), [string.char(217)] = string.char(239), [string.char(218)] = string.char(236), [string.char(219)] = string.char(237), [string.char(220)] = string.char(234), [string.char(221)] = string.char(235), [string.char(222)] = string.char(232), [string.char(223)] = string.char(233), [string.char(224)] = string.char(214), [string.char(225)] = string.char(215), [string.char(226)] = string.char(212), [string.char(227)] = string.char(213), [string.char(228)] = string.char(210), [string.char(229)] = string.char(211), [string.char(230)] = string.char(208), [string.char(231)] = string.char(209), [string.char(232)] = string.char(222), [string.char(233)] = string.char(223), [string.char(234)] = string.char(220), [string.char(235)] = string.char(221), [string.char(236)] = string.char(218), [string.char(237)] = string.char(219), [string.char(238)] = string.char(216), [string.char(239)] = string.char(217), [string.char(240)] = string.char(198), [string.char(241)] = string.char(199), [string.char(242)] = string.char(196), [string.char(243)] = string.char(197), [string.char(244)] = string.char(194), [string.char(245)] = string.char(195), [string.char(246)] = string.char(192), [string.char(247)] = string.char(193), [string.char(248)] = string.char(206), [string.char(249)] = string.char(207), [string.char(250)] = string.char(204), [string.char(251)] = string.char(205), [string.char(252)] = string.char(202), [string.char(253)] = string.char(203), [string.char(254)] = string.char(200), [string.char(255)] = string.char(201), } local blocksize = 64 -- 512 bits function M.hmac_sha1(key, text) assert(type(key) == 'string', "key passed to hmac_sha1 should be a string") assert(type(text) == 'string', "text passed to hmac_sha1 should be a string") if #key > blocksize then key = sha1_binary(key) end local key_xord_with_0x36 = key:gsub('.', xor_with_0x36) .. string.rep(string.char(0x36), blocksize - #key) local key_xord_with_0x5c = key:gsub('.', xor_with_0x5c) .. string.rep(string.char(0x5c), blocksize - #key) return M.sha1(key_xord_with_0x5c .. M.sha1_binary(key_xord_with_0x36 .. text)) end function M.hmac_sha1_binary(key, text) return hex_to_binary(M.hmac_sha1(key, text)) end return M --[[------------ VALIDATION TESTS -- uncomment to execute ------------------------------------ print(1) assert(sha1 "http://regex.info/blog/" == "7f103bf600de51dfe91062300c14738b32725db5", 1) print(2) assert(sha1(string.rep("a", 10000)) == "a080cbda64850abb7b7f67ee875ba068074ff6fe", 2) print(3) assert(sha1 "abc" == "a9993e364706816aba3e25717850c26c9cd0d89d", 3) print(4) assert(sha1 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" == "84983e441c3bd26ebaae4aa1f95129e5e54670f1", 4) print(5) assert(sha1 "The quick brown fox jumps over the lazy dog" == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", 5) print(6) assert(sha1 "The quick brown fox jumps over the lazy cog" == "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3", 6) -- a few randomly generated tests print(7) assert("efb750130b6cc9adf4be219435e575442ec68b7c" == sha1(string.char(136,43,218,202,158,86,64,140,154,173,20,184,170,125,37,54,208,68,171,24,164,89,142,111,148,235,187,181,122):rep(76)), 7) print(8) assert("432dff9d4023e13194170287103d0377ed182d96" == sha1(string.char(20,174):rep(407)), 8) print(9) assert("ccba5c47946530726bb86034dbee1dbf0c203e99" == sha1(string.char(20,54,149,252,176,4,96,100,223):rep(753)), 9) print(10) assert("4d6fea4f8576cd6648ae2d2ee4dc5df0a8309115" == sha1(string.char(118,171,221,33,54,209,223,152,35,67,88,50):rep(985)), 10) print(11) assert("f560412aabf813d01f15fdc6650489584aabd266" == sha1(string.char(23,85,29,13,146,55,164,14,206,196,109,183,53,92,97,123,242,220,112,15,43,113,22,246,114,29,209,219,190):rep(177)), 11) print(12) assert("b56795e12f3857b3ba1cbbcedb4d92dd9c419328" == sha1(string.char(21,216):rep(131)), 12) print(13) assert("54f292ecb7561e8ce27984685b427234c9465095" == sha1(string.char(15,205,12,181,4,114,128,118,219):rep(818)), 13) print(14) assert("fe265c1b5a848e5f3ada94a7e1bb98a8ce319835" == sha1(string.char(136,165,10,46,167,184,86,255,58,206,237,21,255,15,198,211,145,112,228,146,26,69,92,158,182,165,244,39,152):rep(605)), 14) print(15) assert("96f186998825075d528646059edadb55fdd96659" == sha1(string.char(100,226,28,248,132,70,221,54,92,181,82,128,191,12,250,244):rep(94)), 15) print(16) assert("e29c68e4d6ffd3998b2180015be9caee59dd8c8a" == sha1(string.char(247,14,15,163,0,53,50,113,84,121):rep(967)), 16) print(17) assert("6d2332a82b3600cbc5d2417f944c38be9f1081ae" == sha1(string.char(93,98,119,201,41,27,89,144,25,141,117,26,111,132):rep(632)), 17) print(18) assert("d84a91da8fb3aa7cd59b99f347113939406ef8eb" == sha1(string.char(28,252,0,4,150,164,91):rep(568)), 18) print(19) assert("8edf1b92ad5a90ed762def9a873a799b4bda97f9" == sha1(string.char(166,67,113,111,161,253,169,195,158,97,96,150,49,219,103,16,186,184,37,109,228,111):rep(135)), 19) print(20) assert("d5b2c7019f9ff2f75c38dc040c827ab9d1a42157" == sha1(string.char(38,252,110,224,168,60,2,133,8,153,200,0,199,104,191,62,28,168,73,48,199,217,83):rep(168)), 20) print(21) assert("5aeb57041bfada3b72e3514f493d7b9f4ca96620" == sha1(string.char(57):rep(738)), 21) print(22) assert("4548238c8c2124c6398427ed447ae8abbb8ead27" == sha1(string.char(221,131,171):rep(230)), 22) print(23) assert("ed0960b87a790a24eb2890d8ea8b18043f1a87d5" == sha1(string.char(151,113,144,19,249,148,75,51,164,233,102,232,3,58,81,99,101,255,93,231,147,150,212,216,109,62):rep(110)), 23) print(24) assert("d7ac6233298783af55901907bb99c13b2afbca99" == sha1(string.char(44,239,189,203,196,79,82,143,99,21,125,75,167,26,108,161,9,193,72):rep(919)), 24) print(25) assert("43600b41a3c5267e625bbdfde95027429c330c60" == sha1(string.char(122,70,129,24,192,213,205,224,62,79,81,129,22,171):rep(578)), 25) print(26) assert("5816df09a78e4594c1b02b170aa57333162def38" == sha1(string.char(76,103,48,150,115,161,86,42,247,82,197,213,155,108,215,18,119):rep(480)), 26) print(27) assert("ef7903b1e811a086a9a5a5142242132e1367ae1d" == sha1(string.char(143,70):rep(65)), 27) print(28) assert("6e16b2dac71e338a4bd26f182fdd5a2de3c30e6c" == sha1(string.char(130,114,144,219,245,72,205,44,149,68,150,169,243):rep(197)), 28) print(29) assert("6cc772f978ca5ef257273f046030f84b170f90c9" == sha1(string.char(26,49,141,64,30,61,12):rep(362)), 29) print(30) assert("54231fc19a04a64fc1aa3dce0882678b04062012" == sha1(string.char(76,252,160,253,253,167,27,179,237,15,219,46,141,255,23,53,184,190,233,125,211,11):rep(741)), 30) print(31) assert("5511a993b808e572999e508c3ce27d5f12bb4730" == sha1(string.char(197,139,184,188,200,31,171,236,252,147,123,75,7,138,111,167,68,114,73,80,51,233,241,233,91):rep(528)), 31) print(32) assert("64c4577d4763c95f47ac5d21a292836a34b8b124" == sha1(string.char(177,114,100,216,18,57,2,110,108,60,81,80,253,144,179,47,228,42,105,72,86,18,30,167):rep(901)), 32) print(33) assert("bb0467117e3b630c2b3d9cdf063a7e6766a3eae1" == sha1(string.char(249,99,174,228,15,211,121,152,203,115,197,198,66,17,196,6,159,170,116):rep(800)), 33) print(34) assert("1f9c66fca93bc33a071eef7d25cf0b492861e679" == sha1(string.char(205,64,237,65,171,0,176,17,104,6,101,29,128,200,214,24,32,91,115,71,26,11,226,69,141,83,249,129):rep(288)), 34) print(35) assert("55d228d9bfd522105fe1e1f1b5b09a1e8ee9f782" == sha1(string.char(96,37,252,185,137,194,215,191,190,235,73,224,125,18,146,74,32,82,58,95,49,102,85,57,241,54,55):rep(352)), 35) print(36) assert("58c3167e666bf3b4062315a84a72172688ad08b1" == sha1(string.char(65,91,96,147,212,18,32,144,138,187,70,26,105,42,71,13,229,137,185,10,86,124,171,204,104,42,2,172):rep(413)), 36) print(37) assert("f97936ca990d1c11a9967fd12fc717dcd10b8e9e" == sha1(string.char(253,159,59,76,230,153,22,198,15,9,223,3,31):rep(518)), 37) print(38) assert("5d15229ad10d2276d45c54b83fc0879579c2828e" == sha1(string.char(149,20,176,144,39,216,82,80,56,38,152,49,167,120,222,20,26,51,157,131,160,52,6):rep(895)), 38) print(39) assert("3757d3e98d46205a6b129e09b0beefaa0e453e64" == sha1(string.char(120,131,113,78,7,19,59,120,210,220,73,118,36,240,64,46,149,3,120,223,80,232,255,212,250,76,109,108,133):rep(724)), 39) print(40) assert("5e62539caa6c16752739f4f9fd33ca9032fff7e1" == sha1(string.char(216,240,166,165,2,203,2,189,137,219,231,229):rep(61)), 40) print(41) assert("3ff1c031417e7e9a34ce21be6d26033f66cb72c9" == sha1(string.char(4,178,215,183,17,198,184,253,137,108,178,74,244,126,32):rep(942)), 41) print(42) assert("8c20831fc3c652e5ce53b9612878e0478ab11ee6" == sha1(string.char(115,157,59,188,221,67,52,151,147,233,84,30,243,250,109,103,101,0,219,13,176,38,21):rep(767)), 42) print(43) assert("09c7c977cb39893c096449770e1ed75eebb9e5a1" == sha1(string.char(184,131,17,61,201,164,19,25,36,141,173,74,134,132,104,23,104,136,121,232,12,203,115,111,54,114,251,223,61,126):rep(458)), 43) print(44) assert("9534d690768bc85d2919a059b05561ec94547fc2" == sha1(string.char(49,93,136,112,92,42,117,28,31):rep(187)), 44) print(45) assert("7dfca0671de92a62de78f63c0921ff087f2ba61d" == sha1(string.char(194,78,252,112,175,6,26,103,4,47,195,99,78,130,40,58,84,175,240,180,255,108,3,42,51,111,35,49,217,160):rep(72)), 45) print(46) assert("62bf20c51473c6a0f23752e369cabd6c167c9415" == sha1(string.char(28,126,243,196,155,31,158,50):rep(166)), 46) print(47) assert("2ece95e43aba523cdbf248d07c05f569ecd0bd12" == sha1(string.char(76,230,117,248,231,228):rep(294)), 47) print(48) assert("722752e863386b737f29a08f23a0ec21c4313519" == sha1(string.char(61,102,1,118):rep(470)), 48) print(49) assert("a638db01b5af10a828c6e5b73f4ca881974124a0" == sha1(string.char(130,8,4):rep(768)), 49) print(50) assert("54c7f932548703cc75877195276bc2aa9643cf9b" == sha1(string.char(193,232,122,142,213,243,224,29,201,6,127,45,4,36,92,200,148,111,106,110,221,235,197,51,66,221,123,155,222,186):rep(290)), 50) print(51) assert("ecfc29397445d85c0f6dd6dc50a1272accba0920" == sha1(string.char(221,76,21,148,12,109,232,113,230,110,96,82,36):rep(196)), 51) print(52) assert("31d966d9540f77b49598fa22be4b599c3ba307aa" == sha1(string.char(148,237,212,223,44,133,153):rep(53)), 52) print(53) assert("9f97c8ace98db9f61d173bf2b705404eb2e9e283" == sha1(string.char(190,233,29,208,161,231,248,214,210):rep(451)), 53) print(54) assert("63449cfce29849d882d9552947ebf82920392aea" == sha1(string.char(216,12,113,137,33,99,200,140,6,222,170,2,115,50,138,134,211,244,176,250,42,95):rep(721)), 54) print(55) assert("15dc62f4469fb9eae76cd86a84d576905c4bbfe7" == sha1(string.char(50,194,13,88,156,226,39,135,165,204):rep(417)), 55) print(56) assert("abbc342bcfdb67944466e7086d284500e25aa103" == sha1(string.char(35,39,227,31,206,163,148,163,172,253,98,21,215,43,226,227,130,151,236,177,176,63,30,47,74):rep(960)), 56) print(57) assert("77ae3a7d3948eaa2c60d6bc165ba2812122f0cce" == sha1(string.char(166,83,82,49,153,89,58,79,131,163,125,18,43,135,120,17,48,94,136):rep(599)), 57) print(58) assert("d62e1c4395c8657ab1b1c776b924b29a8e009de1" == sha1(string.char(196,199,71,80,10,233,9,229,91,72,73,205,75,77,122,243,219,152):rep(964)), 58) print(59) assert("15d98d5279651f4a2566eda6eec573812d050ff7" == sha1(string.char(78,70,7,229,21,78,164,158,114,232,100,102,92,18,133,160,56,177,160,49,168,149,13,39,249,214,54,41):rep(618)), 59) print(60) assert("c3d9bc6535736f09fbb018427c994e58bbcb98f6" == sha1(string.char(129,208,110,40,135,3):rep(618)), 60) print(61) assert("7dc6b3f309cbe9fa3b2947c2526870a39bf96dc4" == sha1(string.char(126,184,110,39,55,177,108,179,214,200,175,118,125,212,19,147,137,133,89,209,89,189,233,164,71,81,156,215,152):rep(908)), 61) print(62) assert("b2d4ca3e787a1e475f6608136e89134ae279be57" == sha1(string.char(182,80,145,53,128,194,228,155,53):rep(475)), 62) print(63) assert("fbe6b9c3a7442806c5b9491642c69f8e56fdd576" == sha1(string.char(9,208,72,179,222,245,140,143,123,111,236,241,40,36,49,68,61,16,169,124,104,42,136,82,172):rep(189)), 63) print(64) assert("f87d96380201954801004f6b82af1953427dfdcb" == sha1(string.char(153,133,37,2,24,150,93,242,223,68,202,54,118,141,76,35,100,137,13):rep(307)), 64) print(65) assert("a953e2d054dd77f75337dd9dfa58ec4d3978cfb4" == sha1(string.char(112,215,41,50,221,94):rep(155)), 65) print(66) assert("e5c3047f9abfdd60f0c386b9a820f11d7028bc70" == sha1(string.char(247,177,124,213,47,175,139,203,81,21,85):rep(766)), 66) print(67) assert("ee6fe88911a13abfc0006f8809f51b9de7f5920f" == sha1(string.char(81,84,151,242,186,133,39,245,175,79,66,170,246,216,0,88,100,190,137,2,146,58):rep(10)), 67) print(68) assert("091db84d93bb68349eecf6bfa9378251ecd85500" == sha1(string.char(180,71,122,187):rep(129)), 68) print(69) assert("d8041c7d65201cc5a77056a5c7eb94a524494754" == sha1(string.char(188,99,87,126,152,214,159,151,234,223,199,247,213,107,63,59,12,146,175,57,79,200,132,202):rep(81)), 69) print(70) assert("cca1d77faf56f70c82fcb7bc2c0ac9daf553adff" == sha1(string.char(199,1,184,22,113,25,95,87,169,114,130,205,125,159,170,99):rep(865)), 70) print(71) assert("c009245d9767d4f56464a7b3d6b8ad62eba5ddeb" == sha1(string.char(39,168,16,191,95,82,184,102,242,224,15,108):rep(175)), 71) print(72) assert("8ce115679600324b58dc8745e38d9bea0a9fb4d6" == sha1(string.char(164,247,250,142,139,131,158,241,27,36,81,239,26,233,105,64,38,249,151,75,142,17,56,217,125,74,132,213,213):rep(426)), 72) print(73) assert("75f1e55718fd7a3c27792634e70760c6a390d40f" == sha1(string.char(32,145,170,90,188,97,251,159,244,153,21,126,2,67,36,110,31,251,66):rep(659)), 73) print(74) assert("615722261d6ec8cef4a4e7698200582958193f26" == sha1(string.char(51,24,1,69,81,157,34,185,26,159,231,119):rep(994)), 74) print(75) assert("4f61d2c1b60d342c51bc47641e0993d42e89c0f9" == sha1(string.char(175,25,99,122,247,217,204,100,0,35,57,65,150,182,51,79,169,99,9,33,113,113,113):rep(211)), 75) print(76) assert("7d9842e115fc2af17a90a6d85416dbadb663cef3" == sha1(string.char(136,42,39,219,103,95,119,125,205,72,174,15,210,213,23,75,120,56,104,31,63,255,253,100,61,55):rep(668)), 76) print(77) assert("3eccab72b375de3ba95a9f0fa715ae13cae82c08" == sha1(string.char(190,254,173,227,195,41,49,122,135,57,100):rep(729)), 77) print(78) assert("7dd68f741731211e0442ce7251e56950e0d05f96" == sha1(string.char(101,155,117,8,143,40,192,100,162,121,142,191,92):rep(250)), 78) print(79) assert("5e98cdb7f6d7e4e2466f9be23ec20d9177c5ddff" == sha1(string.char(84,67,182,136,89):rep(551)), 79) print(80) assert("dba1c76e22e2c391bde336c50319fbff2d66c3bb" == sha1(string.char(99,226,185,1,192):rep(702)), 80) print(81) assert("4b160b8bfe24147b01a247bfdc7a5296b6354e38" == sha1(string.char(144,141,254,1,166,144,129,232,203,31,192,75,145,12):rep(724)), 81) print(82) assert("27625ad9833144f6b818ef1cf54245dd4897d8aa" == sha1(string.char(31,187,82,156,224,133,116,251,180,165,246,8):rep(661)), 82) print(83) assert("0ce5e059d22a7ba5e2af9f0c6551d010b08ba197" == sha1(string.char(228):rep(672)), 83) print(84) assert("290982513a7f67a876c043d3c7819facb9082ea6" == sha1(string.char(150,44,52,144,68,76,207,114,106,153,99,39,219,81,73,140,71,4,228,220,55,244,210,225,221,32):rep(881)), 84) print(85) assert("14cf924aafceea393a8eb5dd06616c1fe1ccd735" == sha1(string.char(140,194,247,253,117,121,184,216,249,84,41,12,199):rep(738)), 85) print(86) assert("91e9cc620573db9a692bb0171c5c11b5946ad5c3" == sha1(string.char(48,77,182,152,26,145,231,116,179,95,21,248,120,55,73,66):rep(971)), 86) print(87) assert("3eb85ec3db474d01acafcbc5ec6e942b3a04a382" == sha1(string.char(68,211):rep(184)), 87) print(88) assert("f9bd0e886c74d730cb2457c484d30ce6a47f7afa" == sha1(string.char(168,73,19,144,110,93,7,216,40,111,212,192,33,9,136,28,210,175,140,47,125,243,206,157,151,252,26):rep(511)), 88) print(89) assert("64461476eb8bba70e322e4b83db2beaee5b495d4" == sha1(string.char(33,141):rep(359)), 89) print(90) assert("761e44ffa4df3b4e28ca22020dee1e0018107d21" == sha1(string.char(254,172,185,30,245,135,14,5,186,42,47,22):rep(715)), 90) print(91) assert("41161168b99104087bae0f5287b10a15c805596f" == sha1(string.char(79):rep(625)), 91) print(92) assert("7088f4d88146e6e7784172c2ad1f59ec39fa7768" == sha1(string.char(20,138,80,102,138,182,54,210,38,214,125,123,157,209,215,37):rep(315)), 92) print(93) assert("2e498e938cb3126ac1291cee8c483a91479900c1" == sha1(string.char(140,197,97,112,205,97,134,190):rep(552)), 93) print(94) assert("81a2491b727ef2b46fb84e4da2ced84d43587f4e" == sha1(string.char(109,44,17,199,17,107,170,54,113,153,212,161,174):rep(136)), 94) print(95) assert("0e4f8a07072968fbc4fe32deccbb95f113b32df7" == sha1(string.char(181,247,203,166,34,61,180,48,46,77,98,251,72,210,217,242,135,133,38,12,177,163,249,31,1,162):rep(282)), 95) print(96) assert("8d15dddd48575a1a0330976b57e2104629afe559" == sha1(string.char(15,60,105,249,158,45,14,208,202,232,255,181,234,217):rep(769)), 96) print(97) assert("98a9dd7b57418937cbd42f758baac4754d5a4a4b" == sha1(string.char(115,121,91,76,175,110,149,190,56,178,191,157,101,220,190,251,62,41,190,37):rep(879)), 97) print(98) assert("578487979de082f69e657d165df5031f1fa84030" == sha1(string.char(189,240,198,207,102,142,241,154):rep(684)), 98) print(99) assert("3e6667b40afb6bcc052654dd64a653ad4b4f9689" == sha1(string.char(85,82,55,80,43,17,57,20,157,10,148,85,154,58,254,254,221,132,53,105,43,234,251,110,111):rep(712)), 99) -- -- now tests for the HMAC-SHA1 computation -- assert("31285f3fa3c6a086d030cf0f06b07e7a96b5cbd0" == hmac_sha1("63xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "data"), 100) assert("2d183212abc09247e21282d366eeb14d0bc41fb4" == hmac_sha1("64xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "data"), 101) assert("ff825333e64e696fc13d82c19071fa46dc94a066" == hmac_sha1("65xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "data"), 102) print(103) assert("ecc8b5d3abb5182d3d570a6f060fef2ee6c11a44" == hmac_sha1(string.char(220,58,17,206,77,234,240,187,69,25,179,182,186,38,57,83,120,107,198,148,234,246,46,96,83,28,231,89,3,169,42,62,125,235,137), string.char(1,225,98,83,100,71,237,241,239,170,244,215,3,254,14,24,216,66,69,30,124,126,96,177,241,20,44,3,92,111,243,169,100,119,198,167,146,242,30,124,7,22,251,52,235,95,211,145,56,204,236,37,107,139,17,184,65,207,245,101,241,12,50,149,19,118,208,133,198,33,80,94,87,133,146,202,27,89,201,218,171,206,21,191,43,77,127,30,187,194,166,39,191,208,42,167,77,202,186,225,4,86,218,237,157,117,175,106,63,166,132,136,153,243,187)), 103) print(104) assert("bd1577a9417d804ee2969636fa9dde838beb967d" == hmac_sha1(string.char(216,76,38,50,235,99,92,110,245,5,134,195,113,7), string.char(144,3,250,84,145,227,206,87,188,42,169,182,106,31,207,205,33,76,52,158,255,49,129,169,9,145,203,225,90,228,163,33,49,99,29,135,60,112,152,5,200,121,35,77,56,116,68,109,190,136,184,248,144,172,47,107,30,16,105,232,146,137,24,81,245,94,28,76,27,82,105,146,252,219,119,164,21,14,74,192,209,208,156,56,172,124,89,218,51,108,44,174,193,161,228,147,219,129,172,210,248,239,22,11,62,128,1,50,98,233,141,224,102,152,44,68,66,46,210,114,138,113,121,90,7,70,125,191,192,222,225,200,217,48,22,10,132,29,236,71,108,140,102,96,51,142,51,220,4)), 104) print(105) assert("e8ddf90f0c117ee61b33db4df49d7fc31beca7f7" == hmac_sha1(string.char(189,213,184,86,24,160,198,82,138,223,71,149,249,70,183,47,0,106,27,39,85,102,57,190,237,182,2,10,21,253,252,3,68,73,154,75,79,247,28,132,229,50,2,197,204,213,170,213,255,83,100,213,60,67,202,61,137,125,16,215,254,157,106,5), string.char(78,103,249,15,43,214,87,62,52,57,135,84,44,92,142,209,120,139,76,216,33,223,203,96,218,12,6,126,241,195,47,203,196,22,113,138,228,44,122,37,215,166,184,195,91,97,175,153,115,243,37,225,82,250,54,240,20,237,149,183,5,43,142,113,214,130,100,149,83,232,70,106,152,110,25,74,46,60,159,239,193,173,235,146,173,142,110,71,1,97,54,217,52,228,250,42,223,53,105,24,87,98,117,245,101,189,147,238,48,111,68,52,169,78,151,38,21,249)), 105) print(106) assert("e33c987c31bb45b842868d49e7636bd840a1ffd3" == hmac_sha1(string.char(154,60,91,199,157,45,32,99,248,5,163,234,114,223,234,48,238,82,43,242,52,176,243,5,135,26,141,49,105,120,220,135,192,96,219,152,126,74,58,110,200,56,108,1,68,175,82,235,149,191,67,72,195,46,35,131,237,188,177,223,145,122,26,234,136,93,34,96,71,214,55,27,13,116,235,109,58,83,175,226,59,13,218,93,5,132,43,235), string.char(182,10,154)), 106) print(107) assert("f6039d217c16afadfcfae7c5e3d1859801a0fe22" == hmac_sha1(string.char(73,120,173,165,190,159,174,100,255,56,217,98,249,11,166,25,66,95,96,99,70,73,223,132,231,147,220,151,79,102,111,98), string.char(134,93,229,103)), 107) print(108) assert("f6056b19cf6b070e62a0917a46f4b3aefcf6262d" == hmac_sha1(string.char(49,40,62,214,208,180,147,74,162,196,193,9,118,47,100,9,235,94,3,122,226,163,145,175,233,148,251,88,49,216,208,110,13,97,255,189,120,252,223,241,55,210,77,4), string.char(92,185,37,240,36,97,21,132,188,80,103,36,162,245,63,104,19,106,242,44,96,28,197,26,46,168,73,46,76,105,30,167,101,64,67,119,65,140,177,226,223,108,206,60,59,0,182,125,42,200,101,159,109,6,62,85,67,66,88,137,92,234,61,19,22,177,144,127,129,129,195,230,180,149,128,148,45,18,94,163,196,55,70,184,251,3,200,162,16,210,188,61,186,218,173,227,212,8,125,20,138,82,68,170,24,158,90,98,228,166,246,96,74,24,217,93,91,102,246,221,121,115,157,243,45,158,45,90,186,11,127,179,59,72,37,71,148,123,62,150,114,167,248,197,18,251,92,164,158,83,129,58,127,162,181,92,85,121,13,118,250,221,220,150,231,5,230,28,213,25,251,17,71,68,234,173,10,206,111,72,123,205,49,73,62,209,173,46,94,91,151,122)), 108) print(109) assert("15ddfa1baa0a3723d8aff00aeefa27b5b02ede95" == hmac_sha1(string.char(91,117,129,150,117,169,221,182,193,130,126,206,129,177,184,171,174,224,91,234,60,197,243,158,59,0,122,240,145,106,192,179,96,84,46,239,170,123,120,51,142,101,45,34), string.char(27,71,38,183,232,93,23,174,151,181,121,91,142,138,180,125,75,243,160,220,225,205,205,72,13,162,104,218,47,162,77,23,16,154,31,156,122,67,227,25,190,102,200,57,116,190,131,8,208,76,174,53,204,88,227,239,71,67,208,32,57,72,165,121,80,139,80,29,90,32,229,208,115,169,238,189,206,82,180,68,157,124,119,1,75,27,122,246,197,178,90,225,138,244,73,12,226,104,191,70,53,210,245,250,239,238,3,229,196,22,28,199,122,158,9,33,109,182,109,87,25,159,159,146,217,77,37,25,173,211,38,173,70,252,18,193,7,167,160,135,63,190,149,14,221,143,173,152,184,143,157,245,137,219,74,239,185,40,14,0,29,87,169,84,67,75,255,252,201,131,75,108,43,129,210,193,108,139,60,228,29,36,150,15,86)), 109) print(110) assert("d7cba04970a79f5d04c772fbe74bcc0951ff9c67" == hmac_sha1(string.char(159,179,206,236,86,25,53,102,163,243,239,139,134,14,243), string.char(106,160,249,31,114,205,9,66,139,182,209,218,31,151,57,132,182,85,218,220,103,15,210,218,101,244,240,227,12,184,127,137,40,127,232,195,234,182,0,214,125,122,141,207,61,244,143,202,159,229,100,76,165,44,226,137,100,61,1,107,132,142,144,158,223,249,151,78,186,194,189,83,45,66,178,41,23,172,195,137,170,216,208,27,149,112,68,188,0)), 110) print(111) assert("84625a20dc9ada78ec9de910d37734a299f01c5d" == hmac_sha1(string.char(85,239,250,237,210,126,142,84,119,107,100,163,15,179,132,206,112,85,119,101,44,163,240,10,14,69,169,158,170,190,95,66,129,69,218,229), string.char(210,103,131,185,91,224,115,108,129,11,50,16,90,98,64,124,157,177,50,21,30,201,244,101,136,104,149,102,34,166,25,62,1,79,216,4,221,113,168,169,5,151,172,22,166,28,130,137,251,164,220,189,253,45,149,80,247,84,130,208,69,49,120,8,90,154,100,191,121,81,230,207,23,189,7,164,112,123,158,192,224,255,218,200,70,238,211,161,35,251,150,125,24,10,131,220,57,178,196,38,231,196,206,94,118,32,56,197,136,148,145,247,188,64,56,53,195,140,92,202,22,122,229,105,115,14,42,27,107,223,105)), 111) print(112) assert("c463318ac1878cd770ec93b2710b706296316894" == hmac_sha1(string.char(162,21,153,195,254,135,203,75,152,144,200,187,226,4,248,93,161,180,219,181,99,130,122,28,179,140,152,9,21,115,34,140,162,45,88,4,33,238,179,125,58,23,108,194,158,48,191,40,3,50,81,247,114,241,0,88,147,93,57,178,73,187,11,195,254,171,106,167,245,190,117,160,1,219,200,249,107,233,58,19,122), string.char(246,179,198,163,52,106,45,38,131,22,142,185,149,121,79,211,0,16,102,52,46,176,83,7,32,42,103,184,234,107,180,128,128,130,21,27,236)), 112) print(113) assert("e2d37df980593b3e52aadb0d99d61114fb2c1182" == hmac_sha1(string.char(43,84,125,158,182,211,26,238,222,247,6,171,184,54,70,44,169,4,74,34,98,71,118,189,138,53,8,164,117,22,76,171,57,255,122,230,110,122,228,22,252,123,174,218,222,77,80,150,159,43,236,137,234,48,122,138,100,137,112), string.char(249,234,226,86,109,2,157,76,229,42,178,223,196,247,42,194,17,17,117,3,45,6,80,202,22,105,44,242,84,25,21,189,5,216,35,200,220,192,110,81,215,145,109,179,48,44,40,35,216,240,48,240,33,210,79,35,64,189,81,15,135,228,83,14,254,32,211,229,158,79,188,230,84,106,78,126,226,106,203,59,67,134,186,52,21,48,2,142,231,116,241,167,177,175,74,188,232,234,56,41,181,118,232,190,184,76,64,109,167,178,123,118,3,50,46,254,253,83,156,116,220,247,69,27,160,167,210,205,79,60,28,253,17,219,32,44,217,223,77,153,229,55,113,75,234,154,247,13,133,49,220,200,241,111,136,205,14,78,222,55,181,250,160,143,224,37,63,227,155,12,39,173,209,45,171,93,93,70,36,129,111,173,183,112,31,231,22,146,129,171,75,128,45)), 113) print(114) assert("666f9c282cf544c9c28006713a7461c7efbbdbda" == hmac_sha1(string.char(71,33,203,83,173,199,175,245,206,13,237,187,54,61,85,15,153,125,168,223,231,56,46,250,173,192,247,189,45,166,225,223,109,254,15,79,144,188,71,201,70,25,218,205,13,184,204,219,221,82,133,189,144,179,242,125,211,108,100,1,132,110,231,87,107,91,169,101,241,105,30), string.char(98,122,51,157,136,38,149,9,82,27,218,155,76,61,254,154,43,172,59,105,123,45,97,146,191,58,50,153,139,40,37,116)), 114) print(115) assert("6904a4ce463002b03923c71cdac6c38f57315b63" == hmac_sha1(string.char(15,40,41,76,105,201,153,223,174,12,100,114,234,95,204,95,84,31,26,28,69,85,48,111,40,173,162,6,198,36,252,179,244,9,112,213,64,87,58,186,4,147,229,211,161,30,226,159,75,38,91,89,224,245,156,110,229,50,210), string.char(213,155,72,86,75,185,138,211,199,57,75,9,1,141,184,89,82,180,105,17,193,63,161,202,25,60,16,201,72,179,74,129,73,172,84,39,140,33,25,122,136,143,116,100,100,234,246,108,135,180,85,12,85,151,176,154,172,147,249,242,180,207,126,126,235,203,55,8,251,29,135,134,166,152,80,76,242,15,69,225,199,221,133,118,194,227,9,185,190,125,120,116,182,15,241,209,113,253,241,58,145,106,136,25,60,47,174,209,251,54,159,98,103,88,245,61,108,91,12,245,119,191,232,36)), 115) print(116) assert("c57c742c772f92cce60cf3a1ddc263b8df0950f3" == hmac_sha1(string.char(193,178,151,175,44,234,140,18,10,183,92,17,232,95,94,198,229,188,188,131,247,236,215,129,243,171,223,83,42,173,88,157,29,46,221,57,80,179,139,80), string.char(214,95,30,179,51,95,183,198,185,9,76,215,255,122,91,103,133,117,42,33,0,145,60,129,129,237,203,59,141,214,108,79,247,244,187,250,157,177,245,72,191,63,176,211)), 116) print(117) assert("092336f7f1767874098a54d5f27092fbb92b7c94" == hmac_sha1(string.char(208,10,217,108,72,232,56,67,6,179,160,172,29,67,115,171,118,82,124,118,61,111,21,132,209,92,212,166,181,129,43,55,198,96,169,112,86,212,68,214,81,239,122,216,104,73,114,209,60,182,248,118,74,100,26,1,176,3,166,188), string.char(42,4,235,56,198,119,175,244,93,77)), 117) print(118) assert("c1d58ad2b611c4d9d59e339da7952bdae4a70737" == hmac_sha1(string.char(100,129,37,207,188,116,232,140,204,90,90,93,124,132,140,81,102,156,67,254,228,192,150,161,10,62,143,218,237,111,151,98,78,168,188,87,170,190,35,228,169,228,143,252,213,85,11,124,92,91,18,27,122,141,98,6,77,106,205,209,2,185,249), string.char(58,190,56,255,176,80,220,228,0,251,108,108,220,197,51,131,164,162,60,181,21,54,122,174,31,13,4,84,198,203,105,11,64,230,1,30,218,208,252,219,44,147,2,108,227,66,49,71,21,95,248,93,193,180,165,240,224,226,13,9,208,186,12,118,243,28,113,49,122,192,212,164,43,41,151,183,187,126,115,85,174,40,125,9,54,193,164,95,21,77,200,226,50,115,187,122,34,141,255,224,239,12,132,191,48,102,205,248,128,164,116,48,39,191,98,53,169,230,249,215,231,152,45,27,226,10,143,15,209,157,208,181,15,210,195,5,29,48,29,125,62,59,191,216,170,179,226,110,40,46,32,130,235,48,234,233,17)), 118) print(119) assert("3de84c915278a7d5e7d5629ec88193fb5bbadd15" == hmac_sha1(string.char(89,175,111,33,154,12,173,230,28,117), string.char(188,233,41,180,142,157,96,76,105,212,92,202,155,167,179,28,12,156,64,73,32,253,253,166,9,240,7,0,248,43,101,135,226,231,173,221,180,43,160,217,6,38,183,186,214,217,137,83,148,148,40,141,217,98,209,12,167,102,95,166,136,231,232,84,59,112,148,201,166,104,135,124,189,85,160,183,143,122,200,190,144,205,25,254,180,188,108,225,171,131,240,185,86,243,192,173,130,50,150,57,242,180,132,193,11,110,247,121,25,24,110,199,156,121,233,149,79,103,15,173,184,143,45,125,164,242,125,10,183,189,189,135,121,59,148,106,77,9,16,123,176,100,142,246,156,180,202,87,43,102,113,123)), 119) print(120) assert("e8cc5a50f80e7d52edd7ae4ec037414b70798598" == hmac_sha1(string.char(139,243,17,238,11,156,138,122,212,86,201,213,100,167,65,199,92,182,255,36,221,82,192,213,199,162,69,42,222,95,65,170,146,48,39,185,147,18,140,122,168,141), string.char(141,216,25,29,235,207,123,188,85,53,131,180,125,226,97,244,250,138,64,39,30,250,146,101,219,171,213,158,164,172,137,22,136,86,46,77,95,213,66,198,15,24,164,148,29,166,169,195,196,111,122,147,247,215,148,9,129,40,133,178,69,242,171,235,181,83,241,208,237,17,37,30,188,152,47,214,69,229,114,225,75,172,163,184,38,158,230,177,187,124,33,240,238,148,197,235,237,98,33,237,59,205,147,128,108,254,95,5,6,49,10,224,78,139,164,235,220,78,224,15,213,136,198,217,114,156,130,247,167,64,36,10,183,221,193,220,195,80,125,143,248,228,254,6,221,137,170,211,66)), 120) print(121) assert("80d9a0bc9600e6a0130681158a1787ef6b9c91d6" == hmac_sha1(string.char(152,28,190,131,179,120,137,63,214,85,213,89,116,246,171,92,0,47,44,102,120,206,185,116,71,106,195), string.char(250,9,181,163,46,88,166,238,164,40,207,236,152,104,201,42,14,255,125,57,173,176,230,171,63,6,254,130,140,201,45,152,164,216,171,27,172,105,19,103,128,33,255,93,64,155,55,210,140,2,94,168,168,164,5,218,249,227,221,133,72,112,97,243,140,149,193,80)), 121) print(122) assert("cb4182de586a30d606a057c948fe33733145790a" == hmac_sha1(string.char(193,229,65,81,159,93,162,173,74,64,195,41,80,189,104,238,119,67,255,63,209,247,146,247,210,208,86,14,102,153,246,175,242,209,42,4,243,138,217,58,206,147,19,163,152,239,154,78,5,1,175,97,251,24,185,10,67,107,174,145,178,121,36,238,108,85,214,162,78,195,107,135,114,76,180,37,99,103,78,232,29,244,11,60,236,112,18,241,39,164,107,18), string.char(222,85,11,36,12,191,252,103,180,161,84,168,21,125,50,76,4,148,195,230,210,114,35,116,225,176,16,64,44,20,17,224,227,243,175,251,204,177,41,223,76,216,228,221,54,226,150,209,145,175,142,137,140,25,196,99,252,175,125,15,39,76,47,127,188,51,88,227,194,171,249,141,12,249,225,199,241,112,153,26,107,204,191,23,241,46,223,143,9,9,46,64,197,209,23,18,208,139,148,45,146,94,80,86,49,12,122,218,14,210,133,164,39,227,102,60,129,6,43)), 122) print(123) assert("864e291ec69124c3a43976bae4ba1788f181f027" == hmac_sha1(string.char(231,211,73,154,64,125,224,253,200,234,208,210,83,9), string.char(33,248,155,139,159,173,90,40,200,95,96,12,81,103,8,139,211,189,87,75,8,6,36,103,116,204,137,181,81,233,97,171,47,27,143,164,63,3,223,107,80,232,182,154,7,255,190,171,209,115,219,6,34,109,1,254,214,73,2)), 123) print(124) assert("bee434914e65818f81bd07e4e0bbb58328be3ca1" == hmac_sha1(string.char(222,123,148,175,157,117,104,212,169,13,252,113,231,104,37,8,147,119,92,27,100,132,250,105,63,13,195,90,251,122,185,97,159,68,36,7,75,163,179,3,6,170,164,152,86,30,49,239,201,245,43,220,78,62,154,206,95,24,149,138,138,15,24,68,58,255,99,88,143,192,12), string.char(97,76,73,171,140,99,57,217,56,73,182,189,58,19,177,104,85,85,45,31,170,132,53,51,155,143,70,169,189,5,41,231,34,132,235,228,114,58,100,105,146,27,67,89,32,34,78,133,155,222,88,26,83,198,128,183,19,243,27,186,192,77,184,54,142,57,24)), 124) print(125) assert("0268f79ef55c3651a66a64a21f47495c5beeb212" == hmac_sha1(string.char(181,166,229,31,47,25,64,129,95,242,221,96,73,42,243,170,15,33,14,198,78,194,235,139,177,112,191,190,52,224,93,95,107,125,245,17,170,161,53,148,19,180,83,154,45,98,76,170,51,178,114,71,34,242,184,75,1,130,199,40,197,88,203,86,169,109,206,67,86,175,201,135,101,76,130,144,248,80,212,14,119,186), string.char(53,208,22,216,93,88,59,64,135,112,49,253,34,11,210,160,117,40,219,36,226,45,207,163,134,133,199,101)), 125) print(126) assert("bcb2473c745d7dee1ec17207d1d804d401828035" == hmac_sha1(string.char(143,117,182,35), string.char(110,95,240,139,124,96,238,255,165,146,205,18,155,244,252,176,24,19,253,39,33,248,90,95,34,115,70,63,195,91,124,144,243,91,110,80,173,47,46,231,73,228,207,37,183,28,42,144,66,248,178,255,129,52,55,232,1,33,193,185,184,237,8)), 126) print(127) assert("402ed75be595f59519e3dd52323817a65e9ff95b" == hmac_sha1(string.char(247,77,247,124,27,156,148,227,12,21,17,94,56,14,118,47,140,239,200,249,216,139,7,172,16,211,237,94,62,201,227,42,250,8,179,21,39,85,186,145,147,106,127,67,111,250,163,89,152,115,166,254,8,246,141,238,43,45,194,131,191,202), string.char(138,227,90,40,221,37,181,54,26,20,24,125,19,101,12,120,111,20,104,10,225,140,64,218,8,33,179,95,215,142,203,127,243,231,166,76,234,159,59,160,132,56,215,143,103,75,155,158,56,126,71,252,229,54,34,240,30,133,110,67,146,213,116,73,14,160,186,169,155,196,84,132,171,200,171,56,92,38,136,90,57,155,145,67,190,198,235,112,242,120,150,191,216,41,21,36,205,42,68,145,226,246,178,70,60,157,254,206,70,84,189,36,197,48,208,249,144,223,6,72,17,253,236,106,205,245,30,1,80,121,165,103,12,202,115,227,192,64,42,223,113,200,195,156,120,202,110,131,130,39,64,217,108,23,133,140,56,144,167,77,45,236,145,161,150,229,85,231,203,159,203,85,125,221,226)), 127) print(128) assert("20231b6abcdd7e5d5e22f83706652acf1ae5255e" == hmac_sha1(string.char(132,122,252,170,107,28,195,210,121,194,245,252,42,64,42,103,220,18,61,68,19,78,182,234,93,130,175,20,4,199,66,91,247,247,87,107,89,205,68,125,19,254,59,47,228,134,200,145,148,78,52,236,51,255,152,231,47,168,213,124,228,34,48), string.char(61,232,69,199,207,49,72,159,37,230,105,207,63,141,245,127,142,77,168,111,126,92,145,26,202,215,116,19,125,81,203,11,86,36,19,218,90,255,4,10,21,185,151,111,188,125,123,2,137,151,171,178,195,199,106,55,42,42,20,164,35,177,237,41,207,24,102,218,213,223,204,186,212,30,59,121,52,34,84,76,142,179,75,6,84,8,72,210,72,177,45,103,218,70,165,69,36,152,50,228,147,192,61,104,209,76,155,147,169,162,151,178,72,109,241,41,76,0,60,251,107,99,92,37,95,215,172,154,172,93,254,65,176,43,99,242,151,78,48,58,35,49,23,174,115,224,227,106,49,30,9)), 128) print(129) assert("b5a24d7aadc1e8fb71f914e1fa581085a8114b27" == hmac_sha1(string.char(233,21,254,12,70,129,236,10,187,36,119,197,152,242,131,11,10,243,169,217,128,247,196,111,183,109,146,155,92,91,71,83,0,136,109,1,130,143,0,8,6,22,160,153,190,164,199,56,152,229), string.char(152,112,218,132,38,125,94,106,64,9,137,105)), 129) print(130) assert("7fd9169b441711bef04ea08ed87b1cd8f245aeb2" == hmac_sha1(string.char(108,226,105,159), string.char(103,218,254,85,50,58,111,74,108,60,174,27,113,65,100,217,97,208,125,38,170,151,72,125,82,114,185,58,4,143,39,223,250,168,66,182,37,216,130,111,103,157,59,0,245,222,8,65,240)), 130) print(131) assert("98038102f8476b28dd11b535b6c1b93eb8089360" == hmac_sha1(string.char(77,121,52,138,71,149,161,87,106,75,232,247,8,148,175,24,23,60,151,104,176,208,148,227,226,191,73,123,164,36,177,235,101,190,128,202,139,116,201,125,61,41,204,187,48,107,63,231,12,137,11,228,93,136,178,243,90), string.char(90,6,232,110,12,66,45,86,141,121,2,6,177,135,64,208,45,178,129,37,253,246,74,48,71,211,243,121,31,209,138,147,185,141,65,185,245,9,137,134,148,123,181,128,204,74,222,150,239,169,179,36,236,104,147,255,251,204,5,191,198,185,153,195,26,112,179,170,232,101,238,143,143)), 131) print(132) assert("ba43c9b8e98b4b7176a1bb63fcbed5b004dc4fcd" == hmac_sha1(string.char(133,107,178,183,204,2,203,106,242,180,87,58,134), string.char(211,208,255,34,198,99,119,185,171,52,118,94,65,241,45,24,40,6,2,203,126,216,21,51,245,154,92,198,201,220,190,135,182,137,113,68,250,94,126,233,140,94,118,244,244,98,252,97,217,204,239,218,178,240,65,150,246,217,231,142,157,33,113,135,135,214,137,103,211,213,48,132,171,43,96,51,241,45,42,237,53,247,134,102,163,214,96,147,131,74,180,19,7,12,174,60,37,60,78,85,92,186,121,27,234,128,132,64,47,106,127,218,52,30,59,230,85,240,164,54,168,232,131,110,145,125,255,238,145,237,134,196,197,138,105,74,34,134,29,249,222,119,194,104,230)), 132) print(133) assert("0c1ad0332f0c6c1f61e6cc86f0a343065635ecb3" == hmac_sha1(string.char(230,111,251,74,216,102,12,134,90,44,121,175,56,221,225,235,180,246,56,12,236,119,119,109,97,59,224,121,27,37,72,219,138,193,50,219,193,152,1,229,224,197,233,76,188,62,120,17,63,158,186,198,87,135,34,60,164,139,3,200,20,188,203,110,212,137,91,70,35,255,146,213,216,71,73,143,55,219,54,142,105,83,175,193,32,226,150,51,59), string.char(185,250,11,8,121,214,91,27,1,50,67,204,219,252,212,198,117,234,57,127,214,12,220,104,44,177,225,238,103,138,144,162,28,69,143,108,192,4,160,63,175,185,123,46,151,221,127,145,55,32,85,245,251,178,125,223,107,192,206,207,232,231,190,44,221,173,1,59,12,178,112,22,253,222,14,40,18,141,128,144,196,6,112,206,183,144,215,156,159,79,132,152,170,22,68,106,137,248,12,242,231,98,96,144,148,20,212,30,242,109,36,112,50,51,57,212,181,191,80,73,215,119,244,209,57,108,147,182,67,204,154,48,216,116)), 133) print(134) assert("466442888b6989fd380f918d0476a16ae26279cf" == hmac_sha1(string.char(250,60,248,215,154,159,2,121), string.char(236,249,8,10,180,146,36,144,83,196,49,166,17,81,51,72,28)), 134) print(135) assert("f9febfeda402b930ec1b95c1325788305cb9fde8" == hmac_sha1(string.char(124,195,165,216,158,253,119,86,162,36,185,72,162,141,160,225,183,25,54,123,73,61,40,165,101,154,157,200,113,14,117,144,185,64,236,219,3,87,90,49), string.char(73,1,223,35,5,159,39,85,95,170,227,61,14,227,142,222,255,253,152,123,104,35,229,6,195,106,30,59,5,36,2,173,71,161,217,189,47,193,3,216,34,10,25,30,212,255,141,94,25,72,52,58,50,56,180,99,173,155)), 135) print(136) assert("53fe70b7e825d017ef0bdecbacdda4e8a76cbc6f" == hmac_sha1(string.char(144,144,130,150,207,183,143,100,188,177,90,5,4,95,116,105,252,118,187,251,35,113,251,86,36,234,176,165,55,165,158,4,182,85,62,255,18,146,128,67,221,183,78,71,158,184,140,14,84,44,36,79,244,158,37,1,122,43,103,228,217,253,72,113,228,121,160,29,87,5,158,64,38,253,179,122,187,157,106,99,161,79,97,176,119,86,101,40,142,241,217,85), string.char(12,89,157,112,207,206,171,254,87,106,42,113,70,72,222,239,88,94,14,41,14,175,206,56,219,244,230,40,33,154,107,249,45,70,55,104,151,193,246,133,99,59,244,179,8,145,225,100,146,142,128,74,40,155,99,93,204,253,249,222,64,99,156,121,142,49,166,62,171,223,135,55,212,183,144,218,56,12,211,99,254,58,249,219,197,189,173,141,60,196,241,157,67,151,251,172,49,105,200,88,224,175,9,79,65,40,5,255,222,14,152,149,228,83,154,207,104,132,106,96,40,229,182,120,100,207,223,81,171,141,1,171)), 136) print(137) assert("81b1df7265954a8aee4e119800169660ff9e75c8" == hmac_sha1(string.char(232,167,4,53,90,111,79,91,163,125,230,202,52,242,160,135,66,211,246,17,131,109,109,235,91), string.char(111,177,251,180,63,13,33,205,231,130,203,167,177,156,87,70,33,148,229,163,158,224,123,37,18,204,185,89,235,2,30,252,229,202,170,157,175,157,208,254,135,190,34,14,42,211,154,243,31,100,71,53,169,76,36)), 137) print(138) assert("caf986508402b3feb70c5b44d902f4a9428a44d2" == hmac_sha1(string.char(127,2,162,53,6,172,189,169,176,254,107,46,57,207,23,25,182,72,34,228,164,113,12,179,149,45,169,19,3,204,202,10,126,153,130,41,143,200,198,47,215,15,58,124,225,60,171,98,8,211,72,235,211,187,172,37,119,96,55,243,98,198,225,191,79,207,94,215,255,21,101,128,153,233,88,101,57,195,70,194), string.char(97,24,129,203,10,176,242,39,165,95,51,30,187,106,207,160,18,154,16,130,178,80,206,128,148,56,213,55,46,85,76,100,50,131,41,167,130,12,81,161,158,55,181,12,12,38,89,193,136,220,81,114,191,157,20,221,171,245)), 138) print(139) assert("83bd91a9e8072010f3b54d215c56ada0cd810bb6" == hmac_sha1(string.char(215,33,57,193,51,126,38,114,7,29,93,101,78,152,222,121,42,0,236,169,48,137,202,48,90,249,235,46,44,126,78,251,15,84,200,235,43,108,8,196,210,57,152,86,254), string.char(153,35,68,230,52,95,243,220,32,101,148,76,80,168,187,172,170,254,10,70,31,117,40,131,61,155,200,189,25,198,120,41,181,53,14,175,64,89,126,94,242,61,52,1,188,255,121,254,74,88,19,10,126,225,89,31,21,104,199,82,149,60,110,194,123,236,13,38,7,213,176,182,202,211,178,185,99,8,173,220,168,166,108,208,71,152,174,5,134,167,220,47,74,177,231,90,114,208,168,47,112,74,58,73,94,224,101,64,128,255,186,179,119,159,117,110,2,188,38,73,230,39,50,73,162,22,117,185,182,168,70,252,11,242,243,165,32,104,220,211)), 139) print(140) assert("c123d92ee67689922dfb3b68a45584e7e5dc5dc3" == hmac_sha1(string.char(167,32,181,181,249,210), string.char(249,7,96,196,48,157,109,129,192,227,82,84,196,167,224,145,61,177,60,74,217,117,199,147,147,54,198,138,5,51,135,112,29,184,49,16,0,240,172,21,214,114,146,57,2,154,205,60,113,32,113,255,165,5,178,15,159)), 140) print(141) assert("454d9ba00ac4e0e90a2866ba2abefba40dac9aab" == hmac_sha1(string.char(116,2,170,84,236,37), string.char(219,144,86,39,237,166,110,90,213,70)), 141) print(142) assert("e919cce3908786205511fee0283e1eb41c0c45a1" == hmac_sha1(string.char(180,76,140,201,56,232,48,183,173,36,111,94,208,153,234,255,52,18,121,118,117,77,92,74,241,103,193,164,169,1,60,46,101,73,61,221,26,253,209,124,99,154,177,218,59,238,159,191,0,65,117,78,15,12,92,35,254,40,11,112,112,91,49,248,198,229,161,247,130,170,76,146,8,220,134,96,155,68,50,168,186,135,188,186,36), string.char(26,47,201,201,197,232,196,239,204,197,162,14,53,254,88,75,43,254,11,20,52,61,136,206,162,29,223,55,125,50,200,239,135,51,154,54,78,191,188,0,137,191,149,162,191,103,0,168,52,178,147,251,253,86,98,17,15,202,231,0,122,10,131,25,15,129,48,190,60,205,185,114,193,122,19,47,52,142,124,107,45,174,221,196,18,32,79,12,129,84,40)), 142) print(143) assert("fa770f6b76984edb0f7fa514a19d3c7ef9c82c51" == hmac_sha1(string.char(70,55,200,82,238,241,84,180,129,122,103,199,170,177), string.char(88,236,14,60,249,2,197,242,76,152,248,241,158,232,113,242,209,93,232,113,147,210,80,180,44,124,186,150,172,177,138,131,117,151,174,231,93,248,244,200,191,169,159,206,232,246,2,121,106,183,107,79,210,73,145,244,254,248,85,217,156,221,238,120,224,176,31,56,246,26,3,186,189,86,41,17,34,8,208,58,46,130,226,139,209,194,3,34,55,213,154,12,250,229,201,122,89,47,177,229,80,165,183,77,178,139,3,241,165,196,239,93,98,101,99,210,99,5,135,132,151,197,4,154,87,130,145,175,243,238,132,0,146,14,6,205,227,78,150,59,191,223,74,145,57,82,30,223,90,205,248,47,195,220,215,167,112,216,20,130,26,88,170,101,26,14,216,62,169,217,1,135,193,147,218)), 143) print(144) assert("d3418e6e6d0a96f8ea7c511273423651a63590c8" == hmac_sha1(string.char(61,175,211,89,77,91,143,76,18,30,252,16,181,45,211,37,207,204,174,174,60,208,36,85,23,106,141,215,62,8,158,98,209,49,96,143,129,99,11,159,79,116,98,244,51,237,227,250,73,196,36,216,181,157,159,87,248,108,29,22,181,175,72,92,160,127,46,204,202,175,61,108,172,50,225,48,84,167,116,67,183), string.char(174,62,218,81,85,89,4,35,26)), 144) print(145) assert("f2fbe13b442bff3c09dcdaeaf375cb2f5214f821" == hmac_sha1(string.char(188,80,129,208,85,53,8,122,92,99,56,251,59,108,97,145,1,97,157,181,156,243,30,204,227,88,205,151), string.char(137,30,19,71,50,239,11,212,91,234,79,248,244,118,108,245,251,78,53,136,249,55,210,231,109,207,153,83,10,63,98,225,79,113,124,64,100,16,195,9,136,28,50,215,93,93,153,25,97,77,4,13,46,34,164,59,33,206,62,125,8,79,219,42,155,39,241,96,18)), 145) print(146) assert("aeacb03e8284a01b93e51e483df58a9492035668" == hmac_sha1(string.char(62,67,97,44,112,68,107,91,105,4,183,154,9,14,164,180,87,140,195,231,62,49,250,154,193,186,219,18,100,156,176,124,223,164,68,64,105,214,144,200,65), string.char(221,20,36,192,59,234,90,174,232,184,75,15,92,229,59,191,36,51,4,190,226,35,237,189,21,100,135,138,171,202,163,227,176,231,72,185,43,197,134,157,44,86,26,42,230,251,2,124,220,245,242,116,77,35,197,154,237,73,117,131,126,242,167,242,8,72,163,171,60,29,77,152,142,69,25,234,195,2,159,49,178,63,48,56,131,143,165,22,142,116,109,11,57,71,101,99,84,204,56,233,173,65,180,228,211,10,197,204,26,70,198,81,217,83,130,70,79,54,93,96,116,32,21,219,193,70,55,84,161,89,47,206,13,167,46,104,205,218)), 146) print(147) assert("e163c334e08bd3fa537c1ea309ce99cfbcd97930" == hmac_sha1(string.char(238,187,29,13,100,125,10,129,46,251,49,62,207,74,243,25,25,73,196,100,114,64,141,173,143,144,70,13,162,227,33,255,83,58,254,138,23,146,90,86,17,33,152,227,15,100,200,147,81,114,166,234,47,60,70,190,208,28,16,44,71,150,101,197,182,57,143,79,29,135,45,211,194,62,234,28,244,74,56,104,187,94,146,174,190,198,55,143,134,60,186,144,190,100,102,0,171,151), string.char(177,90,20,162,64,145,130,87,137,70,153,237,51,138,248,29,166,134,168,68,133,121,161,26,228,137,145,116,243,224,201,229,61,107,250,198,214,208,72,169,248,155,247,54,163,167,71,248,69,106,105,139,224,138,85,94,31,143,4,215,83,239,21,198,28,1,120,83,91,92,58,150,110,77,111,166,222,236,170,129,2,121,86,66,42,129,146,232,46,248,136,175,130,118,126,205,184,136,6,35,180,174,194,59,89,243,199,38,97,48,80,98,45,111)), 147) print(148) assert("6a82b3a54ed409f612a934caf96e6c4799286f19" == hmac_sha1(string.char(11,59,108,100,113,56,239,211,2,138,219,101,50,50,111,31,171,212,228,55,89,196,44,158,77,252,212,134,106,7,250,223,219,46,231,87,9,62,213,104,169,49,1,75,3,10,50,238,5,150,47,14,47,45,171,183,40,245,194,249,228,216,85), string.char(97,131,91,189,9,52,88,203,250,245,46,96,7,95,176,61,57,192,91,231,193,32,41,169,96,101,39,240,29,143,24,56,57,177,70,135,225,90,42,192,134,103,239,175,243,246,76,137,14,237,82,215,7,76,246,219,132,50,175,25,164,4,216,65,102,0,114,216,159,80,58,32,4,100,22,35,71,140,49,16,216,182,91,80,181,129,151,55,130,7,77,84,211,111,45,51,192,123,213,192,11,81,138,60,225,21,37,182,180,223,170,163,110,9,47,214,200,249,164,98,215)), 148) print(149) assert("79caa9946fcf0ccdd882bc409abe77d3470d28f7" == hmac_sha1(string.char(202,142,21,201,45,72,11,211,67,134,42,192,96,255,210,211,252,6,101,131,25,195,101,76,250,161,148,242,30,129,241,85,68,173,236,140,120,80,71,62,55,4,33,104,52,160,143,118,252,72), string.char(100,188,93,165,75,34,224,223,6,130,52,160,83,157,253,27,200,125,117,249,41,203,19,242,4,188,209,213,211,20,162,252,215,238,221,30,219,252,246,110,117,77,89,204,221,246,69,62,160,186,37,144,43,151,39,133,254,134,24,223)), 149) print(150) assert("bd1e60a3df42e2687746766d7d67d57e262f3c9b" == hmac_sha1(string.char(57,212,172,224,206,230,13,50,80,54,19,87,147,166,245,67,118,37,101,214,207,60,66,29,197,236,146,140,192,15,36,155,108,121,215,211,210,118,22,20,56,245,42,153,150,32,224,201,171,2,238,41,70,140,73,60,215,243,86,20,169,152,220,104,95,215,187), string.char(245,123,43,109,29,108,197,27,55,167,255,177,226,205,111,126,146,75,93,70,180,90,139,218,243,232,221,247,129,77,115,101,144,42,13,249,223,127,200,213,140,113,23,10,149,107,244,86,41,133,147,26,167,85,189,76,176,12,190,52,90,54,78,29,97,204,161,224,59,243,128,64,133,95,192,19,137,220,96,228,97,161,51,21,157,172,127,76,53,38,83,126,178,26,203,206,165,241,101,130,79,122,75,29,205,240,1,68,222,48,101,7,29,6,82,240,133,112)), 150) print(151) assert("fe249fa66eb1e6228e1e5166d7862d119ffa0dcf" == hmac_sha1(string.char(152,13,170,129,7,65,32,194,85,196,85,12,170,227,139,215,70,137,246,105,100,111,252,221,54,174,90,169,59,11,198,33,110,94,246,195,174,13,212,47,18,94,17,67,68,56,251,213,92,67,243,114,181,166,24,182,238,146,48,196,11,238,91,213,46,184,187,199,15,221,193,36,73,244,30,222,175,132,165,177,162,54,215,130,171,58,26,144,218,62,172,120,188,20,182,242,47,178,120,175), string.char(129,126,32,58,251,104,186,25,18,204,5,240,65,194,32,205,194,18,151,173,185,249,237,55,145,8,41,18,171,28,59,234,62,163,32,173,197,176,206,224,95,176,218,168,183,82,53,172,205,6,223,190,189,16,3,34,212,201,54,152,89,231,194,95,8,238,133,56,139,157,115,35,74,58,21,162,111,36,105,135,151,30,207,33,198,186,122,221,98,36,196,251,27)), 151) print(152) assert("88aef9bb450b75bf96e8b5fd7831ed0d16d7fe7a" == hmac_sha1(string.char(162,225,9,204,87,95,132,152,211,133,93,120,105,156,131,55,245,224,33,115,182,10,28,49,80,175,241,67,66,52,21,55,174,108,66,100,77,20), string.char(55,61,250,187,157,98,212,245,5,54,170,60,235,228,197,182,230,24,195,215,202,55,56,153,9,94,164,107,67,93,143,1,235,195,133,201,103,57,130,177,71,73,169,80,21,251,130,247,21,61,228,39,166,173,211,203,149,55,11,224,70,52,248,118,112,219,39,188,147,5,203,101,158,134,53,250,103,73,154,249,71,181,53,171,227,26,79,200,145,178,24,80,102,26,90,101,70,143,233,17,150,181,170)), 152) print(153) assert("a057dd823478540bbe9a6fcdf2d4dcfcac663545" == hmac_sha1(string.char(83,17,204,150,211,96,88,52,225,90,61,59,28,127,135), string.char(49,226,129,162,111,75,221,186,24,219,219,178,226,132,19,126,192,69,124,114,214,31,7,127,194,134,202,147,45,176,215,141,41,94,69,38,199,231,185,223,10,104,108,50,237,20,76,194,33,43,117,117,176,3,117,117,55,68,112,207,74,72,163)), 153) print(154) assert("b11757ccfafc8feadc4e9402c820f4903f20032b" == hmac_sha1(string.char(34,11,53,219), string.char(225,194,251,106,223,229,212,105,164,172,25,25,224,199,225,172,197,42,167,1,227,165,17,247,75,250,10,208,99,124,254,158,103,74,89,60,78,141,201,44,253,87,248,239,74,86,75,64,249,189,21,170,249,18,139,21,130,226,66,200,231,35,227,147,95,213,133,35,47,236,52,64,122,115,80,170,27,50,182,151,180,106,120,85,103,255,143,27,233,43,217,152,70,82,8,229,103,42,153,38,130,184,108,160,199,69,38,184)), 154) print(155) assert("bfd0994350b2e1e0d6a1faed059f67f1dd8b361f" == hmac_sha1(string.char(221,156,128,63,215,109,55,123,41,27,110,127,209,144,178,143,120,12,226,47,56,212,131,228,3,40,186,208,233,135,33,206,92,214,153,77,12,220,72,240,176,53,22,37,130,58,180,4,111,124,135,31,192,71,117,87,11,41,231,101,37,164,112,3,55,141,250,131,191,117,90,159,224,244,9,251,154), string.char(35,88,113,69,231,5,150,40,123,13,197,27,49,72,161,1,212,222,252,74,197,170,137,72,231,245,117,236,29,12,36,59,225,103,44,119,136,34,241,17,142,239,46,152,129,163,107,17,165,112,187,15,122,217,67,13,215,157,212,26,103,226,237,161,213,3,152,88,247,236,130,133,84,200,132,191,166,8,96,247,4,142,14,81,179,64,88,202,156,242,181,95,162,19,97,223,51,76,176,218,22,116,24,238,204,128,241,236,204,2,56,86,77,211,4,52,221,82,94,76,9,21,182,112,199,161,29,39,183,120,13,0,124,136,95,182,241,3,73,167,51,237,152,149,84,147,41,42,241,174,12,30,226,245,139,230,127,34,205,41,166,228,242,105,251,4,150,29,106,42,27,239,89,249,230,246,242,149,4,60,240,93,13,166,102,239,81,216,137,196)), 155) print(156) assert("15c4527be05987a9b5c33b920be4a4402f7cf941" == hmac_sha1(string.char(132,158,227,135,167,32,19,192,144,48,232,68,79,78,135,122,136,140,97,67,34,91,225,48,126,67,77,115,154,189,13,45,8,234,59,233,245,77,34,76,95,78,3,250,179,224,20,25,6,202,214,115,165,230,85,115,250,236,135,34,32,158,196,45,207,61,71,51,93,27,187,232,175,233,147,68,231,110,12,198,233,165,24,209,206,25,16,252,127,72), string.char(210,162,121,23,181,21,75,54,110,47,15,166,133,206,100,217,57,133,228,32,112,208,186,28,140,8,207,74,185,17,128,29,181,172,20,156,64,192,112,8,207,131,53,10,182,147,224,71,218,94,71,86,215,2,133,46,160,27,51,189,38,130,224,120,185,144,253,117,193,24,154,229,247,132,62,103,65,163,106,172,22,5,2,32,129,38,213,118,110,125,156,14,48,240,170,225,158,89,92,190,254,231,51,220,8,174,188,233,226,106,224,99,218,82,64,219,206,75,166,111,25,7,87,248,145,251,109,106,243,241,89,200,85,184,155,183,249,61,70,87,115,182,81,80,155,24,245,123,184,102,214,255,122,83,61,214,88,235,169,28,147,196,247,97,28,82,193,72,71,96,243,176,35,189,236,44,184,52,151,249,186,189,150,184,142,238,88,113,120,68,234,50,136,104,80,145,179,57,6,186)), 156) print(157) assert("b9f87f5f23583bdd21b1ea18e7e647513b7b0596" == hmac_sha1(string.char(216,79,247,98,215,219,128,232,135,111,179,168,80,76,36,250,224,157,229,209,238,186,212,188,200,52,208,200,210,79,182,186,22,22,37,34,86,107,89,238,168,90,53,30,151,191,89,163,253,24,204,152,118,1,158,25,168,2,123,91,111,39,101,239,247,37,200,51,215,31,146,211,163,136,208), string.char(153,134,211,81,255,219,50,91,67,48,102,63,244,170,129,66,3,151,110,167,142,150,153,95,89,90,23,87,12,85,42,209,197,36,41,189,199,136,196,159,125,53,253,192,135,234,94,34,87,79,143,213,237,149,212,170,231,181,22,72,81,233,151,243,134,71,160,155,121,32,233,251,187,179,139,48,254,206,172,165,202,105,222,31,223,95,203,87,114,52,218,59,187,41,43,135,200,108,102,201,85,199,8,176,249,44,96,104,160,85,149,177,25,88,55,231,85,120,227,6,180,24)), 157) print(158) assert("0b586895674ab11d3b395c07ddb01151a6e562f5" == hmac_sha1(string.char(26,110,222,147,168,18,74,206,186,238,154,250,229,207,138,175,126,82,236,148,74,180,27,168,159,89,211,34,39,115,227,239,22,199,252,96,100,16,193,117,111,102,75,70,2,114,214,196,29,26,43,189,183,0,194,217,204), string.char(90,15,17,198,223,30,20,138,203,132,6,170,107,40,167,58,194,212,244,49,174,60,209,164,26,87,174,177,41,166,95,173,40,61,47,136,147,239,125,167,146,180,97,167,33,185,5,110,128,36,61,52,140,20,189,16,216,83,164,46,74,16,251,250,72,50,47,5,86,60,56,77,101,64,11,120,124,194,212,199,136,87,157,160,90,172,101,222,235,23,111,11,36,11,68,20,43,251,65,212,206,150,0,50,146,170,183,93,89,142,161,50,110,237,95,191,22,184,62,194,81)), 158) print(159) assert("38b25a1d9d927ba5e6b294d2aa69c0ab8ab0a0c5" == hmac_sha1(string.char(93,218,103,160,235,71,107,150,18,170,193,9,63,245,77,150,71,242,137,52,243,12,207,183,222,252,20,215,210,194,241,79), string.char(87,97,35,201,134,196,180)), 159) print(160) assert("a72ce76565c2876e78f86ce9e137a9881328fddc" == hmac_sha1(string.char(48,215,222,182,164,136,31,53,160,28,61,171,220,159,243,154,169,101,191,193,99,28,140,59,60,215,77,170,51,136,50,145,159,135,237,149,83,154,219,223,29,200,85,193,173,201,66,142,100,21,89,144,111,5,24,229,228,154,160,32,210,71,19,63,244,230,61,185,221,158,151,51), string.char(196,237,178,172,24,232,144,251,253,31,8,63,69,58,202,88,120,219,39,34,223,173,196,164,135,93,188,69,126,58,153,37,72,219,50,152,76,235,244,223,205,60,74,12,109,203,134,239,40,181,207,99,118,149,179,84,14,53,189,201,55,110,67,81,116,140,31,247,163,135,53,254,82,230,55,162,255,230,149,144,217,62,164,59,124,59,78,177,115,47,26,169,228,18,167,232,89,161,56,105,127,111,230,93,230,181,222,212,254,85,32,117,140,80,246,117,21,140,221,198,11,196,112,69,122,125,156)), 160) print(161) assert("cd324faf8204be01296bea85a22d991533fd353e" == hmac_sha1(string.char(25,136,140,2,222,149,164,20,148,15,90,33,106,111,10,252,67,120,57,49,251,171,99,173,114,16,102,240,206,188,231,174,51,124,38,1,217,142,4,15,78,4,5,128,207,82), string.char(84,0,42,233,157,150,105,1,216,32,170,11,100,98,103,220,137,102,32,185,55,211,207,179,252,190,248,117,253,189,196,71,112,32,4,198,87,5,133,125,238,107,210,227,149,206,12,124,31,59,213,66,105,100,240,237,149,232,174,140,127,9,65,204,162,243,100,120,6,229,71,56,140,128,228,102,121,14,43,166,252,230,172,93,96,25,214,174,151,2,50,64,152,164,132,115,109,176,25,144,171,252,231,72)), 161) print(162) assert("fb6e40ddbf3df49d4b44ccecf9e9bc74567df49e" == hmac_sha1(string.char(31,41,38,118,207,197,83,231,45,187,105,1,246,6,34,16,214,148,97,64,139,27,73,129,71,129,183,182,228,12,74,242,94,43,121,163,188,242,92,43,154,103,20,208,89,213,63,46,81,60,69,217,238,237,97,18), string.char(126,99,64,121,143,219,76,227,119,32,135,246,48,55,214,38,179,255,33,43,32,140,228,44,218,40,187,117,172,131,225,222,72,61,213,132,167,121,190,167,66,213,199,59,212,61,69,242,46,169,89,191,74,0,228,208,46,112,7,81,88,203,95,180,179,75,116,222,115,239,1,132,178,73,139,252,77,1,151,222,108,84,196,161,79,220,80,44,223,44,131,252,58,28,201,3,77,211,33,208,237,47,251,79,134,223,48,8,0,236,139,11,232,186,188,134,249,29,208,154,137,169,218,228,203,254,106,88,35,252,155,111,119,14,147,161,19,60,145,157,120,236,108,122,218,168,105,59,10,44,99,208,86)), 162) print(163) assert("373f21bf8fe4e855f882cc976ebed31717f4c791" == hmac_sha1(string.char(198,41,45,129,159,48,37,183,170,144,24,223,108,176,68,60,197,245,254,165,24,152,14,25,243,46,6,25,142,99,64,10,145,229,74,232,162,201,72,215,116,26,179,127,107,45,193,232,96,170,168,153,79,47), string.char(79,250,224,177,254,56,111,120,135,79,55,200,199,71,65,132,222,7,106,170,26,179,235,237,47,172,88,28,244,88,137,177,92,178,147,129,147,85,88,157,30,207,235,246,132,98,232,18,201,57,151,90,174,148,126,22,38,118,133,49,83,156,56,195,10,95,180,250,215,220,251,5,131,243,70,2,162,239,197,153,196,28,181,167,26,14,247,86,244,69,190,100,255,158,217,222,58,116,126,245,240,139,255,213,7,28,222,99,12,127,57,2,212,33,136,220,203,251,87,205,213,160,146,162,73,55,112,203,60,243,139,167,45,91,68,62,204,245,206,221,52,253,5,193,69,19,190,131,64,250,12,127,77,212,53,83,102,212,11,215,253,143,111,201)), 163) print(164) assert("df709285c8a1917aaa6d570bd1d4225ca916b110" == hmac_sha1(string.char(193,124,34,185,160,71,134,56,178,152,165,219,223,89,174,116,11,237), string.char(47,110,24,9,42,187,179,71,114,43,155,129,158,24,130,32,208,3,46,63,16,1,192,210,72,220,200,89,120,80,82,65,199,119,167,86,57,33,105,118,215,60,18,155,17,154,63,59,189,153,236,78,219,89,4,116,208,122,56,65,253,220,57,147,162,242,193,86,45,145,151,61,30,138,105,139,99,89)), 164) print(165) assert("66be81c24c87feeecfd805872c6cde41cb1dd732" == hmac_sha1(string.char(128,186,31,231,128,48,206,237,59), string.char(56,228,42,58,98,45,202,132,30,78,80,52,36,128,7,55,209,148,181,52,185,220,137,85,111,128,220,109,55,70,185,242,253,155,165,193,240,63,144,253,240,147,18,161,7,46,40,148,201,0,127,1,33,145,180,247,90,206,178,96,62,137,130,99,248,248,227,135,213,21,230,40,88,162,106,240,218,93,226,108,9,121,173,70,255,106,137,222,135,206,104,153,171,1,52,156,166,27,98,7,74,180,206,11,193,129,77,194,86,224,175,79,77,95,134,62,58,252,180,100,191,53,28,59,121,123,146,107,121,249,168,51,204,170,141,26,84,126,38,77,203,11,58,123,155,167,60,176,151,7,39,75,217,254,32,110,79,123,188,133,158,178,132,198,169,23,5,104,124,44,206,191,239,139,152,110,207,42)), 165) print(166) assert("2d1dd80c3f0fc323ca46ebd0f73c628caa03f88b" == hmac_sha1(string.char(142,87,50,47,146,180,251,164,35,75,53,50,101,115,90,97,66,12), string.char(174,244,41,143,173,27,117,79,53,73,0,189,83,91,13,71,117,85,96,32,199,168,244,72,218,249,207,107,244,1,113,203,160,156,89,244,132,5,4,220,254,112,77,156,158,105,180,98,40,99,198,236,134,209,13,237,93,220,177,70,97,76,178,106,60,60,92,248)), 166) print(167) assert("444ef9725523ad1aac3d1c20f4954cdf1550d706" == hmac_sha1(string.char(242,169,63,243,133,158,118,205,250,154,66,127,178,170,214,241,96,22,173,138,6,189,90,45,108,70,236,108,93,58,54,204,85,241,194,55,55,184), string.char(30,52,200,164,245,80,75)), 167) print(168) assert("2170bcfb79e4ab2164287a30ee26535681e34505" == hmac_sha1(string.char(121,111,11,221,34,216,169,179,73,247,222,122,96,168,61,168,201,230,139,158,110,154,74,83,118,254,237,255,99,212,46,218,83,69,185,10,249,78,46,76,206,206,137,133,118,57,241,114,228,54,51,68,71,224,188,188,0,119,173,94,120,1,25,13,237,4,181,170,222,92,106,28,9,111,128,137,228,2,110,4,137,171,219,70), string.char(108,95,232,156,70,235,149,211,52,84,86,25,251,127,119,231,109,144,54,177,96,118,213,3,8,119,95,192,187,221,115,83,67,39,207,82,215,85,156,198,179,246,177,202,115,103,79,97,222,133,113,201,27,92,185,48,227,223,142,96,143,181,175,238,115,112,29,30,126,59,109,252,136,153,28,112,50,138,155,249,223,114,93,107,122,114,163,226,53,219,44,15,172,233,76,98,175,107,246,181,249,112,230,173,152,211,183,120,227,165,187,10,240,94)), 168) print(169) assert("2bcd1eb6df83aed8bcdfbb36474651f466b1fb22" == hmac_sha1(string.char(178,135,218,237,192,188,60,157,46,65,76,100,66,248,152,23,200,194,67,107,95,127,67,111,149,64,60,158,199,115,159,64,45,192,212,179,46,13,171,104,139,49,185,254,235,183,65,52,140,30,89), string.char(106,32,155,133,229,130,33,200,31,51,242)), 169) print(170) assert("505910401632c487cd9482ecd6ad16928f21d6f4" == hmac_sha1(string.char(170,34,244,62,31,230,158,102,235,63,93,33,111,253,232,211,132,160,120,156,107), string.char(43,16,194,149,208,76,252,14,73,11,1,172,79,41,132,217,125,96,221,110,199,248,129,122,45,63,77,145,21,98,40,149,154,9,127,27,168,224,204,167,203,74,218,196,236,230,47,29,122,138,65,239,123,120,29,68,236,137,130,95,114,230,185,146,32,69,201,48,251,233,103,61,132,167,245,42,68,249,145,166,137,204,186)), 170) print(171) assert("6d5f9ae7e8a51f2e615ae3aa8525a41b0bf77282" == hmac_sha1(string.char(166,8,119,187,177,166,23,183,147,37,177,162,102,16,93,204,247,119,248,179,23,89,48,145,188,37,197,176,238,218,173,6,216,229,224,108,58,78,40,199,9,241,191,154,88,124,237,142,228,7,235,102,142,123,4,124,38,46,170,229,116,243,104,106,26,163,94,2,118,71,173,171,104), string.char(41,12,123,197,199,117,129,177,132,149,175,83,168,79,76,58,236,204,99,121,155,207,228,89,236,154,103,137,183,221,208,93,22,222,28,237,140,21,25,149,188,111,6,85,251,31,73,79,239,246,66,46,215,157,184,5,207,4)), 171) print(172) assert("8c20120cd131e07d9fa46467602d57c9017ca22d" == hmac_sha1(string.char(12,24,169,75,70,190,156,115,112,233,245,216,85,248,62,24,91,179,204,185,0,129,209,137,116,97,242,183,35,151,91,170,41,4,81,12,120,47,78,145,193,50,237,224,62,203,171,169,6,141,126,75,29,40), string.char(47,165,0,107,170,77,37,219,45,135,102,68,144,218,213,74,35,58,246,179,171,3,148,55,216,32,29,102,83,58,29,11,166,75,243,60,21,9,202,179,236,129,212,62,217,203,6,193,18,176,156,198,86,140,135,222,109,48,195,112,167,218,92,76,71,40,128,221,235,43,81,109,198,51,77,122,183,111,173,195,8,249,40,159,212,136,180,215,171,70,60,108,26,185,11,222,67,47,142,179,158,131,135,153,168,251,199,21,44,7,164,68,212,209,54,75,18,200,117,213,16,175,152,29,146,154,151,236,143,173,86,70,224,138,71,33,33,151,122,205,128,223,166,51,149,125,178,225,234,164,180)), 172) print(173) assert("1ef2a94a2e620a164e07590f006c5a46b722fe7e" == hmac_sha1(string.char(78,109,133,245,198,165,112,63,135,53,124,251,110,183,41,34,153,68,22,253,66,201,9,41,15,99,105,14,252,172,212,39,100,14,128,16,64,47,104,37,33,27,203,120,163,182,52,37,27,224,212,40,134,81,70,29,155,101,246,141,238,41,253,124,222,216,49,49,85,46,51,51,122,39,221,156,104,7,14,52,71,93,31,219), string.char(191,94,78,159,209,12,118,97,214,190,238,108,175,252,192,244,8,104,145,30,236,242,45,49,215,185,251,73,46,101,156,221,136,245,45,240,138,174,187,151,0,122,113,154,195,94,245,186,218,211,203,189,37,251,21,33,225,66,168,152,102,200,245,101,102,217,193,215,194,214,48,131,153,140,75,100,237,240,32,89,113,17,125,177,189,188,212,101,211,212,102,57,251,213,216,14,86,204,198,147,122,97,203,127,100,107,126,107,116,34,220,122,154,130,135,199,9,243,9,194,214)), 173) print(174) assert("ad924bedf84061c998029fb2f168877f0b3939bb" == hmac_sha1(string.char(174,37,249,22,190,230,152,74,215,14,1,180,201,164,238,160,59,157,213,35,36,43,116,160,158,144,131,30,213,232,29,183,205,87,35,85,252,120,126,5,54,113,176), string.char(25,233,197,224,170,150,207,83,58,255,63,236,20,13,179,143,48,248,212,16,220,143,14,123,207,59,28,124,19)), 174) print(175) assert("75a6cfbedde0f1b196209a282b25f5f8b9fef3d1" == hmac_sha1(string.char(131,192,35,70,146,214,224,190,220,240,195,81,129,33,207,253,47,230,111,169,187,136,52,244,217,178,143,140,225,154,105,95,112,201,136,90,221,255,44,31,48,178,90,178,218,122,228,165,90,189,107,45,217,249,89,213,136,139,91,187,202,204,26,250,112), string.char(41,13,202,37,1,104,116,166,245,50,221,59,115,68,187,115,80,93,202,147,10,96,209,213,76,103,143,237,217,21,124,152,82,54,147,207,164,43,89,83,118,67,43,179,79,64,127,252,9,26,125,101,80,192,111,224,104,243,45,67,54,251,238,146,154,212,193,181,138,168,231,171,203,62,93,97,46,55,109,253,214,79,60,62,126,183,235,63,121,46,99,3,223,174,223,2,208,78,7,15,161,56,160,59,205,122,138,77,47,250,107,136,65,199,98,86,131,217,96,226,11,166,185,131,231,76,28,83,140,7,146,87,158,20,102,224,86,5,232,96,34,129,172,236,146,1,139,63,252,1,48,196,242,41,145,97,254,174,88,107,169,70,158,165,246,160,4,16,212,109,236)), 175) print(176) assert("c6f51cc53b0a341dafa4607ee834cffaa8c7c2a2" == hmac_sha1(string.char(85,193,15,80,156,124,171,95,40,75,229,181,147,237,153,83,232,67,210,131,57,69,7,226,226,195,164,46,185,83,120,177,67,77,119,201,9,123,117,111,148,176,12,145,14,80,225,95,71,136,179,94,136,6,78,230,149,135,176,131,19,125,185,48,200,244,111,8,28,170,82,121,242,200,208,145,73,59,234,19,87,61,79,137,245,148,212,94,96,253,227,60,162,170,49,102), string.char(200,235,229,185,225,227,209,209,199,11,112,58,19,202,246,237,94,60,90,176,145,87,191,138,171,88,242,239,21,146,3,92,255,188,99,146,74,134,252,19,201,111,239,76,249,231,71,109,230,240,192,234,253,52,58,173,153,24,131,161,97,222,0,203,177,179,186,160,46,206,73,176,154,39,248,22,66,164,232,120,188,5,73,245,68,8,40,157,155,93,50,207)), 176) print(177) assert("a07ef6f8799ef46062ffea5a43bb3edd30c1fdde" == hmac_sha1(string.char(81,90,37,124,211,22,19,34,50,56,90,45,17,230,233,38,76,24,250), string.char(142,185,46,191,103,207,110,48,71,10,217,115,193,52,131,87,106,39,9,80,216,15,235,169,30,143,3,7,188,78,34,136,18,200,181,140,22,253,141,59,235,25,59,204,147,80,162,108,237,101,167,249,7,168,24,123,215,220,198,38,133,253,72,168,10,139,84,22,195,36,241,128,70,132,28,242,56,40,159,113,184,187,89,38,198,255,176,88,112,125,68,12,57,207,3,251,72,198,135,48,118,244,199,192,205,164,181,243,40,33,195,204,9,78,108,253,114,211,173,121,245,104,13,116,143,160,241,139,210,162,78,62,69,232,40,248,254,177,6,148,177,168,51,253,177,84,152,29,107,91,186,68,118,30,125,62,196,24,14,87,158,83,39,240,192,79,78,61,133,109,106,98,120,232,144,18,49,96,17,202,208,189,152,171,219,19,41,132,179,219,83,220,201,36,191)), 177) print(178) assert("63585793821f635534879a8576194f385f4a551a" == hmac_sha1(string.char(78,213,189,105,102,116,246,215), string.char(162,53,102,158,78,125,120,189,186,214,237,16,219,220,44,24,30,62,32,177,104,217,225,27,92,128,95,202,50,177,239,152,151,161,31,152,93,108,29,125,23,63,55,243,160,169,99,102,15,188,196,129,217,239,132,180,177,251,132,173,62,172,21,139,16,137,231,6,243,185,218,60,60,156,166,153,99,149,144,192,151,249,141,165,222,254,4,111,58,46,106,78,160,215,49,128,252,4,114,236,132,108,114,189,143,45,42,84,134,81,47,140,247,146,247,179,63,14,92,136,120,139)), 178) print(179) assert("95bb1229d26df63839ba4846a41505d48ff98290" == hmac_sha1(string.char(121,190,21,20,39,101,53,249,44,132,19,132,4,114,199,22,32,143,38,33,184,181,66,55,183,240,31,204,225,230,125,186,87,25,90,229,11,55,239,62,101,67,238,1,104,178,191,144,148,105,6,26,127,154,135,247,248,171,41,44,57,83,186,220,42,40,68,153,189,221), string.char(99,150,114,100,37,53,229,202,20,171,246,91,188,188,46,232,70,26,151,35,223,28,97,132,9,242,55,238,98,75,108,91,226,48,236,209,133,92,68,194,241,199,188,86,59,255,230,128,252,193,94,113,134,27,32,50,191,176,159,185,89,209,255,192,9,214,252,63,147,8,92,162,114,72,50,101,136,180,95,39,55,143,137,118,40,14,104,3,149,153,230,135,98,93,72,180,72,86,185,80,107,69,68,20,73)), 179) print(180) assert("9e7c9a258a32e6b3667549cef7a61f307f49b4b9" == hmac_sha1(string.char(105,200,69,23,156,169,151,107,30,139,196,145,128,108,52,7,181,248,255,83,176,169,152,51,158,236,49,191,65,208,155,204,105,179,148,226,142,194,63,253,217,184,69,11,135,185,203,150,146,57,129,80,87,84,231,168,63,186,149,85,128,236,135,217,246,255,121,70,251,68,139,215,199,143,87,13,196,20,50,92,55,116,34,141,117,89,228,94,63,142,250,182,58,91,68,214), string.char(38,52,86,63,109,91,84,11,33,250,194,192,178,94,37,17,65,111,173,17,37,54,163,168,142,91,191,197,161,229,44,163,163,125,81,204,167,185,244,119,75,28,211,87,159)), 180) print(181) assert("7fb01c88e7e519265c18e714efd38bc66f831071" == hmac_sha1(string.char(138,214,212,108,83,152,165,123), string.char(148,223,186,162,237,166,230,68,59,78,220,164,231,42,46,211,239,38,39,150,174,50,58,4,0,135,87,123,123,5,33,252,197,6,53,83,27,178,189,228,166,252,91,141,67,44,68,106,222,17,46,84,214,252,110,181,216,132,14,246,209,57,183,155,238,64,215,121,8,169,157,175,182,191,169,94,116,105,91,49,203,30,155,202,39,140,146,6,115,162,112,130,175,86,143,128,126,249,148,185,39,174,63,83,19,76,164,34,228,97,198,250,65,3,168,158,61,130,167,166,144,185,146,184,160,39,189,11,243,125,255,60,217,46)), 181) print(182) assert("15ab3da2a97592c5f2e22586b4c8a8653411e756" == hmac_sha1(string.char(6,242,91,101,37,118,105,53,170,56,114,144,117,49,53,203,169,216,9,232,9,170,204,129,82,41,210,45,86,176,139,80,152,168,1,154,32,111,89,165,143,205,21,236,105,62,231,106,232,205,7,189,245,52,145,100,78,140,200,183,209,232,196,88,109,175,70,153,150,231,252,7,189,119,97,176,216,201,186,245,24,128,33,57,113,188,184,0,146,248,69,255,77,144,101), string.char(186,246,72,178,189,127,22,42,22,217,81,156,253,142,152,86,42,41,164,77,150,11,208,155,154,185,18,81,156,185,140,224,215,98,1,97,33,194,137,206,144,219,207,210,52,203,198,1,109,182,65,138,122,227,168,207,213,110,206,102,12,181,198,195,133,218,23,187,117,190,56,140,154,239,105,62,96,148,126,187,47,24,139,194,18,211,225,252,195,49,102,138,165,160,90,153,100,140,105,154,242,59,133,226,19,68,125,59,83,140,48,240,226,129,151,79,130,59,96,111,27,73,198)), 182) print(183) assert("7b06792805f4e8062ee9dfbbaffccd787c6f98e1" == hmac_sha1(string.char(83,132,152,16,245,136,91,241,37,158,80,92,65,223,79,3,189,213,89,253,159,93,194,52,218), string.char(212,242,37,98,229,190,238,23,210,197,147,253,82,105,146,168,198,253,2,160,165,188,165,221,179,112,136,72,149,79,138,70,101,95,210,73,157,14,211,92,27,230,177,84,170,183,15,40,0,92,222,252,166,48,1,139,40,16,186,178,231,109,100,125,253,125,123,94,115,94,150,157,186,230,115,163,194,164,30,131,162,90,28,61,44,248,137,8,246,173,31,177,236,39,8,10,192,148,211,36,215,57)), 183) print(184) assert("a28fe22ba0845ae3d57273febbbf1d13e8fde928" == hmac_sha1(string.char(149), string.char(11,139,249,120,214,252,67,75)), 184) print(185) assert("87a9daa85402f6c4b02f1e9fd6edd7e5d178bb88" == hmac_sha1(string.char(114,92,75,169,228,153,182,206,125,139,162,232,77,38,72,129,132,81,11,153,91,92,152,253,10,79,138,142,17,191,161,194,147,213,43,214,39,32,146,46,132,40,77,192,82,54,55,239,50,47), string.char(114,8,110,153,77,155,178,113,203,30,21,41,136,111,176,255,74,214,117,12,189,194,198,37,73,152,196,108,207,188,187,31,227,237,17,1,66,200,73,83,31,61,161,61,31,149,1,152,140,202,163,175,140,136,51,59,121,28,125,192,238,96,192,65,33,177,136,135,173,13,52,101,42,55,189,201,157,244,104,235,148,114,84,154,10,99,153,41,208,213,41,83,193,129,216,46,4,226,81,184,1,249,70,93,183,173,9,29,57,75,209,67,227,49,253,132,129,13,157,55,66,191,136,67,95,108,155,116,17,125,151,217,242,204,110,143,189,201,118)), 185) print(186) assert("6300b2f6236b83de0c84ff1816d246231a5d3b79" == hmac_sha1(string.char(215,10,19,7,73,236,63,23,34,49,11,240,186,195,32,171,67,85,7,95,190,237,77,216,115,36,230,204,139,95,229,37,201,115,81,96,217,205,49,22,169,32,90,2,90,93,137,247,83,229,39,88,235,175,191,246,80,40,228,114,188,115,14,252,35,40,130,240,20,25,202,80,184,27,227,175,149,64,110,223,25,64,57,189,153,176,143,30,76,2,68), string.char(13,245,250,139,223,128,3,6,189,59,12,139,38,153,215,76,250,198,91,117,242,118,34,26,133,244,143,5,56,182,213,167,144,71,250,40,202,81,22,14,72,201,143,10,177,4,166,75,160,156,100,5,147,138,104,98,9,125,81,202,44,120,241,221,181,0,169,155,96,1,4,205,145,105,150,122,135,231,42,165,179,83,39,122,159,193,139,28,4,201,178,41,168,11,177,61,39,14,196,60,29,131,201,91,46,35,128,63,167,48,132,134,105,224,246,244,81,144,209,123,222,190,167,138,76,194,42,152,23,125,52,156,18,217,101,207,239,63,235,3,3,49,147,172,158,97,179,86,233,85,155,245,206,205,165,195,180,223,20,62,197,143,149,126,152)), 186) print(187) assert("35fe4e0cf2417a783d5bdbc17bbc0ab77d2699e7" == hmac_sha1(string.char(15,157,117,128,204,42,12,183,229,129,132,234,228,150,235,100,100,77,160,26,154,230,246,138,150,120,252,20,188,138,171,189,208,62,201,58,158,152,167,165,98,249,52,143,7,26,109,227,144,81,213,157,31,155,26,12,206,103,193,29,142,126,205,123,83,111,179,166,31,32,183,183,100,54,51,205,180,186,160,220,176,233,42,94,62,241,88,74,31,24,22,115,179,124,136,206,78,83), string.char(248,157,191,249,76,86,187,243,10,116,1,227,141,21,104,154,167,72,30,245,6,57,40,170,253,15,4,192,237,237,142,141,196,243,231,245,121,219,150,237,212,118,78,25,201,249,174,21,76,98,187,155,82,243,218,142,239,101,235,240,134,70,212,205,136,165,170,71,121,137,44,8,110,14,167,162,233,92,51,191,178,227,85,134,168,222,121,62,35,127,57,92,80,142,91,112,9,248,129,127,236,2,190,165,125,236,188,117,158,241,181,134,54,133,16,64,100,156,59,83,249,105,235,187,160,186,158,173,52,25,129,20,156,209,102,170,209,10,3,233,12,228,205,138,16,140,108,74,75,65,238,155,251,129,73,236,118,93,202,217,46,180,165,27,84,120,61,186,173,148,131,161,187,30,175,21,249,12,245,145,89,93,61,151,254,29,247,51,198,238,111,52,30,254)), 187) print(188) assert("83c2a380e55ecbc6190b9817bb291a00c36de5e8" == hmac_sha1(string.char(61,128,92,30,94,101,187,67,197,177,98,100,191,221,190,196,86,62,8,238,225,3,93,127,28,126,217,206,56,192,90,9,74,34,43,228,190,162,57,99,170,238,230,196,99,213,31,6,184,11,79,82,100,68,255,40,63), string.char(78,173,248,128,215,226,77,57,233,135,163,11,241,74,59,78,169,219,125,37,182,56,139,89,32,52,80,165,233,52,179,54,216,45,205,209,173,33,12,148,231,66,126,155,191,91,155,174,23,15,14,28,77,186,139,113,48,141,153,177,252,194,23,61,181,189,66,151,45,11,119,74,236,107,206,244,41,117,161,182,233,138,57,196,90,118,28,99,186,150,54,180,105,230,2,41,246,19,80,211,173,102,72,78,82,253,5,183,248,101,173,204,2,145,105,4,160,44,110,211,63,45,46,78)), 188) print(189) assert("bd59d0dcf812107a613a2d892322f532c16ec210" == hmac_sha1(string.char(161,183,101,160,169,208,82,58,88,198,190,85,53,240,56,6,20,136,86,18,216,63,190), string.char(39,227,142,194,37,34,121,168,239,99,70,39,179,128,26,113,47,95,70,129,255,219,63,233,44,33,19,127,22,24,208,50,19,141,185,19,54,82,147,138,44,69)), 189) print(190) assert("6aa92cb64b2e390fbf04dc7edfe3af068109ffba" == hmac_sha1(string.char(202,230,55,100,136,80,156,240,98,73,97,72,191,195,185,105,150,97,148,33,167,140,212,100,247,154,5,152,117,24,128,221,150,49,143,86,12,211,161,75,177,75,145,46,112,143,37,181,84,50,230,81), string.char(131,200,0,161,117,217,5,10,64,79,178,147,64,248,35,147,135,103,157,181,194,123,76,13,150,118,204,63,32,203,155,222,227,148,31,28,218,83,245,17,208,200,104,78,85,31,114,194,67,159,184,167,42,199,241,6,182,195,3,79,22,236,124)), 190) print(191) assert("a42cf08fa6d8ad6ae00251aeed0357dca80645c7" == hmac_sha1(string.char(170,52,245,172,122,225,164,248,23,35,54,243,118,35,165,16,6), string.char(245,115,59,162,179,146,39,213,64,240,80,108,190,127,116,16,154,211,33,171,150,46,77,213,99,88,160,101,236,202,70,26,61,83,79,110,127,74,97,34,18,243,140,34,244,249,225,88,132,102,7,99,220,140,46,111,96,48,93,44,47,186,86,246,244,127,236,150,35,69,111,238,54,24,71,157,254,21,2,194,69,47,190,87,72,235,60,243,40,153,111,55,220,25,91,17,156,195,57,207,107,145,6,82,104,232,209)), 191) print(192) assert("8dd62dcf68ef2d193005921161341839b8cac487" == hmac_sha1(string.char(136,5,195,241,18,208,11,46,252,182,96,183,164,87,248,13), string.char(78,49,162,9,47,79,26,139,66,194,248,90,171,207,167,43,201,223,102,192,49,145,83,42,1,52,250,116,216,133,224,224,17,143,41,153,65,214,231,109,160,5,31,85,17,186,199,226,214,92,21,194,148,98,68,209,50,74,26,150,97,59,223,8,131,173,145,6,31,126,248,86,226,2,94,15,3,202,239,99,177,237,61,99,14,253,26,246,0,151,2,7,159,40,249,166)), 192) print(193) assert("eff66e7a69ae7d2a90b2d80c64ce7c41fe560a19" == hmac_sha1(string.char(123,54,89,205,103,116,21,97,164,41,23,224,151,195,22,196,90,52,253,92), string.char(141,12,168,171,49,30,165,57,107,214,157,224,36,163,182,184,103,186,133,22,2,215,52,220,95,205,231,180,221,139,67,184,21,46,172,95,183,220,31,27,227,122,183,196,114,206,132,162,51,164,84,212,172,63,218,236,127,215,218,77,119,105,14,19,164,53,149,11,13,1,29,246,69,200,208,239,154,60,245,31,172,82,158,165,197,250,151,83,12,156,215,201,66,45,238,228,77,125,157,35,235,162,78,220,132,14,137,168,238,127,10,24,41,132,181,43,95,73,33,32,129,149,145,55,80,156,171,73,90,183,166,182,163,154,31,104,14,56,59,102,72,210,121,191,251,239,1,5,76,116,158,89,40,69,220,107,23,168,106,93,92,95,21,91,118,118,71,29,64,142,84,15,153,193,47,214,30,117,236,217)), 193) print(194) assert("0f1adc518afcca2ed7ad0adaaedd544835ddb76e" == hmac_sha1(string.char(142,36,199,16,52,54,62,146,153,25,162,85,251,247), string.char(110,70,53,237,120,53,50,196,24,82,199,210,156,178,110,124,7,24,229,89,39,1,10,96,74,211,36,79,166,4,33,238,64,220,239,129,48,232,244,172,142,79,154,73,36,107,182,208,191,25,201,19,233,23,60,236,180,76,116,53,232,181,101,62,160,252,213,171,166,113,193,73,75,13,209,63,76,92,95,176,119,0,125,174,42,138,77,23,212,81,180,10,193,118,244,242,163,246,206,150,162,92,20,208,51,71,254,197,11,222,203,153,208,251,243,193,124,141,215,171,55,244,230,78,158,32,223,138,156,43,98,39,191,108,111,6,117,130,195,100,221,233,17,98,180,49,132,139,171,20,180,7,206,35,54,17,48,253,130,185,249,2,52,17,207,73,24,33)), 194) print(195) assert("5e87f8d9a653312fd7b070a33a5d9e67b28b9a84" == hmac_sha1(string.char(255,237,33,255,4,170,95,90,88,77,217,10,94,118,134,20,33,208,17,136,77,18,169,205,112,36,203,231,67,47,186,91,7,17,29), string.char(97,211,98,53,135,238,42,101,144,12,75,185,119,223,114,81,201,94,21,118,16,152,74,215,56,61,131,151,83,96,83,59,49,199,255,207,153,90,231,39,181,4,59,9,2,150,207,124,209,120,37,236,195,66,189,209,137,9,165,78,172,142,209,243,237,145,204,210,222,153,52,127,39,174,133,17,186,219,87,142,209,212,223,60,249,57,244,251,44,254,73,238,52,99,94,237,189,185,237,1,101,166,220,170,103,209)), 195) print(196) assert("837c7cc92e0d2c725b1d1d2f02ef787be37896fa" == hmac_sha1(string.char(150,241,64,89,79,72,88,157,113,139,190,43,211,214,202,52,124,91,111,198,47,161,120,17,120,157,112,248,245,154,254,25,233,96,216), string.char(214,251,73,193,181,158,253,28,23,48,186,168,162,26,124,103,22,195,165,63,189,196,162,229,69,1,208,85,249,24,73,101,243,149,68,236,124,147,108,67,37,75,202,143,57,124,71,176,27,216,208,183,164,173,219,170,79,10,198,1,232,35,9,19,70,131,211,60,37,94,146,98,92,31,150,95,89,189,46,38,156,118,171,137,86,87,32,173,77,14,135,233,233,114,162,136,57,113,73,115,134,87,184)), 196) print(197) assert("64534553f76e55b890101380ad9149d3cacb5b76" == hmac_sha1(string.char(231,24,192,54,17,14,98,122,119,170,71,54,206,207,223,109,164,181,124,186,122,111,122,34,157,24,237,130,207,206,117,76,183,162,174,124,60,60,77,114,139,170,194,143,232,74,160,141,161,171,51,178,162,159,234,208,55), string.char(141,184,241,185,112,45,53,192,72,152,139,145,146,149,145,151,12,140,111,79,158,172,212,175,75,225,127,4,252,104,5,94,105,24,141,183,79,208,240,227,63,126,213,4,13,109,216,244,237,24,196,52,212,245,147,109,18,63,69,107,122,245,101,67,212,232,92,25,135,67,127,247,187,143,224,198,105,38,147,12,238,6,57,53,105,246,0,127,222,69,163,44,11,245,82,220,32,108,33,70,93,177,89,75,192,214,104,236,84,28,221,209,27,12,80,239,111,249,57,39,236,193,17,69,66,180,63,193,242,248,72,22,225,56,198,235,111,102,33,171,159,124,220,143,108,10,71,186,219,213,28,209,145,188,36,70,59,9,235,154,57,12,211,146,6,87,83)), 197) print(198) assert("b7efbbc21ac1a746e22368e814ef5921056331ac" == hmac_sha1(string.char(137,153,151,252,88,36,165,92,194,50,19,117), string.char(155,113,35,47,22,52,144,77,130,20,178,133,75,207,168,146,132,209,160,7,123,190,117,196,147,212,142,25,182,222,56,249,192,228,6,224,250,221,89,7,176,27,37,49,215,192,74,132,127,101,32,23,34,131,23,74,37,226,208,205,162,242,102)), 198) print(199) assert("950ad3222f4917f868d09feab237a909fb6d50b7" == hmac_sha1(string.char(78,46,85,132,231,4,243,255,22,45,240,155,151,119,94,213,50,111,10,83,40,204,49,52,17,69,132,44,213,83,54,251,211,159,123,55,17,58,162,170,210,3,35,237,165,181,217,27,7,249,158,22,158,207,77,121,37,63,37,39,204,68,99,158,78,175,73,183,47,99,134,65,74,234,154,33,14,117,126,98,167,242,106,112,145,82), string.char(144,133,184,16,9,8,227,98,190,60,141,255,87,69,63,214,12,67,14,206,32,120,59,232,176,82,32,194,115,52,148,143,126,86,82,101,167,249,17,169,9,105,228)), 199) ---]]----------------------------------------------------------------------------------------- --END
mit
dmccuskey/dmc-wamp
examples/dmc-wamp-publish/dmc_corona/lib/sha1.lua
11
110178
-- -- SHA-1 secure hash computation, and HMAC-SHA1 signature computation, -- in pure Lua (tested on Lua 5.1) -- -- Latest version always at: http://regex.info/blog/lua/sha1 -- -- Copyright 2009 Jeffrey Friedl -- jfriedl@yahoo.com -- http://regex.info/blog/ -- -- -- Version 1 [May 28, 2009] -- -- -- Lua is a pathetic, horrid, turd of a language. Not only doesn't it have -- bitwise integer operators like OR and AND, it doesn't even have integers -- (and those, relatively speaking, are its good points). Yet, this -- implements the SHA-1 digest hash in pure Lua. While coding it, I felt as -- if I were chiseling NAND gates out of rough blocks of silicon. Those not -- already familiar with this woeful language may, upon seeing this code, -- throw up in their own mouth. -- -- It's not super fast.... a 10k-byte message takes about 2 seconds on a -- circa-2008 mid-level server, but it should be plenty adequate for short -- messages, such as is often needed during authentication handshaking. -- -- Algorithm: http://www.itl.nist.gov/fipspubs/fip180-1.htm -- -- This file creates four entries in the global namespace: -- -- local hash_as_hex = sha1(message) -- returns a hex string -- local hash_as_data = sha1_binary(message) -- returns raw bytes -- -- local hmac_as_hex = hmac_sha1(key, message) -- hex string -- local hmac_as_data = hmac_sha1_binary(key, message) -- raw bytes -- -- Pass sha1() a string, and it returns a hash as a 40-character hex string. -- For example, the call -- -- local hash = sha1 "http://regex.info/blog/" -- -- puts the 40-character string -- -- "7f103bf600de51dfe91062300c14738b32725db5" -- -- into the variable 'hash' -- -- Pass sha1_hmac() a key and a message, and it returns the signature as a -- 40-byte hex string. -- -- -- The two "_binary" versions do the same, but return the 20-byte string of raw data -- that the 40-byte hex strings represent. -- ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ local M = {} -- -- Return a W32 object for the number zero -- local function ZERO() return { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, } end local hex_to_bits = { ["0"] = { false, false, false, false }, ["1"] = { false, false, false, true }, ["2"] = { false, false, true, false }, ["3"] = { false, false, true, true }, ["4"] = { false, true, false, false }, ["5"] = { false, true, false, true }, ["6"] = { false, true, true, false }, ["7"] = { false, true, true, true }, ["8"] = { true, false, false, false }, ["9"] = { true, false, false, true }, ["A"] = { true, false, true, false }, ["B"] = { true, false, true, true }, ["C"] = { true, true, false, false }, ["D"] = { true, true, false, true }, ["E"] = { true, true, true, false }, ["F"] = { true, true, true, true }, ["a"] = { true, false, true, false }, ["b"] = { true, false, true, true }, ["c"] = { true, true, false, false }, ["d"] = { true, true, false, true }, ["e"] = { true, true, true, false }, ["f"] = { true, true, true, true }, } -- -- Given a string of 8 hex digits, return a W32 object representing that number -- local function from_hex(hex) assert(type(hex) == 'string') assert(hex:match('^[0123456789abcdefABCDEF]+$')) assert(#hex == 8) local W32 = { } for letter in hex:gmatch('.') do local b = hex_to_bits[letter] assert(b) table.insert(W32, 1, b[1]) table.insert(W32, 1, b[2]) table.insert(W32, 1, b[3]) table.insert(W32, 1, b[4]) end return W32 end local function COPY(old) local W32 = { } for k,v in pairs(old) do W32[k] = v end return W32 end local function ADD(first, ...) local a = COPY(first) local C, b, sum for v = 1, select('#', ...) do b = select(v, ...) C = 0 for i = 1, #a do sum = (a[i] and 1 or 0) + (b[i] and 1 or 0) + C if sum == 0 then a[i] = false C = 0 elseif sum == 1 then a[i] = true C = 0 elseif sum == 2 then a[i] = false C = 1 else a[i] = true C = 1 end end -- we drop any ending carry end return a end local function XOR(first, ...) local a = COPY(first) local b for v = 1, select('#', ...) do b = select(v, ...) for i = 1, #a do a[i] = a[i] ~= b[i] end end return a end local function AND(a, b) local c = ZERO() for i = 1, #a do -- only need to set true bits; other bits remain false if a[i] and b[i] then c[i] = true end end return c end local function OR(a, b) local c = ZERO() for i = 1, #a do -- only need to set true bits; other bits remain false if a[i] or b[i] then c[i] = true end end return c end local function OR3(a, b, c) local d = ZERO() for i = 1, #a do -- only need to set true bits; other bits remain false if a[i] or b[i] or c[i] then d[i] = true end end return d end local function NOT(a) local b = ZERO() for i = 1, #a do -- only need to set true bits; other bits remain false if not a[i] then b[i] = true end end return b end local function ROTATE(bits, a) local b = COPY(a) while bits > 0 do bits = bits - 1 table.insert(b, 1, table.remove(b)) end return b end local binary_to_hex = { ["0000"] = "0", ["0001"] = "1", ["0010"] = "2", ["0011"] = "3", ["0100"] = "4", ["0101"] = "5", ["0110"] = "6", ["0111"] = "7", ["1000"] = "8", ["1001"] = "9", ["1010"] = "a", ["1011"] = "b", ["1100"] = "c", ["1101"] = "d", ["1110"] = "e", ["1111"] = "f", } local function asHEX(a) local hex = "" local i = 1 while i < #a do local binary = (a[i + 3] and '1' or '0') .. (a[i + 2] and '1' or '0') .. (a[i + 1] and '1' or '0') .. (a[i + 0] and '1' or '0') hex = binary_to_hex[binary] .. hex i = i + 4 end return hex end local x67452301 = from_hex("67452301") local xEFCDAB89 = from_hex("EFCDAB89") local x98BADCFE = from_hex("98BADCFE") local x10325476 = from_hex("10325476") local xC3D2E1F0 = from_hex("C3D2E1F0") local x5A827999 = from_hex("5A827999") local x6ED9EBA1 = from_hex("6ED9EBA1") local x8F1BBCDC = from_hex("8F1BBCDC") local xCA62C1D6 = from_hex("CA62C1D6") function M.sha1(msg) assert(type(msg) == 'string') assert(#msg < 0x7FFFFFFF) -- have no idea what would happen if it were large local H0 = x67452301 local H1 = xEFCDAB89 local H2 = x98BADCFE local H3 = x10325476 local H4 = xC3D2E1F0 local msg_len_in_bits = #msg * 8 local first_append = string.char(0x80) -- append a '1' bit plus seven '0' bits local non_zero_message_bytes = #msg +1 +8 -- the +1 is the appended bit 1, the +8 are for the final appended length local current_mod = non_zero_message_bytes % 64 local second_append = "" if current_mod ~= 0 then second_append = string.rep(string.char(0), 64 - current_mod) end -- now to append the length as a 64-bit number. local B1, R1 = math.modf(msg_len_in_bits / 0x01000000) local B2, R2 = math.modf( 0x01000000 * R1 / 0x00010000) local B3, R3 = math.modf( 0x00010000 * R2 / 0x00000100) local B4 = 0x00000100 * R3 local L64 = string.char( 0) .. string.char( 0) .. string.char( 0) .. string.char( 0) -- high 32 bits .. string.char(B1) .. string.char(B2) .. string.char(B3) .. string.char(B4) -- low 32 bits msg = msg .. first_append .. second_append .. L64 assert(#msg % 64 == 0) --local fd = io.open("/tmp/msg", "wb") --fd:write(msg) --fd:close() local chunks = #msg / 64 local W = { } local start, A, B, C, D, E, f, K, TEMP local chunk = 0 while chunk < chunks do -- -- break chunk up into W[0] through W[15] -- start = chunk * 64 + 1 chunk = chunk + 1 for t = 0, 15 do W[t] = from_hex(string.format("%02x%02x%02x%02x", msg:byte(start, start + 3))) start = start + 4 end -- -- build W[16] through W[79] -- for t = 16, 79 do -- For t = 16 to 79 let Wt = S1(Wt-3 XOR Wt-8 XOR Wt-14 XOR Wt-16). W[t] = ROTATE(1, XOR(W[t-3], W[t-8], W[t-14], W[t-16])) end A = H0 B = H1 C = H2 D = H3 E = H4 for t = 0, 79 do if t <= 19 then -- (B AND C) OR ((NOT B) AND D) f = OR(AND(B, C), AND(NOT(B), D)) K = x5A827999 elseif t <= 39 then -- B XOR C XOR D f = XOR(B, C, D) K = x6ED9EBA1 elseif t <= 59 then -- (B AND C) OR (B AND D) OR (C AND D f = OR3(AND(B, C), AND(B, D), AND(C, D)) K = x8F1BBCDC else -- B XOR C XOR D f = XOR(B, C, D) K = xCA62C1D6 end -- TEMP = S5(A) + ft(B,C,D) + E + Wt + Kt; TEMP = ADD(ROTATE(5, A), f, E, W[t], K) --E = D;   D = C;    C = S30(B);   B = A;   A = TEMP; E = D D = C C = ROTATE(30, B) B = A A = TEMP --printf("t = %2d: %s %s %s %s %s", t, A:HEX(), B:HEX(), C:HEX(), D:HEX(), E:HEX()) end -- Let H0 = H0 + A, H1 = H1 + B, H2 = H2 + C, H3 = H3 + D, H4 = H4 + E. H0 = ADD(H0, A) H1 = ADD(H1, B) H2 = ADD(H2, C) H3 = ADD(H3, D) H4 = ADD(H4, E) end return asHEX(H0) .. asHEX(H1) .. asHEX(H2) .. asHEX(H3) .. asHEX(H4) end local function hex_to_binary(hex) return hex:gsub('..', function(hexval) return string.char(tonumber(hexval, 16)) end) end function M.sha1_binary(msg) return hex_to_binary(M.sha1(msg)) end local xor_with_0x5c = { [string.char( 0)] = string.char( 92), [string.char( 1)] = string.char( 93), [string.char( 2)] = string.char( 94), [string.char( 3)] = string.char( 95), [string.char( 4)] = string.char( 88), [string.char( 5)] = string.char( 89), [string.char( 6)] = string.char( 90), [string.char( 7)] = string.char( 91), [string.char( 8)] = string.char( 84), [string.char( 9)] = string.char( 85), [string.char( 10)] = string.char( 86), [string.char( 11)] = string.char( 87), [string.char( 12)] = string.char( 80), [string.char( 13)] = string.char( 81), [string.char( 14)] = string.char( 82), [string.char( 15)] = string.char( 83), [string.char( 16)] = string.char( 76), [string.char( 17)] = string.char( 77), [string.char( 18)] = string.char( 78), [string.char( 19)] = string.char( 79), [string.char( 20)] = string.char( 72), [string.char( 21)] = string.char( 73), [string.char( 22)] = string.char( 74), [string.char( 23)] = string.char( 75), [string.char( 24)] = string.char( 68), [string.char( 25)] = string.char( 69), [string.char( 26)] = string.char( 70), [string.char( 27)] = string.char( 71), [string.char( 28)] = string.char( 64), [string.char( 29)] = string.char( 65), [string.char( 30)] = string.char( 66), [string.char( 31)] = string.char( 67), [string.char( 32)] = string.char(124), [string.char( 33)] = string.char(125), [string.char( 34)] = string.char(126), [string.char( 35)] = string.char(127), [string.char( 36)] = string.char(120), [string.char( 37)] = string.char(121), [string.char( 38)] = string.char(122), [string.char( 39)] = string.char(123), [string.char( 40)] = string.char(116), [string.char( 41)] = string.char(117), [string.char( 42)] = string.char(118), [string.char( 43)] = string.char(119), [string.char( 44)] = string.char(112), [string.char( 45)] = string.char(113), [string.char( 46)] = string.char(114), [string.char( 47)] = string.char(115), [string.char( 48)] = string.char(108), [string.char( 49)] = string.char(109), [string.char( 50)] = string.char(110), [string.char( 51)] = string.char(111), [string.char( 52)] = string.char(104), [string.char( 53)] = string.char(105), [string.char( 54)] = string.char(106), [string.char( 55)] = string.char(107), [string.char( 56)] = string.char(100), [string.char( 57)] = string.char(101), [string.char( 58)] = string.char(102), [string.char( 59)] = string.char(103), [string.char( 60)] = string.char( 96), [string.char( 61)] = string.char( 97), [string.char( 62)] = string.char( 98), [string.char( 63)] = string.char( 99), [string.char( 64)] = string.char( 28), [string.char( 65)] = string.char( 29), [string.char( 66)] = string.char( 30), [string.char( 67)] = string.char( 31), [string.char( 68)] = string.char( 24), [string.char( 69)] = string.char( 25), [string.char( 70)] = string.char( 26), [string.char( 71)] = string.char( 27), [string.char( 72)] = string.char( 20), [string.char( 73)] = string.char( 21), [string.char( 74)] = string.char( 22), [string.char( 75)] = string.char( 23), [string.char( 76)] = string.char( 16), [string.char( 77)] = string.char( 17), [string.char( 78)] = string.char( 18), [string.char( 79)] = string.char( 19), [string.char( 80)] = string.char( 12), [string.char( 81)] = string.char( 13), [string.char( 82)] = string.char( 14), [string.char( 83)] = string.char( 15), [string.char( 84)] = string.char( 8), [string.char( 85)] = string.char( 9), [string.char( 86)] = string.char( 10), [string.char( 87)] = string.char( 11), [string.char( 88)] = string.char( 4), [string.char( 89)] = string.char( 5), [string.char( 90)] = string.char( 6), [string.char( 91)] = string.char( 7), [string.char( 92)] = string.char( 0), [string.char( 93)] = string.char( 1), [string.char( 94)] = string.char( 2), [string.char( 95)] = string.char( 3), [string.char( 96)] = string.char( 60), [string.char( 97)] = string.char( 61), [string.char( 98)] = string.char( 62), [string.char( 99)] = string.char( 63), [string.char(100)] = string.char( 56), [string.char(101)] = string.char( 57), [string.char(102)] = string.char( 58), [string.char(103)] = string.char( 59), [string.char(104)] = string.char( 52), [string.char(105)] = string.char( 53), [string.char(106)] = string.char( 54), [string.char(107)] = string.char( 55), [string.char(108)] = string.char( 48), [string.char(109)] = string.char( 49), [string.char(110)] = string.char( 50), [string.char(111)] = string.char( 51), [string.char(112)] = string.char( 44), [string.char(113)] = string.char( 45), [string.char(114)] = string.char( 46), [string.char(115)] = string.char( 47), [string.char(116)] = string.char( 40), [string.char(117)] = string.char( 41), [string.char(118)] = string.char( 42), [string.char(119)] = string.char( 43), [string.char(120)] = string.char( 36), [string.char(121)] = string.char( 37), [string.char(122)] = string.char( 38), [string.char(123)] = string.char( 39), [string.char(124)] = string.char( 32), [string.char(125)] = string.char( 33), [string.char(126)] = string.char( 34), [string.char(127)] = string.char( 35), [string.char(128)] = string.char(220), [string.char(129)] = string.char(221), [string.char(130)] = string.char(222), [string.char(131)] = string.char(223), [string.char(132)] = string.char(216), [string.char(133)] = string.char(217), [string.char(134)] = string.char(218), [string.char(135)] = string.char(219), [string.char(136)] = string.char(212), [string.char(137)] = string.char(213), [string.char(138)] = string.char(214), [string.char(139)] = string.char(215), [string.char(140)] = string.char(208), [string.char(141)] = string.char(209), [string.char(142)] = string.char(210), [string.char(143)] = string.char(211), [string.char(144)] = string.char(204), [string.char(145)] = string.char(205), [string.char(146)] = string.char(206), [string.char(147)] = string.char(207), [string.char(148)] = string.char(200), [string.char(149)] = string.char(201), [string.char(150)] = string.char(202), [string.char(151)] = string.char(203), [string.char(152)] = string.char(196), [string.char(153)] = string.char(197), [string.char(154)] = string.char(198), [string.char(155)] = string.char(199), [string.char(156)] = string.char(192), [string.char(157)] = string.char(193), [string.char(158)] = string.char(194), [string.char(159)] = string.char(195), [string.char(160)] = string.char(252), [string.char(161)] = string.char(253), [string.char(162)] = string.char(254), [string.char(163)] = string.char(255), [string.char(164)] = string.char(248), [string.char(165)] = string.char(249), [string.char(166)] = string.char(250), [string.char(167)] = string.char(251), [string.char(168)] = string.char(244), [string.char(169)] = string.char(245), [string.char(170)] = string.char(246), [string.char(171)] = string.char(247), [string.char(172)] = string.char(240), [string.char(173)] = string.char(241), [string.char(174)] = string.char(242), [string.char(175)] = string.char(243), [string.char(176)] = string.char(236), [string.char(177)] = string.char(237), [string.char(178)] = string.char(238), [string.char(179)] = string.char(239), [string.char(180)] = string.char(232), [string.char(181)] = string.char(233), [string.char(182)] = string.char(234), [string.char(183)] = string.char(235), [string.char(184)] = string.char(228), [string.char(185)] = string.char(229), [string.char(186)] = string.char(230), [string.char(187)] = string.char(231), [string.char(188)] = string.char(224), [string.char(189)] = string.char(225), [string.char(190)] = string.char(226), [string.char(191)] = string.char(227), [string.char(192)] = string.char(156), [string.char(193)] = string.char(157), [string.char(194)] = string.char(158), [string.char(195)] = string.char(159), [string.char(196)] = string.char(152), [string.char(197)] = string.char(153), [string.char(198)] = string.char(154), [string.char(199)] = string.char(155), [string.char(200)] = string.char(148), [string.char(201)] = string.char(149), [string.char(202)] = string.char(150), [string.char(203)] = string.char(151), [string.char(204)] = string.char(144), [string.char(205)] = string.char(145), [string.char(206)] = string.char(146), [string.char(207)] = string.char(147), [string.char(208)] = string.char(140), [string.char(209)] = string.char(141), [string.char(210)] = string.char(142), [string.char(211)] = string.char(143), [string.char(212)] = string.char(136), [string.char(213)] = string.char(137), [string.char(214)] = string.char(138), [string.char(215)] = string.char(139), [string.char(216)] = string.char(132), [string.char(217)] = string.char(133), [string.char(218)] = string.char(134), [string.char(219)] = string.char(135), [string.char(220)] = string.char(128), [string.char(221)] = string.char(129), [string.char(222)] = string.char(130), [string.char(223)] = string.char(131), [string.char(224)] = string.char(188), [string.char(225)] = string.char(189), [string.char(226)] = string.char(190), [string.char(227)] = string.char(191), [string.char(228)] = string.char(184), [string.char(229)] = string.char(185), [string.char(230)] = string.char(186), [string.char(231)] = string.char(187), [string.char(232)] = string.char(180), [string.char(233)] = string.char(181), [string.char(234)] = string.char(182), [string.char(235)] = string.char(183), [string.char(236)] = string.char(176), [string.char(237)] = string.char(177), [string.char(238)] = string.char(178), [string.char(239)] = string.char(179), [string.char(240)] = string.char(172), [string.char(241)] = string.char(173), [string.char(242)] = string.char(174), [string.char(243)] = string.char(175), [string.char(244)] = string.char(168), [string.char(245)] = string.char(169), [string.char(246)] = string.char(170), [string.char(247)] = string.char(171), [string.char(248)] = string.char(164), [string.char(249)] = string.char(165), [string.char(250)] = string.char(166), [string.char(251)] = string.char(167), [string.char(252)] = string.char(160), [string.char(253)] = string.char(161), [string.char(254)] = string.char(162), [string.char(255)] = string.char(163), } local xor_with_0x36 = { [string.char( 0)] = string.char( 54), [string.char( 1)] = string.char( 55), [string.char( 2)] = string.char( 52), [string.char( 3)] = string.char( 53), [string.char( 4)] = string.char( 50), [string.char( 5)] = string.char( 51), [string.char( 6)] = string.char( 48), [string.char( 7)] = string.char( 49), [string.char( 8)] = string.char( 62), [string.char( 9)] = string.char( 63), [string.char( 10)] = string.char( 60), [string.char( 11)] = string.char( 61), [string.char( 12)] = string.char( 58), [string.char( 13)] = string.char( 59), [string.char( 14)] = string.char( 56), [string.char( 15)] = string.char( 57), [string.char( 16)] = string.char( 38), [string.char( 17)] = string.char( 39), [string.char( 18)] = string.char( 36), [string.char( 19)] = string.char( 37), [string.char( 20)] = string.char( 34), [string.char( 21)] = string.char( 35), [string.char( 22)] = string.char( 32), [string.char( 23)] = string.char( 33), [string.char( 24)] = string.char( 46), [string.char( 25)] = string.char( 47), [string.char( 26)] = string.char( 44), [string.char( 27)] = string.char( 45), [string.char( 28)] = string.char( 42), [string.char( 29)] = string.char( 43), [string.char( 30)] = string.char( 40), [string.char( 31)] = string.char( 41), [string.char( 32)] = string.char( 22), [string.char( 33)] = string.char( 23), [string.char( 34)] = string.char( 20), [string.char( 35)] = string.char( 21), [string.char( 36)] = string.char( 18), [string.char( 37)] = string.char( 19), [string.char( 38)] = string.char( 16), [string.char( 39)] = string.char( 17), [string.char( 40)] = string.char( 30), [string.char( 41)] = string.char( 31), [string.char( 42)] = string.char( 28), [string.char( 43)] = string.char( 29), [string.char( 44)] = string.char( 26), [string.char( 45)] = string.char( 27), [string.char( 46)] = string.char( 24), [string.char( 47)] = string.char( 25), [string.char( 48)] = string.char( 6), [string.char( 49)] = string.char( 7), [string.char( 50)] = string.char( 4), [string.char( 51)] = string.char( 5), [string.char( 52)] = string.char( 2), [string.char( 53)] = string.char( 3), [string.char( 54)] = string.char( 0), [string.char( 55)] = string.char( 1), [string.char( 56)] = string.char( 14), [string.char( 57)] = string.char( 15), [string.char( 58)] = string.char( 12), [string.char( 59)] = string.char( 13), [string.char( 60)] = string.char( 10), [string.char( 61)] = string.char( 11), [string.char( 62)] = string.char( 8), [string.char( 63)] = string.char( 9), [string.char( 64)] = string.char(118), [string.char( 65)] = string.char(119), [string.char( 66)] = string.char(116), [string.char( 67)] = string.char(117), [string.char( 68)] = string.char(114), [string.char( 69)] = string.char(115), [string.char( 70)] = string.char(112), [string.char( 71)] = string.char(113), [string.char( 72)] = string.char(126), [string.char( 73)] = string.char(127), [string.char( 74)] = string.char(124), [string.char( 75)] = string.char(125), [string.char( 76)] = string.char(122), [string.char( 77)] = string.char(123), [string.char( 78)] = string.char(120), [string.char( 79)] = string.char(121), [string.char( 80)] = string.char(102), [string.char( 81)] = string.char(103), [string.char( 82)] = string.char(100), [string.char( 83)] = string.char(101), [string.char( 84)] = string.char( 98), [string.char( 85)] = string.char( 99), [string.char( 86)] = string.char( 96), [string.char( 87)] = string.char( 97), [string.char( 88)] = string.char(110), [string.char( 89)] = string.char(111), [string.char( 90)] = string.char(108), [string.char( 91)] = string.char(109), [string.char( 92)] = string.char(106), [string.char( 93)] = string.char(107), [string.char( 94)] = string.char(104), [string.char( 95)] = string.char(105), [string.char( 96)] = string.char( 86), [string.char( 97)] = string.char( 87), [string.char( 98)] = string.char( 84), [string.char( 99)] = string.char( 85), [string.char(100)] = string.char( 82), [string.char(101)] = string.char( 83), [string.char(102)] = string.char( 80), [string.char(103)] = string.char( 81), [string.char(104)] = string.char( 94), [string.char(105)] = string.char( 95), [string.char(106)] = string.char( 92), [string.char(107)] = string.char( 93), [string.char(108)] = string.char( 90), [string.char(109)] = string.char( 91), [string.char(110)] = string.char( 88), [string.char(111)] = string.char( 89), [string.char(112)] = string.char( 70), [string.char(113)] = string.char( 71), [string.char(114)] = string.char( 68), [string.char(115)] = string.char( 69), [string.char(116)] = string.char( 66), [string.char(117)] = string.char( 67), [string.char(118)] = string.char( 64), [string.char(119)] = string.char( 65), [string.char(120)] = string.char( 78), [string.char(121)] = string.char( 79), [string.char(122)] = string.char( 76), [string.char(123)] = string.char( 77), [string.char(124)] = string.char( 74), [string.char(125)] = string.char( 75), [string.char(126)] = string.char( 72), [string.char(127)] = string.char( 73), [string.char(128)] = string.char(182), [string.char(129)] = string.char(183), [string.char(130)] = string.char(180), [string.char(131)] = string.char(181), [string.char(132)] = string.char(178), [string.char(133)] = string.char(179), [string.char(134)] = string.char(176), [string.char(135)] = string.char(177), [string.char(136)] = string.char(190), [string.char(137)] = string.char(191), [string.char(138)] = string.char(188), [string.char(139)] = string.char(189), [string.char(140)] = string.char(186), [string.char(141)] = string.char(187), [string.char(142)] = string.char(184), [string.char(143)] = string.char(185), [string.char(144)] = string.char(166), [string.char(145)] = string.char(167), [string.char(146)] = string.char(164), [string.char(147)] = string.char(165), [string.char(148)] = string.char(162), [string.char(149)] = string.char(163), [string.char(150)] = string.char(160), [string.char(151)] = string.char(161), [string.char(152)] = string.char(174), [string.char(153)] = string.char(175), [string.char(154)] = string.char(172), [string.char(155)] = string.char(173), [string.char(156)] = string.char(170), [string.char(157)] = string.char(171), [string.char(158)] = string.char(168), [string.char(159)] = string.char(169), [string.char(160)] = string.char(150), [string.char(161)] = string.char(151), [string.char(162)] = string.char(148), [string.char(163)] = string.char(149), [string.char(164)] = string.char(146), [string.char(165)] = string.char(147), [string.char(166)] = string.char(144), [string.char(167)] = string.char(145), [string.char(168)] = string.char(158), [string.char(169)] = string.char(159), [string.char(170)] = string.char(156), [string.char(171)] = string.char(157), [string.char(172)] = string.char(154), [string.char(173)] = string.char(155), [string.char(174)] = string.char(152), [string.char(175)] = string.char(153), [string.char(176)] = string.char(134), [string.char(177)] = string.char(135), [string.char(178)] = string.char(132), [string.char(179)] = string.char(133), [string.char(180)] = string.char(130), [string.char(181)] = string.char(131), [string.char(182)] = string.char(128), [string.char(183)] = string.char(129), [string.char(184)] = string.char(142), [string.char(185)] = string.char(143), [string.char(186)] = string.char(140), [string.char(187)] = string.char(141), [string.char(188)] = string.char(138), [string.char(189)] = string.char(139), [string.char(190)] = string.char(136), [string.char(191)] = string.char(137), [string.char(192)] = string.char(246), [string.char(193)] = string.char(247), [string.char(194)] = string.char(244), [string.char(195)] = string.char(245), [string.char(196)] = string.char(242), [string.char(197)] = string.char(243), [string.char(198)] = string.char(240), [string.char(199)] = string.char(241), [string.char(200)] = string.char(254), [string.char(201)] = string.char(255), [string.char(202)] = string.char(252), [string.char(203)] = string.char(253), [string.char(204)] = string.char(250), [string.char(205)] = string.char(251), [string.char(206)] = string.char(248), [string.char(207)] = string.char(249), [string.char(208)] = string.char(230), [string.char(209)] = string.char(231), [string.char(210)] = string.char(228), [string.char(211)] = string.char(229), [string.char(212)] = string.char(226), [string.char(213)] = string.char(227), [string.char(214)] = string.char(224), [string.char(215)] = string.char(225), [string.char(216)] = string.char(238), [string.char(217)] = string.char(239), [string.char(218)] = string.char(236), [string.char(219)] = string.char(237), [string.char(220)] = string.char(234), [string.char(221)] = string.char(235), [string.char(222)] = string.char(232), [string.char(223)] = string.char(233), [string.char(224)] = string.char(214), [string.char(225)] = string.char(215), [string.char(226)] = string.char(212), [string.char(227)] = string.char(213), [string.char(228)] = string.char(210), [string.char(229)] = string.char(211), [string.char(230)] = string.char(208), [string.char(231)] = string.char(209), [string.char(232)] = string.char(222), [string.char(233)] = string.char(223), [string.char(234)] = string.char(220), [string.char(235)] = string.char(221), [string.char(236)] = string.char(218), [string.char(237)] = string.char(219), [string.char(238)] = string.char(216), [string.char(239)] = string.char(217), [string.char(240)] = string.char(198), [string.char(241)] = string.char(199), [string.char(242)] = string.char(196), [string.char(243)] = string.char(197), [string.char(244)] = string.char(194), [string.char(245)] = string.char(195), [string.char(246)] = string.char(192), [string.char(247)] = string.char(193), [string.char(248)] = string.char(206), [string.char(249)] = string.char(207), [string.char(250)] = string.char(204), [string.char(251)] = string.char(205), [string.char(252)] = string.char(202), [string.char(253)] = string.char(203), [string.char(254)] = string.char(200), [string.char(255)] = string.char(201), } local blocksize = 64 -- 512 bits function M.hmac_sha1(key, text) assert(type(key) == 'string', "key passed to hmac_sha1 should be a string") assert(type(text) == 'string', "text passed to hmac_sha1 should be a string") if #key > blocksize then key = sha1_binary(key) end local key_xord_with_0x36 = key:gsub('.', xor_with_0x36) .. string.rep(string.char(0x36), blocksize - #key) local key_xord_with_0x5c = key:gsub('.', xor_with_0x5c) .. string.rep(string.char(0x5c), blocksize - #key) return M.sha1(key_xord_with_0x5c .. M.sha1_binary(key_xord_with_0x36 .. text)) end function M.hmac_sha1_binary(key, text) return hex_to_binary(M.hmac_sha1(key, text)) end return M --[[------------ VALIDATION TESTS -- uncomment to execute ------------------------------------ print(1) assert(sha1 "http://regex.info/blog/" == "7f103bf600de51dfe91062300c14738b32725db5", 1) print(2) assert(sha1(string.rep("a", 10000)) == "a080cbda64850abb7b7f67ee875ba068074ff6fe", 2) print(3) assert(sha1 "abc" == "a9993e364706816aba3e25717850c26c9cd0d89d", 3) print(4) assert(sha1 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" == "84983e441c3bd26ebaae4aa1f95129e5e54670f1", 4) print(5) assert(sha1 "The quick brown fox jumps over the lazy dog" == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", 5) print(6) assert(sha1 "The quick brown fox jumps over the lazy cog" == "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3", 6) -- a few randomly generated tests print(7) assert("efb750130b6cc9adf4be219435e575442ec68b7c" == sha1(string.char(136,43,218,202,158,86,64,140,154,173,20,184,170,125,37,54,208,68,171,24,164,89,142,111,148,235,187,181,122):rep(76)), 7) print(8) assert("432dff9d4023e13194170287103d0377ed182d96" == sha1(string.char(20,174):rep(407)), 8) print(9) assert("ccba5c47946530726bb86034dbee1dbf0c203e99" == sha1(string.char(20,54,149,252,176,4,96,100,223):rep(753)), 9) print(10) assert("4d6fea4f8576cd6648ae2d2ee4dc5df0a8309115" == sha1(string.char(118,171,221,33,54,209,223,152,35,67,88,50):rep(985)), 10) print(11) assert("f560412aabf813d01f15fdc6650489584aabd266" == sha1(string.char(23,85,29,13,146,55,164,14,206,196,109,183,53,92,97,123,242,220,112,15,43,113,22,246,114,29,209,219,190):rep(177)), 11) print(12) assert("b56795e12f3857b3ba1cbbcedb4d92dd9c419328" == sha1(string.char(21,216):rep(131)), 12) print(13) assert("54f292ecb7561e8ce27984685b427234c9465095" == sha1(string.char(15,205,12,181,4,114,128,118,219):rep(818)), 13) print(14) assert("fe265c1b5a848e5f3ada94a7e1bb98a8ce319835" == sha1(string.char(136,165,10,46,167,184,86,255,58,206,237,21,255,15,198,211,145,112,228,146,26,69,92,158,182,165,244,39,152):rep(605)), 14) print(15) assert("96f186998825075d528646059edadb55fdd96659" == sha1(string.char(100,226,28,248,132,70,221,54,92,181,82,128,191,12,250,244):rep(94)), 15) print(16) assert("e29c68e4d6ffd3998b2180015be9caee59dd8c8a" == sha1(string.char(247,14,15,163,0,53,50,113,84,121):rep(967)), 16) print(17) assert("6d2332a82b3600cbc5d2417f944c38be9f1081ae" == sha1(string.char(93,98,119,201,41,27,89,144,25,141,117,26,111,132):rep(632)), 17) print(18) assert("d84a91da8fb3aa7cd59b99f347113939406ef8eb" == sha1(string.char(28,252,0,4,150,164,91):rep(568)), 18) print(19) assert("8edf1b92ad5a90ed762def9a873a799b4bda97f9" == sha1(string.char(166,67,113,111,161,253,169,195,158,97,96,150,49,219,103,16,186,184,37,109,228,111):rep(135)), 19) print(20) assert("d5b2c7019f9ff2f75c38dc040c827ab9d1a42157" == sha1(string.char(38,252,110,224,168,60,2,133,8,153,200,0,199,104,191,62,28,168,73,48,199,217,83):rep(168)), 20) print(21) assert("5aeb57041bfada3b72e3514f493d7b9f4ca96620" == sha1(string.char(57):rep(738)), 21) print(22) assert("4548238c8c2124c6398427ed447ae8abbb8ead27" == sha1(string.char(221,131,171):rep(230)), 22) print(23) assert("ed0960b87a790a24eb2890d8ea8b18043f1a87d5" == sha1(string.char(151,113,144,19,249,148,75,51,164,233,102,232,3,58,81,99,101,255,93,231,147,150,212,216,109,62):rep(110)), 23) print(24) assert("d7ac6233298783af55901907bb99c13b2afbca99" == sha1(string.char(44,239,189,203,196,79,82,143,99,21,125,75,167,26,108,161,9,193,72):rep(919)), 24) print(25) assert("43600b41a3c5267e625bbdfde95027429c330c60" == sha1(string.char(122,70,129,24,192,213,205,224,62,79,81,129,22,171):rep(578)), 25) print(26) assert("5816df09a78e4594c1b02b170aa57333162def38" == sha1(string.char(76,103,48,150,115,161,86,42,247,82,197,213,155,108,215,18,119):rep(480)), 26) print(27) assert("ef7903b1e811a086a9a5a5142242132e1367ae1d" == sha1(string.char(143,70):rep(65)), 27) print(28) assert("6e16b2dac71e338a4bd26f182fdd5a2de3c30e6c" == sha1(string.char(130,114,144,219,245,72,205,44,149,68,150,169,243):rep(197)), 28) print(29) assert("6cc772f978ca5ef257273f046030f84b170f90c9" == sha1(string.char(26,49,141,64,30,61,12):rep(362)), 29) print(30) assert("54231fc19a04a64fc1aa3dce0882678b04062012" == sha1(string.char(76,252,160,253,253,167,27,179,237,15,219,46,141,255,23,53,184,190,233,125,211,11):rep(741)), 30) print(31) assert("5511a993b808e572999e508c3ce27d5f12bb4730" == sha1(string.char(197,139,184,188,200,31,171,236,252,147,123,75,7,138,111,167,68,114,73,80,51,233,241,233,91):rep(528)), 31) print(32) assert("64c4577d4763c95f47ac5d21a292836a34b8b124" == sha1(string.char(177,114,100,216,18,57,2,110,108,60,81,80,253,144,179,47,228,42,105,72,86,18,30,167):rep(901)), 32) print(33) assert("bb0467117e3b630c2b3d9cdf063a7e6766a3eae1" == sha1(string.char(249,99,174,228,15,211,121,152,203,115,197,198,66,17,196,6,159,170,116):rep(800)), 33) print(34) assert("1f9c66fca93bc33a071eef7d25cf0b492861e679" == sha1(string.char(205,64,237,65,171,0,176,17,104,6,101,29,128,200,214,24,32,91,115,71,26,11,226,69,141,83,249,129):rep(288)), 34) print(35) assert("55d228d9bfd522105fe1e1f1b5b09a1e8ee9f782" == sha1(string.char(96,37,252,185,137,194,215,191,190,235,73,224,125,18,146,74,32,82,58,95,49,102,85,57,241,54,55):rep(352)), 35) print(36) assert("58c3167e666bf3b4062315a84a72172688ad08b1" == sha1(string.char(65,91,96,147,212,18,32,144,138,187,70,26,105,42,71,13,229,137,185,10,86,124,171,204,104,42,2,172):rep(413)), 36) print(37) assert("f97936ca990d1c11a9967fd12fc717dcd10b8e9e" == sha1(string.char(253,159,59,76,230,153,22,198,15,9,223,3,31):rep(518)), 37) print(38) assert("5d15229ad10d2276d45c54b83fc0879579c2828e" == sha1(string.char(149,20,176,144,39,216,82,80,56,38,152,49,167,120,222,20,26,51,157,131,160,52,6):rep(895)), 38) print(39) assert("3757d3e98d46205a6b129e09b0beefaa0e453e64" == sha1(string.char(120,131,113,78,7,19,59,120,210,220,73,118,36,240,64,46,149,3,120,223,80,232,255,212,250,76,109,108,133):rep(724)), 39) print(40) assert("5e62539caa6c16752739f4f9fd33ca9032fff7e1" == sha1(string.char(216,240,166,165,2,203,2,189,137,219,231,229):rep(61)), 40) print(41) assert("3ff1c031417e7e9a34ce21be6d26033f66cb72c9" == sha1(string.char(4,178,215,183,17,198,184,253,137,108,178,74,244,126,32):rep(942)), 41) print(42) assert("8c20831fc3c652e5ce53b9612878e0478ab11ee6" == sha1(string.char(115,157,59,188,221,67,52,151,147,233,84,30,243,250,109,103,101,0,219,13,176,38,21):rep(767)), 42) print(43) assert("09c7c977cb39893c096449770e1ed75eebb9e5a1" == sha1(string.char(184,131,17,61,201,164,19,25,36,141,173,74,134,132,104,23,104,136,121,232,12,203,115,111,54,114,251,223,61,126):rep(458)), 43) print(44) assert("9534d690768bc85d2919a059b05561ec94547fc2" == sha1(string.char(49,93,136,112,92,42,117,28,31):rep(187)), 44) print(45) assert("7dfca0671de92a62de78f63c0921ff087f2ba61d" == sha1(string.char(194,78,252,112,175,6,26,103,4,47,195,99,78,130,40,58,84,175,240,180,255,108,3,42,51,111,35,49,217,160):rep(72)), 45) print(46) assert("62bf20c51473c6a0f23752e369cabd6c167c9415" == sha1(string.char(28,126,243,196,155,31,158,50):rep(166)), 46) print(47) assert("2ece95e43aba523cdbf248d07c05f569ecd0bd12" == sha1(string.char(76,230,117,248,231,228):rep(294)), 47) print(48) assert("722752e863386b737f29a08f23a0ec21c4313519" == sha1(string.char(61,102,1,118):rep(470)), 48) print(49) assert("a638db01b5af10a828c6e5b73f4ca881974124a0" == sha1(string.char(130,8,4):rep(768)), 49) print(50) assert("54c7f932548703cc75877195276bc2aa9643cf9b" == sha1(string.char(193,232,122,142,213,243,224,29,201,6,127,45,4,36,92,200,148,111,106,110,221,235,197,51,66,221,123,155,222,186):rep(290)), 50) print(51) assert("ecfc29397445d85c0f6dd6dc50a1272accba0920" == sha1(string.char(221,76,21,148,12,109,232,113,230,110,96,82,36):rep(196)), 51) print(52) assert("31d966d9540f77b49598fa22be4b599c3ba307aa" == sha1(string.char(148,237,212,223,44,133,153):rep(53)), 52) print(53) assert("9f97c8ace98db9f61d173bf2b705404eb2e9e283" == sha1(string.char(190,233,29,208,161,231,248,214,210):rep(451)), 53) print(54) assert("63449cfce29849d882d9552947ebf82920392aea" == sha1(string.char(216,12,113,137,33,99,200,140,6,222,170,2,115,50,138,134,211,244,176,250,42,95):rep(721)), 54) print(55) assert("15dc62f4469fb9eae76cd86a84d576905c4bbfe7" == sha1(string.char(50,194,13,88,156,226,39,135,165,204):rep(417)), 55) print(56) assert("abbc342bcfdb67944466e7086d284500e25aa103" == sha1(string.char(35,39,227,31,206,163,148,163,172,253,98,21,215,43,226,227,130,151,236,177,176,63,30,47,74):rep(960)), 56) print(57) assert("77ae3a7d3948eaa2c60d6bc165ba2812122f0cce" == sha1(string.char(166,83,82,49,153,89,58,79,131,163,125,18,43,135,120,17,48,94,136):rep(599)), 57) print(58) assert("d62e1c4395c8657ab1b1c776b924b29a8e009de1" == sha1(string.char(196,199,71,80,10,233,9,229,91,72,73,205,75,77,122,243,219,152):rep(964)), 58) print(59) assert("15d98d5279651f4a2566eda6eec573812d050ff7" == sha1(string.char(78,70,7,229,21,78,164,158,114,232,100,102,92,18,133,160,56,177,160,49,168,149,13,39,249,214,54,41):rep(618)), 59) print(60) assert("c3d9bc6535736f09fbb018427c994e58bbcb98f6" == sha1(string.char(129,208,110,40,135,3):rep(618)), 60) print(61) assert("7dc6b3f309cbe9fa3b2947c2526870a39bf96dc4" == sha1(string.char(126,184,110,39,55,177,108,179,214,200,175,118,125,212,19,147,137,133,89,209,89,189,233,164,71,81,156,215,152):rep(908)), 61) print(62) assert("b2d4ca3e787a1e475f6608136e89134ae279be57" == sha1(string.char(182,80,145,53,128,194,228,155,53):rep(475)), 62) print(63) assert("fbe6b9c3a7442806c5b9491642c69f8e56fdd576" == sha1(string.char(9,208,72,179,222,245,140,143,123,111,236,241,40,36,49,68,61,16,169,124,104,42,136,82,172):rep(189)), 63) print(64) assert("f87d96380201954801004f6b82af1953427dfdcb" == sha1(string.char(153,133,37,2,24,150,93,242,223,68,202,54,118,141,76,35,100,137,13):rep(307)), 64) print(65) assert("a953e2d054dd77f75337dd9dfa58ec4d3978cfb4" == sha1(string.char(112,215,41,50,221,94):rep(155)), 65) print(66) assert("e5c3047f9abfdd60f0c386b9a820f11d7028bc70" == sha1(string.char(247,177,124,213,47,175,139,203,81,21,85):rep(766)), 66) print(67) assert("ee6fe88911a13abfc0006f8809f51b9de7f5920f" == sha1(string.char(81,84,151,242,186,133,39,245,175,79,66,170,246,216,0,88,100,190,137,2,146,58):rep(10)), 67) print(68) assert("091db84d93bb68349eecf6bfa9378251ecd85500" == sha1(string.char(180,71,122,187):rep(129)), 68) print(69) assert("d8041c7d65201cc5a77056a5c7eb94a524494754" == sha1(string.char(188,99,87,126,152,214,159,151,234,223,199,247,213,107,63,59,12,146,175,57,79,200,132,202):rep(81)), 69) print(70) assert("cca1d77faf56f70c82fcb7bc2c0ac9daf553adff" == sha1(string.char(199,1,184,22,113,25,95,87,169,114,130,205,125,159,170,99):rep(865)), 70) print(71) assert("c009245d9767d4f56464a7b3d6b8ad62eba5ddeb" == sha1(string.char(39,168,16,191,95,82,184,102,242,224,15,108):rep(175)), 71) print(72) assert("8ce115679600324b58dc8745e38d9bea0a9fb4d6" == sha1(string.char(164,247,250,142,139,131,158,241,27,36,81,239,26,233,105,64,38,249,151,75,142,17,56,217,125,74,132,213,213):rep(426)), 72) print(73) assert("75f1e55718fd7a3c27792634e70760c6a390d40f" == sha1(string.char(32,145,170,90,188,97,251,159,244,153,21,126,2,67,36,110,31,251,66):rep(659)), 73) print(74) assert("615722261d6ec8cef4a4e7698200582958193f26" == sha1(string.char(51,24,1,69,81,157,34,185,26,159,231,119):rep(994)), 74) print(75) assert("4f61d2c1b60d342c51bc47641e0993d42e89c0f9" == sha1(string.char(175,25,99,122,247,217,204,100,0,35,57,65,150,182,51,79,169,99,9,33,113,113,113):rep(211)), 75) print(76) assert("7d9842e115fc2af17a90a6d85416dbadb663cef3" == sha1(string.char(136,42,39,219,103,95,119,125,205,72,174,15,210,213,23,75,120,56,104,31,63,255,253,100,61,55):rep(668)), 76) print(77) assert("3eccab72b375de3ba95a9f0fa715ae13cae82c08" == sha1(string.char(190,254,173,227,195,41,49,122,135,57,100):rep(729)), 77) print(78) assert("7dd68f741731211e0442ce7251e56950e0d05f96" == sha1(string.char(101,155,117,8,143,40,192,100,162,121,142,191,92):rep(250)), 78) print(79) assert("5e98cdb7f6d7e4e2466f9be23ec20d9177c5ddff" == sha1(string.char(84,67,182,136,89):rep(551)), 79) print(80) assert("dba1c76e22e2c391bde336c50319fbff2d66c3bb" == sha1(string.char(99,226,185,1,192):rep(702)), 80) print(81) assert("4b160b8bfe24147b01a247bfdc7a5296b6354e38" == sha1(string.char(144,141,254,1,166,144,129,232,203,31,192,75,145,12):rep(724)), 81) print(82) assert("27625ad9833144f6b818ef1cf54245dd4897d8aa" == sha1(string.char(31,187,82,156,224,133,116,251,180,165,246,8):rep(661)), 82) print(83) assert("0ce5e059d22a7ba5e2af9f0c6551d010b08ba197" == sha1(string.char(228):rep(672)), 83) print(84) assert("290982513a7f67a876c043d3c7819facb9082ea6" == sha1(string.char(150,44,52,144,68,76,207,114,106,153,99,39,219,81,73,140,71,4,228,220,55,244,210,225,221,32):rep(881)), 84) print(85) assert("14cf924aafceea393a8eb5dd06616c1fe1ccd735" == sha1(string.char(140,194,247,253,117,121,184,216,249,84,41,12,199):rep(738)), 85) print(86) assert("91e9cc620573db9a692bb0171c5c11b5946ad5c3" == sha1(string.char(48,77,182,152,26,145,231,116,179,95,21,248,120,55,73,66):rep(971)), 86) print(87) assert("3eb85ec3db474d01acafcbc5ec6e942b3a04a382" == sha1(string.char(68,211):rep(184)), 87) print(88) assert("f9bd0e886c74d730cb2457c484d30ce6a47f7afa" == sha1(string.char(168,73,19,144,110,93,7,216,40,111,212,192,33,9,136,28,210,175,140,47,125,243,206,157,151,252,26):rep(511)), 88) print(89) assert("64461476eb8bba70e322e4b83db2beaee5b495d4" == sha1(string.char(33,141):rep(359)), 89) print(90) assert("761e44ffa4df3b4e28ca22020dee1e0018107d21" == sha1(string.char(254,172,185,30,245,135,14,5,186,42,47,22):rep(715)), 90) print(91) assert("41161168b99104087bae0f5287b10a15c805596f" == sha1(string.char(79):rep(625)), 91) print(92) assert("7088f4d88146e6e7784172c2ad1f59ec39fa7768" == sha1(string.char(20,138,80,102,138,182,54,210,38,214,125,123,157,209,215,37):rep(315)), 92) print(93) assert("2e498e938cb3126ac1291cee8c483a91479900c1" == sha1(string.char(140,197,97,112,205,97,134,190):rep(552)), 93) print(94) assert("81a2491b727ef2b46fb84e4da2ced84d43587f4e" == sha1(string.char(109,44,17,199,17,107,170,54,113,153,212,161,174):rep(136)), 94) print(95) assert("0e4f8a07072968fbc4fe32deccbb95f113b32df7" == sha1(string.char(181,247,203,166,34,61,180,48,46,77,98,251,72,210,217,242,135,133,38,12,177,163,249,31,1,162):rep(282)), 95) print(96) assert("8d15dddd48575a1a0330976b57e2104629afe559" == sha1(string.char(15,60,105,249,158,45,14,208,202,232,255,181,234,217):rep(769)), 96) print(97) assert("98a9dd7b57418937cbd42f758baac4754d5a4a4b" == sha1(string.char(115,121,91,76,175,110,149,190,56,178,191,157,101,220,190,251,62,41,190,37):rep(879)), 97) print(98) assert("578487979de082f69e657d165df5031f1fa84030" == sha1(string.char(189,240,198,207,102,142,241,154):rep(684)), 98) print(99) assert("3e6667b40afb6bcc052654dd64a653ad4b4f9689" == sha1(string.char(85,82,55,80,43,17,57,20,157,10,148,85,154,58,254,254,221,132,53,105,43,234,251,110,111):rep(712)), 99) -- -- now tests for the HMAC-SHA1 computation -- assert("31285f3fa3c6a086d030cf0f06b07e7a96b5cbd0" == hmac_sha1("63xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "data"), 100) assert("2d183212abc09247e21282d366eeb14d0bc41fb4" == hmac_sha1("64xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "data"), 101) assert("ff825333e64e696fc13d82c19071fa46dc94a066" == hmac_sha1("65xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "data"), 102) print(103) assert("ecc8b5d3abb5182d3d570a6f060fef2ee6c11a44" == hmac_sha1(string.char(220,58,17,206,77,234,240,187,69,25,179,182,186,38,57,83,120,107,198,148,234,246,46,96,83,28,231,89,3,169,42,62,125,235,137), string.char(1,225,98,83,100,71,237,241,239,170,244,215,3,254,14,24,216,66,69,30,124,126,96,177,241,20,44,3,92,111,243,169,100,119,198,167,146,242,30,124,7,22,251,52,235,95,211,145,56,204,236,37,107,139,17,184,65,207,245,101,241,12,50,149,19,118,208,133,198,33,80,94,87,133,146,202,27,89,201,218,171,206,21,191,43,77,127,30,187,194,166,39,191,208,42,167,77,202,186,225,4,86,218,237,157,117,175,106,63,166,132,136,153,243,187)), 103) print(104) assert("bd1577a9417d804ee2969636fa9dde838beb967d" == hmac_sha1(string.char(216,76,38,50,235,99,92,110,245,5,134,195,113,7), string.char(144,3,250,84,145,227,206,87,188,42,169,182,106,31,207,205,33,76,52,158,255,49,129,169,9,145,203,225,90,228,163,33,49,99,29,135,60,112,152,5,200,121,35,77,56,116,68,109,190,136,184,248,144,172,47,107,30,16,105,232,146,137,24,81,245,94,28,76,27,82,105,146,252,219,119,164,21,14,74,192,209,208,156,56,172,124,89,218,51,108,44,174,193,161,228,147,219,129,172,210,248,239,22,11,62,128,1,50,98,233,141,224,102,152,44,68,66,46,210,114,138,113,121,90,7,70,125,191,192,222,225,200,217,48,22,10,132,29,236,71,108,140,102,96,51,142,51,220,4)), 104) print(105) assert("e8ddf90f0c117ee61b33db4df49d7fc31beca7f7" == hmac_sha1(string.char(189,213,184,86,24,160,198,82,138,223,71,149,249,70,183,47,0,106,27,39,85,102,57,190,237,182,2,10,21,253,252,3,68,73,154,75,79,247,28,132,229,50,2,197,204,213,170,213,255,83,100,213,60,67,202,61,137,125,16,215,254,157,106,5), string.char(78,103,249,15,43,214,87,62,52,57,135,84,44,92,142,209,120,139,76,216,33,223,203,96,218,12,6,126,241,195,47,203,196,22,113,138,228,44,122,37,215,166,184,195,91,97,175,153,115,243,37,225,82,250,54,240,20,237,149,183,5,43,142,113,214,130,100,149,83,232,70,106,152,110,25,74,46,60,159,239,193,173,235,146,173,142,110,71,1,97,54,217,52,228,250,42,223,53,105,24,87,98,117,245,101,189,147,238,48,111,68,52,169,78,151,38,21,249)), 105) print(106) assert("e33c987c31bb45b842868d49e7636bd840a1ffd3" == hmac_sha1(string.char(154,60,91,199,157,45,32,99,248,5,163,234,114,223,234,48,238,82,43,242,52,176,243,5,135,26,141,49,105,120,220,135,192,96,219,152,126,74,58,110,200,56,108,1,68,175,82,235,149,191,67,72,195,46,35,131,237,188,177,223,145,122,26,234,136,93,34,96,71,214,55,27,13,116,235,109,58,83,175,226,59,13,218,93,5,132,43,235), string.char(182,10,154)), 106) print(107) assert("f6039d217c16afadfcfae7c5e3d1859801a0fe22" == hmac_sha1(string.char(73,120,173,165,190,159,174,100,255,56,217,98,249,11,166,25,66,95,96,99,70,73,223,132,231,147,220,151,79,102,111,98), string.char(134,93,229,103)), 107) print(108) assert("f6056b19cf6b070e62a0917a46f4b3aefcf6262d" == hmac_sha1(string.char(49,40,62,214,208,180,147,74,162,196,193,9,118,47,100,9,235,94,3,122,226,163,145,175,233,148,251,88,49,216,208,110,13,97,255,189,120,252,223,241,55,210,77,4), string.char(92,185,37,240,36,97,21,132,188,80,103,36,162,245,63,104,19,106,242,44,96,28,197,26,46,168,73,46,76,105,30,167,101,64,67,119,65,140,177,226,223,108,206,60,59,0,182,125,42,200,101,159,109,6,62,85,67,66,88,137,92,234,61,19,22,177,144,127,129,129,195,230,180,149,128,148,45,18,94,163,196,55,70,184,251,3,200,162,16,210,188,61,186,218,173,227,212,8,125,20,138,82,68,170,24,158,90,98,228,166,246,96,74,24,217,93,91,102,246,221,121,115,157,243,45,158,45,90,186,11,127,179,59,72,37,71,148,123,62,150,114,167,248,197,18,251,92,164,158,83,129,58,127,162,181,92,85,121,13,118,250,221,220,150,231,5,230,28,213,25,251,17,71,68,234,173,10,206,111,72,123,205,49,73,62,209,173,46,94,91,151,122)), 108) print(109) assert("15ddfa1baa0a3723d8aff00aeefa27b5b02ede95" == hmac_sha1(string.char(91,117,129,150,117,169,221,182,193,130,126,206,129,177,184,171,174,224,91,234,60,197,243,158,59,0,122,240,145,106,192,179,96,84,46,239,170,123,120,51,142,101,45,34), string.char(27,71,38,183,232,93,23,174,151,181,121,91,142,138,180,125,75,243,160,220,225,205,205,72,13,162,104,218,47,162,77,23,16,154,31,156,122,67,227,25,190,102,200,57,116,190,131,8,208,76,174,53,204,88,227,239,71,67,208,32,57,72,165,121,80,139,80,29,90,32,229,208,115,169,238,189,206,82,180,68,157,124,119,1,75,27,122,246,197,178,90,225,138,244,73,12,226,104,191,70,53,210,245,250,239,238,3,229,196,22,28,199,122,158,9,33,109,182,109,87,25,159,159,146,217,77,37,25,173,211,38,173,70,252,18,193,7,167,160,135,63,190,149,14,221,143,173,152,184,143,157,245,137,219,74,239,185,40,14,0,29,87,169,84,67,75,255,252,201,131,75,108,43,129,210,193,108,139,60,228,29,36,150,15,86)), 109) print(110) assert("d7cba04970a79f5d04c772fbe74bcc0951ff9c67" == hmac_sha1(string.char(159,179,206,236,86,25,53,102,163,243,239,139,134,14,243), string.char(106,160,249,31,114,205,9,66,139,182,209,218,31,151,57,132,182,85,218,220,103,15,210,218,101,244,240,227,12,184,127,137,40,127,232,195,234,182,0,214,125,122,141,207,61,244,143,202,159,229,100,76,165,44,226,137,100,61,1,107,132,142,144,158,223,249,151,78,186,194,189,83,45,66,178,41,23,172,195,137,170,216,208,27,149,112,68,188,0)), 110) print(111) assert("84625a20dc9ada78ec9de910d37734a299f01c5d" == hmac_sha1(string.char(85,239,250,237,210,126,142,84,119,107,100,163,15,179,132,206,112,85,119,101,44,163,240,10,14,69,169,158,170,190,95,66,129,69,218,229), string.char(210,103,131,185,91,224,115,108,129,11,50,16,90,98,64,124,157,177,50,21,30,201,244,101,136,104,149,102,34,166,25,62,1,79,216,4,221,113,168,169,5,151,172,22,166,28,130,137,251,164,220,189,253,45,149,80,247,84,130,208,69,49,120,8,90,154,100,191,121,81,230,207,23,189,7,164,112,123,158,192,224,255,218,200,70,238,211,161,35,251,150,125,24,10,131,220,57,178,196,38,231,196,206,94,118,32,56,197,136,148,145,247,188,64,56,53,195,140,92,202,22,122,229,105,115,14,42,27,107,223,105)), 111) print(112) assert("c463318ac1878cd770ec93b2710b706296316894" == hmac_sha1(string.char(162,21,153,195,254,135,203,75,152,144,200,187,226,4,248,93,161,180,219,181,99,130,122,28,179,140,152,9,21,115,34,140,162,45,88,4,33,238,179,125,58,23,108,194,158,48,191,40,3,50,81,247,114,241,0,88,147,93,57,178,73,187,11,195,254,171,106,167,245,190,117,160,1,219,200,249,107,233,58,19,122), string.char(246,179,198,163,52,106,45,38,131,22,142,185,149,121,79,211,0,16,102,52,46,176,83,7,32,42,103,184,234,107,180,128,128,130,21,27,236)), 112) print(113) assert("e2d37df980593b3e52aadb0d99d61114fb2c1182" == hmac_sha1(string.char(43,84,125,158,182,211,26,238,222,247,6,171,184,54,70,44,169,4,74,34,98,71,118,189,138,53,8,164,117,22,76,171,57,255,122,230,110,122,228,22,252,123,174,218,222,77,80,150,159,43,236,137,234,48,122,138,100,137,112), string.char(249,234,226,86,109,2,157,76,229,42,178,223,196,247,42,194,17,17,117,3,45,6,80,202,22,105,44,242,84,25,21,189,5,216,35,200,220,192,110,81,215,145,109,179,48,44,40,35,216,240,48,240,33,210,79,35,64,189,81,15,135,228,83,14,254,32,211,229,158,79,188,230,84,106,78,126,226,106,203,59,67,134,186,52,21,48,2,142,231,116,241,167,177,175,74,188,232,234,56,41,181,118,232,190,184,76,64,109,167,178,123,118,3,50,46,254,253,83,156,116,220,247,69,27,160,167,210,205,79,60,28,253,17,219,32,44,217,223,77,153,229,55,113,75,234,154,247,13,133,49,220,200,241,111,136,205,14,78,222,55,181,250,160,143,224,37,63,227,155,12,39,173,209,45,171,93,93,70,36,129,111,173,183,112,31,231,22,146,129,171,75,128,45)), 113) print(114) assert("666f9c282cf544c9c28006713a7461c7efbbdbda" == hmac_sha1(string.char(71,33,203,83,173,199,175,245,206,13,237,187,54,61,85,15,153,125,168,223,231,56,46,250,173,192,247,189,45,166,225,223,109,254,15,79,144,188,71,201,70,25,218,205,13,184,204,219,221,82,133,189,144,179,242,125,211,108,100,1,132,110,231,87,107,91,169,101,241,105,30), string.char(98,122,51,157,136,38,149,9,82,27,218,155,76,61,254,154,43,172,59,105,123,45,97,146,191,58,50,153,139,40,37,116)), 114) print(115) assert("6904a4ce463002b03923c71cdac6c38f57315b63" == hmac_sha1(string.char(15,40,41,76,105,201,153,223,174,12,100,114,234,95,204,95,84,31,26,28,69,85,48,111,40,173,162,6,198,36,252,179,244,9,112,213,64,87,58,186,4,147,229,211,161,30,226,159,75,38,91,89,224,245,156,110,229,50,210), string.char(213,155,72,86,75,185,138,211,199,57,75,9,1,141,184,89,82,180,105,17,193,63,161,202,25,60,16,201,72,179,74,129,73,172,84,39,140,33,25,122,136,143,116,100,100,234,246,108,135,180,85,12,85,151,176,154,172,147,249,242,180,207,126,126,235,203,55,8,251,29,135,134,166,152,80,76,242,15,69,225,199,221,133,118,194,227,9,185,190,125,120,116,182,15,241,209,113,253,241,58,145,106,136,25,60,47,174,209,251,54,159,98,103,88,245,61,108,91,12,245,119,191,232,36)), 115) print(116) assert("c57c742c772f92cce60cf3a1ddc263b8df0950f3" == hmac_sha1(string.char(193,178,151,175,44,234,140,18,10,183,92,17,232,95,94,198,229,188,188,131,247,236,215,129,243,171,223,83,42,173,88,157,29,46,221,57,80,179,139,80), string.char(214,95,30,179,51,95,183,198,185,9,76,215,255,122,91,103,133,117,42,33,0,145,60,129,129,237,203,59,141,214,108,79,247,244,187,250,157,177,245,72,191,63,176,211)), 116) print(117) assert("092336f7f1767874098a54d5f27092fbb92b7c94" == hmac_sha1(string.char(208,10,217,108,72,232,56,67,6,179,160,172,29,67,115,171,118,82,124,118,61,111,21,132,209,92,212,166,181,129,43,55,198,96,169,112,86,212,68,214,81,239,122,216,104,73,114,209,60,182,248,118,74,100,26,1,176,3,166,188), string.char(42,4,235,56,198,119,175,244,93,77)), 117) print(118) assert("c1d58ad2b611c4d9d59e339da7952bdae4a70737" == hmac_sha1(string.char(100,129,37,207,188,116,232,140,204,90,90,93,124,132,140,81,102,156,67,254,228,192,150,161,10,62,143,218,237,111,151,98,78,168,188,87,170,190,35,228,169,228,143,252,213,85,11,124,92,91,18,27,122,141,98,6,77,106,205,209,2,185,249), string.char(58,190,56,255,176,80,220,228,0,251,108,108,220,197,51,131,164,162,60,181,21,54,122,174,31,13,4,84,198,203,105,11,64,230,1,30,218,208,252,219,44,147,2,108,227,66,49,71,21,95,248,93,193,180,165,240,224,226,13,9,208,186,12,118,243,28,113,49,122,192,212,164,43,41,151,183,187,126,115,85,174,40,125,9,54,193,164,95,21,77,200,226,50,115,187,122,34,141,255,224,239,12,132,191,48,102,205,248,128,164,116,48,39,191,98,53,169,230,249,215,231,152,45,27,226,10,143,15,209,157,208,181,15,210,195,5,29,48,29,125,62,59,191,216,170,179,226,110,40,46,32,130,235,48,234,233,17)), 118) print(119) assert("3de84c915278a7d5e7d5629ec88193fb5bbadd15" == hmac_sha1(string.char(89,175,111,33,154,12,173,230,28,117), string.char(188,233,41,180,142,157,96,76,105,212,92,202,155,167,179,28,12,156,64,73,32,253,253,166,9,240,7,0,248,43,101,135,226,231,173,221,180,43,160,217,6,38,183,186,214,217,137,83,148,148,40,141,217,98,209,12,167,102,95,166,136,231,232,84,59,112,148,201,166,104,135,124,189,85,160,183,143,122,200,190,144,205,25,254,180,188,108,225,171,131,240,185,86,243,192,173,130,50,150,57,242,180,132,193,11,110,247,121,25,24,110,199,156,121,233,149,79,103,15,173,184,143,45,125,164,242,125,10,183,189,189,135,121,59,148,106,77,9,16,123,176,100,142,246,156,180,202,87,43,102,113,123)), 119) print(120) assert("e8cc5a50f80e7d52edd7ae4ec037414b70798598" == hmac_sha1(string.char(139,243,17,238,11,156,138,122,212,86,201,213,100,167,65,199,92,182,255,36,221,82,192,213,199,162,69,42,222,95,65,170,146,48,39,185,147,18,140,122,168,141), string.char(141,216,25,29,235,207,123,188,85,53,131,180,125,226,97,244,250,138,64,39,30,250,146,101,219,171,213,158,164,172,137,22,136,86,46,77,95,213,66,198,15,24,164,148,29,166,169,195,196,111,122,147,247,215,148,9,129,40,133,178,69,242,171,235,181,83,241,208,237,17,37,30,188,152,47,214,69,229,114,225,75,172,163,184,38,158,230,177,187,124,33,240,238,148,197,235,237,98,33,237,59,205,147,128,108,254,95,5,6,49,10,224,78,139,164,235,220,78,224,15,213,136,198,217,114,156,130,247,167,64,36,10,183,221,193,220,195,80,125,143,248,228,254,6,221,137,170,211,66)), 120) print(121) assert("80d9a0bc9600e6a0130681158a1787ef6b9c91d6" == hmac_sha1(string.char(152,28,190,131,179,120,137,63,214,85,213,89,116,246,171,92,0,47,44,102,120,206,185,116,71,106,195), string.char(250,9,181,163,46,88,166,238,164,40,207,236,152,104,201,42,14,255,125,57,173,176,230,171,63,6,254,130,140,201,45,152,164,216,171,27,172,105,19,103,128,33,255,93,64,155,55,210,140,2,94,168,168,164,5,218,249,227,221,133,72,112,97,243,140,149,193,80)), 121) print(122) assert("cb4182de586a30d606a057c948fe33733145790a" == hmac_sha1(string.char(193,229,65,81,159,93,162,173,74,64,195,41,80,189,104,238,119,67,255,63,209,247,146,247,210,208,86,14,102,153,246,175,242,209,42,4,243,138,217,58,206,147,19,163,152,239,154,78,5,1,175,97,251,24,185,10,67,107,174,145,178,121,36,238,108,85,214,162,78,195,107,135,114,76,180,37,99,103,78,232,29,244,11,60,236,112,18,241,39,164,107,18), string.char(222,85,11,36,12,191,252,103,180,161,84,168,21,125,50,76,4,148,195,230,210,114,35,116,225,176,16,64,44,20,17,224,227,243,175,251,204,177,41,223,76,216,228,221,54,226,150,209,145,175,142,137,140,25,196,99,252,175,125,15,39,76,47,127,188,51,88,227,194,171,249,141,12,249,225,199,241,112,153,26,107,204,191,23,241,46,223,143,9,9,46,64,197,209,23,18,208,139,148,45,146,94,80,86,49,12,122,218,14,210,133,164,39,227,102,60,129,6,43)), 122) print(123) assert("864e291ec69124c3a43976bae4ba1788f181f027" == hmac_sha1(string.char(231,211,73,154,64,125,224,253,200,234,208,210,83,9), string.char(33,248,155,139,159,173,90,40,200,95,96,12,81,103,8,139,211,189,87,75,8,6,36,103,116,204,137,181,81,233,97,171,47,27,143,164,63,3,223,107,80,232,182,154,7,255,190,171,209,115,219,6,34,109,1,254,214,73,2)), 123) print(124) assert("bee434914e65818f81bd07e4e0bbb58328be3ca1" == hmac_sha1(string.char(222,123,148,175,157,117,104,212,169,13,252,113,231,104,37,8,147,119,92,27,100,132,250,105,63,13,195,90,251,122,185,97,159,68,36,7,75,163,179,3,6,170,164,152,86,30,49,239,201,245,43,220,78,62,154,206,95,24,149,138,138,15,24,68,58,255,99,88,143,192,12), string.char(97,76,73,171,140,99,57,217,56,73,182,189,58,19,177,104,85,85,45,31,170,132,53,51,155,143,70,169,189,5,41,231,34,132,235,228,114,58,100,105,146,27,67,89,32,34,78,133,155,222,88,26,83,198,128,183,19,243,27,186,192,77,184,54,142,57,24)), 124) print(125) assert("0268f79ef55c3651a66a64a21f47495c5beeb212" == hmac_sha1(string.char(181,166,229,31,47,25,64,129,95,242,221,96,73,42,243,170,15,33,14,198,78,194,235,139,177,112,191,190,52,224,93,95,107,125,245,17,170,161,53,148,19,180,83,154,45,98,76,170,51,178,114,71,34,242,184,75,1,130,199,40,197,88,203,86,169,109,206,67,86,175,201,135,101,76,130,144,248,80,212,14,119,186), string.char(53,208,22,216,93,88,59,64,135,112,49,253,34,11,210,160,117,40,219,36,226,45,207,163,134,133,199,101)), 125) print(126) assert("bcb2473c745d7dee1ec17207d1d804d401828035" == hmac_sha1(string.char(143,117,182,35), string.char(110,95,240,139,124,96,238,255,165,146,205,18,155,244,252,176,24,19,253,39,33,248,90,95,34,115,70,63,195,91,124,144,243,91,110,80,173,47,46,231,73,228,207,37,183,28,42,144,66,248,178,255,129,52,55,232,1,33,193,185,184,237,8)), 126) print(127) assert("402ed75be595f59519e3dd52323817a65e9ff95b" == hmac_sha1(string.char(247,77,247,124,27,156,148,227,12,21,17,94,56,14,118,47,140,239,200,249,216,139,7,172,16,211,237,94,62,201,227,42,250,8,179,21,39,85,186,145,147,106,127,67,111,250,163,89,152,115,166,254,8,246,141,238,43,45,194,131,191,202), string.char(138,227,90,40,221,37,181,54,26,20,24,125,19,101,12,120,111,20,104,10,225,140,64,218,8,33,179,95,215,142,203,127,243,231,166,76,234,159,59,160,132,56,215,143,103,75,155,158,56,126,71,252,229,54,34,240,30,133,110,67,146,213,116,73,14,160,186,169,155,196,84,132,171,200,171,56,92,38,136,90,57,155,145,67,190,198,235,112,242,120,150,191,216,41,21,36,205,42,68,145,226,246,178,70,60,157,254,206,70,84,189,36,197,48,208,249,144,223,6,72,17,253,236,106,205,245,30,1,80,121,165,103,12,202,115,227,192,64,42,223,113,200,195,156,120,202,110,131,130,39,64,217,108,23,133,140,56,144,167,77,45,236,145,161,150,229,85,231,203,159,203,85,125,221,226)), 127) print(128) assert("20231b6abcdd7e5d5e22f83706652acf1ae5255e" == hmac_sha1(string.char(132,122,252,170,107,28,195,210,121,194,245,252,42,64,42,103,220,18,61,68,19,78,182,234,93,130,175,20,4,199,66,91,247,247,87,107,89,205,68,125,19,254,59,47,228,134,200,145,148,78,52,236,51,255,152,231,47,168,213,124,228,34,48), string.char(61,232,69,199,207,49,72,159,37,230,105,207,63,141,245,127,142,77,168,111,126,92,145,26,202,215,116,19,125,81,203,11,86,36,19,218,90,255,4,10,21,185,151,111,188,125,123,2,137,151,171,178,195,199,106,55,42,42,20,164,35,177,237,41,207,24,102,218,213,223,204,186,212,30,59,121,52,34,84,76,142,179,75,6,84,8,72,210,72,177,45,103,218,70,165,69,36,152,50,228,147,192,61,104,209,76,155,147,169,162,151,178,72,109,241,41,76,0,60,251,107,99,92,37,95,215,172,154,172,93,254,65,176,43,99,242,151,78,48,58,35,49,23,174,115,224,227,106,49,30,9)), 128) print(129) assert("b5a24d7aadc1e8fb71f914e1fa581085a8114b27" == hmac_sha1(string.char(233,21,254,12,70,129,236,10,187,36,119,197,152,242,131,11,10,243,169,217,128,247,196,111,183,109,146,155,92,91,71,83,0,136,109,1,130,143,0,8,6,22,160,153,190,164,199,56,152,229), string.char(152,112,218,132,38,125,94,106,64,9,137,105)), 129) print(130) assert("7fd9169b441711bef04ea08ed87b1cd8f245aeb2" == hmac_sha1(string.char(108,226,105,159), string.char(103,218,254,85,50,58,111,74,108,60,174,27,113,65,100,217,97,208,125,38,170,151,72,125,82,114,185,58,4,143,39,223,250,168,66,182,37,216,130,111,103,157,59,0,245,222,8,65,240)), 130) print(131) assert("98038102f8476b28dd11b535b6c1b93eb8089360" == hmac_sha1(string.char(77,121,52,138,71,149,161,87,106,75,232,247,8,148,175,24,23,60,151,104,176,208,148,227,226,191,73,123,164,36,177,235,101,190,128,202,139,116,201,125,61,41,204,187,48,107,63,231,12,137,11,228,93,136,178,243,90), string.char(90,6,232,110,12,66,45,86,141,121,2,6,177,135,64,208,45,178,129,37,253,246,74,48,71,211,243,121,31,209,138,147,185,141,65,185,245,9,137,134,148,123,181,128,204,74,222,150,239,169,179,36,236,104,147,255,251,204,5,191,198,185,153,195,26,112,179,170,232,101,238,143,143)), 131) print(132) assert("ba43c9b8e98b4b7176a1bb63fcbed5b004dc4fcd" == hmac_sha1(string.char(133,107,178,183,204,2,203,106,242,180,87,58,134), string.char(211,208,255,34,198,99,119,185,171,52,118,94,65,241,45,24,40,6,2,203,126,216,21,51,245,154,92,198,201,220,190,135,182,137,113,68,250,94,126,233,140,94,118,244,244,98,252,97,217,204,239,218,178,240,65,150,246,217,231,142,157,33,113,135,135,214,137,103,211,213,48,132,171,43,96,51,241,45,42,237,53,247,134,102,163,214,96,147,131,74,180,19,7,12,174,60,37,60,78,85,92,186,121,27,234,128,132,64,47,106,127,218,52,30,59,230,85,240,164,54,168,232,131,110,145,125,255,238,145,237,134,196,197,138,105,74,34,134,29,249,222,119,194,104,230)), 132) print(133) assert("0c1ad0332f0c6c1f61e6cc86f0a343065635ecb3" == hmac_sha1(string.char(230,111,251,74,216,102,12,134,90,44,121,175,56,221,225,235,180,246,56,12,236,119,119,109,97,59,224,121,27,37,72,219,138,193,50,219,193,152,1,229,224,197,233,76,188,62,120,17,63,158,186,198,87,135,34,60,164,139,3,200,20,188,203,110,212,137,91,70,35,255,146,213,216,71,73,143,55,219,54,142,105,83,175,193,32,226,150,51,59), string.char(185,250,11,8,121,214,91,27,1,50,67,204,219,252,212,198,117,234,57,127,214,12,220,104,44,177,225,238,103,138,144,162,28,69,143,108,192,4,160,63,175,185,123,46,151,221,127,145,55,32,85,245,251,178,125,223,107,192,206,207,232,231,190,44,221,173,1,59,12,178,112,22,253,222,14,40,18,141,128,144,196,6,112,206,183,144,215,156,159,79,132,152,170,22,68,106,137,248,12,242,231,98,96,144,148,20,212,30,242,109,36,112,50,51,57,212,181,191,80,73,215,119,244,209,57,108,147,182,67,204,154,48,216,116)), 133) print(134) assert("466442888b6989fd380f918d0476a16ae26279cf" == hmac_sha1(string.char(250,60,248,215,154,159,2,121), string.char(236,249,8,10,180,146,36,144,83,196,49,166,17,81,51,72,28)), 134) print(135) assert("f9febfeda402b930ec1b95c1325788305cb9fde8" == hmac_sha1(string.char(124,195,165,216,158,253,119,86,162,36,185,72,162,141,160,225,183,25,54,123,73,61,40,165,101,154,157,200,113,14,117,144,185,64,236,219,3,87,90,49), string.char(73,1,223,35,5,159,39,85,95,170,227,61,14,227,142,222,255,253,152,123,104,35,229,6,195,106,30,59,5,36,2,173,71,161,217,189,47,193,3,216,34,10,25,30,212,255,141,94,25,72,52,58,50,56,180,99,173,155)), 135) print(136) assert("53fe70b7e825d017ef0bdecbacdda4e8a76cbc6f" == hmac_sha1(string.char(144,144,130,150,207,183,143,100,188,177,90,5,4,95,116,105,252,118,187,251,35,113,251,86,36,234,176,165,55,165,158,4,182,85,62,255,18,146,128,67,221,183,78,71,158,184,140,14,84,44,36,79,244,158,37,1,122,43,103,228,217,253,72,113,228,121,160,29,87,5,158,64,38,253,179,122,187,157,106,99,161,79,97,176,119,86,101,40,142,241,217,85), string.char(12,89,157,112,207,206,171,254,87,106,42,113,70,72,222,239,88,94,14,41,14,175,206,56,219,244,230,40,33,154,107,249,45,70,55,104,151,193,246,133,99,59,244,179,8,145,225,100,146,142,128,74,40,155,99,93,204,253,249,222,64,99,156,121,142,49,166,62,171,223,135,55,212,183,144,218,56,12,211,99,254,58,249,219,197,189,173,141,60,196,241,157,67,151,251,172,49,105,200,88,224,175,9,79,65,40,5,255,222,14,152,149,228,83,154,207,104,132,106,96,40,229,182,120,100,207,223,81,171,141,1,171)), 136) print(137) assert("81b1df7265954a8aee4e119800169660ff9e75c8" == hmac_sha1(string.char(232,167,4,53,90,111,79,91,163,125,230,202,52,242,160,135,66,211,246,17,131,109,109,235,91), string.char(111,177,251,180,63,13,33,205,231,130,203,167,177,156,87,70,33,148,229,163,158,224,123,37,18,204,185,89,235,2,30,252,229,202,170,157,175,157,208,254,135,190,34,14,42,211,154,243,31,100,71,53,169,76,36)), 137) print(138) assert("caf986508402b3feb70c5b44d902f4a9428a44d2" == hmac_sha1(string.char(127,2,162,53,6,172,189,169,176,254,107,46,57,207,23,25,182,72,34,228,164,113,12,179,149,45,169,19,3,204,202,10,126,153,130,41,143,200,198,47,215,15,58,124,225,60,171,98,8,211,72,235,211,187,172,37,119,96,55,243,98,198,225,191,79,207,94,215,255,21,101,128,153,233,88,101,57,195,70,194), string.char(97,24,129,203,10,176,242,39,165,95,51,30,187,106,207,160,18,154,16,130,178,80,206,128,148,56,213,55,46,85,76,100,50,131,41,167,130,12,81,161,158,55,181,12,12,38,89,193,136,220,81,114,191,157,20,221,171,245)), 138) print(139) assert("83bd91a9e8072010f3b54d215c56ada0cd810bb6" == hmac_sha1(string.char(215,33,57,193,51,126,38,114,7,29,93,101,78,152,222,121,42,0,236,169,48,137,202,48,90,249,235,46,44,126,78,251,15,84,200,235,43,108,8,196,210,57,152,86,254), string.char(153,35,68,230,52,95,243,220,32,101,148,76,80,168,187,172,170,254,10,70,31,117,40,131,61,155,200,189,25,198,120,41,181,53,14,175,64,89,126,94,242,61,52,1,188,255,121,254,74,88,19,10,126,225,89,31,21,104,199,82,149,60,110,194,123,236,13,38,7,213,176,182,202,211,178,185,99,8,173,220,168,166,108,208,71,152,174,5,134,167,220,47,74,177,231,90,114,208,168,47,112,74,58,73,94,224,101,64,128,255,186,179,119,159,117,110,2,188,38,73,230,39,50,73,162,22,117,185,182,168,70,252,11,242,243,165,32,104,220,211)), 139) print(140) assert("c123d92ee67689922dfb3b68a45584e7e5dc5dc3" == hmac_sha1(string.char(167,32,181,181,249,210), string.char(249,7,96,196,48,157,109,129,192,227,82,84,196,167,224,145,61,177,60,74,217,117,199,147,147,54,198,138,5,51,135,112,29,184,49,16,0,240,172,21,214,114,146,57,2,154,205,60,113,32,113,255,165,5,178,15,159)), 140) print(141) assert("454d9ba00ac4e0e90a2866ba2abefba40dac9aab" == hmac_sha1(string.char(116,2,170,84,236,37), string.char(219,144,86,39,237,166,110,90,213,70)), 141) print(142) assert("e919cce3908786205511fee0283e1eb41c0c45a1" == hmac_sha1(string.char(180,76,140,201,56,232,48,183,173,36,111,94,208,153,234,255,52,18,121,118,117,77,92,74,241,103,193,164,169,1,60,46,101,73,61,221,26,253,209,124,99,154,177,218,59,238,159,191,0,65,117,78,15,12,92,35,254,40,11,112,112,91,49,248,198,229,161,247,130,170,76,146,8,220,134,96,155,68,50,168,186,135,188,186,36), string.char(26,47,201,201,197,232,196,239,204,197,162,14,53,254,88,75,43,254,11,20,52,61,136,206,162,29,223,55,125,50,200,239,135,51,154,54,78,191,188,0,137,191,149,162,191,103,0,168,52,178,147,251,253,86,98,17,15,202,231,0,122,10,131,25,15,129,48,190,60,205,185,114,193,122,19,47,52,142,124,107,45,174,221,196,18,32,79,12,129,84,40)), 142) print(143) assert("fa770f6b76984edb0f7fa514a19d3c7ef9c82c51" == hmac_sha1(string.char(70,55,200,82,238,241,84,180,129,122,103,199,170,177), string.char(88,236,14,60,249,2,197,242,76,152,248,241,158,232,113,242,209,93,232,113,147,210,80,180,44,124,186,150,172,177,138,131,117,151,174,231,93,248,244,200,191,169,159,206,232,246,2,121,106,183,107,79,210,73,145,244,254,248,85,217,156,221,238,120,224,176,31,56,246,26,3,186,189,86,41,17,34,8,208,58,46,130,226,139,209,194,3,34,55,213,154,12,250,229,201,122,89,47,177,229,80,165,183,77,178,139,3,241,165,196,239,93,98,101,99,210,99,5,135,132,151,197,4,154,87,130,145,175,243,238,132,0,146,14,6,205,227,78,150,59,191,223,74,145,57,82,30,223,90,205,248,47,195,220,215,167,112,216,20,130,26,88,170,101,26,14,216,62,169,217,1,135,193,147,218)), 143) print(144) assert("d3418e6e6d0a96f8ea7c511273423651a63590c8" == hmac_sha1(string.char(61,175,211,89,77,91,143,76,18,30,252,16,181,45,211,37,207,204,174,174,60,208,36,85,23,106,141,215,62,8,158,98,209,49,96,143,129,99,11,159,79,116,98,244,51,237,227,250,73,196,36,216,181,157,159,87,248,108,29,22,181,175,72,92,160,127,46,204,202,175,61,108,172,50,225,48,84,167,116,67,183), string.char(174,62,218,81,85,89,4,35,26)), 144) print(145) assert("f2fbe13b442bff3c09dcdaeaf375cb2f5214f821" == hmac_sha1(string.char(188,80,129,208,85,53,8,122,92,99,56,251,59,108,97,145,1,97,157,181,156,243,30,204,227,88,205,151), string.char(137,30,19,71,50,239,11,212,91,234,79,248,244,118,108,245,251,78,53,136,249,55,210,231,109,207,153,83,10,63,98,225,79,113,124,64,100,16,195,9,136,28,50,215,93,93,153,25,97,77,4,13,46,34,164,59,33,206,62,125,8,79,219,42,155,39,241,96,18)), 145) print(146) assert("aeacb03e8284a01b93e51e483df58a9492035668" == hmac_sha1(string.char(62,67,97,44,112,68,107,91,105,4,183,154,9,14,164,180,87,140,195,231,62,49,250,154,193,186,219,18,100,156,176,124,223,164,68,64,105,214,144,200,65), string.char(221,20,36,192,59,234,90,174,232,184,75,15,92,229,59,191,36,51,4,190,226,35,237,189,21,100,135,138,171,202,163,227,176,231,72,185,43,197,134,157,44,86,26,42,230,251,2,124,220,245,242,116,77,35,197,154,237,73,117,131,126,242,167,242,8,72,163,171,60,29,77,152,142,69,25,234,195,2,159,49,178,63,48,56,131,143,165,22,142,116,109,11,57,71,101,99,84,204,56,233,173,65,180,228,211,10,197,204,26,70,198,81,217,83,130,70,79,54,93,96,116,32,21,219,193,70,55,84,161,89,47,206,13,167,46,104,205,218)), 146) print(147) assert("e163c334e08bd3fa537c1ea309ce99cfbcd97930" == hmac_sha1(string.char(238,187,29,13,100,125,10,129,46,251,49,62,207,74,243,25,25,73,196,100,114,64,141,173,143,144,70,13,162,227,33,255,83,58,254,138,23,146,90,86,17,33,152,227,15,100,200,147,81,114,166,234,47,60,70,190,208,28,16,44,71,150,101,197,182,57,143,79,29,135,45,211,194,62,234,28,244,74,56,104,187,94,146,174,190,198,55,143,134,60,186,144,190,100,102,0,171,151), string.char(177,90,20,162,64,145,130,87,137,70,153,237,51,138,248,29,166,134,168,68,133,121,161,26,228,137,145,116,243,224,201,229,61,107,250,198,214,208,72,169,248,155,247,54,163,167,71,248,69,106,105,139,224,138,85,94,31,143,4,215,83,239,21,198,28,1,120,83,91,92,58,150,110,77,111,166,222,236,170,129,2,121,86,66,42,129,146,232,46,248,136,175,130,118,126,205,184,136,6,35,180,174,194,59,89,243,199,38,97,48,80,98,45,111)), 147) print(148) assert("6a82b3a54ed409f612a934caf96e6c4799286f19" == hmac_sha1(string.char(11,59,108,100,113,56,239,211,2,138,219,101,50,50,111,31,171,212,228,55,89,196,44,158,77,252,212,134,106,7,250,223,219,46,231,87,9,62,213,104,169,49,1,75,3,10,50,238,5,150,47,14,47,45,171,183,40,245,194,249,228,216,85), string.char(97,131,91,189,9,52,88,203,250,245,46,96,7,95,176,61,57,192,91,231,193,32,41,169,96,101,39,240,29,143,24,56,57,177,70,135,225,90,42,192,134,103,239,175,243,246,76,137,14,237,82,215,7,76,246,219,132,50,175,25,164,4,216,65,102,0,114,216,159,80,58,32,4,100,22,35,71,140,49,16,216,182,91,80,181,129,151,55,130,7,77,84,211,111,45,51,192,123,213,192,11,81,138,60,225,21,37,182,180,223,170,163,110,9,47,214,200,249,164,98,215)), 148) print(149) assert("79caa9946fcf0ccdd882bc409abe77d3470d28f7" == hmac_sha1(string.char(202,142,21,201,45,72,11,211,67,134,42,192,96,255,210,211,252,6,101,131,25,195,101,76,250,161,148,242,30,129,241,85,68,173,236,140,120,80,71,62,55,4,33,104,52,160,143,118,252,72), string.char(100,188,93,165,75,34,224,223,6,130,52,160,83,157,253,27,200,125,117,249,41,203,19,242,4,188,209,213,211,20,162,252,215,238,221,30,219,252,246,110,117,77,89,204,221,246,69,62,160,186,37,144,43,151,39,133,254,134,24,223)), 149) print(150) assert("bd1e60a3df42e2687746766d7d67d57e262f3c9b" == hmac_sha1(string.char(57,212,172,224,206,230,13,50,80,54,19,87,147,166,245,67,118,37,101,214,207,60,66,29,197,236,146,140,192,15,36,155,108,121,215,211,210,118,22,20,56,245,42,153,150,32,224,201,171,2,238,41,70,140,73,60,215,243,86,20,169,152,220,104,95,215,187), string.char(245,123,43,109,29,108,197,27,55,167,255,177,226,205,111,126,146,75,93,70,180,90,139,218,243,232,221,247,129,77,115,101,144,42,13,249,223,127,200,213,140,113,23,10,149,107,244,86,41,133,147,26,167,85,189,76,176,12,190,52,90,54,78,29,97,204,161,224,59,243,128,64,133,95,192,19,137,220,96,228,97,161,51,21,157,172,127,76,53,38,83,126,178,26,203,206,165,241,101,130,79,122,75,29,205,240,1,68,222,48,101,7,29,6,82,240,133,112)), 150) print(151) assert("fe249fa66eb1e6228e1e5166d7862d119ffa0dcf" == hmac_sha1(string.char(152,13,170,129,7,65,32,194,85,196,85,12,170,227,139,215,70,137,246,105,100,111,252,221,54,174,90,169,59,11,198,33,110,94,246,195,174,13,212,47,18,94,17,67,68,56,251,213,92,67,243,114,181,166,24,182,238,146,48,196,11,238,91,213,46,184,187,199,15,221,193,36,73,244,30,222,175,132,165,177,162,54,215,130,171,58,26,144,218,62,172,120,188,20,182,242,47,178,120,175), string.char(129,126,32,58,251,104,186,25,18,204,5,240,65,194,32,205,194,18,151,173,185,249,237,55,145,8,41,18,171,28,59,234,62,163,32,173,197,176,206,224,95,176,218,168,183,82,53,172,205,6,223,190,189,16,3,34,212,201,54,152,89,231,194,95,8,238,133,56,139,157,115,35,74,58,21,162,111,36,105,135,151,30,207,33,198,186,122,221,98,36,196,251,27)), 151) print(152) assert("88aef9bb450b75bf96e8b5fd7831ed0d16d7fe7a" == hmac_sha1(string.char(162,225,9,204,87,95,132,152,211,133,93,120,105,156,131,55,245,224,33,115,182,10,28,49,80,175,241,67,66,52,21,55,174,108,66,100,77,20), string.char(55,61,250,187,157,98,212,245,5,54,170,60,235,228,197,182,230,24,195,215,202,55,56,153,9,94,164,107,67,93,143,1,235,195,133,201,103,57,130,177,71,73,169,80,21,251,130,247,21,61,228,39,166,173,211,203,149,55,11,224,70,52,248,118,112,219,39,188,147,5,203,101,158,134,53,250,103,73,154,249,71,181,53,171,227,26,79,200,145,178,24,80,102,26,90,101,70,143,233,17,150,181,170)), 152) print(153) assert("a057dd823478540bbe9a6fcdf2d4dcfcac663545" == hmac_sha1(string.char(83,17,204,150,211,96,88,52,225,90,61,59,28,127,135), string.char(49,226,129,162,111,75,221,186,24,219,219,178,226,132,19,126,192,69,124,114,214,31,7,127,194,134,202,147,45,176,215,141,41,94,69,38,199,231,185,223,10,104,108,50,237,20,76,194,33,43,117,117,176,3,117,117,55,68,112,207,74,72,163)), 153) print(154) assert("b11757ccfafc8feadc4e9402c820f4903f20032b" == hmac_sha1(string.char(34,11,53,219), string.char(225,194,251,106,223,229,212,105,164,172,25,25,224,199,225,172,197,42,167,1,227,165,17,247,75,250,10,208,99,124,254,158,103,74,89,60,78,141,201,44,253,87,248,239,74,86,75,64,249,189,21,170,249,18,139,21,130,226,66,200,231,35,227,147,95,213,133,35,47,236,52,64,122,115,80,170,27,50,182,151,180,106,120,85,103,255,143,27,233,43,217,152,70,82,8,229,103,42,153,38,130,184,108,160,199,69,38,184)), 154) print(155) assert("bfd0994350b2e1e0d6a1faed059f67f1dd8b361f" == hmac_sha1(string.char(221,156,128,63,215,109,55,123,41,27,110,127,209,144,178,143,120,12,226,47,56,212,131,228,3,40,186,208,233,135,33,206,92,214,153,77,12,220,72,240,176,53,22,37,130,58,180,4,111,124,135,31,192,71,117,87,11,41,231,101,37,164,112,3,55,141,250,131,191,117,90,159,224,244,9,251,154), string.char(35,88,113,69,231,5,150,40,123,13,197,27,49,72,161,1,212,222,252,74,197,170,137,72,231,245,117,236,29,12,36,59,225,103,44,119,136,34,241,17,142,239,46,152,129,163,107,17,165,112,187,15,122,217,67,13,215,157,212,26,103,226,237,161,213,3,152,88,247,236,130,133,84,200,132,191,166,8,96,247,4,142,14,81,179,64,88,202,156,242,181,95,162,19,97,223,51,76,176,218,22,116,24,238,204,128,241,236,204,2,56,86,77,211,4,52,221,82,94,76,9,21,182,112,199,161,29,39,183,120,13,0,124,136,95,182,241,3,73,167,51,237,152,149,84,147,41,42,241,174,12,30,226,245,139,230,127,34,205,41,166,228,242,105,251,4,150,29,106,42,27,239,89,249,230,246,242,149,4,60,240,93,13,166,102,239,81,216,137,196)), 155) print(156) assert("15c4527be05987a9b5c33b920be4a4402f7cf941" == hmac_sha1(string.char(132,158,227,135,167,32,19,192,144,48,232,68,79,78,135,122,136,140,97,67,34,91,225,48,126,67,77,115,154,189,13,45,8,234,59,233,245,77,34,76,95,78,3,250,179,224,20,25,6,202,214,115,165,230,85,115,250,236,135,34,32,158,196,45,207,61,71,51,93,27,187,232,175,233,147,68,231,110,12,198,233,165,24,209,206,25,16,252,127,72), string.char(210,162,121,23,181,21,75,54,110,47,15,166,133,206,100,217,57,133,228,32,112,208,186,28,140,8,207,74,185,17,128,29,181,172,20,156,64,192,112,8,207,131,53,10,182,147,224,71,218,94,71,86,215,2,133,46,160,27,51,189,38,130,224,120,185,144,253,117,193,24,154,229,247,132,62,103,65,163,106,172,22,5,2,32,129,38,213,118,110,125,156,14,48,240,170,225,158,89,92,190,254,231,51,220,8,174,188,233,226,106,224,99,218,82,64,219,206,75,166,111,25,7,87,248,145,251,109,106,243,241,89,200,85,184,155,183,249,61,70,87,115,182,81,80,155,24,245,123,184,102,214,255,122,83,61,214,88,235,169,28,147,196,247,97,28,82,193,72,71,96,243,176,35,189,236,44,184,52,151,249,186,189,150,184,142,238,88,113,120,68,234,50,136,104,80,145,179,57,6,186)), 156) print(157) assert("b9f87f5f23583bdd21b1ea18e7e647513b7b0596" == hmac_sha1(string.char(216,79,247,98,215,219,128,232,135,111,179,168,80,76,36,250,224,157,229,209,238,186,212,188,200,52,208,200,210,79,182,186,22,22,37,34,86,107,89,238,168,90,53,30,151,191,89,163,253,24,204,152,118,1,158,25,168,2,123,91,111,39,101,239,247,37,200,51,215,31,146,211,163,136,208), string.char(153,134,211,81,255,219,50,91,67,48,102,63,244,170,129,66,3,151,110,167,142,150,153,95,89,90,23,87,12,85,42,209,197,36,41,189,199,136,196,159,125,53,253,192,135,234,94,34,87,79,143,213,237,149,212,170,231,181,22,72,81,233,151,243,134,71,160,155,121,32,233,251,187,179,139,48,254,206,172,165,202,105,222,31,223,95,203,87,114,52,218,59,187,41,43,135,200,108,102,201,85,199,8,176,249,44,96,104,160,85,149,177,25,88,55,231,85,120,227,6,180,24)), 157) print(158) assert("0b586895674ab11d3b395c07ddb01151a6e562f5" == hmac_sha1(string.char(26,110,222,147,168,18,74,206,186,238,154,250,229,207,138,175,126,82,236,148,74,180,27,168,159,89,211,34,39,115,227,239,22,199,252,96,100,16,193,117,111,102,75,70,2,114,214,196,29,26,43,189,183,0,194,217,204), string.char(90,15,17,198,223,30,20,138,203,132,6,170,107,40,167,58,194,212,244,49,174,60,209,164,26,87,174,177,41,166,95,173,40,61,47,136,147,239,125,167,146,180,97,167,33,185,5,110,128,36,61,52,140,20,189,16,216,83,164,46,74,16,251,250,72,50,47,5,86,60,56,77,101,64,11,120,124,194,212,199,136,87,157,160,90,172,101,222,235,23,111,11,36,11,68,20,43,251,65,212,206,150,0,50,146,170,183,93,89,142,161,50,110,237,95,191,22,184,62,194,81)), 158) print(159) assert("38b25a1d9d927ba5e6b294d2aa69c0ab8ab0a0c5" == hmac_sha1(string.char(93,218,103,160,235,71,107,150,18,170,193,9,63,245,77,150,71,242,137,52,243,12,207,183,222,252,20,215,210,194,241,79), string.char(87,97,35,201,134,196,180)), 159) print(160) assert("a72ce76565c2876e78f86ce9e137a9881328fddc" == hmac_sha1(string.char(48,215,222,182,164,136,31,53,160,28,61,171,220,159,243,154,169,101,191,193,99,28,140,59,60,215,77,170,51,136,50,145,159,135,237,149,83,154,219,223,29,200,85,193,173,201,66,142,100,21,89,144,111,5,24,229,228,154,160,32,210,71,19,63,244,230,61,185,221,158,151,51), string.char(196,237,178,172,24,232,144,251,253,31,8,63,69,58,202,88,120,219,39,34,223,173,196,164,135,93,188,69,126,58,153,37,72,219,50,152,76,235,244,223,205,60,74,12,109,203,134,239,40,181,207,99,118,149,179,84,14,53,189,201,55,110,67,81,116,140,31,247,163,135,53,254,82,230,55,162,255,230,149,144,217,62,164,59,124,59,78,177,115,47,26,169,228,18,167,232,89,161,56,105,127,111,230,93,230,181,222,212,254,85,32,117,140,80,246,117,21,140,221,198,11,196,112,69,122,125,156)), 160) print(161) assert("cd324faf8204be01296bea85a22d991533fd353e" == hmac_sha1(string.char(25,136,140,2,222,149,164,20,148,15,90,33,106,111,10,252,67,120,57,49,251,171,99,173,114,16,102,240,206,188,231,174,51,124,38,1,217,142,4,15,78,4,5,128,207,82), string.char(84,0,42,233,157,150,105,1,216,32,170,11,100,98,103,220,137,102,32,185,55,211,207,179,252,190,248,117,253,189,196,71,112,32,4,198,87,5,133,125,238,107,210,227,149,206,12,124,31,59,213,66,105,100,240,237,149,232,174,140,127,9,65,204,162,243,100,120,6,229,71,56,140,128,228,102,121,14,43,166,252,230,172,93,96,25,214,174,151,2,50,64,152,164,132,115,109,176,25,144,171,252,231,72)), 161) print(162) assert("fb6e40ddbf3df49d4b44ccecf9e9bc74567df49e" == hmac_sha1(string.char(31,41,38,118,207,197,83,231,45,187,105,1,246,6,34,16,214,148,97,64,139,27,73,129,71,129,183,182,228,12,74,242,94,43,121,163,188,242,92,43,154,103,20,208,89,213,63,46,81,60,69,217,238,237,97,18), string.char(126,99,64,121,143,219,76,227,119,32,135,246,48,55,214,38,179,255,33,43,32,140,228,44,218,40,187,117,172,131,225,222,72,61,213,132,167,121,190,167,66,213,199,59,212,61,69,242,46,169,89,191,74,0,228,208,46,112,7,81,88,203,95,180,179,75,116,222,115,239,1,132,178,73,139,252,77,1,151,222,108,84,196,161,79,220,80,44,223,44,131,252,58,28,201,3,77,211,33,208,237,47,251,79,134,223,48,8,0,236,139,11,232,186,188,134,249,29,208,154,137,169,218,228,203,254,106,88,35,252,155,111,119,14,147,161,19,60,145,157,120,236,108,122,218,168,105,59,10,44,99,208,86)), 162) print(163) assert("373f21bf8fe4e855f882cc976ebed31717f4c791" == hmac_sha1(string.char(198,41,45,129,159,48,37,183,170,144,24,223,108,176,68,60,197,245,254,165,24,152,14,25,243,46,6,25,142,99,64,10,145,229,74,232,162,201,72,215,116,26,179,127,107,45,193,232,96,170,168,153,79,47), string.char(79,250,224,177,254,56,111,120,135,79,55,200,199,71,65,132,222,7,106,170,26,179,235,237,47,172,88,28,244,88,137,177,92,178,147,129,147,85,88,157,30,207,235,246,132,98,232,18,201,57,151,90,174,148,126,22,38,118,133,49,83,156,56,195,10,95,180,250,215,220,251,5,131,243,70,2,162,239,197,153,196,28,181,167,26,14,247,86,244,69,190,100,255,158,217,222,58,116,126,245,240,139,255,213,7,28,222,99,12,127,57,2,212,33,136,220,203,251,87,205,213,160,146,162,73,55,112,203,60,243,139,167,45,91,68,62,204,245,206,221,52,253,5,193,69,19,190,131,64,250,12,127,77,212,53,83,102,212,11,215,253,143,111,201)), 163) print(164) assert("df709285c8a1917aaa6d570bd1d4225ca916b110" == hmac_sha1(string.char(193,124,34,185,160,71,134,56,178,152,165,219,223,89,174,116,11,237), string.char(47,110,24,9,42,187,179,71,114,43,155,129,158,24,130,32,208,3,46,63,16,1,192,210,72,220,200,89,120,80,82,65,199,119,167,86,57,33,105,118,215,60,18,155,17,154,63,59,189,153,236,78,219,89,4,116,208,122,56,65,253,220,57,147,162,242,193,86,45,145,151,61,30,138,105,139,99,89)), 164) print(165) assert("66be81c24c87feeecfd805872c6cde41cb1dd732" == hmac_sha1(string.char(128,186,31,231,128,48,206,237,59), string.char(56,228,42,58,98,45,202,132,30,78,80,52,36,128,7,55,209,148,181,52,185,220,137,85,111,128,220,109,55,70,185,242,253,155,165,193,240,63,144,253,240,147,18,161,7,46,40,148,201,0,127,1,33,145,180,247,90,206,178,96,62,137,130,99,248,248,227,135,213,21,230,40,88,162,106,240,218,93,226,108,9,121,173,70,255,106,137,222,135,206,104,153,171,1,52,156,166,27,98,7,74,180,206,11,193,129,77,194,86,224,175,79,77,95,134,62,58,252,180,100,191,53,28,59,121,123,146,107,121,249,168,51,204,170,141,26,84,126,38,77,203,11,58,123,155,167,60,176,151,7,39,75,217,254,32,110,79,123,188,133,158,178,132,198,169,23,5,104,124,44,206,191,239,139,152,110,207,42)), 165) print(166) assert("2d1dd80c3f0fc323ca46ebd0f73c628caa03f88b" == hmac_sha1(string.char(142,87,50,47,146,180,251,164,35,75,53,50,101,115,90,97,66,12), string.char(174,244,41,143,173,27,117,79,53,73,0,189,83,91,13,71,117,85,96,32,199,168,244,72,218,249,207,107,244,1,113,203,160,156,89,244,132,5,4,220,254,112,77,156,158,105,180,98,40,99,198,236,134,209,13,237,93,220,177,70,97,76,178,106,60,60,92,248)), 166) print(167) assert("444ef9725523ad1aac3d1c20f4954cdf1550d706" == hmac_sha1(string.char(242,169,63,243,133,158,118,205,250,154,66,127,178,170,214,241,96,22,173,138,6,189,90,45,108,70,236,108,93,58,54,204,85,241,194,55,55,184), string.char(30,52,200,164,245,80,75)), 167) print(168) assert("2170bcfb79e4ab2164287a30ee26535681e34505" == hmac_sha1(string.char(121,111,11,221,34,216,169,179,73,247,222,122,96,168,61,168,201,230,139,158,110,154,74,83,118,254,237,255,99,212,46,218,83,69,185,10,249,78,46,76,206,206,137,133,118,57,241,114,228,54,51,68,71,224,188,188,0,119,173,94,120,1,25,13,237,4,181,170,222,92,106,28,9,111,128,137,228,2,110,4,137,171,219,70), string.char(108,95,232,156,70,235,149,211,52,84,86,25,251,127,119,231,109,144,54,177,96,118,213,3,8,119,95,192,187,221,115,83,67,39,207,82,215,85,156,198,179,246,177,202,115,103,79,97,222,133,113,201,27,92,185,48,227,223,142,96,143,181,175,238,115,112,29,30,126,59,109,252,136,153,28,112,50,138,155,249,223,114,93,107,122,114,163,226,53,219,44,15,172,233,76,98,175,107,246,181,249,112,230,173,152,211,183,120,227,165,187,10,240,94)), 168) print(169) assert("2bcd1eb6df83aed8bcdfbb36474651f466b1fb22" == hmac_sha1(string.char(178,135,218,237,192,188,60,157,46,65,76,100,66,248,152,23,200,194,67,107,95,127,67,111,149,64,60,158,199,115,159,64,45,192,212,179,46,13,171,104,139,49,185,254,235,183,65,52,140,30,89), string.char(106,32,155,133,229,130,33,200,31,51,242)), 169) print(170) assert("505910401632c487cd9482ecd6ad16928f21d6f4" == hmac_sha1(string.char(170,34,244,62,31,230,158,102,235,63,93,33,111,253,232,211,132,160,120,156,107), string.char(43,16,194,149,208,76,252,14,73,11,1,172,79,41,132,217,125,96,221,110,199,248,129,122,45,63,77,145,21,98,40,149,154,9,127,27,168,224,204,167,203,74,218,196,236,230,47,29,122,138,65,239,123,120,29,68,236,137,130,95,114,230,185,146,32,69,201,48,251,233,103,61,132,167,245,42,68,249,145,166,137,204,186)), 170) print(171) assert("6d5f9ae7e8a51f2e615ae3aa8525a41b0bf77282" == hmac_sha1(string.char(166,8,119,187,177,166,23,183,147,37,177,162,102,16,93,204,247,119,248,179,23,89,48,145,188,37,197,176,238,218,173,6,216,229,224,108,58,78,40,199,9,241,191,154,88,124,237,142,228,7,235,102,142,123,4,124,38,46,170,229,116,243,104,106,26,163,94,2,118,71,173,171,104), string.char(41,12,123,197,199,117,129,177,132,149,175,83,168,79,76,58,236,204,99,121,155,207,228,89,236,154,103,137,183,221,208,93,22,222,28,237,140,21,25,149,188,111,6,85,251,31,73,79,239,246,66,46,215,157,184,5,207,4)), 171) print(172) assert("8c20120cd131e07d9fa46467602d57c9017ca22d" == hmac_sha1(string.char(12,24,169,75,70,190,156,115,112,233,245,216,85,248,62,24,91,179,204,185,0,129,209,137,116,97,242,183,35,151,91,170,41,4,81,12,120,47,78,145,193,50,237,224,62,203,171,169,6,141,126,75,29,40), string.char(47,165,0,107,170,77,37,219,45,135,102,68,144,218,213,74,35,58,246,179,171,3,148,55,216,32,29,102,83,58,29,11,166,75,243,60,21,9,202,179,236,129,212,62,217,203,6,193,18,176,156,198,86,140,135,222,109,48,195,112,167,218,92,76,71,40,128,221,235,43,81,109,198,51,77,122,183,111,173,195,8,249,40,159,212,136,180,215,171,70,60,108,26,185,11,222,67,47,142,179,158,131,135,153,168,251,199,21,44,7,164,68,212,209,54,75,18,200,117,213,16,175,152,29,146,154,151,236,143,173,86,70,224,138,71,33,33,151,122,205,128,223,166,51,149,125,178,225,234,164,180)), 172) print(173) assert("1ef2a94a2e620a164e07590f006c5a46b722fe7e" == hmac_sha1(string.char(78,109,133,245,198,165,112,63,135,53,124,251,110,183,41,34,153,68,22,253,66,201,9,41,15,99,105,14,252,172,212,39,100,14,128,16,64,47,104,37,33,27,203,120,163,182,52,37,27,224,212,40,134,81,70,29,155,101,246,141,238,41,253,124,222,216,49,49,85,46,51,51,122,39,221,156,104,7,14,52,71,93,31,219), string.char(191,94,78,159,209,12,118,97,214,190,238,108,175,252,192,244,8,104,145,30,236,242,45,49,215,185,251,73,46,101,156,221,136,245,45,240,138,174,187,151,0,122,113,154,195,94,245,186,218,211,203,189,37,251,21,33,225,66,168,152,102,200,245,101,102,217,193,215,194,214,48,131,153,140,75,100,237,240,32,89,113,17,125,177,189,188,212,101,211,212,102,57,251,213,216,14,86,204,198,147,122,97,203,127,100,107,126,107,116,34,220,122,154,130,135,199,9,243,9,194,214)), 173) print(174) assert("ad924bedf84061c998029fb2f168877f0b3939bb" == hmac_sha1(string.char(174,37,249,22,190,230,152,74,215,14,1,180,201,164,238,160,59,157,213,35,36,43,116,160,158,144,131,30,213,232,29,183,205,87,35,85,252,120,126,5,54,113,176), string.char(25,233,197,224,170,150,207,83,58,255,63,236,20,13,179,143,48,248,212,16,220,143,14,123,207,59,28,124,19)), 174) print(175) assert("75a6cfbedde0f1b196209a282b25f5f8b9fef3d1" == hmac_sha1(string.char(131,192,35,70,146,214,224,190,220,240,195,81,129,33,207,253,47,230,111,169,187,136,52,244,217,178,143,140,225,154,105,95,112,201,136,90,221,255,44,31,48,178,90,178,218,122,228,165,90,189,107,45,217,249,89,213,136,139,91,187,202,204,26,250,112), string.char(41,13,202,37,1,104,116,166,245,50,221,59,115,68,187,115,80,93,202,147,10,96,209,213,76,103,143,237,217,21,124,152,82,54,147,207,164,43,89,83,118,67,43,179,79,64,127,252,9,26,125,101,80,192,111,224,104,243,45,67,54,251,238,146,154,212,193,181,138,168,231,171,203,62,93,97,46,55,109,253,214,79,60,62,126,183,235,63,121,46,99,3,223,174,223,2,208,78,7,15,161,56,160,59,205,122,138,77,47,250,107,136,65,199,98,86,131,217,96,226,11,166,185,131,231,76,28,83,140,7,146,87,158,20,102,224,86,5,232,96,34,129,172,236,146,1,139,63,252,1,48,196,242,41,145,97,254,174,88,107,169,70,158,165,246,160,4,16,212,109,236)), 175) print(176) assert("c6f51cc53b0a341dafa4607ee834cffaa8c7c2a2" == hmac_sha1(string.char(85,193,15,80,156,124,171,95,40,75,229,181,147,237,153,83,232,67,210,131,57,69,7,226,226,195,164,46,185,83,120,177,67,77,119,201,9,123,117,111,148,176,12,145,14,80,225,95,71,136,179,94,136,6,78,230,149,135,176,131,19,125,185,48,200,244,111,8,28,170,82,121,242,200,208,145,73,59,234,19,87,61,79,137,245,148,212,94,96,253,227,60,162,170,49,102), string.char(200,235,229,185,225,227,209,209,199,11,112,58,19,202,246,237,94,60,90,176,145,87,191,138,171,88,242,239,21,146,3,92,255,188,99,146,74,134,252,19,201,111,239,76,249,231,71,109,230,240,192,234,253,52,58,173,153,24,131,161,97,222,0,203,177,179,186,160,46,206,73,176,154,39,248,22,66,164,232,120,188,5,73,245,68,8,40,157,155,93,50,207)), 176) print(177) assert("a07ef6f8799ef46062ffea5a43bb3edd30c1fdde" == hmac_sha1(string.char(81,90,37,124,211,22,19,34,50,56,90,45,17,230,233,38,76,24,250), string.char(142,185,46,191,103,207,110,48,71,10,217,115,193,52,131,87,106,39,9,80,216,15,235,169,30,143,3,7,188,78,34,136,18,200,181,140,22,253,141,59,235,25,59,204,147,80,162,108,237,101,167,249,7,168,24,123,215,220,198,38,133,253,72,168,10,139,84,22,195,36,241,128,70,132,28,242,56,40,159,113,184,187,89,38,198,255,176,88,112,125,68,12,57,207,3,251,72,198,135,48,118,244,199,192,205,164,181,243,40,33,195,204,9,78,108,253,114,211,173,121,245,104,13,116,143,160,241,139,210,162,78,62,69,232,40,248,254,177,6,148,177,168,51,253,177,84,152,29,107,91,186,68,118,30,125,62,196,24,14,87,158,83,39,240,192,79,78,61,133,109,106,98,120,232,144,18,49,96,17,202,208,189,152,171,219,19,41,132,179,219,83,220,201,36,191)), 177) print(178) assert("63585793821f635534879a8576194f385f4a551a" == hmac_sha1(string.char(78,213,189,105,102,116,246,215), string.char(162,53,102,158,78,125,120,189,186,214,237,16,219,220,44,24,30,62,32,177,104,217,225,27,92,128,95,202,50,177,239,152,151,161,31,152,93,108,29,125,23,63,55,243,160,169,99,102,15,188,196,129,217,239,132,180,177,251,132,173,62,172,21,139,16,137,231,6,243,185,218,60,60,156,166,153,99,149,144,192,151,249,141,165,222,254,4,111,58,46,106,78,160,215,49,128,252,4,114,236,132,108,114,189,143,45,42,84,134,81,47,140,247,146,247,179,63,14,92,136,120,139)), 178) print(179) assert("95bb1229d26df63839ba4846a41505d48ff98290" == hmac_sha1(string.char(121,190,21,20,39,101,53,249,44,132,19,132,4,114,199,22,32,143,38,33,184,181,66,55,183,240,31,204,225,230,125,186,87,25,90,229,11,55,239,62,101,67,238,1,104,178,191,144,148,105,6,26,127,154,135,247,248,171,41,44,57,83,186,220,42,40,68,153,189,221), string.char(99,150,114,100,37,53,229,202,20,171,246,91,188,188,46,232,70,26,151,35,223,28,97,132,9,242,55,238,98,75,108,91,226,48,236,209,133,92,68,194,241,199,188,86,59,255,230,128,252,193,94,113,134,27,32,50,191,176,159,185,89,209,255,192,9,214,252,63,147,8,92,162,114,72,50,101,136,180,95,39,55,143,137,118,40,14,104,3,149,153,230,135,98,93,72,180,72,86,185,80,107,69,68,20,73)), 179) print(180) assert("9e7c9a258a32e6b3667549cef7a61f307f49b4b9" == hmac_sha1(string.char(105,200,69,23,156,169,151,107,30,139,196,145,128,108,52,7,181,248,255,83,176,169,152,51,158,236,49,191,65,208,155,204,105,179,148,226,142,194,63,253,217,184,69,11,135,185,203,150,146,57,129,80,87,84,231,168,63,186,149,85,128,236,135,217,246,255,121,70,251,68,139,215,199,143,87,13,196,20,50,92,55,116,34,141,117,89,228,94,63,142,250,182,58,91,68,214), string.char(38,52,86,63,109,91,84,11,33,250,194,192,178,94,37,17,65,111,173,17,37,54,163,168,142,91,191,197,161,229,44,163,163,125,81,204,167,185,244,119,75,28,211,87,159)), 180) print(181) assert("7fb01c88e7e519265c18e714efd38bc66f831071" == hmac_sha1(string.char(138,214,212,108,83,152,165,123), string.char(148,223,186,162,237,166,230,68,59,78,220,164,231,42,46,211,239,38,39,150,174,50,58,4,0,135,87,123,123,5,33,252,197,6,53,83,27,178,189,228,166,252,91,141,67,44,68,106,222,17,46,84,214,252,110,181,216,132,14,246,209,57,183,155,238,64,215,121,8,169,157,175,182,191,169,94,116,105,91,49,203,30,155,202,39,140,146,6,115,162,112,130,175,86,143,128,126,249,148,185,39,174,63,83,19,76,164,34,228,97,198,250,65,3,168,158,61,130,167,166,144,185,146,184,160,39,189,11,243,125,255,60,217,46)), 181) print(182) assert("15ab3da2a97592c5f2e22586b4c8a8653411e756" == hmac_sha1(string.char(6,242,91,101,37,118,105,53,170,56,114,144,117,49,53,203,169,216,9,232,9,170,204,129,82,41,210,45,86,176,139,80,152,168,1,154,32,111,89,165,143,205,21,236,105,62,231,106,232,205,7,189,245,52,145,100,78,140,200,183,209,232,196,88,109,175,70,153,150,231,252,7,189,119,97,176,216,201,186,245,24,128,33,57,113,188,184,0,146,248,69,255,77,144,101), string.char(186,246,72,178,189,127,22,42,22,217,81,156,253,142,152,86,42,41,164,77,150,11,208,155,154,185,18,81,156,185,140,224,215,98,1,97,33,194,137,206,144,219,207,210,52,203,198,1,109,182,65,138,122,227,168,207,213,110,206,102,12,181,198,195,133,218,23,187,117,190,56,140,154,239,105,62,96,148,126,187,47,24,139,194,18,211,225,252,195,49,102,138,165,160,90,153,100,140,105,154,242,59,133,226,19,68,125,59,83,140,48,240,226,129,151,79,130,59,96,111,27,73,198)), 182) print(183) assert("7b06792805f4e8062ee9dfbbaffccd787c6f98e1" == hmac_sha1(string.char(83,132,152,16,245,136,91,241,37,158,80,92,65,223,79,3,189,213,89,253,159,93,194,52,218), string.char(212,242,37,98,229,190,238,23,210,197,147,253,82,105,146,168,198,253,2,160,165,188,165,221,179,112,136,72,149,79,138,70,101,95,210,73,157,14,211,92,27,230,177,84,170,183,15,40,0,92,222,252,166,48,1,139,40,16,186,178,231,109,100,125,253,125,123,94,115,94,150,157,186,230,115,163,194,164,30,131,162,90,28,61,44,248,137,8,246,173,31,177,236,39,8,10,192,148,211,36,215,57)), 183) print(184) assert("a28fe22ba0845ae3d57273febbbf1d13e8fde928" == hmac_sha1(string.char(149), string.char(11,139,249,120,214,252,67,75)), 184) print(185) assert("87a9daa85402f6c4b02f1e9fd6edd7e5d178bb88" == hmac_sha1(string.char(114,92,75,169,228,153,182,206,125,139,162,232,77,38,72,129,132,81,11,153,91,92,152,253,10,79,138,142,17,191,161,194,147,213,43,214,39,32,146,46,132,40,77,192,82,54,55,239,50,47), string.char(114,8,110,153,77,155,178,113,203,30,21,41,136,111,176,255,74,214,117,12,189,194,198,37,73,152,196,108,207,188,187,31,227,237,17,1,66,200,73,83,31,61,161,61,31,149,1,152,140,202,163,175,140,136,51,59,121,28,125,192,238,96,192,65,33,177,136,135,173,13,52,101,42,55,189,201,157,244,104,235,148,114,84,154,10,99,153,41,208,213,41,83,193,129,216,46,4,226,81,184,1,249,70,93,183,173,9,29,57,75,209,67,227,49,253,132,129,13,157,55,66,191,136,67,95,108,155,116,17,125,151,217,242,204,110,143,189,201,118)), 185) print(186) assert("6300b2f6236b83de0c84ff1816d246231a5d3b79" == hmac_sha1(string.char(215,10,19,7,73,236,63,23,34,49,11,240,186,195,32,171,67,85,7,95,190,237,77,216,115,36,230,204,139,95,229,37,201,115,81,96,217,205,49,22,169,32,90,2,90,93,137,247,83,229,39,88,235,175,191,246,80,40,228,114,188,115,14,252,35,40,130,240,20,25,202,80,184,27,227,175,149,64,110,223,25,64,57,189,153,176,143,30,76,2,68), string.char(13,245,250,139,223,128,3,6,189,59,12,139,38,153,215,76,250,198,91,117,242,118,34,26,133,244,143,5,56,182,213,167,144,71,250,40,202,81,22,14,72,201,143,10,177,4,166,75,160,156,100,5,147,138,104,98,9,125,81,202,44,120,241,221,181,0,169,155,96,1,4,205,145,105,150,122,135,231,42,165,179,83,39,122,159,193,139,28,4,201,178,41,168,11,177,61,39,14,196,60,29,131,201,91,46,35,128,63,167,48,132,134,105,224,246,244,81,144,209,123,222,190,167,138,76,194,42,152,23,125,52,156,18,217,101,207,239,63,235,3,3,49,147,172,158,97,179,86,233,85,155,245,206,205,165,195,180,223,20,62,197,143,149,126,152)), 186) print(187) assert("35fe4e0cf2417a783d5bdbc17bbc0ab77d2699e7" == hmac_sha1(string.char(15,157,117,128,204,42,12,183,229,129,132,234,228,150,235,100,100,77,160,26,154,230,246,138,150,120,252,20,188,138,171,189,208,62,201,58,158,152,167,165,98,249,52,143,7,26,109,227,144,81,213,157,31,155,26,12,206,103,193,29,142,126,205,123,83,111,179,166,31,32,183,183,100,54,51,205,180,186,160,220,176,233,42,94,62,241,88,74,31,24,22,115,179,124,136,206,78,83), string.char(248,157,191,249,76,86,187,243,10,116,1,227,141,21,104,154,167,72,30,245,6,57,40,170,253,15,4,192,237,237,142,141,196,243,231,245,121,219,150,237,212,118,78,25,201,249,174,21,76,98,187,155,82,243,218,142,239,101,235,240,134,70,212,205,136,165,170,71,121,137,44,8,110,14,167,162,233,92,51,191,178,227,85,134,168,222,121,62,35,127,57,92,80,142,91,112,9,248,129,127,236,2,190,165,125,236,188,117,158,241,181,134,54,133,16,64,100,156,59,83,249,105,235,187,160,186,158,173,52,25,129,20,156,209,102,170,209,10,3,233,12,228,205,138,16,140,108,74,75,65,238,155,251,129,73,236,118,93,202,217,46,180,165,27,84,120,61,186,173,148,131,161,187,30,175,21,249,12,245,145,89,93,61,151,254,29,247,51,198,238,111,52,30,254)), 187) print(188) assert("83c2a380e55ecbc6190b9817bb291a00c36de5e8" == hmac_sha1(string.char(61,128,92,30,94,101,187,67,197,177,98,100,191,221,190,196,86,62,8,238,225,3,93,127,28,126,217,206,56,192,90,9,74,34,43,228,190,162,57,99,170,238,230,196,99,213,31,6,184,11,79,82,100,68,255,40,63), string.char(78,173,248,128,215,226,77,57,233,135,163,11,241,74,59,78,169,219,125,37,182,56,139,89,32,52,80,165,233,52,179,54,216,45,205,209,173,33,12,148,231,66,126,155,191,91,155,174,23,15,14,28,77,186,139,113,48,141,153,177,252,194,23,61,181,189,66,151,45,11,119,74,236,107,206,244,41,117,161,182,233,138,57,196,90,118,28,99,186,150,54,180,105,230,2,41,246,19,80,211,173,102,72,78,82,253,5,183,248,101,173,204,2,145,105,4,160,44,110,211,63,45,46,78)), 188) print(189) assert("bd59d0dcf812107a613a2d892322f532c16ec210" == hmac_sha1(string.char(161,183,101,160,169,208,82,58,88,198,190,85,53,240,56,6,20,136,86,18,216,63,190), string.char(39,227,142,194,37,34,121,168,239,99,70,39,179,128,26,113,47,95,70,129,255,219,63,233,44,33,19,127,22,24,208,50,19,141,185,19,54,82,147,138,44,69)), 189) print(190) assert("6aa92cb64b2e390fbf04dc7edfe3af068109ffba" == hmac_sha1(string.char(202,230,55,100,136,80,156,240,98,73,97,72,191,195,185,105,150,97,148,33,167,140,212,100,247,154,5,152,117,24,128,221,150,49,143,86,12,211,161,75,177,75,145,46,112,143,37,181,84,50,230,81), string.char(131,200,0,161,117,217,5,10,64,79,178,147,64,248,35,147,135,103,157,181,194,123,76,13,150,118,204,63,32,203,155,222,227,148,31,28,218,83,245,17,208,200,104,78,85,31,114,194,67,159,184,167,42,199,241,6,182,195,3,79,22,236,124)), 190) print(191) assert("a42cf08fa6d8ad6ae00251aeed0357dca80645c7" == hmac_sha1(string.char(170,52,245,172,122,225,164,248,23,35,54,243,118,35,165,16,6), string.char(245,115,59,162,179,146,39,213,64,240,80,108,190,127,116,16,154,211,33,171,150,46,77,213,99,88,160,101,236,202,70,26,61,83,79,110,127,74,97,34,18,243,140,34,244,249,225,88,132,102,7,99,220,140,46,111,96,48,93,44,47,186,86,246,244,127,236,150,35,69,111,238,54,24,71,157,254,21,2,194,69,47,190,87,72,235,60,243,40,153,111,55,220,25,91,17,156,195,57,207,107,145,6,82,104,232,209)), 191) print(192) assert("8dd62dcf68ef2d193005921161341839b8cac487" == hmac_sha1(string.char(136,5,195,241,18,208,11,46,252,182,96,183,164,87,248,13), string.char(78,49,162,9,47,79,26,139,66,194,248,90,171,207,167,43,201,223,102,192,49,145,83,42,1,52,250,116,216,133,224,224,17,143,41,153,65,214,231,109,160,5,31,85,17,186,199,226,214,92,21,194,148,98,68,209,50,74,26,150,97,59,223,8,131,173,145,6,31,126,248,86,226,2,94,15,3,202,239,99,177,237,61,99,14,253,26,246,0,151,2,7,159,40,249,166)), 192) print(193) assert("eff66e7a69ae7d2a90b2d80c64ce7c41fe560a19" == hmac_sha1(string.char(123,54,89,205,103,116,21,97,164,41,23,224,151,195,22,196,90,52,253,92), string.char(141,12,168,171,49,30,165,57,107,214,157,224,36,163,182,184,103,186,133,22,2,215,52,220,95,205,231,180,221,139,67,184,21,46,172,95,183,220,31,27,227,122,183,196,114,206,132,162,51,164,84,212,172,63,218,236,127,215,218,77,119,105,14,19,164,53,149,11,13,1,29,246,69,200,208,239,154,60,245,31,172,82,158,165,197,250,151,83,12,156,215,201,66,45,238,228,77,125,157,35,235,162,78,220,132,14,137,168,238,127,10,24,41,132,181,43,95,73,33,32,129,149,145,55,80,156,171,73,90,183,166,182,163,154,31,104,14,56,59,102,72,210,121,191,251,239,1,5,76,116,158,89,40,69,220,107,23,168,106,93,92,95,21,91,118,118,71,29,64,142,84,15,153,193,47,214,30,117,236,217)), 193) print(194) assert("0f1adc518afcca2ed7ad0adaaedd544835ddb76e" == hmac_sha1(string.char(142,36,199,16,52,54,62,146,153,25,162,85,251,247), string.char(110,70,53,237,120,53,50,196,24,82,199,210,156,178,110,124,7,24,229,89,39,1,10,96,74,211,36,79,166,4,33,238,64,220,239,129,48,232,244,172,142,79,154,73,36,107,182,208,191,25,201,19,233,23,60,236,180,76,116,53,232,181,101,62,160,252,213,171,166,113,193,73,75,13,209,63,76,92,95,176,119,0,125,174,42,138,77,23,212,81,180,10,193,118,244,242,163,246,206,150,162,92,20,208,51,71,254,197,11,222,203,153,208,251,243,193,124,141,215,171,55,244,230,78,158,32,223,138,156,43,98,39,191,108,111,6,117,130,195,100,221,233,17,98,180,49,132,139,171,20,180,7,206,35,54,17,48,253,130,185,249,2,52,17,207,73,24,33)), 194) print(195) assert("5e87f8d9a653312fd7b070a33a5d9e67b28b9a84" == hmac_sha1(string.char(255,237,33,255,4,170,95,90,88,77,217,10,94,118,134,20,33,208,17,136,77,18,169,205,112,36,203,231,67,47,186,91,7,17,29), string.char(97,211,98,53,135,238,42,101,144,12,75,185,119,223,114,81,201,94,21,118,16,152,74,215,56,61,131,151,83,96,83,59,49,199,255,207,153,90,231,39,181,4,59,9,2,150,207,124,209,120,37,236,195,66,189,209,137,9,165,78,172,142,209,243,237,145,204,210,222,153,52,127,39,174,133,17,186,219,87,142,209,212,223,60,249,57,244,251,44,254,73,238,52,99,94,237,189,185,237,1,101,166,220,170,103,209)), 195) print(196) assert("837c7cc92e0d2c725b1d1d2f02ef787be37896fa" == hmac_sha1(string.char(150,241,64,89,79,72,88,157,113,139,190,43,211,214,202,52,124,91,111,198,47,161,120,17,120,157,112,248,245,154,254,25,233,96,216), string.char(214,251,73,193,181,158,253,28,23,48,186,168,162,26,124,103,22,195,165,63,189,196,162,229,69,1,208,85,249,24,73,101,243,149,68,236,124,147,108,67,37,75,202,143,57,124,71,176,27,216,208,183,164,173,219,170,79,10,198,1,232,35,9,19,70,131,211,60,37,94,146,98,92,31,150,95,89,189,46,38,156,118,171,137,86,87,32,173,77,14,135,233,233,114,162,136,57,113,73,115,134,87,184)), 196) print(197) assert("64534553f76e55b890101380ad9149d3cacb5b76" == hmac_sha1(string.char(231,24,192,54,17,14,98,122,119,170,71,54,206,207,223,109,164,181,124,186,122,111,122,34,157,24,237,130,207,206,117,76,183,162,174,124,60,60,77,114,139,170,194,143,232,74,160,141,161,171,51,178,162,159,234,208,55), string.char(141,184,241,185,112,45,53,192,72,152,139,145,146,149,145,151,12,140,111,79,158,172,212,175,75,225,127,4,252,104,5,94,105,24,141,183,79,208,240,227,63,126,213,4,13,109,216,244,237,24,196,52,212,245,147,109,18,63,69,107,122,245,101,67,212,232,92,25,135,67,127,247,187,143,224,198,105,38,147,12,238,6,57,53,105,246,0,127,222,69,163,44,11,245,82,220,32,108,33,70,93,177,89,75,192,214,104,236,84,28,221,209,27,12,80,239,111,249,57,39,236,193,17,69,66,180,63,193,242,248,72,22,225,56,198,235,111,102,33,171,159,124,220,143,108,10,71,186,219,213,28,209,145,188,36,70,59,9,235,154,57,12,211,146,6,87,83)), 197) print(198) assert("b7efbbc21ac1a746e22368e814ef5921056331ac" == hmac_sha1(string.char(137,153,151,252,88,36,165,92,194,50,19,117), string.char(155,113,35,47,22,52,144,77,130,20,178,133,75,207,168,146,132,209,160,7,123,190,117,196,147,212,142,25,182,222,56,249,192,228,6,224,250,221,89,7,176,27,37,49,215,192,74,132,127,101,32,23,34,131,23,74,37,226,208,205,162,242,102)), 198) print(199) assert("950ad3222f4917f868d09feab237a909fb6d50b7" == hmac_sha1(string.char(78,46,85,132,231,4,243,255,22,45,240,155,151,119,94,213,50,111,10,83,40,204,49,52,17,69,132,44,213,83,54,251,211,159,123,55,17,58,162,170,210,3,35,237,165,181,217,27,7,249,158,22,158,207,77,121,37,63,37,39,204,68,99,158,78,175,73,183,47,99,134,65,74,234,154,33,14,117,126,98,167,242,106,112,145,82), string.char(144,133,184,16,9,8,227,98,190,60,141,255,87,69,63,214,12,67,14,206,32,120,59,232,176,82,32,194,115,52,148,143,126,86,82,101,167,249,17,169,9,105,228)), 199) ---]]----------------------------------------------------------------------------------------- --END
mit
majetideepak/arrow
c_glib/example/lua/read-batch.lua
10
1572
-- Licensed to the Apache Software Foundation (ASF) under one -- or more contributor license agreements. See the NOTICE file -- distributed with this work for additional information -- regarding copyright ownership. The ASF licenses this file -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -- KIND, either express or implied. See the License for the -- specific language governing permissions and limitations -- under the License. local lgi = require 'lgi' local Arrow = lgi.Arrow local input_path = arg[1] or "/tmp/batch.arrow"; local input = Arrow.MemoryMappedInputStream.new(input_path) local reader = Arrow.RecordBatchFileReader.new(input) for i = 0, reader:get_n_record_batches() - 1 do local record_batch = reader:read_record_batch(i) print(string.rep("=", 40)) print("record-batch["..i.."]:") for j = 0, record_batch:get_n_columns() - 1 do local column_name = record_batch:get_column_name(j) local column_data = record_batch:get_column_data(j) io.write(" "..column_name..": [") for k = 0, record_batch:get_n_rows() - 1 do if k > 0 then io.write(", ") end io.write(column_data:get_value(k)) end print("]") end end input:close()
apache-2.0
artynet/luci
applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/sensors.lua
5
2954
-- Copyright 2015 Jo-Philipp Wich <jow@openwrt.org> -- Licensed to the public under the Apache License 2.0. local m, s, o local sensor_types = { ["12v"] = "voltage", ["2.0v"] = "voltage", ["2.5v"] = "voltage", ["3.3v"] = "voltage", ["5.0v"] = "voltage", ["5v"] = "voltage", ["ain1"] = "voltage", ["ain2"] = "voltage", ["cpu_temp"] = "temperature", ["fan1"] = "fanspeed", ["fan2"] = "fanspeed", ["fan3"] = "fanspeed", ["fan4"] = "fanspeed", ["fan5"] = "fanspeed", ["fan6"] = "fanspeed", ["fan7"] = "fanspeed", ["in0"] = "voltage", ["in10"] = "voltage", ["in2"] = "voltage", ["in3"] = "voltage", ["in4"] = "voltage", ["in5"] = "voltage", ["in6"] = "voltage", ["in7"] = "voltage", ["in8"] = "voltage", ["in9"] = "voltage", ["power1"] = "power", ["remote_temp"] = "temperature", ["temp1"] = "temperature", ["temp2"] = "temperature", ["temp3"] = "temperature", ["temp4"] = "temperature", ["temp5"] = "temperature", ["temp6"] = "temperature", ["temp7"] = "temperature", ["temp"] = "temperature", ["vccp1"] = "voltage", ["vccp2"] = "voltage", ["vdd"] = "voltage", ["vid1"] = "voltage", ["vid2"] = "voltage", ["vid3"] = "voltage", ["vid4"] = "voltage", ["vid5"] = "voltage", ["vid"] = "voltage", ["vin1"] = "voltage", ["vin2"] = "voltage", ["vin3"] = "voltage", ["vin4"] = "voltage", ["volt12"] = "voltage", ["volt5"] = "voltage", ["voltbatt"] = "voltage", ["vrm"] = "voltage" } m = Map("luci_statistics", translate("Sensors Plugin Configuration"), translate("The sensors plugin uses the Linux Sensors framework to gather environmental statistics.")) s = m:section( NamedSection, "collectd_sensors", "luci_statistics" ) o = s:option( Flag, "enable", translate("Enable this plugin") ) o.default = 0 o = s:option(Flag, "__all", translate("Monitor all sensors")) o:depends("enable", 1) o.default = 1 o.write = function() end o.cfgvalue = function(self, sid) local v = self.map:get(sid, "Sensor") if v == nil or (type(v) == "table" and #v == 0) or (type(v) == "string" and #v == 0) then return "1" end end o = s:option(MultiValue, "Sensor", translate("Sensor list"), translate("Hold Ctrl to select multiple items or to deselect entries.")) o:depends({enable = 1, __all = "" }) o.widget = "select" o.rmempty = true o.size = 0 local sensorcli = io.popen("/usr/sbin/sensors -u -A") if sensorcli then local bus, sensor while true do local ln = sensorcli:read("*ln") if not ln then break elseif ln:match("^[%w-]+$") then bus = ln elseif ln:match("^[%w-]+:$") then sensor = ln:sub(0, -2):lower() if bus and sensor_types[sensor] then o:value("%s/%s-%s" %{ bus, sensor_types[sensor], sensor }) o.size = o.size + 1 end elseif ln == "" then bus = nil sensor = nil end end sensorcli:close() end o = s:option( Flag, "IgnoreSelected", translate("Monitor all except specified") ) o.default = 0 o.rmempty = true o:depends({ enable = 1, __all = "" }) return m
apache-2.0
akh00/kong
kong/plugins/acl/api.lua
6
1524
local crud = require "kong.api.crud_helpers" return { ["/consumers/:username_or_id/acls/"] = { before = function(self, dao_factory, helpers) crud.find_consumer_by_username_or_id(self, dao_factory, helpers) self.params.consumer_id = self.consumer.id end, GET = function(self, dao_factory) crud.paginated_set(self, dao_factory.acls) end, PUT = function(self, dao_factory) crud.put(self.params, dao_factory.acls) end, POST = function(self, dao_factory) crud.post(self.params, dao_factory.acls) end }, ["/consumers/:username_or_id/acls/:group_or_id"] = { before = function(self, dao_factory, helpers) crud.find_consumer_by_username_or_id(self, dao_factory, helpers) self.params.consumer_id = self.consumer.id local acls, err = crud.find_by_id_or_field( dao_factory.acls, { consumer_id = self.params.consumer_id }, self.params.group_or_id, "group" ) if err then return helpers.yield_error(err) elseif #acls == 0 then return helpers.responses.send_HTTP_NOT_FOUND() end self.params.group_or_id = nil self.acl = acls[1] end, GET = function(self, dao_factory, helpers) return helpers.responses.send_HTTP_OK(self.acl) end, PATCH = function(self, dao_factory) crud.patch(self.params, dao_factory.acls, self.acl) end, DELETE = function(self, dao_factory) crud.delete(self.acl, dao_factory.acls) end } }
apache-2.0
Daniex0r/project-roleplay-rp
resources/system-real/c_reload.lua
1
2134
local noReloadGuns = { [25]=true, [33]=true, [34]=true, [35]=true, [36]=true, [37]=true } function isGun(id) return getSlotFromWeapon(id) >= 2 and getSlotFromWeapon(id) <= 7 end savedAmmo = { } local handled = true function weaponAmmo(prevSlot, currSlot) cleanupUI() triggerEvent("checkReload", source) end addEventHandler("onClientPlayerWeaponSwitch", getLocalPlayer(), weaponAmmo) function disableAutoReload(weapon, ammo, ammoInClip) if (ammoInClip==1) and not getElementData(getLocalPlayer(), "deagle:reload") and not getElementData(getLocalPlayer(), "scoreboard:reload") then triggerServerEvent("addFakeBullet", getLocalPlayer(), weapon, ammo) triggerEvent("i:s:w:r", getLocalPlayer()) triggerEvent("checkReload", source) elseif (ammoInClip==0) then -- panic? --outputChatBox("We never ever should get this, comprende?") else cleanupUI() end end addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), disableAutoReload) function drawText() local scrWidth, scrHeight = guiGetScreenSize() dxDrawText("Wciśnij 'R' by załadować broń!", 0, 0, scrWidth, scrHeight, tocolor(255, 255, 255, 170), 1.02, "pricedown", "center", "bottom") end function checkReloadStatus () local weaponID = getPedWeapon(getLocalPlayer()) if getPedAmmoInClip (getLocalPlayer()) == 1 and isGun(weaponID) then -- getElementData(source, "r:cf:"..tostring(weaponID)) or if not handled then addEventHandler("onClientRender", getRootElement(), drawText) handled = true end --triggerServerEvent("addFakeBullet", getLocalPlayer(), weaponID, getPedTotalAmmo(getLocalPlayer())) --toggleControl ( "fire", false ) else cleanupUI(false) end end addEvent("checkReload", true) addEventHandler("checkReload", getRootElement(), checkReloadStatus) setTimer(checkReloadStatus, 500, 0) function cleanupUI(bplaySound) if (bplaySound) then playSound("reload.wav") setTimer(playSound, 400, 1, "reload.wav") end removeEventHandler("onClientRender", getRootElement(), drawText) handled = false end addEvent("cleanupUI", true) addEventHandler("cleanupUI", getRootElement(), cleanupUI) fileDelete("c_reload.lua")
gpl-2.0
gilala/redis
deps/lua/test/sort.lua
889
1494
-- two implementations of a sort function -- this is an example only. Lua has now a built-in function "sort" -- extracted from Programming Pearls, page 110 function qsort(x,l,u,f) if l<u then local m=math.random(u-(l-1))+l-1 -- choose a random pivot in range l..u x[l],x[m]=x[m],x[l] -- swap pivot to first position local t=x[l] -- pivot value m=l local i=l+1 while i<=u do -- invariant: x[l+1..m] < t <= x[m+1..i-1] if f(x[i],t) then m=m+1 x[m],x[i]=x[i],x[m] -- swap x[i] and x[m] end i=i+1 end x[l],x[m]=x[m],x[l] -- swap pivot to a valid place -- x[l+1..m-1] < x[m] <= x[m+1..u] qsort(x,l,m-1,f) qsort(x,m+1,u,f) end end function selectionsort(x,n,f) local i=1 while i<=n do local m,j=i,i+1 while j<=n do if f(x[j],x[m]) then m=j end j=j+1 end x[i],x[m]=x[m],x[i] -- swap x[i] and x[m] i=i+1 end end function show(m,x) io.write(m,"\n\t") local i=1 while x[i] do io.write(x[i]) i=i+1 if x[i] then io.write(",") end end io.write("\n") end function testsorts(x) local n=1 while x[n] do n=n+1 end; n=n-1 -- count elements show("original",x) qsort(x,1,n,function (x,y) return x<y end) show("after quicksort",x) selectionsort(x,n,function (x,y) return x>y end) show("after reverse selection sort",x) qsort(x,1,n,function (x,y) return x<y end) show("after quicksort again",x) end -- array to be sorted x={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"} testsorts(x)
bsd-3-clause
artynet/luci
applications/luci-app-radicale/luasrc/controller/radicale.lua
28
8642
-- Copyright 2014-2016 Christian Schoenebeck <christian dot schoenebeck at gmail dot com> -- Licensed under the Apache License, Version 2.0 module("luci.controller.radicale", package.seeall) local NX = require("nixio") local NXFS = require("nixio.fs") local DISP = require("luci.dispatcher") local HTTP = require("luci.http") local I18N = require("luci.i18n") -- not globally avalible here local IPKG = require("luci.model.ipkg") local UTIL = require("luci.util") local SYS = require("luci.sys") local srv_name = "radicale" local srv_ver_min = "1.1" -- minimum version of service required local srv_ver_cmd = [[/usr/bin/radicale --version]] local app_name = "luci-app-radicale" local app_title = I18N.translate("Radicale CalDAV/CardDAV Server") local app_version = "1.1.0-1" function index() entry( {"admin", "services", "radicale"}, alias("admin", "services", "radicale", "edit"), _("CalDAV/CardDAV"), 58) entry( {"admin", "services", "radicale", "edit"}, cbi("radicale") ).leaf = true entry( {"admin", "services", "radicale", "logview"}, call("_logread") ).leaf = true entry( {"admin", "services", "radicale", "startstop"}, post("_startstop") ).leaf = true entry( {"admin", "services", "radicale", "status"}, call("_status") ).leaf = true end -- Application / Service specific information functions function app_description() return I18N.translate("The Radicale Project is a complete CalDAV (calendar) and CardDAV (contact) server solution.") .. [[<br />]] .. I18N.translate("Calendars and address books are available for both local and remote access, possibly limited through authentication policies.") .. [[<br />]] .. I18N.translate("They can be viewed and edited by calendar and contact clients on mobile phones or computers.") end function app_title_main() return [[<a href="javascript:alert(']] .. I18N.translate("Version Information") .. [[\n\n]] .. app_name .. [[\n\t]] .. I18N.translate("Version") .. [[:\t]] .. app_version .. [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("required") .. [[:]] .. [[\n\t]] .. I18N.translate("Version") .. [[:\t]] .. srv_ver_min .. [[ ]] .. I18N.translate("or higher") .. [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("installed") .. [[:]] .. [[\n\t]] .. I18N.translate("Version") .. [[:\t]] .. (service_version() or I18N.translate("NOT installed")) .. [[\n\n]] .. [[')">]] .. I18N.translate(app_title) .. [[</a>]] end function app_title_back() return [[<a href="]] .. DISP.build_url("admin", "services", "radicale") .. [[">]] .. I18N.translate(app_title) .. [[</a>]] end function app_err_value() if not service_version() then return [[<h3><strong><br /><font color="red">&nbsp;&nbsp;&nbsp;&nbsp;]] .. I18N.translate("Software package '%s' is not installed." % srv_name) .. [[</font><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]] .. I18N.translate("required") .. [[: ]] .. srv_name .. [[ ]] .. srv_ver_min .. [[<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;]] .. [[<a href="]] .. DISP.build_url("admin", "system", "packages") ..[[">]] .. I18N.translate("Please install current version !") .. [[</a><br />&nbsp;</strong></h3>]] else return [[<h3><strong><br /><font color="red">&nbsp;&nbsp;&nbsp;&nbsp;]] .. I18N.translate("Software package '%s' is outdated." % srv_name) .. [[</font><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]] .. I18N.translate("installed") .. [[: ]] .. srv_name .. [[ ]] .. service_version() .. [[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]] .. I18N.translate("required") .. [[: ]] .. srv_name .. [[ ]] .. srv_ver_min .. [[<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;]] .. [[<a href="]] .. DISP.build_url("admin", "system", "packages") ..[[">]] .. I18N.translate("Please update to current version !") .. [[</a><br />&nbsp;</strong></h3>]] end end function service_version() local ver = nil IPKG.list_installed(srv_name, function(n, v, d) if v and (#v > 0) then ver = v end end ) if not ver or (#ver == 0) then ver = UTIL.exec(srv_ver_cmd) if #ver == 0 then ver = nil end end return ver end function service_ok() return IPKG.compare_versions((service_version() or "0"), ">=", srv_ver_min) end -- called by XHR.get from detail_logview.htm function _logread() -- read application settings local uci = UCI.cursor() local logfile = uci:get("radicale", "radicale", "logfile") or "/var/log/radicale" uci:unload("radicale") local ldata=NXFS.readfile(logfile) if not ldata or #ldata == 0 then ldata="_nodata_" end HTTP.write(ldata) end -- called by XHR.get from detail_startstop.htm function _startstop() local pid = get_pid() if pid > 0 then SYS.call("/etc/init.d/radicale stop") NX.nanosleep(1) -- sleep a second if NX.kill(pid, 0) then -- still running NX.kill(pid, 9) -- send SIGKILL end pid = 0 else SYS.call("/etc/init.d/radicale start") NX.nanosleep(1) -- sleep a second pid = get_pid() if pid > 0 and not NX.kill(pid, 0) then pid = 0 -- process did not start end end HTTP.write(tostring(pid)) -- HTTP needs string not number end -- called by XHR.poll from detail_startstop.htm function _status() local pid = get_pid() HTTP.write(tostring(pid)) -- HTTP needs string not number end --return pid of running process function get_pid() return tonumber(SYS.exec([[ps | grep "[p]ython.*[r]adicale" 2>/dev/null | awk '{print $1}']])) or 0 end -- replacement of build-in parse of "Value" -- modified AbstractValue.parse(self, section, novld) from cbi.lua -- validate is called if rmempty/optional true or false -- before write check if forcewrite, value eq default, and more function value_parse(self, section, novld) local fvalue = self:formvalue(section) local fexist = ( fvalue and (#fvalue > 0) ) -- not "nil" and "not empty" local cvalue = self:cfgvalue(section) local rm_opt = ( self.rmempty or self.optional ) local eq_cfg -- flag: equal cfgvalue -- If favlue and cvalue are both tables and have the same content -- make them identical if type(fvalue) == "table" and type(cvalue) == "table" then eq_cfg = (#fvalue == #cvalue) if eq_cfg then for i=1, #fvalue do if cvalue[i] ~= fvalue[i] then eq_cfg = false end end end if eq_cfg then fvalue = cvalue end end -- removed parameter "section" from function call because used/accepted nowhere -- also removed call to function "transfer" local vvalue, errtxt = self:validate(fvalue) -- error handling; validate return "nil" if not vvalue then if novld then -- and "novld" set return -- then exit without raising an error end if fexist then -- and there is a formvalue self:add_error(section, "invalid", errtxt) return -- so data are invalid elseif not rm_opt then -- and empty formvalue but NOT (rmempty or optional) set self:add_error(section, "missing", errtxt) return -- so data is missing elseif errtxt then self:add_error(section, "invalid", errtxt) return end -- error ("\n option: " .. self.option .. -- "\n fvalue: " .. tostring(fvalue) .. -- "\n fexist: " .. tostring(fexist) .. -- "\n cvalue: " .. tostring(cvalue) .. -- "\n vvalue: " .. tostring(vvalue) .. -- "\n vexist: " .. tostring(vexist) .. -- "\n rm_opt: " .. tostring(rm_opt) .. -- "\n eq_cfg: " .. tostring(eq_cfg) .. -- "\n eq_def: " .. tostring(eq_def) .. -- "\n novld : " .. tostring(novld) .. -- "\n errtxt: " .. tostring(errtxt) ) end -- lets continue with value returned from validate eq_cfg = ( vvalue == cvalue ) -- update equal_config flag local vexist = ( vvalue and (#vvalue > 0) ) and true or false -- not "nil" and "not empty" local eq_def = ( vvalue == self.default ) -- equal_default flag -- (rmempty or optional) and (no data or equal_default) if rm_opt and (not vexist or eq_def) then if self:remove(section) then -- remove data from UCI self.section.changed = true -- and push events end return end -- not forcewrite and no changes, so nothing to write if not self.forcewrite and eq_cfg then return end -- we should have a valid value here assert (vvalue, "\n option: " .. self.option .. "\n fvalue: " .. tostring(fvalue) .. "\n fexist: " .. tostring(fexist) .. "\n cvalue: " .. tostring(cvalue) .. "\n vvalue: " .. tostring(vvalue) .. "\n vexist: " .. tostring(vexist) .. "\n rm_opt: " .. tostring(rm_opt) .. "\n eq_cfg: " .. tostring(eq_cfg) .. "\n eq_def: " .. tostring(eq_def) .. "\n errtxt: " .. tostring(errtxt) ) -- write data to UCI; raise event only on changes if self:write(section, vvalue) and not eq_cfg then self.section.changed = true end end
apache-2.0
marshmellow42/proxmark3
client/scripts/tnp3dump.lua
6
7183
local cmds = require('commands') local getopt = require('getopt') local bin = require('bin') local lib14a = require('read14a') local utils = require('utils') local md5 = require('md5') local dumplib = require('html_dumplib') local toys = require('default_toys') example =[[ script run tnp3dump script run tnp3dump -n script run tnp3dump -p script run tnp3dump -k aabbccddeeff script run tnp3dump -k aabbccddeeff -n script run tnp3dump -o myfile script run tnp3dump -n -o myfile script run tnp3dump -p -o myfile script run tnp3dump -k aabbccddeeff -n -o myfile ]] author = "Iceman" usage = "script run tnp3dump -k <key> -n -p -o <filename>" desc =[[ This script will try to dump the contents of a Mifare TNP3xxx card. It will need a valid KeyA in order to find the other keys and decode the card. Arguments: -h : this help -k <key> : Sector 0 Key A. -n : Use the nested cmd to find all keys -p : Use the precalc to find all keys -o : filename for the saved dumps ]] local RANDOM = '20436F707972696768742028432920323031302041637469766973696F6E2E20416C6C205269676874732052657365727665642E20' local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds local DEBUG = false -- the debug flag local numBlocks = 64 local numSectors = 16 --- -- A debug printout-function function dbg(args) if not DEBUG then return end if type(args) == "table" then local i = 1 while result[i] do dbg(result[i]) i = i+1 end else print("###", args) end end --- -- This is only meant to be used when errors occur function oops(err) print("ERROR: ",err) end --- -- Usage help function help() print(desc) print("Example usage") print(example) end -- -- Exit message function ExitMsg(msg) print( string.rep('--',20) ) print( string.rep('--',20) ) print(msg) print() end local function readdumpkeys(infile) t = infile:read("*all") len = string.len(t) local len,hex = bin.unpack(("H%d"):format(len),t) return hex end local function waitCmd() local response = core.WaitForResponseTimeout(cmds.CMD_ACK,TIMEOUT) if response then local count,cmd,arg0 = bin.unpack('LL',response) if(arg0==1) then local count,arg1,arg2,data = bin.unpack('LLH511',response,count) return data:sub(1,32) else return nil, "Couldn't read block.." end end return nil, "No response from device" end local function main(args) print( string.rep('--',20) ) print( string.rep('--',20) ) local keyA local cmd local err local useNested = false local usePreCalc = false local cmdReadBlockString = 'hf mf rdbl %d A %s' local input = "dumpkeys.bin" local outputTemplate = os.date("toydump_%Y-%m-%d_%H%M%S"); -- Arguments for the script for o, a in getopt.getopt(args, 'hk:npo:') do if o == "h" then return help() end if o == "k" then keyA = a end if o == "n" then useNested = true end if o == "p" then usePreCalc = true end if o == "o" then outputTemplate = a end end -- validate input args. keyA = keyA or '4b0b20107ccb' if #(keyA) ~= 12 then return oops( string.format('Wrong length of write key (was %d) expected 12', #keyA)) end -- Turn off Debug local cmdSetDbgOff = "hf mf dbg 0" core.console( cmdSetDbgOff) result, err = lib14a.read14443a(false, true) if not result then return oops(err) end core.clearCommandBuffer() -- Show tag info print((' Found tag %s'):format(result.name)) dbg(('Using keyA : %s'):format(keyA)) --Trying to find the other keys if useNested then core.console( ('hf mf nested 1 0 A %s d'):format(keyA) ) end core.clearCommandBuffer() local akeys = '' if usePreCalc then local pre = require('precalc') akeys = pre.GetAll(result.uid) else print('Loading dumpkeys.bin') local hex, err = utils.ReadDumpFile(input) if not hex then return oops(err) end akeys = hex:sub(0,12*16) end -- Read block 0 cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = 0,arg2 = 0,arg3 = 0, data = keyA} err = core.SendCommand(cmd:getBytes()) if err then return oops(err) end local block0, err = waitCmd() if err then return oops(err) end -- Read block 1 cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = 1,arg2 = 0,arg3 = 0, data = keyA} err = core.SendCommand(cmd:getBytes()) if err then return oops(err) end local block1, err = waitCmd() if err then return oops(err) end local tmpHash = block0..block1..'%02x'..RANDOM local key local pos = 0 local blockNo local blocks = {} print('Reading card data') core.clearCommandBuffer() -- main loop io.write('Reading blocks > ') for blockNo = 0, numBlocks-1, 1 do if core.ukbhit() then print("aborted by user") break end pos = (math.floor( blockNo / 4 ) * 12)+1 key = akeys:sub(pos, pos + 11 ) cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = blockNo ,arg2 = 0,arg3 = 0, data = key} local err = core.SendCommand(cmd:getBytes()) if err then return oops(err) end local blockdata, err = waitCmd() if err then return oops(err) end if blockNo%4 ~= 3 then if blockNo < 8 then -- Block 0-7 not encrypted blocks[blockNo+1] = ('%02d :: %s'):format(blockNo,blockdata) else -- blocks with zero not encrypted. if string.find(blockdata, '^0+$') then blocks[blockNo+1] = ('%02d :: %s'):format(blockNo,blockdata) else local baseStr = utils.ConvertHexToAscii(tmpHash:format(blockNo)) local key = md5.sumhexa(baseStr) local aestest = core.aes128_decrypt(key, blockdata) local hex = utils.ConvertAsciiToBytes(aestest) hex = utils.ConvertBytesToHex(hex) blocks[blockNo+1] = ('%02d :: %s'):format(blockNo,hex) io.write(blockNo..',') end end else -- Sectorblocks, not encrypted blocks[blockNo+1] = ('%02d :: %s%s'):format(blockNo,key,blockdata:sub(13,32)) end end io.write('\n') core.clearCommandBuffer() -- Print results local bindata = {} local emldata = '' for _,s in pairs(blocks) do local slice = s:sub(8,#s) local str = utils.ConvertBytesToAscii( utils.ConvertHexToBytes(slice) ) emldata = emldata..slice..'\n' for c in (str):gmatch('.') do bindata[#bindata+1] = c end end print( string.rep('--',20) ) local uid = block0:sub(1,8) local toytype = block1:sub(1,4) local cardidLsw = block1:sub(9,16) local cardidMsw = block1:sub(16,24) local cardid = block1:sub(9,24) local subtype = block1:sub(25,28) -- Write dump to files if not DEBUG then local foo = dumplib.SaveAsBinary(bindata, outputTemplate..'-'..uid..'.bin') print(("Wrote a BIN dump to: %s"):format(foo)) local bar = dumplib.SaveAsText(emldata, outputTemplate..'-'..uid..'.eml') print(("Wrote a EML dump to: %s"):format(bar)) end print( string.rep('--',20) ) -- Show info local item = toys.Find(toytype, subtype) if item then print((' ITEM TYPE : %s - %s (%s)'):format(item[6],item[5], item[4]) ) else print((' ITEM TYPE : 0x%s 0x%s'):format(toytype, subtype)) end print( (' UID : 0x%s'):format(uid) ) print( (' CARDID : 0x%s'):format(cardid ) ) print( string.rep('--',20) ) core.clearCommandBuffer() end main(args)
gpl-2.0
artynet/luci
applications/luci-app-radicale2/luasrc/model/cbi/radicale2/storage.lua
7
1895
-- Licensed to the public under the Apache License 2.0. local rad2 = luci.controller.radicale2 local fs = require("nixio.fs") local m = Map("radicale2", translate("Radicale 2.x"), translate("A lightweight CalDAV/CardDAV server")) local s = m:section(NamedSection, "storage", "section", translate("Storage")) s.addremove = true s.anonymous = false o = s:option(ListValue, "type", translate("Storage Type")) o:value("", translate("Default (multifilesystem)")) o:value("multifilesystem", translate("Multiple files on filesystem")) o.default = "" o.rmempty = true o = s:option(Value, "filesystem_folder", translate("Folder"), translate("Folder in which to store collections")) o:depends("type", "") o:depends("type", "multifilesystem") o.rmempty = true o.placeholder = "/srv/radicale2/data" o = s:option(Flag, "filesystem_locking", translate("Use File Locks"), translate("Prevent other instances or processes from modifying collections while in use")) o:depends("type", "") o:depends("type", "multifilesystem") o.rmempty = true o.default = o.enabled o = s:option(Value, "max_sync_token_age", translate("Max Sync Token Age"), translate("Delete sync token that are older (seconds)")) o:depends("type", "") o:depends("type", "multifilesystem") o.rmempty = true o.placeholder = 2592000 o.datatype = "uinteger" o = s:option(Flag, "filesystem_close_lock_file", translate("Close Lock File"), translate("Close the lock file when no more clients are waiting")) o:depends("type", "") o:depends("type", "multifilesystem") o.rmempty = true o.default = o.disabled o = s:option(Value, "hook", translate("Hook"), translate("Command that is run after changes to storage")) o:depends("type", "") o:depends("type", "multifilesystem") o.rmempty = true o.placeholder = ("Example: ([ -d .git ] || git init) && git add -A && (git diff --cached --quiet || git commit -m \"Changes by \"%(user)s") return m
apache-2.0
MeGa-TeAm/megabot
plugins/time.lua
94
3004
-- Implement a command !time [area] which uses -- 2 Google APIs to get the desired result: -- 1. Geocoding to get from area to a lat/long pair -- 2. Timezone to get the local time in that lat/long location -- Globals -- If you have a google api key for the geocoding/timezone api api_key = nil base_api = "https://maps.googleapis.com/maps/api" dateFormat = "%A %d %B - %H:%M:%S" -- Need the utc time for the google api function utctime() return os.time(os.date("!*t")) end -- Use the geocoding api to get the lattitude and longitude with accuracy specifier -- CHECKME: this seems to work without a key?? function get_latlong(area) local api = base_api .. "/geocode/json?" local parameters = "address=".. (URL.escape(area) or "") if api_key ~= nil then parameters = parameters .. "&key="..api_key end -- Do the request local res, code = https.request(api..parameters) if code ~=200 then return nil end local data = json:decode(res) if (data.status == "ZERO_RESULTS") then return nil end if (data.status == "OK") then -- Get the data lat = data.results[1].geometry.location.lat lng = data.results[1].geometry.location.lng acc = data.results[1].geometry.location_type types= data.results[1].types return lat,lng,acc,types end end -- Use timezone api to get the time in the lat, -- Note: this needs an API key function get_time(lat,lng) local api = base_api .. "/timezone/json?" -- Get a timestamp (server time is relevant here) local timestamp = utctime() local parameters = "location=" .. URL.escape(lat) .. "," .. URL.escape(lng) .. "&timestamp="..URL.escape(timestamp) if api_key ~=nil then parameters = parameters .. "&key="..api_key end local res,code = https.request(api..parameters) if code ~= 200 then return nil end local data = json:decode(res) if (data.status == "ZERO_RESULTS") then return nil end if (data.status == "OK") then -- Construct what we want -- The local time in the location is: -- timestamp + rawOffset + dstOffset local localTime = timestamp + data.rawOffset + data.dstOffset return localTime, data.timeZoneId end return localTime end function getformattedLocalTime(area) if area == nil then return "The time in nowhere is never" end lat,lng,acc = get_latlong(area) if lat == nil and lng == nil then return 'It seems that in "'..area..'" they do not have a concept of time.' end local localTime, timeZoneId = get_time(lat,lng) return "The local time in "..timeZoneId.." is: ".. os.date(dateFormat,localTime) end function run(msg, matches) return getformattedLocalTime(matches[1]) end return { description = "Displays the local time in an area", usage = "!time [area]: Displays the local time in that area", patterns = {"^!time (.*)$"}, run = run } --Copyright and edit; @behroozyaghi --Persian Translate; @behroozyaghi --ch : @nod32team --کپی بدون ذکر منبع حرام است
gpl-2.0
ahmedcharles/Mudlet
src/mudlet-lua/lua/geyser/GeyserMapper.lua
21
1556
-------------------------------------- -- -- -- The Geyser Layout Manager by guy -- -- createMapper support by Vadi -- -- -- -------------------------------------- --- Represents a mapper primitive -- @class table -- @name Geyser.Mapper -- @field wrapAt Where line wrapping occurs. Default is 300 characters. Geyser.Mapper = Geyser.Window:new({ name = "MapperClass" }) -- Save a reference to our parent constructor Geyser.Mapper.parent = Geyser.Window -- Overridden reposition function - mapper does it differently right now function Geyser.Mapper:reposition() if self.hidden then return end createMapper(self:get_x(), self:get_y(), self:get_width(), self:get_height()) end function Geyser.Mapper:hide_impl() createMapper(self:get_x(), self:get_y(), 0, 0) end function Geyser.Mapper:show_impl() createMapper(self:get_x(), self:get_y(), self:get_width(), self:get_height()) end -- Overridden constructor function Geyser.Mapper:new (cons, container) cons = cons or {} cons.type = cons.type or "mapper" -- Call parent's constructor local me = self.parent:new(cons, container) me.was_hidden = false -- Set the metatable. setmetatable(me, self) self.__index = self ----------------------------------------------------------- -- Now create the Mapper using primitives createMapper(me:get_x(), me:get_y(), me:get_width(), me:get_height()) -- Set any defined colors Geyser.Color.applyColors(me) --print(" New in " .. self.name .. " : " .. me.name) return me end
gpl-2.0
artynet/luci
modules/luci-base/luasrc/util.lua
6
17653
-- Copyright 2008 Steven Barth <steven@midlink.org> -- Licensed to the public under the Apache License 2.0. local io = require "io" local math = require "math" local table = require "table" local debug = require "debug" local ldebug = require "luci.debug" local string = require "string" local coroutine = require "coroutine" local tparser = require "luci.template.parser" local json = require "luci.jsonc" local lhttp = require "lucihttp" local _ubus = require "ubus" local _ubus_connection = nil local getmetatable, setmetatable = getmetatable, setmetatable local rawget, rawset, unpack, select = rawget, rawset, unpack, select local tostring, type, assert, error = tostring, type, assert, error local ipairs, pairs, next, loadstring = ipairs, pairs, next, loadstring local require, pcall, xpcall = require, pcall, xpcall local collectgarbage, get_memory_limit = collectgarbage, get_memory_limit module "luci.util" -- -- Pythonic string formatting extension -- getmetatable("").__mod = function(a, b) local ok, res if not b then return a elseif type(b) == "table" then local k, _ for k, _ in pairs(b) do if type(b[k]) == "userdata" then b[k] = tostring(b[k]) end end ok, res = pcall(a.format, a, unpack(b)) if not ok then error(res, 2) end return res else if type(b) == "userdata" then b = tostring(b) end ok, res = pcall(a.format, a, b) if not ok then error(res, 2) end return res end end -- -- Class helper routines -- -- Instantiates a class local function _instantiate(class, ...) local inst = setmetatable({}, {__index = class}) if inst.__init__ then inst:__init__(...) end return inst end -- The class object can be instantiated by calling itself. -- Any class functions or shared parameters can be attached to this object. -- Attaching a table to the class object makes this table shared between -- all instances of this class. For object parameters use the __init__ function. -- Classes can inherit member functions and values from a base class. -- Class can be instantiated by calling them. All parameters will be passed -- to the __init__ function of this class - if such a function exists. -- The __init__ function must be used to set any object parameters that are not shared -- with other objects of this class. Any return values will be ignored. function class(base) return setmetatable({}, { __call = _instantiate, __index = base }) end function instanceof(object, class) local meta = getmetatable(object) while meta and meta.__index do if meta.__index == class then return true end meta = getmetatable(meta.__index) end return false end -- -- Scope manipulation routines -- coxpt = setmetatable({}, { __mode = "kv" }) local tl_meta = { __mode = "k", __index = function(self, key) local t = rawget(self, coxpt[coroutine.running()] or coroutine.running() or 0) return t and t[key] end, __newindex = function(self, key, value) local c = coxpt[coroutine.running()] or coroutine.running() or 0 local r = rawget(self, c) if not r then rawset(self, c, { [key] = value }) else r[key] = value end end } -- the current active coroutine. A thread local store is private a table object -- whose values can't be accessed from outside of the running coroutine. function threadlocal(tbl) return setmetatable(tbl or {}, tl_meta) end -- -- Debugging routines -- function perror(obj) return io.stderr:write(tostring(obj) .. "\n") end function dumptable(t, maxdepth, i, seen) i = i or 0 seen = seen or setmetatable({}, {__mode="k"}) for k,v in pairs(t) do perror(string.rep("\t", i) .. tostring(k) .. "\t" .. tostring(v)) if type(v) == "table" and (not maxdepth or i < maxdepth) then if not seen[v] then seen[v] = true dumptable(v, maxdepth, i+1, seen) else perror(string.rep("\t", i) .. "*** RECURSION ***") end end end end -- -- String and data manipulation routines -- function pcdata(value) return value and tparser.pcdata(tostring(value)) end function urlencode(value) if value ~= nil then local str = tostring(value) return lhttp.urlencode(str, lhttp.ENCODE_IF_NEEDED + lhttp.ENCODE_FULL) or str end return nil end function urldecode(value, decode_plus) if value ~= nil then local flag = decode_plus and lhttp.DECODE_PLUS or 0 local str = tostring(value) return lhttp.urldecode(str, lhttp.DECODE_IF_NEEDED + flag) or str end return nil end function striptags(value) return value and tparser.striptags(tostring(value)) end function shellquote(value) return string.format("'%s'", string.gsub(value or "", "'", "'\\''")) end -- for bash, ash and similar shells single-quoted strings are taken -- literally except for single quotes (which terminate the string) -- (and the exception noted below for dash (-) at the start of a -- command line parameter). function shellsqescape(value) local res res, _ = string.gsub(value, "'", "'\\''") return res end -- bash, ash and other similar shells interpret a dash (-) at the start -- of a command-line parameters as an option indicator regardless of -- whether it is inside a single-quoted string. It must be backlash -- escaped to resolve this. This requires in some funky special-case -- handling. It may actually be a property of the getopt function -- rather than the shell proper. function shellstartsqescape(value) res, _ = string.gsub(value, "^%-", "\\-") return shellsqescape(res) end -- containing the resulting substrings. The optional max parameter specifies -- the number of bytes to process, regardless of the actual length of the given -- string. The optional last parameter, regex, specifies whether the separator -- sequence is interpreted as regular expression. -- pattern as regular expression (optional, default is false) function split(str, pat, max, regex) pat = pat or "\n" max = max or #str local t = {} local c = 1 if #str == 0 then return {""} end if #pat == 0 then return nil end if max == 0 then return str end repeat local s, e = str:find(pat, c, not regex) max = max - 1 if s and max < 0 then t[#t+1] = str:sub(c) else t[#t+1] = str:sub(c, s and s - 1) end c = e and e + 1 or #str + 1 until not s or max < 0 return t end function trim(str) return (str:gsub("^%s*(.-)%s*$", "%1")) end function cmatch(str, pat) local count = 0 for _ in str:gmatch(pat) do count = count + 1 end return count end -- one token per invocation, the tokens are separated by whitespace. If the -- input value is a table, it is transformed into a string first. A nil value -- will result in a valid iterator which aborts with the first invocation. function imatch(v) if type(v) == "table" then local k = nil return function() k = next(v, k) return v[k] end elseif type(v) == "number" or type(v) == "boolean" then local x = true return function() if x then x = false return tostring(v) end end elseif type(v) == "userdata" or type(v) == "string" then return tostring(v):gmatch("%S+") end return function() end end -- value or 0 if the unit is unknown. Upper- or lower case is irrelevant. -- Recognized units are: -- o "y" - one year (60*60*24*366) -- o "m" - one month (60*60*24*31) -- o "w" - one week (60*60*24*7) -- o "d" - one day (60*60*24) -- o "h" - one hour (60*60) -- o "min" - one minute (60) -- o "kb" - one kilobyte (1024) -- o "mb" - one megabyte (1024*1024) -- o "gb" - one gigabyte (1024*1024*1024) -- o "kib" - one si kilobyte (1000) -- o "mib" - one si megabyte (1000*1000) -- o "gib" - one si gigabyte (1000*1000*1000) function parse_units(ustr) local val = 0 -- unit map local map = { -- date stuff y = 60 * 60 * 24 * 366, m = 60 * 60 * 24 * 31, w = 60 * 60 * 24 * 7, d = 60 * 60 * 24, h = 60 * 60, min = 60, -- storage sizes kb = 1024, mb = 1024 * 1024, gb = 1024 * 1024 * 1024, -- storage sizes (si) kib = 1000, mib = 1000 * 1000, gib = 1000 * 1000 * 1000 } -- parse input string for spec in ustr:lower():gmatch("[0-9%.]+[a-zA-Z]*") do local num = spec:gsub("[^0-9%.]+$","") local spn = spec:gsub("^[0-9%.]+", "") if map[spn] or map[spn:sub(1,1)] then val = val + num * ( map[spn] or map[spn:sub(1,1)] ) else val = val + num end end return val end -- also register functions above in the central string class for convenience string.pcdata = pcdata string.striptags = striptags string.split = split string.trim = trim string.cmatch = cmatch string.parse_units = parse_units function append(src, ...) for i, a in ipairs({...}) do if type(a) == "table" then for j, v in ipairs(a) do src[#src+1] = v end else src[#src+1] = a end end return src end function combine(...) return append({}, ...) end function contains(table, value) for k, v in pairs(table) do if value == v then return k end end return false end -- Both table are - in fact - merged together. function update(t, updates) for k, v in pairs(updates) do t[k] = v end end function keys(t) local keys = { } if t then for k, _ in kspairs(t) do keys[#keys+1] = k end end return keys end function clone(object, deep) local copy = {} for k, v in pairs(object) do if deep and type(v) == "table" then v = clone(v, deep) end copy[k] = v end return setmetatable(copy, getmetatable(object)) end -- Serialize the contents of a table value. function _serialize_table(t, seen) assert(not seen[t], "Recursion detected.") seen[t] = true local data = "" local idata = "" local ilen = 0 for k, v in pairs(t) do if type(k) ~= "number" or k < 1 or math.floor(k) ~= k or ( k - #t ) > 3 then k = serialize_data(k, seen) v = serialize_data(v, seen) data = data .. ( #data > 0 and ", " or "" ) .. '[' .. k .. '] = ' .. v elseif k > ilen then ilen = k end end for i = 1, ilen do local v = serialize_data(t[i], seen) idata = idata .. ( #idata > 0 and ", " or "" ) .. v end return idata .. ( #data > 0 and #idata > 0 and ", " or "" ) .. data end -- with loadstring(). function serialize_data(val, seen) seen = seen or setmetatable({}, {__mode="k"}) if val == nil then return "nil" elseif type(val) == "number" then return val elseif type(val) == "string" then return "%q" % val elseif type(val) == "boolean" then return val and "true" or "false" elseif type(val) == "function" then return "loadstring(%q)" % get_bytecode(val) elseif type(val) == "table" then return "{ " .. _serialize_table(val, seen) .. " }" else return '"[unhandled data type:' .. type(val) .. ']"' end end function restore_data(str) return loadstring("return " .. str)() end -- -- Byte code manipulation routines -- -- will be stripped before it is returned. function get_bytecode(val) local code if type(val) == "function" then code = string.dump(val) else code = string.dump( loadstring( "return " .. serialize_data(val) ) ) end return code -- and strip_bytecode(code) end -- numbers and debugging numbers will be discarded. Original version by -- Peter Cawley (http://lua-users.org/lists/lua-l/2008-02/msg01158.html) function strip_bytecode(code) local version, format, endian, int, size, ins, num, lnum = code:byte(5, 12) local subint if endian == 1 then subint = function(code, i, l) local val = 0 for n = l, 1, -1 do val = val * 256 + code:byte(i + n - 1) end return val, i + l end else subint = function(code, i, l) local val = 0 for n = 1, l, 1 do val = val * 256 + code:byte(i + n - 1) end return val, i + l end end local function strip_function(code) local count, offset = subint(code, 1, size) local stripped = { string.rep("\0", size) } local dirty = offset + count offset = offset + count + int * 2 + 4 offset = offset + int + subint(code, offset, int) * ins count, offset = subint(code, offset, int) for n = 1, count do local t t, offset = subint(code, offset, 1) if t == 1 then offset = offset + 1 elseif t == 4 then offset = offset + size + subint(code, offset, size) elseif t == 3 then offset = offset + num elseif t == 254 or t == 9 then offset = offset + lnum end end count, offset = subint(code, offset, int) stripped[#stripped+1] = code:sub(dirty, offset - 1) for n = 1, count do local proto, off = strip_function(code:sub(offset, -1)) stripped[#stripped+1] = proto offset = offset + off - 1 end offset = offset + subint(code, offset, int) * int + int count, offset = subint(code, offset, int) for n = 1, count do offset = offset + subint(code, offset, size) + size + int * 2 end count, offset = subint(code, offset, int) for n = 1, count do offset = offset + subint(code, offset, size) + size end stripped[#stripped+1] = string.rep("\0", int * 3) return table.concat(stripped), offset end return code:sub(1,12) .. strip_function(code:sub(13,-1)) end -- -- Sorting iterator functions -- function _sortiter( t, f ) local keys = { } local k, v for k, v in pairs(t) do keys[#keys+1] = k end local _pos = 0 table.sort( keys, f ) return function() _pos = _pos + 1 if _pos <= #keys then return keys[_pos], t[keys[_pos]], _pos end end end -- the provided callback function. function spairs(t,f) return _sortiter( t, f ) end -- The table pairs are sorted by key. function kspairs(t) return _sortiter( t ) end -- The table pairs are sorted by value. function vspairs(t) return _sortiter( t, function (a,b) return t[a] < t[b] end ) end -- -- System utility functions -- function bigendian() return string.byte(string.dump(function() end), 7) == 0 end function exec(command) local pp = io.popen(command) local data = pp:read("*a") pp:close() return data end function execi(command) local pp = io.popen(command) return pp and function() local line = pp:read() if not line then pp:close() end return line end end -- Deprecated function execl(command) local pp = io.popen(command) local line = "" local data = {} while true do line = pp:read() if (line == nil) then break end data[#data+1] = line end pp:close() return data end local ubus_codes = { "INVALID_COMMAND", "INVALID_ARGUMENT", "METHOD_NOT_FOUND", "NOT_FOUND", "NO_DATA", "PERMISSION_DENIED", "TIMEOUT", "NOT_SUPPORTED", "UNKNOWN_ERROR", "CONNECTION_FAILED" } local function ubus_return(...) if select('#', ...) == 2 then local rv, err = select(1, ...), select(2, ...) if rv == nil and type(err) == "number" then return nil, err, ubus_codes[err] end end return ... end function ubus(object, method, data) if not _ubus_connection then _ubus_connection = _ubus.connect() assert(_ubus_connection, "Unable to establish ubus connection") end if object and method then if type(data) ~= "table" then data = { } end return ubus_return(_ubus_connection:call(object, method, data)) elseif object then return _ubus_connection:signatures(object) else return _ubus_connection:objects() end end function serialize_json(x, cb) local js = json.stringify(x) if type(cb) == "function" then cb(js) else return js end end function libpath() return require "nixio.fs".dirname(ldebug.__file__) end function checklib(fullpathexe, wantedlib) local fs = require "nixio.fs" local haveldd = fs.access('/usr/bin/ldd') local haveexe = fs.access(fullpathexe) if not haveldd or not haveexe then return false end local libs = exec(string.format("/usr/bin/ldd %s", shellquote(fullpathexe))) if not libs then return false end for k, v in ipairs(split(libs)) do if v:find(wantedlib) then return true end end return false end ------------------------------------------------------------------------------- -- Coroutine safe xpcall and pcall versions -- -- Encapsulates the protected calls with a coroutine based loop, so errors can -- be dealed without the usual Lua 5.x pcall/xpcall issues with coroutines -- yielding inside the call to pcall or xpcall. -- -- Authors: Roberto Ierusalimschy and Andre Carregal -- Contributors: Thomas Harning Jr., Ignacio Burgueño, Fabio Mascarenhas -- -- Copyright 2005 - Kepler Project -- -- $Id: coxpcall.lua,v 1.13 2008/05/19 19:20:02 mascarenhas Exp $ ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -- Implements xpcall with coroutines ------------------------------------------------------------------------------- local coromap = setmetatable({}, { __mode = "k" }) local function handleReturnValue(err, co, status, ...) if not status then return false, err(debug.traceback(co, (...)), ...) end if coroutine.status(co) == 'suspended' then return performResume(err, co, coroutine.yield(...)) else return true, ... end end function performResume(err, co, ...) return handleReturnValue(err, co, coroutine.resume(co, ...)) end local function id(trace, ...) return trace end function coxpcall(f, err, ...) local current = coroutine.running() if not current then if err == id then return pcall(f, ...) else if select("#", ...) > 0 then local oldf, params = f, { ... } f = function() return oldf(unpack(params)) end end return xpcall(f, err) end else local res, co = pcall(coroutine.create, f) if not res then local newf = function(...) return f(...) end co = coroutine.create(newf) end coromap[co] = current coxpt[co] = coxpt[current] or current or 0 return performResume(err, co, ...) end end function copcall(f, ...) return coxpcall(f, id, ...) end
apache-2.0
mrshayan/iran_power_ok
plugins/boobs.lua
1
1785
do -- Recursive function local function getRandomButts(attempt) attempt = attempt or 0 attempt = attempt + 1 local res,status = http.request("http://api.obutts.ru/noise/1") if status ~= 200 then return nil end local data = json:decode(res)[1] -- The OpenBoobs API sometimes returns an empty array if not data and attempt <= 3 then print('Cannot get that butts, trying another one...') return getRandomButts(attempt) end return 'http://media.obutts.ru/' .. data.preview end local function getRandomBoobs(attempt) attempt = attempt or 0 attempt = attempt + 1 local res,status = http.request("http://api.oboobs.ru/noise/1") if status ~= 200 then return nil end local data = json:decode(res)[1] -- The OpenBoobs API sometimes returns an empty array if not data and attempt < 10 then print('Cannot get that boobs, trying another one...') return getRandomBoobs(attempt) end return 'http://media.oboobs.ru/' .. data.preview end local function run(msg, matches) local url = nil if matches[1] == "عکس سکسی" then url = getRandomBoobs() end if matches[1] == "عکس سکسی" then url = getRandomButts() end if url ~= nil then local receiver = get_receiver(msg) send_photo_from_url(receiver, url) else return 'Error getting boobs/butts for you, please try again later.' end end return { description = "Gets a random boobs or butts pic", usage = { "عکس سکسی: Get a boobs NSFW image. 🔞", "عکس سکسی: Get a butts NSFW image. 🔞" }, patterns = { "^عکس سکسی$", "^عکس سکسی$" }, run = run } end --Copyright; @behroozyaghi --Persian Translate; @behroozyaghi --ch : @nod32team --کپی بدون ذکر منبع حرام است
gpl-2.0
FastTM/Fast-Unique
plugins/setlang.lua
1
1753
local plugin = {} local function doKeyboard_lang() local keyboard = { inline_keyboard = {} } for lang, flag in pairs(config.available_languages) do local line = {{text = flag, callback_data = 'langselected:'..lang}} table.insert(keyboard.inline_keyboard, line) end return keyboard end function plugin.onTextMessage(msg, blocks) if not (msg.chat.type ~= 'private' and not roles.is_admin_cached(msg)) then local keyboard = doKeyboard_lang() api.sendMessage(msg.chat.id, _("*List of available languages*:"), true, keyboard) end end function plugin.onCallbackQuery(msg, blocks) if msg.chat.type ~= 'private' and not roles.is_admin_cached(msg) then api.answerCallbackQuery(msg.cb_id, _("You are not an admin")) else if blocks[1] == 'selectlang' then local keyboard = doKeyboard_lang() api.editMessageText(msg.chat.id, msg.message_id, _("*List of available languages*:"), true, keyboard) else locale.language = blocks[1] db:set('lang:'..msg.chat.id, locale.language) if (blocks[1] == 'ar' or blocks[1] == 'fa') and msg.chat.type ~= 'private' then db:hset('chat:'..msg.chat.id..':char', 'Arab', 'allowed') db:hset('chat:'..msg.chat.id..':char', 'Rtl', 'allowed') end -- TRANSLATORS: replace 'English' with the name of your language api.editMessageText(msg.chat.id, msg.message_id, _("English language is *set*").._(".\nPlease note that translators are volunteers, and some strings of the translation you selected _could not have been translated yet_"), true) end end end plugin.triggers = { onTextMessage = {config.cmd..'(lang)$'}, onCallbackQuery = { '^###cb:(selectlang)', '^###cb:langselected:(%l%l)$', '^###cb:langselected:(%l%l_%u%u)$' } } return plugin
gpl-2.0
Hzj-jie/koreader-base
thirdparty/lua-ljsqlite3/init.lua
2
20250
-------------------------------------------------------------------------------- -- A library for interfacing with SQLite3 databases. -- -- Copyright (C) 2011-2016 Stefano Peluchetti. All rights reserved. -- -- Features, documentation and more: http://www.scilua.org . -- -- This file is part of the LJSQLite3 library, which is released under the MIT -- license: full text in file LICENSE.TXT in the library's root folder. -------------------------------------------------------------------------------- -- TODO: Refactor according to latest style / coding guidelines. -- TODO: introduce functionality to get of a defined type to avoid if check? -- TODO: Add extended error codes from Sqlite? -- TODO: Consider type checks? -- TODO: Exposed cdef constants are ok? -- TODO: Resultset (and so exec) could be optimized by avoiding loads/stores -- TODO: of row table via _step? local ffi = require "ffi" local bit = require "bit" local xsys = require "xsys" local split, trim = xsys.string.split, xsys.string.trim local function err(code, msg) error("ljsqlite3["..code.."] "..msg) end -- Codes ----------------------------------------------------------------------- local sqlconstants = {} -- SQLITE_* and OPEN_* declarations. local codes = { [0] = "OK", "ERROR", "INTERNAL", "PERM", "ABORT", "BUSY", "LOCKED", "NOMEM", "READONLY", "INTERRUPT", "IOERR", "CORRUPT", "NOTFOUND", "FULL", "CANTOPEN", "PROTOCOL", "EMPTY", "SCHEMA", "TOOBIG", "CONSTRAINT", "MISMATCH", "MISUSE", "NOLFS", "AUTH", "FORMAT", "RANGE", "NOTADB", [100] = "ROW", [101] = "DONE" } -- From 0 to 26. do local types = { "INTEGER", "FLOAT", "TEXT", "BLOB", "NULL" } -- From 1 to 5. local opens = { READONLY = 0x00000001; READWRITE = 0x00000002; CREATE = 0x00000004; DELETEONCLOSE = 0x00000008; EXCLUSIVE = 0x00000010; AUTOPROXY = 0x00000020; URI = 0x00000040; MAIN_DB = 0x00000100; TEMP_DB = 0x00000200; TRANSIENT_DB = 0x00000400; MAIN_JOURNAL = 0x00000800; TEMP_JOURNAL = 0x00001000; SUBJOURNAL = 0x00002000; MASTER_JOURNAL = 0x00004000; NOMUTEX = 0x00008000; FULLMUTEX = 0x00010000; SHAREDCACHE = 0x00020000; PRIVATECACHE = 0x00040000; WAL = 0x00080000; } local t = sqlconstants local pre = "static const int32_t SQLITE_" for i=0,26 do t[#t+1] = pre..codes[i].."="..i..";\n" end for i=100,101 do t[#t+1] = pre..codes[i].."="..i..";\n" end for i=1,5 do t[#t+1] = pre..types[i].."="..i..";\n" end pre = pre.."OPEN_" for k,v in pairs(opens) do t[#t+1] = pre..k.."="..bit.tobit(v)..";\n" end end -- Cdef ------------------------------------------------------------------------ -- SQLITE_*, OPEN_* ffi.cdef(table.concat(sqlconstants)) -- sqlite3*, ljsqlite3_* ffi.cdef[[ // Typedefs. typedef struct sqlite3 sqlite3; typedef struct sqlite3_stmt sqlite3_stmt; typedef void (*sqlite3_destructor_type)(void*); typedef struct sqlite3_context sqlite3_context; typedef struct Mem sqlite3_value; // Get informative error message. const char *sqlite3_errmsg(sqlite3*); // Connection. int sqlite3_open_v2(const char *filename, sqlite3 **ppDb, int flags, const char *zVfs); int sqlite3_close(sqlite3*); int sqlite3_busy_timeout(sqlite3*, int ms); // Statement. int sqlite3_prepare_v2(sqlite3 *conn, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail); int sqlite3_step(sqlite3_stmt*); int sqlite3_reset(sqlite3_stmt *pStmt); int sqlite3_finalize(sqlite3_stmt *pStmt); // Extra functions for SELECT. int sqlite3_column_count(sqlite3_stmt *pStmt); const char *sqlite3_column_name(sqlite3_stmt*, int N); int sqlite3_column_type(sqlite3_stmt*, int iCol); // Get value from SELECT. int64_t sqlite3_column_int64(sqlite3_stmt*, int iCol); double sqlite3_column_double(sqlite3_stmt*, int iCol); int sqlite3_column_bytes(sqlite3_stmt*, int iCol); const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); // Set value in bind. int sqlite3_bind_int64(sqlite3_stmt*, int, int64_t); int sqlite3_bind_double(sqlite3_stmt*, int, double); int sqlite3_bind_null(sqlite3_stmt*, int); int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); // Clear bindings. int sqlite3_clear_bindings(sqlite3_stmt*); // Get value in callbacks. int sqlite3_value_type(sqlite3_value*); int64_t sqlite3_value_int64(sqlite3_value*); double sqlite3_value_double(sqlite3_value*); int sqlite3_value_bytes(sqlite3_value*); const unsigned char *sqlite3_value_text(sqlite3_value*); //Not used. const void *sqlite3_value_blob(sqlite3_value*); // Set value in callbacks. void sqlite3_result_error(sqlite3_context*, const char*, int); void sqlite3_result_int64(sqlite3_context*, int64_t); void sqlite3_result_double(sqlite3_context*, double); void sqlite3_result_null(sqlite3_context*); void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); // Persistency of data in callbacks (here just a pointer for tagging). void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); // Typedefs for callbacks. typedef void (*ljsqlite3_cbstep)(sqlite3_context*,int,sqlite3_value**); typedef void (*ljsqlite3_cbfinal)(sqlite3_context*); // Register callbacks. int sqlite3_create_function( sqlite3 *conn, const char *zFunctionName, int nArg, int eTextRep, void *pApp, void (*xFunc)(sqlite3_context*,int,sqlite3_value**), void (*xStep)(sqlite3_context*,int,sqlite3_value**), void (*xFinal)(sqlite3_context*) ); ]] -------------------------------------------------------------------------------- local sql = ffi.load("sqlite3") local transient = ffi.cast("sqlite3_destructor_type", -1) local int64_ct = ffi.typeof("int64_t") local blob_mt = {} -- For tagging only. local function blob(str) return setmetatable({ str }, blob_mt) end local connstmt = {} -- Statements for a conn. local conncb = {} -- Callbacks for a conn. local aggregatestate = {} -- Aggregate states. local stmt_step local stmt_mt, stmt_ct = {} stmt_mt.__index = stmt_mt local conn_mt, conn_ct = {} conn_mt.__index = conn_mt -- Checks ---------------------------------------------------------------------- -- Helper function to get error msg and code from sqlite. local function codemsg(pconn, code) return codes[code]:lower(), ffi.string(sql.sqlite3_errmsg(pconn)) end -- Throw error for a given connection. local function E_conn(pconn, code) local code, msg = codemsg(pconn, code) err(code, msg) end -- Test code is OK or throw error for a given connection. local function T_okcode(pconn, code) if code ~= sql.SQLITE_OK then E_conn(pconn, code) end end local function T_open(x) if x._closed then err("misuse", "object is closed") end end -- Getters / Setters to minimize code duplication ------------------------------ local sql_get_code = [=[ return function(stmt_or_value <opt_i>) local t = sql.sqlite3_<variant>_type(stmt_or_value <opt_i>) if t == sql.SQLITE_INTEGER then return sql.sqlite3_<variant>_int64(stmt_or_value <opt_i>) elseif t == sql.SQLITE_FLOAT then return sql.sqlite3_<variant>_double(stmt_or_value <opt_i>) elseif t == sql.SQLITE_TEXT then local nb = sql.sqlite3_<variant>_bytes(stmt_or_value <opt_i>) return ffi.string(sql.sqlite3_<variant>_text(stmt_or_value <opt_i>), nb) elseif t == sql.SQLITE_BLOB then local nb = sql.sqlite3_<variant>_bytes(stmt_or_value <opt_i>) return ffi.string(sql.sqlite3_<variant>_blob(stmt_or_value <opt_i>), nb) elseif t == sql.SQLITE_NULL then return nil else err("constraint", "unexpected SQLite3 type") end end ]=] local sql_set_code = [=[ return function(stmt_or_value, v <opt_i>) local t = type(v) if ffi.istype(int64_ct, v) then return sql.sqlite3_<variant>_int64(stmt_or_value <opt_i>, v) elseif t == "number" then return sql.sqlite3_<variant>_double(stmt_or_value <opt_i>, v) elseif t == "string" then return sql.sqlite3_<variant>_text(stmt_or_value <opt_i>, v, #v, transient) elseif t == "table" and getmetatable(v) == blob_mt then v = v[1] return sql.sqlite3_<variant>_blob(stmt_or_value <opt_i>, v, #v, transient) elseif t == "nil" then return sql.sqlite3_<variant>_null(stmt_or_value <opt_i>) else err("constraint", "unexpected Lua type") end end ]=] -- Environment for setters/getters. local sql_env = { sql = sql, transient = transient, ffi = ffi, int64_ct = int64_ct, blob_mt = blob_mt, getmetatable = getmetatable, err = err, type = type } local function sql_format(s, variant, index) return s:gsub("<variant>", variant):gsub("<opt_i>", index) end local function loadcode(s, env) local ret = assert(loadstring(s)) if env then setfenv(ret, env) end return ret() end -- Must always be called from *:_* function due to error level 4. local get_column = loadcode(sql_format(sql_get_code, "column", ",i"), sql_env) local get_value = loadcode(sql_format(sql_get_code, "value" , " "), sql_env) local set_column = loadcode(sql_format(sql_set_code, "bind" , ",i"), sql_env) local set_value = loadcode(sql_format(sql_set_code, "result", " "), sql_env) -- Connection ------------------------------------------------------------------ local open_modes = { ro = sql.SQLITE_OPEN_READONLY, rw = sql.SQLITE_OPEN_READWRITE, rwc = bit.bor(sql.SQLITE_OPEN_READWRITE, sql.SQLITE_OPEN_CREATE) } local function open(str, mode) mode = mode or "rwc" mode = open_modes[mode] if not mode then err("constraint", "argument #2 to open must be ro, rw, or rwc") end local aptr = ffi.new("sqlite3*[1]") -- Usually aptr is set even if error code, so conn always needs to be closed. local code = sql.sqlite3_open_v2(str, aptr, mode, nil) local conn = conn_ct(aptr[0], false) -- Must create this anyway due to conn:close() function. connstmt[conn] = setmetatable({}, { __mode = "k" }) conncb[conn] = { scalar = {}, step = {}, final = {} } if code ~= sql.SQLITE_OK then local code, msg = codemsg(conn._ptr, code) -- Before closing! conn:close() -- Free resources, should not fail here in this case! err(code, msg) end return conn end function conn_mt:close() T_open(self) -- Close all stmt linked to conn. for k,_ in pairs(connstmt[self]) do if not k._closed then k:close() end end -- Close all callbacks linked to conn. for _,v in pairs(conncb[self].scalar) do v:free() end for _,v in pairs(conncb[self].step) do v:free() end for _,v in pairs(conncb[self].final) do v:free() end local code = sql.sqlite3_close(self._ptr) T_okcode(self._ptr, code) connstmt[self] = nil -- Table connstmt is not weak, need to clear manually. conncb[self] = nil self._closed = true -- Set only if close succeded. end function conn_mt:__gc() if not self._closed then self:close() end end function conn_mt:prepare(stmtstr) T_open(self) local aptr = ffi.new("sqlite3_stmt*[1]") -- If error code aptr NULL, so no need to close anything. local code = sql.sqlite3_prepare_v2(self._ptr, stmtstr, #stmtstr, aptr, nil) T_okcode(self._ptr, code) local stmt = stmt_ct(aptr[0], false, self._ptr, code) connstmt[self][stmt] = true return stmt end -- Connection exec, __call, rowexec -------------------------------------------- function conn_mt:exec(commands, get) T_open(self) local cmd1 = split(commands, ";") local res, n for i=1,#cmd1 do local cmd = trim(cmd1[i]) if #cmd > 0 then local stmt = self:prepare(cmd) res, n = stmt:resultset(get) stmt:close() end end return res, n -- Only last record is returned. end function conn_mt:rowexec(command) T_open(self) local stmt = self:prepare(command) local res = stmt:_step() if stmt:_step() then err("misuse", "multiple records returned, 1 expected") end stmt:close() return unpack(res) end function conn_mt:__call(commands, out) T_open(self) out = out or print local cmd1 = split(commands, ";") for c=1,#cmd1 do local cmd = trim(cmd1[c]) if #cmd > 0 then local stmt = self:prepare(cmd) local ret, n = stmt:resultset() if ret then -- All the results get handled, not only last one. out(unpack(ret[0])) -- Headers are printed. for i=1,n do local o = {} for j=1,#ret[0] do local v = ret[j][i] if type(v) == "nil" then v = "" end -- Empty strings for NULLs. o[#o+1] = tostring(v) end out(unpack(o)) end end stmt:close() end end end -- Callbacks ------------------------------------------------------------------- -- Update (one of) callbacks registry for sqlite functions. local function updatecb(self, where, name, f) local cbs = conncb[self][where] if cbs[name] then -- Callback already present, free old one. cbs[name]:free() end cbs[name] = f -- Could be nil and that's fine. end -- Return manually casted callback that sqlite expects, scalar. local function scalarcb(name, f) local values = {} -- Conversion buffer. local function sqlf(context, nvalues, pvalues) -- Indexing 0,N-1. for i=1,nvalues do values[i] = get_value(pvalues[i - 1]) end -- Throw error via sqlite function if necessary. local ok, result = pcall(f, unpack(values, 1, nvalues)) if not ok then local msg = "Lua registered scalar function "..name.." error: "..result sql.sqlite3_result_error(context, msg, #msg) else set_value(context, result) end end return ffi.cast("ljsqlite3_cbstep", sqlf) end -- Return the state for aggregate case (created via initstate()). We use the ptr -- returned from aggregate_context() for tagging only, all the state data is -- handled from Lua side. local function getstate(context, initstate, size) -- Only pointer address relevant for indexing, size irrelevant. local ptr = sql.sqlite3_aggregate_context(context, size) local pid = tonumber(ffi.cast("intptr_t",ptr)) local state = aggregatestate[pid] if type(state) == "nil" then state = initstate() aggregatestate[pid] = state end return state, pid end -- Return manually casted callback that sqlite expects, stepper for aggregate. local function stepcb(name, f, initstate) local values = {} -- Conversion buffer. local function sqlf(context, nvalues, pvalues) -- Indexing 0,N-1. for i=1,nvalues do values[i] = get_value(pvalues[i - 1]) end local state = getstate(context, initstate, 1) -- Throw error via sqlite function if necessary. local ok, result = pcall(f, state, unpack(values, 1, nvalues)) if not ok then local msg = "Lua registered step function "..name.." error: "..result sql.sqlite3_result_error(context, msg, #msg) end end return ffi.cast("ljsqlite3_cbstep", sqlf) end -- Return manually casted callback that sqlite expects, finalizer for aggregate. local function finalcb(name, f, initstate) local function sqlf(context) local state, pid = getstate(context, initstate, 0) aggregatestate[pid] = nil -- Clear the state. local ok, result = pcall(f, state) -- Throw error via sqlite function if necessary. if not ok then local msg = "Lua registered final function "..name.." error: "..result sql.sqlite3_result_error(context, msg, #msg) else set_value(context, result) end end return ffi.cast("ljsqlite3_cbfinal", sqlf) end function conn_mt:setscalar(name, f) T_open(self) jit.off(stmt_step) -- Necessary to avoid bad calloc in some use cases. local cbf = f and scalarcb(name, f) or nil local code = sql.sqlite3_create_function(self._ptr, name, -1, 5, nil, cbf, nil, nil) -- If cbf nil this clears the function is sqlite. T_okcode(self._ptr, code) updatecb(self, "scalar", name, cbf) -- Update and clear old. end function conn_mt:setaggregate(name, initstate, step, final) T_open(self) jit.off(stmt_step) -- Necessary to avoid bad calloc in some use cases. local cbs = step and stepcb (name, step, initstate) or nil local cbf = final and finalcb(name, final, initstate) or nil local code = sql.sqlite3_create_function(self._ptr, name, -1, 5, nil, nil, cbs, cbf) -- If cbs, cbf nil this clears the function is sqlite. T_okcode(self._ptr, code) updatecb(self, "step", name, cbs) -- Update and clear old. updatecb(self, "final", name, cbf) -- Update and clear old. end conn_ct = ffi.metatype("struct { sqlite3* _ptr; bool _closed; }", conn_mt) -- Statement ------------------------------------------------------------------- function stmt_mt:reset() T_open(self) -- Ignore possible error code, it would be repetition of error raised during -- most recent evaluation of statement which would have been raised already. sql.sqlite3_reset(self._ptr) self._code = sql.SQLITE_OK -- Always succeds. return self end function stmt_mt:close() T_open(self) -- Ignore possible error code, it would be repetition of error raised during -- most recent evaluation of statement which would have been raised already. sql.sqlite3_finalize(self._ptr) self._code = sql.SQLITE_OK -- Always succeds. self._closed = true -- Must be called exaclty once. end function stmt_mt:__gc() if not self._closed then self:close() end end -- Statement step, resultset --------------------------------------------------- function stmt_mt:_ncol() return sql.sqlite3_column_count(self._ptr) end function stmt_mt:_header(h) for i=1,self:_ncol() do -- Here indexing 0,N-1. h[i] = ffi.string(sql.sqlite3_column_name(self._ptr, i - 1)) end end stmt_step = function(self, row, header) -- Must check code ~= SQL_DONE or sqlite3_step --> undefined result. if self._code == sql.SQLITE_DONE then return nil end -- Already finished. self._code = sql.sqlite3_step(self._ptr) if self._code == sql.SQLITE_ROW then -- All the sql.* functions called never errors here. row = row or {} for i=1,self:_ncol() do row[i] = get_column(self._ptr, i - 1) end if header then self:_header(header) end return row, header elseif self._code == sql.SQLITE_DONE then -- Have finished now. return nil else -- If code not DONE or ROW then it's error. E_conn(self._conn, self._code) end end stmt_mt._step = stmt_step function stmt_mt:step(row, header) T_open(self) return self:_step(row, header) end function stmt_mt:resultset(get, maxrecords) T_open(self) get = get or "hik" maxrecords = maxrecords or math.huge if maxrecords < 1 then err("constraint", "agument #1 to resultset must be >= 1") end local hash, hasi, hask = get:find("h"), get:find("i"), get:find("k") local r, h = self:_step({}, {}) if not r then return nil, 0 end -- No records case. -- First record, o is a temporary table used to get records. local o = hash and { [0] = h } or {} for i=1,#h do o[i] = { r[i] } end -- Other records. local n = 1 while n < maxrecords and self:_step(r) do n = n + 1 for i=1,#h do o[i][n] = r[i] end end local out = { [0] = o[0] } -- Eventually copy colnames. if hasi then -- Use numeric indexes. for i=1,#h do out[i] = o[i] end end if hask then -- Use colnames indexes. for i=1,#h do out[h[i]] = o[i] end end return out, n end -- Statement bind -------------------------------------------------------------- function stmt_mt:_bind1(i, v) local code = set_column(self._ptr, v, i) -- Here indexing 1,N. T_okcode(self._conn, code) return self end function stmt_mt:bind1(i, v) T_open(self) return self:_bind1(i, v) end function stmt_mt:bind(...) T_open(self) for i=1,select("#", ...) do self:_bind1(i, select(i, ...)) end return self end function stmt_mt:clearbind() T_open(self) local code = sql.sqlite3_clear_bindings(self._ptr) T_okcode(self._conn, code) return self end stmt_ct = ffi.metatype([[struct { sqlite3_stmt* _ptr; bool _closed; sqlite3* _conn; int32_t _code; }]], stmt_mt) return { open = open, blob = blob, }
agpl-3.0
vinhqdang/spice
torch-rnn/test/TemporalCrossEntropyCriterion_test.lua
18
2660
require 'torch' require 'nn' require 'cutorch' require 'cunn' require 'TemporalCrossEntropyCriterion' local tester = torch.Tester() local tests = torch.TestSuite() -- Run a nn.CrossEntropyCriterion explicitly over all minibatch elements -- and timesteps, and make sure that we get the same results for both -- loss and gradient. function tests.naiveTest() local N, T, C = 2, 3, 4 local crit = nn.TemporalCrossEntropyCriterion() local scores = torch.randn(N, T, C) local target = torch.Tensor(N, T):random(C + 1):add(-1):long() local loss = crit:forward(scores, target) local grad_scores = crit:backward(scores, target) local naive_crit = nn.CrossEntropyCriterion() local lsm = nn.LogSoftMax() local naive_losses = torch.zeros(N, T) local naive_grad = torch.zeros(N, T, C) for n = 1, N do for t = 1, T do if target[{n, t}] ~= 0 then local score_slice = scores[{n, t}]:view(1, C) local logprobs = lsm:forward(score_slice) local target_slice = torch.LongTensor{target[{n, t}]} naive_losses[{n, t}] = naive_crit:forward(score_slice, target_slice) naive_grad[{n, t}]:copy(naive_crit:backward(score_slice, target_slice)) end end end if crit.batch_average then naive_losses:div(N) naive_grad:div(N) end if crit.time_average then naive_losses:div(T) naive_grad:div(T) end local naive_loss = naive_losses:sum() tester:assertTensorEq(naive_losses, crit.losses, 1e-5) tester:assertTensorEq(naive_grad, grad_scores, 1e-5) tester:assert(torch.abs(naive_loss - loss) < 1e-5) end -- Just make sure it runs, and that the sparsity patten in the -- loss and gradient are correct. function simpleTest(dtype) return function() torch.manualSeed(0) local N, T, C = 4, 5, 3 local crit = nn.TemporalCrossEntropyCriterion():type(dtype) local scores = torch.randn(N, T, C):type(dtype) local target = torch.Tensor(N, T):random(C + 1):add(-1):type(dtype) local loss = crit:forward(scores, target) local grad_scores = crit:backward(scores, target) -- Make sure that all zeros in target give rise to zeros in the -- right place in crit.losses and grad_scores for n = 1, N do for t = 1, T do if target[{n, t}] == 0 then tester:assert(crit.losses[{n, t}] == 0) tester:assert(torch.all(torch.eq(grad_scores[{n, t}], 0))) end end end torch.seed() end end tests.simpleDoubleTest = simpleTest('torch.DoubleTensor') tests.simpleFloatTest = simpleTest('torch.FloatTensor') tests.simpleCudaTest = simpleTest('torch.CudaTensor') tester:add(tests) tester:run()
gpl-3.0
blackhacker666/zep
plugins/info_fa.lua
1
8927
do local Arian = 89655129 --put your id here(BOT OWNER ID) local function setrank(msg, name, value) -- setrank function local hash = nil if msg.to.type == 'chat' then hash = 'rank:'..msg.to.id..':variables' end if hash then redis:hset(hash, name, value) return send_msg('chat#id'..msg.to.id, 'مقام کاربر ('..name..') به '..value..' تغییر داده شد ', ok_cb, true) end end local function res_user_callback(extra, success, result) -- /info <username> function if success == 1 then if result.username then Username = '@'..result.username else Username = 'ندارد' end local text = 'نام کامل : '..(result.first_name or '')..' '..(result.last_name or '')..'\n' ..'یوزر: '..Username..'\n' ..'ایدی کاربری : '..result.id..'\n\n' local hash = 'rank:'..extra.chat2..':variables' local value = redis:hget(hash, result.id) if not value then if result.id == tonumber(Arian) then text = text..'مقام : مدیر کل ربات (Executive Admin) \n\n' elseif is_admin2(result.id) then text = text..'مقام : ادمین ربات (Admin) \n\n' elseif is_owner2(result.id, extra.chat2) then text = text..'مقام : مدیر کل گروه (Owner) \n\n' elseif is_momod2(result.id, extra.chat2) then text = text..'مقام : مدیر گروه (Moderator) \n\n' else text = text..'مقام : کاربر (Member) \n\n' end else text = text..'مقام : '..value..'\n\n' end local uhash = 'user:'..result.id local user = redis:hgetall(uhash) local um_hash = 'msgs:'..result.id..':'..extra.chat2 user_info_msgs = tonumber(redis:get(um_hash) or 0) text = text..'تعداد پیام های فرستاده شده : '..user_info_msgs..'\n\n' text = text..'@' send_msg(extra.receiver, text, ok_cb, true) else send_msg(extra.receiver, extra.user..' نام کاربری مورد نظر یافت نشد.', ok_cb, false) end end local function action_by_id(extra, success, result) -- /info <ID> function if success == 1 then if result.username then Username = '@'..result.username else Username = 'ندارد' end local text = 'نام کامل : '..(result.first_name or '')..' '..(result.last_name or '')..'\n' ..'یوزر: '..Username..'\n' ..'ایدی کاربری : '..result.id..'\n\n' local hash = 'rank:'..extra.chat2..':variables' local value = redis:hget(hash, result.id) if not value then if result.id == tonumber(Arian) then text = text..'مقام : مدیر کل ربات (Executive Admin) \n\n' elseif is_admin2(result.id) then text = text..'مقام : ادمین ربات (Admin) \n\n' elseif is_owner2(result.id, extra.chat2) then text = text..'مقام : مدیر کل گروه (Owner) \n\n' elseif is_momod2(result.id, extra.chat2) then text = text..'مقام : مدیر گروه (Moderator) \n\n' else text = text..'مقام : کاربر (Member) \n\n' end else text = text..'مقام : '..value..'\n\n' end local uhash = 'user:'..result.id local user = redis:hgetall(uhash) local um_hash = 'msgs:'..result.id..':'..extra.chat2 user_info_msgs = tonumber(redis:get(um_hash) or 0) text = text..'تعداد پیام های فرستاده شده : '..user_info_msgs..'\n\n' text = text..'@signal_robot' send_msg(extra.receiver, text, ok_cb, true) else send_msg(extra.receiver, 'ایدی شخص مورد نظر در سیستم ثبت نشده است.\nاز دستور زیر استفاده کنید\n/info @username', ok_cb, false) end end local function action_by_reply(extra, success, result)-- (reply) /info function if result.from.username then Username = '@'..result.from.username else Username = 'ندارد' end local text = 'نام کامل : '..(result.from.first_name or '')..' '..(result.from.last_name or '')..'\n' ..'یوزر: '..Username..'\n' ..'ایدی کاربری : '..result.from.id..'\n\n' local hash = 'rank:'..result.to.id..':variables' local value = redis:hget(hash, result.from.id) if not value then if result.from.id == tonumber(Arian) then text = text..'مقام : مدیر کل ربات (Executive Admin) \n\n' elseif is_admin2(result.from.id) then text = text..'مقام : ادمین ربات (Admin) \n\n' elseif is_owner2(result.from.id, result.to.id) then text = text..'مقام : مدیر کل گروه (Owner) \n\n' elseif is_momod2(result.from.id, result.to.id) then text = text..'مقام : مدیر گروه (Moderator) \n\n' else text = text..'مقام : کاربر (Member) \n\n' end else text = text..'مقام : '..value..'\n\n' end local user_info = {} local uhash = 'user:'..result.from.id local user = redis:hgetall(uhash) local um_hash = 'msgs:'..result.from.id..':'..result.to.id user_info_msgs = tonumber(redis:get(um_hash) or 0) text = text..'تعداد پیام های فرستاده شده : '..user_info_msgs..'\n\n' text = text..'@tele_mega' send_msg(extra.receiver, text, ok_cb, true) end local function action_by_reply2(extra, success, result) local value = extra.value setrank(result, result.from.id, value) end local function run(msg, matches) if matches[1]:lower() == 'setrank' then local hash = 'usecommands:'..msg.from.id..':'..msg.to.id redis:incr(hash) if not is_sudo(msg) then return "Only for Sudo" end local receiver = get_receiver(msg) local Reply = msg.reply_id if msg.reply_id then local value = string.sub(matches[2], 1, 1000) msgr = get_message(msg.reply_id, action_by_reply2, {receiver=receiver, Reply=Reply, value=value}) else local name = string.sub(matches[2], 1, 50) local value = string.sub(matches[3], 1, 1000) local text = setrank(msg, name, value) return text end end if matches[1]:lower() == 'info' and not matches[2] then local receiver = get_receiver(msg) local Reply = msg.reply_id if msg.reply_id then msgr = get_message(msg.reply_id, action_by_reply, {receiver=receiver, Reply=Reply}) else if msg.from.username then Username = '@'..msg.from.username else Username = 'ندارد' end local text = 'نام : '..(msg.from.first_name or 'ندارد')..'\n' local text = text..'فامیل : '..(msg.from.last_name or 'ندارد')..'\n' local text = text..'یوزر : '..Username..'\n' local text = text..'ایدی کاربری : '..msg.from.id..'\n\n' local hash = 'rank:'..msg.to.id..':variables' if hash then local value = redis:hget(hash, msg.from.id) if not value then if msg.from.id == tonumber(Arian) then text = text..'مقام : مدیر کل ربات (Executive Admin) \n\n' elseif is_sudo(msg) then text = text..'مقام : ادمین ربات (Admin) \n\n' elseif is_owner(msg) then text = text..'مقام : مدیر کل گروه (Owner) \n\n' elseif is_momod(msg) then text = text..'مقام : مدیر گروه (Moderator) \n\n' else text = text..'مقام : کاربر (Member) \n\n' end else text = text..'مقام : '..value..'\n' end end local uhash = 'user:'..msg.from.id local user = redis:hgetall(uhash) local um_hash = 'msgs:'..msg.from.id..':'..msg.to.id user_info_msgs = tonumber(redis:get(um_hash) or 0) text = text..'تعداد پیام های فرستاده شده : '..user_info_msgs..'\n\n' if msg.to.type == 'chat' then text = text..'نام گروه : '..msg.to.title..'\n' text = text..'ایدی گروه : '..msg.to.id end text = text..'\n\n@tele_mega' return send_msg(receiver, text, ok_cb, true) end end if matches[1]:lower() == 'info' and matches[2] then local user = matches[2] local chat2 = msg.to.id local receiver = get_receiver(msg) if string.match(user, '^%d+$') then user_info('user#id'..user, action_by_id, {receiver=receiver, user=user, text=text, chat2=chat2}) elseif string.match(user, '^@.+$') then username = string.gsub(user, '@', '') msgr = res_user(username, res_user_callback, {receiver=receiver, user=user, text=text, chat2=chat2}) end end end return { description = 'Know your information or the info of a chat members.', usage = { '!info: Return your info and the chat info if you are in one.', '(Reply)!info: Return info of replied user if used by reply.', '!info <id>: Return the info\'s of the <id>.', '!info @<user_name>: Return the member @<user_name> information from the current chat.', '!setrank <userid> <rank>: change members rank.', '(Reply)!setrank <rank>: change members rank.', }, patterns = { "^[/!]([Ii][Nn][Ff][Oo])$", "^[/!]([Ii][Nn][Ff][Oo]) (.*)$", "^[/!]([Ss][Ee][Tt][Rr][Aa][Nn][Kk]) (%d+) (.*)$", "^[/!]([Ss][Ee][Tt][Rr][Aa][Nn][Kk]) (.*)$", }, run = run } end
gpl-2.0
squadette/vlc
share/lua/intf/telnet.lua
2
7964
--[==========================================================================[ telnet.lua: VLM interface plugin --[==========================================================================[ Copyright (C) 2007 the VideoLAN team $Id$ Authors: Antoine Cellerier <dionoea at videolan dot org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. --]==========================================================================] description= [============================================================================[ VLM Interface plugin Copy (features wise) of the original VLC modules/control/telnet.c module. Differences are: * it's in Lua * 'lock' command to lock the telnet promt * possibility to listen on different hosts including stdin for example: listen on stdin: vlc -I lua --lua-intf telnet --lua-config "telnet={host='*console'}" listen on stdin + 2 ports on localhost: vlc -I lua --lua-intf telnet --lua-config "telnet={hosts={'localhost:4212','localhost:5678','*console'}}" Configuration options setable throught the --lua-config option are: * hosts: A list of hosts to listen on (see examples above). * host: A host to listen on. (won't be used if `hosts' is set) * password: The password used for remote clients. * prompt: The prompt. ]============================================================================] require "host" --[[ Some telnet command special characters ]] WILL = "\251" -- Indicates the desire to begin performing, or confirmation that you are now performing, the indicated option. WONT = "\252" -- Indicates the refusal to perform, or continue performing, the indicated option. DO = "\253" -- Indicates the request that the other party perform, or confirmation that you are expecting the other party to perform, the indicated option. DONT = "\254" -- Indicates the demand that the other party stop performing, or confirmation that you are no longer expecting the other party to perform, the indicated option. IAC = "\255" -- Interpret as command ECHO = "\001" --[[ Client status change callbacks ]] function on_password( client ) if client.type == host.client_type.net then client:send( "Password: " ..IAC..WILL..ECHO ) else -- no authentification needed on stdin client:switch_status( host.status.read ) end end function on_read( client ) client:send( config.prompt and tostring(config.prompt) or "> " ) end function on_write( client ) end --[[ Misc functions ]] function telnet_commands( client ) -- remove telnet command replies from the client's data client.buffer = string.gsub( client.buffer, IAC.."["..DO..DONT..WILL..WONT.."].", "" ) end function vlm_message_to_string(client,message,prefix) local prefix = prefix or "" if message.value then client:append(prefix .. message.name .. " : " .. message.value) return else client:append(prefix .. message.name) if message.children then for i,c in ipairs(message.children) do vlm_message_to_string(client,c,prefix.." ") end end return end end --[[ Configure the host ]] h = host.host() h.status_callbacks[host.status.password] = on_password h.status_callbacks[host.status.read] = on_read h.status_callbacks[host.status.write] = on_write h:listen( config.hosts or config.host or "localhost:4212" ) password = config.password or "admin" --[[ Launch vlm ]] vlm = vlc.vlm() --[[ Commands ]] function shutdown(client) h:broadcast("Shutting down.\r\n") vlc.msg.err("shutdown requested") vlc.misc.quit() return true end function logout(client) client:del() return true end function quit(client) if client.type == host.client_type.net then return logout(client) else return shutdown(client) end end function lock(client) client:send("\r\n") client:switch_status( host.status.password ) client.buffer = "" return false end function print_text(text) return function(client) client:append(string.gsub(text,"\r?\n","\r\n")) return true end end function help(client) client:append(" Telnet Specific Commands:") for c,t in pairs(commands) do client:append(" "..c.." : "..t.help) end return true end commands = { ["shutdown"] = { func = shutdown, help = "shutdown VLC" }, ["quit"] = { func = quit, help = "logout from telnet/shutdown VLC from local shell" }, ["logout"] = { func = logout, help = "logout" }, ["lock"] = { func = lock, help = "lock the telnet prompt" }, ["description"] = { func = print_text(description), help = "describe this module" }, ["license"] = { func = print_text(vlc.misc.license()), help = "print VLC's license message" }, ["help"] = { func = help, help = "show this help", dovlm = true }, } function client_command( client ) local cmd = client.buffer client.buffer = "" if not commands[cmd] or not commands[cmd].func or commands[cmd].dovlm then -- if it's not an interface specific command, it has to be a VLM command local message, vlc_err = vlm:execute_command( cmd ) vlm_message_to_string( client, message ) if not commands[cmd] or not commands[cmd].func and not commands[cmd].dovlm then if vlc_err ~= 0 then client:append( "Type `help' for help." ) end return true end end ok, msg = pcall( commands[cmd].func, client ) if not ok then client:append( "Error in `"..cmd.."' "..msg ) return true end return msg end --[[ The main loop ]] while not vlc.misc.should_die() do h:accept() local w, r = h:select( 0.1 ) -- Handle writes for _, client in pairs(w) do local len = client:send() client.buffer = string.sub(client.buffer,len+1) if client.buffer == "" then client:switch_status( host.status.read ) end end -- Handle reads for _, client in pairs(r) do local str = client:recv(1000) local done = false if string.match(str,"\n$") then client.buffer = string.gsub(client.buffer..str,"\r?\n$","") done = true elseif client.buffer == "" and ((client.type == host.client_type.stdio and str == "") or (client.type == host.client_type.net and str == "\004")) then -- Caught a ^D client.buffer = "quit" done = true else client.buffer = client.buffer .. str end if client.type == host.client_type.net then telnet_commands( client ) end if done then if client.status == host.status.password then if client.buffer == password then client:send( IAC..WONT..ECHO.."\r\nWelcome, Master\r\n" ) client.buffer = "" client:switch_status( host.status.write ) else client:send( "\r\nWrong password\r\nPassword: " ) client.buffer = "" end elseif client_command( client ) then client:switch_status( host.status.write ) end end end end --[[ Clean up ]] vlm = nil
gpl-2.0
dismantl/luci-0.12
modules/admin-full/luasrc/controller/admin/index.lua
79
1245
--[[ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth <steven@midlink.org> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 $Id$ ]]-- module("luci.controller.admin.index", package.seeall) function index() local root = node() if not root.target then root.target = alias("admin") root.index = true end local page = node("admin") page.target = firstchild() page.title = _("Administration") page.order = 10 page.sysauth = "root" page.sysauth_authenticator = "htmlauth" page.ucidata = true page.index = true -- Empty services menu to be populated by addons entry({"admin", "services"}, firstchild(), _("Services"), 40).index = true entry({"admin", "logout"}, call("action_logout"), _("Logout"), 90) end function action_logout() local dsp = require "luci.dispatcher" local sauth = require "luci.sauth" if dsp.context.authsession then sauth.kill(dsp.context.authsession) dsp.context.urltoken.stok = nil end luci.http.header("Set-Cookie", "sysauth=; path=" .. dsp.build_url()) luci.http.redirect(luci.dispatcher.build_url()) end
apache-2.0
Noltari/luci
applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/olsrd.lua
30
1473
-- Copyright 2011 Manuel Munz <freifunk at somakoma dot de> -- Licensed to the public under the Apache License 2.0. m = Map("luci_statistics", translate("OLSRd Plugin Configuration"), translate("The OLSRd plugin reads information about meshed networks from the txtinfo plugin of OLSRd.")) s = m:section(NamedSection, "collectd_olsrd", "luci_statistics" ) enable = s:option(Flag, "enable", translate("Enable this plugin")) enable.default = 0 host = s:option(Value, "Host", translate("Host"), translate("IP or hostname where to get the txtinfo output from")) host.placeholder = "127.0.0.1" host.datatype = "host(1)" host.rmempty = true port = s:option(Value, "Port", translate("Port")) port.placeholder = "2006" port.datatype = "range(0,65535)" port.rmempty = true port.cast = "string" cl = s:option(ListValue, "CollectLinks", translate("CollectLinks"), translate("Specifies what information to collect about links.")) cl:value("No") cl:value("Summary") cl:value("Detail") cl.default = "Detail" cr = s:option(ListValue, "CollectRoutes", translate("CollectRoutes"), translate("Specifies what information to collect about routes.")) cr:value("No") cr:value("Summary") cr:value("Detail") cr.default = "Summary" ct = s:option(ListValue, "CollectTopology", translate("CollectTopology"), translate("Specifies what information to collect about the global topology.")) ct:value("No") ct:value("Summary") ct:value("Detail") ct.default = "Summary" return m
apache-2.0
LaFamiglia/Illarion-Content
triggerfield/cistern_ambient.lua
1
10245
--[[ Illarion Server This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. ]] -- triggerfields for better atmosphere --[[ SQL Statements: INSERT INTO triggerfields VALUES (X,Y,Z,'triggerfield.cistern'); ]] local common = require("base.common") local ambient_base = require("triggerfield.base.ambient") local M = {} --[[ position: coordinates direction: array with directions, 0=North,2=East,4=South,6=West. Set nil for always german/english: text hours: array with hours when text shall be shown, in range of 0 to 23. Set to nil for always. months: array with months when text shall be shown, in range of 1 to 16. Set to nil for always. chance: Chance that this triggerfield is triggered in percent (integer) for script: cisternList.add( position(x,y,z), {0,1,7}, "german", "english", {0,1,23}, {1,2,16}, chance ); for db: INSERT INTO triggerfields VALUES (840,848,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (823,832,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (822,832,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (821,832,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (820,832,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (838,836,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (847,844,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (837,840,-3,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (832,831,-3,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (839,823,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (355,471,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (354,471,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (360,464,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (360,465,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (368,471,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (368,470,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (382,482,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (105,580,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (114,583,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (115,560,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (135,556,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (105,563,-6,'triggerfield.cistern_ambient'); INSERT INTO triggerfields VALUES (113,570,-6,'triggerfield.cistern_ambient'); ]] local cisternList = ambient_base() --cistern_dungeon triggers using Ambient.lua as a guide cisternList.add( position(840,848,-6),nil,"Die Brücke knarrt laut und unheilvoll während du darüber läufst.","The bridge creaks ominously and loud as you walk over it.",nil,nil,30); --cistern_dungeon_-6 cisternList.add( position(823,832,-6),nil,"Du hörst das Trippeln vieler kleiner Füsse, als du um die Ecke gehst.","You hear the scurrying of lots of little feet as you round the corner.",nil,nil,30); --cistern_dungeon_-6 cisternList.add( position(822,832,-6),nil,"Du hörst das Trippeln vieler kleiner Füsse, als du um die Ecke gehst.","You hear the scurrying of lots of little feet as you round the corner.",nil,nil,30); --cistern_dungeon_-6 cisternList.add( position(821,832,-6),nil,"Du hörst das Trippeln vieler kleiner Füsse, als du um die Ecke gehst.","You hear the scurrying of lots of little feet as you round the corner.",nil,nil,30); --cistern_dungeon_-6 cisternList.add( position(820,832,-6),nil,"Du hörst das Trippeln vieler kleiner Füsse, als du um die Ecke gehst.","You hear the scurrying of lots of little feet as you round the corner.",nil,nil,30); --cistern_dungeon_-6 cisternList.add( position(838,836,-6),nil,"Da ist ein lautes Krachen als du versuchst durch einen Engen Platz zu gehen. Als du rüber schaust, wirst du wohl viele Paare leuchtender Augen entdecken, die von den Stalagmiten und Steinen zu dir rüberschauen","There's a loud crash as you are trying to get through a tight space, as you look over, you see many sets of glowing eyes looking at you from within the stalagmites and rocks.",nil,nil,30); --cistern_dungeon_-6 cisternList.add( position(847,844,-6),nil,"Als du über den Stein wischt, erreicht dich eine Klaue von irgendwoher versteckt dahinter und kratzt herüber zu deiner Hand. Glücklicherweise berührt sie dich kaum dabei.","As you brush past the rock, a claw reaches out from somewhere hidden behind it and scratches across your hand, thankfully, barely touching you.",nil,nil,30); --cistern_dungeon_-6 cisternList.add( position(837,840,-3),nil,"Eine Bohle bricht, dein Fuß schlittert durch ein Loch ins Wasser und den Schlamm darunter.","A board cracks, breaking apart, your foot slips through the hole, slamming down into the water and mud below.",nil,nil,30); --cistern_dungeon_-3 cisternList.add( position(832,831,-3),nil,"Auf dem riesigen felsigen Pfeiler über dir hörst du ein Geräusch. Als du hochschaust siehst du wie eine riesige Ratte über deinen Kopf springt auf einem Stalagmiten landet und in die Dunkelheit davon huscht.","You hear something over your head atop the rocky mountainous pile. As you look up, you see a huge rat fling itself over your head and land on a stalagmite and scurry away into the dark.",nil,nil,30); --cistern_dungeon_-3 cisternList.add( position(839,823,-6),nil,"Ein seltsamer Geruch verpestet die Luft, als du dich umschaust, siehst du, dass jemand den Kadaver einer Ratte in das Feuer geworfen hat.","A strange smell permeates the air, looking around, you can see someone has thrown the carcass of a rat on the fire.",nil,nil,30); --cistern_dungeon_-6 --cistern_storage triggers using Ambient.lua as a guide cisternList.add( position(355,471,-6),nil,"Du hörst etwas über deinem Kopf, als du hochschaust siehst du wie sich eine riesige Ratte über deinen Kopf katapultiert, auf einem Stalagmiten landet und in die Dunkelheit davon huscht.","You hear something over your head. As you look up, you see a huge rat fling itself over your head and land on a stalagmite and scurry away into the dark.",nil,nil,30); --cistern_storage cisternList.add( position(354,471,-6),nil,"Du hörst etwas über deinem Kopf, als du hochschaust siehst du wie sich eine riesige Ratte über deinen Kopf katapultiert, auf einem Stalagmiten landet und in die Dunkelheit davon huscht.","You hear something over your head. As you look up, you see a huge rat fling itself over your head and land on a stalagmite and scurry away into the dark.",nil,nil,30); --cistern_storage cisternList.add( position(360,464,-6),nil,"Als du durch die Tür schaust, hörst du ein Scharren auf der anderen Seite.","As you look through the door, you hear lots of scrabbling on the other side.",nil,nil,30); --cistern_storage cisternList.add( position(360,465,-6),nil,"Als du durch die Tür schaust, hörst du ein Scharren auf der anderen Seite.","As you look through the door, you hear lots of scrabbling on the other side.",nil,nil,30); --cistern_storage cisternList.add( position(368,471,-6),nil,"Die Brücke knarrt laut und unheilvoll während du darüber läufst.","The bridge creaks ominously and loud as you walk over it.",nil,nil,30); --cistern_storage cisternList.add( position(368,470,-6),nil,"Die Brücke knarrt laut und unheilvoll während du darüber läufst.","The bridge creaks ominously and loud as you walk over it.",nil,nil,30); --cistern_storage cisternList.add( position(382,482,-6),nil,"Eine Riesige Kanalratte springt überraschend hinter dem großen glühendem Pilz hervor und erschreckt dich.","A giant sewer rat jumps out from behind the huge glowing mushroom, startling the unprepared mind.",nil,nil,30); --cistern_storage -- cistern_cave triggers using Ambient.lua as a guide cisternList.add( position(105,580,-6),nil,"Wenn Du dich umsiehst erkennst Du, das alle möglichen Dinge herumgeschleppt und in Haufen gelagert worden.","As you look around, you can see where things have been carried off and stored in little piles all around.",nil,nil,30); --cistern_cave cisternList.add( position(114,583,-6),nil,"Wenn Du dich umsiehst erkennst Du, das alle möglichen Dinge herumgeschleppt und in Haufen gelagert worden.","As you look around, you can see where things have been carried off and stored in little piles all around.",nil,nil,30); --cistern_cave cisternList.add( position(115,560,-6),nil,"Ein strenger Geruch liegt in der Luft. Beim Umsehen erkennst Du, das jemand einen Rattenkadaver ins Feuer geworfen hat.","A strange smell permeates the air, looking around, you can see someone has thrown the carcass of a rat on the fire.",nil,nil,30); --cistern_cave cisternList.add( position(135,556,-6),nil,"Ein strenger Geruch liegt in der Luft. Beim Umsehen erkennst Du, das jemand einen Rattenkadaver ins Feuer geworfen hat.","A strange smell permeates the air, looking around, you can see someone has thrown the carcass of a rat on the fire.",nil,nil,30); --cistern_cave cisternList.add( position(105,563,-6),nil,"Die Brücke knarrt laut und unheilvoll während du darüber läufst.","The bridge creaks ominously and loud as you walk over it.",nil,nil,30); --cistern_cave cisternList.add( position(113,570,-6),nil,"Eine Riesige Kanalratte springt überraschend hinter dem großen glühendem Pilz hervor und erschreckt dich.","A giant sewer rat jumps out from behind the huge glowing mushroom, startling the unprepared mind.",nil,nil,30); --cistern_cave function M.MoveToField(Char) local this = cisternList.get(Char) if this then common.InformNLS(Char, this.german, this.english) end end return M
agpl-3.0
ramindel0761/setdelete
bot/utils.lua
1
22551
--Begin Utils.lua By #deleteTeam :) local clock = os.clock function sleep(time) -- seconds local t0 = clock() while clock() - t0 <= time do end end function var_cb(msg, data) -------------Get Var------------ bot = {} msg.to = {} msg.from = {} msg.media = {} msg.id = msg.id_ msg.to.type = gp_type(data.chat_id_) if data.content_.caption_ then msg.media.caption = data.content_.caption_ end if data.reply_to_message_id_ ~= 0 then msg.reply_id = data.reply_to_message_id_ else msg.reply_id = false end function get_gp(arg, data) if gp_type(msg.chat_id_) == "channel" or gp_type(msg.chat_id_) == "chat" then msg.to.id = msg.chat_id_ msg.to.title = data.title_ else msg.to.id = msg.chat_id_ msg.to.title = false end end tdcli_function ({ ID = "GetChat", chat_id_ = data.chat_id_ }, get_gp, nil) function botifo_cb(arg, data) bot.id = data.id_ our_id = data.id_ if data.username_ then bot.username = data.username_ else bot.username = false end if data.first_name_ then bot.first_name = data.first_name_ end if data.last_name_ then bot.last_name = data.last_name_ else bot.last_name = false end if data.first_name_ and data.last_name_ then bot.print_name = data.first_name_..' '..data.last_name_ else bot.print_name = data.first_name_ end if data.phone_number_ then bot.phone = data.phone_number_ else bot.phone = false end end tdcli_function({ ID = 'GetMe'}, botifo_cb, {chat_id=msg.chat_id_}) function get_user(arg, data) msg.from.id = data.id_ if data.username_ then msg.from.username = data.username_ else msg.from.username = false end if data.first_name_ then msg.from.first_name = data.first_name_ end if data.last_name_ then msg.from.last_name = data.last_name_ else msg.from.last_name = false end if data.first_name_ and data.last_name_ then msg.from.print_name = data.first_name_..' '..data.last_name_ else msg.from.print_name = data.first_name_ end if data.phone_number_ then msg.from.phone = data.phone_number_ else msg.from.phone = false end match_plugins(msg) end tdcli_function ({ ID = "GetUser", user_id_ = data.sender_user_id_ }, get_user, nil) -------------End------------- end function set_config(msg) local function config_cb(arg, data) local hash = "gp_lang:"..msg.to.id local lang = redis:get(hash) --print(serpent.block(data)) for k,v in pairs(data.members_) do local function config_mods(arg, data) local administration = load_data(_config.moderation.data) if data.username_ then user_name = '@'..check_markdown(data.username_) else user_name = check_markdown(data.first_name_) end administration[tostring(msg.to.id)]['mods'][tostring(data.id_)] = user_name save_data(_config.moderation.data, administration) end tdcli_function ({ ID = "GetUser", user_id_ = v.user_id_ }, config_mods, {user_id=v.user_id_}) if data.members_[k].status_.ID == "ChatMemberStatusCreator" then owner_id = v.user_id_ local function config_owner(arg, data) -- print(serpent.block(data)) local administration = load_data(_config.moderation.data) if data.username_ then user_name = '@'..check_markdown(data.username_) else user_name = check_markdown(data.first_name_) end administration[tostring(msg.to.id)]['owners'][tostring(data.id_)] = user_name save_data(_config.moderation.data, administration) end tdcli_function ({ ID = "GetUser", user_id_ = owner_id }, config_owner, {user_id=owner_id}) end end if not lang then return tdcli.sendMessage(msg.to.id, msg.id, 0, "_All group admins has been promoted and group creator is now group owner_", 0, "md") else return tdcli.sendMessage(msg.to.id, msg.id, 0, "_تمام ادمین های گروه به مقام مدیر منتصب شدند و سازنده گروه به مقام مالک گروه منتصب شد_", 0, "md") end end tdcli.getChannelMembers(msg.to.id, 0, 'Administrators', 200, config_cb, {chat_id=msg.to.id}) end function serialize_to_file(data, file, uglify) file = io.open(file, 'w+') local serialized if not uglify then serialized = serpent.block(data, { comment = false, name = '_' }) else serialized = serpent.dump(data) end file:write(serialized) file:close() end function string.random(length) local str = ""; for i = 1, length do math.random(97, 122) str = str..string.char(math.random(97, 122)); end return str; end function string:split(sep) local sep, fields = sep or ":", {} local pattern = string.format("([^%s]+)", sep) self:gsub(pattern, function(c) fields[#fields+1] = c end) return fields end -- DEPRECATED function string.trim(s) print("string.trim(s) is DEPRECATED use string:trim() instead") return s:gsub("^%s*(.-)%s*$", "%1") end -- Removes spaces function string:trim() return self:gsub("^%s*(.-)%s*$", "%1") end function get_http_file_name(url, headers) -- Eg: foo.var local file_name = url:match("[^%w]+([%.%w]+)$") -- Any delimited alphanumeric on the url file_name = file_name or url:match("[^%w]+(%w+)[^%w]+$") -- Random name, hope content-type works file_name = file_name or str:random(5) local content_type = headers["content-type"] local extension = nil if content_type then extension = mimetype.get_mime_extension(content_type) end if extension then file_name = file_name.."."..extension end local disposition = headers["content-disposition"] if disposition then -- checking -- attachment; filename=CodeCogsEqn.png file_name = disposition:match('filename=([^;]+)') or file_name end -- return return file_name end -- Saves file to /tmp/. If file_name isn't provided, -- will get the text after the last "/" for filename -- do ski msg_caption = '\n#'..string.reverse("INARI.RM") -- Waiting for ski:) -- and content-type for extension function download_to_file(url, file_name) -- print to server -- print("url to download: "..url) -- uncomment if needed local respbody = {} local options = { url = url, sink = ltn12.sink.table(respbody), redirect = true } -- nil, code, headers, status local response = nil if url:starts('https') then options.redirect = false response = {https.request(options)} else response = {http.request(options)} end local code = response[2] local headers = response[3] local status = response[4] if code ~= 200 then return nil end file_name = file_name or get_http_file_name(url, headers) local file_path = "data/"..file_name -- print("Saved to: "..file_path) -- uncomment if needed file = io.open(file_path, "w+") file:write(table.concat(respbody)) file:close() return file_path end function run_command(str) local cmd = io.popen(str) local result = cmd:read('*all') cmd:close() return result end function string:isempty() return self == nil or self == '' end -- Returns true if the string is blank function string:isblank() self = self:trim() return self:isempty() end -- DEPRECATED!!!!! function string.starts(String, Start) -- print("string.starts(String, Start) is DEPRECATED use string:starts(text) instead") -- uncomment if needed return Start == string.sub(String,1,string.len(Start)) end -- Returns true if String starts with Start function string:starts(text) return text == string.sub(self,1,string.len(text)) end function unescape_html(str) local map = { ["lt"] = "<", ["gt"] = ">", ["amp"] = "&", ["quot"] = '"', ["apos"] = "'" } new = string.gsub(str, '(&(#?x?)([%d%a]+);)', function(orig, n, s) var = map[s] or n == "#" and string.char(s) var = var or n == "#x" and string.char(tonumber(s,16)) var = var or orig return var end) return new end function pairsByKeys (t, f) local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f) local i = 0 -- iterator variable local iter = function () -- iterator function i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iter end function run_bash(str) local cmd = io.popen(str) local result = cmd:read('*all') return result end function scandir(directory) local i, t, popen = 0, {}, io.popen for filename in popen('ls -a "'..directory..'"'):lines() do i = i + 1 t[i] = filename end return t end function plugins_names( ) local files = {} for k, v in pairs(scandir("plugins")) do -- Ends with .lua if (v:match(".lua$")) then table.insert(files, v) end end return files end -- Function name explains what it does. function file_exists(name) local f = io.open(name,"r") if f ~= nil then io.close(f) return true else return false end end function gp_type(chat_id) local gp_type = "pv" local id = tostring(chat_id) if id:match("^-100") then gp_type = "channel" elseif id:match("-") then gp_type = "chat" end return gp_type end function is_reply(msg) local var = false if msg.reply_to_message_id_ ~= 0 then -- reply message id is not 0 var = true end return var end function is_supergroup(msg) chat_id = tostring(msg.chat_id_) if chat_id:match('^-100') then --supergroups and channels start with -100 if not msg.is_post_ then return true end else return false end end function is_channel(msg) chat_id = tostring(msg.chat_id_) if chat_id:match('^-100') then -- Start with -100 (like channels and supergroups) if msg.is_post_ then -- message is a channel post return true else return false end end end function is_group(msg) chat_id = tostring(msg.chat_id_) if chat_id:match('^-100') then --not start with -100 (normal groups does not have -100 in first) return false elseif chat_id:match('^-') then return true else return false end end function is_private(msg) chat_id = tostring(msg.chat_id_) if chat_id:match('^-') then --private chat does not start with - return false else return true end end function check_markdown(text) --markdown escape ( when you need to escape markdown , use it like : check_markdown('your text') str = text if str:match('_') then output = str:gsub('_',[[\_]]) elseif str:match('*') then output = str:gsub('*','\\*') elseif str:match('`') then output = str:gsub('`','\\`') else output = str end return output end function is_sudo(msg) local var = false -- Check users id in config for v,user in pairs(_config.sudo_users) do if user == msg.sender_user_id_ then var = true end end return var end function is_owner(msg) local var = false local data = load_data(_config.moderation.data) local user = msg.sender_user_id_ if data[tostring(msg.chat_id_)] then if data[tostring(msg.chat_id_)]['owners'] then if data[tostring(msg.chat_id_)]['owners'][tostring(msg.sender_user_id_)] then var = true end end end for v,user in pairs(_config.admins) do if user[1] == msg.sender_user_id_ then var = true end end for v,user in pairs(_config.sudo_users) do if user == msg.sender_user_id_ then var = true end end return var end function is_admin(msg) local var = false local user = msg.sender_user_id_ for v,user in pairs(_config.admins) do if user[1] == msg.sender_user_id_ then var = true end end for v,user in pairs(_config.sudo_users) do if user == msg.sender_user_id_ then var = true end end return var end --Check if user is the mod of that group or not function is_mod(msg) local var = false local data = load_data(_config.moderation.data) local usert = msg.sender_user_id_ if data[tostring(msg.chat_id_)] then if data[tostring(msg.chat_id_)]['mods'] then if data[tostring(msg.chat_id_)]['mods'][tostring(msg.sender_user_id_)] then var = true end end end if data[tostring(msg.chat_id_)] then if data[tostring(msg.chat_id_)]['owners'] then if data[tostring(msg.chat_id_)]['owners'][tostring(msg.sender_user_id_)] then var = true end end end for v,user in pairs(_config.admins) do if user[1] == msg.sender_user_id_ then var = true end end for v,user in pairs(_config.sudo_users) do if user == msg.sender_user_id_ then var = true end end return var end function is_sudo1(user_id) local var = false -- Check users id in config for v,user in pairs(_config.sudo_users) do if user == user_id then var = true end end return var end function is_owner1(chat_id, user_id) local var = false local data = load_data(_config.moderation.data) local user = user_id if data[tostring(chat_id)] then if data[tostring(chat_id)]['owners'] then if data[tostring(chat_id)]['owners'][tostring(user)] then var = true end end end for v,user in pairs(_config.admins) do if user[1] == user_id then var = true end end for v,user in pairs(_config.sudo_users) do if user == user_id then var = true end end return var end function is_admin1(user_id) local var = false local user = user_id for v,user in pairs(_config.admins) do if user[1] == user_id then var = true end end for v,user in pairs(_config.sudo_users) do if user == user_id then var = true end end return var end --Check if user is the mod of that group or not function is_mod1(chat_id, user_id) local var = false local data = load_data(_config.moderation.data) local usert = user_id if data[tostring(chat_id)] then if data[tostring(chat_id)]['mods'] then if data[tostring(chat_id)]['mods'][tostring(usert)] then var = true end end end if data[tostring(chat_id)] then if data[tostring(chat_id)]['owners'] then if data[tostring(chat_id)]['owners'][tostring(usert)] then var = true end end end for v,user in pairs(_config.admins) do if user[1] == user_id then var = true end end for v,user in pairs(_config.sudo_users) do if user == user_id then var = true end end return var end -- Check if user can use the plugin and warns user -- Returns true if user was warned and false if not warned (is allowed) function warns_user_not_allowed(plugin, msg) if not user_allowed(plugin, msg) then local text = '*This plugin requires privileged user*' local receiver = msg.chat_id_ tdcli.sendMessage(msg.chat_id_, "", 0, result, 0, "md") return true else return false end end -- Check if user can use the plugin function user_allowed(plugin, msg) if plugin.privileged and not is_sudo(msg) then return false end return true end function is_banned(user_id, chat_id) local var = false local data = load_data(_config.moderation.data) if data[tostring(chat_id)] then if data[tostring(chat_id)]['banned'] then if data[tostring(chat_id)]['banned'][tostring(user_id)] then var = true end end end return var end function is_silent_user(user_id, chat_id) local var = false local data = load_data(_config.moderation.data) if data[tostring(chat_id)] then if data[tostring(chat_id)]['is_silent_users'] then if data[tostring(chat_id)]['is_silent_users'][tostring(user_id)] then var = true end end end return var end function is_whitelist(user_id, chat_id) local var = false local data = load_data(_config.moderation.data) if data[tostring(chat_id)] then if data[tostring(chat_id)]['whitelist'] then if data[tostring(chat_id)]['whitelist'][tostring(user_id)] then var = true end end end return var end function is_gbanned(user_id) local var = false local data = load_data(_config.moderation.data) local user = user_id local gban_users = 'gban_users' if data[tostring(gban_users)] then if data[tostring(gban_users)][tostring(user)] then var = true end end return var end function is_filter(msg, text) local var = false local data = load_data(_config.moderation.data) if data[tostring(msg.chat_id_)]['filterlist'] then for k,v in pairs(data[tostring(msg.chat_id_)]['filterlist']) do if string.find(string.lower(text), string.lower(k)) then var = true end end end return var end function kick_user(user_id, chat_id) if not tonumber(user_id) then return false end tdcli.changeChatMemberStatus(chat_id, user_id, 'Kicked', dl_cb, nil) end function del_msg(chat_id, message_ids) local msgid = {[0] = message_ids} tdcli.deleteMessages(chat_id, msgid, dl_cb, nil) end function channel_unblock(chat_id, user_id) tdcli.changeChatMemberStatus(chat_id, user_id, 'Left', dl_cb, nil) end function channel_set_admin(chat_id, user_id) tdcli.changeChatMemberStatus(chat_id, user_id, 'Editor', dl_cb, nil) end function channel_set_mod(chat_id, user_id) tdcli.changeChatMemberStatus(chat_id, user_id, 'Moderator', dl_cb, nil) end function channel_demote(chat_id, user_id) tdcli.changeChatMemberStatus(chat_id, user_id, 'Member', dl_cb, nil) end function file_dl(file_id) tdcli.downloadFile(file_id, dl_cb, nil) end function banned_list(chat_id) local hash = "gp_lang:"..chat_id local lang = redis:get(hash) local data = load_data(_config.moderation.data) local i = 1 if not data[tostring(chat_id)] then if not lang then return '_Group is not added_' else return 'گروه به لیست گروه های مدیریتی ربات اضافه نشده است' end end -- determine if table is empty if next(data[tostring(chat_id)]['banned']) == nil then --fix way if not lang then return "_No_ *banned* _users in this group_" else return "*هیچ کاربری از این گروه محروم نشده*" end end if not lang then message = '*List of banned users :*\n' else message = '_لیست کاربران محروم شده از گروه :_\n' end for k,v in pairs(data[tostring(chat_id)]['banned']) do message = message ..i.. '- '..v..' [' ..k.. '] \n' i = i + 1 end return message end function silent_users_list(chat_id) local hash = "gp_lang:"..chat_id local lang = redis:get(hash) local data = load_data(_config.moderation.data) local i = 1 if not data[tostring(chat_id)] then if not lang then return '_Group is not added_' else return 'گروه به لیست گروه های مدیریتی ربات اضافه نشده است' end end -- determine if table is empty if next(data[tostring(chat_id)]['is_silent_users']) == nil then --fix way if not lang then return "_No_ *silent* _users in this group_" else return "*لیست کاربران سایلنت شده خالی است*" end end if not lang then message = '*List of silent users :*\n' else message = '_لیست کاربران سایلنت شده :_\n' end for k,v in pairs(data[tostring(chat_id)]['is_silent_users']) do message = message ..i.. '- '..v..' [' ..k.. '] \n' i = i + 1 end return message end function whitelist(chat_id) local hash = "gp_lang:"..chat_id local lang = redis:get(hash) local data = load_data(_config.moderation.data) local i = 1 if not data[tostring(chat_id)] then if not lang then return '_Group is not added_' else return 'گروه به لیست گروه های مدیریتی ربات اضافه نشده است' end end if not data[tostring(chat_id)]['whitelist'] then data[tostring(chat_id)]['whitelist'] = {} save_data(_config.moderation.data, data) end -- determine if table is empty if next(data[tostring(chat_id)]['whitelist']) == nil then --fix way if not lang then return "_No_ *users* _in white list_" else return "*هیچ کاربری در لیست سفید وجود ندارد*" end end if not lang then message = '*Users of white list :*\n' else message = '_کاربران لیست سفید :_\n' end for k,v in pairs(data[tostring(chat_id)]['whitelist']) do message = message ..i.. '- '..v..' [' ..k.. '] \n' i = i + 1 end return message end function gbanned_list(msg) local hash = "gp_lang:"..msg.chat_id_ local lang = redis:get(hash) local data = load_data(_config.moderation.data) local i = 1 if not data['gban_users'] then data['gban_users'] = {} save_data(_config.moderation.data, data) end if next(data['gban_users']) == nil then --fix way if not lang then return "_No_ *globally banned* _users available_" else return "*هیچ کاربری از گروه های ربات محروم نشده*" end end if not lang then message = '*List of globally banned users :*\n' else message = '_لیست کاربران محروم شده از گروه های ربات :_\n' end for k,v in pairs(data['gban_users']) do message = message ..i.. '- '..v..' [' ..k.. '] \n' i = i + 1 end return message end function filter_list(msg) local hash = "gp_lang:"..msg.chat_id_ local lang = redis:get(hash) local data = load_data(_config.moderation.data) if not data[tostring(msg.chat_id_)]['filterlist'] then data[tostring(msg.chat_id_)]['filterlist'] = {} save_data(_config.moderation.data, data) end if not data[tostring(msg.chat_id_)] then if not lang then return '_Group is not added_' else return 'گروه به لیست گروه های مدیریتی ربات اضافه نشده است' end end -- determine if table is empty if next(data[tostring(msg.chat_id_)]['filterlist']) == nil then --fix way if not lang then return "*Filtered words list* _is empty_" else return "_لیست کلمات فیلتر شده خالی است_" end end if not data[tostring(msg.chat_id_)]['filterlist'] then data[tostring(msg.chat_id_)]['filterlist'] = {} save_data(_config.moderation.data, data) end if not lang then filterlist = '*List of filtered words :*\n' else filterlist = '_لیست کلمات فیلتر شده :_\n' end local i = 1 for k,v in pairs(data[tostring(msg.chat_id_)]['filterlist']) do filterlist = filterlist..'*'..i..'* - _'..check_markdown(k)..'_\n' i = i + 1 end return filterlist end
gpl-3.0