MCPcopy Create free account
hub / github.com/MaxBittker/rs-sdk / load

Method load

server/engine/src/engine/entity/PlayerLoading.ts:29–164  ·  view source on GitHub ↗
(name: string, sav: Packet, client: ClientSocket | null)

Source from the content-addressed store, hash-verified

27 return crc === Packet.getcrc(sav.data, 0, sav.data.length - 4);
28 }
29
30 static load(name: string, sav: Packet, client: ClientSocket | null) {
31 const hash64 = toBase37(name); // username or email.
32 const name37 = toBase37(name); // always username.
33 const safeName = fromBase37(name37); // always safe username.
34 // Exchange participants use the atomic ledger checkpoint, including after a crash.
35 const checkpoint = playerSaveStore()?.saved(safeName);
36 if (checkpoint) sav = new Packet(checkpoint);
37
38 const player = client ? new NetworkPlayer(safeName, name37, hash64, client) : new Player(safeName, name37, hash64);
39
40 player.lastConnected = World.currentTick;
41 player.lastResponse = World.currentTick;
42
43 if (sav.data.length < 2) {
44 for (let i = 0; i < 21; i++) {
45 player.stats[i] = 0;
46 player.baseLevels[i] = 1;
47 player.levels[i] = 1;
48 }
49
50 // hitpoints starts at level 10
51 player.stats[PlayerStat.HITPOINTS] = getExpByLevel(10);
52 player.baseLevels[PlayerStat.HITPOINTS] = 10;
53 player.levels[PlayerStat.HITPOINTS] = 10;
54 return player;
55 }
56
57 if (sav.g2() !== PlayerLoading.SAV_MAGIC) {
58 throw new Error('Invalid save file');
59 }
60
61 const version = sav.g2();
62 if (version > PlayerLoading.SAV_VERSION) {
63 throw new Error('Unsupported save version');
64 }
65
66 sav.pos = sav.data.length - 4;
67 const crc = sav.g4s();
68 if (crc != Packet.getcrc(sav.data, 0, sav.data.length - 4)) {
69 throw new Error('Incorrect save checksum');
70 }
71
72 sav.pos = 4;
73 player.x = sav.g2();
74 player.z = sav.g2();
75 player.level = sav.g1();
76 for (let i = 0; i < 7; i++) {
77 player.body[i] = sav.g1();
78 if (player.body[i] === 255) {
79 player.body[i] = -1;
80 }
81 }
82 for (let i = 0; i < 5; i++) {
83 player.colors[i] = sav.g1();
84 }
85 player.gender = sav.g1();
86 player.runenergy = sav.g2();

Callers 5

reloadMethod · 0.45
startMethod · 0.45
processLoginsMethod · 0.45
onLoginMessageMethod · 0.45
initMethod · 0.45

Calls 15

toBase37Function · 0.85
fromBase37Function · 0.85
getLevelByExpFunction · 0.85
g4sMethod · 0.80
gVarIntMethod · 0.80
getCombatLevelMethod · 0.80
getExpByLevelFunction · 0.70
g2Method · 0.45
getcrcMethod · 0.45
g1Method · 0.45
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected