Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if alan and alan.socket then alan.socket = nil end
- 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, force)
- if not force and cookies[uniqueid] then callback(cookies[uniqueid]) return end
- local socket = OOSock(IPPROTO_TCP)
- socket:Connect("www.a-i.com", 80)
- socket:Send(
- Format(
- [[GET %s HTTP/1.1
- Host: www.a-i.com
- ]],
- AlanURL()
- )
- )
- 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, cookie)
- if not cookies[uniqueid] then return end
- pending_answers[uniqueid] = callback
- Connect()
- socket:Send(
- Format(
- [[GET %s&question=%s HTTP/1.1
- Host: www.a-i.com
- Cookie: %s
- ]],
- AlanURL(),
- URLEscape(question),
- (cookie and URLEscape()) or URLEscape(cookies[uniqueid])
- )
- )
- file.Write("testestst.txt", Format(
- [[GET %s&question=%s HTTP/1.1
- Host: www.a-i.com
- Cookie: %s
- ]],
- AlanURL(),
- URLEscape(question),
- cookie or cookies[uniqueid]
- ))
- 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 cookie_found and IsAnswer(data) and pending_answers[cookie_found] then
- pending_answers[cookie_found](GetAnswer(data))
- 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(13, -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", "hey", print)
- end)
Advertisement
Add Comment
Please, Sign In to add comment