Ejemplo n.º 1
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api, out object[] responseParams)
        {
            Vector3D storeLast;

            responseParams = new object[0];
            string   player             = connection.Credentials.Username;
            EntityId connectionEntityId = api.FindPlayerEntityId(player);
            Entity   entity;

            if (!api.TryGetEntity(connectionEntityId, out entity))
            {
                return("commands.playerEntityNotFound");
            }
            if (StaxelEssentialsHolder.GetBack() == null)
            {
                return("You don't have a place to go back to!");
            }
            storeLast = entity.Physics.Position;
            if (entity.Physics.Teleport(StaxelEssentialsHolder.GetBack()))
            {
                StaxelEssentialsHolder.SetBack(storeLast);
                return("commands.teleport.success");
            }
            return("commands.teleport.distance");
        }
Ejemplo n.º 2
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };

            try {
                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                if (bits.Any())
                {
                    if (bits.Skip(1).Any())
                    {
                        WorldEditManager.Import(player, bits[1]);
                    }
                }
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }

            return("mods.nimbusfox.worldedit.success.load");
        }
Ejemplo n.º 3
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api, out object[] responseParams)
        {
            responseParams = new object[0];
            string player = connection.Credentials.Username;

            if (bits.Length != 2)
            {
                return("Usage: /tp2 player");
            }

            EntityId playerEntityId1 = api.FindPlayerEntityId(player);
            EntityId playerEntityId2 = api.FindPlayerEntityId(bits[1]);
            Entity   entity1;
            Entity   entity2;

            if (!api.TryGetEntity(playerEntityId1, out entity1) || !api.TryGetEntity(playerEntityId2, out entity2))
            {
                return("commands.playerEntityNotFound");
            }
            StaxelEssentialsHolder.SetBack(entity1.Physics.Position);
            if (!entity1.Physics.Teleport(entity2.Physics.Position))
            {
                return("commands.teleport.distance");
            }
            return("commands.teleport.success");
        }
Ejemplo n.º 4
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };
            try {
                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                WorldEditManager.Copy(player);

                long tileCount;

                WorldEditManager.Set(player, "staxel.tile.Sky", out tileCount, out _);
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }

            return("mods.nimbusfox.worldedit.success.copy");
        }
Ejemplo n.º 5
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            try {
                responseParams = new object[] { };
                var repeat    = 1;
                var direction = "forwards";

                if (bits.Length >= 2)
                {
                    int.TryParse(bits[1], out repeat);
                }

                if (bits.Length >= 3)
                {
                    direction = bits[2];
                }

                WorldEditManager.Stack(WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid), repeat, direction);
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object> {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }
            return("");
        }
Ejemplo n.º 6
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };

            try {
                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                WorldEditManager.AddPos1(player);

                responseParams = new object[] {
                    player.Physics.BottomPosition().X,
                                                    player.Physics.BottomPosition().Y,
                                                    player.Physics.BottomPosition().Z
                };
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }
            return("mods.nimbusfox.worldedit.success.pos1");
        }
Ejemplo n.º 7
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };
            try {
                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                var tilecount = WorldEditManager.Paste(player);

                if (tilecount == 0)
                {
                    return("mods.nimbusfox.worldedit.error.emptyclipboard");
                }

                responseParams = new object[] { tilecount.ToString() };
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }
            return("mods.nimbusfox.worldedit.success.paste");
        }
Ejemplo n.º 8
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api, out object[] responseParams)
        {
            responseParams = new object[0];
            if (bits.Length != 3)
            {
                return("Usage: /pay player amount");
            }
            string   player          = connection.Credentials.Username;
            string   buyer           = bits[1];
            EntityId playerEntityId1 = api.FindPlayerEntityId(player);
            EntityId playerEntityId2 = api.FindPlayerEntityId(buyer);
            Entity   entity1;
            Entity   entity2;

            if (!api.TryGetEntity(playerEntityId1, out entity1) || !api.TryGetEntity(playerEntityId2, out entity2))
            {
                return("commands.playerEntityNotFound");
            }
            int result;

            if (!int.TryParse(bits[2], out result) || entity1.Inventory.GetMoney() - result < 0 || result < 1)
            {
                return("commands.givePetals.invalidNumber");
            }
            entity1.Inventory.AdjustMoney(-result);
            entity2.Inventory.AdjustMoney(result);
            return("payed");
        }
Ejemplo n.º 9
0
    private string ConnectionMessage(ClientServerConnection connection)
    {
        string message = "Connection";

        message += "|" + connection.ColorString();

        return(message);
    }
