Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PVP Stats #120

Merged
merged 33 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f4dca9e
Update to Swift 4.2
123FLO321 May 23, 2020
ee3c6d1
Add Test Print
123FLO321 May 23, 2020
d403eb5
fix error
123FLO321 May 23, 2020
09803f8
fix protobuf version
123FLO321 May 23, 2020
8bcc6df
Fix Dockerfiles
123FLO321 May 23, 2020
3183baf
Don't re-use 4.1 cache
123FLO321 May 23, 2020
19a3c32
No space in path
123FLO321 May 23, 2020
ba72813
remove temp test
123FLO321 May 23, 2020
40c3ba5
pvp stats
123FLO321 May 23, 2020
fd8b33f
fix woops
123FLO321 May 23, 2020
e611d06
skip if costume is no-evolve
123FLO321 May 24, 2020
263e25d
fix crash
123FLO321 May 24, 2020
9cb98fe
make swiftlint happy
123FLO321 May 24, 2020
7045bd1
Merge branch 'master' into pvp-stats
123FLO321 May 24, 2020
75d2fb4
spelling
123FLO321 May 24, 2020
7093393
fix another crash
123FLO321 May 24, 2020
671020e
good pvp and iv in front
123FLO321 May 24, 2020
65bb66d
Add level and cp to pvp stats
123FLO321 May 24, 2020
2b3cd83
fix raid markers
123FLO321 May 24, 2020
8296a52
Fix raid marker url
123FLO321 May 25, 2020
c58ef01
Merge branch 'pvp-stats' of github.com:123FLO321/RealDeviceMap into p…
123FLO321 May 25, 2020
5415877
fix raid marker for real now
123FLO321 May 28, 2020
c2f25a9
Merge branch 'master' into pvp-stats
123FLO321 May 28, 2020
ac9d9f3
Merge branch 'master' into pvp-stats
123FLO321 May 29, 2020
8fc9441
Merge branch 'pvp-stats' of github.com:123FLO321/RealDeviceMap into p…
123FLO321 May 29, 2020
839c2f6
make pvp info toggle-able
123FLO321 May 29, 2020
cda9e12
fix eslint
123FLO321 May 29, 2020
3fe7768
Merge branch 'master' into pvp-stats
123FLO321 Jul 6, 2020
c283860
Merge branch 'master' into pvp-stats
123FLO321 Jul 17, 2020
ace0e8c
auto load masterfile after changes, image gen check if image is png
123FLO321 Jul 18, 2020
874089a
Merge branch 'pvp-stats' of github.com:123FLO321/RealDeviceMap into p…
123FLO321 Jul 18, 2020
99e71b6
improve performance when multiple threads see a pokemon for the first…
123FLO321 Jul 20, 2020
70aa7d1
fix build
123FLO321 Jul 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/docker/Dockerfile-localbuild-base
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ RUN tar -xzf /tmp/swiftenv.tar.gz -C /usr/local/ --strip 1
# Add swiftenv shims to PATH
ENV PATH /usr/local/shims:$PATH

# Install swift 4.1
RUN swiftenv install 4.1
RUN touch /etc/ld.so.conf.d/swift.conf && echo "/usr/local/versions/4.1/usr/lib/swift/linux" >> /etc/ld.so.conf.d/swift.conf && ldconfig
# Install swift 4.2
RUN swiftenv install 4.2
RUN touch /etc/ld.so.conf.d/swift.conf && echo "/usr/local/versions/4.2/usr/lib/swift/linux" >> /etc/ld.so.conf.d/swift.conf && ldconfig

# Install OpenSSL 1.1.1c
RUN apt-get -y update && apt-get install -y build-essential checkinstall zlib1g-dev
Expand Down
2 changes: 1 addition & 1 deletion .github/docker/Dockerfile-localbuild-debug
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Base Image
FROM docker.pkg.github.com/realdevicemap/realdevicemap/realdevicemap:base
FROM docker.pkg.github.com/realdevicemap/realdevicemap/realdevicemap:base.4.2

## Copy Files
COPY .build/debug/RealDeviceMap /app/
Expand Down
2 changes: 1 addition & 1 deletion .github/docker/Dockerfile-localbuild-release
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Base Image
FROM docker.pkg.github.com/realdevicemap/realdevicemap/realdevicemap:base
FROM docker.pkg.github.com/realdevicemap/realdevicemap/realdevicemap:base.4.2

