Example #1
0
    private void Map_BlockChanged(object sender, JSMap.BlockChangedEventArgs e)
    {
        //Loop through all blocks objects, see if we have to update or add one
        GameObject foundBlock = null;
        foreach (var block in GameObject.FindGameObjectsWithTag("Block"))
        {
            if (Mathf.Approximately(block.transform.position.x, e.X) && Mathf.Approximately(block.transform.position.y, e.Y)) {
                foundBlock = block;
                break;
            }
        }

        if (e.BlockType == null)
        {
            if (foundBlock != null)
            {
                DestroyObject(foundBlock);
            }
        }
        else
        {
            if (foundBlock == null)
            {
                foundBlock = (GameObject)Instantiate(BlockPrefab, new Vector3(e.X, e.Y, 0), Quaternion.identity);
            }

            foundBlock.renderer.material = blockMaterials[e.BlockType.Name];
        }
    }
Example #2
0
    // Use this for initialization
    void Awake()
    {
        ScriptEngine = new ScriptEngine();
        ScriptEngine.SetGlobalValue("console", new JSConsole(ScriptEngine));

        BlockTypes = new ObservableDictionary<string, JSBlockType>();
        BlockTypes.OnAdded += HandleBlockTypesOnAdded;

        Map = new JSMap(ScriptEngine);
    }
Example #3
0
        public WorldDesc(XElement e)
        {
            Id            = e.ParseString("@id");
            DisplayName   = e.ParseString("@display", Id);
            Background    = e.ParseInt("Background");
            ShowDisplays  = e.ParseBool("ShowDisplays");
            AllowTeleport = e.ParseBool("AllowTeleport");
            BlockSight    = e.ParseInt("BlockSight");

            string[] maps = e.ParseStringArray("Maps", ";", new string[0]);
            Maps = new JSMap[maps.Length];
            for (int i = 0; i < maps.Length; i++)
            {
                Maps[i] = new JSMap(File.ReadAllText(Resources.CombineResourcePath($"Worlds/{maps[i]}")));
            }
        }
Example #4
0
        public static void Hello(Client client, PacketReader rdr)
        {
            string buildVersion = rdr.ReadString();
            int    gameId       = rdr.ReadInt32();
            string username     = rdr.ReadString();
            string password     = rdr.ReadString();

            byte[] mapJson = rdr.ReadBytes(rdr.ReadInt32());

            if (client.State == ProtocolState.Handshaked) //Only allow Hello to be processed once.
            {
                AccountModel acc = Database.Verify(username, password, client.IP);
                if (acc == null)
                {
                    client.Send(Failure(0, "Invalid account."));
                    Manager.AddTimedAction(1000, client.Disconnect);
                    return;
                }

                if (acc.Banned)
                {
                    client.Send(Failure(0, "Banned."));
                    Manager.AddTimedAction(1000, client.Disconnect);
                    return;
                }

                if (!acc.Ranked && gameId == Manager.EditorId)
                {
                    client.Send(Failure(0, "Not ranked."));
                    Manager.AddTimedAction(1000, client.Disconnect);
                }

                Manager.GetClient(acc.Id)?.Disconnect();

                if (Database.IsAccountInUse(acc))
                {
                    client.Send(Failure(0, "Account in use!"));
                    Manager.AddTimedAction(1000, client.Disconnect);
                    return;
                }

                client.Account           = acc;
                client.Account.Connected = true;
                client.Account.Save();
                client.TargetWorldId = gameId;

                Manager.AccountIdToClientId[client.Account.Id] = client.Id;
                World world = Manager.GetWorld(gameId);

#if DEBUG
                if (client.TargetWorldId == Manager.EditorId)
                {
                    Program.Print(PrintType.Debug, "Loading editor world");
                    JSMap map = new JSMap(Encoding.UTF8.GetString(mapJson));
                    world = new World(map, Resources.Worlds["Dreamland"]);
                    client.TargetWorldId = Manager.AddWorld(world);
                }
#endif

                if (world == null)
                {
                    client.Send(Failure(0, "Invalid world!"));
                    Manager.AddTimedAction(1000, client.Disconnect);
                    return;
                }

                uint seed = (uint)MathUtils.NextInt(1, int.MaxValue - 1);
                client.Random = new wRandom(seed);
                client.Send(MapInfo(world.Width, world.Height, world.Name, world.DisplayName, seed, world.Background, world.ShowDisplays, world.AllowTeleport));
                client.State = ProtocolState.Awaiting; //Allow the processing of Load/Create.
            }
        }