Exemplo n.º 1
0
 /// <summary> Retrieve a SyncData context by name. Creates a context if one does not already exist. </summary>
 /// <param name="name"> Name of context to retrieve. </param>
 /// <returns> SyncData context with the given name. </returns>
 public SyncData Context(string name)
 {
     if (!contexts.ContainsKey(name))
     {
         var ctx = contexts[name] = new SyncData(this, name);
         ctx.OnEnable();
     }
     return(contexts[name]);
 }
Exemplo n.º 2
0
        /// <summary> RPC, Server->Client. Clears all datas from the local data set. </summary>
        /// <param name="msg"> RPC Message Info </param>
        public void ClearAllJson(RPCMessage msg)
        {
            string   target  = msg[0];
            SyncData context = Context(target);
            Client   c       = msg.sender;

            if (c.isSlave)
            {
                context.locJson.Clear();
            }
        }
Exemplo n.º 3
0
        /// <summary> RPC, Server->Client. Applies JsonData recieved over the wire. </summary>
        /// <param name="msg"> RPC Message info. </param>
        public void SyncJson(RPCMessage msg)
        {
            string   target  = msg[0];
            SyncData context = Context(target);
            Client   c       = msg.sender;

            if (server.isSlave)
            {
                JsonObject data = Json.TryParse(msg[1]) as JsonObject;
                if (data != null)
                {
                    context.locJson.SetRecursively(data);
                }
            }
        }
Exemplo n.º 4
0
        public void Unsubscribe(RPCMessage msg)
        {
            string   target  = msg[0];
            SyncData context = Context(target);

            if (server.isMaster)
            {
                string[] args = new string[msg.numArgs - 1];
                for (int i = 1; i < msg.numArgs; i++)
                {
                    args[i - 1] = msg[i];
                }                                                                               // Skip the first arg, as it is the context.

                context.DoUnsubscribe(msg.sender, args);
            }
        }
Exemplo n.º 5
0
        /// <summary> RPC, Client->Server, subscribes client to given sets of data. </summary>
        /// <param name="msg"> RPC Message info. </param>
        public void Subscribe(RPCMessage msg)
        {
            string   target  = msg[0];
            SyncData context = Context(target);

            if (server.isMaster)
            {
                string[] args = new string[msg.numArgs - 1];                 // Skip name of context in first arg
                for (int i = 1; i < msg.numArgs; i++)
                {
                    args[i - 1] = msg[i];
                }

                context.DoSubscribe(msg.sender, args);
            }
        }
Exemplo n.º 6
0
        /// <summary> RPC, Server->Client. Clears the given sets of data from the local data set. </summary>
        /// <param name="msg"> RPC Message info. </param>
        public void ClearJson(RPCMessage msg)
        {
            string   target  = msg[0];
            SyncData context = Context(target);
            Client   c       = msg.sender;

            if (c.isSlave)
            {
                for (int i = 1; i < msg.numArgs; i++)
                {
                    JsonObject obj = context.locJson;
                    if (obj.ContainsKey(msg[i]))
                    {
                        obj.Remove(msg[i]);
                    }
                }
            }
        }