public void AddPropertyTenant(PropertyModel property, int tenantId, string accessType = "guest") { var tenantSession = Sessions.GetPlayerByCharID(tenantId); if (tenantSession == null) { return; } MySQL.execute("INSERT INTO property_tenants (`PropertyID`, `TenantCharacterID`, `AccessType`) VALUES (@id, @charid, @access)", new Dictionary <string, dynamic> { { "@id", property.PropertyId }, { "@charid", tenantId }, { "@access", accessType }, }, new Action <dynamic>(rows => { Log.Info($"Successfully registered character id {tenantId} as a tenant of property {property.PropertyId} with access type {accessType}"); var ownerSession = Sessions.GetPlayerByCharID(property.OwnerCharacterId); if (accessType == "guest") { ownerSession.Message("[Property]", $"You just gave {tenantSession.FirstName} {tenantSession.LastName} keys to this property"); tenantSession.Message("[Property]", $"You just got given keys to {property.Address} by {ownerSession.FirstName} {ownerSession.LastName}"); property.TemporaryCharacterAccess.Add(tenantId); } if (accessType == "co-owner") { ownerSession.Message("[Property]", $"You just gave {tenantSession.FirstName} {tenantSession.LastName} partial ownership to this property"); tenantSession.Message("[Property]", $"You just got given partial ownership to {property.Address} by {ownerSession.FirstName} {ownerSession.LastName}"); property.PropertyCharacterAccess.Add(tenantId); } property.ResyncProperty(); })); }
public void RemovePropertyTenant(PropertyModel property, int tenantId, bool silent = false) { MySQL.execute("DELETE FROM property_tenants WHERE PropertyID = @id AND TenantCharacterID = @charid", new Dictionary <string, dynamic> { { "@id", property.PropertyId }, { "@charid", tenantId } }, new Action <dynamic>(rows => { Log.Info($"Successfully removed character id {tenantId} as a tenant of property {property.PropertyId}"); var ownerSession = Sessions.GetPlayerByCharID(property.OwnerCharacterId); var tenantSession = Sessions.GetPlayerByCharID(tenantId); if (!silent) { ownerSession.Message("[Property]", $"You just revoked {(tenantSession == null ? tenantId.ToString() : tenantSession.FirstName + " " + tenantSession.LastName)} persistent access to this property"); tenantSession?.Message("[Property]", $"Your keys for {property.Address} were just taken off you"); } if (property.PropertyCharacterAccess.Contains(tenantId)) { property.PropertyCharacterAccess.Remove(tenantId); } if (property.TemporaryCharacterAccess.Contains(tenantId)) { property.TemporaryCharacterAccess.Remove(tenantId); } MySQL.execute("UPDATE vehicle_data SET Garage = 'Public1' WHERE Garage = ? AND CharID = ?", new List <dynamic> { $"home-{property.PropertyId}", tenantId }, new Action <dynamic>(data => { Log.Verbose($"Reset garages for vehicles in property {property.PropertyId} to Public1 due to the property being deleted"); })); property.DesyncPropertyForPlayer(tenantId); property.ResyncProperty(); })); }