File tree 9 files changed +67
-7
lines changed
9 files changed +67
-7
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,14 @@ class Database {
60
60
return await this . _db . collection ( 'characters' ) . findOne ( { login } ) ;
61
61
}
62
62
63
- async getCharactersByLogin ( login ) {
63
+ async getCharactersByLogin ( login ) { // fix delete
64
64
return await this . _db . collection ( 'characters' ) . find ( { login } ) . toArray ( ) ;
65
65
}
66
66
67
+ async getCharacterByObjectId ( objectId ) {
68
+ return await this . _db . collection ( 'characters' ) . findOne ( { objectId } ) ;
69
+ }
70
+
67
71
async checkCharacterNameExists ( characterName ) {
68
72
const character = await this . _db . collection ( 'characters' ) . findOne ( {
69
73
'characterName' : {
Original file line number Diff line number Diff line change @@ -93,9 +93,11 @@ class Client {
93
93
94
94
break ;
95
95
case 9 :
96
- new clientPackets . Logout ( packet , this ) ;
96
+ new clientPackets . Logout ( packet , this ) ;
97
97
98
- break ;
98
+ break ;
99
+ case 70 :
100
+ new clientPackets . RequestRestart ( packet , this ) ;
99
101
}
100
102
}
101
103
Original file line number Diff line number Diff line change @@ -7,14 +7,14 @@ class Logout {
7
7
constructor ( packet , client ) {
8
8
this . _client = client ;
9
9
this . _data = new ClientPacket ( packet ) ;
10
- this . _data . readC ( )
10
+ this . _data . readC ( ) ;
11
11
12
12
this . _init ( ) ;
13
13
}
14
14
15
15
async _init ( ) {
16
16
const player = players . getPlayerByClient ( this . _client ) ;
17
- const character = await database . getCharacterByLogin ( player . login ) ;
17
+ const character = await database . getCharacterByObjectId ( player . objectId ) ;
18
18
19
19
character . x = Math . floor ( player . x ) ; // fix, update all doc?
20
20
character . y = Math . floor ( player . y ) ;
Original file line number Diff line number Diff line change @@ -50,9 +50,9 @@ class RequestAuthLogin {
50
50
51
51
player . update ( {
52
52
login : this . login
53
- } ) ;
53
+ } ) ; // fix?
54
54
55
- this . _client . sendPacket ( new serverPackets . CharacterSelectInfo ( this . login , characters ) ) ;
55
+ this . _client . sendPacket ( new serverPackets . CharacterSelectInfo ( player . login , characters ) ) ;
56
56
}
57
57
}
58
58
Original file line number Diff line number Diff line change
1
+ const serverPackets = require ( './../ServerPackets/serverPackets' ) ;
2
+ const ClientPacket = require ( "./ClientPacket" ) ;
3
+ const database = require ( './../../Database' ) ;
4
+ const players = require ( './../Models/Players' ) ;
5
+
6
+ class RequestRestart {
7
+ constructor ( packet , client ) {
8
+ this . _client = client ;
9
+ this . _data = new ClientPacket ( packet ) ;
10
+ this . _data . readC ( ) ;
11
+
12
+ this . _init ( ) ;
13
+ }
14
+
15
+ async _init ( ) {
16
+ const player = players . getPlayerByClient ( this . _client ) ;
17
+ const character = await database . getCharacterByObjectId ( player . objectId ) ;
18
+
19
+ character . x = Math . floor ( player . x ) ; // fix, update all doc?
20
+ character . y = Math . floor ( player . y ) ;
21
+ character . z = Math . floor ( player . z ) ;
22
+
23
+ await database . updateCharacterByObjectId ( character . objectId , character ) ;
24
+
25
+ const allowRestart = true ; // fix
26
+ const characters = await database . getCharactersByLogin ( player . login ) ;
27
+
28
+ this . _client . sendPacket ( new serverPackets . RestartResponse ( allowRestart ) ) ;
29
+ this . _client . sendPacket ( new serverPackets . CharacterSelectInfo ( player . login , characters ) ) ;
30
+ }
31
+ }
32
+
33
+ module . exports = RequestRestart ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const MoveBackwardToLocation = require('./MoveBackwardToLocation');
10
10
const Action = require ( './Action' ) ;
11
11
const RequestAttack = require ( './RequestAttack' ) ;
12
12
const Logout = require ( './Logout' ) ;
13
+ const RequestRestart = require ( './RequestRestart' ) ;
13
14
14
15
module . exports = {
15
16
ProtocolVersion,
@@ -24,4 +25,5 @@ module.exports = {
24
25
Action,
25
26
RequestAttack,
26
27
Logout,
28
+ RequestRestart,
27
29
}
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ class Player extends Character {
7
7
8
8
this . _client = client ;
9
9
this . target = null ;
10
+ // this characterObjectId fix
11
+ // this getActiveChar ?
10
12
}
11
13
12
14
getClient ( ) {
Original file line number Diff line number Diff line change
1
+ const ServerPacket = require ( './ServerPacket.js' ) ;
2
+
3
+ class RestartResponse {
4
+ constructor ( allowRestart ) {
5
+ this . _packet = new ServerPacket ( 5 ) ;
6
+ this . _packet . writeC ( 0x74 )
7
+ . writeD ( allowRestart ? 0x01 : 0x00 ) ;
8
+ }
9
+
10
+ getBuffer ( ) {
11
+ return this . _packet . getBuffer ( ) ;
12
+ }
13
+ }
14
+
15
+ module . exports = RestartResponse ;
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ const StopRotating = require('./StopRotating');
20
20
const DeleteObject = require ( './DeleteObject' ) ;
21
21
const StopMove = require ( './StopMove' ) ;
22
22
const LeaveWorld = require ( './LeaveWorld' ) ;
23
+ const RestartResponse = require ( './RestartResponse' ) ;
23
24
24
25
module . exports = {
25
26
CryptInit,
@@ -44,4 +45,5 @@ module.exports = {
44
45
DeleteObject,
45
46
StopMove,
46
47
LeaveWorld,
48
+ RestartResponse,
47
49
}
You can’t perform that action at this time.
0 commit comments