[Bug] Scripts get no line when the connection closes, so waiting for `Connection closed.` never matches (different than Genie 4)

Open
#454 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 5 days

@syntaki is already working on this.

Since Dec 1, 2026.

  • #467 by @syntaki — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
backend, testing

Research direction

Read the issue’s description of MainWindowViewModel, GameText.AddSystemLine, ScriptEngine.OnGameLine, and GenieCore’s $connected update to trace how disconnects reach scripts and triggers. The report says the author already has a fix with tests, so check for existing work before starting; done means scripts and triggers receive the described Genie 4 disconnect line on closure while the window output stays unchanged.

Written by the indexing model from the issue text.

Description

area:scripting bug est:<1d g4-regression P2

What happened

When the connection closes, a script gets no line it can match. The window prints [16:52:49] disconnected, but that line is not passed to scripts, so matchre, waitfor and action never see it. A script that sends quit and waits for the connection to close gets nothing and takes its timeout.

Scripts written for Genie 4 wait for its Connection closed. line after a quit, so on 5.0.0 they take the timeout branch every time.

What you expected

A line that scripts can match when the connection closes, as in Genie 4. Genie 4 prints [13:20] Connection closed., or [13:20] Connection lost. (reason) when the link breaks, and scripts and triggers see both.

Steps to reproduce

  1. Save this as closed-a.cmd:

    matchre GOT Connection closed\.
    put quit
    matchwait 5
    put #echo NO LINE CAME
    exit
    GOT:
    put #echo LINE CAME
    
  2. Connect a character and run .closed-a.

  3. The connection closes. When the five seconds are up the script prints NO LINE CAME.

It is the same with matchre GOT disconnected, the word Genie 5 prints itself.

Waiting on the variable works: with waiteval ($connected = 0) in place of the matchre and matchwait lines, the script goes on as soon as the connection closes.

Environment

  • OS + version: Ubuntu 26.04
  • Genie 5 version: 5.0.0
  • Install type: AppImage
  • Connection mode: Direct SGE

Logs / session capture

[script] closed-a started (~/.local/share/Genie5/Scripts/closed-a.cmd)
quit
[16:52:49] disconnected
NO LINE CAME

LINE CAME is never printed.

Anything else

Cause, as far as I can read it:

  • MainWindowViewModel prints [HH:MM:SS] disconnected (and ⚠ Connection lost: ... for a broken link) with GameText.AddSystemLine. That writes to the game window only. Nothing goes to ScriptEngine.OnGameLine or to the triggers.
  • GenieCore sets $connected to 0 at the same moment, and that is all a script is told.
  • Genie 4 prints its line from Connection.DisconnectCallback (PrintSocketError for a broken link) through Game.PrintTextToWindow, the same path as game text. That path hands every main-window line to the triggers and to each running script.

The same is true of main as of 394cd28.

Workaround: in the script, wait for $connected to become 0 instead of waiting for the line.

I have a fix with tests (when $connected goes from 1 to 0, scripts and triggers are given Genie 4's line, [HH:mm] Connection closed. or [HH:mm] Connection lost. (reason); what the window shows is unchanged) and can open a pull request if that is welcome.

Dominant language
C#
Stars
2
Forks
5
Avg merge
4d 3h
Merged PRs (30d)
22

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GenieClient/Genie5

All issues in GenieClient/Genie5

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.