public void Save(object message) { Entity entity = message as Entity; entity.save = true; ActorSystem.Instance.Find("/remote/default").Tell(entity); }
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; } } }
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); } } }
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); }
// 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); }
// 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); }
public override void OnReceive(object message) { Entity entity = message as Entity; if (entity.objectdbGetResponse.entityFound) { objectReceived(entity); } }
public static byte[] EntityToByteArray(Entity entity) { byte[] data; MemoryStream stream = new MemoryStream(); Serializer.Serialize(stream, entity); data = stream.ToArray(); return(data); }
public void TellRemote(Entity entity) { if (entity.json) { JsonEntity json = new JsonEntity(); json.json = JsonConvert.SerializeObject(entity); entity.jsonEntity = json; } client.SendEntity(entity); }
public override void OnReceive(object message) { try { Entity entity = message as Entity; Tell("/GameMachine/GameSystems/Devnull", entity); } catch (Exception ex) { ProxyServer.logger.Info(ex); } }
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); } }
public override void OnReceive(object message) { Entity entity = message as Entity; if (!String.IsNullOrEmpty(destination) && destination != "default") { entity.destination = destination; } actorSystem.TellRemote(entity); }
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); }
private void Ping() { Entity entity = new Entity(); entity.id = "ping"; byte[] bytes = MessageUtil.EntityToByteArray(entity); while (true) { Thread.Sleep(1000); Send(bytes); } }
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); } }
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"); } }
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); }
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); } }
// 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); }
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; } } } }
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); } }
// 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); }
// 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); }
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; } }
public void Tell(string destination, Entity entity) { entity.destination = destination; byte[] bytes = MessageUtil.EntityToByteArray(entity); proxyClient.Send(bytes); }
public void SendEntity(Entity entity) { clientMessage.entity.Add(entity); Send(Serialize(clientMessage)); clientMessage.entity.Clear(); }
public Entity call(Entity entity) { return entity; }