Skip to content

Commit 3162598

Browse files
committedApr 14, 2024
update spaces, add readme
1 parent 817e85b commit 3162598

39 files changed

+771
-770
lines changed
 

‎GameServer/ClientPackets/CharacterCreate.js

+44-44
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,64 @@ const characterTemplates = require('./../data/characterTemplates.json');
66
const players = require('./../Models/Players');
77

88
class CharacterCreate {
9-
constructor(packet, client) {
9+
constructor(packet, client) {
1010
this._client = client;
11-
this._data = new ClientPacket(packet);
12-
this._data.readC()
13-
.readS()
14-
.readD()
15-
.readD()
16-
.readD()
17-
.readD()
18-
.readD()
19-
.readD()
20-
.readD()
21-
.readD()
22-
.readD()
23-
.readD()
24-
.readD()
25-
.readD();
26-
27-
this._init();
28-
}
11+
this._data = new ClientPacket(packet);
12+
this._data.readC()
13+
.readS()
14+
.readD()
15+
.readD()
16+
.readD()
17+
.readD()
18+
.readD()
19+
.readD()
20+
.readD()
21+
.readD()
22+
.readD()
23+
.readD()
24+
.readD()
25+
.readD();
26+
27+
this._init();
28+
}
2929

3030
get name() {
31-
return this._data.getData()[1];
32-
}
31+
return this._data.getData()[1];
32+
}
3333

34-
get race() {
35-
return this._data.getData()[2];
36-
}
34+
get race() {
35+
return this._data.getData()[2];
36+
}
3737

38-
get gender() {
39-
return this._data.getData()[3];
40-
}
38+
get gender() {
39+
return this._data.getData()[3];
40+
}
4141

42-
get classId() {
43-
return this._data.getData()[4];
44-
}
42+
get classId() {
43+
return this._data.getData()[4];
44+
}
4545

46-
get hairStyle() {
47-
return this._data.getData()[11];
48-
}
46+
get hairStyle() {
47+
return this._data.getData()[11];
48+
}
4949

50-
get hairColor() {
51-
return this._data.getData()[12];
52-
}
50+
get hairColor() {
51+
return this._data.getData()[12];
52+
}
5353

54-
get face() {
55-
return this._data.getData()[13];
56-
}
54+
get face() {
55+
return this._data.getData()[13];
56+
}
5757

5858
_checkNameLetters(name) {
5959
const regexp = /^[0-9A-Za-z]*$/gi;
6060

61-
if (regexp.test(name)) {
61+
if (regexp.test(name)) {
6262
return true;
6363
} else {
6464
return false;
6565
}
66-
}
66+
}
6767

6868
async checkMaxNumberCharacters(login) {
6969
const characters = await database.getCharactersByLogin(login);
@@ -76,7 +76,7 @@ class CharacterCreate {
7676
}
7777
}
7878