Ejemplo n.º 10
0
        public DirectoryWatcher(String _dir, ClientServerConnection _client)
        {
            client = _client;
              dir = _dir;

              start();
              //      listen();
        }
Ejemplo n.º 11
0
 private void SetCharacter(ClientServerConnection connection, int nr, string player, string character, bool chosen)
 {
     if (chosen)
     {
         connection.ConfirmCharacter(nr, character);
     }
     else
     {
         connection.CancelCharacter(nr);
     }
 }
Ejemplo n.º 12
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };
            try {
                bits = bits.Skip(1).ToArray();

                var newCode = "";
                var oldCode = "";

                if (bits.Length > 0)
                {
                    newCode = TileShortCodes.GetTileCode(bits[0]);
                }

                if (bits.Length > 1)
                {
                    oldCode = TileShortCodes.GetTileCode(bits[1]);
                }

                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                long          tileCount;
                ReplaceResult result;

                WorldEditManager.Replace(player, newCode, oldCode, out tileCount, out result);

                if (result == ReplaceResult.InvalidPositions)
                {
                    return("mods.nimbusfox.worldedit.error.noregion");
                }

                if (result == ReplaceResult.InvalidTile)
                {
                    responseParams = new object[] { newCode };
                    return("mods.nimbusfox.worldedit.error.invalidtile");
                }

                responseParams = new object[] { tileCount.ToString() };
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }

            return("mods.nimbusfox.worldedit.success.replaced");
        }
Ejemplo n.º 13
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };
            try {
                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                var height = 0;
                var width  = 0;
                var tile   = "staxel.tile.dirt.dirt";

                if (bits.Length >= 2)
                {
                    int.TryParse(bits[1], out width);
                    height = width;
                }

                if (bits.Length >= 3)
                {
                    int.TryParse(bits[2], out height);
                }

                if (bits.Length >= 4)
                {
                    tile = TileShortCodes.GetTileCode(bits[3]);
                }

                long tileCount;

                if (!WorldEditManager.Wall(player, width, height, out tileCount, tile))
                {
                    responseParams = new object[] { bits[3] };
                    return("mods.nimbusfox.worldedit.error.invalidtile");
                }

                responseParams = new object[] { tileCount.ToString() };
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }

            return("mods.nimbusfox.worldedit.success.set");
        }
Ejemplo n.º 14
0
        public ClientSetup()
        {
            ClientServerConnection.LogHandlers.Add(new ClientServerConnection.LoggingHandlerDelegate(logToConsole));

              // set up the defaults
              account = new ClientAccount();
              account.ServerName = "localhost";
              account.ServerPort = Common.DefaultCommunicationPort;
              account.User = "******";
              account.Password = "******";

              configDir = ClientServerConnection.DefaultConfigDir;

              Console.WriteLine("Welcome to the Mybox client setup wizard");

              gatherInput();

              account.Directory = Common.EndDirWithSlash(account.Directory);
              configDir = Common.EndDirWithSlash(configDir);

              // attach the account to the server to get the user
              ClientServerConnection client = new ClientServerConnection();

              Console.WriteLine("client initialized. trying coonection...");

              client.StartGetAccountMode(account);

              // data directory
              if (!Common.CreateLocalDirectory(account.Directory)) {
            Console.WriteLine("Data directory could not be created: " + account.Directory);
            Common.ExitError();
              }

              // config directory
              if (!Common.CreateLocalDirectory(configDir)) {
            Console.WriteLine("Config directory could not be created: " + configDir);
            Common.ExitError();
              }

              try {
            ClientServerConnection.SetConfigDir(configDir);
              } catch (Exception) {
            // toss config file not found exception since it is expected for a new setup
              }

              if (!saveConfig())
            Console.WriteLine("Unable to save config file");
              else
            Console.WriteLine("Setup finished successfully");
        }
Ejemplo n.º 15
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api, out object[] responseParams)
        {
            responseParams = new object[0];
            string   player             = connection.Credentials.Username;
            EntityId connectionEntityId = api.FindPlayerEntityId(player);
            Entity   entity;

            if (!api.TryGetEntity(connectionEntityId, out entity))
            {
                return("commands.playerEntityNotFound");
            }
            entity.PlayerEntityLogic.SetHome(entity.Physics.Position);
            return("Home set! Note, sleeping in a bed will reset this!");
        }
