-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Protonull/prettier
Update prettier config + run prettier; update better-sqlite3
- Loading branch information
Showing
25 changed files
with
1,381 additions
and
1,342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Prettier | ||
4355eb2a9a3c7694e0014a5ca2e4fb187a9806e6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
{ | ||
"name": "civmap-server", | ||
"version": "SNAPSHOT", | ||
"private": true, | ||
"author": "Gjum", | ||
"license": "GPL-3.0-only", | ||
"scripts": { | ||
"build": "tsc", | ||
"format": "prettier -w .", | ||
"test": "true", | ||
"start": "node -r source-map-support/register dist/main.js", | ||
"start:dev": "tsc && node --inspect -r source-map-support/register dist/main.js" | ||
}, | ||
"dependencies": { | ||
"async-mutex": "^0.4.0", | ||
"better-sqlite3": "^8.5.0", | ||
"kysely": "^0.26.1", | ||
"source-map-support": "^0.5.21", | ||
"zod": "^3.21.4", | ||
"zod-validation-error": "^1.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/better-sqlite3": "^7.6.4", | ||
"@types/node": "^18.17.4", | ||
"dotenv": "^16.0.1", | ||
"prettier": "^3.0.1", | ||
"typescript": "^5.1.6" | ||
}, | ||
"prettier": { | ||
"useTabs": true, | ||
"tabWidth": 2, | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"semi": false | ||
} | ||
"name": "civmap-server", | ||
"version": "SNAPSHOT", | ||
"private": true, | ||
"author": "Gjum", | ||
"license": "GPL-3.0-only", | ||
"scripts": { | ||
"build": "tsc", | ||
"format": "prettier -w .", | ||
"test": "true", | ||
"start": "node -r source-map-support/register dist/main.js", | ||
"start:dev": "tsc && node --inspect -r source-map-support/register dist/main.js" | ||
}, | ||
"dependencies": { | ||
"async-mutex": "^0.4.0", | ||
"better-sqlite3": "^9.5.0", | ||
"kysely": "^0.26.1", | ||
"source-map-support": "^0.5.21", | ||
"zod": "^3.21.4", | ||
"zod-validation-error": "^1.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/better-sqlite3": "^7.6.4", | ||
"@types/node": "^18.17.4", | ||
"dotenv": "^16.0.1", | ||
"prettier": "^3.0.1", | ||
"typescript": "^5.1.6" | ||
}, | ||
"prettier": { | ||
"useTabs": false, | ||
"tabWidth": 4, | ||
"trailingComma": "all", | ||
"singleQuote": false, | ||
"semi": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
import { spawn } from 'child_process' | ||
import { promisify } from 'util' | ||
import * as database from './database' | ||
import { spawn } from "child_process"; | ||
import { promisify } from "util"; | ||
import * as database from "./database"; | ||
|
||
export async function renderTile( | ||
dimension: string, | ||
tileX: number, | ||
tileZ: number, | ||
dimension: string, | ||
tileX: number, | ||
tileZ: number, | ||
) { | ||
const allChunks = await database.getRegionChunks(dimension, tileX, tileZ) | ||
const allChunks = await database.getRegionChunks(dimension, tileX, tileZ); | ||
|
||
const proc = spawn( | ||
'../render/target/release/civmap-render', | ||
[String(tileX), String(tileZ), 'tiles'], | ||
{ cwd: '../render' }, // so render can find blocks.json | ||
) | ||
proc.stdout.pipe(process.stdout) | ||
proc.stderr.pipe(process.stderr) | ||
const proc = spawn( | ||
"../render/target/release/civmap-render", | ||
[String(tileX), String(tileZ), "tiles"], | ||
{ cwd: "../render" }, // so render can find blocks.json | ||
); | ||
proc.stdout.pipe(process.stdout); | ||
proc.stderr.pipe(process.stderr); | ||
|
||
const write = promisify<Buffer, void>(proc.stdin.write.bind(proc.stdin)) | ||
const write = promisify<Buffer, void>(proc.stdin.write.bind(proc.stdin)); | ||
|
||
const numBuf = Buffer.allocUnsafe(4) | ||
numBuf.writeUInt32BE(allChunks.length) | ||
await write(numBuf) | ||
const numBuf = Buffer.allocUnsafe(4); | ||
numBuf.writeUInt32BE(allChunks.length); | ||
await write(numBuf); | ||
|
||
const chunkHeaderBuf = Buffer.allocUnsafe(4 + 4 + 2) // reused. 32+32+16 bit | ||
for (const chunk of allChunks) { | ||
chunkHeaderBuf.writeInt32BE(chunk.chunk_x, 0) | ||
chunkHeaderBuf.writeInt32BE(chunk.chunk_z, 4) | ||
chunkHeaderBuf.writeUInt16BE(chunk.version, 8) | ||
await write(chunkHeaderBuf) | ||
await write(chunk.data) | ||
} | ||
const chunkHeaderBuf = Buffer.allocUnsafe(4 + 4 + 2); // reused. 32+32+16 bit | ||
for (const chunk of allChunks) { | ||
chunkHeaderBuf.writeInt32BE(chunk.chunk_x, 0); | ||
chunkHeaderBuf.writeInt32BE(chunk.chunk_z, 4); | ||
chunkHeaderBuf.writeUInt16BE(chunk.version, 8); | ||
await write(chunkHeaderBuf); | ||
await write(chunk.data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,137 @@ | ||
import lib_readline from 'readline' | ||
import lib_stream from 'stream' | ||
import lib_readline from "readline"; | ||
import lib_stream from "stream"; | ||
|
||
import * as metadata from './metadata' | ||
import * as metadata from "./metadata"; | ||
|
||
//idk where these come from lol | ||
interface TerminalExtras { | ||
output: lib_stream.Writable | ||
_refreshLine(): void | ||
output: lib_stream.Writable; | ||
_refreshLine(): void; | ||
} | ||
type TermType = lib_readline.Interface & TerminalExtras | ||
type TermType = lib_readline.Interface & TerminalExtras; | ||
const term = lib_readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}) as TermType | ||
input: process.stdin, | ||
output: process.stdout, | ||
}) as TermType; | ||
|
||
if (!('MAPSYNC_DUMB_TERM' in process.env)) { | ||
//Adapted from https://stackoverflow.com/questions/10606814/readline-with-console-log-in-the-background/10608048#10608048 | ||
function fixStdoutFor(term: TermType) { | ||
var oldStdout = process.stdout | ||
var newStdout = Object.create(oldStdout) | ||
var oldStderr = process.stderr | ||
var newStderr = Object.create(oldStdout) | ||
function write_func(outout: lib_stream.Writable) { | ||
return function (this: lib_stream.Writable) { | ||
term.output.write('\x1b[2K\r') | ||
var result = outout.write.apply( | ||
this, | ||
Array.prototype.slice.call(arguments) as any, | ||
) | ||
term._refreshLine() | ||
return result | ||
} | ||
} | ||
newStdout.write = write_func(oldStdout) | ||
newStderr.write = write_func(oldStderr) | ||
Object.defineProperty(process, 'stdout', { | ||
get: function () { | ||
return newStdout | ||
}, | ||
}) | ||
Object.defineProperty(process, 'stderr', { | ||
get: function () { | ||
return newStderr | ||
}, | ||
}) | ||
} | ||
fixStdoutFor(term) | ||
const old_log = console.log | ||
console.log = function () { | ||
term.output.write('\x1b[2K\r') | ||
old_log.apply(this, arguments as any) | ||
term._refreshLine() | ||
} | ||
const old_error = console.error | ||
console.error = function () { | ||
term.output.write('\x1b[2K\r') | ||
old_error.apply(this, arguments as any) | ||
term._refreshLine() | ||
} | ||
if (!("MAPSYNC_DUMB_TERM" in process.env)) { | ||
//Adapted from https://stackoverflow.com/questions/10606814/readline-with-console-log-in-the-background/10608048#10608048 | ||
function fixStdoutFor(term: TermType) { | ||
var oldStdout = process.stdout; | ||
var newStdout = Object.create(oldStdout); | ||
var oldStderr = process.stderr; | ||
var newStderr = Object.create(oldStdout); | ||
function write_func(outout: lib_stream.Writable) { | ||
return function (this: lib_stream.Writable) { | ||
term.output.write("\x1b[2K\r"); | ||
var result = outout.write.apply( | ||
this, | ||
Array.prototype.slice.call(arguments) as any, | ||
); | ||
term._refreshLine(); | ||
return result; | ||
}; | ||
} | ||
newStdout.write = write_func(oldStdout); | ||
newStderr.write = write_func(oldStderr); | ||
Object.defineProperty(process, "stdout", { | ||
get: function () { | ||
return newStdout; | ||
}, | ||
}); | ||
Object.defineProperty(process, "stderr", { | ||
get: function () { | ||
return newStderr; | ||
}, | ||
}); | ||
} | ||
fixStdoutFor(term); | ||
const old_log = console.log; | ||
console.log = function () { | ||
term.output.write("\x1b[2K\r"); | ||
old_log.apply(this, arguments as any); | ||
term._refreshLine(); | ||
}; | ||
const old_error = console.error; | ||
console.error = function () { | ||
term.output.write("\x1b[2K\r"); | ||
old_error.apply(this, arguments as any); | ||
term._refreshLine(); | ||
}; | ||
} | ||
|
||
async function handle_input(input: string): Promise<void> { | ||
const command_end_i = input.indexOf(' ') | ||
const command = ( | ||
command_end_i > -1 ? input.substring(0, command_end_i) : input | ||
).toLowerCase() | ||
const extras = command_end_i > -1 ? input.substring(command_end_i + 1) : '' | ||
const command_end_i = input.indexOf(" "); | ||
const command = ( | ||
command_end_i > -1 ? input.substring(0, command_end_i) : input | ||
).toLowerCase(); | ||
const extras = command_end_i > -1 ? input.substring(command_end_i + 1) : ""; | ||
|
||
if (command === '') { | ||
} else if (command === 'ping') console.log('pong') | ||
else if (command === 'help') { | ||
console.log('ping - Prints "pong" for my sanity. -SirAlador') | ||
console.log( | ||
'help - Prints info about commands, including the help command.', | ||
) | ||
console.log('whitelist_load - Loads the whitelist from disk') | ||
console.log('whitelist_save - Saves the whitelist to disk') | ||
console.log( | ||
'whitelist_add <uuid> - Adds the given account UUID to the\n whitelist, and saves the whitelist to disk', | ||
) | ||
console.log( | ||
'whitelist_add_ign <ign> - Adds the UUID cached with the\n given IGN to the whitelist, and saves the whitelist to disk', | ||
) | ||
console.log( | ||
'whitelist_remove <uuid> - Removes the given account UUID\n from the whitelist, and saves the whitelist to disk', | ||
) | ||
console.log( | ||
'whitelist_remove_ign <ign> - Removes the UUID cached with\n the given IGN from the whitelist, and saves the whitelist to disk', | ||
) | ||
} else if (command === 'whitelist_load') await metadata.loadWhitelist() | ||
else if (command === 'whitelist_save') await metadata.saveWhitelist() | ||
else if (command === 'whitelist_add') { | ||
if (extras.length === 0) | ||
throw new Error('Did not provide UUID to whitelist') | ||
const uuid = extras | ||
metadata.whitelist.add(uuid) | ||
await metadata.saveWhitelist() | ||
} else if (command === 'whitelist_add_ign') { | ||
if (extras.length === 0) | ||
throw new Error('Did not provide UUID to whitelist') | ||
const ign = extras | ||
const uuid = metadata.getCachedPlayerUuid(ign) | ||
if (uuid == null) throw new Error('No cached UUID for IGN ' + ign) | ||
metadata.whitelist.add(uuid) | ||
await metadata.saveWhitelist() | ||
} else if (command === 'whitelist_remove') { | ||
if (extras.length === 0) | ||
throw new Error('Did not provide UUID to whitelist') | ||
const uuid = extras | ||
metadata.whitelist.delete(uuid) | ||
await metadata.saveWhitelist() | ||
} else if (command === 'whitelist_remove_ign') { | ||
if (extras.length === 0) | ||
throw new Error('Did not provide UUID to whitelist') | ||
const ign = extras | ||
const uuid = metadata.getCachedPlayerUuid(ign) | ||
if (uuid == null) throw new Error('No cached UUID for IGN ' + ign) | ||
metadata.whitelist.delete(uuid) | ||
await metadata.saveWhitelist() | ||
} else { | ||
throw new Error(`Unknown command "${command}"`) | ||
} | ||
if (command === "") { | ||
} else if (command === "ping") console.log("pong"); | ||
else if (command === "help") { | ||
console.log('ping - Prints "pong" for my sanity. -SirAlador'); | ||
console.log( | ||
"help - Prints info about commands, including the help command.", | ||
); | ||
console.log("whitelist_load - Loads the whitelist from disk"); | ||
console.log("whitelist_save - Saves the whitelist to disk"); | ||
console.log( | ||
"whitelist_add <uuid> - Adds the given account UUID to the\n whitelist, and saves the whitelist to disk", | ||
); | ||
console.log( | ||
"whitelist_add_ign <ign> - Adds the UUID cached with the\n given IGN to the whitelist, and saves the whitelist to disk", | ||
); | ||
console.log( | ||
"whitelist_remove <uuid> - Removes the given account UUID\n from the whitelist, and saves the whitelist to disk", | ||
); | ||
console.log( | ||
"whitelist_remove_ign <ign> - Removes the UUID cached with\n the given IGN from the whitelist, and saves the whitelist to disk", | ||
); | ||
} else if (command === "whitelist_load") await metadata.loadWhitelist(); | ||
else if (command === "whitelist_save") await metadata.saveWhitelist(); | ||
else if (command === "whitelist_add") { | ||
if (extras.length === 0) | ||
throw new Error("Did not provide UUID to whitelist"); | ||
const uuid = extras; | ||
metadata.whitelist.add(uuid); | ||
await metadata.saveWhitelist(); | ||
} else if (command === "whitelist_add_ign") { | ||
if (extras.length === 0) | ||
throw new Error("Did not provide UUID to whitelist"); | ||
const ign = extras; | ||
const uuid = metadata.getCachedPlayerUuid(ign); | ||
if (uuid == null) throw new Error("No cached UUID for IGN " + ign); | ||
metadata.whitelist.add(uuid); | ||
await metadata.saveWhitelist(); | ||
} else if (command === "whitelist_remove") { | ||
if (extras.length === 0) | ||
throw new Error("Did not provide UUID to whitelist"); | ||
const uuid = extras; | ||
metadata.whitelist.delete(uuid); | ||
await metadata.saveWhitelist(); | ||
} else if (command === "whitelist_remove_ign") { | ||
if (extras.length === 0) | ||
throw new Error("Did not provide UUID to whitelist"); | ||
const ign = extras; | ||
const uuid = metadata.getCachedPlayerUuid(ign); | ||
if (uuid == null) throw new Error("No cached UUID for IGN " + ign); | ||
metadata.whitelist.delete(uuid); | ||
await metadata.saveWhitelist(); | ||
} else { | ||
throw new Error(`Unknown command "${command}"`); | ||
} | ||
} | ||
|
||
function input_loop() { | ||
console.log('===========================================================') | ||
term.question('>', (input: string) => | ||
handle_input(input.trim()) | ||
.catch((e) => { | ||
console.error('Command failed:') | ||
console.error(e) | ||
}) | ||
.finally(input_loop), | ||
) | ||
console.log("==========================================================="); | ||
term.question(">", (input: string) => | ||
handle_input(input.trim()) | ||
.catch((e) => { | ||
console.error("Command failed:"); | ||
console.error(e); | ||
}) | ||
.finally(input_loop), | ||
); | ||
} | ||
input_loop() | ||
input_loop(); |
Oops, something went wrong.