Commit 57adc2f0 authored by nanahira's avatar nanahira

for attack things

parent d5b64bd1
Pipeline #6620 passed with stages
in 62 minutes and 36 seconds
...@@ -180,12 +180,13 @@ class YGOProMessagesHelper { ...@@ -180,12 +180,13 @@ class YGOProMessagesHelper {
} }
handlerCollection.get(translatedProto).push(handlerObj); handlerCollection.get(translatedProto).push(handlerObj);
} }
async handleBuffer(messageBuffer, direction, protoFilter, params, disconnectIfInvalid = false) { async handleBuffer(messageBuffer, direction, protoFilter, params, preconnect = false) {
let feedback = null; let feedback = null;
let messageLength = 0; let messageLength = 0;
let bufferProto = 0; let bufferProto = 0;
let datas = []; let datas = [];
for (let l = 0; l < this.singleHandleLimit; ++l) { const limit = preconnect ? 2 : this.singleHandleLimit;
for (let l = 0; l < limit; ++l) {
if (messageLength === 0) { if (messageLength === 0) {
if (messageBuffer.length >= 2) { if (messageBuffer.length >= 2) {
messageLength = messageBuffer.readUInt16LE(0); messageLength = messageBuffer.readUInt16LE(0);
...@@ -216,7 +217,7 @@ class YGOProMessagesHelper { ...@@ -216,7 +217,7 @@ class YGOProMessagesHelper {
if (messageBuffer.length >= 2 + messageLength) { if (messageBuffer.length >= 2 + messageLength) {
const proto = this.constants[direction][bufferProto]; const proto = this.constants[direction][bufferProto];
let cancel = proto && protoFilter && !protoFilter.includes(proto); let cancel = proto && protoFilter && !protoFilter.includes(proto);
if (cancel && disconnectIfInvalid) { if (cancel && preconnect) {
feedback = { feedback = {
type: "INVALID_PACKET", type: "INVALID_PACKET",
message: `${direction} proto not allowed` message: `${direction} proto not allowed`
...@@ -240,6 +241,12 @@ class YGOProMessagesHelper { ...@@ -240,6 +241,12 @@ class YGOProMessagesHelper {
for (let handler of handlerCollection.get(bufferProto)) { for (let handler of handlerCollection.get(bufferProto)) {
cancel = await handler.handle(buffer, info, datas, params); cancel = await handler.handle(buffer, info, datas, params);
if (cancel) { if (cancel) {
if (cancel === '_cancel') {
return {
datas: [],
feedback
};
}
break; break;
} }
} }
...@@ -262,10 +269,10 @@ class YGOProMessagesHelper { ...@@ -262,10 +269,10 @@ class YGOProMessagesHelper {
break; break;
} }
} }
if (l === this.singleHandleLimit - 1) { if (l === limit - 1) {
feedback = { feedback = {
type: "OVERSIZE", type: "OVERSIZE",
message: `Oversized ${direction}` message: `Oversized ${direction} ${limit}`
}; };
} }
} }
......
...@@ -8,13 +8,13 @@ import net from "net"; ...@@ -8,13 +8,13 @@ import net from "net";
class Handler { class Handler {
private handler: (buffer: Buffer, info: any, datas: Buffer[], params: any) => Promise<boolean>; private handler: (buffer: Buffer, info: any, datas: Buffer[], params: any) => Promise<boolean | string>;
synchronous: boolean; synchronous: boolean;
constructor(handler: (buffer: Buffer, info: any, datas: Buffer[], params: any) => Promise<boolean>, synchronous: boolean) { constructor(handler: (buffer: Buffer, info: any, datas: Buffer[], params: any) => Promise<boolean | string>, synchronous: boolean) {
this.handler = handler; this.handler = handler;
this.synchronous = synchronous || false; this.synchronous = synchronous || false;
} }
async handle(buffer: Buffer, info: any, datas: Buffer[], params: any) { async handle(buffer: Buffer, info: any, datas: Buffer[], params: any): Promise<boolean | string> {
if (this.synchronous) { if (this.synchronous) {
return !!(await this.handler(buffer, info, datas, params)); return !!(await this.handler(buffer, info, datas, params));
} else { } else {
...@@ -208,7 +208,7 @@ export class YGOProMessagesHelper { ...@@ -208,7 +208,7 @@ export class YGOProMessagesHelper {
}); });
} }
addHandler(protostr: string, handler: (buffer: Buffer, info: any, datas: Buffer[], params: any) => Promise<boolean>, synchronous: boolean, priority: number) { addHandler(protostr: string, handler: (buffer: Buffer, info: any, datas: Buffer[], params: any) => Promise<boolean | string>, synchronous: boolean, priority: number) {
if (priority < 0 || priority > 4) { if (priority < 0 || priority > 4) {
throw "Invalid priority: " + priority; throw "Invalid priority: " + priority;
} }
...@@ -258,7 +258,7 @@ export class YGOProMessagesHelper { ...@@ -258,7 +258,7 @@ export class YGOProMessagesHelper {
} else { } else {
if (messageBuffer.length >= 2 + messageLength) { if (messageBuffer.length >= 2 + messageLength) {
const proto = this.constants[direction][bufferProto]; const proto = this.constants[direction][bufferProto];
let cancel = proto && protoFilter && !protoFilter.includes(proto); let cancel: string | boolean = proto && protoFilter && !protoFilter.includes(proto);
if (cancel && preconnect) { if (cancel && preconnect) {
feedback = { feedback = {
type: "INVALID_PACKET", type: "INVALID_PACKET",
...@@ -283,6 +283,12 @@ export class YGOProMessagesHelper { ...@@ -283,6 +283,12 @@ export class YGOProMessagesHelper {
for (let handler of handlerCollection.get(bufferProto)) { for (let handler of handlerCollection.get(bufferProto)) {
cancel = await handler.handle(buffer, info, datas, params); cancel = await handler.handle(buffer, info, datas, params);
if (cancel) { if (cancel) {
if (cancel === '_cancel') {
return {
datas: [],
feedback
}
}
break; break;
} }
} }
...@@ -307,7 +313,7 @@ export class YGOProMessagesHelper { ...@@ -307,7 +313,7 @@ export class YGOProMessagesHelper {
if (l === limit - 1) { if (l === limit - 1) {
feedback = { feedback = {
type: "OVERSIZE", type: "OVERSIZE",
message: `Oversized ${direction}` message: `Oversized ${direction} ${limit}`
}; };
} }
} }
......
...@@ -1964,7 +1964,7 @@ netRequestHandler = (client) -> ...@@ -1964,7 +1964,7 @@ netRequestHandler = (client) ->
ROOM_bad_ip[client.ip] = 1 ROOM_bad_ip[client.ip] = 1
CLIENT_kick(client) CLIENT_kick(client)
return return
if !client.server if client.closed || !client.server
return return
if client.established if client.established
client.server.write buffer for buffer in handle_data.datas client.server.write buffer for buffer in handle_data.datas
...@@ -2000,6 +2000,11 @@ deck_name_match = global.deck_name_match = (deck_name, player_name) -> ...@@ -2000,6 +2000,11 @@ deck_name_match = global.deck_name_match = (deck_name, player_name) ->
# return true to cancel a synchronous message # return true to cancel a synchronous message
ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server, datas)-> ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server, datas)->
# second PLAYER_INFO = attack
if client.name
log.info 'DUP PLAYER_INFO', client.ip
CLIENT_kick client
return '_cancel'
# checkmate use username$password, but here don't # checkmate use username$password, but here don't
# so remove the password # so remove the password
name_full =info.name.replace(/\\/g, "").split("$") name_full =info.name.replace(/\\/g, "").split("$")
......
...@@ -2631,7 +2631,7 @@ ...@@ -2631,7 +2631,7 @@
return; return;
} }
} }
if (!client.server) { if (client.closed || !client.server) {
return; return;
} }
if (client.established) { if (client.established) {
...@@ -2686,6 +2686,12 @@ ...@@ -2686,6 +2686,12 @@
// return true to cancel a synchronous message // return true to cancel a synchronous message
ygopro.ctos_follow('PLAYER_INFO', true, async function(buffer, info, client, server, datas) { ygopro.ctos_follow('PLAYER_INFO', true, async function(buffer, info, client, server, datas) {
var geo, lang, name, name_full, struct, vpass; var geo, lang, name, name_full, struct, vpass;
// second PLAYER_INFO = attack
if (client.name) {
log.info('DUP PLAYER_INFO', client.ip);
CLIENT_kick(client);
return '_cancel';
}
// checkmate use username$password, but here don't // checkmate use username$password, but here don't
// so remove the password // so remove the password
name_full = info.name.replace(/\\/g, "").split("$"); name_full = info.name.replace(/\\/g, "").split("$");
......
...@@ -113,4 +113,4 @@ translateHandler = (handler) -> ...@@ -113,4 +113,4 @@ translateHandler = (handler) ->
if client if client
client.system_kicked = true client.system_kicked = true
client.destroy() client.destroy()
return return '_cancel'
...@@ -185,6 +185,7 @@ ...@@ -185,6 +185,7 @@
client.system_kicked = true; client.system_kicked = true;
client.destroy(); client.destroy();
} }
return '_cancel';
}; };
}).call(this); }).call(this);
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