79-
async _init() {
79+
async _init() {
8080
const player = players.getPlayerByClient(this._client);
8181

8282
if (await this.checkMaxNumberCharacters(player.login)) {
@@ -112,7 +112,7 @@ class CharacterCreate {
112112
character.objectId = await database.getNextObjectId();
113113
character.login = player.login;
114114
character.maximumHp = character.hp;
115-
character.maximumMp = character.mp;
115+
character.maximumMp = character.mp;
116116
character.gender = this.gender;
117117
character.hairStyle = this.hairStyle;
118118
character.hairColor = this.hairColor;
@@ -152,7 +152,7 @@ class CharacterCreate {
152152

153153
this._client.sendPacket(new serverPackets.CharacterCreateSuccess());
154154
this._client.sendPacket(new serverPackets.CharacterSelectInfo(player.login, characters));
155-
}
155+
}
156156
}
157157

158158
module.exports = CharacterCreate;

‎GameServer/ClientPackets/CharacterDelete.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ const database = require('./../../Database');
44
const players = require('./../Models/Players');
55

66
class CharacterDelete {
7-
constructor(packet, client) {
7+
constructor(packet, client) {
88
this._client = client;
9-
this._data = new ClientPacket(packet);
10-
this._data.readC()
9+
this._data = new ClientPacket(packet);
10+
this._data.readC()
1111
.readD();
1212

13-
this._init();
14-
}
13+
this._init();
14+
}
1515

1616
get characterSlot () {
17-
return this._data.getData()[1];
18-
}
17+
return this._data.getData()[1];
18+
}
1919

20-
async _init() {
20+
async _init() {
2121
const player = players.getPlayerByClient(this._client);
2222
const characters = await database.getCharactersByLogin(player.login);
2323
const character = characters[this.characterSlot];
@@ -26,7 +26,7 @@ class CharacterDelete {
2626

2727
this._client.sendPacket(new serverPackets.CharacterDeleteOk());
2828
this._client.sendPacket(new serverPackets.CharacterSelectInfo(player.login, await database.getCharactersByLogin(player.login))); // fix?
29-
}
29+
}
3030
}
3131

3232
module.exports = CharacterDelete;

‎GameServer/ClientPackets/CharacterSelected.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ const database = require('./../../Database');
44
const players = require('./../Models/Players');
55

66
class CharacterSelected {
7-
constructor(packet, client) {
7+
constructor(packet, client) {
88
this._client = client;
9-
this._data = new ClientPacket(packet);
10-
this._data.readC()
9+
this._data = new ClientPacket(packet);
10+
this._data.readC()
1111
.readD();
1212

13-
this._init();
14-
}
13+
this._init();
14+
}
1515

1616
get characterSlot () {
17-
return this._data.getData()[1];
18-
}
17+
return this._data.getData()[1];
18+
}
1919

20-
async _init() {
20+
async _init() {
2121
const player = players.getPlayerByClient(this._client);
2222
const characters = await database.getCharactersByLogin(player.login);
2323
const character = characters[this.characterSlot];
2424

2525
player.update(character);
2626
this._client.sendPacket(new serverPackets.CharacterSelected(character));
27-
}
27+
}
2828
}
2929

3030
module.exports = CharacterSelected;

‎GameServer/ClientPackets/EnterWorld.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ const ClientPacket = require("./ClientPacket");
33
const players = require('./../Models/Players');
44

55
class EnterWorld {
6-
constructor(packet, client) {
6+
constructor(packet, client) {
77
this._client = client;
8-
this._data = new ClientPacket(packet);
9-
this._data.readC();
8+
this._data = new ClientPacket(packet);
9+
this._data.readC();
1010

11-
this._init();
12-
}
11+
this._init();
12+
}
1313

14-
async _init() {
14+
async _init() {
1515
const player = players.getPlayerByClient(this._client);
1616

1717
this._client.sendPacket(new serverPackets.UserInfo(player));
1818
this._client.sendPacket(new serverPackets.SunRise());
19-
}
19+
}
2020
}
2121

2222
module.exports = EnterWorld;

‎GameServer/ClientPackets/MoveBackwardToLocation.js

+41-41
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,56 @@ const ClientPacket = require("./ClientPacket");
33
const players = require('./../Models/Players');
44

55
class MoveBackwardToLocation {
6-
constructor(packet, client) {
6+
constructor(packet, client) {
77
this._client = client;
8-
this._data = new ClientPacket(packet);
9-
this._data.readC()
10-
.readD()
11-
.readD()
12-
.readD()
13-
.readD()
14-
.readD()
15-
.readD();
8+
this._data = new ClientPacket(packet);
9+
this._data.readC()
10+
.readD()
11+
.readD()
12+
.readD()
13+
.readD()
14+
.readD()
15+
.readD();
1616

17-
this._init();
18-
}
17+
this._init();
18+
}
1919

2020
get targetX() {
21-
return this._data.getData()[1];
22-
}
23-
get targetY() {
24-
return this._data.getData()[2];
25-
}
26-
get targetZ() {
27-
return this._data.getData()[3];
28-
}
29-
get originX() {
30-
return this._data.getData()[4];
31-
}
32-
get originY() {
33-
return this._data.getData()[5];
34-
}
35-
get originZ() {
36-
return this._data.getData()[6];
37-
}
21+
return this._data.getData()[1];
22+
}
23+
get targetY() {
24+
return this._data.getData()[2];
25+
}
26+
get targetZ() {
27+
return this._data.getData()[3];
28+
}
29+
get originX() {
30+
return this._data.getData()[4];
31+
}
32+
get originY() {
33+
return this._data.getData()[5];
34+
}
35+
get originZ() {
36+
return this._data.getData()[6];
37+
}
3838

39-
_init() {
39+
_init() {
4040
const player = players.getPlayerByClient(this._client);
4141
const positions = {
42-
target: {
43-
x: this.targetX,
44-
y: this.targetY,
45-
z: this.targetZ
46-
},
47-
origin: {
48-
x: this.originX,
49-
y: this.originY,
50-
z: this.originZ
51-
}
52-
}
42+
target: {
43+
x: this.targetX,
44+
y: this.targetY,
45+
z: this.targetZ
46+
},
47+
origin: {
48+
x: this.originX,
49+
y: this.originY,
50+
z: this.originZ
51+
}
52+
}
5353

5454
this._client.sendPacket(new serverPackets.MoveToLocation(positions, player.objectId));
55-
}
55+
}
5656
}
5757

5858
module.exports = MoveBackwardToLocation;

‎GameServer/ClientPackets/NewCharacter.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ const ClientPacket = require("./ClientPacket");
33
const characterTemplates = require('./../data/characterTemplates.json');
44

55
class NewCharacter {
6-
constructor(packet, client) {
6+
constructor(packet, client) {
77
this._client = client;
8-
this._data = new ClientPacket(packet);
9-
this._data.readC();
8+
this._data = new ClientPacket(packet);
9+
this._data.readC();
1010

11-
this._init();
12-
}
11+
this._init();
12+
}
1313

14-
_init() {
14+
_init() {
1515
this._client.sendPacket(new serverPackets.CharacterTemplates(characterTemplates));
16-
}
16+
}
1717
}
1818

1919
module.exports = NewCharacter;

‎GameServer/ClientPackets/ProtocolVersion.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ const ClientPacket = require("./ClientPacket");
33
const config = require('./../../config');
44

