Initial commit
This commit is contained in:
commit
85d23c8c95
49
src/main.py
Normal file
49
src/main.py
Normal file
@ -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")
|
BIN
static/empty.jpg
Normal file
BIN
static/empty.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
41
static/index.html
Normal file
41
static/index.html
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>leafblade Minecraft Server</title>
|
||||||
|
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
#map {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
@media (max-width:768px) {
|
||||||
|
#overlay { width: 100% }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="container"></div>
|
||||||
|
this is the base site
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
41
static/ui.html
Normal file
41
static/ui.html
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>leafblade Minecraft Server</title>
|
||||||
|
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
#map {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
@media (max-width:768px) {
|
||||||
|
#overlay { width: 100% }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="container"></div>
|
||||||
|
this is the UI
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
75
static/unmined.leaflet.patched.js
Normal file
75
static/unmined.leaflet.patched.js
Normal file
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user