forked from Giotino/LessDestructiveFarm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
31,235 additions
and
0 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,9 @@ | ||
/node_modules/ | ||
|
||
/build/ | ||
/.next/ | ||
|
||
/.env | ||
/game/* | ||
|
||
schema.gql |
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,9 @@ | ||
/node_modules/ | ||
|
||
/build/ | ||
/.next/ | ||
|
||
/.env | ||
/game/* | ||
|
||
!/game/.gitkeep |
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,6 @@ | ||
{ | ||
"singleQuote": true, | ||
"printWidth": 100, | ||
"tabWidth": 2, | ||
"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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM node:16 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
ADD ./package.json . | ||
ADD ./package-lock.json . | ||
|
||
RUN npm i | ||
|
||
RUN npx next telemetry disable | ||
|
||
ADD . . | ||
RUN npm run build | ||
|
||
ENV NODE_ENV production | ||
RUN npm prune --production | ||
|
||
EXPOSE 3000 | ||
|
||
CMD [ "npm", "start" ] |
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,8 @@ | ||
# Less Destructive Farm | ||
|
||
Look at the examples in `game-archive`, you should put your node module that export a submitter with the game configuration in the `game` folder. | ||
|
||
The package.json and the other module files should be directly inside the game folder: | ||
- game/package.json | ||
- game/index.js | ||
- game/... |
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,29 @@ | ||
version: '3' | ||
|
||
services: | ||
app: | ||
build: . | ||
depends_on: | ||
- postgres | ||
environment: | ||
- DB_HOST=postgres | ||
- DB_NAME=farm | ||
- DB_USER=postgres | ||
- DB_PASS=postgres | ||
- DB_DIALECT=postgres | ||
volumes: | ||
- ./game:/usr/src/app/game | ||
ports: | ||
- '3000:3000' | ||
|
||
postgres: | ||
image: postgres:12 | ||
environment: | ||
- POSTGRES_DB=farm | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=postgres | ||
volumes: | ||
- pg_data:/var/lib/postgresql/data | ||
|
||
volumes: | ||
pg_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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const got = require('got'); | ||
|
||
const SYSTEM_IP = 'http://HTTP_FLAG_SUBMISSION_URL/flags'; | ||
const TEAM_TOKEN = ''; | ||
const TIMEOUT_MS = 5000; | ||
const teams = require('./teams.json'); | ||
|
||
module.exports = { | ||
flagFormat: '[A-Z0-9]{31}=', | ||
submitInterval: 120, | ||
teams, | ||
submitFlags: async (flags, onSubmit) => { | ||
const tot = flags.length; | ||
const chunkSize = 20; | ||
for (let i = 0; i<tot-chunkSize; i+=chunkSize) { | ||
const answer = await got.put(SYSTEM_IP, { | ||
headers: { | ||
'X-Team-Token': TEAM_TOKEN | ||
}, | ||
timeout: TIMEOUT_MS, | ||
body: JSON.stringify(flags.slice(i, i+chunkSize)) | ||
}).json(); | ||
|
||
for (const a of answer) { | ||
await onSubmit(a.flag, a.status ? 'ACCEPTED' : 'REJECTED', a.msg.split(']')[1]); | ||
} | ||
} | ||
} | ||
}; |
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,14 @@ | ||
{ | ||
"name": "game", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "UNLICENSED", | ||
"dependencies": { | ||
"got": "^11.8.1" | ||
} | ||
} |
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,85 @@ | ||
const { Socket } = require('net'); | ||
|
||
const SYSTEM_IP = 'TCP_FLAG_SUBMISSION_IP'; | ||
const SYSTEM_PORT = 31337; | ||
const TIMEOUT_MS = 5000; | ||
const teams = require('./teams.json'); | ||
|
||
//status: 'QUEUED' | 'SKIPPED' | 'ACCEPTED' | 'REJECTED' | ||
const responseToStatus = (response) => { | ||
response = response.toLowerCase(); | ||
if (response.startsWith('[ok]')) return 'ACCEPTED'; | ||
if (response.startsWith('[err]')) return 'REJECTED'; | ||
return 'QUEUED'; | ||
}; | ||
|
||
module.exports = { | ||
flagFormat: '/^\w{31}=$/', | ||
submitInterval: 120, | ||
teams, | ||
submitFlags: (flags, onSubmit) => | ||
new Promise(async (resolve, reject) => { | ||
const socket = new Socket(); | ||
|
||
socket.setTimeout(TIMEOUT_MS); | ||
|
||
let buffer = ''; | ||
const untilNewline = (chunk) => { | ||
buffer += chunk; | ||
if (buffer.includes('\n')) { | ||
const rows = buffer.split(/\n/g); | ||
buffer = rows.pop(); | ||
|
||
return rows; | ||
} | ||
return null; | ||
}; | ||
|
||
let submitted = 0; | ||
|
||
socket.on('connect', () => { | ||
// Send all flag | ||
(async () => { | ||
for (const flag of flags) if (!socket.destroyed) socket.write(flag + '\n'); | ||
})(); | ||
}); | ||
|
||
// Work on responses | ||
socket.on('data', async (chunk) => { | ||
const rows = untilNewline(chunk); | ||
if (rows) { | ||
for (const row of rows) { | ||
const response = row.trim(); | ||
|
||
if (response.toLowerCase().includes('unavailable')) { | ||
socket.end(); | ||
break; | ||
} | ||
|
||
console.log(response); | ||
const status = responseToStatus(response); | ||
console.log(status); | ||
await onSubmit(flags[submitted++], status, response); // await or the DB is going to explode | ||
if (submitted == flags.length) socket.end(); | ||
} | ||
} | ||
}); | ||
|
||
socket.on('timeout', () => { | ||
console.log('Socket timeout'); | ||
socket.end(); | ||
}); | ||
|
||
socket.on('error', (e) => { | ||
console.log('Socket error', e); | ||
socket.end(); | ||
reject(); | ||
}); | ||
|
||
socket.on('close', () => { | ||
resolve(); | ||
}); | ||
|
||
socket.connect(SYSTEM_PORT, SYSTEM_IP, () => {}); | ||
}), | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
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 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> |
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,7 @@ | ||
{ | ||
"verbose": true, | ||
"watch": ["src/*"], | ||
"ignore": ["node_modules", ".next", "src/pages", "src/next"], | ||
"ext": "js ts tsx json", | ||
"exec": "ts-node --project tsconfig.server.json src/server.ts" | ||
} |
Oops, something went wrong.