Python1320

Untitled

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