Esempio n. 1
0
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (!PluginSettings.Instance.WaypointsEnabled)
            {
                return(false);
            }

            if (words.Count() != 1)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            List <WaypointItem> items = Waypoints.Instance.Get(userId);

            if (items.FirstOrDefault(x => x.Name.ToLower() == words[0].ToLower()) == null)
            {
                Communication.SendPrivateInformation(userId, string.Format("You do not have a waypoint with the name: {0}", words[0]));
                return(true);
            }


            Waypoints.Instance.Remove(userId, words[0]);
            //Communication.SendClientMessage(userId, string.Format("/waypoint remove '{0}'", words[0]));
            WaypointItem item = items[0];

            item.Remove = true;
            Communication.WaypointMessage(item);
            Communication.SendPrivateInformation(userId, string.Format("Removed waypoint: '{0}'", words[0]));
            return(true);
        }
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (!PluginSettings.Instance.WaypointsEnabled)
            {
                return(false);
            }

            if (words.Count() != 1)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string     playerName = PlayerMap.Instance.GetPlayerNameFromSteamId(userId);
            long       playerId   = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId);
            IMyFaction faction    = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId);

            if (faction == null)
            {
                Communication.SendPrivateInformation(userId, string.Format("Unable to find your faction information.  You must be in a faction to use this."));
                return(true);
            }

            List <WaypointItem> items = Waypoints.Instance.Get((ulong)faction.FactionId);
            WaypointItem        item  = items.FirstOrDefault(x => x.Name.ToLower() == words[0].ToLower());

            if (item == null)
            {
                Communication.SendPrivateInformation(userId, string.Format("You do not have a faction waypoint with the name: {0}", words[0]));
                return(true);
            }

            if (item.Leader && !faction.IsLeader(playerId))
            {
                Communication.SendPrivateInformation(userId, string.Format("You must be a faction leader to remove the waypoint: {0}", words[0]));
                return(true);
            }

            Waypoints.Instance.Remove((ulong)faction.FactionId, words[0]);
            foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
            {
                if (Player.CheckPlayerSameFaction(userId, steamId))
                {
                    //Communication.SendClientMessage(steamId, string.Format("/waypoint remove '{0}'", words[0]));
                    item.Remove = true;
                    Communication.WaypointMessage(item);
                }
            }

            Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} has removed the waypoint: '{1}'", playerName, words[0]));
            return(true);
        }
		// /waypoint add "name" "text" X Y Z
		// /waypoint remove "name"
		public override void HandleCommand(byte[] data)
		{
            string text = Encoding.Unicode.GetString( data );
            WaypointItem item = new WaypointItem( );

            if ( text == "clear" )
            {
                HandleWaypointClear( );
                return;
            }

            item = MyAPIGateway.Utilities.SerializeFromXML<WaypointItem>( text );
            Logging.Instance.WriteLine( string.Format( "Waypoint: {0}", item.Name ) );
                        
            if ( !item.Remove && item.Name != "")
			{
				long distance = 10000001L;
                HandleWaypointAdd( item.Name, item.Text, item.WaypointType, item.Position, distance );
			}
			else if (item.Remove)
			{
				HandleWaypointRemove(item.Name);
			}
		}
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (!PluginSettings.Instance.WaypointsEnabled)
            {
                return(false);
            }

            if (words.Length != 2)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string name  = words[0];
            string group = words[1];

            List <WaypointItem> items = Waypoints.Instance.Get(userId);
            WaypointItem        item  = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);

            if (item != null)
            {
                if (Waypoints.Instance.GroupAdd(userId, words[0], words[1]))
                {
                    Communication.SendPrivateInformation(userId, string.Format("Waypoint '{0}' added to the group '{1}'", name, group));
                }
                else
                {
                    Communication.SendPrivateInformation(userId, string.Format("Failed to add waypoint '{0}' to the group '{1}'", name, group));
                }

                return(true);
            }

            string     playerName = PlayerMap.Instance.GetPlayerNameFromSteamId(userId);
            long       playerId   = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId);
            IMyFaction faction    = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId);

            if (faction != null)
            {
                items = Waypoints.Instance.Get((ulong)faction.FactionId);
                item  = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);

                if (item != null)
                {
                    if (item.Leader && !faction.IsLeader(playerId))
                    {
                        Communication.SendPrivateInformation(userId, "Only a faction leader can modify this item");
                        return(true);
                    }

                    if (Waypoints.Instance.GroupAdd((ulong)faction.FactionId, words[0], words[1]))
                    {
                        Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} added the waypoint '{1}' to the group '{2}'", playerName, name, group));
                    }
                    else
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Failed to add faction waypoint '{0}' to the group '{1}'", name, group));
                    }

                    return(true);
                }
            }

            Communication.SendPrivateInformation(userId, string.Format("You do not have a waypoint with the name '{0}'", name));
            return(true);
        }
