public void handle(CloudLandClient client, IMessage messageReceived) { ServerEntityUpdateMessage message = (ServerEntityUpdateMessage)messageReceived; Loom.QueueOnMainThread(() => { Transform entityTransform = client.getClientComponent().entitiesParent.Find("entity|" + message.EntityId); if (entityTransform == null) { return; } if (message.FlagPosition) { entityTransform.localPosition = new Vector3((float)message.X, (float)message.Y, (float)message.Z); } if (message.FlagRotation) { if (entityTransform.GetComponent <HeadEntity>() != null) { entityTransform.localRotation = Quaternion.Euler(0f, message.Yaw, 0f); entityTransform.Find("Head").localRotation = Quaternion.Euler(message.Pitch, message.Yaw, 0f); } else { entityTransform.localRotation = Quaternion.Euler(message.Pitch, message.Yaw, 0f); } } if (message.FlagMeta) { entityTransform.GetComponent <Entity>().meta = message.Meta; entityTransform.GetComponent <Entity>().updateMeta = true; } }); }
public void handle(CloudLandClient client, IMessage messageReceived) { ServerUpdateWindowMessage msg = (ServerUpdateWindowMessage)messageReceived; ServerUpdateWindowElementHandler hdl = new ServerUpdateWindowElementHandler(); foreach (ServerUpdateWindowElementMessage rec in msg.Records) { hdl.handle(client, rec); } }
public void handle(CloudLandClient client, IMessage messageReceived) { ServerChunkMessage chunk = (ServerChunkMessage)messageReceived; //UnityEngine.Debug.Log("Received chunk: (" + chunk.X + "," + chunk.Z + "), chunk size=" + chunk.Chunk.Length); //UnityEngine.Debug.Log("Processing chunk " + string.Format("({0}, {1}, {2})", chunk.X, chunk.Y, chunk.Z)); byte[] ids = new byte[8192]; Buffer.BlockCopy(chunk.Chunk.ToByteArray(), 0, ids, 0, 8192); client.getClientComponent().chunkManager.chunkQueue.QueueCreation( chunk.X, chunk.Y, chunk.Z, ids); }
public void handle(CloudLandClient client, IMessage messageReceived) { ServerCursorItemMessage msg = (ServerCursorItemMessage)messageReceived; if (msg.Item.Id == 0 && msg.Item.Count == 0) { Loom.QueueOnMainThread(() => WindowManager.INSTANCE.cursorItem = null); } else { Loom.QueueOnMainThread(() => WindowManager.INSTANCE.cursorItem = msg.Item); } }
public void handle(CloudLandClient client, IMessage messageReceived) { ServerRemoveEntityMessage message = (ServerRemoveEntityMessage)messageReceived; Loom.QueueOnMainThread(() => { Transform t = client.getClientComponent().entitiesParent.Find("entity|" + message.EntityId); if (t != null) { GameObject.Destroy(t.gameObject); } }); }
public void handle(CloudLandClient client, IMessage messageReceived) { ServerRemoveEntityMessage message = (ServerRemoveEntityMessage)messageReceived; Loom.QueueOnMainThread(() => { Transform t = client.getClientComponent().entitiesParent.Find("entity|" + message.EntityId); if (t != null) { ClientComponent.INSTANCE.entityManager.destroy(t.GetComponent <Entity>()); } }); }
public void handle(CloudLandClient client, IMessage messageReceived) { if (messageReceived is ServerUpdateBlockMessage) { handleSingle(client, (ServerUpdateBlockMessage)messageReceived); } else { foreach (ServerUpdateBlockMessage single in ((ServerUpdateBlockBatchMessage)messageReceived).Records) { handleSingle(client, single); } } }
// Use this for initialization void Start() { INSTANCE = this; GameObject obj = new GameObject(); obj.name = "Loom Object"; obj.AddComponent(typeof(Loom)); Block.InitializePrototypes(); client = new CloudLandClient(this); client.connect(LoginScreen.addr, 21098); }
public void handle(CloudLandClient client, IMessage messageReceived) { ServerJoinGameMessage message = (ServerJoinGameMessage)messageReceived; Loom.QueueOnMainThread(() => { client.getClientComponent().playerObject.transform.position = new UnityEngine.Vector3(message.X, message.Y, message.Z); client.getClientComponent().username = message.Username; client.getClientComponent().uuid = message.Uuid; client.getClientComponent().playerObject.SetActive(true); UnityEngine.Debug.Log("Player location updated to: " + string.Format("({0}, {1}, {2})", message.X, message.Y, message.Z)); client.loggedIn = true; }); }
public void handle(CloudLandClient client, IMessage messageReceived) { ServerHandshakeMessage message = (ServerHandshakeMessage)messageReceived; if (!message.Success) { UnityEngine.Debug.Log("Failed to handshake, reason: " + message.Message); return; } UnityEngine.Debug.Log("success handshaked! "); ClientAuthenticateMessage auth = new ClientAuthenticateMessage(); auth.UserId = 0; auth.Token = "random token"; client.sendMessage(auth); }
public void handle(CloudLandClient client, IMessage messageReceived) { ServerAddEntityMessage message = (ServerAddEntityMessage)messageReceived; Loom.QueueOnMainThread(() => { if (client.getClientComponent().entitiesParent.Find("entity|" + message.EntityId) != null) { GameObject.Destroy(client.getClientComponent().entitiesParent.Find("entity|" + message.EntityId).gameObject); } GameObject prefab = (GameObject)Resources.Load("Entities/" + message.EntityType.ToString()); GameObject obj = GameObject.Instantiate(prefab, new Vector3((float)message.X, (float)message.Y, (float)message.Z), Quaternion.Euler(message.Pitch, message.Yaw, 0f), client.getClientComponent().entitiesParent); // An entity prefab MUST include a sub-class of Entity obj.GetComponent <Entity>().entityId = message.EntityId; obj.GetComponent <Entity>().meta = message.Meta; obj.transform.name = "entity|" + message.EntityId; }); }
public void handle(CloudLandClient client, IMessage messageReceived) { ServerUpdateWindowElementMessage msg = (ServerUpdateWindowElementMessage)messageReceived; if (msg.WindowId == 0) { // TODO: handle inventory Loom.QueueOnMainThread(() => { ClientComponent.INSTANCE.GetComponent <PlayerInventory>().updateFromMetadata(msg.ElementIndex, msg.NewElement.Value); }); return; } GameWindow window = WindowManager.INSTANCE.getWindowById(msg.WindowId); if (window == null) { return; } Loom.QueueOnMainThread(() => window.updateElement(msg.ElementIndex, msg.NewElement)); }
public void handle(CloudLandClient client, IMessage messageReceived) { Org.Dragonet.Cloudland.Net.Protocol.ServerWindowOpenMessage msg = (Org.Dragonet.Cloudland.Net.Protocol.ServerWindowOpenMessage)messageReceived; Loom.QueueOnMainThread(() => WindowManager.INSTANCE.createWindow(msg)); }
private void handleSingle(CloudLandClient client, ServerUpdateBlockMessage message) { Loom.QueueOnMainThread(() => client.getClientComponent().chunkManager.setBlockAt(message.X, message.Y, message.Z, (int)(message.Id & 0xFFFF))); }