示例#1
0
        public void AddEvents(string regionName, string events)
        {
            RtRegion rt = GetRtRegionByName(regionName);

            if (rt == null)
            {
                throw new Exception("Invalid region!");
            }

            if (string.IsNullOrWhiteSpace(events) || events.ToLower() == Events.None)
            {
                throw new ArgumentException("Invalid events!");
            }

            StringBuilder modified = new StringBuilder(rt.Events == Events.None ? "" : rt.Events);
            var           toAdd    = Events.ValidateEventsList(events).Item1;

            toAdd.ForEach(r => {
                if (!rt.HasEvent(r))
                {
                    modified.Append($",{r}");
                }
            });
            if (modified[0] == ',')
            {
                modified.Remove(0, 1);
            }

            if (_database.Query("UPDATE RtRegions SET Events = @0 WHERE Id = @1", modified, rt.Id) == 0)
            {
                throw new Exception("Database error: No affected rows.");
            }
            rt.Events = modified.ToString();
        }
示例#2
0
        public void Reload()
        {
            try {
                using (
                    var reader =
                        _database.QueryReader(
                            "SELECT `rtregions`.* FROM `rtregions`, `regions` WHERE `rtregions`.RegionId = `regions`.Id AND `regions`.WorldID = @0",
                            Main.worldID.ToString())
                    ) {
                    Regions.Clear();

                    while (reader.Read())
                    {
                        var id        = reader.Get <int>("Id");
                        var regionId  = reader.Get <int>("RegionId");
                        var events    = reader.Get <string>("Events");
                        var entermsg  = reader.Get <string>("EnterMsg");
                        var leavemsg  = reader.Get <string>("LeaveMsg");
                        var msg       = reader.Get <string>("Message");
                        var msgitv    = reader.Get <int?>("MessageInterval");
                        var tempgroup = reader.Get <string>("TempGroup");
                        var itemb     = reader.Get <string>("Itembans");
                        var projb     = reader.Get <string>("Projbans");
                        var tileb     = reader.Get <string>("Tilebans");

                        var temp = TShock.Groups.GroupExists(tempgroup)
                                                        ? TShock.Utils.GetGroup(tempgroup)
                                                        : null;
                        var region = new RtRegion(id, regionId)
                        {
                            Events      = events ?? Events.None,
                            EnterMsg    = entermsg,
                            LeaveMsg    = leavemsg,
                            Message     = msg,
                            MsgInterval = msgitv ?? 0,
                            TempGroup   = temp,
                            Itembans    = itemb,
                            Projbans    = projb,
                            Tilebans    = tileb
                        };

                        if (region.HasEvent(Events.TempGroup) && region.TempGroup == null)
                        {
                            TShock.Log.ConsoleError("[RegionTrigger] TempGroup '{0}' of region '{1}' is invalid!", tempgroup, region.Region.Name);
                        }

                        Regions.Add(region);
                    }
                }
            } catch (Exception e) {
#if DEBUG
                Debug.WriteLine(e);
                Debugger.Break();
#endif
                TShock.Log.ConsoleError("[RegionTrigger] Load regions failed. Check log for more information.");
                TShock.Log.Error(e.ToString());
            }
        }
示例#3
0
        private static void OnRegionLeft(TSPlayer player, RtRegion region, RtPlayer data)
        {
            if (region.HasEvent(Event.LeaveMsg))
            {
                if (string.IsNullOrWhiteSpace(region.LeaveMsg))
                {
                    player.SendInfoMessage("You have left region {0}", region.Region.Name);
                }
                else
                {
                    player.SendMessage(region.LeaveMsg, Color.White);
                }
            }

            if (region.HasEvent(Event.TempGroup) && player.tempGroup == region.TempGroup)
            {
                player.tempGroup = null;
                player.SendInfoMessage("You are no longer in group {0}.", region.TempGroup.Name);
            }

            if (region.HasEvent(Event.Godmode))
            {
                player.GodMode = false;
                player.SendInfoMessage("You are no longer in godmode!");
            }

            if (region.HasEvent(Event.Pvp) || region.HasEvent(Event.NoPvp) || region.HasEvent(Event.InvariantPvp))
            {
                data.ForcePvP     = null;
                data.CanTogglePvP = true;
                player.SendInfoMessage("You can toggle your PvP status now.");
            }
        }
示例#4
0
        public void AddFlags(string regionName, string flags)
        {
            var region = TShock.Regions.GetRegionByName(regionName);

            if (region == null)
            {
                throw new Exception($"Couldn't find region named '{regionName}'!");
            }

            RtRegion rt = GetRtRegionById(region.ID);

            if (rt == null)
            {
                throw new Exception("Region has not been defined!");
            }
            if (string.IsNullOrWhiteSpace(flags) || flags.ToLower() == Events.None)
            {
                throw new ArgumentException("Invalid events!");
            }

            var oldstr = rt.Events;
            var newevt = flags.ToLower().Split(',');

            if (oldstr.Length != 0)
            {
                oldstr += ',';
            }

            oldstr = newevt
                     .Where(en => !string.IsNullOrWhiteSpace(en) && Events.Contains(en) && !rt.HasEvent(en))
                     .Aggregate(oldstr, (current, en) => current + $"{en},");
            oldstr = oldstr.Substring(0, oldstr.Length - 1);

            if (_database.Query("UPDATE RtRegions SET Flags=@0 WHERE Id=@1", oldstr, rt.Id) == 0)
            {
                throw new Exception("Database error: No affected rows.");
            }
            rt.Events = oldstr;
        }