Ejemplo n.º 16
0
    // Start using phone controls
    public void UsePhoneController()
    {
        currentControl      = Instantiate(prefabPhoneConnection, loadControllerTo);
        currentControl.name = id + " Connection";

        hasCurrentControl = true;

        phoneConnection = currentControl.GetComponent <ClientServerConnection>();
        if (phoneConnection != null)
        {
            characterClassMenu.PhoneCharacter();
            phoneConnection.SetClientNr(id, clr, characterClassMenu, this);
        }

        playerMenuController.SetActive(false);
        playerMenuLoadConnection.SetActive(true);
    }
Ejemplo n.º 17
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };

            if (bits.Length >= 2)
            {
                if (bits[1].ToLower() == "confirm")
                {
                    api.Facade().SetCheated();
                    DebugEnabled = true;
                    return("nimbusfox.powerapi.command.debug.enabled");
                }
            }

            return("nimbusfox.powerapi.command.debug.confirmation");
        }
Ejemplo n.º 18
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };

            if (!EnableDebugCommand.DebugEnabled)
            {
                return("nimbusfox.powerapi.command.debugRequired");
            }

            if (!api.TryGetEntity(connection.ConnectionEntityId, out var player))
            {
                return("");
            }

            if (player.Inventory.ActiveItem().IsNull())
            {
                return("nimbusfox.powerapi.command.noItemInHand");
            }

            var activeItem = player.Inventory.ActiveItem().Item;

            if (activeItem is ChargeableItem == false)
            {
                responseParams = new object[] { activeItem.Configuration.Code };
                return("nimbusfox.powerapi.command.addPower.nonChargeableItem");
            }

            responseParams = new object[2];

            responseParams[0] = 0.ToString();
            responseParams[1] = activeItem.Configuration.Code;

            if (bits.Length >= 2)
            {
                if (long.TryParse(bits[1], out var toAdd))
                {
                    var chargeableItem = activeItem as ChargeableItem;
                    var diff           = chargeableItem.AddPower(toAdd);
                    responseParams[0] = diff.ToString();
                }
            }

            return("nimbusfox.powerapi.command.addPower.added");
        }
Ejemplo n.º 19
0
    private void ConnectionAvailable(ClientServerConnection connection, int nr, NetworkConnection conn, string[] deltas)
    {
        StringMessage msg = new StringMessage();

        if (connection.Available(nr))
        {
            msg.value = ConnectionMessage(connection);
            NetworkServer.SendToClient(conn.connectionId, 889, msg);
            currentconnections.Add(conn);

            connection.OpenConnection();

            return;
        }

        msg.value = DisconnectMessage();
        NetworkServer.SendToClient(conn.connectionId, 889, msg);
    }
Ejemplo n.º 20
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api, out object[] responseParams)
        {
            responseParams = new object[0];
            string   player             = connection.Credentials.Username;
            EntityId connectionEntityId = api.FindPlayerEntityId(player);
            Entity   entity;

            if (!api.TryGetEntity(connectionEntityId, out entity))
            {
                return("commands.playerEntityNotFound");
            }
            StaxelEssentialsHolder.SetBack(entity.Physics.Position);
            if (entity.Physics.Teleport(entity.PlayerEntityLogic.GetHome()))
            {
                return("commands.teleport.success");
            }
            return("commands.teleport.distance");
        }
Ejemplo n.º 21
0
    // Return to control selection
    public void ReturnToController()
    {
        stController    = null;
        phoneConnection = null;
        phonecontrol    = false;

        Destroy(currentControl);
        currentControl = null;

        hasCurrentControl = false;

        backgroundImage.enabled = true;

        playerMenuLoadConnection.SetActive(false);
        playerMenuCharacters.SetActive(false);
        playerMenuController.SetActive(true);

        parentCode.UpdateNavigation(false, this);
    }
        private static bool ConsoleMessage(ClientServerConnection __instance, DataPacket packet)
        {
            var blob = packet.Blob;

            if (!blob.Contains("message"))
            {
                return(true);
            }

            try {
                var message   = blob.FetchBlob("message");
                var storeBlob = message.FetchBlob("store");
                CoreHook.StartRestore(storeBlob);
                return(false);
            } catch {
                //ignore
            }

            return(true);
        }
