Commit 6eb1de84 authored by mercury233's avatar mercury233

fix ctos, add surrender handling

parent fbcf6db0
...@@ -720,14 +720,14 @@ net.createServer (client) -> ...@@ -720,14 +720,14 @@ net.createServer (client) ->
cancel = false cancel = false
if ygopro.ctos_follows[ctos_proto] if ygopro.ctos_follows[ctos_proto]
b = ctos_buffer.slice(3, ctos_message_length - 1 + 3) b = ctos_buffer.slice(3, ctos_message_length - 1 + 3)
info = null
if struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]] if struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]
struct._setBuff(b) struct._setBuff(b)
if ygopro.ctos_follows[ctos_proto].synchronous info = _.clone(struct.fields)
cancel = ygopro.ctos_follows[ctos_proto].callback b, _.clone(struct.fields), client, server if ygopro.ctos_follows[ctos_proto].synchronous
else cancel = ygopro.ctos_follows[ctos_proto].callback b, info, client, server
ygopro.ctos_follows[ctos_proto].callback b, _.clone(struct.fields), client, server
else else
ygopro.ctos_follows[ctos_proto].callback b, null, client, server ygopro.ctos_follows[ctos_proto].callback b, info, client, server
datas.push ctos_buffer.slice(0, 2 + ctos_message_length) unless cancel datas.push ctos_buffer.slice(0, 2 + ctos_message_length) unless cancel
ctos_buffer = ctos_buffer.slice(2 + ctos_message_length) ctos_buffer = ctos_buffer.slice(2 + ctos_message_length)
ctos_message_length = 0 ctos_message_length = 0
...@@ -788,17 +788,14 @@ net.createServer (client) -> ...@@ -788,17 +788,14 @@ net.createServer (client) ->
stanzas = stoc_proto stanzas = stoc_proto
if ygopro.stoc_follows[stoc_proto] if ygopro.stoc_follows[stoc_proto]
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3) b = stoc_buffer.slice(3, stoc_message_length - 1 + 3)
info = null
if struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]] if struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]
struct._setBuff(b) struct._setBuff(b)
if ygopro.stoc_follows[stoc_proto].synchronous info = _.clone(struct.fields)
cancel = ygopro.stoc_follows[stoc_proto].callback b, _.clone(struct.fields), client, server if ygopro.stoc_follows[stoc_proto].synchronous
else cancel = ygopro.stoc_follows[stoc_proto].callback b, info, client, server
ygopro.stoc_follows[stoc_proto].callback b, _.clone(struct.fields), client, server
else else
if ygopro.stoc_follows[stoc_proto].synchronous ygopro.stoc_follows[stoc_proto].callback b, info, client, server
cancel = ygopro.stoc_follows[stoc_proto].callback b, null, client, server
else
ygopro.stoc_follows[stoc_proto].callback b, null, client, server
datas.push stoc_buffer.slice(0, 2 + stoc_message_length) unless cancel datas.push stoc_buffer.slice(0, 2 + stoc_message_length) unless cancel
stoc_buffer = stoc_buffer.slice(2 + stoc_message_length) stoc_buffer = stoc_buffer.slice(2 + stoc_message_length)
stoc_message_length = 0 stoc_message_length = 0
...@@ -1221,12 +1218,17 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ...@@ -1221,12 +1218,17 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
playertype = buffer.readUInt8(1) playertype = buffer.readUInt8(1)
client.is_first = !(playertype & 0xf) client.is_first = !(playertype & 0xf)
client.lp = room.hostinfo.start_lp client.lp = room.hostinfo.start_lp
if client.is_host
room.turn = 0
#ygopro.stoc_send_chat_to_room(room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}") #ygopro.stoc_send_chat_to_room(room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}")
if ygopro.constants.MSG[msg] == 'NEW_TURN' and client.surrend_confirm if ygopro.constants.MSG[msg] == 'NEW_TURN'
client.surrend_confirm = false if client.is_host
ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE) room.turn = room.turn + 1
if client.surrend_confirm
client.surrend_confirm = false
ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE)
if ygopro.constants.MSG[msg] == 'WIN' and client.is_host if ygopro.constants.MSG[msg] == 'WIN' and client.is_host
pos = buffer.readUInt8(1) pos = buffer.readUInt8(1)
...@@ -1417,6 +1419,17 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)-> ...@@ -1417,6 +1419,17 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
client.deck_saved = true client.deck_saved = true
return return
ygopro.ctos_follow 'SURRENDER', true, (buffer, info, client, server)->
room=ROOM_all[client.rid]
return unless room
if !room.started or room.hostinfo.mode==2
return true
if room.random_type and room.turn < 3
ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE)
return true
return false
ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)-> ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
return unless room return unless room
...@@ -1428,7 +1441,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)-> ...@@ -1428,7 +1441,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
when '/投降', '/surrender' when '/投降', '/surrender'
if !room.started or room.hostinfo.mode==2 if !room.started or room.hostinfo.mode==2
return cancel return cancel
if room.random_type if room.random_type and room.turn < 3
ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE)
return cancel return cancel
if client.surrend_confirm if client.surrend_confirm
......
...@@ -888,7 +888,7 @@ ...@@ -888,7 +888,7 @@
} }
client.pre_establish_buffers = new Array(); client.pre_establish_buffers = new Array();
client.on('data', function(ctos_buffer) { client.on('data', function(ctos_buffer) {
var b, bad_ip_count, buffer, cancel, ctos_message_length, ctos_proto, datas, j, k, len, len1, looplimit, room, struct; var b, bad_ip_count, buffer, cancel, ctos_message_length, ctos_proto, datas, info, j, k, 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) {
...@@ -921,15 +921,15 @@ ...@@ -921,15 +921,15 @@
cancel = false; cancel = false;
if (ygopro.ctos_follows[ctos_proto]) { if (ygopro.ctos_follows[ctos_proto]) {
b = ctos_buffer.slice(3, ctos_message_length - 1 + 3); b = ctos_buffer.slice(3, ctos_message_length - 1 + 3);
info = null;
if (struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]) { if (struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]) {
struct._setBuff(b); struct._setBuff(b);
if (ygopro.ctos_follows[ctos_proto].synchronous) { info = _.clone(struct.fields);
cancel = ygopro.ctos_follows[ctos_proto].callback(b, _.clone(struct.fields), client, server); }
} else { if (ygopro.ctos_follows[ctos_proto].synchronous) {
ygopro.ctos_follows[ctos_proto].callback(b, _.clone(struct.fields), client, server); cancel = ygopro.ctos_follows[ctos_proto].callback(b, info, client, server);
}
} else { } else {
ygopro.ctos_follows[ctos_proto].callback(b, null, client, server); ygopro.ctos_follows[ctos_proto].callback(b, info, client, server);
} }
} }
if (!cancel) { if (!cancel) {
...@@ -972,7 +972,7 @@ ...@@ -972,7 +972,7 @@
} }
}); });
server.on('data', function(stoc_buffer) { server.on('data', function(stoc_buffer) {
var b, buffer, cancel, datas, j, len, looplimit, stanzas, stoc_message_length, stoc_proto, struct; var b, buffer, cancel, datas, info, j, len, looplimit, stanzas, stoc_message_length, stoc_proto, struct;
stoc_message_length = 0; stoc_message_length = 0;
stoc_proto = 0; stoc_proto = 0;
datas = []; datas = [];
...@@ -1000,19 +1000,15 @@ ...@@ -1000,19 +1000,15 @@
stanzas = stoc_proto; stanzas = stoc_proto;
if (ygopro.stoc_follows[stoc_proto]) { if (ygopro.stoc_follows[stoc_proto]) {
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3); b = stoc_buffer.slice(3, stoc_message_length - 1 + 3);
info = null;
if (struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]) { if (struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]) {
struct._setBuff(b); struct._setBuff(b);
if (ygopro.stoc_follows[stoc_proto].synchronous) { info = _.clone(struct.fields);
cancel = ygopro.stoc_follows[stoc_proto].callback(b, _.clone(struct.fields), client, server); }
} else { if (ygopro.stoc_follows[stoc_proto].synchronous) {
ygopro.stoc_follows[stoc_proto].callback(b, _.clone(struct.fields), client, server); cancel = ygopro.stoc_follows[stoc_proto].callback(b, info, client, server);
}
} else { } else {
if (ygopro.stoc_follows[stoc_proto].synchronous) { ygopro.stoc_follows[stoc_proto].callback(b, info, client, server);
cancel = ygopro.stoc_follows[stoc_proto].callback(b, null, client, server);
} else {
ygopro.stoc_follows[stoc_proto].callback(b, null, client, server);
}
} }
} }
if (!cancel) { if (!cancel) {
...@@ -1466,10 +1462,18 @@ ...@@ -1466,10 +1462,18 @@
playertype = buffer.readUInt8(1); playertype = buffer.readUInt8(1);
client.is_first = !(playertype & 0xf); client.is_first = !(playertype & 0xf);
client.lp = room.hostinfo.start_lp; client.lp = room.hostinfo.start_lp;
if (client.is_host) {
room.turn = 0;
}
} }
if (ygopro.constants.MSG[msg] === 'NEW_TURN' && client.surrend_confirm) { if (ygopro.constants.MSG[msg] === 'NEW_TURN') {
client.surrend_confirm = false; if (client.is_host) {
ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE); room.turn = room.turn + 1;
}
if (client.surrend_confirm) {
client.surrend_confirm = false;
ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE);
}
} }
if (ygopro.constants.MSG[msg] === 'WIN' && client.is_host) { if (ygopro.constants.MSG[msg] === 'WIN' && client.is_host) {
pos = buffer.readUInt8(1); pos = buffer.readUInt8(1);
...@@ -1737,6 +1741,22 @@ ...@@ -1737,6 +1741,22 @@
} }
}); });
ygopro.ctos_follow('SURRENDER', true, function(buffer, info, client, server) {
var room;
room = ROOM_all[client.rid];
if (!room) {
return;
}
if (!room.started || room.hostinfo.mode === 2) {
return true;
}
if (room.random_type && room.turn < 3) {
ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE);
return true;
}
return false;
});
ygopro.ctos_follow('CHAT', true, function(buffer, info, client, server) { ygopro.ctos_follow('CHAT', true, function(buffer, info, client, server) {
var cancel, cmd, msg, name, oldmsg, room, struct, windbot; var cancel, cmd, msg, name, oldmsg, room, struct, windbot;
room = ROOM_all[client.rid]; room = ROOM_all[client.rid];
...@@ -1755,7 +1775,7 @@ ...@@ -1755,7 +1775,7 @@
if (!room.started || room.hostinfo.mode === 2) { if (!room.started || room.hostinfo.mode === 2) {
return cancel; return cancel;
} }
if (room.random_type) { if (room.random_type && room.turn < 3) {
ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "${surrender_denied}", ygopro.constants.COLORS.BABYBLUE);
return cancel; return cancel;
} }
......
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