Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Achievements [WIP] #239

Open
wants to merge 68 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
d46af97
Revamp beta dialog a bit, add help one, fix beta dialog script error,…
aydenp Sep 9, 2017
9472ecd
Fix javascript not automatically processing
aydenp Sep 9, 2017
9692b9c
Fix notification error
aydenp Sep 9, 2017
8fce51c
Fix get started padding
aydenp Sep 9, 2017
5afdd24
Fix password regex, captcha reset on sites without captcha
aydenp Sep 9, 2017
77e3481
Merge branch 'master' of https://www.github.com/dynasticdevelop/place
aydenp Sep 9, 2017
cf4b33d
FUCK U TRAVIS SUCK MY BALLS
aydenp Sep 9, 2017
69d806d
fix signups x2
nullpixel Sep 9, 2017
8e41439
Fix admin panel nav items
aydenp Sep 9, 2017
4769fea
Merge branch 'master' of https://www.github.com/dynasticdevelop/place
aydenp Sep 9, 2017
c505eac
Update user.js
aydenp Sep 10, 2017
25c8e91
Disable password Regex checking for now
nullpixel Sep 14, 2017
a4ed06a
updated timelapse url
deadbaed Sep 17, 2017
3f26c82
Add support for sign up/in banners
aydenp Oct 22, 2017
74adb7a
Allow null editors
aydenp Oct 22, 2017
98c7449
fix null error in leaderboard manager
nullpixel Oct 25, 2017
c80d8b1
Add maintenance configuration options to deal with situations better
nullpixel Nov 27, 2017
444a931
Fix regression introduced by c80d8b1a20b80139b9ce3b952d0a11836351f7d4
nullpixel Nov 29, 2017
d5cfaa4
Add logging for 2FA, fix rate limit store logging (#236)
aydenp Dec 23, 2017
54d8300
Update user.js
aydenp Dec 23, 2017
7d06972
-re
aydenp Dec 23, 2017
6cc38ec
Update logger.js
aydenp Dec 23, 2017
c10453f
Update logger.js
aydenp Dec 23, 2017
80cf39f
Update layout.pug
aydenp Dec 23, 2017
a95563a
Start block flags support
aydenp Dec 26, 2017
2e5de9c
Added IP and user agent views for admins ONLY (#237)
EricRabil Dec 28, 2017
b95fb8c
Fix #234
aydenp Dec 31, 2017
b5242df
Resize to 1600x1600 (#238)
nullpixel Dec 31, 2017
18c39bd
Start scalable zoom
aydenp Dec 31, 2017
a47c27c
Merge branch 'master' of https://github.com/dynastic/place
aydenp Dec 31, 2017
48aecd5
Bring back achievements tab
aydenp Dec 31, 2017
6cc8c15
Update resize.js
EricRabil Dec 31, 2017
021402c
Update resize.js
EricRabil Dec 31, 2017
4422150
To achieve, or not to achieve.
EricRabil Dec 31, 2017
8eef19c
Improved duplication removal from arrays
EricRabil Dec 31, 2017
cfbd4db
Fixed Mongoose deprecation warnings
EricRabil Dec 31, 2017
21e53eb
Ignore all subsequent changes to the achievements file
EricRabil Dec 31, 2017
0890cf2
Finish up zoom, minus grid
aydenp Dec 31, 2017
60c7e15
Deploy OCNFETTI
aydenp Jan 1, 2018
7dc7a55
Update resource version
aydenp Jan 1, 2018
18e5541
Merge branch 'master' of https://github.com/dynastic/place
aydenp Jan 1, 2018
71de6fb
Attempt to fix sizing issues
aydenp Jan 1, 2018
f76b93e
fix legit
nullpixel Jan 1, 2018
b4155e5
fix
nullpixel Jan 1, 2018
f91459b
fix?
nullpixel Jan 1, 2018
d98e918
fix x3
nullpixel Jan 1, 2018
c3f77a1
Accomodate peer-review requests
EricRabil Jan 1, 2018
e318384
Disabled confetti
EricRabil Jan 1, 2018
877a186
Ignored a dev file
EricRabil Jan 1, 2018
65483cd
lmao
nullpixel Jan 1, 2018
27625ee
Merge branch 'master' of github.com:nullpixel1/place
nullpixel Jan 1, 2018
558c4d4
Fix zoom scale during animation
aydenp Jan 3, 2018
c911fb3
Fix mouse wheel for Gecko browsers
aydenp Jan 3, 2018
19f1e90
Fix scroll wheel while in popout
aydenp Jan 3, 2018
a74175a
Fix wheel delta with new event
aydenp Jan 3, 2018
c1c9a19
Set zoomed in threshold to halfway between initial and zoomed in point
aydenp Jan 3, 2018
b38d292
Fix non-legit builds
aydenp Jan 3, 2018
9c5c58a
Fix hand element sizing
aydenp Jan 3, 2018
0cde988
Fix grid hint
aydenp Jan 3, 2018
2c515e7
Fix grid hint positioning during zoom
aydenp Jan 3, 2018
f1809b7
Update grid hint properly when using arrow navigation
aydenp Jan 3, 2018
ee00063
Better not ready message
aydenp Jan 3, 2018
8375a55
Fuck grid tbh
aydenp Jan 3, 2018
0cb2dd1
res version
aydenp Jan 3, 2018
5ea66e4
fuck travis and whoever did this
aydenp Jan 3, 2018
183f582
Bring feature/achievements up to date with master (#241)
aydenp Jan 3, 2018
ee58e05
Merge pull request #242 from dynastic/master
aydenp Jan 3, 2018
406f972
Merge branch 'master' into feature/achievements
nullpixel May 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,6 +10,7 @@ views/legit.*
config/community_guidelines.md
config/privacy_policy.md
config/tos.md
config/achievements.js
modules/*

### Linux ###
Expand Down
3 changes: 2 additions & 1 deletion app.js
Expand Up @@ -95,7 +95,8 @@ app.recreateServer = () => {
}
app.recreateServer();

mongoose.connect(app.config.database);
mongoose.connect(app.config.database, {useMongoClient: true});
mongoose.Promise = global.Promise;

const handlePendingDeletions = () => {
setInterval(() => {
Expand Down
126 changes: 126 additions & 0 deletions config/achievements.js
@@ -0,0 +1,126 @@
const olderThan = (date = Date.now(), time = {milliseconds: 0, seconds: 0, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0}) => {
let computedTime = Date.now();
if (time.milliseconds) {
computedTime -= time.milliseconds;
}
if (time.seconds) {
computedTime -= time.seconds * 1000;
}
if (time.minutes) {
computedTime -= time.minutes * 1000 * 60;
}
if (time.hours) {
computedTime -= time.hours * 1000 * 60 * 60;
}
if (time.days) {
computedTime -= time.days * 1000 * 60 * 60 * 24;
}
if (time.weeks) {
computedTime -= time.weeks * 1000 * 60 * 60 * 24 * 7;
}
if (time.months) {
let cTime = new Date();
cTime.setTime(Date.now() - computedTime);
const newMonths = cTime.getMonth() + time.months;
cTime.setMonth(newMonths);
computedTime = cTime.getTime();
}
if (time.years) {
computedTime -= time.years * 1000 * 60 * 60 * 24 * 365;
}
console.log("Minimum: " + computedTime);
console.log("Date: " + date);
return computedTime > date;
};

module.exports = [
// User has placed at least five pixels
{
name: "First Pixel!",
description: "You've placed one pixel!",
imageURL: null,
meetsCriteria(user) {
return user.placeCount >= 1;
}
},
{
name: "Ten Pixels!",
description: "Congrats on hitting ten pixels! Keep it going!",
imageURL: null,
meetsCriteria(user) {
return user.placeCount >= 10;
}
},
{
name: "100 Pixels!",
description: "W00T! Let's go let's go let's go!!! Get to 1000 pixels!",
imageURL: null,
meetsCriteria(user) {
return user.placeCount >= 100;
}
},
{
name: "1000 Pixels!",
description: "I see you, placing those pixels all sexy 'n shit.",
imageURL: null,
meetsCriteria(user) {
return user.placeCount >= 1000;
}
},
{
name: "Addict",
description: "People can safely default to assuming you're on canvas.place",
imageURL: null,
meetsCriteria(user) {
return user.placeCount >= 10000;
}
},
{
name: "Ultra-Addict",
description: "You play canvas.place so much, you should just run the website.",
imageURL: null,
meetsCriteria(user) {
return user.placeCount >= 50000;
}
},
{
name: "Beginner",
description: "You're just starting out, but don't fret. You're going great places.",
imageURL: null,
meetsCriteria(user) {
return olderThan(user.creationDate, {days: 1});
}
},
{
name: "Novice",
description: "You're wiser than the average fellow but have much left to learn.",
imageURL: null,
meetsCriteria(user) {
return olderThan(user.creationDate, {weeks: 1});
}
},
{
name: "Intermediate",
description: "You're getting the hang of it! Keep at it.",
imageURL: null,
meetsCriteria(user) {
return olderThan(user.creationDate, {months: 1});
}
},
{
name: "Advanced",
description: "You've got it! I consider you to be proficient at the art of placing.",
imageURL: null,
meetsCriteria(user) {
return olderThan(user.creationDate, {months: 6});
}
},
{
name: "Expert",
description: "You're better than me, so..",
imageURL: null,
meetsCriteria(user) {
return olderThan(user.creationDate, {years: 1});
}
}
];
19 changes: 19 additions & 0 deletions controllers/AchievementsController.js
@@ -0,0 +1,19 @@
const User = require("../models/user");

const handleBadRequest = (res, e) => {
console.error(e);
res.status(500).json({success: false, error: {message: "An error occurred while processing your request"}});
}

exports.getUserAchievements = (req, res, next) => {
if (!req.params.username) return res.status(400).json({success: false, error: {code: "bad_request", message: "The username parameter is rqeuired."}});
const name = req.params.username;
User.findByUsername(name).then(user => {
if (!user) {
return res.status(404).json({success: false, error: {code: "not_found", message: "The username provided does not match any registered users."}});
}
user.getAchievements().then(achievements => {
res.json({achievements, success: true});
}).catch((e) => handleBadRequest(res, e));
}).catch((e) => handleBadRequest(res, e));
}
2 changes: 1 addition & 1 deletion models/access.js
Expand Up @@ -85,7 +85,7 @@ AccessSchema.statics.findSimilarIPUserIDs = function(user) {
this.findIPsForUser(user).then((ipAddresses) => {
this.find({ hashedIPAddress: { $in: ipAddresses }, userID: { $ne: user._id } }).then((accesses) => {
var userIDs = accesses.map((access) => String(access.userID));
resolve([...new Set(userIDs)]);
resolve(stripDuplicates((userIDs)));
}).catch(reject);
}).catch(reject);
});
Expand Down
8 changes: 8 additions & 0 deletions models/user.js
Expand Up @@ -6,6 +6,7 @@ const Pixel = require("./pixel");
const Access = require("./access");
const dataTables = require("mongoose-datatables");
const TOSManager = require("../util/TOSManager");
const achievements = require("../config/achievements");

var UserSchema = new Schema({
name: {
Expand Down Expand Up @@ -124,6 +125,13 @@ UserSchema.pre("save", function(next) {
}
});

UserSchema.methods.getAchievements = function() {
return new Promise((resolve, reject) => {
const userAchievements = achievements.filter(achievement => achievement.meetsCriteria(this));
resolve(userAchievements);
});
}

UserSchema.methods.comparePassword = function(passwd, cb) {
bcrypt.compare(passwd, this.password, function(err, isMatch) {
if (err) return cb(err);
Expand Down
Empty file modified public/js/jquery.confetti.js 100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions routes/api.js
Expand Up @@ -15,6 +15,7 @@ const AccountPageController = require("../controllers/AccountPageController");
const TOTPSetupController = require("../controllers/TOTPSetupController");
const ChangelogController = require("../controllers/ChangelogController");
const WarpController = require("../controllers/WarpController");
const AchievementsController = require("../controllers/AchievementsController");
const UserDownloadController = require("../controllers/UserDownloadController");

function APIRouter(app) {
Expand Down Expand Up @@ -187,6 +188,7 @@ function APIRouter(app) {
router.route("/chat").get(ChatController.getAPIChat).post([requireUser, chatRatelimit.prevent], ChatController.postAPIChatMessage);

router.get("/user/:username", AccountPageController.getAPIAccount);
router.get("/user/:username/achievements", AchievementsController.getUserAchievements);

router.get("/changelog/latest", ChangelogController.getLatestChangelog);
router.route("/changelog/missed").get([requireUser, ChangelogController.getMissedChangelogs]).post([requireUser, ChangelogController.postMissedChangelogs]).delete([requireUser, ChangelogController.deleteMissedChangelogs]);
Expand Down
7 changes: 4 additions & 3 deletions views/layout.pug
Expand Up @@ -18,6 +18,7 @@ block dependencies
- var hasCommunityGuidelines = fs.existsSync("./config/community_guidelines.md");
- var hasTOS = TOSManager.hasTOSSync();
- var hasPP = TOSManager.hasPrivacyPolicySync();
- const stripDuplicates = (arr = []) => { for (let i = 0; i < arr.length; i++) { if (arr.indexOf(arr[i]) !== i) arr.splice(i, 1); } return arr; }
mixin renderBadge(badge, prefersShortText = false)
span.label.badge-label(class=`label-${badge.style || "default"}`, title=badge.title) #{prefersShortText && badge.shortText ? badge.shortText : badge.text}
mixin renderBadges(badges, prefersShortText = false)
Expand Down Expand Up @@ -73,7 +74,7 @@ html(lang="en")
link(href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css", rel="stylesheet")
// Provided CSS
- css.unshift("/css/global.css")
each item in [...new Set(css)]
each item in stripDuplicates(css)
link(href=item + "?v=" + resourceVersion, rel="stylesheet")
+getViewExtensions("head")
// Shivs
Expand Down Expand Up @@ -180,7 +181,7 @@ html(lang="en")
- js.unshift("https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js", "/js/cookies-eu-banner.min.js", "/js/build/site.js");
each item in [...new Set(js)]
script(src=item + "?v=" + resourceVersion)
each item in [...new Set(jsSnippets.concat(jsModSnippets))]
each item in stripDuplicates(jsSnippets.concat(jsModSnippets))
script !{item}
if fs.existsSync("./views/public/legit.js") && !isAdmin && needsLegit
script !{fs.readFileSync("./views/public/legit.js")}
Expand All @@ -194,4 +195,4 @@ html(lang="en")

ga("create", "#{config.googleAnalyticsTrackingID}", "auto");
ga("send", "pageview");
});
});
2 changes: 1 addition & 1 deletion views/public/index.pug
Expand Up @@ -25,4 +25,4 @@ block content
unless user
include views/auth-dialog
include views/help-dialog
- var js = ["https://cdn.jsdelivr.net/interact.js/1.2.6/interact.min.js", "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.0.0/bootstrap-slider.min.js", "https://cdn.jsdelivr.net/jquery.minicolors/2.1.2/jquery.minicolors.min.js", "https://cdn.jsdelivr.net/clipboard.js/1.6.0/clipboard.min.js", "https://unpkg.com/eventemitter3@latest/umd/eventemitter3.min.js", "/js/build/socket.js", "/js/build/popout.js", "/js/build/place.js", "https://cdn.rawgit.com/rmm5t/jquery-timeago/180864a9c544a49e43719b457250af216d5e4c3a/jquery.timeago.js"];
- var js = ["https://cdn.jsdelivr.net/interact.js/1.2.6/interact.min.js", "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.0.0/bootstrap-slider.min.js", "https://cdn.jsdelivr.net/jquery.minicolors/2.1.2/jquery.minicolors.min.js", "https://cdn.jsdelivr.net/clipboard.js/1.6.0/clipboard.min.js", "https://unpkg.com/eventemitter3@latest/umd/eventemitter3.min.js", "/js/build/socket.js", "/js/build/popout.js", "/js/build/place.js", "https://cdn.rawgit.com/rmm5t/jquery-timeago/180864a9c544a49e43719b457250af216d5e4c3a/jquery.timeago.js"];