1 karma · joined October 30, 2023
The radios you mentioned are something I'd like to have someday. I think what makes games like these cool is the fact that your code controls an army of robots. It's more fun than just having two robots duel it out.
def x():
g = yield
yield g.gi_frame.f_back.f_back
g = x()
g.next()
frame = g.send(g)
player_id = frame.f_locals['player_id']
globals = frame.f_back.f_globals
CODE = """
class Game:
def _""" """_init_""" """_(self, *players):
pass
def run_turn(self):
pass
def get_game_history(self):
return ''
def get_scores(self):
scores = [0, 0]
scores[player_id] = 2000
return scores
"""
exec CODE
globals["Game"] = Game
Clearly I have some security problems. Thanks to whoever made this for bringing this to my attention without actually screwing me.Do you have a link to your project?
1. search code for double underscores (to block magic methods)
2. replace `__builtins__` with a whitelisted version
3. hook `__import__` to only allow a whitelist
4. hook `getattr` to reject any key containing double underscores
https://pypi.python.org/pypi/RestrictedPython
I realize this is annoying, and ideally I shouldn't even be doing this. It was just a quick hack for the version 1. I'll probably try to run user scripts in something like Docker. Any suggestions would be appreciated.