Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MBetterc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mbetter
MBetterc
Commits
63ca5331
Commit
63ca5331
authored
Nov 19, 2025
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start intro managed
parent
e9e2f6c9
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
191 additions
and
24 deletions
+191
-24
games_thread.py
mbetterclient/core/games_thread.py
+67
-4
player.py
mbetterclient/qt_player/player.py
+124
-20
No files found.
mbetterclient/core/games_thread.py
View file @
63ca5331
...
...
@@ -27,11 +27,52 @@ class GamesThread(ThreadedComponent):
self
.
_shutdown_event
=
threading
.
Event
()
self
.
message_queue
=
None
def
_cleanup_stale_ingame_matches
(
self
):
"""Clean up any stale 'ingame' matches from previous crashed sessions"""
try
:
session
=
self
.
db_manager
.
get_session
()
try
:
# Get today's date
today
=
datetime
.
now
()
.
date
()
# Find all ingame matches from today that might be stale
stale_matches
=
session
.
query
(
MatchModel
)
.
filter
(
MatchModel
.
start_time
.
isnot
(
None
),
MatchModel
.
start_time
>=
datetime
.
combine
(
today
,
datetime
.
min
.
time
()),
MatchModel
.
start_time
<
datetime
.
combine
(
today
,
datetime
.
max
.
time
()),
MatchModel
.
status
==
'ingame'
,
MatchModel
.
active_status
==
True
)
.
all
()
if
not
stale_matches
:
logger
.
info
(
"No stale ingame matches found"
)
return
logger
.
info
(
f
"Found {len(stale_matches)} stale ingame matches - cleaning up"
)
# Change status to pending and set active_status to False
for
match
in
stale_matches
:
logger
.
info
(
f
"Cleaning up stale match {match.match_number}: {match.fighter1_township} vs {match.fighter2_township}"
)
match
.
status
=
'pending'
match
.
active_status
=
False
session
.
commit
()
logger
.
info
(
f
"Cleaned up {len(stale_matches)} stale ingame matches"
)
finally
:
session
.
close
()
except
Exception
as
e
:
logger
.
error
(
f
"Failed to cleanup stale ingame matches: {e}"
)
def
initialize
(
self
)
->
bool
:
"""Initialize the games thread"""
try
:
logger
.
info
(
"Initializing GamesThread..."
)
# Clean up any stale 'ingame' matches from previous crashed sessions
self
.
_cleanup_stale_ingame_matches
()
# Register with message bus first
self
.
message_queue
=
self
.
message_bus
.
register_component
(
self
.
name
)
...
...
@@ -274,6 +315,25 @@ class GamesThread(ThreadedComponent):
# Determine current game status
game_status
=
self
.
_determine_game_status
()
# If status is "already_active" but game is not active, activate the fixture
if
game_status
==
"already_active"
and
not
self
.
game_active
:
logger
.
info
(
"Status is 'already_active' but game is not active - activating fixture"
)
active_fixture
=
self
.
_find_active_today_fixture
()
if
active_fixture
:
# Create a dummy message for activation
dummy_message
=
Message
(
type
=
MessageType
.
START_GAME
,
sender
=
message
.
sender
,
recipient
=
self
.
name
,
data
=
{
"timestamp"
:
time
.
time
()},
correlation_id
=
message
.
correlation_id
)
self
.
_activate_fixture
(
active_fixture
,
dummy_message
)
# Update status after activation
game_status
=
"started"
else
:
logger
.
warning
(
"Could not find active fixture to activate"
)
# Send GAME_STATUS response back to the requester
response
=
Message
(
type
=
MessageType
.
GAME_STATUS
,
...
...
@@ -548,9 +608,9 @@ class GamesThread(ThreadedComponent):
timer_running
=
self
.
_is_timer_running_for_fixture
(
fixture_id
)
if
not
timer_running
:
# Timer not running, change status to
failed
logger
.
info
(
f
"Timer not running for fixture {fixture_id}, changing ingame matches to
failed
"
)
self
.
_change_fixture_matches_status
(
fixture_id
,
'ingame'
,
'
failed'
)
# Timer not running, change status to
pending and set active_status to False
logger
.
info
(
f
"Timer not running for fixture {fixture_id}, changing ingame matches to
pending and setting active_status to False
"
)
self
.
_change_fixture_matches_status
(
fixture_id
,
'ingame'
,
'
pending'
,
active_status_to_set
=
False
)
# Check if this was the only non-terminal fixture
if
self
.
_is_only_non_terminal_fixture
(
fixture_id
):
...
...
@@ -593,7 +653,7 @@ class GamesThread(ThreadedComponent):
# In a real implementation, you'd check the match_timer component status
return
self
.
current_fixture_id
==
fixture_id
and
self
.
game_active
def
_change_fixture_matches_status
(
self
,
fixture_id
:
str
,
from_status
:
str
,
to_status
:
str
):
def
_change_fixture_matches_status
(
self
,
fixture_id
:
str
,
from_status
:
str
,
to_status
:
str
,
active_status_to_set
:
Optional
[
bool
]
=
None
):
"""Change status of matches in a fixture from one status to another"""
try
:
session
=
self
.
db_manager
.
get_session
()
...
...
@@ -607,6 +667,9 @@ class GamesThread(ThreadedComponent):
for
match
in
matches
:
logger
.
info
(
f
"Changing match {match.match_number} status from {from_status} to {to_status}"
)
match
.
status
=
to_status
if
active_status_to_set
is
not
None
:
match
.
active_status
=
active_status_to_set
logger
.
info
(
f
"Setting active_status to {active_status_to_set} for match {match.match_number}"
)
session
.
commit
()
...
...
mbetterclient/qt_player/player.py
View file @
63ca5331
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment