Exemplo n.º 1
0
        public void Save(object message)
        {
            Entity entity = message as Entity;

            entity.save = true;
            ActorSystem.Instance.Find("/remote/default").Tell(entity);
        }
Exemplo n.º 2
0
        public void DeliverQueuedMessages()
        {
            Entity entity = new Entity();

            for (int i = 0; i < 10; i++)
            {
                if (client.entityQueue.TryDequeue(out entity))
                {
                    // See if we have a json entity
                    if (entity.jsonEntity != null)
                    {
                        entity = JsonConvert.DeserializeObject <Entity>(entity.jsonEntity.json);
                    }

                    // entities with a destination get routed directly
                    if (!String.IsNullOrEmpty(entity.destination))
                    {
                        DeliverByDestination(entity);
                    }
                    else
                    {
                        DeliverByComponent(entity);
                    }
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public override void OnReceive(object message)
        {
            Entity entity = message as Entity;

            if (entity.neighbors != null)
            {
                if (entity.neighbors.entity.Count >= 1)
                {
                    List <TrackingUpdate> updates = new List <TrackingUpdate>();
                    foreach (Entity r in entity.neighbors.entity)
                    {
                        TrackingUpdate update = new TrackingUpdate(r.vector3.x, r.vector3.y, r.vector3.z);
                        update.entityId = r.id;
                        if (r.trackExtra != null)
                        {
                            update.trackExtra = r.trackExtra;
                        }


                        updates.Add(update);
                    }

                    updateReceived(updates);
                }
            }
        }
Exemplo n.º 4
0
        public void Update(TrackingUpdate update)
        {
            Entity entity = new Entity();

            entity.id         = "1";
            entity.entityType = update.entityType;

            entity.vector3   = new Vector3();
            entity.vector3.x = update.x;
            entity.vector3.y = update.y;
            entity.vector3.z = update.z;

            TrackEntity trackEntity = new TrackEntity();

            trackEntity.value = true;
            if (update.trackExtra != null)
            {
                trackEntity.trackExtra = update.trackExtra;
            }
            entity.trackEntity = trackEntity;

            entity.getNeighbors = CreateGetNeighbors(update.neighborEntityType, entity.vector3);


            ActorSystem.Instance.Find("/remote/default").Tell(entity);
        }
Exemplo n.º 5
0
        // Use this if you want to create your own ChatMessage.
        // This is useful if you want to embed other data besides text.
        //  Do this by attaching an entity to the ChatMessage.
        public void SendChatMessage(ChatMessage message)
        {
            Entity entity = new Entity();

            entity.id          = "chatmessage";
            entity.chatMessage = message;
            actorSystem.Find("/remote/default").Tell(entity);
        }
Exemplo n.º 6
0
        // Tells the chat system to send you a complete list of channels you are subscribed to.
        //  If you joined a channel with the subscribers flag set, you will also get back a full
        // list of subscribers for that channel.
        public void ChatStatus()
        {
            Entity entity = new Entity();

            entity.id         = "chat_status";
            entity.chatStatus = new ChatStatus();
            actorSystem.Find("/remote/default").Tell(entity);
        }
Exemplo n.º 7
0
        public override void OnReceive(object message)
        {
            Entity entity = message as Entity;

            if (entity.objectdbGetResponse.entityFound)
            {
                objectReceived(entity);
            }
        }
Exemplo n.º 8
0
        public static byte[] EntityToByteArray(Entity entity)
        {
            byte[]       data;
            MemoryStream stream = new MemoryStream();

            Serializer.Serialize(stream, entity);
            data = stream.ToArray();
            return(data);
        }
Exemplo n.º 9
0
 public void TellRemote(Entity entity)
 {
     if (entity.json)
     {
         JsonEntity json = new JsonEntity();
         json.json         = JsonConvert.SerializeObject(entity);
         entity.jsonEntity = json;
     }
     client.SendEntity(entity);
 }
Exemplo n.º 10
0
 public override void OnReceive(object message)
 {
     try
     {
         Entity entity = message as Entity;
         Tell("/GameMachine/GameSystems/Devnull", entity);
     } catch (Exception ex)
     {
         ProxyServer.logger.Info(ex);
     }
 }
Exemplo n.º 11
0
        private void CreateMethodCache()
        {
            Entity entity = new Entity();

            foreach (PropertyInfo info in entity.GetType().GetProperties())
            {
                MethodInfo minfo = info.GetGetMethod();
                string     name  = info.Name;
                methods.Add(name, minfo);
            }
        }
Exemplo n.º 12
0
    public override void OnReceive(object message)
    {
        Entity entity = message as Entity;

        if (!String.IsNullOrEmpty(destination) && destination != "default")
        {
            entity.destination = destination;
        }

        actorSystem.TellRemote(entity);
    }
Exemplo n.º 13
0
        public void Find(string entityId)
        {
            Entity entity = new Entity();

            entity.id = entityId;
            ObjectdbGet get = new ObjectdbGet();

            get.entityId       = entityId;
            get.playerId       = playerId;
            entity.objectdbGet = get;
            ActorSystem.Instance.Find("/remote/default").Tell(entity);
        }
Exemplo n.º 14
0
        private void Ping()
        {
            Entity entity = new Entity();

            entity.id = "ping";
            byte[] bytes = MessageUtil.EntityToByteArray(entity);
            while (true)
            {
                Thread.Sleep(1000);
                Send(bytes);
            }
        }
Exemplo n.º 15
0
        public void DeliverByDestination(Entity entity)
        {
            UntypedActor actor = Find(entity.destination);

            if (actor.GetType().Name == "DeadLetters")
            {
                Logger.Debug("Incoming entity has invalid destination: " + entity.destination);
            }
            else
            {
                actor.Tell(entity);
            }
        }
Exemplo n.º 16
0
    void OnObjectReceived(object message)
    {
        Entity entity = message as Entity;

        Logger.Debug("Received entity with id " + entity.id + " from server");

        // Look for native byte messages
        if (entity.nativeBytes != null)
        {
            byte[] bytes = entity.nativeBytes.bytes;
            Logger.Debug("Found native bytes");
        }
    }
Exemplo n.º 17
0
        public void leaveChannel(string channelName)
        {
            Entity entity = new Entity();

            entity.id = "chatjoin";
            LeaveChat   leaveChat   = new LeaveChat();
            ChatChannel chatChannel = new ChatChannel();

            chatChannel.name = channelName;
            leaveChat.chatChannel.Add(chatChannel);
            entity.leaveChat = leaveChat;
            actorSystem.Find("/remote/default").Tell(entity);
        }
Exemplo n.º 18
0
        public override void OnReceive(object message)
        {
            Entity entity = message as Entity;

            if (entity.chatChannels != null)
            {
                processChannels(entity.chatChannels);
            }

            if (entity.chatMessage != null)
            {
                messageReceived(entity.chatMessage);
            }
        }
Exemplo n.º 19
0
        // Simple usage, just sends text
        public void sendMessage(string senderId, string channelName, string messageText, string messageType)
        {
            Entity entity = new Entity();

            entity.id = "chatmessage";

            ChatMessage chatMessage = new ChatMessage();
            ChatChannel chatChannel = new ChatChannel();

            chatChannel.name        = channelName;
            chatMessage.chatChannel = chatChannel;
            chatMessage.message     = messageText;
            chatMessage.type        = messageType;
            chatMessage.senderId    = senderId;
            entity.chatMessage      = chatMessage;
            actorSystem.Find("/remote/default").Tell(entity);
        }
Exemplo n.º 20
0
        public void DeliverByComponent(Entity entity)
        {
            MethodInfo method;
            bool       findFailed;

            foreach (UntypedActor actor in actors.Values)
            {
                //Logger.Debug("Processing actor " + actor.GetType().Name);

                List <List <string> > componentSets = actor.GetComponentSets();
                foreach (List <string> componentSet in componentSets)
                {
                    // See if message contains component set
                    findFailed = false;
                    foreach (string component in componentSet)
                    {
                        if (methods.ContainsKey(component))
                        {
                            method = methods [component];

                            //Logger.Debug("Looking for component " + component);
                            if (method.Invoke(entity, null) == null)
                            {
                                findFailed = true;
                            }
                            else
                            {
                                Logger.Debug("Found component " + component);
                            }
                        }
                        else
                        {
                            Logger.Debug("Bad Component " + component);
                        }
                    }

                    if (!findFailed)
                    {
                        actor.Tell(entity);
                        findFailed = false;
                        break;
                    }
                }
            }
        }
Exemplo n.º 21
0
        public static void Route(byte[] bytes, ProxyClient proxyClient)
        {
            try
            {
                IActor actor;
                Entity entity = MessageUtil.ByteArrayToEntity(bytes);

                if (entity.id == "ping")
                {
                    return;
                }

                string typeName = entity.destination;
                string threadId = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
                string id       = typeName + threadId;

                if (MessageRouter.actors.TryGetValue(id, out actor))
                {
                    actor.PostInit(proxyClient);
                    actor.OnReceive(entity);
                }
                else
                {
                    Type type = Type.GetType(typeName);
                    if (type == null)
                    {
                        MessageRouter.logger.Info(typeName + " is null");
                        return;
                    }
                    actor = Activator.CreateInstance(type) as IActor;
                    if (MessageRouter.actors.TryAdd(id, actor))
                    {
                        actor.PostInit(proxyClient);
                        actor.OnReceive(entity);
                    }
                    else
                    {
                        MessageRouter.logger.Info("Unable to add actor " + id);
                    }
                }
            } catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 22
0
        // flags is a pipe separated list of strings.  Currently subscribers is the only flag recognized
        //  If the subscribers flag is set, the status updates from the server will include a list of subscribers
        // in each channel, instead of just the channel name.
        public void joinChannel(string channelName, string flags = "")
        {
            if (subscriptions.Contains(channelName))
            {
                return;
            }

            Entity entity = new Entity();

            entity.id = "chatjoin";
            JoinChat    joinChat    = new JoinChat();
            ChatChannel chatChannel = new ChatChannel();

            chatChannel.name  = channelName;
            chatChannel.flags = flags;
            joinChat.chatChannel.Add(chatChannel);
            entity.joinChat = joinChat;
            actorSystem.Find("/remote/default").Tell(entity);
        }
Exemplo n.º 23
0
    // The persistence layer will scope data it saves to the player.  This is done on the server side
    // and is transparent to the client.  This is a convenience feature for prototyping and development. Do
    // not use this in a production app.

    // **IMPORTANT**
    // Please note that this is still not completely secure, as a hacked client can still write out data
    // you are not expecting and there is no way to validate the data before saving it (other then the scoping).  Any server logic that
    // you write that depends on data saved using this feature is WRONG.  Do not do that.  You have been warned.


    void Start()
    {
        //Setup.  The following 3 steps are required for peristence to work

        // 1. Find the ObjectDb actor.  It is started automatically by the actor system
        ObjectDb db = ActorSystem.Instance.Find("ObjectDb") as ObjectDb;

        // 2. Set the callback to receive objects from the server
        ObjectDb.ObjectReceived callback = OnObjectReceived;
        db.OnObjectReceived(callback);

        // 3. Set the player id
        db.SetPlayerId(User.Instance.username);



        // Saving and retrieving entities
        Entity entity = new Entity();

        entity.id = "dbtest";
        db.Save(entity);
        db.Find(entity.id);


        // If you want to save arbitrary binary data, you must wrap it in a NativeBytes message and attach that
        // message to the entity you are saving.

        // Simple byte array to use as a test
        string str = "Howdy";

        byte[] bytes = new byte[str.Length * sizeof(char)];
        System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);

        // Wrap the byte array and save it
        NativeBytes nativeBytes = new NativeBytes();

        nativeBytes.bytes  = bytes;
        entity.nativeBytes = nativeBytes;
        entity.id          = "native_bytes_test";
        db.Save(entity);
        db.Find(entity.id);
    }
Exemplo n.º 24
0
        public Entity Route(string klass, Entity message)
        {
            try
            {
                Callable callable;
                string typeName = klass;
                string threadId = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
                string id = typeName + threadId;

                if (callables.TryGetValue(id, out callable))
                {
                    return callable.call(message);
                } else
                {
                    Type type = Type.GetType(typeName);
                    if (type == null)
                    {
                        MessageRouter.logger.Info(typeName + " is null");
                        return null;
                    }
                    callable = Activator.CreateInstance(type) as Callable;
                    MessageRouter.logger.Info("Callable created with id " + id);
                    if (callables.TryAdd(id, callable))
                    {
                        return callable.call(message);
                    } else
                    {
                        MessageRouter.logger.Info("Unable to add callable " + id);
                        return null;
                    }
                }
            } catch (Exception ex)
            {
                MessageRouter.logger.Info(ex.Message);
                return null;
            }
        }
Exemplo n.º 25
0
 public void Tell(string destination, Entity entity)
 {
     entity.destination = destination;
     byte[] bytes = MessageUtil.EntityToByteArray(entity);
     proxyClient.Send(bytes);
 }
Exemplo n.º 26
0
 public void SendEntity(Entity entity)
 {
     clientMessage.entity.Add(entity);
     Send(Serialize(clientMessage));
     clientMessage.entity.Clear();
 }
Exemplo n.º 27
0
 public Entity call(Entity entity)
 {
     return entity;
 }