Namespace globals mp_broadcast
A message based information broadcast for the multiplayer network. Copyright (C) 2008 - 2013 Anders Gidenstam (anders(at)gidenstam.org) This file is licensed under the GPL license version 2 or later.
Classes
Binary
Some routines for encoding/decoding values into/from a string. NOTE: MP is picky about what it sends in a string propery. Encode 7 bits as a printable 8 bit character.
BroadcastChannel
Broadcast primitive using a MP enabled string property. Broadcasts from users in multiplayer.ignore are ignored. BroadcastChannel.new(mpp_path, process) Create a new broadcast primitive. Any MP user with the same primitive will receive all messages sent to the channel from the point she/he joined (barring severe MP packet loss). NOTE: Message delivery is not guaranteed. mpp_path - MP property path : string process - handler called when receiving a message : func (n, msg) n is the base node of the senders property tree (i.e. /ai/models/multiplay[x]) send_to_self - if 1 locally sent messages are : int {0,1} delivered just like remote messages. If 0 locally sent messages are not delivered to the local receiver. accept_predicate - function to select which : func (p) multiplayers to listen to. p is the multiplayer entry node. The default is to accept any multiplayer. on_disconnect - function to be called when an : func (p) accepted MP user leaves. enable_send - Set to 0 to disable sending. BroadcastChannel.send(msg) Sends the message msg to the channel. msg - text string with Binary data encoded data : string BroadcastChannel.die() Destroy this BroadcastChannel instance.
EventChannel
Event broadcast channel using a MP enabled string property. Events from users in multiplayer.ignore are ignored. EventChannel.new(mpp_path) Create a new event broadcast channel. Any MP user with the same primitive will receive all messages sent to the channel from the point she/he joined (barring severe MP packet loss). NOTE: Message delivery is not guaranteed. mpp_path - MP property path : string EventChannel.register(event_hash, handler) Register a handler for the event identified by the hash event_hash. event_hash - hash value for the event : a unique 4 character string handler - a handler function for the event : func (sender, msg) EventChannel.deregister(event_hash) Deregister the handler for the event identified by the hash event_hash. event_hash - hash value for the event : a unique 4 character string EventChannel.send(event_hash, msg) Sends the event event_hash with the message msg to the channel. event_hash - hash value for the event : a unique 4 character string msg - text string with Binary data encoded data : string EventChannel.die() Destroy this EventChannel instance.
LamportClock
Lamport clock. Useful for creating a total order for events or messages. The users' callsigns are used to break ties. LamportClock.new() Creates a new lamport clock for this user. LamportClock.merge(sender, sender_timestamp) Merges the timestamp from the sender with the local clock. sender : base node of the senders property tree sender_timestamp : the timestamp received from the sender. Returns 1 if the local clock was advanced; 0 otherwise. LamportClock.advance() Advances the local clock one tick. LamportClock.timestamp() Returns an encoded 4 character long timestamp from the local clock.
MessageChannel
Detects incomming messages encoded in a string property. n - MP source : property node process - action : func (v) NOTE: This is a low level component. The same object is seldom used for both sending and receiving.