- This article is about the Scratch plugin. For the Scratch Team event in null-gravity, see Scratch in Space.
Scratch Space (by Magnie) is a "plugin server" in Python which allows you to add plugins to the server and clients can choose which plugin to use. Chat.PY (chat2) and Virtual Space (virtual_space) are examples of those. It's hosted on Sourceforge using SVN.
Some features the server allows is recoding the plugins while the server is online. No server reset is needed.
- Only the "client part" will be reloaded. Since reloading the server part of the plugin will break all the clients connected.
How the Server Works
- When you first start up the server it loads the server part of the plugins listed inside the code.
- Once someone connects they can broadcast '<plugin' to load 'plugin'. Or as a real example '<chat2' which loads the client part of the plugin.
- Once that person is connected, you can recode the client part and then the person can send '<plugin' again and it will reload the client part of that plugin.
- The client can then send messages to the plugins by placing the colon at the beginning.
- The client can then either disconnect or broadcast '>plugin' to remove that plugin from the plugins in use.
How the Protocol Works
Messages are sent back and forth by using the Remote Sensors Protocol. The Space Protocol consists of the letters |, <, >, and :.
| means 'echo' so you can broadcast '|test' and that will broadcast 'test' to your Scratch client.
< means 'load plugin' allowing you to use a plugin loaded on the server.
> means 'remove plugin' allowing you to switch between multiple plugins without them clashing.
: means 'plugin message' allowing you to send requests to the plugin.
The creator, Magnie, is currently working on a better 'plugin format' that makes it simpler for the server and plugin to interact and make the server more stable.
# Test Plugin # This is an example plugin for the server. # What it does is ignore all messages except 'test' # and every time a client sends 'test' the count is # increased by one. Then it sends the amount of # tests that have been sent with a broadcast # 'You have added a test.' to the client. class Server(object): def __init__(self): self.number_of_tests = 0 # The counter def disconnect(self): pass class Plugin(object): def __init__(self, client, server): self.client = client self.server = server.plugin_servers['test'] # Set the server to the "server" of the counter def broadcast(self, message): owner = self.client if message == 'test': # Increase the counter by one. self.server.number_of_tests += 1 # Send the value of the counter to the client. owner.send_sensor( 'number of tests', str( self.server.number_of_tests ) ) # Send a broadcast that it has been updated. owner.send_broadcast( "You have added a test." ) else: print message def sensor(self, name, value): pass def disconnect(self): pass