Skip to content

Commit 245c4fc

Browse files
author
minecraft server
committed
Finally fixed that damn EBADF problem - scheduled messages used an expired user object.
1 parent ff788a2 commit 245c4fc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

plugins/schedule.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
DESCRIPTION = """A module for registering a callback to occur at a later time."""
55

66
import time
7+
import logging
8+
from helpers import InvalidUserError
79

810
events = [] # list of (time, key, callback), ordered on time.
911

@@ -52,5 +54,10 @@ def clear(key):
5254
def on_tick(users):
5355
now = time.time()
5456
while events and now >= events[0][0]:
55-
events[0][1]()
57+
try:
58+
events[0][1]()
59+
except InvalidUserError, ex:
60+
logging.info("User %s disconnected before packet could be sent in event: %s" % (ex.args[0], events[0]))
61+
except Exception:
62+
logging.exception("Error while running event: %s" % (events[0]))
5663
events.pop(0)

proxy.py

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def main():
4848
import helpers # Hax before import does important hax
4949
helpers.active_users = active_users
5050
helpers.send_packet = send_packet
51+
helpers.InvalidUserError = InvalidUserError
5152

5253
from plugins import plugins as _plugins # Lazy import prevents circular references
5354

@@ -318,7 +319,11 @@ def send_packet(packet, user, to_server):
318319
"""Takes packet, user object and whether to send to server (as though from user) or vice versa.
319320
Simulates that kind of packet having been recived and passes it on as normal,
320321
ie. a packet still goes through the whole list of plugins.
322+
Raises InvalidUserError if user no longer exists.
321323
"""
324+
if user not in user_map.values():
325+
raise InvalidUserError(user)
326+
322327
packets = handle_packet(packet, user, to_server)
323328

324329
try:
@@ -365,6 +370,10 @@ def __str__(self):
365370
return "%s@%s:%s" % ((self.username,) + self.addr)
366371

367372

373+
class InvalidUserError(Exception):
374+
pass
375+
376+
368377
def active_users():
369378
"""A hack to allow a "logged in" helper"""
370379
global user_map

0 commit comments

Comments
 (0)