Python1320

Untitled

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