Skip to content

Commit 7a9310a

Browse files
committed
Fix Matchmaker hotpatching
Matchmaker is now globally accessible under Ladders, rather than needing to be manually required. This fixes a crash when hotpatching certain things.
1 parent 7ba80db commit 7a9310a

File tree

6 files changed

+9
-21
lines changed

6 files changed

+9
-21
lines changed

chat-commands.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
const crypto = require('crypto');
2121
const FS = require('./fs');
2222

23-
const Matchmaker = require('./ladders-matchmaker').matchmaker;
24-
2523
const MAX_REASON_LENGTH = 300;
2624
const MUTE_LENGTH = 7 * 60 * 1000;
2725
const HOURMUTE_LENGTH = 60 * 60 * 1000;
@@ -2112,7 +2110,7 @@ exports.commands = {
21122110

21132111
let entry = targetUser.name + " was forced to choose a new name by " + user.name + (reason ? ": " + reason : "");
21142112
this.privateModCommand("(" + entry + ")");
2115-
Matchmaker.cancelSearch(targetUser);
2113+
Ladders.matchmaker.cancelSearch(targetUser);
21162114
targetUser.resetName(true);
21172115
targetUser.send("|nametaken||" + user.name + " considers your name inappropriate" + (reason ? ": " + reason : "."));
21182116
return true;
@@ -2142,7 +2140,7 @@ exports.commands = {
21422140
}
21432141

21442142
this.globalModlog("NAMELOCK", targetUser, ` by ${user.name}${reasonText}`);
2145-
Matchmaker.cancelSearch(targetUser);
2143+
Ladders.matchmaker.cancelSearch(targetUser);
21462144
Punishments.namelock(targetUser, null, null, reason);
21472145
targetUser.popup(`|modal|${user.name} has locked your name and you can't change names anymore${reasonText}`);
21482146
return true;
@@ -3301,9 +3299,9 @@ exports.commands = {
33013299
return false;
33023300
}
33033301
}
3304-
Matchmaker.searchBattle(user, target);
3302+
Ladders.matchmaker.searchBattle(user, target);
33053303
} else {
3306-
Matchmaker.cancelSearch(user, target);
3304+
Ladders.matchmaker.cancelSearch(user, target);
33073305
}
33083306
},
33093307

ladders-remote.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'use strict';
1616

1717
let Ladders = module.exports = getLadder;
18+
Object.assign(Ladders, require('./ladders-matchmaker'));
1819

1920
Ladders.get = Ladders;
2021
Ladders.formatsListPrefix = '';

ladders.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
const FS = require('./fs');
1919

2020
let Ladders = module.exports = getLadder;
21+
Object.assign(Ladders, require('./ladders-matchmaker'));
2122

2223
Ladders.get = Ladders;
2324

rooms.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const REPORT_USER_STATS_INTERVAL = 10 * 60 * 1000;
1818
const CRASH_REPORT_THROTTLE = 60 * 60 * 1000;
1919

2020
const FS = require('./fs');
21-
const Matchmaker = require('./ladders-matchmaker').matchmaker;
2221

2322
let Rooms = module.exports = getRoom;
2423

@@ -1455,8 +1454,8 @@ Rooms.createBattle = function (format, options) {
14551454
if (p1 === p2) throw new Error(`Players can't battle themselves`);
14561455
if (!p1) throw new Error(`p1 required`);
14571456
if (!p2) throw new Error(`p2 required`);
1458-
Matchmaker.cancelSearch(p1);
1459-
Matchmaker.cancelSearch(p2);
1457+
Ladders.matchmaker.cancelSearch(p1);
1458+
Ladders.matchmaker.cancelSearch(p2);
14601459

14611460
if (Rooms.global.lockdown === true) {
14621461
p1.popup("The server is restarting. Battles will be available again in a few minutes.");

test/application/rooms.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const assert = require('assert');
44

5-
const {matchmaker, Matchmaker} = require('../../ladders-matchmaker');
65
const {User} = require('../../dev-tools/users-utils');
76

87
describe('Rooms features', function () {
@@ -27,11 +26,6 @@ describe('Rooms features', function () {
2726
const packedTeam = 'Weavile||lifeorb||swordsdance,knockoff,iceshard,iciclecrash|Jolly|,252,,,4,252|||||';
2827

2928
let room;
30-
before(function () {
31-
Rooms.global.ladderIpLog.end();
32-
clearInterval(matchmaker.periodicMatchInterval);
33-
matchmaker.periodicMatchInterval = null;
34-
});
3529
afterEach(function () {
3630
Users.users.forEach(user => {
3731
room.onLeave(user);
@@ -40,9 +34,6 @@ describe('Rooms features', function () {
4034
});
4135
if (room) room.destroy();
4236
});
43-
after(function () {
44-
Object.assign(matchmaker, new Matchmaker());
45-
});
4637

4738
it('should allow two users to join the battle', function () {
4839
let p1 = new User();

users.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ const PERMALOCK_CACHE_TIME = 30 * 24 * 60 * 60 * 1000;
3434

3535
const FS = require('./fs');
3636

37-
const Matchmaker = require('./ladders-matchmaker').matchmaker;
38-
3937
let Users = module.exports = getUser;
4038

4139
/*********************************************************
@@ -1343,7 +1341,7 @@ class User {
13431341
}));
13441342
}
13451343
cancelSearch(format) {
1346-
return Matchmaker.cancelSearch(this, format);
1344+
return Ladders.matchmaker.cancelSearch(this, format);
13471345
}
13481346
makeChallenge(user, format, team/*, isPrivate*/) {
13491347
user = getUser(user);

0 commit comments

Comments
 (0)