Python1320

Untitled

Oct 25th, 2010
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.25 KB | None | 0 0
  1. do
  2.  
  3.     module("alan", package.seeall)
  4.  
  5.     require("oosocks")
  6.  
  7.     cookies = {}
  8.     answer = ""
  9.     name = "Alan"
  10.     pending_answers = {}
  11.  
  12.     socket = OOSock(IPPROTO_TCP)
  13.  
  14.     function AlanURL()
  15.         return Format("/alan1/webface1_ctrl.asp?gender=male&style=%s&name=%s&action0=name:%s&DName=%s", URLEscape(name), URLEscape(name), URLEscape(name), URLEscape(name))
  16.     end
  17.  
  18.     function Connect()
  19.         socket:Connect("www.a-i.com", 80)
  20.     end
  21.  
  22.     function GetCookieID(uniqueid, callback)
  23.    
  24.         if cookies[uniqueid] then callback(cookies[uniqueid]) return end
  25.  
  26.         local socket = OOSock(IPPROTO_TCP)
  27.  
  28.         socket:Connect("www.a-i.com", 80)
  29.  
  30.         socket:SendLine(Format("GET %s HTTP/1.1", AlanURL()))
  31.         socket:SendLine("Host: www.a-i.com")
  32.         socket:SendLine("")
  33.  
  34.         socket:ReceiveLine()
  35.        
  36.         socket:SetCallback(function(socket, callType, callId, err, data, peer, peerPort)
  37.             if callType == SCKCALL_REC_LINE and err == SCKERR_OK and data ~= "" then
  38.                 if IsCookie(data) then
  39.                     cookies[uniqueid] = GetCookie(data)
  40.                     callback(cookies[uniqueid])
  41.                     --print("assigned cookie to", uniqueid, GetCookie(data))
  42.                     socket = nil
  43.                 return end
  44.  
  45.                 socket:ReceiveLine()
  46.  
  47.             end
  48.         end)
  49.  
  50.  
  51.  
  52.     end
  53.  
  54.     function SendQuestion(uniqueid, question, callback)
  55.  
  56.         if not cookies[uniqueid] then return end
  57.  
  58.         pending_answers[uniqueid] = callback
  59.  
  60.         Connect()
  61.  
  62.         socket:SendLine(Format("GET %s&question=%s HTTP/1.1", AlanURL(), URLEscape(question)))
  63.         socket:SendLine("Host: www.a-i.com")
  64.         socket:SendLine(Format("Cookie: ASPSESSIONIDACRQSRQC=%s", cookies[uniqueid]))
  65.         socket:SendLine("")
  66.  
  67.         socket:ReceiveLine()
  68.        
  69.     end
  70.  
  71.     local cookie_found = false
  72.  
  73.     socket:SetCallback(function(socket, callType, callId, err, data, peer, peerPort)
  74.         if callType == SCKCALL_REC_LINE and err == SCKERR_OK and data ~= "" then
  75.             if IsCookie(data) and IsCookieAssigned(GetCookie(data)) then
  76.                 cookie_found = GetUniqueIDFromCookie(GetCookie(data))
  77.             end
  78.  
  79.             --if IsAnswer(data) then print(GetAnswer(data)) end
  80.             --if IsCookie(data) then print(data, GetCookie(data)) end
  81.  
  82.             if cookie_found and IsAnswer(data) and pending_answers[cookie_found] then
  83.                 pending_answers[cookie_found](GetAnswer(data), cookies[cookie_found])
  84.                 pending_answers[cookie_found] = nil
  85.                 cookie_found = false
  86.             return end
  87.  
  88.             socket:ReceiveLine()
  89.         end
  90.     end)
  91.  
  92.     function URLEscape(s)
  93.         return string.gsub(s, "([^A-Za-z0-9_])", function(c)
  94.             return string.format("%%%02x", string.byte(c))
  95.         end)
  96.     end
  97.  
  98.     function IsCookieAssigned(cookie)
  99.         return table.HasValue(cookies, cookie)
  100.     end
  101.  
  102.     function GetUniqueIDFromCookie(cookie)
  103.         for key, value in pairs(cookies) do
  104.             if value == cookie then return key end
  105.         end
  106.     end
  107.  
  108.     function IsCookie(data)
  109.         return data:Left(12) == "Set-Cookie: "
  110.     end
  111.  
  112.     function GetCookie(data)
  113.         return data:sub(34, -10)
  114.     end
  115.  
  116.     function SetCookie(cookie, player)
  117.         cookies[data] = player
  118.     end
  119.  
  120.     function IsAnswer(data)
  121.         return data:Left(16) == "<option>answer ="
  122.     end
  123.  
  124.     function GetAnswer(data)
  125.         local answer = data:sub(17, -1):Trim()
  126.         return answer
  127.     end
  128.  
  129. end
  130.  
  131.  
  132. alan.GetCookieID("caps", function(cookie)
  133.     print(cookie)
  134.     alan.SendQuestion("caps", "hi", function(answer, cookie)
  135.         print(answer, cookie)
  136.         alan.SendQuestion("caps", "what are you doing", print)
  137.     end)
  138. end)
Advertisement
Add Comment
Please, Sign In to add comment