Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do
- module("alan", package.seeall)
- require("oosocks")
- cookies = {}
- answer = ""
- name = "Alan"
- pending_answers = {}
- socket = OOSock(IPPROTO_TCP)
- function AlanURL()
- 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))
- end
- function Connect()
- socket:Connect("www.a-i.com", 80)
- end
- function GetCookieID(uniqueid, callback)
- if cookies[uniqueid] then callback(cookies[uniqueid]) return end
- local socket = OOSock(IPPROTO_TCP)
- socket:Connect("www.a-i.com", 80)
- socket:SendLine(Format("GET %s HTTP/1.1", AlanURL()))
- socket:SendLine("Host: www.a-i.com")
- socket:SendLine("")
- socket:ReceiveLine()
- socket:SetCallback(function(socket, callType, callId, err, data, peer, peerPort)
- if callType == SCKCALL_REC_LINE and err == SCKERR_OK and data ~= "" then
- if IsCookie(data) then
- cookies[uniqueid] = GetCookie(data)
- callback(cookies[uniqueid])
- --print("assigned cookie to", uniqueid, GetCookie(data))
- socket = nil
- return end
- socket:ReceiveLine()
- end
- end)
- end
- function SendQuestion(uniqueid, question, callback)
- if not cookies[uniqueid] then return end
- pending_answers[uniqueid] = callback
- Connect()
- socket:SendLine(Format("GET %s&question=%s HTTP/1.1", AlanURL(), URLEscape(question)))
- socket:SendLine("Host: www.a-i.com")
- socket:SendLine(Format("Cookie: ASPSESSIONIDACRQSRQC=%s", cookies[uniqueid]))
- socket:SendLine("")
- socket:ReceiveLine()
- end
- local cookie_found = false
- socket:SetCallback(function(socket, callType, callId, err, data, peer, peerPort)
- if callType == SCKCALL_REC_LINE and err == SCKERR_OK and data ~= "" then
- if IsCookie(data) and IsCookieAssigned(GetCookie(data)) then
- cookie_found = GetUniqueIDFromCookie(GetCookie(data))
- end
- --if IsAnswer(data) then print(GetAnswer(data)) end
- --if IsCookie(data) then print(data, GetCookie(data)) end
- if cookie_found and IsAnswer(data) and pending_answers[cookie_found] then
- pending_answers[cookie_found](GetAnswer(data), cookies[cookie_found])
- pending_answers[cookie_found] = nil
- cookie_found = false
- return end
- socket:ReceiveLine()
- end
- end)
- function URLEscape(s)
- return string.gsub(s, "([^A-Za-z0-9_])", function(c)
- return string.format("%%%02x", string.byte(c))
- end)
- end
- function IsCookieAssigned(cookie)
- return table.HasValue(cookies, cookie)
- end
- function GetUniqueIDFromCookie(cookie)
- for key, value in pairs(cookies) do
- if value == cookie then return key end
- end
- end
- function IsCookie(data)
- return data:Left(12) == "Set-Cookie: "
- end
- function GetCookie(data)
- return data:sub(34, -10)
- end
- function SetCookie(cookie, player)
- cookies[data] = player
- end
- function IsAnswer(data)
- return data:Left(16) == "<option>answer ="
- end
- function GetAnswer(data)
- local answer = data:sub(17, -1):Trim()
- return answer
- end
- end
- alan.GetCookieID("caps", function(cookie)
- print(cookie)
- alan.SendQuestion("caps", "hi", function(answer, cookie)
- print(answer, cookie)
- alan.SendQuestion("caps", "what are you doing", print)
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment