Beispiel #1
0
        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();
            }));
        }