Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "dynamic"]
path = dynamic
url = https://github.com/nebulaservices/dynamic
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

This is our third edition of [Ruby](https://github.com/ruby-network/ruby-v1). This edition primarily uses the Ruby programming language whilst also adding more features

[![Ruby Network Discord](https://invidget.switchblade.xyz/rbWVGBfuwV?theme=dark)](https://discord.gg/rbWVGBfuwV)
[![Ruby Network Discord](https://invidget.switchblade.xyz/bXJCZJZcJe?theme=dark)](https://discord.gg/bXJCZJZcJe)

## Features

Expand Down Expand Up @@ -84,17 +84,15 @@ This is our third edition of [Ruby](https://github.com/ruby-network/ruby-v1). Th

- [x] Basic Password protection for the website (you can set a password in the settings page)

- [ ] Customizable apps and games

- [ ] Partners page for all of our wonderful partners

- [ ] Apps

- [x] History page
- [x] History page

- [ ] Keybinds cheat sheet

- [ ] Backgrounds, using Particles.js and other libraries

- [ ] Multiple Users when self hosting in private mode
- [x] Multiple Users when self hosting in private mode

---

Expand Down
30 changes: 0 additions & 30 deletions build.js

This file was deleted.

41 changes: 0 additions & 41 deletions buildFiles/rhbuild.js

This file was deleted.

1 change: 0 additions & 1 deletion dynamic
Submodule dynamic deleted from 27de61
4 changes: 4 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
set :uvPath, File.join(settings.root, 'node_modules', '@titaniumnetwork-dev', 'ultraviolet', 'dist')
uvPath()

# Dynamic "middleware"
set :dynamicPath, File.join(settings.root, 'node_modules', '@nebula-services', 'dynamic', 'dist')
dynamicPath()

# Other routes
get '/rubyHealth/?' do
return "OK"
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"scripts": {
"dev": "bundle exec rerun --ignore 'src/public/css/*' --signal 'TERM' -c -w 5 --no-notify -- puma",
"start": "bundle exec puma -e production",
"install": "bundle install && npm run build",
"build": "node ./build.js",
"install": "bundle install",
"build:rh": "tsc -p ./rammerhead/tsconfig.json",
"cli": "bundle exec ruby ./cli/cli.rb"
},
"engines": {
Expand All @@ -17,14 +17,15 @@
"dependencies": {
"@fastify/http-proxy": "^9.2.1",
"@fastify/middie": "^8.3.0",
"@nebula-services/dynamic": "^0.7.2-patch.2",
"@titaniumnetwork-dev/ultraviolet": "^2.0.0",
"@tomphttp/bare-server-node": "^2.0.0",
"chalk": "^5.2.0",
"esbuild": "^0.19.2",
"fastify": "^4.21.0",
"progress-estimator": "^0.3.1",
"rammerhead": "https://github.com/Ruby-Network/rammerhead/releases/download/v1/rammerhead-2.tgz",
"sass": "^1.62.1",
"typescript": "^5.3.3",
"yaml": "^2.3.1"
}
}
19 changes: 0 additions & 19 deletions postgres.yml

This file was deleted.

5 changes: 4 additions & 1 deletion rammerhead/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Rammerhead source files for the browser. Compiled for older browsers via [ESBuild](https://esbuild.github.io/).
# Rammerhead source files for browser.

- The `rh.ts` file is compiled to `rh.js` and the put into [src/public/js/rh](../src/public/js/rh/).
- Build command is: `yarn build:rh`
- The other folder [./oldJS/](./oldJS/) contains old files that were crappier versions of `rh.ts`
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
176 changes: 176 additions & 0 deletions rammerhead/rh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
function RammerheadEncode(baseUrl) {
const mod = (n, m) => ((n % m) + m) % m;
const baseDictionary =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~-";
const shuffledIndicator = "_rhs";
const generateDictionary = function () {
let str = "";
const split = baseDictionary.split("");
while (split.length > 0) {
str += split.splice(Math.floor(Math.random() * split.length), 1)[0];
}
return str;
};
interface StrShuffler {
dictionary: any;
}
class StrShuffler {
constructor(dictionary = generateDictionary()) {
this.dictionary = dictionary;
}
shuffle(str) {
if (str.startsWith(shuffledIndicator)) {
return str;
}
let shuffledStr = "";
for (let i = 0; i < str.length; i++) {
const char = str.charAt(i);
const idx = baseDictionary.indexOf(char);
if (char === "%" && str.length - i >= 3) {
shuffledStr += char;
shuffledStr += str.charAt(++i);
shuffledStr += str.charAt(++i);
} else if (idx === -1) {
shuffledStr += char;
} else {
shuffledStr += this.dictionary.charAt(
mod(idx + i, baseDictionary.length)
);
}
}
return shuffledIndicator + shuffledStr;
}
unshuffle(str) {
if (!str.startsWith(shuffledIndicator)) {
return str;
}

str = str.slice(shuffledIndicator.length);

let unshuffledStr = "";
for (let i = 0; i < str.length; i++) {
const char = str.charAt(i);
const idx = this.dictionary.indexOf(char);
if (char === "%" && str.length - i >= 3) {
unshuffledStr += char;
unshuffledStr += str.charAt(++i);
unshuffledStr += str.charAt(++i);
} else if (idx === -1) {
unshuffledStr += char;
} else {
unshuffledStr += baseDictionary.charAt(
mod(idx - i, baseDictionary.length)
);
}
}
return unshuffledStr;
}
}
function get(url, callback, shush = false) {
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.send();

request.onerror = function () {
if (!shush) console.log("Cannot communicate with the server");
};
request.onload = function () {
if (request.status === 200) {
callback(request.responseText);
} else {
if (!shush)
console.log(
'unexpected server response to not match "200". Server says "' +
request.responseText +
'"'
);
}
};
}
var api = {
newsession(callback) {
get("/newsession", callback);
},
sessionexists(id, callback) {
get("/sessionexists?id=" + encodeURIComponent(id), function (res) {
if (res === "exists") return callback(true);
if (res === "not found") return callback(false);
console.log("unexpected response from server. received" + res);
});
},
shuffleDict(id, callback) {
console.log("Shuffling", id);
get("/api/shuffleDict?id=" + encodeURIComponent(id), function (res) {
callback(JSON.parse(res));
});
}
};
var localStorageKey = "rammerhead_sessionids";
var localStorageKeyDefault = "rammerhead_default_sessionid";
var sessionIdsStore = {
get() {
var rawData = localStorage.getItem(localStorageKey);
if (!rawData) return [];
try {
var data = JSON.parse(rawData);
if (!Array.isArray(data)) throw "getout";
return data;
} catch (e) {
return [];
}
},
set(data) {
if (!data || !Array.isArray(data)) throw new TypeError("must be array");
localStorage.setItem(localStorageKey, JSON.stringify(data));
},
getDefault() {
var sessionId = localStorage.getItem(localStorageKeyDefault);
if (sessionId) {
var data = sessionIdsStore.get();
data.filter(function (e) {
return e.id === sessionId;
});
if (data.length) return data[0];
}
return null;
},
setDefault(id) {
localStorage.setItem(localStorageKeyDefault, id);
}
};
function addSession(id) {
var data = sessionIdsStore.get();
data.unshift({ id: id, createdOn: new Date().toLocaleString() });
sessionIdsStore.set(data);
}
function getSessionId() {
return new Promise((resolve) => {
var id = localStorage.getItem("session-string");
api.sessionexists(id, function (value) {
if (!value) {
console.log("Session validation failed");
api.newsession(function (id) {
addSession(id);
localStorage.setItem("session-string", id);
console.log(id);
console.log("^ new id");
resolve(id);
});
} else {
resolve(id);
}
});
});
}
var ProxyHref;

return getSessionId().then((id) => {
return new Promise((resolve, reject) => {
api.shuffleDict(id, function (shuffleDict) {
var shuffler = new StrShuffler(shuffleDict);
ProxyHref = "/" + id + "/" + shuffler.shuffle(baseUrl);
resolve(ProxyHref);
});
});
});
}
12 changes: 12 additions & 0 deletions rammerhead/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"noEmit": false,
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {},
"outDir": "../src/public/js/rh/",
}
}
2 changes: 1 addition & 1 deletion require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require 'sequel'
require 'bcrypt'
require './ruby/utils.rb'
require './ruby/uv.rb'
require './ruby/proxyPaths.rb'
require './ruby/auth.rb'
require './ruby/validator.rb'
require './ruby/db.rb'
19 changes: 19 additions & 0 deletions ruby/proxyPaths.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def uvPath
get '/uv/*' do
if params[:splat][0] == 'uv.config.js'
send_file File.join(settings.public_folder, 'js', 'uv', params[:splat][0])
else
send_file File.join(settings.uvPath, params[:splat][0])
end
end
end

def dynamicPath
get '/dynamic/*' do
if params[:splat][0] == 'dynamic.config.js'
send_file File.join(settings.public_folder, 'js', 'dynamic', params[:splat][0])
else
send_file File.join(settings.dynamicPath, params[:splat][0])
end
end
end
Loading