initial commit
This commit is contained in:
commit
b504782bcd
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
DuckRevamp/*
|
||||
server/node_modules/*
|
BIN
client/images/DuckIcon.png
Normal file
BIN
client/images/DuckIcon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 143 KiB |
BIN
client/images/dancing-duckdancing.gif
Normal file
BIN
client/images/dancing-duckdancing.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 398 KiB |
51
client/index.html
Normal file
51
client/index.html
Normal file
|
@ -0,0 +1,51 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="images/DuckIcon.png" />
|
||||
<title>Dancing Duck</title>
|
||||
<style>
|
||||
#customAlert {
|
||||
display: none;
|
||||
z-index: 1;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background-color: white;
|
||||
border: 2px solid black;
|
||||
border-radius: 10px;
|
||||
width: 75%;
|
||||
height: 75%;
|
||||
color: black !important;
|
||||
}
|
||||
#customAlert > button {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
width: auto !important;
|
||||
height: auto !important;
|
||||
}
|
||||
#customAlert > * {
|
||||
margin: auto;
|
||||
padding: auto;
|
||||
color: black !important;
|
||||
}
|
||||
#customAlert > img {
|
||||
display: inline-block;
|
||||
object-fit: contain;
|
||||
height: 100%;
|
||||
width: 100%
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="setup();" style="font-family:arial; background-color:black;color:white;">
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script src="js/client.js"></script>
|
||||
<div id="customAlert"></div>
|
||||
<h1 style="text-align:center"><a title="Das E steht für Reichtum">(E)</a>nt<a title="Das e steht für einfach mal die Fr**se halten">e</a></h1>
|
||||
<div style="display: flex; justify-content: center; align-items: center;">
|
||||
<p style="text-align: right"> It hurts when IP<br>Umdrehungen: <a id="countE" title="Zahl kann je nach Zeit unterschiedlich sein.">0</a><br>Shots pro Person: <a id="countS">0</a></p>
|
||||
<img title="DUCK DUCK DUCK DUCK DUCK DUCK DUCK GOOSE DUCK DUCK DUCK DUCK DUCK DUCK DUCK" src="images/dancing-duckdancing.gif">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
96
client/js/client.js
Normal file
96
client/js/client.js
Normal file
|
@ -0,0 +1,96 @@
|
|||
const socket = io();
|
||||
let count = 0;
|
||||
let loaded = false;
|
||||
let ownID = -1;
|
||||
|
||||
function setCount(c) {
|
||||
document.getElementById("countE").innerText = c;
|
||||
document.getElementById("countS").innerText = Math.round(c/70000)-18;
|
||||
}
|
||||
|
||||
function setup() {
|
||||
setTimeout(()=>{
|
||||
setInterval(()=>{
|
||||
count++;
|
||||
setCount(count);
|
||||
},5600);
|
||||
setInterval(()=>{
|
||||
socket.emit('duckUpdate', count, ownID);
|
||||
},168000);
|
||||
},1000);
|
||||
}
|
||||
|
||||
socket.on('connected', (c, p) => {
|
||||
if (!loaded) {
|
||||
console.log("Connected. Received:", c, "; Using ID:", p);
|
||||
count = c;
|
||||
setCount(c);
|
||||
ownID = p;
|
||||
loaded = true;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('message', (i, s, t) => {
|
||||
// console.log("Alert", m, "with", i, "in", t, "ms.");
|
||||
setTimeout(()=>{
|
||||
let aM = document.getElementById("customAlert");
|
||||
aM.style.display = "block";
|
||||
if (i != "") {
|
||||
let aI = document.createElement("img");
|
||||
aI.src = i;
|
||||
aI.subreddit = s;
|
||||
aM.appendChild(aI);
|
||||
}
|
||||
|
||||
let gT = document.createElement("p");
|
||||
gT.innerText = "Rate, von welchem Subreddit dieses Bild stammt:";
|
||||
let gI = document.createElement("input");
|
||||
gI.type = "text";
|
||||
let gB = document.createElement("a");
|
||||
gB.style.border = "2px black solid";
|
||||
gB.innerText = "Absenden";
|
||||
gB.onclick = e => {
|
||||
const parent = e.target.parentElement;
|
||||
let sub = parent.getElementsByTagName("img")[0].subreddit;
|
||||
let guess = parent.getElementsByTagName("input")[0].value;
|
||||
if (guess == sub) {
|
||||
alert("Du hast den richtigen Subreddit erraten!");
|
||||
} else {
|
||||
alert("Das war wohl leider die falsche Antwort.");
|
||||
}
|
||||
};
|
||||
aM.appendChild(gT);
|
||||
aM.appendChild(gI);
|
||||
aM.appendChild(gB);
|
||||
|
||||
let aB = document.createElement("button");
|
||||
aB.innerText = "Schließen";
|
||||
aB.onclick = e => {
|
||||
let pE = e.target.parentElement;
|
||||
pE.style.display = "none";
|
||||
pE.innerHTML = "";
|
||||
};
|
||||
aM.appendChild(aB);
|
||||
}, t);
|
||||
});
|
||||
|
||||
socket.on('update', c => {
|
||||
console.log("Received updated Count:", c);
|
||||
count = c;
|
||||
});
|
||||
|
||||
socket.on('receiveMessage', (otherID, message) => {
|
||||
console.log("User '" + otherID + "':", message);
|
||||
});
|
||||
|
||||
function querryRIF(imageSearch = Array(), delay = 0) {
|
||||
socket.emit("duckRIF", imageSearch, delay);
|
||||
}
|
||||
|
||||
function sendMessage(message, userID) {
|
||||
socket.emit("duckMessage", ownID, userID, message);
|
||||
}
|
||||
|
||||
function nickname(name) {
|
||||
socket.emit('duckRename', ownID, name);
|
||||
}
|
1
server/count.save
Normal file
1
server/count.save
Normal file
|
@ -0,0 +1 @@
|
|||
2191551
|
4045
server/package-lock.json
generated
Normal file
4045
server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
server/package.json
Normal file
22
server/package.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "server",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon server.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^0.24.0",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"express": "^4.17.3",
|
||||
"global-agent": "^3.0.0",
|
||||
"nodemon": "^2.0.15",
|
||||
"reddit-image-fetcher": "^2.0.10",
|
||||
"reddit.images": "^1.0.7",
|
||||
"socket.io": "^4.4.1"
|
||||
}
|
||||
}
|
210
server/server.js
Normal file
210
server/server.js
Normal file
|
@ -0,0 +1,210 @@
|
|||
// Start Date: 2021/10/11 15:00:00
|
||||
|
||||
const port = 3000;
|
||||
|
||||
/*
|
||||
const axios = require('axios');
|
||||
const cheerio = require('cheerio');
|
||||
*/
|
||||
|
||||
const RIF = require('reddit-image-fetcher');
|
||||
/*
|
||||
const GPA = require('global-agent');
|
||||
const NPA = GPA.createGlobalProxyAgent();
|
||||
NPA.HTTP_PROXY = 'http://webproxy.bs.ptb.de:8080';
|
||||
NPA.HTTPS_PROXY = 'http://webproxy.bs.ptb.de:8080';
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const cSave = __dirname+'/count.save';
|
||||
|
||||
const http = require('http');
|
||||
const express = require('express');
|
||||
const socketio = require('socket.io');
|
||||
|
||||
const app = express();
|
||||
const clientPath = __dirname+'/../client';
|
||||
console.log('Serving static from ' + clientPath);
|
||||
app.use(express.static(clientPath));
|
||||
|
||||
const server = http.createServer(app);
|
||||
const io = socketio(server);
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(r => {
|
||||
setTimeout(r, ms);
|
||||
});
|
||||
}
|
||||
|
||||
function saveCount() {
|
||||
let actualCount = Math.floor((new Date() - new Date("2021/10/11 15:00:00")) / 5600);
|
||||
if (duckCount < actualCount || typeof duckCount != "number") { duckCount = actualCount; }
|
||||
console.log("Newly Calculated: "+actualCount+"; Saved Count: "+duckCount);
|
||||
fs.writeFile(cSave, duckCount.toString(), e=>{if(e){console.log("Error writing to SAVE file on", new Date());}});
|
||||
}
|
||||
|
||||
server.on('error', err => {
|
||||
console.error('Server error:', err);
|
||||
});
|
||||
|
||||
server.on('close', saveCount);
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log('Server Started on Port '+port);
|
||||
fs.readFile(cSave, {encoding: 'utf-8'}, (e,d)=>{
|
||||
if(e){console.log("Error reading from SAVE file on", new Date());return;}
|
||||
console.log("Loaded Count:", d);
|
||||
duckCount = parseInt(d);
|
||||
});
|
||||
setInterval(()=>{duckCount++;},5600);
|
||||
setInterval(saveCount,336000);
|
||||
// setTimeout(()=>{console.clear();},10000);
|
||||
});
|
||||
|
||||
let duckCount = 0;
|
||||
let duckClients = Array();
|
||||
|
||||
io.on('connection', socket => {
|
||||
let id = -1;
|
||||
|
||||
console.log("New Client has connected.");
|
||||
while (true) {
|
||||
let current = Math.floor(Math.random()*89+10);
|
||||
let isUsed = false;
|
||||
for (let i = 0; i < duckClients.length; i++) {
|
||||
if (duckClients[i].uid == current) {
|
||||
isUsed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isUsed) {
|
||||
id = current;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (id != -1) {
|
||||
console.log('Handing ID', id);
|
||||
socket.emit('connected', duckCount, id);
|
||||
duckClients.push({socket, id});
|
||||
}
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
for (let i = 0; i < duckClients.length; i++) {
|
||||
if (duckClients[i].socket == socket) {
|
||||
console.log("Disconnecting DUCK User. ID", duckClients[i].id);
|
||||
duckClients.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('updateCount', c => {
|
||||
duckCount = c;
|
||||
saveCount();
|
||||
});
|
||||
|
||||
socket.on('saveCount', saveCount);
|
||||
|
||||
socket.on('duckUpdate', (c, p)=>{
|
||||
// console.log("Received Update Task.");
|
||||
if (c < duckCount) {
|
||||
// console.log("Searching Client with ID:", p);
|
||||
for (let i = 0; i < duckClients.length; i++) {
|
||||
if (duckClients[i].id == p) {
|
||||
// console.log("Updating Client with ID:", p);
|
||||
duckClients[i].socket.emit('update', duckCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('duckRIF', async (s, t) => {
|
||||
let imgSrc = "", subreddit = "";
|
||||
if (s.length > 0) {
|
||||
console.log("Spreading Reddit-Image(/-s) (from subs.: '" + s.join(', ') + "') after:", t, "ms.");
|
||||
let gotResult = false;
|
||||
|
||||
await RIF.fetch({
|
||||
type: 'custom',
|
||||
total: 50,
|
||||
subreddit: s
|
||||
}).then(r=>{
|
||||
gotResult = true;
|
||||
if (r && r != null) {
|
||||
if (r.length > 0) {
|
||||
const index = Math.floor(r.length * Math.random());
|
||||
if (!r[index].NSFW && r[index].image != "") {
|
||||
imgSrc = r[index].image;
|
||||
subreddit = r[index].subreddit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}).catch(e=>{
|
||||
gotResult = true;
|
||||
consle.log("Error on 'RIF':",e);
|
||||
});
|
||||
|
||||
while (!gotResult) {
|
||||
await sleep(100);
|
||||
}
|
||||
|
||||
/*
|
||||
let data;
|
||||
axios.get(
|
||||
"https://reddit.com/r/" + s
|
||||
).then(r => {
|
||||
data = r.data;
|
||||
gotResult = true;
|
||||
}).catch(e => {
|
||||
gotResult = true;
|
||||
console.log("Error on 'Axios':", e);
|
||||
});
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const urlMeme = $("._2_tDEnGMLxpM6uOa2kaDB3.ImageBox-image.media-element._1XWObl-3b9tPy64oaG6fax");
|
||||
const indexValue = Math.floor(Math.random()*urlMeme.length);
|
||||
imgSrc = urlMeme[indexValue].attribs.src;
|
||||
*/
|
||||
}
|
||||
|
||||
if (imgSrc != "") {
|
||||
duckClients.forEach(c => {
|
||||
c.socket.emit('message', imgSrc, subreddit, t);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('duckMessage', (inID, outName, msg) => {
|
||||
let inName = inID;
|
||||
for (let i = 0; i < duckClients.length; i++) {
|
||||
if (duckClients[i].id == inID && duckClients[i].nickname) {
|
||||
inName = duckClients[i].nickname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
let outID = outName;
|
||||
for (let i = 0; i < duckClients.length; i++) {
|
||||
if (duckClients[i].nickname == outName) {
|
||||
outID = duckClients[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < duckClients.length; i++) {
|
||||
if (duckClients[i].id == outID) {
|
||||
duckClients[i].socket.emit('receiveMessage', inName, msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('duckRename', (id, nn) => {
|
||||
for (let i = 0; i < duckClients.length; i++) {
|
||||
if (duckClients[i].id == id) {
|
||||
duckClients[i].nickname = nn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user