private void HandleMessage(byte[] data) { using (MessageReader mr = new MessageReader(data)) { PermissionMessageType type = (PermissionMessageType)mr.Read <int>(); lock (vesselPermissions) { switch (type) { case PermissionMessageType.PERMISSION_INFO: Guid vesselID = new Guid(mr.Read <string>()); string vesselOwner = mr.Read <string>(); VesselPermission vesselPermission = new VesselPermission(vesselID, vesselOwner); vesselPermission.protection = (VesselProtectionType)Enum.Parse(typeof(VesselProtectionType), mr.Read <string>()); if (mr.Read <bool>()) { vesselPermission.group = mr.Read <string>(); } vesselPermissions[vesselID] = vesselPermission; break; case PermissionMessageType.PERMISSION_SYNCED: synced = true; break; } } } }
public bool PlayerHasVesselPermission(string playerName, Guid vesselID) { lock (vesselPermissions) { if (Settings.settingsStore.forcePublicSpaceObjects && vesselPermissions[vesselID].protection != VesselProtectionType.PUBLIC && GetSavedValue(vesselID, "type") == "SpaceObject") { SetVesselProtection(vesselID, VesselProtectionType.PUBLIC); } if (!vesselPermissions.ContainsKey(vesselID)) { return(true); } VesselPermission vp = vesselPermissions[vesselID]; if (vp.owner == playerName) { return(true); } if (vp.protection == VesselProtectionType.PUBLIC) { return(true); } if (vp.protection == VesselProtectionType.GROUP && vp.group != null && vp.group != "") { if (Groups.fetch.PlayerInGroup(playerName, vp.group)) { return(true); } } } return(false); }
public bool PlayerHasVesselPermission(string playerName, Guid vesselID) { lock (vesselPermissions) { if (!vesselPermissions.ContainsKey(vesselID)) { return(true); } VesselPermission vp = vesselPermissions[vesselID]; if (vp.owner == playerName) { return(true); } if (vp.protection == VesselProtectionType.PUBLIC) { return(true); } if (vp.protection == VesselProtectionType.GROUP && vp.group != null && vp.group != "") { if (groups.PlayerInGroup(playerName, vp.group)) { return(true); } } } return(false); }
private void SaveVesselPermissions(Guid guid) { lock (vesselPermissions) { string filePath = Path.Combine(vesselsFolder, guid + ".txt"); if (File.Exists(filePath)) { File.Delete(filePath); } if (!vesselPermissions.ContainsKey(guid)) { return; } VesselPermission vesselPermission = vesselPermissions[guid]; using (StreamWriter sw = new StreamWriter(filePath)) { sw.WriteLine(vesselPermission.owner); sw.WriteLine(vesselPermission.protection); if (!string.IsNullOrEmpty(vesselPermission.group)) { sw.WriteLine(vesselPermission.group); } } Messages.PermissionMessage.SendVesselPermissionToAll(guid); } }
private void Load() { vesselPermissions.Clear(); lock (vesselPermissions) { string[] files = Directory.GetFiles(vesselsFolder); foreach (string file in files) { Guid vesselGuid = Guid.Parse(Path.GetFileNameWithoutExtension(file)); try { using (StreamReader sr = new StreamReader(file)) { string playerString = sr.ReadLine(); string protectionString = sr.ReadLine(); string groupName = sr.ReadLine(); VesselPermission vp = new VesselPermission(vesselGuid, playerString); vp.protection = (VesselProtectionType)Enum.Parse(typeof(VesselProtectionType), protectionString); vp.group = groupName; vesselPermissions.Add(vesselGuid, vp); } } catch { DarkLog.Normal("Deleting vessel permissions file " + file + " as it is broken."); File.Delete(file); } } } }
public static void SendVesselPermissionToAll(Guid vesselID) { DarkLog.Debug("Sending permissions to everyone, vessel: " + vesselID); Dictionary <Guid, VesselPermission> vesselPermissions = Permissions.fetch.GetPermissionsCopy(); if (!vesselPermissions.ContainsKey(vesselID)) { return; } VesselPermission vesselPermission = vesselPermissions[vesselID]; using (MessageWriter mw = new MessageWriter()) { mw.Write <int>((int)PermissionMessageType.PERMISSION_INFO); mw.Write <string>(vesselID.ToString()); mw.Write <string>(vesselPermission.owner); mw.Write <string>(vesselPermission.protection.ToString()); if (!string.IsNullOrEmpty(vesselPermission.group)) { mw.Write <bool>(true); mw.Write <string>(vesselPermission.group); } else { mw.Write <bool>(false); } ServerMessage sm = new ServerMessage(); sm.type = ServerMessageType.PERMISSION; sm.data = mw.GetMessageBytes(); ClientHandler.SendToAll(null, sm, true); } }
public Dictionary <Guid, VesselPermission> GetPermissionsCopy() { Dictionary <Guid, VesselPermission> retVal = new Dictionary <Guid, VesselPermission>(); lock (vesselPermissions) { foreach (KeyValuePair <Guid, VesselPermission> kvp in vesselPermissions) { VesselPermission vpCopy = new VesselPermission(kvp.Key, kvp.Value.owner); vpCopy.protection = kvp.Value.protection; vpCopy.group = kvp.Value.group; retVal.Add(kvp.Key, vpCopy); } } return(retVal); }
private void DrawContent(int windowID) { GUI.DragWindow(moveRect); GUILayout.BeginVertical(); Guid vesselID = Guid.Empty; if (FlightGlobals.fetch != null && FlightGlobals.fetch.activeVessel != null) { vesselID = FlightGlobals.fetch.activeVessel.id; } if (FlightGlobals.fetch != null && FlightGlobals.fetch.activeVessel != null && permissions.vesselPermissions.ContainsKey(vesselID) && lockSystem.LockIsOurs("control-" + vesselID)) { VesselPermission vesselPermission = permissions.vesselPermissions[vesselID]; if (vesselPermission.owner == dmpSettings.playerName) { GUILayout.BeginHorizontal(); if (vesselPermission.protection != VesselProtectionType.PUBLIC) { if (GUILayout.Button("Set to public")) { permissions.SetVesselProtection(vesselID, VesselProtectionType.PUBLIC); } } if (vesselPermission.protection != VesselProtectionType.GROUP) { if (GUILayout.Button("Set to group")) { permissions.SetVesselProtection(vesselID, VesselProtectionType.GROUP); } } if (vesselPermission.protection != VesselProtectionType.PRIVATE) { if (GUILayout.Button("Set to private")) { permissions.SetVesselProtection(vesselID, VesselProtectionType.PRIVATE); } } GUILayout.EndHorizontal(); if (vesselPermission.protection == VesselProtectionType.GROUP) { if (groups.playerGroups.ContainsKey(dmpSettings.playerName)) { foreach (string group in groups.playerGroups[dmpSettings.playerName]) { if (GUILayout.Button("Set to group: " + group)) { permissions.SetVesselGroup(vesselID, group); } } } } GUILayout.Space(20); foreach (PlayerStatus playerStatus in playerStatusWorker.playerStatusList) { if (playerStatus.playerName != dmpSettings.playerName) { if (GUILayout.Button("Give owner to: " + playerStatus.playerName)) { permissions.SetVesselOwner(vesselID, playerStatus.playerName); } } } } else { GUILayout.Label("Not vessel owner, belongs to: " + vesselPermission.owner); } } else { GUILayout.Label("Not flying vessel"); } GUILayout.EndVertical(); }