整理代码
This commit is contained in:
@@ -80,15 +80,13 @@ local _send do
|
|||||||
local shr=bit.rshift
|
local shr=bit.rshift
|
||||||
|
|
||||||
local mask_key={1,14,5,14}
|
local mask_key={1,14,5,14}
|
||||||
|
local mask_str=char(unpack(mask_key))
|
||||||
|
|
||||||
function _send(opcode,message)
|
function _send(opcode,message)
|
||||||
--Message type
|
--Message type
|
||||||
SOCK:send(char(bor(0x80,opcode)))
|
SOCK:send(char(bor(0x80,opcode)))
|
||||||
|
|
||||||
if not message then
|
if message then
|
||||||
SOCK:send(char(0x80,unpack(mask_key)))
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
|
|
||||||
--Length
|
--Length
|
||||||
local length=#message
|
local length=#message
|
||||||
if length>65535 then
|
if length>65535 then
|
||||||
@@ -98,12 +96,16 @@ local _send do
|
|||||||
else
|
else
|
||||||
SOCK:send(char(bor(length,0x80)))
|
SOCK:send(char(bor(length,0x80)))
|
||||||
end
|
end
|
||||||
SOCK:send(char(unpack(mask_key)))
|
SOCK:send(mask_str)
|
||||||
local msgbyte={byte(message,1,length)}
|
local msgbyte={byte(message,1,length)}
|
||||||
for i=1,length do
|
for i=1,length do
|
||||||
msgbyte[i]=bxor(msgbyte[i],mask_key[(i-1)%4+1])
|
msgbyte[i]=bxor(msgbyte[i],mask_key[(i-1)%4+1])
|
||||||
end
|
end
|
||||||
return SOCK:send(char(unpack(msgbyte)))
|
return SOCK:send(char(unpack(msgbyte)))
|
||||||
|
else
|
||||||
|
SOCK:send("\128"..mask_str)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local length
|
local length
|
||||||
|
|||||||
Reference in New Issue
Block a user