## Copy Files
COPY .build/release/RealDeviceMap /app/
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/cache@v1
with:
path: .build
key: ${{ runner.os }}-debug-spm-${{ hashFiles('Package.resolved') }}
key: ${{ runner.os }}-debug-4.2-spm-${{ hashFiles('Package.resolved') }}
- name: Build
run: swift build -v -c debug
- name: Test
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
- uses: actions/cache@v1
with:
path: .build
key: ${{ runner.os }}-release-spm-${{ hashFiles('Package.resolved') }}
key: ${{ runner.os }}-release-4.2-spm-${{ hashFiles('Package.resolved') }}
- name: Build
run: swift build -v -c release
- name: Upload executeable
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.build/
.build_lin/
.packages_lin/
.swiftpm/
Package.resolved

# Xcode
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1
4.2
4 changes: 4 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ identifier_name:
- id
- cp
- xp
- iv
type_name:
excluded:
- IV
4 changes: 3 additions & 1 deletion Dockerfile-debug
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Base Image
FROM perfectlysoft/perfectassistant:4.1 AS base
FROM swift:4.2 AS base

# Perfect-COpenSSL
RUN apt-get -y update && apt-get install -y libssl-dev
Expand All @@ -19,6 +19,8 @@ RUN apt-get -y update && apt-get install -y imagemagick && cp /usr/bin/convert /
# MySQL Client
RUN apt-get -y update && apt-get install -y mysql-client-5.7

# WGet
RUN apt-get -y update && apt-get install -y wget

## Build Image
FROM base AS build
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-release
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Base Image
FROM perfectlysoft/perfectassistant:4.1 AS base
FROM swift:4.2 AS base

# Perfect-COpenSSL
RUN apt-get -y update && apt-get install -y libssl-dev
Expand Down
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.1
// swift-tools-version:4.2

import PackageDescription

