Python1320

Untitled

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