-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,15 @@ const ProtoBuf = require('protobufjs'); | |
const GoogleOAuth = require('gpsoauthnode'); | ||
const Long = require('long'); | ||
const ByteBuffer = require('bytebuffer'); | ||
const bignum = require('bignum'); | ||
|
||
const s2 = require('simple-s2-node'); | ||
const s2 = require('s2geometry-node'); | ||
const Logins = require('./logins'); | ||
const fs = require('fs'); | ||
const pokemonlist = JSON.parse(fs.readFileSync(__dirname + '/pokemons.json', 'utf8')); | ||
|
||
let builder = ProtoBuf.loadProtoFile('pokemon.proto'); | ||
if (builder === null) { | ||
builder = ProtoBuf.loadProtoFile(__dirname + '/pokemon.proto'); | ||
builder = ProtoBuf.loadProtoFile(__dirname + '/pokemon2.proto'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
const pokemonProto = builder.build(); | ||
This comment has been minimized.
Sorry, something went wrong.
FabioAntunes
|
||
|
@@ -31,8 +30,9 @@ function GetCoords(self) { | |
return [latitude, longitude]; | ||
}; | ||
|
||
|
||
function getNeighbors(lat, lng) { | ||
var origin = s2.S2CellId.from_lat_lng(s2.S2LatLng.from_degrees(lat, lng)).parent(15); | ||
var origin = new s2.S2CellId(new s2.S2LatLng(lat, lng)).parent(15); | ||
var walk = [origin.id()]; | ||
// 10 before and 10 after | ||
var next = origin.next(); | ||
|
@@ -238,45 +238,34 @@ function Pokeio() { | |
self.Heartbeat = function (callback) { | ||
let {apiEndpoint, accessToken} = self.playerInfo; | ||
|
||
let nullbytes = new Buffer(21); | ||
|
||
var nullbytes = new Array(21); | ||
nullbytes.fill(0); | ||
|
||
// Generating walk data using s2 geometry | ||
var walk = getNeighbors(self.playerInfo.latitude, self.playerInfo.longitude).sort((a, b) => { | ||
return a.cmp(b); | ||
}); | ||
var buffer = new ByteBuffer(21 * 10).LE(); | ||
walk.forEach((elem) => { | ||
buffer.writeVarint64(s2.S2Utils.long_from_bignum(elem)); | ||
var walk = getNeighbors(self.playerInfo.latitude, self.playerInfo.longitude).sort(function (a, b) { | ||
return a > b; | ||
}); | ||
|
||
// Creating MessageQuad for Requests type=106 | ||
buffer.flip(); | ||
var walkData = new RequestEnvelop.MessageQuad({ | ||
'f1': buffer.toBuffer(), | ||
'f1': walk, | ||
'f2': nullbytes, | ||
'lat': self.playerInfo.latitude, | ||
'long': self.playerInfo.longitude | ||
}); | ||
|
||
var req = [ | ||
new RequestEnvelop.Requests(106, walkData.encode().toBuffer()), | ||
new RequestEnvelop.Requests(126), | ||
new RequestEnvelop.Requests(4, (new RequestEnvelop.Unknown3(Date.now().toString())).encode().toBuffer()), | ||
new RequestEnvelop.Requests(129), | ||
new RequestEnvelop.Requests(5, (new RequestEnvelop.Unknown3('05daf51635c82611d1aac95c0b051d3ec088a930')).encode().toBuffer()) | ||
]; | ||
var req = [new RequestEnvelop.Requests(106, walkData.encode().toBuffer()), new RequestEnvelop.Requests(126), new RequestEnvelop.Requests(4, new RequestEnvelop.Unknown3(Date.now().toString()).encode().toBuffer()), new RequestEnvelop.Requests(129), new RequestEnvelop.Requests(5, new RequestEnvelop.Unknown3('05daf51635c82611d1aac95c0b051d3ec088a930').encode().toBuffer())]; | ||
|
||
api_req(apiEndpoint, accessToken, req, function (err, f_ret) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
else if (!f_ret || !f_ret.payload || !f_ret.payload[0]) { | ||
} else if (!f_ret || !f_ret.payload || !f_ret.payload[0]) { | ||
return callback('No result'); | ||
} | ||
|
||
var heartbeat = ResponseEnvelop.HeartbeatPayload.decode(f_ret.payload[0]); | ||
callback(null, heartbeat) | ||
callback(null, heartbeat); | ||
}); | ||
}; | ||
|
||
|
@@ -299,7 +288,7 @@ function Pokeio() { | |
'spawnpoint_id': mapPokemon.SpawnPointId, | ||
'hit_pokemon': true, | ||
'spin_modifier': 1, | ||
'normalized_hit_position': 1 | ||
'normalized_hit_position': 2 | ||
}); | ||
|
||
var req = new RequestEnvelop.Requests(103, catchPokemon.encode().toBuffer()); | ||
|
@@ -319,11 +308,12 @@ function Pokeio() { | |
}; | ||
|
||
self.EncounterPokemon = function (catchablePokemon, callback) { | ||
// console.log(catchablePokemon); | ||
let {apiEndpoint, accessToken, latitude, longitude} = self.playerInfo; | ||
|
||
var encounterPokemon = new RequestEnvelop.EncounterMessage({ | ||
'encounter_id': catchablePokemon.EncounterId, | ||
'spawn_point_id': catchablePokemon.SpawnPointId, | ||
'spawnpoint_id': catchablePokemon.SpawnPointId, | ||
'player_latitude': latitude, | ||
'player_longitude': longitude | ||
}); | ||
|
@@ -391,6 +381,42 @@ function Pokeio() { | |
}); | ||
} | ||
}; | ||
|
||
self.changePosition = function () { | ||
self.playerInfo.longitude = self.playerInfo.longitude + 0.000055; | ||
self.playerInfo.latitude = self.playerInfo.latitude + 0.000055; | ||
return true; | ||
}; | ||
|
||
self.hatchEggs = function(cb) { | ||
self.changePosition(); | ||
self.Heartbeat(cb); | ||
}; | ||
|
||
self.GetFort = function(fortid, fortlat, fortlong, callback) { | ||
var FortMessage = new RequestEnvelop.FortSearchMessage({ | ||
'fort_id': fortid, | ||
'player_latitude': fortlat, | ||
'player_longitude': fortlong, | ||
'fort_latitude': fortlat, | ||
'fort_longitude': fortlong | ||
}); | ||
|
||
// console.log(FortMessage); | ||
|
||
var req = new RequestEnvelop.Requests(101, FortMessage.encode().toBuffer()); | ||
|
||
api_req(self.playerInfo.apiEndpoint, self.playerInfo.accessToken, req, function (err, f_ret) { | ||
if (err) { | ||
return callback(err); | ||
} else if (!f_ret || !f_ret.payload || !f_ret.payload[0]) { | ||
return callback('No result'); | ||
} | ||
|
||
var FortSearchResponse = ResponseEnvelop.FortSearchResponse.decode(f_ret.payload[0]); | ||
callback(null, FortSearchResponse); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = new Pokeio(); | ||
|
14 comments
on commit 526d671
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What environment are you using? I can't compile s2geometry-node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LASkuma - ubuntu with node v6.2.2, what version of node are you using?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried 4.x, 6.2.1 and 6.3.0. All of them don't work for me. The problem comes from isinf function inside of s2geometry-node. I've also tried a lot of different gcc and g++ versions but still no luck.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What OS are you on? If it's windows, I believe there might be an issue with the library for windows users, I will talk to the creator tomorrow (today) and take a look at it myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's Ubuntu. It seems that I can only run it on my mac.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird - I'm on ubuntu and I run it perfectly fine. Maybe try sudo npm install
and then just npm install
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What version of Ubuntu are you using? I'm using 16.04. I really think I should switch back to 14.04.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm on ubuntu 14.04
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try 14.04 then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know! Hopefully I'll have issues turned back on for this repo by tomorrow. Feel free to contribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Built succeed from Ubuntu 14.04.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone suceeded with ubuntu 16.04?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still trying on ubuntu 16.04 with no luck...
Should be
builder = ProtoBuf.loadProtoFile(__dirname + '/pokemon.proto');
here