55
class ProtocolVersion {
6-
constructor(packet, client) {
6+
constructor(packet, client) {
77
this._client = client;
8-
this._data = new ClientPacket(packet);
9-
this._data.readC()
10-
.readD();
8+
this._data = new ClientPacket(packet);
9+
this._data.readC()
10+
.readD();
1111

12-
this._init();
13-
}
12+
this._init();
13+
}
1414

15-
get version() {
16-
return this._data.getData()[1];
17-
}
15+
get version() {
16+
return this._data.getData()[1];
17+
}
1818

19-
_init() {
19+
_init() {
2020
if (this.version === config.main.PROTOCOL_VERSION_CLIENT) {
2121
this._client.sendPacket(new serverPackets.CryptInit(config.main.encryptionKeys.XOR), false);
2222
}
23-
}
23+
}
2424
}
2525

2626
module.exports = ProtocolVersion;

‎GameServer/ClientPackets/RequestAuthLogin.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,42 @@ const database = require('./../../Database');
44
const players = require('./../Models/Players');
55

66
class RequestAuthLogin {
7-
constructor(packet, client) {
7+
constructor(packet, client) {
88
this._client = client;
9-
this._data = new ClientPacket(packet);
10-
this._data.readC()
9+
this._data = new ClientPacket(packet);
10+
this._data.readC()
1111
.readS()
1212
.readD()
1313
.readD()
1414
.readD()
1515
.readD();
1616

17-
this._init();
18-
}
17+
this._init();
18+
}
1919

2020
get login() {
21-
return this._data.getData()[1];
22-
}
21+
return this._data.getData()[1];
22+
}
2323

2424
get sessionKey1() {
25-
const sessionKey1 = [];
25+
const sessionKey1 = [];
2626

27-
sessionKey1[0] = this._data.getData()[4].toString(16);
28-
sessionKey1[1] = this._data.getData()[5].toString(16);
27+
sessionKey1[0] = this._data.getData()[4].toString(16);
28+
sessionKey1[1] = this._data.getData()[5].toString(16);
2929

30-
return sessionKey1;
31-
}
30+
return sessionKey1;
31+
}
3232

3333
get sessionKey2() {
34-
const sessionKey2 = [];
34+
const sessionKey2 = [];
3535

36-
sessionKey2[0] = this._data.getData()[3].toString(16);
37-
sessionKey2[1] = this._data.getData()[2].toString(16);
36+
sessionKey2[0] = this._data.getData()[3].toString(16);
37+
sessionKey2[1] = this._data.getData()[2].toString(16);
3838

39-
return sessionKey2;
40-
}
39+
return sessionKey2;
40+
}
4141

42-
async _init() {
42+
async _init() {
4343
const player = players.getPlayerByClient(this._client);
4444
const characters = await database.getCharactersByLogin(this.login);
4545

@@ -48,7 +48,7 @@ class RequestAuthLogin {
4848
});
4949

5050
this._client.sendPacket(new serverPackets.CharacterSelectInfo(this.login, characters));
51-
}
51+
}
5252
}
5353

5454
module.exports = RequestAuthLogin;

‎GameServer/ClientPackets/RequestQuestList.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ const serverPackets = require('./../ServerPackets/serverPackets');
22
const ClientPacket = require("./ClientPacket");
33

44
class RequestQuestList {
5-
constructor(packet, client) {
5+
constructor(packet, client) {
66
this._client = client;
7-
this._data = new ClientPacket(packet);
8-
this._data.readC();
7+
this._data = new ClientPacket(packet);
8+
this._data.readC();
99

10-
this._init();
11-
}
10+
this._init();
11+
}
1212

13-
_init() {
13+
_init() {
1414
this._client.sendPacket(new serverPackets.QuestList());
15-
}
15+
}
1616
}
1717

1818
module.exports = RequestQuestList;

‎GameServer/Models/Character.js

