fix(server): deliver maintenance warnings to idle clients and keep the console readable while restarting
Idle game clients only poll the plaintext /ServerNowTime every three minutes, and that bootstrap reply carried no Notify, so a scheduled maintenance reached them only through a later gameplay request, often at the very end. The bootstrap reply now carries the same server-wide Notify (maintenance start and notice sequence) as game responses. While the server drains and restarts, the console's text formatting API is unreachable, so error and status text failed with "Text formatting failed". text.js now renders the %[n]s translations locally when the API cannot be reached, and the updates view shows a translated restarting notice and keeps polling during maintenance.
This commit is contained in:
1 parent
47e88b52ad
commit
1b08616183
10 files changed
+63
-9
No files matched your search
@@ -48,6 +48,15 @@
|
||||
if (!scheduled) { scheduled = true; queueMicrotask(flush); }
|
||||
return request.promise;
|
||||
}
|
||||
// formatLocally supports the verbs translations use: %[n]s, %s and %%.
|
||||
function formatLocally(template, args) {
|
||||
let next = 0;
|
||||
return String(template).replace(/%(?:\[(\d+)\])?([sdv%])/g, (match, index, verb) => {
|
||||
if (verb === '%') return '%';
|
||||
const position = index ? Number(index) - 1 : next++;
|
||||
return position >= 0 && position < args.length ? String(args[position]) : match;
|
||||
});
|
||||
}
|
||||
class Component {
|
||||
#content; #args;
|
||||
constructor(content, args) { this.#content = content; this.#args = args; }
|
||||
@@ -60,7 +69,10 @@
|
||||
for (;;) {
|
||||
const language = locale();
|
||||
const args = await Promise.all(this.#args.map(value => value && typeof value.getString === 'function' ? value.getString() : value));
|
||||
const text = await requestFormattedText(language, this.#content, args);
|
||||
let text;
|
||||
// The server formats with Go's fmt; while it is unreachable (for example
|
||||
// restarting for an update) render the same %[n]s templates locally.
|
||||
try { text = await requestFormattedText(language, this.#content, args); } catch { text = formatLocally(lookup(this.#content) ?? this.#content, args); }
|
||||
if (language === locale()) return text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1100,7 +1100,11 @@ const updatesView = (() => {
|
||||
}
|
||||
async function load() {
|
||||
try { status = (await api('updates')).value; await render(); }
|
||||
catch (error) { await say($('update-status'), error, 'err'); }
|
||||
catch (error) {
|
||||
// Applying an update stops this server; keep polling until the new one answers.
|
||||
const restarting = status && status.maintenance && (!error.status || error.status >= 502);
|
||||
await say($('update-status'), restarting ? Component.translatable('console.updates.restarting') : error, restarting ? '' : 'err');
|
||||
}
|
||||
}
|
||||
async function apply() {
|
||||
const selectedComponent = status.available ? 'server' : status.schedules && status.schedules.available ? 'schedules' : 'server';
|
||||
|
||||
@@ -503,5 +503,6 @@
|
||||
"console.error.incompatible_schedules": "This schedule set does not match the running game and GameData versions.",
|
||||
"console.error.confirming_update": "The previous update is still being checked. Wait until it is confirmed healthy.",
|
||||
"console.updates.component": "Update content",
|
||||
"console.updates.component.server": "Server program"
|
||||
"console.updates.component.server": "Server program",
|
||||
"console.updates.restarting": "The server is restarting to apply the update. This page reconnects automatically."
|
||||
}
|
||||
@@ -503,5 +503,6 @@
|
||||
"console.error.incompatible_schedules": "このセットは現在のゲームおよび GameData バージョンと互換性がありません。",
|
||||
"console.error.confirming_update": "前回の更新の動作確認中です。正常動作の確認が完了するまでお待ちください。",
|
||||
"console.updates.component": "更新内容",
|
||||
"console.updates.component.server": "サーバープログラム"
|
||||
"console.updates.component.server": "サーバープログラム",
|
||||
"console.updates.restarting": "更新を適用するためにサーバーを再起動しています。このページは自動的に再接続します。"
|
||||
}
|
||||
@@ -503,5 +503,6 @@
|
||||
"console.error.incompatible_schedules": "현재 게임 및 GameData 버전과 호환되지 않는 일정입니다.",
|
||||
"console.error.confirming_update": "이전 업데이트의 정상 작동을 확인하는 중입니다. 확인이 완료될 때까지 기다려 주세요.",
|
||||
"console.updates.component": "업데이트 내용",
|
||||
"console.updates.component.server": "서버 프로그램"
|
||||
"console.updates.component.server": "서버 프로그램",
|
||||
"console.updates.restarting": "업데이트를 적용하기 위해 서버를 다시 시작하는 중입니다. 이 페이지는 자동으로 다시 연결됩니다."
|
||||
}
|
||||
@@ -503,5 +503,6 @@
|
||||
"console.error.incompatible_schedules": "此排期集与当前游戏及 GameData 版本不兼容。",
|
||||
"console.error.confirming_update": "上一次更新仍在进行健康检查,请等待确认完成。",
|
||||
"console.updates.component": "更新内容",
|
||||
"console.updates.component.server": "服务端程序"
|
||||
"console.updates.component.server": "服务端程序",
|
||||
"console.updates.restarting": "服务器正在重启以应用更新,本页面会自动重新连接。"
|
||||
}
|
||||
@@ -503,5 +503,6 @@
|
||||
"console.error.incompatible_schedules": "此排期集與目前遊戲及 GameData 版本不相容。",
|
||||
"console.error.confirming_update": "上次更新仍在進行健康檢查,請等待確認完成。",
|
||||
"console.updates.component": "更新內容",
|
||||
"console.updates.component.server": "伺服器程式"
|
||||
"console.updates.component.server": "伺服器程式",
|
||||
"console.updates.restarting": "伺服器正在重新啟動以套用更新,本頁面會自動重新連線。"
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func Serve(args []string) (serveErr error) {
|
||||
_, message := updater.LoginsClosed(i18n.FromGameLanguage(language))
|
||||
return message
|
||||
}
|
||||
dispatcher := transport.Bootstrap{Config: c.bootstrap, Notices: c.notices, LoginsClosed: loginsClosed}
|
||||
dispatcher := transport.Bootstrap{Config: c.bootstrap, Notices: c.notices, LoginsClosed: loginsClosed, Broadcast: game.Broadcast}
|
||||
handler := transport.HTTP{
|
||||
Dispatcher: dispatcher, Raw: game, Authentication: c.authentication,
|
||||
AuthenticationHandler: authHandler, ResourcePolicy: c.publicResources,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// An idle game client only polls the plaintext /ServerNowTime, so the
|
||||
// server-wide Notify (maintenance start, notice sequence) must ride on that
|
||||
// reply, not only on gameplay requests an idle player never sends.
|
||||
func TestServerNowTimeCarriesTheBroadcastNotify(t *testing.T) {
|
||||
broadcast := []byte{0x38, 0x2a}
|
||||
b := Bootstrap{Broadcast: func() []byte { return broadcast }}
|
||||
reply, err := b.Dispatch("/ServerNowTime", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, err := base64.StdEncoding.DecodeString(reply.Notify)
|
||||
if err != nil || !bytes.Equal(raw, broadcast) {
|
||||
t.Fatalf("ServerNowTime Notify = %q (%v), want base64 of the broadcast fields", reply.Notify, err)
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,10 @@ type Bootstrap struct {
|
||||
// language (Define_LanguageType) while maintenance has closed new
|
||||
// logins, or "".
|
||||
LoginsClosed func(language uint64) string
|
||||
// Broadcast returns the server-wide Notify fields. An idle game client
|
||||
// only polls the plaintext /ServerNowTime, so maintenance warnings and
|
||||
// notice changes must ride on that reply too.
|
||||
Broadcast func() []byte
|
||||
}
|
||||
|
||||
var ErrNotImplemented = errors.New("packet not implemented")
|
||||
@@ -100,7 +104,13 @@ func (b Bootstrap) Dispatch(path string, request []byte) (Reply, error) {
|
||||
case "/ServerInfo":
|
||||
return Reply{Data: bootstrap.ServerInfo(b.Config)}, nil
|
||||
case "/ServerNowTime":
|
||||
return Reply{Data: bootstrap.ServerNowTime(b.now())}, nil
|
||||
reply := Reply{Data: bootstrap.ServerNowTime(b.now())}
|
||||
if b.Broadcast != nil {
|
||||
if notify := b.Broadcast(); len(notify) != 0 {
|
||||
reply.Notify = base64.StdEncoding.EncodeToString(notify)
|
||||
}
|
||||
}
|
||||
return reply, nil
|
||||
case "/NoticeInfo":
|
||||
if b.Notices == nil {
|
||||
return Reply{}, nil
|
||||
|
||||
Reference in new issue
Block a user