From 85d23c8c9505864171305c5dcb73b2706d983c34 Mon Sep 17 00:00:00 2001 From: Dominic Zimmer Date: Thu, 16 Apr 2020 14:40:46 +0200 Subject: [PATCH] Initial commit --- model.py | 0 src/main.py | 49 +++++++++++++++++++ static/empty.jpg | Bin 0 -> 2005 bytes static/index.html | 41 ++++++++++++++++ static/ui.html | 41 ++++++++++++++++ static/unmined.leaflet.patched.js | 75 ++++++++++++++++++++++++++++++ 6 files changed, 206 insertions(+) create mode 100644 model.py create mode 100644 src/main.py create mode 100644 static/empty.jpg create mode 100644 static/index.html create mode 100644 static/ui.html create mode 100644 static/unmined.leaflet.patched.js diff --git a/model.py b/model.py new file mode 100644 index 0000000..e69de29 diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..d005b2f --- /dev/null +++ b/src/main.py @@ -0,0 +1,49 @@ +import aiohttp.web + +routes = aiohttp.web.RouteTableDef() + +routes.static('/static', 'static') + +admintoken = "ae33fd8cc4fdcb1ff50ba42ff48046a7" + +meta_dict = {} + +@routes.get(r'/{client:[a-z][a-z][a-z][a-z][a-z]}') +async def handler(request): + #session = request.match_info.get("session", "") + client = request.match_info.get("client", "") + print(f"{client=} accessed") + return aiohttp.web.FileResponse('static/ui.html') + + +async def handle_request(data, client): + return "foo" in data + +@routes.post('/{client}/api') +async def handler(request): + client = request.match_info.get("client", "") + + data = await request.post() + + ok = await handle_request(data, client) + if ok: + #return aiohttp.web.json_response({"x" : x}) + return aiohttp.web.Response(status=200) + else: + return aiohttp.web.Response(status=400) + +@routes.get(f"/api/{admintoken}") +async def handler(request): + return aiohttp.web.json_response(meta_dict) + +@routes.get('/') +async def handler(request): + del request # unused + return aiohttp.web.FileResponse('static/index.html') + + +if __name__ == '__main__': + app = aiohttp.web.Application() + app.add_routes(routes) + aiohttp.web.run_app(app, port=42042) + print("should save state") diff --git a/static/empty.jpg b/static/empty.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2e227ee896fc08344069fc43d5d11a2ac24ada08 GIT binary patch literal 2005 zcmeHGO=uHA6#iy6+ia6fyW4JRkbq=6i2;zW0VN^AFHZ zB-2SSvKWg2{3iwzPBGUg7OaK2#;lb}Ph|K<=}|h7IG@R$Os2<=6C03PWxG=M?FTB= zhLcT=SyR(zEdM9;Vkdw-P;z#?b~KY2r!Not{tA={csU|+d62x^p+d241I!}As9kd! zgf9?2ywIo#e1ouQ&*ln*9}J8@=H@~ToCx8z?E{7{>?RULakUmeTwENJ;O*LjR|C6A&(~JP(}kIG*`(} zN0!#dJmQ72!xY)1$TCIP6mbmms37OYL)3scWL<6RGY1d2E~bqE%6rbg?gjkUfYn9L zf861G^)4X41D;m9@$)U<$T#vYc74&?K>uan@lw~9zYaXP0z_77IVb1tBhy=&nE}4s z2SU@p;0qvdwyhhjiFMq24NQ_&m%6-n`+$sgE>9#4SqaS~Z1Y}7PgUm-m zQ5D7KQv!Z}kE#VUEf@#}Lwy5!sL$vN2K6D`7&OD-u-3mLGGs;u%&;kvFqvX}O0S~y znxSCG{A=USV5p4xTxJF&gUJTtO9;DnNa(O;D!EN@vo;!k15IX-bXlk7eK5Llb^Gfd zD{x6vN&me{Evk}AwPT8eU4mi!nISV4XPYvlF2i$|o_J>$PX>$crd>Ln + + + + leafblade Minecraft Server + + + + + + + + + + +
+ this is the base site + + + + diff --git a/static/ui.html b/static/ui.html new file mode 100644 index 0000000..5cbc075 --- /dev/null +++ b/static/ui.html @@ -0,0 +1,41 @@ + + + + + leafblade Minecraft Server + + + + + + + + + + +
+ this is the UI + + + + diff --git a/static/unmined.leaflet.patched.js b/static/unmined.leaflet.patched.js new file mode 100644 index 0000000..5879966 --- /dev/null +++ b/static/unmined.leaflet.patched.js @@ -0,0 +1,75 @@ +function Unmined() { + + this.map = function (mapId, options, regions) { + + const minMapX = options.minRegionX * 512, + minMapY = options.minRegionZ * 512, + mapWidth = (options.maxRegionX + 1 - options.minRegionX) * 512, + mapHeight = (options.maxRegionZ + 1 - options.minRegionZ) * 512, + zoomOffset = 0 - options.minZoom, + + unminedLayer = new L.TileLayer.Functional( + function (view) { + const zoom = view.zoom - zoomOffset, + zoomFactor = Math.pow(2, zoom), + + tileSize = 256, + + minTileX = Math.floor(minMapX * zoomFactor / tileSize), + minTileY = Math.floor(minMapY * zoomFactor / tileSize), + maxTileX = Math.ceil((minMapX + mapWidth) * zoomFactor / tileSize) - 1, + maxTileY = Math.ceil((minMapY + mapHeight) * zoomFactor / tileSize) - 1, + + tileX = view.tile.column, + tileY = view.tile.row, + + tileBlockSize = tileSize / zoomFactor, + tileBlockPoint = { + x: tileX * tileBlockSize, + z: tileY * tileBlockSize + }; + + const intersectsWithTile = function (region) { + return (tileBlockPoint.x < (region.x + 1) * 512) + && (tileBlockPoint.x + tileBlockSize > region.x * 512) + && (tileBlockPoint.z < (region.z + 1) * 512) + && (tileBlockPoint.z + tileBlockSize > region.z * 512); + }; + + if (tileX >= minTileX + && tileY >= minTileY + && tileX <= maxTileX + && tileY <= maxTileY + && ((regions === undefined) || regions.some(intersectsWithTile))) { + return ('/static/unmined/tiles/zoom.{z}/{xd}/{yd}/tile.{x}.{y}.' + options.imageFormat) + .replace('{z}', zoom) + .replace('{yd}', '' + Math.floor(tileY / 10)) + .replace('{xd}', '' + Math.floor(tileX / 10)) + .replace('{y}', view.tile.row) + .replace('{x}', view.tile.column); + } else { + return "/static/empty.jpg"; + } + }, + { + detectRetina: false, + bounds: [[minMapX, minMapY], [minMapX + mapWidth, minMapY + mapHeight]] + }); + + let map = L.map(mapId, { + crs: L.CRS.Simple, + minZoom: options.minZoom + zoomOffset, + maxZoom: options.maxZoom + zoomOffset, + layers: [unminedLayer], + maxBoundsViscosity: 1.0 + }).setView([0, 0], options.defaultZoom + zoomOffset); + + let northWest = map.unproject([minMapX, minMapY], map.getMaxZoom()); + let southEast = map.unproject([minMapX + mapWidth, minMapY + mapHeight], map.getMaxZoom()); + map.setMaxBounds(new L.LatLngBounds(northWest, southEast)); + + return map; + + } + +} \ No newline at end of file