Python1320

Untitled

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