Esempio n. 5
0
        public override void Handle()
        {
            lock (m_waypointAdd)
            {
                if (m_waypointAdd.Count < 1)
                {
                    return;
                }
            }

            if (MyAPIGateway.Players == null)
            {
                return;
            }

            List <IMyPlayer> players = new List <IMyPlayer>();
            bool             result  = false;

            Wrapper.GameAction(() =>
            {
                try
                {
                    MyAPIGateway.Players.GetPlayers(players, null);
                    result = true;
                }
                catch (Exception ex)
                {
                    Logging.WriteLineAndConsole(string.Format("Waypoints(): Unable to get player list: {0}", ex.ToString()));
                }
            });

            if (!result)
            {
                return;
            }

            lock (m_waypointAdd)
            {
                for (int r = m_waypointAdd.Count - 1; r >= 0; r--)
                {
                    ulong steamId = m_waypointAdd[r];

                    IMyPlayer player = players.FirstOrDefault(x => x.SteamUserId == steamId && x.Controller != null && x.Controller.ControlledEntity != null);
                    if (player != null)
                    {
                        Logging.WriteLineAndConsole("Player in game, creating waypoints");
                        m_waypointAdd.Remove(steamId);

                        // Add defaults
                        if (Waypoints.Instance.Get(steamId).Count < 1)
                        {
                            foreach (ServerWaypointItem item in PluginSettings.Instance.WaypointDefaultItems)
                            {
                                WaypointItem newItem = new WaypointItem();
                                newItem.Name         = item.Name;
                                newItem.Text         = item.Name;
                                newItem.WaypointType = WaypointTypes.Neutral;
                                newItem.Position     = new Vector3D(item.X, item.Y, item.Z);
                                newItem.SteamId      = steamId;
                                Waypoints.Instance.Add(newItem);
                            }
                        }

                        Waypoints.SendClientWaypoints(steamId);
                    }
                }
            }

            base.Handle();
        }
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (!PluginSettings.Instance.WaypointsEnabled)
            {
                return(false);
            }

            if (words.Length != 6 && words.Length != 7 && words.Length != 1)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string     playerName = PlayerMap.Instance.GetPlayerNameFromSteamId(userId);
            long       playerId   = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId);
            IMyFaction faction    = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId);

            if (faction == null)
            {
                Communication.SendPrivateInformation(userId, string.Format("Unable to find your faction information.  You must be in a faction to use this."));
                return(true);
            }

            List <WaypointItem> items = Waypoints.Instance.Get((ulong)faction.FactionId);

            if (PluginSettings.Instance.WaypointsMaxPerFaction > 0 && items.Count >= PluginSettings.Instance.WaypointsMaxPerFaction)
            {
                Communication.SendPrivateInformation(userId, string.Format("Waypoint limit has been reached.  You may only have {0} faction waypoints at a time on this server.  Please remove some waypoints in order to add new ones.", PluginSettings.Instance.WaypointsMaxPerPlayer));
                return(true);
            }

            if (words.Length == 1)
            {
                IMyEntity playerEntity = Player.FindControlledEntity(playerId);
                if (playerEntity == null)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Can't find your position"));
                    return(true);
                }

                Vector3D pos  = playerEntity.GetPosition();
                string   name = words[0];

                foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
                {
                    if (Player.CheckPlayerSameFaction(userId, steamId))
                    {
                        Communication.WaypointMessage(steamId, string.Format("add '{0}' '{0}' Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z)));
                    }
                }

                WaypointItem item = new WaypointItem
                {
                    SteamId      = (ulong)faction.FactionId,
                    Name         = name,
                    Text         = name,
                    Position     = pos,
                    WaypointType = WaypointTypes.Neutral,
                    Leader       = faction.IsLeader(playerId)
                };
                Waypoints.Instance.Add(item);

                Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: '{0}' at {1} by '{2}'", item.Name, General.Vector3DToString(item.Position), playerName));
            }
            else
            {
                for (int r = 3; r < 6; r++)
                {
                    double test;
                    if (!double.TryParse(words[r], out test))
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", words[r]));
                        return(true);
                    }
                }

                string add = string.Join(" ", words.Select(s => s.ToLowerInvariant()));

                foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
                {
                    if (Player.CheckPlayerSameFaction(userId, steamId))
                    {
                        Communication.WaypointMessage(steamId, string.Format("add {0}", add));
                    }
                }

                string group = "";
                if (words.Length == 7)
                {
                    group = words[7];
                }

                WaypointItem item = new WaypointItem
                {
                    SteamId = (ulong)faction.FactionId,
                    Name    = words[0],
                    Text    = words[1]
                };
                WaypointTypes type;
                Enum.TryParse(words[2], true, out type);
                item.WaypointType = type;
                item.Position     = new Vector3D(double.Parse(words[3]), double.Parse(words[4]), double.Parse(words[5]));
                item.Group        = group;
                item.Leader       = faction.IsLeader(playerId);
                Waypoints.Instance.Add(item);

                Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: '{0}' at {1} by '{2}'", item.Name, General.Vector3DToString(item.Position), playerName));
            }
            return(true);
        }
        public override bool HandleCommand(ulong userId, string command)
        {
            string[] words = command.Split(' ');
            if (!PluginSettings.Instance.WaypointsEnabled)
            {
                return(false);
            }

            string[] splits = General.SplitString(string.Join(" ", words));

            if (splits.Length != 1)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string name = splits[0];

            List <WaypointItem> items = Waypoints.Instance.Get(userId);
            WaypointItem        item  = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);

            if (item != null)
            {
                if (Waypoints.Instance.GroupRemove(userId, name))
                {
                    Communication.SendPrivateInformation(userId, string.Format("Waypoint '{0}' removed from group", name));
                }
                else
                {
                    Communication.SendPrivateInformation(userId, string.Format("Failed to remove waypoint '{0}' from group", name));
                }

                return(true);
            }

            string     playerName = PlayerMap.Instance.GetPlayerNameFromSteamId(userId);
            long       playerId   = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId);
            IMyFaction faction    = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId);

            if (faction != null)
            {
                items = Waypoints.Instance.Get((ulong)faction.FactionId);
                item  = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);

                if (item != null)
                {
                    if (item.Leader && !faction.IsLeader(playerId))
                    {
                        Communication.SendPrivateInformation(userId, "Only a faction leader can modify this item");
                        return(true);
                    }

                    if (Waypoints.Instance.GroupRemove((ulong)faction.FactionId, name))
                    {
                        Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} removed the waypoint '{1}' from it's group", playerName, name));
                    }
                    else
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Failed to remove faction waypoint '{0}' from it's group", name));
                    }

                    return(true);
                }
            }

            return(true);
        }
