Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ygopro.ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) {
- var check, decrypted_buffer, finish, i, id, j, k, len, len1, name, ref, ref1, replay_id, room, secret;
- info.pass = info.pass.trim();
- if (settings.modules.stop) {
- ygopro.stoc_die(client, settings.modules.stop);
- } else if (info.pass.toUpperCase() === "R" && settings.modules.cloud_replay.enabled) {
- ygopro.stoc_send_chat(client, "${cloud_replay_hint}", ygopro.constants.COLORS.BABYBLUE);
- redisdb.lrange(client.ip + ":replays", 0, 2, function(err, result) {
- _.each(result, function(replay_id, id) {
- redisdb.hgetall("replay:" + replay_id, function(err, replay) {
- if (err || !replay) {
- if (err) {
- log.info("cloud replay getall error: " + err);
- }
- return;
- }
- ygopro.stoc_send_chat(client, "<" + (id - 0 + 1) + "> R#" + replay_id + " " + replay.player_names + " " + replay.date_time, ygopro.constants.COLORS.BABYBLUE);
- });
- });
- });
- setTimeout((function() {
- ygopro.stoc_send(client, 'ERROR_MSG', {
- msg: 1,
- code: 9
- });
- client.destroy();
- }), 500);
- } else if (info.pass.slice(0, 2).toUpperCase() === "R#" && settings.modules.cloud_replay.enabled) {
- replay_id = info.pass.split("#")[1];
- if (replay_id > 0 && replay_id <= 9) {
- redisdb.lindex(client.ip + ":replays", replay_id - 1, function(err, replay_id) {
- if (err || !replay_id) {
- if (err) {
- log.info("cloud replay replayid error: " + err);
- }
- ygopro.stoc_die(client, "${cloud_replay_no}");
- return;
- }
- redisdb.hgetall("replay:" + replay_id, client.open_cloud_replay);
- });
- } else if (replay_id) {
- redisdb.hgetall("replay:" + replay_id, client.open_cloud_replay);
- } else {
- ygopro.stoc_die(client, "${cloud_replay_no}");
- }
- } else if (info.pass.toUpperCase() === "W" && settings.modules.cloud_replay.enabled) {
- replay_id = Cloud_replay_ids[Math.floor(Math.random() * Cloud_replay_ids.length)];
- redisdb.hgetall("replay:" + replay_id, client.open_cloud_replay);
- client.destroy();
- } else if (!info.pass.length && !settings.modules.random_duel.enabled && !settings.modules.windbot.enabled) {
- ygopro.stoc_die(client, "${blank_room_name}");
- } else if (info.pass.length && settings.modules.mycard.enabled && info.pass.slice(0, 3) !== 'AI#') {
- ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE);
- if (info.pass.length <= 8) {
- ygopro.stoc_die(client, '${invalid_password_length}');
- return;
- }
- buffer = new Buffer(info.pass.slice(0, 8), 'base64');
- if (buffer.length !== 6) {
- ygopro.stoc_die(client, '${invalid_password_payload}');
- return;
- }
- check = function(buf) {
- var checksum, i, j, ref;
- checksum = 0;
- for (i = j = 0, ref = buf.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
- checksum += buf.readUInt8(i);
- }
- return (checksum & 0xFF) === 0;
- };
- finish = function(buffer) {
- var action, j, len, name, opt1, opt2, opt3, options, ref, room, title;
- action = buffer.readUInt8(1) >> 4;
- if (buffer !== decrypted_buffer && (action === 1 || action === 2 || action === 4)) {
- ygopro.stoc_die(client, '${invalid_password_unauthorized}');
- return;
- }
- switch (action) {
- case 1:
- case 2:
- name = crypto.createHash('md5').update(info.pass + client.name).digest('base64').slice(0, 10).replace('+', '-').replace('/', '_');
- if (ROOM_find_by_name(name)) {
- ygopro.stoc_die(client, '${invalid_password_existed}');
- return;
- }
- opt1 = buffer.readUInt8(2);
- opt2 = buffer.readUInt16LE(3);
- opt3 = buffer.readUInt8(5);
- options = {
- lflist: 0,
- time_limit: 180,
- rule: (opt1 >> 5) & 3,
- mode: (opt1 >> 3) & 3,
- enable_priority: !!((opt1 >> 2) & 1),
- no_check_deck: !!((opt1 >> 1) & 1),
- no_shuffle_deck: !!(opt1 & 1),
- start_lp: opt2,
- start_hand: opt3 >> 4,
- draw_count: opt3 & 0xF
- };
- options.lflist = _.findIndex(settings.lflist, function(list) {
- return ((options.rule === 1) === list.tcg) && list.date.isBefore();
- });
- room = new Room(name, options);
- room.title = info.pass.slice(8).replace(String.fromCharCode(0xFEFF), ' ');
- room["private"] = action === 2;
- break;
- case 3:
- name = info.pass.slice(8);
- room = ROOM_find_by_name(name);
- if (!room) {
- ygopro.stoc_die(client, '${invalid_password_not_found}');
- return;
- }
- break;
- case 4:
- room = ROOM_find_or_create_by_name('M#' + info.pass.slice(8));
- room["private"] = true;
- room.arena = settings.modules.arena_mode.mode;
- if (room.arena === "athletic") {
- room.max_player = 2;
- room.welcome = "${athletic_arena_tip}";
- }
- break;
- case 5:
- title = info.pass.slice(8).replace(String.fromCharCode(0xFEFF), ' ');
- room = ROOM_find_by_title(title);
- if (!room) {
- ygopro.stoc_die(client, '${invalid_password_not_found}');
- return;
- }
- break;
- default:
- ygopro.stoc_die(client, '${invalid_password_action}');
- return;
- }
- if (!room) {
- ygopro.stoc_die(client, "${server_full}");
- } else if (room.error) {
- ygopro.stoc_die(client, room.error);
- } else if (room.started) {
- if (settings.modules.cloud_replay.enable_halfway_watch) {
- client.setTimeout(300000);
- client.rid = _.indexOf(ROOM_all, room);
- client.is_post_watcher = true;
- ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}");
- room.watchers.push(client);
- ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
- ref = room.watcher_buffers;
- for (j = 0, len = ref.length; j < len; j++) {
- buffer = ref[j];
- client.write(buffer);
- }
- } else {
- ygopro.stoc_die(client, "${watch_denied}");
- }
- } else {
- client.setTimeout(300000);
- client.rid = _.indexOf(ROOM_all, room);
- room.connect(client);
- }
- };
- if (id = users_cache[client.name]) {
- secret = id % 65535 + 1;
- decrypted_buffer = new Buffer(6);
- ref = [0, 2, 4];
- for (j = 0, len = ref.length; j < len; j++) {
- i = ref[j];
- decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i);
- }
- if (check(decrypted_buffer)) {
- return finish(decrypted_buffer);
- }
- }
- request({
- baseUrl: settings.modules.mycard.auth_base_url,
- url: '/users/' + encodeURIComponent(client.name) + '.json',
- qs: {
- api_key: settings.modules.mycard.auth_key,
- api_username: client.name,
- skip_track_visit: true
- },
- json: true
- }, function(error, response, body) {
- var k, len1, ref1;
- if (body && body.user) {
- users_cache[client.name] = body.user.id;
- secret = body.user.id % 65535 + 1;
- decrypted_buffer = new Buffer(6);
- ref1 = [0, 2, 4];
- for (k = 0, len1 = ref1.length; k < len1; k++) {
- i = ref1[k];
- decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i);
- }
- if (check(decrypted_buffer)) {
- buffer = decrypted_buffer;
- }
- }
- if (!check(buffer)) {
- ygopro.stoc_die(client, '${invalid_password_checksum}');
- return;
- }
- return finish(buffer);
- });
- } else if (!client.name || client.name === "") {
- ygopro.stoc_die(client, "${bad_user_name}");
- } else if (ROOM_connected_ip[client.ip] > 5) {
- log.warn("MULTI LOGIN", client.name, client.ip);
- ygopro.stoc_die(client, "${too_much_connection}" + client.ip);
- } else if (_.indexOf(settings.ban.banned_user, client.name) > -1) {
- settings.ban.banned_ip.push(client.ip);
- log.warn("BANNED USER LOGIN", client.name, client.ip);
- ygopro.stoc_die(client, "${banned_user_login}");
- } else if (_.indexOf(settings.ban.banned_ip, client.ip) > -1) {
- log.warn("BANNED IP LOGIN", client.name, client.ip);
- ygopro.stoc_die(client, "${banned_ip_login}");
- } else if (_.any(settings.ban.badword_level3, function(badword) {
- var regexp;
- regexp = new RegExp(badword, 'i');
- return name.match(regexp);
- }, name = client.name)) {
- log.warn("BAD NAME LEVEL 3", client.name, client.ip);
- ygopro.stoc_die(client, "${bad_name_level3}");
- } else if (_.any(settings.ban.badword_level2, function(badword) {
- var regexp;
- regexp = new RegExp(badword, 'i');
- return name.match(regexp);
- }, name = client.name)) {
- log.warn("BAD NAME LEVEL 2", client.name, client.ip);
- ygopro.stoc_die(client, "${bad_name_level2}");
- } else if (_.any(settings.ban.badword_level1, function(badword) {
- var regexp;
- regexp = new RegExp(badword, 'i');
- return name.match(regexp);
- }, name = client.name)) {
- log.warn("BAD NAME LEVEL 1", client.name, client.ip);
- ygopro.stoc_die(client, "${bad_name_level1}");
- } else if (info.pass.length && !ROOM_validate(info.pass)) {
- ygopro.stoc_die(client, "${invalid_password_room}");
- } else {
- room = ROOM_find_or_create_by_name(info.pass, client.ip);
- if (!room) {
- ygopro.stoc_die(client, "${server_full}");
- } else if (room.error) {
- ygopro.stoc_die(client, room.error);
- } else if (room.started) {
- if (settings.modules.cloud_replay.enable_halfway_watch) {
- client.setTimeout(300000);
- client.rid = _.indexOf(ROOM_all, room);
- client.is_post_watcher = true;
- ygopro.stoc_send_chat_to_room(room, client.name + " ${watch_join}");
- room.watchers.push(client);
- ygopro.stoc_send_chat(client, "${watch_watching}", ygopro.constants.COLORS.BABYBLUE);
- ref1 = room.watcher_buffers;
- for (k = 0, len1 = ref1.length; k < len1; k++) {
- buffer = ref1[k];
- client.write(buffer);
- }
- } else {
- ygopro.stoc_die(client, "${watch_denied}");
- }
- } else {
- client.setTimeout(300000);
- client.rid = _.indexOf(ROOM_all, room);
- room.connect(client);
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement