Skip to content

Commit d4fca30

Browse files
committed
Lots of cool updates, no need to explain.
1 parent 8f36b8d commit d4fca30

13 files changed

Lines changed: 846 additions & 53 deletions

File tree

server-src/commands.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,12 @@ class CommandHandler {
372372
var allClients = getActiveClients();
373373
var randomClient =
374374
allClients[Math.floor(Math.random(allClients.length - 1))];
375+
if (args[0]) {
376+
randomClient = searchUsersByKey(args[0], senderClient);
377+
}
375378
sendClientCommand(randomClient, "breakdance");
376379
},
377-
"Shows a microwave breakdancing on someones screen, small in a random spot, and teleports around the screen every 1/2 seconds and keeps doing that until the user clicks him or after 30 seconds.",
380+
"<Username>[br]Shows a microwave breakdancing on someones screen, small in a random spot, and teleports around the screen every 1/2 seconds and keeps doing that until the user clicks him or after 30 seconds.",
378381
true
379382
);
380383

server-src/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ e.DISPLAYNAME_CHAR_SET =
2727
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890~`!@#$%^&*()-_=+{[]}|\\'\";:/?.>,<";
2828
e.MAX_NOTIFICATIONS = 20; //Max real time notifcations per user.
2929

30+
e.MAX_USERLIST_SIZE = 150; //Max usernames in user list.
31+
3032
module.exports = e;

server-src/server.js

Lines changed: 164 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,13 @@ async function destroyAccount(username) {
769769
var data = await storage.downloadFile(`user-${username}.json`);
770770
var json = JSON.parse(data);
771771

772-
json.destroyed = true;
773-
json.color = "#d40000";
774-
json.displayName = "[DEACTIVATED]";
775-
json.password = "";
776-
json.sessions = [];
772+
json = {
773+
destroyed: true,
774+
color: "#d40000",
775+
displayName: "[DEACTIVATED]",
776+
password: "",
777+
sessions: [],
778+
};
777779

778780
await storage.uploadFile(
779781
`user-${username}.json`,
@@ -3854,7 +3856,164 @@ const server = http.createServer(async function (req, res) {
38543856
}
38553857
return;
38563858
}
3859+
if (urlsplit[2] == "myuserlist" && req.method == "GET") {
3860+
if (decryptedUserdata) {
3861+
try {
3862+
var stuff = await validateUserCookie(decryptedUserdata);
3863+
if (!stuff.valid) {
3864+
runStaticStuff(req, res, {
3865+
status: 403,
3866+
});
3867+
return;
3868+
}
3869+
try {
3870+
var userListFile = `userlist-${decryptedUserdata.username}.json`;
3871+
var userListRawText = await storage.downloadFile(userListFile);
3872+
var json = JSON.parse(userListRawText.toString());
3873+
res.end(
3874+
JSON.stringify({
3875+
users: json.map((usr) => usr.username),
3876+
})
3877+
);
3878+
} catch (e) {
3879+
res.end(
3880+
JSON.stringify({
3881+
users: [],
3882+
})
3883+
);
3884+
return;
3885+
}
3886+
} catch (e) {
3887+
runStaticStuff(req, res, {
3888+
status: 500,
3889+
});
3890+
}
3891+
} else {
3892+
runStaticStuff(req, res, {
3893+
status: 403,
3894+
});
3895+
}
3896+
return;
3897+
}
3898+
if (urlsplit[2] == "adduserlist" && req.method == "POST") {
3899+
if (decryptedUserdata) {
3900+
try {
3901+
var body = await waitForBody(req);
3902+
var bodyJson = JSON.parse(body.toString());
3903+
if (typeof bodyJson.username !== "string") {
3904+
res.statusCode = 400;
3905+
res.end("Username property must be type of string.");
3906+
return;
3907+
}
3908+
var stuff = await validateUserCookie(decryptedUserdata);
3909+
if (!stuff.valid) {
3910+
runStaticStuff(req, res, {
3911+
status: 403,
3912+
});
3913+
return;
3914+
}
3915+
var userListFile = `userlist-${decryptedUserdata.username}.json`;
3916+
try {
3917+
var userListRawText = await storage.downloadFile(userListFile);
3918+
} catch (e) {
3919+
var userListRawText = "[]";
3920+
}
3921+
var json = JSON.parse(userListRawText.toString());
3922+
var safeUsername = bodyJson.username.trim().toLowerCase();
3923+
if (
3924+
!(
3925+
checkUsername(safeUsername) &&
3926+
(await doesUsernameExist(safeUsername))
3927+
)
3928+
) {
3929+
res.statusCode = 404;
3930+
res.end("Username doesn't exist or invalid");
3931+
return;
3932+
}
3933+
if (safeUsername == decryptedUserdata.username) {
3934+
res.statusCode = 400;
3935+
res.end("You can't add yourself!");
3936+
return;
3937+
}
3938+
if (!json.find((usr) => usr.username == safeUsername)) {
3939+
json.push({ username: safeUsername });
3940+
}
3941+
if (json.length > cons.MAX_USERLIST_SIZE) {
3942+
res.statusCode = 400;
3943+
res.end(
3944+
"Too many trusted usernames stored, remove some to add more."
3945+
);
3946+
return;
3947+
}
3948+
await storage.uploadFile(
3949+
userListFile,
3950+
JSON.stringify(json),
3951+
"application/json"
3952+
);
3953+
res.end("");
3954+
} catch (e) {
3955+
runStaticStuff(req, res, {
3956+
status: 500,
3957+
});
3958+
}
3959+
} else {
3960+
runStaticStuff(req, res, {
3961+
status: 403,
3962+
});
3963+
}
3964+
return;
3965+
}
3966+
if (urlsplit[2] == "removeuserlist" && req.method == "POST") {
3967+
if (decryptedUserdata) {
3968+
try {
3969+
var body = await waitForBody(req);
3970+
var bodyJson = JSON.parse(body.toString());
3971+
if (typeof bodyJson.username !== "string") {
3972+
res.statusCode = 400;
3973+
res.end("Username property must be type of string.");
3974+
return;
3975+
}
3976+
var stuff = await validateUserCookie(decryptedUserdata);
3977+
if (!stuff.valid) {
3978+
runStaticStuff(req, res, {
3979+
status: 403,
3980+
});
3981+
return;
3982+
}
3983+
var userListFile = `userlist-${decryptedUserdata.username}.json`;
3984+
try {
3985+
var userListRawText = await storage.downloadFile(userListFile);
3986+
} catch (e) {
3987+
var userListRawText = "[]";
3988+
}
3989+
var json = JSON.parse(userListRawText.toString());
3990+
var safeUsername = bodyJson.username.trim().toLowerCase();
38573991

3992+
if (!checkUsername(safeUsername)) {
3993+
res.statusCode = 404;
3994+
res.end("Username isn't invalid");
3995+
return;
3996+
}
3997+
3998+
json = json.filter((usr) => usr.username !== safeUsername);
3999+
await storage.uploadFile(
4000+
userListFile,
4001+
JSON.stringify(json),
4002+
"application/json"
4003+
);
4004+
res.end("");
4005+
} catch (e) {
4006+
runStaticStuff(req, res, {
4007+
status: 500,
4008+
});
4009+
}
4010+
} else {
4011+
runStaticStuff(req, res, {
4012+
status: 403,
4013+
});
4014+
}
4015+
return;
4016+
}
38584017
if (urlsplit[2] == "myrooms" && req.method == "GET") {
38594018
if (decryptedUserdata) {
38604019
try {

src/chat/elementjson/chat-styles.css

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ body {
473473
padding: 10px;
474474
box-shadow: 0 0px 30px black;
475475
border-radius: 5px;
476+
overflow-y: auto;
477+
max-height: calc(100vh - 100px);
478+
max-width: calc(100vw - 300px);
479+
min-width: 360px;
476480
}
477481

478482
.centerHorizontal {
@@ -866,32 +870,32 @@ a {
866870
}
867871

868872
.roomSelect {
869-
min-width: 300px;
870-
min-height: 230px;
871-
width: calc(100vw - 100px);
872-
height: calc(100vh - 330px);
873+
min-width: 200px;
874+
height: 300px;
873875
background: var(--storage-group-background-color);
874876
border-width: 2px;
875877
border-color: var(--storage-group-text-color);
876878
border-style: solid;
877879
overflow-y: scroll;
878880
overflow-x: hidden;
881+
border-radius: 5px;
879882
}
880883
.roomSelectIcon {
881884
height: 100%;
882885
width: 30px;
883886
}
884887
.roomButton {
885-
width: 100%;
888+
/*width: calc(calc(100% - 6px) - 5px);*/
886889
height: fit-content;
887890
min-height: 80px;
888891
background: var(--storage-group-background-color);
889-
border-width: 0.5px;
892+
border-width: 5px;
890893
border-color: var(--storage-group-border-color);
891894
border-style: solid;
892895
margin: flex;
893896
text-align: left;
894897
color: var(--storage-group-text-color);
898+
padding: 3px 3px;
895899
}
896900
.roomButtonText {
897901
overflow: hidden;

src/chat/interface/chatinterface.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ reconnectingScreen.hidden = true;
125125

126126
var emojiReactions = require("./emojireactions.js");
127127
var clientSettings = require("./clientsettings.js");
128+
var KnownUserList = require("./userlist-menu.js");
128129

129130
(async function () {
130131
try {
@@ -354,9 +355,7 @@ var clientSettings = require("./clientsettings.js");
354355
}
355356

356357
addOwnershipUsernameButton.addEventListener("click", async function () {
357-
var response = await dialogs.prompt(
358-
"Who do you want to give ownership (admin powers) to?\nDrop their username below:"
359-
);
358+
var response = await KnownUserList.getUserPrompt("Add co-owner");
360359
if (!response) {
361360
return;
362361
}
@@ -372,9 +371,7 @@ var clientSettings = require("./clientsettings.js");
372371
});
373372

374373
addBanUserButton.addEventListener("click", async function () {
375-
var response = await dialogs.prompt(
376-
"Who do you want to block/ban?\nDrop their username below:"
377-
);
374+
var response = await KnownUserList.getUserPrompt("Block/ban user");
378375
if (!response) {
379376
return;
380377
}
@@ -390,9 +387,7 @@ var clientSettings = require("./clientsettings.js");
390387
});
391388

392389
addAllowUserButton.addEventListener("click", async function () {
393-
var response = await dialogs.prompt(
394-
"Who do you want to add to the allow list?\nDrop their username below:"
395-
);
390+
var response = await KnownUserList.getUserPrompt("Allow an user");
396391
if (!response) {
397392
return;
398393
}
@@ -595,6 +590,7 @@ var clientSettings = require("./clientsettings.js");
595590
}),
596591
});
597592
})();
593+
document.title = "Random Rants + | Chatroom [" + json.name + "]";
598594
}
599595
if (json.type == "onlineList") {
600596
var a = [];

src/chat/interface/mediaengine/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,6 @@ async function doMediaSelect() {
827827

828828
//This is not going to die (i hope), i'm just working on making it work with render.com
829829

830-
/*
831830
{
832831
element: "div",
833832
className: "divButton roundborder",
@@ -843,14 +842,15 @@ async function doMediaSelect() {
843842

844843
try {
845844
const response = await fetch(
846-
"https://gvbpaint-realtime-ws.glitch.me/room/create"
845+
"https://randomrants-rt-paint-server.onrender.com/room/create"
847846
);
848847
const { roomId } = await response.json();
849848

850849
loadingMediaDiv.remove();
851850

852-
const embedURL = `https://gvbpaint-realtime.glitch.me/?server=${encodeURIComponent(
853-
"wss://gvbpaint-realtime-ws.glitch.me/" + roomId
851+
const embedURL = `https://random-rants-chat.github.io/randomrants-paint-realtime/?server=${encodeURIComponent(
852+
"wss://randomrants-rt-paint-server.onrender.com/" +
853+
roomId
854854
)}`;
855855

856856
sws.send(
@@ -885,11 +885,12 @@ async function doMediaSelect() {
885885
},
886886
{
887887
element: "span",
888-
textContent: "Collaborative canvas (Modified gvbpaint)",
888+
textContent:
889+
"Collaborative canvas (Modified gvbpaint)",
889890
},
890891
]),
891892
],
892-
}, */
893+
},
893894
{
894895
element: "br",
895896
},

0 commit comments

Comments
 (0)