Example #1
0
        public void Send(object component, object destination, bool reliable)
        {
            GameMessage gameMessage;

            if (component is GameMessage)
            {
                gameMessage = (GameMessage)component;
            }
            else
            {
                gameMessage = new GameMessage();
                Type         t     = component.GetType();
                string       field = Char.ToLowerInvariant(t.Name [0]) + t.Name.Substring(1);
                PropertyInfo prop  = GameMessageProp(field);
                prop.SetValue(gameMessage, component, null);
            }

            if (destination is string)
            {
                gameMessage.destination = (string)destination;
            }
            else
            {
                gameMessage.destinationId = (int)destination;
            }
            if (reliable)
            {
                gameMessage.messageId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
            }
            gameMessages.Add(gameMessage);
            SendGameMessages();
        }
Example #2
0
        private PropertyInfo GameMessageProp(string componentName)
        {
            PropertyInfo prop;

            if (gameMessageProps.ContainsKey(componentName))
            {
                prop = gameMessageProps [componentName];
            }
            else
            {
                GameMessage gameMessage = new GameMessage();
                prop = gameMessage.GetType().GetProperty(componentName);
                gameMessageProps [componentName] = prop;
            }
            return(prop);
        }
Example #3
0
        private void DeliverMessage(GameMessage gameMessage, bool hasError)
        {
            PropertyInfo prop;

            foreach (string componentName in behaviorGameMessages.Keys)
            {
                prop = GameMessageProp(componentName);
                object component = prop.GetValue(gameMessage, null);
                if (component != null)
                {
                    if (component is DynamicMessage)
                    {
                        DynamicMessage dynamicMessage = (DynamicMessage)component;
                        Type           t          = Type.GetType(dynamicNamespace + "." + dynamicMessage.type);
                        object         userObject = Deserialize(dynamicMessage.message, t);
                        behaviorGameMessages[componentName].OnMessage(userObject);
                    }
                    else
                    {
                        behaviorGameMessages[componentName].OnMessage(component);
                    }
                }
            }
        }
        public void Send(object component, object destination, bool reliable)
        {
            GameMessage gameMessage;
            if (component is GameMessage) {
                gameMessage = (GameMessage)component;
            } else {
                gameMessage = new GameMessage ();
                Type t = component.GetType ();
                string field = Char.ToLowerInvariant (t.Name [0]) + t.Name.Substring (1);
                PropertyInfo prop = GameMessageProp (field);
                prop.SetValue (gameMessage, component, null);
            }

            if (destination is string) {
                gameMessage.destination = (string)destination;
            } else {
                gameMessage.destinationId = (int)destination;
            }
            if (reliable) {
                gameMessage.messageId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
            }
            gameMessages.Add (gameMessage);
            SendGameMessages();
        }
 private PropertyInfo GameMessageProp(string componentName)
 {
     PropertyInfo prop;
     if (gameMessageProps.ContainsKey (componentName)) {
         prop = gameMessageProps [componentName];
     } else {
         GameMessage gameMessage = new GameMessage ();
         prop = gameMessage.GetType ().GetProperty (componentName);
         gameMessageProps [componentName] = prop;
     }
     return prop;
 }
 private void DeliverMessage(GameMessage gameMessage, bool hasError)
 {
     PropertyInfo prop;
     foreach (string componentName in behaviorGameMessages.Keys) {
         prop = GameMessageProp(componentName);
         object component = prop.GetValue(gameMessage, null);
         if (component != null) {
             if (component is DynamicMessage) {
                 DynamicMessage dynamicMessage = (DynamicMessage)component;
                 Type t = Type.GetType(dynamicNamespace + "." + dynamicMessage.type);
                 object userObject = Deserialize(dynamicMessage.message, t);
                 behaviorGameMessages[componentName].OnMessage(userObject);
             } else {
                 behaviorGameMessages[componentName].OnMessage(component);
             }
         }
     }
 }
Example #7
0
 public ReliableMessage(GameMessage gameMessage)
 {
     this.gameMessage = gameMessage;
     lastUpdate       = currentTime();
 }
 public ReliableMessage (GameMessage gameMessage)
 {
     this.gameMessage = gameMessage;
     lastUpdate = currentTime ();
 }