-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackets.js
More file actions
139 lines (128 loc) · 4.45 KB
/
packets.js
File metadata and controls
139 lines (128 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function Packet(id){
this.id = id;
}
Packet.prototype.getID = function(data){
return data.slice(0,2);
};
Packet.prototype.readData = function(data){
return data.slice(2,data.length);
};
Packet.prototype.writeData = function(){
sendMessage(new Buffer (this.getData()));
};
///////////////////////////////////////////////////////////////////////////////
function Packet00Login(username,x,y,z){
Packet.call(this,00);
if(username!== "undefined")this.username = username;
if(x!== "undefined")this.x = x;
if(y!== "undefined")this.y = y;
if(z!== "undefined")this.z = z;
}
Packet00Login.prototype.writeData = Packet.prototype.writeData;
Packet00Login.prototype.receivePacket = function(data){
var stuff = data.toString().split(",");
this.username = stuff[0].slice(2,stuff[0].length);
this.x = stuff[1];
this.y = stuff[2];
this.z = stuff[3];
};
Packet00Login.prototype.getData = function(){
return "00" + this.username+','+this.x+','+this.y+','+this.z;
};
///////////////////////////////////////////////////////////////////////////////
function Packet01Disconnect(username,x,y,z){
Packet.call(this,01);
if(username!== "undefined")this.username = username;
}
Packet01Disconnect.prototype.writeData = Packet.prototype.writeData;
Packet01Disconnect.prototype.receivePacket = function(data){
var stuff = data.toString().split(",");
this.username = stuff[0].slice(2,stuff[0].length);
};
Packet01Disconnect.prototype.getData = function(){
return "01" + this.username;
};
///////////////////////////////////////////////////////////////////////////////
function Packet02Move(username,x,y,z,movingDir,isSwimming,inHand){
Packet.call(this,02);
if(username!== "undefined")this.username = username;
if(x!== "undefined")this.x = x;
if(y!== "undefined")this.y = y;
if(z!== "undefined")this.z = z;
if(movingDir!== "undefined")this.movingDir = movingDir;
if(isSwimming!== "undefined")this.isSwimming = isSwimming;
if(inHand!== "undefined")this.inHand = inHand;
}
Packet02Move.prototype.writeData = Packet.prototype.writeData;
Packet02Move.prototype.receivePacket = function(data){
var stuff = data.toString().split(",");
this.username = stuff[0].slice(2,stuff[0].length);
this.x = parseInt(stuff[1]);
this.y = parseInt(stuff[2]);
this.z = parseInt(stuff[3]);
this.movingDir = parseInt(stuff[4]);
this.isSwimming = stuff[5];
this.inHand = parseInt(stuff[6]);
};
Packet02Move.prototype.getData = function(){
return "02" + this.username+','+this.x+','+this.y+','+this.z+
','+this.movingDir+','+this.isSwimming+','+this.inHand;
};
//////////////////////////////////////////////////////////////////////////////
function TileEdit(x,y,z,id){
this.x=x;
this.y=y;
this.z=z;
this.id=id;
}
function Packet05SendTiles(seed,tiles){
Packet.call(this,05);
if(seed!== "undefined")this.seed = seed;
if(tiles!== "undefined")this.tiles = tiles;
}
Packet05SendTiles.prototype.writeData = Packet.prototype.writeData;
Packet05SendTiles.prototype.receivePacket = function(data){
var stuff = data.toString().split(",");
this.seed = stuff[0].slice(2,stuff[0].length);
var blah = stuff[1].split(".");
var t = [];
for(var i=0;i<(blah.length-1)/4;i++){
console.log("new Tile: "+blah[i*4]+','+blah[i*4+1]+','+blah[i*4+2]+','+blah[i*4+3]);
t.push(new TileEdit(parseInt(blah[i*4]),parseInt(blah[i*4+1]),parseInt(blah[i*4+2]),parseInt(blah[i*4+3])));
}
this.tiles = t;
};
Packet05SendTiles.prototype.getData = function(){
// var s = "";
// for(var i=0;i<this.tiles.length;i++){
// var t = this.tiles[i];
// s+=t.x;
// s+=".";
// s+=t.y;
// s+=".";
// s+=t.z;
// s+=".";
// s+=t.id;
// s+=".";
// }
return "05" + this.seed;
};
/////////////////////////////////////////////////////////////////////////////
function Packet06UpdateTile(tile,x,y,z){
Packet.call(this,06);
if(tile!== "undefined")this.tile = tile;
if(x!== "undefined")this.x = x;
if(y!== "undefined")this.y = y;
if(z!== "undefined")this.z = z;
}
Packet06UpdateTile.prototype.writeData = Packet.prototype.writeData;
Packet06UpdateTile.prototype.receivePacket = function(data){
var stuff = data.toString().split(",");
this.tile = stuff[0].slice(2,stuff[0].length);
this.x = parseInt(stuff[1]);
this.y = parseInt(stuff[2]);
this.z = parseInt(stuff[3]);
};
Packet06UpdateTile.prototype.getData = function(){
return "06" + this.tile + ','+this.x+','+this.y+','+this.z;
};