Expand All @@ -16,10 +16,10 @@ let package = Package(
.package(url: "https://github.com/PerfectlySoft/Perfect-Crypto.git", .upToNextMinor(from: "3.2.0")),
.package(url: "https://github.com/123FLO321/Turnstile.git", .upToNextMinor(from: "1.2.3")),
.package(url: "https://github.com/crossroadlabs/Regex.git", .upToNextMinor(from: "1.1.0")),
.package(url: "https://github.com/apple/swift-protobuf.git", .upToNextMinor(from: "1.5.0")),
.package(url: "https://github.com/apple/swift-protobuf.git", .upToNextMinor(from: "1.9.0")),
.package(url: "https://github.com/123FLO321/turf-swift.git", .upToNextMinor(from: "0.3.1")),
.package(url: "https://github.com/123FLO321/S2Geometry.git", .upToNextMinor(from: "0.3.1")),
.package(url: "https://github.com/123FLO321/POGOProtos-Swift.git", .upToNextMinor(from: "1.23.0"))
.package(url: "https://github.com/123FLO321/POGOProtos-Swift.git", .upToNextMinor(from: "1.23.2"))
],
targets: [
.target(
Expand Down Expand Up @@ -47,5 +47,5 @@ let package = Package(
]
)
],
swiftLanguageVersions: [4]
swiftLanguageVersions: [.v4_2]
)
42 changes: 32 additions & 10 deletions Sources/RealDeviceMap/API/ApiRequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ class ApiRequestHandler {
mysql: mysql, minLat: minLat!, maxLat: maxLat!, minLon: minLon!, maxLon: maxLon!, updated: lastUpdate,
raidsOnly: !showGyms, showRaids: permShowRaid, raidFilterExclude: raidFilterExclude,
gymFilterExclude: gymFilterExclude
)
).map({ (object) -> [String: Any] in
return object.getJSONValues()
})
}
let permShowStops = perms.contains(.viewMapPokestop)
let permShowQuests = perms.contains(.viewMapQuest)
Expand All @@ -156,46 +158,66 @@ class ApiRequestHandler {
questsOnly: !showPokestops, showQuests: permShowQuests, showLures: permShowLures,
showInvasions: permShowInvasions, questFilterExclude: questFilterExclude,
pokestopFilterExclude: pokestopFilterExclude
)
).map({ (object) -> [String: Any] in
return object.getJSONValues()
})
}
let permShowIV = perms.contains(.viewMapIV)
if isPost && permViewMap && showPokemon && perms.contains(.viewMapPokemon) {
data["pokemon"] = try? Pokemon.getAll(
mysql: mysql, minLat: minLat!, maxLat: maxLat!, minLon: minLon!, maxLon: maxLon!,
showIV: permShowIV, updated: lastUpdate, pokemonFilterExclude: pokemonFilterExclude,
pokemonFilterIV: pokemonFilterIV
)
).map({ (object) -> [String: Any] in
return object.getJSONValues()
})
}
if isPost && permViewMap && showSpawnpoints && perms.contains(.viewMapSpawnpoint) {
data["spawnpoints"] = try? SpawnPoint.getAll(
mysql: mysql, minLat: minLat!, maxLat: maxLat!, minLon: minLon!, maxLon: maxLon!,
updated: lastUpdate, spawnpointFilterExclude: spawnpointFilterExclude
)
).map({ (object) -> [String: Any] in
return object.getJSONValues()
})
}
if isPost && permViewMap && showActiveDevices && perms.contains(.viewMapDevice) {
data["active_devices"] = try? Device.getAll(mysql: mysql)
data["active_devices"] = try? Device.getAll(
mysql: mysql
).map({ (object) -> [String: Any] in
return object.getJSONValues()
})
}
if isPost && showCells && perms.contains(.viewMapCell) {
data["cells"] = try? Cell.getAll(
mysql: mysql, minLat: minLat!, maxLat: maxLat!, minLon: minLon!, maxLon: maxLon!, updated: lastUpdate
)
).map({ (object) -> [String: Any] in
return object.getJSONValues()
})
}
if lastUpdate == 0 && isPost && showSubmissionPlacementCells && perms.contains(.viewMapSubmissionCells) {
let result = try? SubmissionPlacementCell.getAll(
mysql: mysql, minLat: minLat!, maxLat: maxLat!, minLon: minLon!, maxLon: maxLon!
)
data["submission_placement_cells"] = result?.cells
data["submission_placement_rings"] = result?.rings
data["submission_placement_cells"] = result?.cells.map({ (object) -> [String: Any] in
return object.getJSONValues()
})
data["submission_placement_rings"] = result?.rings.map({ (object) -> [String: Any] in
return object.getJSONValues()
})
}
if lastUpdate == 0 && isPost && showSubmissionTypeCells && perms.contains(.viewMapSubmissionCells) {
data["submission_type_cells"] = try? SubmissionTypeCell.getAll(
mysql: mysql, minLat: minLat!, maxLat: maxLat!, minLon: minLon!, maxLon: maxLon!
)
).map({ (object) -> [String: Any] in
return object.getJSONValues()
})
}
if isPost && showWeathers && perms.contains(.viewMapWeather) {
data["weather"] = try? Weather.getAll(
mysql: mysql, minLat: minLat!, maxLat: maxLat!, minLon: minLon!, maxLon: maxLon!, updated: lastUpdate
)
).map({ (object) -> [String: Any] in
return object.getJSONValues()
})
}
if permViewMap && showPokemonFilter {

Expand Down
24 changes: 10 additions & 14 deletions Sources/RealDeviceMap/Controller/WebHookController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import Foundation
import PerfectLib
import PerfectThread
import cURL
import PerfectCURL

class WebHookController {
Expand Down Expand Up @@ -238,25 +237,22 @@ class WebHookController {
}

private func sendEvents(events: [[String: Any]], url: String) {

guard let body = try? events.jsonEncodedString() else {
Log.error(message: "[WebHookController] Failed to parse events into json string")
return
}
let byteArray = [UInt8](body.utf8)

let curlObject = CURL(url: url)

curlObject.setOption(CURLOPT_HTTPHEADER, s: "Accept: application/json")
curlObject.setOption(CURLOPT_HTTPHEADER, s: "Cache-Control: no-cache")
curlObject.setOption(CURLOPT_USERAGENT, s: "RealDeviceMap")
curlObject.setOption(CURLOPT_POST, int: 1)
curlObject.setOption(CURLOPT_POSTFIELDSIZE, int: byteArray.count)
curlObject.setOption(CURLOPT_COPYPOSTFIELDS, v: UnsafeMutablePointer(mutating: byteArray))
curlObject.setOption(CURLOPT_HTTPHEADER, s: "Content-Type: application/json")

curlObject.perform { (_, _, _) in }

let request = CURLRequest(
url,
.httpMethod(.post),
.postData(byteArray),
.addHeader(.contentType, "application/json"),
.addHeader(.accept, "application/json"),
.addHeader(.cacheControl, "no-cache"),
.addHeader(.userAgent, "RealDeviceMap \(VersionManager.global.version)")
)
request.perform { (_) in }
}

}
64 changes: 64 additions & 0 deletions Sources/RealDeviceMap/Misc/ImageGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ class ImageGenerator {
}
let pokestopDir = Dir("\(projectroot)/resources/webroot/static/img/pokestop/")
let pokemonDir = Dir("\(projectroot)/resources/webroot/static/img/pokemon/")
let pokemonLeagueDir = Dir("\(projectroot)/resources/webroot/static/img/pokemon_league/")
let itemDir = Dir("\(projectroot)/resources/webroot/static/img/item/")
let questDir = Dir("\(projectroot)/resources/webroot/static/img/quest/")
let gruntDir = Dir("\(projectroot)/resources/webroot/static/img/grunt/")
let invasionDir = Dir("\(projectroot)/resources/webroot/static/img/invasion/")
let questInvasionDir = Dir("\(projectroot)/resources/webroot/static/img/quest_invasion/")

let firstFile = File("\(projectroot)/resources/webroot/static/img/misc/first.png")
let secondFile = File("\(projectroot)/resources/webroot/static/img/misc/second.png")
let thirdFile = File("\(projectroot)/resources/webroot/static/img/misc/third.png")

if !raidDir.exists {
try! raidDir.create()
}
Expand All @@ -45,6 +51,9 @@ class ImageGenerator {
if !questInvasionDir.exists {
try! questInvasionDir.create()
}
if !pokemonLeagueDir.exists {
try! pokemonLeagueDir.create()
}

let thread = Threading.getQueue(type: .serial)

Expand All @@ -56,6 +65,48 @@ class ImageGenerator {
}
thread.dispatch {

if pokemonDir.exists && firstFile.exists && secondFile.exists && thirdFile.exists {
Log.info(message: "[ImageGenerator] Creating Pokemon League Images...")
try! pokemonDir.forEachEntry { (pokemonFilename) in
if !pokemonFilename.contains(".png") {
return
}
let pokemonFile = File(pokemonDir.path + pokemonFilename)
let pokemonId = pokemonFilename.replacingOccurrences(of: ".png", with: "")
let newFileFirst = File(pokemonLeagueDir.path + pokemonId + "_1.png")
if !newFileFirst.exists {
Log.debug(message: "[ImageGenerator] Creating #1 Pokemon League Images \(pokemonId)")
combineImagesLeague(image1: pokemonFile.path, image2: firstFile.path, output: newFileFirst.path)
}
let newFileSecond = File(pokemonLeagueDir.path + pokemonId + "_2.png")
if !newFileSecond.exists {
Log.debug(message: "[ImageGenerator] Creating #2 Pokemon League Images \(pokemonId)")
combineImagesLeague(image1: pokemonFile.path, image2: secondFile.path,
output: newFileSecond.path)
}
let newFileThird = File(pokemonLeagueDir.path + pokemonId + "_3.png")
if !newFileThird.exists {
Log.debug(message: "[ImageGenerator] Creating #3 Pokemon League Images \(pokemonId)")
combineImagesLeague(image1: pokemonFile.path, image2: thirdFile.path, output: newFileThird.path)
}
}
Log.info(message: "[ImageGenerator] Pokemon League Images created.")
} else {
Log.warning(message: "[ImageGenerator] Creating Pokemon League Images (missing Dirs)")
if !pokemonDir.exists {
Log.info(message: "[ImageGenerator] Missing dir \(pokemonDir.path)")
}
if !firstFile.exists {
Log.info(message: "[ImageGenerator] Missing file \(firstFile.path)")
}
if !secondFile.exists {
Log.info(message: "[ImageGenerator] Missing file \(secondFile.path)")
}
if !thirdFile.exists {
Log.info(message: "[ImageGenerator] Missing file \(thirdFile.path)")
}
}

if raidDir.exists && gymDir.exists && eggDir.exists && unkownEggDir.exists && pokemonDir.exists {

Log.info(message: "[ImageGenerator] Creating Raid Images...")
Expand Down Expand Up @@ -265,6 +316,7 @@ class ImageGenerator {
}
}

Log.info(message: "[ImageGenerator] Done")
Threading.destroyQueue(thread)

}
Expand Down Expand Up @@ -305,4 +357,16 @@ class ImageGenerator {
_ = Shell("rm", "-f", "tmp1.png").run()
_ = Shell("rm", "-f", "tmp2.png").run()
}

private static func combineImagesLeague(image1: String, image2: String, output: String) {
_ = Shell("/usr/local/bin/convert", "-limit", "thread", "1", image1, "-background", "none",
"-resize", "96x96", "-gravity", "center", "tmp1.png").run(environment: magickEnv)
_ = Shell("/usr/local/bin/convert", "-limit", "thread", "1", image2, "-background", "none",
"-resize", "64x64", "-gravity", "center", "tmp2.png").run(environment: magickEnv)
_ = Shell("/usr/local/bin/convert", "-limit", "thread", "1", "tmp1.png", "tmp2.png",
"-gravity", "SouthWest", "-compose", "over", "-composite", output)
.run(environment: magickEnv)
_ = Shell("rm", "-f", "tmp1.png").run()
_ = Shell("rm", "-f", "tmp2.png").run()
}
}
Loading