Esempio n. 8
0
        public override bool HandleCommand(ulong userId, string command)
        {
            string[] words = command.Split(' ');
            if (!PluginSettings.Instance.WaypointsEnabled)
            {
                if (!PluginSettings.Instance.WaypointsEnabled)
                {
                    return(false);
                }
            }

            string[] splits = General.SplitString(string.Join(" ", words));

            if (splits.Length != 6 && splits.Length != 7 && splits.Length != 5 && splits.Length != 1)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            List <WaypointItem> items = Waypoints.Instance.Get(userId);

            if (PluginSettings.Instance.WaypointsMaxPerPlayer > 0 && items.Count >= PluginSettings.Instance.WaypointsMaxPerPlayer)
            {
                Communication.SendPrivateInformation(userId, string.Format("Waypoint limit has been reached.  You may only have {0} waypoints at a time on this server.  Please remove some waypoints in order to add new ones.", PluginSettings.Instance.WaypointsMaxPerPlayer));
                return(true);
            }

            if (splits.Length == 1)
            {
                long      playerId     = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId);
                IMyEntity playerEntity = Player.FindControlledEntity(playerId);
                if (playerEntity == null)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Can't find your position"));
                    return(true);
                }

                Vector3D pos  = playerEntity.GetPosition();
                string   name = splits[0];

                Communication.SendClientMessage(userId, string.Format("/waypoint add \"{0}\" \"{0}\" Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z)));

                WaypointItem item = new WaypointItem();
                item.SteamId      = userId;
                item.Name         = name;
                item.Text         = name;
                item.Position     = pos;
                item.WaypointType = WaypointTypes.Neutral;
                Waypoints.Instance.Add(item);

                Communication.SendPrivateInformation(userId, string.Format("Waypoint added: {0} at {1}", item.Name, General.Vector3DToString(item.Position)));
            }
            else
            {
                int len = 5;
                if (splits.Length > 5)
                {
                    len = 6;
                }

                for (int r = len - 3; r < len; r++)
                {
                    double test = 0d;
                    if (!double.TryParse(splits[r], out test))
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", splits[r]));
                        return(true);
                    }
                }

                string add = "";
                foreach (string split in splits)
                {
                    if (add == "")
                    {
                        add += split.ToLower();
                    }
                    else
                    {
                        add += " " + split;
                    }
                }

                Communication.SendClientMessage(userId, string.Format("/waypoint add {0}", add));

                string group = "";
                if (splits.Length == 7)
                {
                    group = splits[7];
                }

                WaypointItem item = new WaypointItem();
                item.SteamId = userId;
                item.Name    = splits[0];

                int diff = splits.Length > 5 ? 1 : 0;
                item.Text = splits[diff];
                WaypointTypes type = WaypointTypes.Neutral;
                Enum.TryParse <WaypointTypes>(splits[diff + 1], true, out type);
                item.WaypointType = type;
                item.Position     = new Vector3D(double.Parse(splits[diff + 2]), double.Parse(splits[diff + 3]), double.Parse(splits[diff + 4]));
                item.Group        = group;
                Waypoints.Instance.Add(item);

                Communication.SendPrivateInformation(userId, string.Format("Waypoint added: {0} at {1}", item.Name, General.Vector3DToString(item.Position)));
            }
            return(true);
        }