commit 85d23c8c9505864171305c5dcb73b2706d983c34 Author: Dominic Zimmer Date: Thu Apr 16 14:40:46 2020 +0200 Initial commit 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 0000000..2e227ee Binary files /dev/null and b/static/empty.jpg differ diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..0fb4ee0 --- /dev/null +++ b/static/index.html @@ -0,0 +1,41 @@ + + + + + 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