Python1320

Untitled

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