-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_parser_inbound.js
168 lines (160 loc) · 4.44 KB
/
mod_parser_inbound.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* Outbound parser module
*
* Handles all incoming packets from game server
* and modifies them if needed
*/
module.exports = {
/**
* Parse full packet
*
* @param packet Full packet being examined
* @param callback
*/
parsePacket: function(packet, callback) {
var self = this;
var packets = this.getAllPackets(packet);
// return if packet is null
if(packets == null) return;
// loop thru and get each packets zones
packets.forEach(function(pck) {
zones = self.getPacketZones(pck);
callback(true, 'client', self.executePacket(packet, zones));
});
},
/**
* Break up large packet into individual packets
*
* @param packet Full packet being examined
* @returns array Individual packets
*/
getAllPackets: function(packet) {
return packet.toString().match(/<m (.+?)\/>/g);
},
/**
* Break up single packet into individual zones
*
* @param packet Individual packet being examined
* @returns array Packet zones
*/
getPacketZones: function(packet) {
var stripped_zones = [];
var zones = packet.toString().match(/p\d='(.+?)'/g);
zones.forEach(function(zone) {
zone = zone.replace(/p\d='(.+?)'/, "$1");
stripped_zones.push(zone);
});
return stripped_zones;
},
/**
* Execute packet
*
* @param packet Individual packet being examined
* @param zones Packet zones
* @returns string Individual packet
*/
executePacket: function(packet, zones) {
switch(zones[0]) {
case 'ADDTOBAG':
if(zones[1] == 'loot2') {
return this.checkLoot(packet, zones);
}
break;
case 'ADDOBJ':
// Check for iron rock
if(zones[2] == "Iron Rock" && autominer.isEnabled()) {
autominer.selectRock(zones[1]);
autominer.mineRock(zones[1]);
}
return packet;
break;
case 'SETCOOLDOWN':
// Check cooldown for autocast
if(oisc.params.autocast && oisc.config.autocast_active && zones[1] == oisc.params.autocast_spell && zones[2] == '1') {
// Cooldown at 1 second, start timeout for cast
var autocastCooldownDelay = setTimeout(function(){
oisc.client.write("SAY" + '\x01' + "/do " + oisc.params.autocast_spell + '\u0000');
delete autocastCooldownDelay;
}, oisc.params.autocast_delay);
}
// Check cooldown for precious metals
if(oisc.params.automine && zones[1] == "csPreciousMetals" && zones[2] == '0') {
// Ready to create another rock
autominer.createNewRock();
}
return packet;
break;
case 'SETACTION':
if(zones[2] == 'SPEED') {
// Speed changed on server
var server_speed = zones[3];
oisc.config.speed_server = server_speed;
if(oisc.config.speed != 0) {
var setSpeedBack = setTimeout(function() { oisc.server.write("<p c='1'><m p='2' p0='SV' p1='_root.me.speed' p2='" + oisc.config.speed + "'/></p>"); }, 500);
}
}
break;
case 'SAY':
// Check auto cast
if(oisc.config.autocast_active && zones[1] == '**' && zones[2].indexOf('You have slain') != -1) {
oisc.config.autocast_active = false;
}
// Check autominer
if(oisc.params.automine && zones[1] == '**' && zones[2].indexOf('you dig up') != -1) {
// Metal aquired, move to next area
autominer.moveToNextMineArea();
}
return packet;
break;
default:
return packet;
break;
}
},
/**
* Check for loot
*
* @param packet Individual packet being examined
* @param zones Packet zones
* @returns string Individual packet
*/
checkLoot: function(packet, zones) {
self = this;
// split loot individually
var loot = zones[2].split(';');
loot.pop();
loot.forEach(function(item) {
item = item.split(',');
item_id = item[0];
item_specs = item[item.length-1].split(' - ');
item_name = item_specs[0].trim();
if(oisc.params.loot_coins == true && item_name.indexOf('Coins') != -1) {
// grab coins
self.grabLoot(item_id);
}
else if(oisc.params.loot_all === true) {
// check value of item, grab if over loot_value
if(item_specs.length < 3) {
item_quality = 'none';
item_value = item_specs[1].replace(/[^\d.]/g, "");
}
else {
item_quality = item_specs[1].replace("quality: ", "");
item_value = item_specs[2].replace(/[^\d.]/g, "");
}
if(item_value >= oisc.params.loot_value) {
self.grabLoot(item_id);
}
}
});
return packet;
},
/**
* Grab loot
*
* @param item_id ID of item to grab
*/
grabLoot: function(item_id) {
oisc.client.write("CLICKBAGITEM" + '\x01' + "loot" + '\x01' + item_id + '\u0000');
}
}