Commit 1157a4bf authored by mercury233's avatar mercury233

update buffer

parent c47548f3
...@@ -690,7 +690,7 @@ net.createServer (client) -> ...@@ -690,7 +690,7 @@ net.createServer (client) ->
client.write replay_buffer client.write replay_buffer
setTimeout (()-> setTimeout (()->
client.destroy() client.destroy()
return), 1000 return), 5000
return return
return return
...@@ -699,15 +699,15 @@ net.createServer (client) -> ...@@ -699,15 +699,15 @@ net.createServer (client) ->
client.pre_establish_buffers = new Array() client.pre_establish_buffers = new Array()
client.on 'data', (data) -> client.on 'data', (ctos_buffer) ->
if client.is_post_watcher if client.is_post_watcher
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
room.watcher.write data if room room.watcher.write ctos_buffer if room
else else
ctos_buffer = new Buffer(0) #ctos_buffer = new Buffer(0)
ctos_message_length = 0 ctos_message_length = 0
ctos_proto = 0 ctos_proto = 0
ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学 #ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
datas = [] datas = []
...@@ -718,11 +718,13 @@ net.createServer (client) -> ...@@ -718,11 +718,13 @@ net.createServer (client) ->
if ctos_buffer.length >= 2 if ctos_buffer.length >= 2
ctos_message_length = ctos_buffer.readUInt16LE(0) ctos_message_length = ctos_buffer.readUInt16LE(0)
else else
log.warn("bad ctos_buffer length", client.ip) unless ctos_buffer.length == 0
break break
else if ctos_proto == 0 else if ctos_proto == 0
if ctos_buffer.length >= 3 if ctos_buffer.length >= 3
ctos_proto = ctos_buffer.readUInt8(2) ctos_proto = ctos_buffer.readUInt8(2)
else else
log.warn("bad ctos_proto length", client.ip)
break break
else else
if ctos_buffer.length >= 2 + ctos_message_length if ctos_buffer.length >= 2 + ctos_message_length
...@@ -743,6 +745,7 @@ net.createServer (client) -> ...@@ -743,6 +745,7 @@ net.createServer (client) ->
ctos_message_length = 0 ctos_message_length = 0
ctos_proto = 0 ctos_proto = 0
else else
log.warn("bad ctos_message length", client.ip)
break break
looplimit++ looplimit++
...@@ -765,11 +768,11 @@ net.createServer (client) -> ...@@ -765,11 +768,11 @@ net.createServer (client) ->
return return
# 服务端到客户端(stoc) # 服务端到客户端(stoc)
server.on 'data', (data)-> server.on 'data', (stoc_buffer)->
stoc_buffer = new Buffer(0) #stoc_buffer = new Buffer(0)
stoc_message_length = 0 stoc_message_length = 0
stoc_proto = 0 stoc_proto = 0
stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学 #stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
#unless ygopro.stoc_follows[stoc_proto] and ygopro.stoc_follows[stoc_proto].synchronous #unless ygopro.stoc_follows[stoc_proto] and ygopro.stoc_follows[stoc_proto].synchronous
#client.write data #client.write data
...@@ -782,11 +785,13 @@ net.createServer (client) -> ...@@ -782,11 +785,13 @@ net.createServer (client) ->
if stoc_buffer.length >= 2 if stoc_buffer.length >= 2
stoc_message_length = stoc_buffer.readUInt16LE(0) stoc_message_length = stoc_buffer.readUInt16LE(0)
else else
log.warn("bad stoc_buffer length", client.ip) unless stoc_buffer.length == 0
break break
else if stoc_proto == 0 else if stoc_proto == 0
if stoc_buffer.length >= 3 if stoc_buffer.length >= 3
stoc_proto = stoc_buffer.readUInt8(2) stoc_proto = stoc_buffer.readUInt8(2)
else else
log.warn("bad stoc_proto length", client.ip)
break break
else else
if stoc_buffer.length >= 2 + stoc_message_length if stoc_buffer.length >= 2 + stoc_message_length
...@@ -811,6 +816,7 @@ net.createServer (client) -> ...@@ -811,6 +816,7 @@ net.createServer (client) ->
stoc_message_length = 0 stoc_message_length = 0
stoc_proto = 0 stoc_proto = 0
else else
log.warn("bad stoc_message length", client.ip)
break break
looplimit++ looplimit++
......
...@@ -891,23 +891,21 @@ ...@@ -891,23 +891,21 @@
client.write(replay_buffer); client.write(replay_buffer);
setTimeout((function() { setTimeout((function() {
client.destroy(); client.destroy();
}), 1000); }), 5000);
}); });
}; };
} }
client.pre_establish_buffers = new Array(); client.pre_establish_buffers = new Array();
client.on('data', function(data) { client.on('data', function(ctos_buffer) {
var b, bad_ip_count, buffer, cancel, ctos_buffer, ctos_message_length, ctos_proto, datas, k, l, len, len1, looplimit, room, struct; var b, bad_ip_count, buffer, cancel, ctos_message_length, ctos_proto, datas, k, l, len, len1, looplimit, room, struct;
if (client.is_post_watcher) { if (client.is_post_watcher) {
room = ROOM_all[client.rid]; room = ROOM_all[client.rid];
if (room) { if (room) {
room.watcher.write(data); room.watcher.write(ctos_buffer);
} }
} else { } else {
ctos_buffer = new Buffer(0);
ctos_message_length = 0; ctos_message_length = 0;
ctos_proto = 0; ctos_proto = 0;
ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length);
datas = []; datas = [];
looplimit = 0; looplimit = 0;
while (true) { while (true) {
...@@ -915,12 +913,16 @@ ...@@ -915,12 +913,16 @@
if (ctos_buffer.length >= 2) { if (ctos_buffer.length >= 2) {
ctos_message_length = ctos_buffer.readUInt16LE(0); ctos_message_length = ctos_buffer.readUInt16LE(0);
} else { } else {
if (ctos_buffer.length !== 0) {
log.warn("bad ctos_buffer length", client.ip);
}
break; break;
} }
} else if (ctos_proto === 0) { } else if (ctos_proto === 0) {
if (ctos_buffer.length >= 3) { if (ctos_buffer.length >= 3) {
ctos_proto = ctos_buffer.readUInt8(2); ctos_proto = ctos_buffer.readUInt8(2);
} else { } else {
log.warn("bad ctos_proto length", client.ip);
break; break;
} }
} else { } else {
...@@ -946,6 +948,7 @@ ...@@ -946,6 +948,7 @@
ctos_message_length = 0; ctos_message_length = 0;
ctos_proto = 0; ctos_proto = 0;
} else { } else {
log.warn("bad ctos_message length", client.ip);
break; break;
} }
} }
...@@ -975,12 +978,10 @@ ...@@ -975,12 +978,10 @@
} }
} }
}); });
server.on('data', function(data) { server.on('data', function(stoc_buffer) {
var b, buffer, cancel, datas, k, len, looplimit, stanzas, stoc_buffer, stoc_message_length, stoc_proto, struct; var b, buffer, cancel, datas, k, len, looplimit, stanzas, stoc_message_length, stoc_proto, struct;
stoc_buffer = new Buffer(0);
stoc_message_length = 0; stoc_message_length = 0;
stoc_proto = 0; stoc_proto = 0;
stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length);
datas = []; datas = [];
looplimit = 0; looplimit = 0;
while (true) { while (true) {
...@@ -988,12 +989,16 @@ ...@@ -988,12 +989,16 @@
if (stoc_buffer.length >= 2) { if (stoc_buffer.length >= 2) {
stoc_message_length = stoc_buffer.readUInt16LE(0); stoc_message_length = stoc_buffer.readUInt16LE(0);
} else { } else {
if (stoc_buffer.length !== 0) {
log.warn("bad stoc_buffer length", client.ip);
}
break; break;
} }
} else if (stoc_proto === 0) { } else if (stoc_proto === 0) {
if (stoc_buffer.length >= 3) { if (stoc_buffer.length >= 3) {
stoc_proto = stoc_buffer.readUInt8(2); stoc_proto = stoc_buffer.readUInt8(2);
} else { } else {
log.warn("bad stoc_proto length", client.ip);
break; break;
} }
} else { } else {
...@@ -1024,6 +1029,7 @@ ...@@ -1024,6 +1029,7 @@
stoc_message_length = 0; stoc_message_length = 0;
stoc_proto = 0; stoc_proto = 0;
} else { } else {
log.warn("bad stoc_message length", client.ip);
break; break;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment