Skip to content

Commit db471a5

Browse files
committed
feat: restrict f2p world/area login
1 parent 5179db5 commit db471a5

9 files changed

Lines changed: 49 additions & 6 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE account ADD COLUMN members BOOLEAN NOT NULL DEFAULT 1;

prisma/multiworld/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ model account {
3838
3939
notes String? @db.Text
4040
notes_updated DateTime?
41+
42+
members Boolean @default(true)
4143
}
4244

4345
model session {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE account ADD COLUMN members BOOLEAN NOT NULL DEFAULT 1;

prisma/singleworld/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ model account {
3838
3939
notes String?
4040
notes_updated DateTime?
41+
42+
members Boolean @default(true)
4143
}
4244

4345
// logged in sessions

src/db/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type account = {
2020
staffmodlevel: Generated<number>;
2121
notes: string | null;
2222
notes_updated: string | null;
23+
members: Generated<boolean>;
2324
};
2425
export type account_session = {
2526
id: Generated<number>;

src/engine/World.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,9 +1819,14 @@ class World {
18191819
client.send(Uint8Array.from([16]));
18201820
client.close();
18211821
return;
1822+
} else if (reply === 9) {
1823+
// logging in to p2p on a f2p account
1824+
client.send(Uint8Array.from([12]));
1825+
client.close();
1826+
return;
18221827
}
18231828

1824-
const { account_id, username, lowMemory, reconnecting, staffmodlevel, muted_until } = msg;
1829+
const { account_id, username, lowMemory, reconnecting, staffmodlevel, muted_until, members } = msg;
18251830
const save = msg.save ?? new Uint8Array();
18261831

18271832
// if (reconnecting && !this.getPlayerByUsername(username)) {
@@ -1845,6 +1850,7 @@ class World {
18451850
player.staffModLevel = staffmodlevel;
18461851
player.lowMemory = lowMemory;
18471852
player.muted_until = muted_until ? new Date(muted_until) : null;
1853+
player.members = members;
18481854

18491855
if (this.logoutRequests.has(username)) {
18501856
// already logged in (on another world)
@@ -1853,6 +1859,20 @@ class World {
18531859
return;
18541860
}
18551861

1862+
if (!Environment.NODE_MEMBERS && !this.gameMap.isFreeToPlay(player.x, player.z)) {
1863+
// in a p2p zone when logging into f2p
1864+
if(player.members) {
1865+
client.send(Uint8Array.from([17]));
1866+
client.close();
1867+
this.loginThread.postMessage({
1868+
type: 'player_force_logout',
1869+
username: username
1870+
});
1871+
return;
1872+
}
1873+
player.teleport(3221, 3218, 0);
1874+
}
1875+
18561876
this.newPlayers.add(player);
18571877
client.state = 1;
18581878
} catch (err) {

src/engine/entity/Player.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ export default class Player extends PathingEntity {
321321
lastZone: number = -1;
322322

323323
muted_until: Date | null = null;
324+
members: boolean = true;
324325

325326
constructor(username: string, username37: bigint, hash64: bigint) {
326327
super(0, 3094, 3106, 1, 1, EntityLifeCycle.FOREVER, MoveRestrict.NORMAL, BlockWalk.NPC, MoveStrategy.SMART, InfoProt.PLAYER_FACE_COORD.id, InfoProt.PLAYER_FACE_ENTITY.id); // tutorial island.

src/server/login/LoginClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ export default class LoginClient extends InternalClient {
5151
return { reply: -1, account_id: -1, save: null, muted_until: null };
5252
}
5353

54-
const { response, account_id, staffmodlevel, save, muted_until } = reply.result;
54+
const { response, account_id, staffmodlevel, save, muted_until, members } = reply.result;
5555

5656
return {
5757
reply: response,
5858
account_id,
5959
staffmodlevel,
6060
save: save ? Buffer.from(save, 'base64') : null,
61-
muted_until };
61+
muted_until,
62+
members };
6263
}
6364

6465
// returns true if the login server acknowledged the logout

src/server/login/LoginServer.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ export default class LoginServer {
109109
return;
110110
}
111111

112+
if (Environment.NODE_MEMBERS && !account.members) {
113+
s.send(JSON.stringify({
114+
replyTo,
115+
response: 9
116+
}));
117+
return;
118+
}
119+
112120
if (reconnecting && account.logged_in === nodeId) {
113121
await db.insertInto('session').values({
114122
uuid: socket,
@@ -129,14 +137,16 @@ export default class LoginServer {
129137
staffmodlevel: account.staffmodlevel,
130138
muted_until: account.muted_until,
131139
save: save.toString('base64'),
140+
members: account.members
132141
}));
133142
} else {
134143
s.send(JSON.stringify({
135144
replyTo,
136145
response: 2,
137146
account_id: account.id,
138147
staffmodlevel: account.staffmodlevel,
139-
muted_until: account.muted_until
148+
muted_until: account.muted_until,
149+
members: account.members
140150
}));
141151
}
142152
return;
@@ -182,7 +192,8 @@ export default class LoginServer {
182192
response: 4,
183193
account_id: account.id,
184194
staffmodlevel: account.staffmodlevel,
185-
muted_until: account.muted_until
195+
muted_until: account.muted_until,
196+
members: account.members
186197
}));
187198
return;
188199
}
@@ -194,7 +205,8 @@ export default class LoginServer {
194205
account_id: account.id,
195206
staffmodlevel: account.staffmodlevel,
196207
save: save.toString('base64'),
197-
muted_until: account.muted_until
208+
muted_until: account.muted_until,
209+
members: account.members
198210
}));
199211
} else if (type === 'player_logout') {
200212
const { replyTo, username, save } = msg;

0 commit comments

Comments
 (0)