コード例 #1
0
        // load log file (=past jail records)
        public static void LoadLogFile()
        {
            JSONNode jsonLog;

            if (!JSON.Deserialize(LogFilePath, out jsonLog, false))
            {
                Log.Write("No {0} found inside world directory, nothing to load", LOG_FILE);
                return;
            }

            Log.Write("Loading jail history records from {0}", LOG_FILE);
            try {
                JSONNode players;
                jsonLog.TryGetAs("players", out players);
                foreach (JSONNode node in players.LoopArray())
                {
                    string         PlayerId = node.GetAs <string>("steamId");
                    Players.Player target;
                    string         error;
                    if (!PlayerHelper.TryGetPlayer(PlayerId, out target, out error, true))
                    {
                        Log.Write($"Could not find player with id {PlayerId} from {LOG_FILE}");
                        continue;
                    }

                    List <JailLogRecord> playerHistory = new List <JailLogRecord>();
                    JSONNode             jsonPlayerRecords;
                    node.TryGetAs("records", out jsonPlayerRecords);
                    foreach (JSONNode record in jsonPlayerRecords.LoopArray())
                    {
                        long   timestamp  = record.GetAs <long>("timestamp");
                        long   duration   = record.GetAs <long>("duration");
                        string jailedById = record.GetAs <string>("jailedBy");
                        string reason     = record.GetAs <string>("reason");

                        Players.Player causedBy;
                        PlayerHelper.TryGetPlayer(jailedById, out causedBy, out error, true);
                        JailLogRecord playerRecord = new JailLogRecord(timestamp, duration, causedBy, reason);
                        playerHistory.Add(playerRecord);
                    }

                    jailLog.Add(target, playerHistory);
                }
            } catch (Exception e) {
                Log.Write("Error parsing {0}: {1}", LOG_FILE, e.Message);
            }
            return;
        }
コード例 #2
0
        // send a player to jail
        public static void jailPlayer(Players.Player target, Players.Player causedBy, string reason, long jailtime)
        {
            if (!validJail)
            {
                if (causedBy == null)
                {
                    Log.Write($"Cannot Jail {target.Name}: no valid jail found");
                }
                else
                {
                    Chat.Send(causedBy, "<color=yellow>No valid jail found. Unable to complete jailing</color>");
                }
                return;
            }

            Helper.TeleportPlayer(target, jailPosition);

            List <string> permissions = new List <string>();

            foreach (string permission in permissionList)
            {
                if (PermissionsManager.HasPermission(target, permission))
                {
                    permissions.Add(permission);
                    // PermissionsManager.RemovePermissionOfUser(causedBy, target, permission);
                }
            }

            long now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond / 1000;
            // create/add history record
            JailLogRecord        logRecord = new JailLogRecord(now, jailtime * 60, causedBy, reason);
            List <JailLogRecord> playerRecords;

            if (jailLog.TryGetValue(target, out playerRecords))
            {
                playerRecords.Add(logRecord);
            }
            else
            {
                playerRecords = new List <JailLogRecord>();
                playerRecords.Add(logRecord);
                jailLog.Add(target, playerRecords);
            }
            SaveLogFile();

            // create jail record
            JailRecord record = new JailRecord(now, jailtime * 60, causedBy, reason, permissions);

            jailedPersons.Add(target, record);
            Save();

            string sender;

            if (causedBy == null)
            {
                sender = "Server";
            }
            else
            {
                sender = causedBy.Name;
            }
            Chat.Send(target, $"<color=red>{sender} threw you into jail! Reason: {reason}</color>");
            Chat.Send(target, $"Remaining Jail Time: {jailtime} minutes, type /jailtime to check");
            Chat.SendToConnectedBut(target, $"<color=red>{sender} threw {target.Name} into jail! Reason: {reason}</color>");
            Log.Write($"{sender} threw {target.Name} into jail! Reason: {reason}");
            return;
        }