同步操作将从 呵大官人/fooking 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
--[[fb是fooking buffer, 目前提供size, data, append, seek四个方法fb.size(buffer) 返回buffer长度fb.data(buffer) 返回buffer数据(string)fb.append(buffer, "data") 向buffer追加数据fb.seek(buffer, 10) 设置buffer向后偏移长度,如: buffer数据为abcdef,长度为6, 设置seek(buffer, 2),那么buffer内容为cdef,并且长度为4fc是fooking connection, 目前提供buffer,send两个方法fc.buffer(conn) 返回conn的read buffer, 类型为lightuserdatafc.send(conn, "hello") 向conn发送数据fc.id() 获取客户端session idinput与output处理函数返回三种状态值,小于0, 等于0或大于0小于0: 表示数据包不足,等待下次处理(output如果返回值小于0,则不返回任何数据到客户端)等于0: 表示继续由fooking按原生协议处理(size+body),大于0: 表示已经处理,数据由output返回]]local fb = require("fooking.buffer");local fc = require("fooking.connection");dofile("Sha1.lua")function onConnect(conn)print("new client, sid="..fc.id(conn))endfunction onClose(conn)print("close client, sid="..fc.id(conn))endfunction onRead(conn, requestid, input, output)local l = fb.size(input);local s = fb.data(input);fb.seek(input, l);--fc.send(conn, "HTTP/1.1 OK\r\nConnection: keep-alive\r\nContent-Length: 11\r\n\r\nhello world");if requestid == 0 then--握手协议local startpos = string.find(s, "Sec-WebSocket-Key: ", 1, true);if not startpos thenprint("not found Sec-WebSocket-Key");return 1;endlocal endpos = string.find(s, "\r\n", startpos + 19 , true);if not endpos thenprint("Sec-WebSocket-Key is not invalid");return 1;endlocal key = string.sub(s, startpos + 19, endpos - 1);local rkey = base64Encode(Sha1(key.."258EAFA5-E914-47DA-95CA-C5AB0DC85B11"));fc.send(conn, "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nUpgrade: WebSocket\r\nSec-WebSocket-Accept: "..rkey.."\r\n\r\n");elselocal body = wsDecode(s);fb.append(output, body);endreturn 1;endfunction onWrite(conn, requestid, input, output)local l = fb.size(input);local s = fb.data(input);fb.seek(input, l);local data = wsEncode(s);fc.send(conn, data);return 1;endfunction base64Encode(str)local b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'local s64 = ''while #str > 0 do -- iterate through stringlocal bytes_num = 0 -- number of shifted byteslocal buf = 0 -- input bufferfor byte_cnt=1,3 dobuf = (buf * 256)if #str > 0 then -- if string not empty, shift 1st byte to bufbuf = buf + string.byte(str, 1, 1)str = string.sub(str, 2)bytes_num = bytes_num + 1endendfor group_cnt=1,(bytes_num+1) dob64char = math.fmod(math.floor(buf/262144), 64) + 1s64 = s64 .. string.sub(b64chars, b64char, b64char)buf = buf * 64endfor fill_cnt=1,(3-bytes_num) dos64 = s64 .. '='endendreturn s64endfunction wsEncode(str)local data = "";--fin=1, rsv=000, opcode=0001local fin = 1 << 7;local rsv = 0;local opc = 1;data = data .. string.pack("B", fin | rsv | opc);--lengthlocal slen = #str;local mask = 0;if slen > 65535 thendata = data .. string.pack("B", 127 | mask) .. string.pack(">J", slen);elseif slen > 125 thendata = data .. string.pack("B", 126 | mask) .. string.pack(">H", slen);elsedata = data .. string.pack("B", slen | mask);end--mask--TODO--bodydata = data .. str;return data;endfunction wsDecode(s)--数据处理local c1,c2 = string.byte(s, 1, 2);local fin = c1 >> 7 & 0x1;local rsv1 = c1 >> 6 & 0x1;local rsv2 = c1 >> 5 & 0x1;local rsv3 = c1 >> 4 & 0x1;local opcode = c1 & 0xF;local hashmask = c2 >> 7 & 0x1;local length = c2 & 0x7F;local mask = "";if length == 126 thenif hashmask == 1 thenmask = string.sub(s, 5, 8);endlocal c3,c4 = string.byte(s, 3, 4);length = c3 << 8 | c4;elseif length == 127 thenif hashmask == 1 thenmask = string.sub(s, 11, 14);endlocal c3,c4,c5,c6,c7,c8,c9,c10 = string.byte(s, 3, 10);length = (c3 << 56) | (c4 << 48) | (c5 << 40) | (c6 << 32) |(c7 << 24) | (c8 << 16) | (c9 << 8) | c10;elseif hashmask == 1 thenmask = string.sub(s, 3, 6);endlocal offset = 2;--length offsetif length > 65535 thenoffset = offset + 8;elseif length > 125 thenoffset = offset + 2;end--mask offsetif hashmask == 1 thenoffset = offset + 4;endlocal body = "";if hashmask == 1 thenlocal m1,m2,m3,m4 = string.byte(mask, 1, 4);local marr = {m1, m2, m3, m4};for i=1,length dobody = body .. string.char(string.byte(s, offset+i) ~ marr[(i-1)%4+1]);endelsebody = string.sub(s, offset);endreturn body;end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。