+66-66
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
11
class Character {
2-
constructor() {
3-
this.objectId = null;
4-
this.login = null;
5-
this.name = null;
6-
this.title = "";
7-
this.level = 1;
8-
this.gender = null;
9-
this.hairStyle = null;
10-
this.hairColor = null;
11-
this.face = null;
12-
this.heading = 0;
13-
this.accessLevel = 0;
14-
this.online = false;
15-
this.onlineTime = 0;
16-
this.clanId = 0;
2+
constructor() {
3+
this.objectId = null;
4+
this.login = null;
5+
this.name = null;
6+
this.title = "";
7+
this.level = 1;
8+
this.gender = null;
9+
this.hairStyle = null;
10+
this.hairColor = null;
11+
this.face = null;
12+
this.heading = 0;
13+
this.accessLevel = 0;
14+
this.online = false;
15+
this.onlineTime = 0;
16+
this.clanId = 0;
1717
this.clanLeader = 0;
1818
this.clanCrestId = 0;
1919
this.allianceId = 0;
2020
this.allianceCrestId = 0;
2121
this.gm = 0;
2222
this.privateStoreType = 0;
23-
this.exp = 0;
24-
this.sp = 0;
23+
this.exp = 0;
24+
this.sp = 0;
2525

26-
this.pvp = 0;
27-
this.pk = 0;
28-
this.karma = 0;
26+
this.pvp = 0;
27+
this.pk = 0;
28+
this.karma = 0;
2929

30-
this.classId = null;
31-
this.className = null;
32-
this.raceId = null;
33-
34-
this.str = null;
35-
this.dex = null;
36-
this.con = null;
37-
this.int = null;
38-
this.wit = null;
39-
this.men = null;
40-
this.hp = null;
41-
this.maximumHp = null;
42-
this.mp = null;
43-
this.maximumMp = null;
30+
this.classId = null;
31+
this.className = null;
32+
this.raceId = null;
33+
34+
this.str = null;
35+
this.dex = null;
36+
this.con = null;
37+
this.int = null;
38+
this.wit = null;
39+
this.men = null;
40+
this.hp = null;
41+
this.maximumHp = null;
42+
this.mp = null;
43+
this.maximumMp = null;
4444

45-
this.pAtk = null;
46-
this.pDef = null;
47-
this.mAtk = null;
48-
this.mDef = null;
49-
this.pSpd = null;
50-
this.mSpd = null;
51-
this.accuracy = null;
52-
this.critical = null;
53-
this.evasion = null;
54-
this.runSpeed = null;
55-
this.walkSpeed = null;
56-
this.swimSpeed = null;
57-
this.maximumLoad = null;
58-
59-
this.x = null;
60-
this.y = null;
61-
this.z = null;
62-
63-
this.canCraft = null;
64-
65-
this.maleMovementMultiplier = null;
66-
this.maleAttackSpeedMultiplier = null;
67-
this.maleCollisionRadius = null;
68-
this.maleCollisionHeight = null;
69-
70-
this.femaleMovementMultiplier = null;
71-
this.femaleAttackSpeedMultiplier = null;
72-
this.femaleCollisionRadius = null;
73-
this.femaleCollisionHeight = null;
74-
75-
this.items = [];
45+
this.pAtk = null;
46+
this.pDef = null;
47+
this.mAtk = null;
48+
this.mDef = null;
49+
this.pSpd = null;
50+
this.mSpd = null;
51+
this.accuracy = null;
52+
this.critical = null;
53+
this.evasion = null;
54+
this.runSpeed = null;
55+
this.walkSpeed = null;
56+
this.swimSpeed = null;
57+
this.maximumLoad = null;
58+
59+
this.x = null;
60+
this.y = null;
61+
this.z = null;
62+
63+
this.canCraft = null;
64+
65+
this.maleMovementMultiplier = null;
66+
this.maleAttackSpeedMultiplier = null;
67+
this.maleCollisionRadius = null;
68+
this.maleCollisionHeight = null;
69+
70+
this.femaleMovementMultiplier = null;
71+
this.femaleAttackSpeedMultiplier = null;
72+
this.femaleCollisionRadius = null;
73+
this.femaleCollisionHeight = null;
74+
75+
this.items = [];
7676

7777
this.underwear = { objectId: 0, itemId: 0 }
7878
this.ear = {
@@ -95,7 +95,7 @@ class Character {
9595
this.legs = { objectId: 0, itemId: 0 }
9696
this.feet = { objectId: 0, itemId: 0 }
9797
this.back = { objectId: 0, itemId: 0 }
98-
}
98+
}
9999

100100
static create(template) {
101101
const character = new Character();

‎GameServer/ServerPackets/CharacterCreateFail.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class CharacterCreateFail {
4-
constructor(reason) {
4+
constructor(reason) {
55
this._packet = new ServerPacket(5);
66
this._packet.writeC(0x26)
77
.writeD(reason);

‎GameServer/ServerPackets/CharacterCreateSuccess.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class CharacterCreateSuccess {
4-
constructor() {
4+
constructor() {
55
this._packet = new ServerPacket(5);
66
this._packet.writeC(0x25)
77
.writeD(0x01);

‎GameServer/ServerPackets/CharacterDeleteOk.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class CharacterDeleteOk {
4-
constructor() {
4+
constructor() {
55
this._packet = new ServerPacket(1);
66
this._packet.writeC(0x33);
77
}

‎GameServer/ServerPackets/CharacterSelectInfo.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class CharacterSelectInfo {
4-
constructor(login, characters) {
4+
constructor(login, characters) {
55
this._packet = new ServerPacket(characters ? characters.length * 400 : 10); // fix
66
this._packet.writeC(0x1f)
77

@@ -12,20 +12,20 @@ class CharacterSelectInfo {
1212
this._packet.writeS(characters[i].name)
1313
.writeD(characters[i].objectId)
1414
.writeS(login)
15-
.writeD(0x55555555) // getSessionId
16-
.writeD(characters[i].clanId)
15+
.writeD(0x55555555) // getSessionId
16+
.writeD(characters[i].clanId)
1717

1818
.writeD(0x00)
1919

2020
.writeD(characters[i].gender)
21-
.writeD(characters[i].raceId)
22-
.writeD(characters[i].classId)
21+
.writeD(characters[i].raceId)
22+
.writeD(characters[i].classId)
2323

2424
.writeD(0x01)
2525

2626
.writeD(characters[i].x) // no effect ?
27-
.writeD(characters[i].y) // no effect ?
28-
.writeD(characters[i].z) // no effect ?
27+
.writeD(characters[i].y) // no effect ?
28+
.writeD(characters[i].z) // no effect ?
2929

3030
.writeF(characters[i].hp)
3131
.writeF(characters[i].mp)
@@ -84,7 +84,7 @@ class CharacterSelectInfo {
8484
.writeD(characters[i].face)
8585

8686
.writeF(characters[i].maximumHp)
87-
.writeF(characters[i].maximumMp)
87+
.writeF(characters[i].maximumMp)
8888

8989
.writeD(0x00); //writeD(charInfoPackage.getDeleteTimer()); // days left before delete .. if != 0 then char is inactive
9090
}

‎GameServer/ServerPackets/CharacterSelected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class CharacterSelected {
4-
constructor(character) {
4+
constructor(character) {
55
this._packet = new ServerPacket(230 + ServerPacket.strlen(character.name) + ServerPacket.strlen(character.title)); // fix
66
this._packet.writeC(0x21)
77
.writeS(character.name)

‎GameServer/ServerPackets/CharacterTemplates.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class CharacterTemplates {
4-
constructor(characters) {
4+
constructor(characters) {
55
this._packet = new ServerPacket(85 * characters.length);
66
this._packet.writeC(0x23)
77
.writeD(characters.length);

‎GameServer/ServerPackets/CryptInit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class CryptInit {
4-
constructor(key) {
4+
constructor(key) {
55
this._packet = new ServerPacket(10);
66
this._packet.writeC(0x00)
77
.writeC(0x01) // 0x00 - protocol version is different, 0x01 - ok

‎GameServer/ServerPackets/MoveToLocation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class MoveToLocation {
4-
constructor(positions, objectId) {
4+
constructor(positions, objectId) {
55
this._packet = new ServerPacket(29);
66
this._packet.writeC(0x01)
77
.writeD(objectId)

‎GameServer/ServerPackets/QuestList.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class QuestList {
4-
constructor() {
4+
constructor() {
55
this._packet = new ServerPacket(10);
66
this._packet.writeC(0x98)
77
.writeH(0x00)

‎GameServer/ServerPackets/ServerPacket.js

+48-48
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,54 @@
55
// writeS - string
66

77
class ServerPacket {
8-
constructor(size) {
9-
this._buffer = Buffer.alloc(size + 4 + (size + 4) % 8); // (size + 4) % 8 - checksum. the packet is a multiple of 8.
10-
this._offset = 0;
11-
}
12-
13-
writeC(value) {
14-
this._buffer.writeUInt8(value, this._offset);
15-
this._offset++;
16-
17-
return this;
18-
}
19-
20-
writeH(value) {
21-
this._buffer.writeUInt16LE(value, this._offset);
22-
this._offset += 2;
23-
24-
return this;
25-
}
26-
27-
writeD(value) {
28-
this._buffer.writeInt32LE(value, this._offset);
29-
this._offset += 4;
30-
31-
return this;
32-
}
33-
34-
writeF(value) {
35-
this._buffer.writeDoubleLE(value, this._offset);
36-
this._offset += 8;
37-
38-
return this;
39-
}
40-
41-
writeS(string) {
42-
this._buffer.write(string, this._offset, 'ucs2');
43-
this._offset += Buffer.byteLength(string, 'ucs2') + 2;
44-
this._buffer.writeInt16LE(0, this._offset - 2);
45-
46-
return this;
47-
}
48-
49-
getBuffer() {
50-
return this._buffer;
51-
}
52-
53-
static strlen(str) {
54-
return Buffer.byteLength(str, 'ucs2') + 2;
55-
}
8+
constructor(size) {
9+
this._buffer = Buffer.alloc(size + 4 + (size + 4) % 8); // (size + 4) % 8 - checksum. the packet is a multiple of 8.
10+
this._offset = 0;
11+
}
12+
13+
writeC(value) {
14+
this._buffer.writeUInt8(value, this._offset);
15+
this._offset++;
16+
17+
return this;
18+
}
19+
20+
writeH(value) {
21+
this._buffer.writeUInt16LE(value, this._offset);
22+
this._offset += 2;
23+
24+
return this;
25+
}
26+
27+
writeD(value) {
28+
this._buffer.writeInt32LE(value, this._offset);
29+
this._offset += 4;
30+
31+
return this;
32+
}
33+
34+
writeF(value) {
35+
this._buffer.writeDoubleLE(value, this._offset);
36+
this._offset += 8;
37+
38+
return this;
39+
}
40+
41+
writeS(string) {
42+
this._buffer.write(string, this._offset, 'ucs2');
43+
this._offset += Buffer.byteLength(string, 'ucs2') + 2;
44+
this._buffer.writeInt16LE(0, this._offset - 2);
45+
46+
return this;
47+
}
48+
49+
getBuffer() {
50+
return this._buffer;
51+
}
52+
53+
static strlen(str) {
54+
return Buffer.byteLength(str, 'ucs2') + 2;
55+
}
5656
}
5757

5858
module.exports = ServerPacket;

‎GameServer/ServerPackets/SunRise.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class SunRise {
4-
constructor() {
4+
constructor() {
55
this._packet = new ServerPacket(1);
66
this._packet.writeC(0x28);
77
}

‎GameServer/ServerPackets/SunSet.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class SunSet {
4-
constructor() {
4+
constructor() {
55
this._packet = new ServerPacket(1);
66
this._packet.writeC(0x29);
77
}

‎GameServer/ServerPackets/UserInfo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class UserInfo {
4-
constructor(player) {
4+
constructor(player) {
55
this._packet = new ServerPacket(600 + ServerPacket.strlen(player.name));
66
this._packet.writeC(0x04)
77
.writeD(player.x)

‎GameServer/libs/XOR.js

+55-55
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
11
class XOR {
2-
constructor(key) {
3-
this.decryptKey = Buffer.from(key);
4-
this.encryptKey = Buffer.from(key);
5-
}
2+
constructor(key) {
3+
this.decryptKey = Buffer.from(key);
4+
this.encryptKey = Buffer.from(key);
5+
}
66

7-
decrypt(data) {
8-
let temp = 0;
9-
let count = 0;
10-
11-
for (let i = 0; i < data.length; ++i) {
12-
if(count == 8) {
7+
decrypt(data) {
8+
let temp = 0;
9+
let count = 0;
10+
11+
for (let i = 0; i < data.length; ++i) {
12+
if(count == 8) {
1313
count = 0;
1414
}
15-
16-
let temp2 = data[i] & 0xff;
17-
15+
16+
let temp2 = data[i] & 0xff;
17+
1818
data[i] = (temp2 ^ (this.decryptKey[count]) ^ temp);
19-
temp = temp2;
20-
count++;
21-
}
19+
temp = temp2;
20+
count++;
21+
}
2222

23-
let old = this.decryptKey[0] & 0xff;
24-
23+
let old = this.decryptKey[0] & 0xff;
24+
2525
old |= this.decryptKey[1] << 8 & 0xff00;
26-
old |= this.decryptKey[2] << 0x10 & 0xff0000;
27-
old |= this.decryptKey[3] << 0x18 & 0xff000000;
28-
29-
old += data.length;
30-
31-
this.decryptKey[0] = (old & 0xff);
32-
this.decryptKey[1] = (old >> 0x08 & 0xff);
33-
this.decryptKey[2] = (old >> 0x10 & 0xff);
34-
this.decryptKey[3] = (old >> 0x18 & 0xff);
35-
36-
return data;
37-
}
26+
old |= this.decryptKey[2] << 0x10 & 0xff0000;
27+
old |= this.decryptKey[3] << 0x18 & 0xff000000;
28+
29+
old += data.length;
30+
31+
this.decryptKey[0] = (old & 0xff);
32+
this.decryptKey[1] = (old >> 0x08 & 0xff);
33+
this.decryptKey[2] = (old >> 0x10 & 0xff);
34+
this.decryptKey[3] = (old >> 0x18 & 0xff);
35+
36+
return data;
37+
}
3838

39-
encrypt(data) {
40-
let temp = 0;
41-
let count = 0;
42-
43-
for (let i = 0; i < data.length; ++i) {
44-
if(count == 8) {
39+
encrypt(data) {
40+
let temp = 0;
41+
let count = 0;
42+
43+
for (let i = 0; i < data.length; ++i) {
44+
if(count == 8) {
4545
count = 0;
4646
}
47-
48-
let temp2 = data[i] & 0xff;
49-
47+
48+
let temp2 = data[i] & 0xff;
49+
5050
data[i] = (temp2 ^ (this.encryptKey[count]) ^ temp);
51-
temp = data[i];
52-
count++;
53-
}
51+
temp = data[i];
52+
count++;
53+
}
5454

55-
let old = this.encryptKey[0] & 0xff;
56-
55+
let old = this.encryptKey[0] & 0xff;
56+
5757
old |= this.encryptKey[1] << 8 & 0xff00;
58-
old |= this.encryptKey[2] << 0x10 & 0xff0000;
59-
old |= this.encryptKey[3] << 0x18 & 0xff000000;
60-
61-
old += data.length;
62-
63-
this.encryptKey[0] = (old & 0xff);
64-
this.encryptKey[1] = (old >> 0x08 & 0xff);
65-
this.encryptKey[2] = (old >> 0x10 & 0xff);
66-
this.encryptKey[3] = (old >> 0x18 & 0xff);
58+
old |= this.encryptKey[2] << 0x10 & 0xff0000;
59+
old |= this.encryptKey[3] << 0x18 & 0xff000000;
60+
61+
old += data.length;
62+
63+
this.encryptKey[0] = (old & 0xff);
64+
this.encryptKey[1] = (old >> 0x08 & 0xff);
65+
this.encryptKey[2] = (old >> 0x10 & 0xff);
66+
this.encryptKey[3] = (old >> 0x18 & 0xff);
6767

68-
return data;
69-
}
68+
return data;
69+
}
7070
}
7171

7272
module.exports = XOR;

‎LoginServer/ClientPackets/RequestAuthLogin.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ const ClientPacket = require("./ClientPacket");
33
const database = require('./../../Database');
44

55
class RequestAuthLogin {
6-
constructor(packet, client) {
6+
constructor(packet, client) {
77
this._client = client;
8-
this._data = new ClientPacket(packet);
9-
this._data.readC()
10-
.readB(14)
11-
.readB(16);
8+
this._data = new ClientPacket(packet);
9+
this._data.readC()
10+
.readB(14)
11+
.readB(16);
1212

13-
this._init();
14-
}
13+
this._init();
14+
}
1515

16-
get login() {
17-
return this._data.getData()[1].toString("ascii").replace(/\u0000/gi, "").toLowerCase();
18-
}
16+
get login() {
17+
return this._data.getData()[1].toString("ascii").replace(/\u0000/gi, "").toLowerCase();
18+
}
1919

20-
get password() {
21-
return this._data.getData()[2].toString("ascii").replace(/\u0000/gi, "").toLowerCase();
22-
}
20+
get password() {
21+
return this._data.getData()[2].toString("ascii").replace(/\u0000/gi, "").toLowerCase();
22+
}
2323

24-
async _init() {
24+
async _init() {
2525
const user = await database.getAccountByLogin(this.login);
2626

2727
if (!user) {
@@ -37,7 +37,7 @@ class RequestAuthLogin {
3737
}
3838

3939
this._client.sendPacket(new serverPackets.LoginOk([0x00000000, 0x00000000]))
40-
}
40+
}
4141
}
4242

4343
module.exports = RequestAuthLogin;

‎LoginServer/ClientPackets/RequestServerList.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ const ClientPacket = require("./ClientPacket");
33
const config = require('./../../config');
44

55
class RequestServerList {
6-
constructor(packet, client) {
6+
constructor(packet, client) {
77
this._client = client;
8-
this._data = new ClientPacket(packet);
9-
this._data.readC()
8+
this._data = new ClientPacket(packet);
9+
this._data.readC()
1010
.readD()
1111
.readD();
1212

13-
this._init();
14-
}
13+
this._init();
14+
}
1515

1616
get sessionKey1() {
17-
const sessionKey1 = [];
17+
const sessionKey1 = [];
1818

19-
sessionKey1[0] = this._data.getData()[1].toString(16);
20-
sessionKey1[1] = this._data.getData()[2].toString(16);
19+
sessionKey1[0] = this._data.getData()[1].toString(16);
20+
sessionKey1[1] = this._data.getData()[2].toString(16);
2121

22-
return sessionKey1;
23-
}
22+
return sessionKey1;
23+
}
2424

25-
_init() {
25+
_init() {
2626
this._client.sendPacket(new serverPackets.ServerList(config.gameserver.host, config.gameserver.port));
27-
}
27+
}
2828
}
2929

3030
module.exports = RequestServerList;

‎LoginServer/ClientPackets/RequestServerLogin.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@ const serverPackets = require('./../ServerPackets/serverPackets');
22
const ClientPacket = require("./ClientPacket");
33

44
class RequestServerLogin {
5-
constructor(packet, client) {
5+
constructor(packet, client) {
66
this._client = client;
7-
this._data = new ClientPacket(packet);
8-
this._data.readC()
7+
this._data = new ClientPacket(packet);
8+
this._data.readC()
99
.readD()
1010
.readD()
1111
.readC();
1212

13-
this._init();
14-
}
13+
this._init();
14+
}
1515

1616
get sessionKey1() {
17-
const sessionKey1 = [];
17+
const sessionKey1 = [];
1818

19-
sessionKey1[0] = this._data.getData()[1].toString(16);
20-
sessionKey1[1] = this._data.getData()[2].toString(16);
19+
sessionKey1[0] = this._data.getData()[1].toString(16);
20+
sessionKey1[1] = this._data.getData()[2].toString(16);
2121

22-
return sessionKey1;
23-
}
22+
return sessionKey1;
23+
}
2424

25-
get serverNumber() {
26-
return this._data.getData()[3];
27-
}
25+
get serverNumber() {
26+
return this._data.getData()[3];
27+
}
2828

29-
_init() {
29+
_init() {
3030
this._client.sendPacket(new serverPackets.PlayOk([0x00000000, 0x00000000]));
31-
}
31+
}
3232
}
3333

3434
module.exports = RequestServerLogin;

‎LoginServer/ServerPackets/InitLS.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class InitLS {
4-
constructor() {
4+
constructor() {
55
this._sessionID = 0x03ed779c;
66
this._packet = new ServerPacket(9);
77
this._packet.writeC(0x00)

‎LoginServer/ServerPackets/LoginFail.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class LoginFail {
4-
constructor(reason) {
4+
constructor(reason) {
55
this._packet = new ServerPacket(12);
66
this._packet.writeC(0x01)
77
.writeC(reason);

‎LoginServer/ServerPackets/LoginOk.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class LoginOk {
4-
constructor(SessionKey1) {
4+
constructor(SessionKey1) {
55
this._packet = new ServerPacket(48);
66
this._packet.writeC(0x03)
77
.writeD(SessionKey1[0])

‎LoginServer/ServerPackets/PlayFail.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class PlayFail {
4-
constructor(reason) {
4+
constructor(reason) {
55
this._packet = new ServerPacket(12);
66
this._packet.writeC(0x06)
77
.writeC(reason);

‎LoginServer/ServerPackets/PlayOk.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const ServerPacket = require('./ServerPacket.js');
22

33
class PlayOk {
4-
constructor(SessionKey2) {
4+
constructor(SessionKey2) {
55
this._packet = new ServerPacket(12);
66
this._packet.writeC(0x07)
77
.writeD(SessionKey2[0])

‎LoginServer/ServerPackets/ServerPacket.js

+48-48
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,54 @@
55
// writeS - string
66

77
class ServerPacket {
8-
constructor(size) {
9-
this._buffer = Buffer.alloc(size + 4 + (size + 4) % 8); // (size + 4) % 8 - checksum. the packet is a multiple of 8.
10-
this._offset = 0;
11-
}
12-
13-
writeC(value) {
14-
this._buffer.writeUInt8(value, this._offset);
15-
this._offset++;
16-
17-
return this;
18-
}
19-
20-
writeH(value) {
21-
this._buffer.writeUInt16LE(value, this._offset);
22-
this._offset += 2;
23-
24-
return this;
25-
}
26-
27-
writeD(value) {
28-
this._buffer.writeInt32LE(value, this._offset);
29-
this._offset += 4;
30-
31-
return this;
32-
}
33-
34-
writeF(value) {
35-
this._buffer.writeDoubleLE(value, this._offset);
36-
this._offset += 8;
37-
38-
return this;
39-
}
40-
41-
writeS(string) {
42-
this._buffer.write(string, this._offset, 'ucs2');
43-
this._offset += Buffer.byteLength(string, 'ucs2') + 2;
44-
this._buffer.writeInt16LE(0, this._offset - 2);
45-
46-
return this;
47-
}
48-
49-
getBuffer() {
50-
return this._buffer;
51-
}
52-
53-
static strlen(str) {
54-
return Buffer.byteLength(str, 'ucs2') + 2;
55-
}
8+
constructor(size) {
9+
this._buffer = Buffer.alloc(size + 4 + (size + 4) % 8); // (size + 4) % 8 - checksum. the packet is a multiple of 8.
10+
this._offset = 0;
11+
}
12+
13+
writeC(value) {
14+
this._buffer.writeUInt8(value, this._offset);
15+
this._offset++;
16+
17+
return this;
18+
}
19+
20+
writeH(value) {
21+
this._buffer.writeUInt16LE(value, this._offset);
22+
this._offset += 2;
23+
24+
return this;
25+
}
26+
27+
writeD(value) {
28+
this._buffer.writeInt32LE(value, this._offset);
29+
this._offset += 4;
30+
31+
return this;
32+
}
33+
34+
writeF(value) {
35+
this._buffer.writeDoubleLE(value, this._offset);
36+
this._offset += 8;
37+
38+
return this;
39+
}
40+
41+
writeS(string) {
42+
this._buffer.write(string, this._offset, 'ucs2');
43+
this._offset += Buffer.byteLength(string, 'ucs2') + 2;
44+
this._buffer.writeInt16LE(0, this._offset - 2);
45+
46+
return this;
47+
}
48+
49+
getBuffer() {
50+
return this._buffer;
51+
}
52+
53+
static strlen(str) {
54+
return Buffer.byteLength(str, 'ucs2') + 2;
55+
}
5656
}
5757

5858
module.exports = ServerPacket;

‎LoginServer/libs/blowfish.js

+321-321
Large diffs are not rendered by default.

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
in progress...

‎config/gameserver.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
host: "127.0.0.1",
3-
port: 7777,
2+
host: "127.0.0.1",
3+
port: 7777,
44
}

‎config/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const loginserver = require('./loginserver');
33
const gameserver = require('./gameserver');
44

55
module.exports = {
6-
main,
7-
loginserver,
8-
gameserver,
6+
main,
7+
loginserver,
8+
gameserver,
99
}

‎config/loginserver.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
host: "127.0.0.1",
3-
port: 2106,
2+
host: "127.0.0.1",
3+
port: 2106,
44
}

‎config/main.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = {
2-
encryptionKeys: {
3-
blowfish: [0x5b,0x3b,0x27,0x2e,0x5d,0x39,0x34,0x2d,0x33,0x31,0x3d,0x3d,0x2d,0x25,0x26,0x40,0x21,0x5e,0x2b,0x5d],
4-
XOR: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], // [0x94, 0x35, 0x00, 0x00, 0xa1, 0x6c, 0x54, 0x87]
5-
},
6-
PROTOCOL_VERSION_CLIENT: 419,
2+
encryptionKeys: {
3+
blowfish: [0x5b,0x3b,0x27,0x2e,0x5d,0x39,0x34,0x2d,0x33,0x31,0x3d,0x3d,0x2d,0x25,0x26,0x40,0x21,0x5e,0x2b,0x5d],
4+
XOR: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], // [0x94, 0x35, 0x00, 0x00, 0xa1, 0x6c, 0x54, 0x87]
5+
},
6+
PROTOCOL_VERSION_CLIENT: 419,
77
PROTOCOL_VERSION_SERVER: 30810, // 0x785a
88
}

0 commit comments

Comments
 (0)
Please sign in to comment.