Ejemplo n.º 23
0
    private void ServerReceiveMessage(NetworkMessage message)
    {
        StringMessage msg = new StringMessage();

        msg.value = message.ReadMessage <StringMessage>().value;

        string[] deltas = msg.value.Split('|');

        if (transform.childCount == 0)
        {
            msg.value = DisconnectMessage();
            NetworkServer.SendToClient(message.conn.connectionId, 889, msg);
        }

        foreach (Transform child in transform)
        {
            ClientServerConnection connection = child.GetComponent <ClientServerConnection>();
            if (connection != null)
            {
                string strNr = deltas[0];
                int    nr    = int.Parse(strNr);

                if (deltas[1].Equals("start"))
                {
                    ConnectionAvailable(connection, nr, message.conn, deltas);
                }
                else if (deltas[1].Equals("character"))
                {
                    SetCharacter(connection, nr, deltas[0], deltas[2], true);
                }
                else if (deltas[1].Equals("cancel"))
                {
                    SetCharacter(connection, nr, deltas[0], "", false);
                }
                else if (deltas[1].Equals("game"))
                {
                    connection.UseMove(nr, deltas);
                }
            }
        }
    }
Ejemplo n.º 24
0
        public static bool OnServerPacket(ClientServerConnection connection, DataPacket packet)
        {
            if (Instance == null)
            {
                return(true);
            }
            //Console.WriteLine($"Server Packet: {packet?.Kind} from {connection?.Credentials?.Username}");

            if (packet != null)
            {
                var blob   = packet.Blob;
                var user   = connection.Credentials;
                var sender = Instance.GetPlayer(connection);

                switch (packet.Kind)
                {
                case DataPacketKind.HelloServer:
                    var player = new Player(user.Username, user.Uid);
                    Instance.Connections.Add(player, connection);
                    if (Instance.Host.Events.PlayerJoined.Invoke(new EventManager.PlayerJoinEventArgs(player)))
                    {
                        return(false);
                    }
                    break;

                case DataPacketKind.Disconnect:
                    Instance.Host.Events.PlayerQuit.Invoke(new EventManager.PlayerQuitEventArgs(sender));
                    Instance.Connections.Remove(sender);
                    break;

                case DataPacketKind.ConsoleMessage:
                    if (Instance.Host.Events.Chat.Invoke(new EventManager.ChatEventArgs(sender,
                                                                                        blob.GetString("message"))))
                    {
                        return(false);
                    }
                    break;
                }
            }
            return(true);
        }
Ejemplo n.º 25
0
    // Start is called before the first frame update
    void Start()
    {
        playerload       = GameObject.Find("PlayerLoader");
        parentCharacters = transform.Find("Characters");
        settings         = new SettingsLevel(moveSpeed, jumpSpeed, gravity, distanceRangerAttack);

        if (playerload != null)
        {
            foreach (Transform child in playerBoardUI)
            {
                Destroy(child.gameObject);
            }

            int i = 0;
            foreach (Transform child in playerload.transform)
            {
                Vector3    spawnPoint    = new Vector3(0, 2.5f, 0);
                Quaternion rotationPoint = Quaternion.identity;

                Transform transformSpawnPoint = parentSpawnPointCharacters.GetChild(i);
                if (transformSpawnPoint != null)
                {
                    spawnPoint    = transformSpawnPoint.position;
                    rotationPoint = transformSpawnPoint.rotation;
                }

                StandardController stController = child.GetComponent <StandardController>();
                if (stController != null)
                {
                    GameObject character = stController.StartGame(parentCharacters, spawnPoint, rotationPoint, settings);

                    GameObject scoreUI = Instantiate(prefabPlayerScore, playerBoardUI);

                    PlayerManager pManager = character.GetComponent <PlayerManager>();
                    pManager.killsNeeded = killsNeeded;

                    PlayerUI uiPlayer = scoreUI.GetComponent <PlayerUI>();
                    uiPlayer.SetPlayer(pManager);
                    uiPlayer.ShowBells();
                }

                ClientServerConnection phoneConnection = child.GetComponent <ClientServerConnection>();
                if (phoneConnection != null)
                {
                    GameObject character = phoneConnection.StartGame(parentCharacters, spawnPoint, rotationPoint, settings);

                    GameObject scoreUI = Instantiate(prefabPlayerScore, playerBoardUI);

                    PlayerManager pManager = character.GetComponent <PlayerManager>();
                    pManager.killsNeeded = killsNeeded;

                    PlayerUI uiPlayer = scoreUI.GetComponent <PlayerUI>();
                    uiPlayer.SetPlayer(pManager);
                    uiPlayer.ShowBells();
                }

                i++;
            }
        }

        // Switch menu clients
        Server.StartGame();

        // Show message
        StartCoroutine(ShowMessage());

        pickups.SearchForPlayers();

        if (FadeInOut.screen != null)
        {
            FadeInOut.screen.FadeIn();
        }
    }
Ejemplo n.º 26
0
 private Player GetPlayer(ClientServerConnection connection)
 {
     return(Connections.FirstOrDefault(c => c.Value == connection).Key);
 }