|
| 1 | +#SECURITY NOTE: anything in here can be created simply by sending the |
| 2 | +# class name over the network. This is a potential vulnerability |
| 3 | +# I wouldn't suggest letting any of these classes DO anything, especially |
| 4 | +# things like file system access, or allocating huge amounts of memory |
| 5 | + |
| 6 | +class Event: |
| 7 | + """this is a superclass for any events that might be generated by an |
| 8 | + object and sent to the EventManager""" |
| 9 | + def __init__(self): |
| 10 | + self.name = "Generic Event" |
| 11 | + |
| 12 | +class TickEvent(Event): |
| 13 | + def __init__(self): |
| 14 | + self.name = "CPU Tick Event" |
| 15 | + |
| 16 | +class QuitEvent(Event): |
| 17 | + def __init__(self): |
| 18 | + self.name = "Program Quit Event" |
| 19 | + |
| 20 | +class MapBuiltEvent(Event): |
| 21 | + def __init__(self, map): |
| 22 | + self.name = "Map Finished Building Event" |
| 23 | + self.map = map |
| 24 | + |
| 25 | +class GameStartRequest(Event): |
| 26 | + def __init__(self): |
| 27 | + self.name = "Game Start Request" |
| 28 | + |
| 29 | +class GameStartedEvent(Event): |
| 30 | + def __init__(self, game): |
| 31 | + self.name = "Game Started Event" |
| 32 | + self.game = game |
| 33 | + |
| 34 | +class CharactorMoveRequest(Event): |
| 35 | + def __init__(self, direction): |
| 36 | + self.name = "Charactor Move Request" |
| 37 | + self.direction = direction |
| 38 | + |
| 39 | +class CharactorMoveEvent(Event): |
| 40 | + def __init__(self, charactor): |
| 41 | + self.name = "Charactor Move Event" |
| 42 | + self.charactor = charactor |
| 43 | + |
| 44 | +class CharactorPlaceEvent(Event): |
| 45 | + """this event occurs when a Charactor is *placed* in a sector, |
| 46 | + ie it doesn't move there from an adjacent sector.""" |
| 47 | + def __init__(self, charactor): |
| 48 | + self.name = "Charactor Placement Event" |
| 49 | + self.charactor = charactor |
| 50 | + |
| 51 | +class ServerConnectEvent(Event): |
| 52 | + def __init__(self, serverReference): |
| 53 | + self.name = "Network Server Connection Event" |
| 54 | + self.server = serverReference |
| 55 | + |
| 56 | +class ClientConnectEvent(Event): |
| 57 | + """this event is generated by the Server whenever a client connects |
| 58 | + to it""" |
| 59 | + def __init__(self, client): |
| 60 | + self.name = "Network Client Connection Event" |
| 61 | + self.client = client |
| 62 | + |
| 63 | + |
| 64 | +from twisted.spread import pb |
| 65 | +class CopyableTickEvent(TickEvent, pb.Copyable, pb.RemoteCopy): |
| 66 | + def __init__(self, obj ): |
| 67 | + pass |
| 68 | + |
| 69 | +class CopyableQuitEvent(QuitEvent, pb.Copyable, pb.RemoteCopy): |
| 70 | + def __init__(self, obj ): |
| 71 | + pass |
| 72 | + |
| 73 | +class CopyableMapBuiltEvent(MapBuiltEvent, pb.Copyable, pb.RemoteCopy): |
| 74 | + def __init__(self, obj ): |
| 75 | + pass |
| 76 | + |
| 77 | +class CopyableGameStartRequest(GameStartRequest, pb.Copyable, pb.RemoteCopy): |
| 78 | + def __init__(self, obj ): |
| 79 | + pass |
| 80 | + |
| 81 | +class CopyableGameStartedEvent(GameStartedEvent, pb.Copyable, pb.RemoteCopy): |
| 82 | + def __init__(self, obj ): |
| 83 | + self.game = id( obj.game ) |
| 84 | + |
| 85 | +class CopyableCharactorMoveRequest(CharactorMoveRequest, pb.Copyable, pb.RemoteCopy): |
| 86 | + def __init__(self, obj ): |
| 87 | + CharactorMoveRequest.__init__(self, obj.direction) |
| 88 | + |
| 89 | +class CopyableCharactorMoveEvent(CharactorMoveEvent, pb.Copyable, pb.RemoteCopy): |
| 90 | + def __init__(self, obj ): |
| 91 | + CharactorMoveEvent.__init__(self, obj.charactor) |
| 92 | + |
| 93 | +class CopyableCharactorPlaceEvent(CharactorPlaceEvent, pb.Copyable, pb.RemoteCopy): |
| 94 | + def __init__(self, obj ): |
| 95 | + self.charactor = id( obj.charactor ) |
| 96 | + |
| 97 | +class CopyableServerConnectEvent(ServerConnectEvent, pb.Copyable, pb.RemoteCopy): |
| 98 | + def __init__(self, obj ): |
| 99 | + ServerConnectEvent.__init__(self, obj.server) |
| 100 | + |
| 101 | +class CopyableClientConnectEvent(ClientConnectEvent, pb.Copyable, pb.RemoteCopy): |
| 102 | + def __init__(self, obj ): |
| 103 | + ClientConnectEvent.__init__(self, obj.client) |
0 commit comments