Commit 57adc2f0 authored by nanahira's avatar nanahira

for attack things

parent d5b64bd1
......@@ -180,12 +180,13 @@ class YGOProMessagesHelper {
}
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 messageLength = 0;
let bufferProto = 0;
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 (messageBuffer.length >= 2) {
messageLength = messageBuffer.readUInt16LE(0);
......@@ -216,7 +217,7 @@ class YGOProMessagesHelper {
if (messageBuffer.length >= 2 + messageLength) {
const proto = this.constants[direction][bufferProto];
let cancel = proto && protoFilter && !protoFilter.includes(proto);
if (cancel && disconnectIfInvalid) {
if (cancel && preconnect) {
feedback = {
type: "INVALID_PACKET",
message: `${direction} proto not allowed`
......@@ -240,6 +241,12 @@ class YGOProMessagesHelper {
for (let handler of handlerCollection.get(bufferProto)) {
cancel = await handler.handle(buffer, info, datas, params);
if (cancel) {
if (cancel === '_cancel') {
return {
datas: [],
feedback
};
}
break;
}
}
......@@ -262,10 +269,10 @@ class YGOProMessagesHelper {
break;
}
}
if (l === this.singleHandleLimit - 1) {
if (l === limit - 1) {
feedback = {
type: "OVERSIZE",
message: `Oversized ${direction}`
message: `Oversized ${direction} ${limit}`
};
}
}
......
......@@ -8,13 +8,13 @@ import net from "net";
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;
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.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) {
return !!(await this.handler(buffer, info, datas, params));
} else {
......@@ -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) {
throw "Invalid priority: " + priority;
}
......@@ -258,7 +258,7 @@ export class YGOProMessagesHelper {
} else {
if (messageBuffer.length >= 2 + messageLength) {
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) {
feedback = {
type: "INVALID_PACKET",
......@@ -283,6 +283,12 @@ export class YGOProMessagesHelper {
for (let handler of handlerCollection.get(bufferProto)) {
cancel = await handler.handle(buffer, info, datas, params);
if (cancel) {
if (cancel === '_cancel') {
return {
datas: [],
feedback
}
}
break;
}
}
......@@ -307,7 +313,7 @@ export class YGOProMessagesHelper {
if (l === limit - 1) {
feedback = {
type: "OVERSIZE",
message: `Oversized ${direction}`
message: `Oversized ${direction} ${limit}`
};
}
}
......
......@@ -1964,7 +1964,7 @@ netRequestHandler = (client) ->
ROOM_bad_ip[client.ip] = 1
CLIENT_kick(client)
return
if !client.server
if client.closed || !client.server
return
if client.established
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) ->
# return true to cancel a synchronous message
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
# so remove the password
name_full =info.name.replace(/\\/g, "").split("$")
......
......@@ -2631,7 +2631,7 @@
return;
}
}
if (!client.server) {
if (client.closed || !client.server) {
return;
}
if (client.established) {
......@@ -2686,6 +2686,12 @@
// return true to cancel a synchronous message
ygopro.ctos_follow('PLAYER_INFO', true, async function(buffer, info, client, server, datas) {
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
// so remove the password
name_full = info.name.replace(/\\/g, "").split("$");
......
......@@ -113,4 +113,4 @@ translateHandler = (handler) ->
if client
client.system_kicked = true
client.destroy()
return
return '_cancel'
......@@ -185,6 +185,7 @@
client.system_kicked = true;
client.destroy();
}
return '_cancel';
};
}).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