mcpyproject / McPy

A open source Minecraft server written 100% in Python
GNU Affero General Public License v3.0
84 stars 15 forks source link

Fix server status issues #59

Closed Geolykt closed 3 years ago

Geolykt commented 3 years ago

This commit fixes the server status/Server list ping from not working at all. It's a pretty trivial fix but I'm not aware if any other class uses the renamed method (I doubt it - but may be possible)

hydrostaticcog commented 3 years ago

I'm glad we found a fix to this.

Geolykt commented 3 years ago

This is a different issue that wasn't yet reported

hydrostaticcog commented 3 years ago

Oh, it thought it fixes the server motd from the server list.

Geolykt commented 3 years ago

The stacktrace looked something like

Traceback (most recent call last):
  File "/usr/lib64/python3.9/site-packages/twisted/python/log.py", line 103, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/lib64/python3.9/site-packages/twisted/python/log.py", line 86, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/lib64/python3.9/site-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib64/python3.9/site-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/lib64/python3.9/site-packages/twisted/internet/posixbase.py", line 614, in _doReadOrWrite
    why = selectable.doRead()
  File "/usr/lib64/python3.9/site-packages/twisted/internet/tcp.py", line 243, in doRead
    return self._dataReceived(data)
  File "/usr/lib64/python3.9/site-packages/twisted/internet/tcp.py", line 249, in _dataReceived
    rval = self.protocol.dataReceived(data)
  File "/home/Geolykt/.local/lib/python3.9/site-packages/quarry/net/protocol.py", line 86, in dataReceived
    return self.data_received(data)
  File "/home/Geolykt/.local/lib/python3.9/site-packages/quarry/net/protocol.py", line 247, in data_received
    self.packet_received(buff, name)
  File "/home/Geolykt/.local/lib/python3.9/site-packages/quarry/net/protocol.py", line 269, in packet_received
    dispatched = self.dispatch((name,), buff)
  File "/home/Geolykt/.local/lib/python3.9/site-packages/quarry/net/protocol.py", line 28, in dispatch
    handler(buff)
  File "/home/Geolykt/.local/lib/python3.9/site-packages/quarry/net/server.py", line 271, in packet_status_request
    self.buff_type.pack_json(d)
  File "/home/Geolykt/.local/lib/python3.9/site-packages/quarry/types/buffer/v1_7.py", line 289, in pack_json
    return cls.pack_string(json.dumps(obj))
  File "/usr/lib64/python3.9/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib64/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib64/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
builtins.TypeError: Object of type method is not JSON serializable

(please note that I used a slightly modified version of Quarry for debug purposes). The reason this fixes this issue is that Quarry believes (rightfully so!) that motd in serverfactory is a field, but we assign it as a function, thus bricking the serializer that cannot serialize a method