Skip to content

Commit

Permalink
server: experiment with autoreconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Bizzonium committed Aug 2, 2024
1 parent 4d1162e commit 4fb3893
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 138 deletions.
2 changes: 2 additions & 0 deletions code/controllers/configuration/entries/config.dm
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@

/datum/config_entry/flag/shutdown_on_reboot

/datum/config_entry/flag/autoreconnect

/datum/config_entry/flag/disable_karma

/datum/config_entry/number/base_mc_tick_rate
Expand Down
4 changes: 3 additions & 1 deletion code/game/world.dm
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ GLOBAL_LIST_EMPTY(world_topic_handlers)
to_chat(world, span_boldannounceooc("Reboot will take a little longer, due to pending updates."))

// Send the reboot banner to all players
var/position = 0 // queue autoreconnect
for(var/client/C in GLOB.clients)
C?.tgui_panel?.send_roundrestart()
C?.tgui_panel?.send_roundrestart(position)
position++
if(CONFIG_GET(string/server)) // If you set a server location in config.txt, it sends you there instead of trying to reconnect to the same world address. -- NeoFite
C << link("byond://[CONFIG_GET(string/server)]")

Expand Down
7 changes: 5 additions & 2 deletions code/modules/tgui/tgui_panel/tgui_panel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,8 @@
*
* Sends a round restart notification.
*/
/datum/tgui_panel/proc/send_roundrestart()
window.send_message("roundrestart")
/datum/tgui_panel/proc/send_roundrestart(position)
window.send_message("roundrestart", list(
"autoreconnect" = CONFIG_GET(flag/autoreconnect) && CONFIG_GET(flag/shutdown_on_reboot),
"position" = position,
))
14 changes: 12 additions & 2 deletions tgui/packages/tgui-panel/game/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from './actions';
import { selectGame } from './selectors';
import { CONNECTION_LOST_AFTER, AUTO_RECONNECT_AFTER } from './constants';
import { url } from '../reconnect';

const withTimestamp = (action) => ({
...action,
Expand Down Expand Up @@ -55,8 +56,17 @@ export const gameMiddleware = (store) => {
return next(withTimestamp(action));
}
if (type === autoReconnect.type) {
// Byond.command('.reconnect');
return;
Byond.command('.reconnect');

// const link = document.createElement('a');
// link.id = 'reconnectLink';
// link.href = `byond://${url}`;
// link.textContent = 'reconnectLink';
// document.body.appendChild(link);
// document.getElementById('reconnectLink')?.click();
// Byond.command('.quit');

return next(action);
}

return next(action);
Expand Down
14 changes: 4 additions & 10 deletions tgui/packages/tgui-panel/game/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import { connectionRestored } from './actions';
import { roundRestarted } from './actions';
import { AUTO_RECONNECT_AFTER } from './constants';

const getRandomIntInclusive = (min, max) => {
const minCeiled = Math.ceil(min);
const maxFloored = Math.floor(max);
return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled);
};

const initialState = {
// TODO: This is where round info should be.
roundId: null,
Expand All @@ -27,14 +21,14 @@ const initialState = {
export const gameReducer = (state = initialState, action) => {
const { type, payload, meta } = action;
if (type === roundRestarted.type) {
const { autoreconnect, position } = payload;
return {
...state,
roundRestartedAt: meta.now,
autoReconnectAfter:
// Add a random amount of time to the auto reconnect time
// to avoid all clients reconnecting at the same time
// from 0 to 15 seconds with 100ms step
meta.now + AUTO_RECONNECT_AFTER + getRandomIntInclusive(0, 150) * 100,
// Add a delay to the auto reconnect time to avoid all clients
// reconnecting at the same time with 500ms step
autoreconnect ? meta.now + AUTO_RECONNECT_AFTER + position * 500 : null,
};
}
if (type === connectionLost.type) {
Expand Down
2 changes: 1 addition & 1 deletion tgui/packages/tgui-panel/reconnect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Stack } from 'tgui/components';

let url: string | null = null;
export let url: string | null = null;

setInterval(() => {
Byond.winget('', 'url').then((currentUrl) => {
Expand Down
244 changes: 122 additions & 122 deletions tgui/public/tgui-panel.bundle.js

Large diffs are not rendered by default.

0 comments on commit 4fb3893

Please sign in to comment.