Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if alan.socket then alan.socket = nil end
- do
- module("alan")
- require("oosocks")
- cookies = {}
- answer = ""
- name = "Alan"
- pending = {}
- 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()
- Connect()
- local index = table.insert(
- pending,
- socket:Send(
- Format(
- [[GET %s HTTP/1.1
- Host: www.a-i.com
- ]],
- AlanURL()
- )
- )
- )
- socket:ReceiveLine()
- return index
- end
- function SendQuestion(player, text)
- local text = URLEscape(text)
- Connect()
- socket:Send(
- Format(
- [[GET %s&question=%s HTTP/1.1
- Host: www.a-i.com
- Cookie: %s]],
- AlanURL(),
- text,
- cookie
- )
- )
- end
- function URLEscape(s)
- return string.gsub(s, "([^A-Za-z0-9_])", function(c)
- return string.format("%%%02x", string.byte(c))
- 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 HasAnswer(data)
- return data:Left(16) == "<option>answer ="
- end
- function GetAnswer(data)
- local answer = data:sub(17, -1):Trim()
- return answer
- end
- 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
- print(GetCookie(data))
- end
- if HasAnswer(data) then
- print(GetAnswer(data))
- end
- socket:ReceiveLine()
- end
- end)
- end
- print(alan.GetCookieID())
Advertisement
Add Comment
Please, Sign In to add comment