Compare commits

...

18 Commits

Author SHA1 Message Date
CI
5b2de88c3d chore: release version v1.16.0
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / 🛠 Build (1.17, 18.x, 27) (push) Waiting to run
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2024-11-15 07:59:04 +00:00
Dmitry Popov
82080b232f feat(Signatures): Add additional filters support to signature list, show description icon 2024-11-15 08:58:25 +01:00
CI
666bc7af43 chore: release version v1.15.5
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / 🛠 Build (1.17, 18.x, 27) (push) Waiting to run
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2024-11-14 12:57:21 +00:00
Dmitry Popov
dc077d5a5b chore: release version v1.15.4 2024-11-14 13:56:52 +01:00
CI
29c840c64a chore: release version v1.15.4
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / 🛠 Build (1.17, 18.x, 27) (push) Waiting to run
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2024-11-14 08:28:05 +00:00
Dmitry Popov
65e0f89f33 fix(Core): Untracked characters still tracked on map (#63)
fixes #60
2024-11-14 12:27:37 +04:00
CI
d3b9b36332 chore: release version v1.15.3
Some checks are pending
Build / 🚀 Deploy to test env (fly.io) (push) Waiting to run
Build / 🛠 Build (1.17, 18.x, 27) (push) Waiting to run
Build / 🛠 Build Docker Images (linux/amd64) (push) Blocked by required conditions
Build / 🏷 Create Release (push) Blocked by required conditions
2024-11-13 07:47:06 +00:00
Dmitry Popov
90bbf29ea1 Db unix socket (#62)
* feat(Core): Add support for Unix sockets for DB connection

* chore: release version v1.15.2

* chore: release version v1.15.2
2024-11-13 11:46:39 +04:00
CI
57f73684e8 chore: release version v1.15.2
Some checks failed
Build / 🚀 Deploy to test env (fly.io) (push) Has been cancelled
Build / 🛠 Build (1.17, 18.x, 27) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/amd64) (push) Has been cancelled
Build / 🏷 Create Release (push) Has been cancelled
2024-11-07 21:45:12 +00:00
Dmitry Popov
7833cdebb2 Merge branch 'main' of github.com:wanderer-industries/wanderer 2024-11-07 22:44:22 +01:00
Dmitry Popov
67a5ae2985 chore: release version v1.15.0 2024-11-07 22:44:19 +01:00
CI
f58c52d26b chore: release version v1.15.1 2024-11-07 21:42:31 +00:00
Dmitry Popov
41e7739461 Merge branch 'main' of github.com:wanderer-industries/wanderer 2024-11-07 22:41:52 +01:00
Dmitry Popov
332152b677 fix(Dev): Update .devcontainer instructions 2024-11-07 22:41:43 +01:00
CI
85b49fe1f0 chore: release version v1.15.0 2024-11-07 21:40:09 +00:00
Dmitry Popov
e7924532be feat(Connections): Add connection mark EOL time (#56) 2024-11-08 01:39:44 +04:00
CI
475d950ad6 chore: release version v1.14.1
Some checks failed
Build / 🚀 Deploy to test env (fly.io) (push) Has been cancelled
Build / 🛠 Build (1.17, 18.x, 27) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/amd64) (push) Has been cancelled
Build / 🏷 Create Release (push) Has been cancelled
2024-11-06 14:13:14 +00:00
Dmitry Popov
e6cfb29c6f fix(Core): Fix character tracking permissions 2024-11-06 15:12:44 +01:00
32 changed files with 766 additions and 406 deletions

View File

@@ -1,12 +1,7 @@
FROM elixir:1.16-otp-25
FROM elixir:1.17-otp-27
RUN apt update -yq
RUN apt install -yq curl gnupg mc inotify-tools
RUN apt install -yq curl gnupg
RUN apt --fix-broken install
RUN apt remove -y nodejs nodejs-doc
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt install -y nodejs
RUN npm install --global yarn
RUN mix local.hex --force

View File

@@ -2,7 +2,7 @@ version: "0.1"
services:
db:
image: postgres:14.3
image: postgres:13-alpine
restart: always
environment:
POSTGRES_USER: postgres
@@ -10,13 +10,13 @@ services:
ports:
- "5432:5432"
volumes:
- db:/var/lib/postgresql/data
- db-new:/var/lib/postgresql/data
wanderer:
environment:
PORT: 8000
DB_HOST: db
WEB_APP_URL: "http://localhost:4444"
WEB_APP_URL: "http://localhost:8000"
ERL_AFLAGS: "-kernel shell_history enabled"
build:
context: .
@@ -33,4 +33,4 @@ services:
volumes:
elixir-artifacts: {}
db: {}
db-new: {}

View File

@@ -18,4 +18,4 @@ jobs:
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.PORT }}
script: |
/app/release/linux/deploy.sh ${{ github.event.release.tag_name }}
/home/wanderer/app/deploy.sh ${{ github.event.release.tag_name }}

View File

@@ -1,3 +1,3 @@
erlang 25.3
elixir 1.16-otp-25
erlang 26.2.5.5
elixir 1.17.3-otp-26
nodejs 18.0.0

View File

@@ -2,6 +2,66 @@
<!-- changelog -->
## [v1.16.0](https://github.com/wanderer-industries/wanderer/compare/v1.15.5...v1.16.0) (2024-11-15)
### Features:
* Signatures: Add additional filters support to signature list, show description icon
## [v1.15.5](https://github.com/wanderer-industries/wanderer/compare/v1.15.4...v1.15.5) (2024-11-14)
## [v1.15.4](https://github.com/wanderer-industries/wanderer/compare/v1.15.3...v1.15.4) (2024-11-14)
### Bug Fixes:
* Core: Untracked characters still tracked on map (#63)
## [v1.15.3](https://github.com/wanderer-industries/wanderer/compare/v1.15.2...v1.15.3) (2024-11-13)
## [v1.15.2](https://github.com/wanderer-industries/wanderer/compare/v1.15.1...v1.15.2) (2024-11-07)
## [v1.15.1](https://github.com/wanderer-industries/wanderer/compare/v1.15.0...v1.15.1) (2024-11-07)
### Bug Fixes:
* Dev: Update .devcontainer instructions
## [v1.15.0](https://github.com/wanderer-industries/wanderer/compare/v1.14.1...v1.15.0) (2024-11-07)
### Features:
* Connections: Add connection mark EOL time (#56)
## [v1.14.1](https://github.com/wanderer-industries/wanderer/compare/v1.14.0...v1.14.1) (2024-11-06)
### Bug Fixes:
* Core: Fix character tracking permissions
## [v1.14.0](https://github.com/wanderer-industries/wanderer/compare/v1.13.12...v1.14.0) (2024-11-05)

View File

@@ -20,11 +20,11 @@ Interested to learn more? [Check more on our website](https://wanderer.ltd/news)
Wanderer is open source project and we have a free as in beer and self-hosted solution called [Wanderer Community Edition (CE)](https://wanderer.ltd/news/community-edition). Here are the differences between Wanderer and Wanderer CE:
| | Wanderer Cloud | Wanderer Community Edition |
| ------------- | ------------- | ------------- |
| **Infrastructure management** | Easy and convenient. It takes 2 minutes to register your character and create a map. We manage everything so you dont have to worry about anything and can focus on gameplay. | You do it all yourself. You need to get a server and you need to manage your infrastructure. You are responsible for installation, maintenance, upgrades, server capacity, uptime, backup, security, stability, consistency, loading time and so on.|
| **Release schedule** | Continuously developed and improved with new features and updates multiple times per week. | Latest features and improvements won't be immediately available.|
| **Server location** | All visitor data is exclusively processed on EU-owned cloud infrastructure. We keep your site data on a secure, encrypted and green energy powered server in Germany. This ensures that your site data is protected by the strict European Union data privacy laws and ensures compliance with GDPR. Your website data never leaves the EU. | You have full control and can host your instance on any server in any country that you wish. Host it on a server in your basement or host it with any cloud provider wherever you want, even those that are not GDPR compliant.|
| | Wanderer Cloud | Wanderer Community Edition |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Infrastructure management** | Easy and convenient. It takes 2 minutes to register your character and create a map. We manage everything so you dont have to worry about anything and can focus on gameplay. | You do it all yourself. You need to get a server and you need to manage your infrastructure. You are responsible for installation, maintenance, upgrades, server capacity, uptime, backup, security, stability, consistency, loading time and so on. |
| **Release schedule** | Continuously developed and improved with new features and updates multiple times per week. | Latest features and improvements won't be immediately available. |
| **Server location** | All visitor data is exclusively processed on EU-owned cloud infrastructure. We keep your site data on a secure, encrypted and green energy powered server in Germany. This ensures that your site data is protected by the strict European Union data privacy laws and ensures compliance with GDPR. Your website data never leaves the EU. | You have full control and can host your instance on any server in any country that you wish. Host it on a server in your basement or host it with any cloud provider wherever you want, even those that are not GDPR compliant. |
Interested in self-hosting Wanderer CE on your server? Take a look at our [Wanderer CE installation instructions](https://github.com/wanderer-industries/community-edition/).
@@ -54,7 +54,13 @@ Now you can visit [`localhost:8000`](http://localhost:8000) from your browser.
#### Using .devcontainer
- Run devcontainer
- See how to start server in #setup section
- Install additional dependencies inside Dev container
- `root@0d0a785313b6:/app# apt update`
- `root@0d0a785313b6:/app# curl -sL https://deb.nodesource.com/setup_18.x | bash -`
- `root@0d0a785313b6:/app# apt-get install nodejs inotify-tools -y`
- `root@0d0a785313b6:/app# mix setup`
- See how to run server in #Run section
#### Using nix flakes

View File

@@ -10,13 +10,17 @@ import {
Setting,
COSMIC_SIGNATURE,
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/SystemSignatureSettingsDialog';
import { SignatureGroup } from '@/hooks/Mapper/types';
interface SystemLinkSignatureDialogProps {
data: CommandLinkSignatureToSystem;
setVisible: (visible: boolean) => void;
}
const signatureSettings: Setting[] = [{ key: COSMIC_SIGNATURE, name: 'Show Cosmic Signatures', value: true }];
const signatureSettings: Setting[] = [
{ key: COSMIC_SIGNATURE, name: 'Show Cosmic Signatures', value: true },
{ key: SignatureGroup.Wormhole, name: 'Wormhole', value: true },
];
export const SystemLinkSignatureDialog = ({ data, setVisible }: SystemLinkSignatureDialogProps) => {
const { outCommand } = useMapRootState();
@@ -59,6 +63,7 @@ export const SystemLinkSignatureDialog = ({ data, setVisible }: SystemLinkSignat
>
<SystemSignaturesContent
systemId={`${data.solar_system_source}`}
hideLinkedSignatures
settings={signatureSettings}
onSelect={handleSelect}
selectable={true}

View File

@@ -12,6 +12,7 @@ import {
SHIP,
DRONE,
} from './SystemSignatureSettingsDialog';
import { SignatureGroup } from '@/hooks/Mapper/types';
import React, { useCallback, useEffect, useState } from 'react';
@@ -27,6 +28,12 @@ const settings: Setting[] = [
{ key: STARBASE, name: 'Show Starbase', value: true },
{ key: SHIP, name: 'Show Ships', value: true },
{ key: DRONE, name: 'Show Drones And Charges', value: true },
{ key: SignatureGroup.Wormhole, name: 'Show Wormholes', value: true },
{ key: SignatureGroup.RelicSite, name: 'Show Relic Sites', value: true },
{ key: SignatureGroup.DataSite, name: 'Show Data Sites', value: true },
{ key: SignatureGroup.OreSite, name: 'Show Ore Sites', value: true },
{ key: SignatureGroup.GasSite, name: 'Show Gas Sites', value: true },
{ key: SignatureGroup.CombatSite, name: 'Show Combat Sites', value: true },
];
const SIGNATURE_SETTINGS_KEY = 'wanderer_system_signature_settings';
@@ -91,8 +98,7 @@ export const SystemSignatures = () => {
</InfoDrawer>
<InfoDrawer title={<b className="text-slate-50">How to delete?</b>}>
For delete any signature first of all you need select before
<br /> and then use <b className="text-sky-500">Del</b> or{' '}
<b className="text-sky-500">Backspace</b>
<br /> and then use <b className="text-sky-500">Backspace</b>
</InfoDrawer>
</div>
) as React.ReactNode,

View File

@@ -3,6 +3,7 @@ import { useClipboard } from '@/hooks/Mapper/hooks/useClipboard';
import { parseSignatures } from '@/hooks/Mapper/helpers';
import { Commands, OutCommand } from '@/hooks/Mapper/types/mapHandlers.ts';
import { WdTooltip, WdTooltipHandlers } from '@/hooks/Mapper/components/ui-kit';
import { GROUPS_LIST } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts';
import { DataTable, DataTableRowClickEvent, DataTableRowMouseEvent, SortOrder } from 'primereact/datatable';
import { Column } from 'primereact/column';
@@ -30,6 +31,7 @@ import { PrimeIcons } from 'primereact/api';
import { SignatureSettings } from '@/hooks/Mapper/components/mapRootContent/components/SignatureSettings';
import { useMapEventListener } from '@/hooks/Mapper/events';
import { WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit/WdTooltipWrapper';
import { COSMIC_SIGNATURE } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/SystemSignatureSettingsDialog';
type SystemSignaturesSortSettings = {
sortField: string;
@@ -44,10 +46,17 @@ const SORT_DEFAULT_VALUES: SystemSignaturesSortSettings = {
interface SystemSignaturesContentProps {
systemId: string;
settings: Setting[];
hideLinkedSignatures?: boolean;
selectable?: boolean;
onSelect?: (signature: SystemSignature) => void;
}
export const SystemSignaturesContent = ({ systemId, settings, selectable, onSelect }: SystemSignaturesContentProps) => {
export const SystemSignaturesContent = ({
systemId,
settings,
hideLinkedSignatures,
selectable,
onSelect,
}: SystemSignaturesContentProps) => {
const { outCommand } = useMapRootState();
const [signatures, setSignatures, signaturesRef] = useRefState<SystemSignature[]>([]);
@@ -80,13 +89,32 @@ export const SystemSignaturesContent = ({ systemId, settings, selectable, onSele
}
}, []);
const groupSettings = useMemo(() => settings.filter(s => (GROUPS_LIST as string[]).includes(s.key)), [settings]);
const filteredSignatures = useMemo(() => {
return signatures
.filter(x => settings.find(y => y.key === x.kind)?.value)
.filter(x => {
if (hideLinkedSignatures && !!x.linked_system) {
return false;
}
const isCosmicSignature = x.kind === COSMIC_SIGNATURE;
if (isCosmicSignature) {
const showCosmicSignatures = settings.find(y => y.key === COSMIC_SIGNATURE)?.value;
if (showCosmicSignatures) {
return !x.group || groupSettings.find(y => y.key === x.group)?.value;
} else {
return !!x.group && groupSettings.find(y => y.key === x.group)?.value;
}
}
return settings.find(y => y.key === x.kind)?.value;
})
.sort((a, b) => {
return new Date(b.updated_at || 0).getTime() - new Date(a.updated_at || 0).getTime();
});
}, [signatures, settings]);
}, [signatures, settings, groupSettings, hideLinkedSignatures]);
const handleGetSignatures = useCallback(async () => {
const { signatures } = await outCommand({
@@ -354,13 +382,15 @@ export const SystemSignaturesContent = ({ systemId, settings, selectable, onSele
sortable
></Column>
<Column
bodyClassName="p-0 pl-1 pr-2"
field="group"
body={renderToolbar}
// headerClassName={headerClasses}
style={{ maxWidth: 26, minWidth: 26, width: 26 }}
></Column>
{!selectable && (
<Column
bodyClassName="p-0 pl-1 pr-2"
field="group"
body={renderToolbar}
// headerClassName={headerClasses}
style={{ maxWidth: 26, minWidth: 26, width: 26 }}
></Column>
)}
</DataTable>
</>
)}
@@ -370,12 +400,14 @@ export const SystemSignaturesContent = ({ systemId, settings, selectable, onSele
content={hoveredSig ? <SignatureView {...hoveredSig} /> : null}
/>
<SignatureSettings
systemId={systemId}
show={showSignatureSettings}
onHide={() => setShowSignatureSettings(false)}
signatureData={selectedSignature}
/>
{showSignatureSettings && (
<SignatureSettings
systemId={systemId}
show
onHide={() => setShowSignatureSettings(false)}
signatureData={selectedSignature}
/>
)}
{askUser && (
<div className="absolute left-[1px] top-[29px] h-[calc(100%-30px)] w-[calc(100%-3px)] bg-stone-900/10 backdrop-blur-sm">

View File

@@ -1,5 +1,9 @@
import { PrimeIcons } from 'primereact/api';
import { SignatureGroup, SystemSignature } from '@/hooks/Mapper/types';
import { SystemViewStandalone, WHClassView } from '@/hooks/Mapper/components/ui-kit';
import { WdTooltipWrapper } from '@/hooks/Mapper/components/ui-kit/WdTooltipWrapper';
import clsx from 'clsx';
import { renderName } from './renderName.tsx';
import classes from './renderInfoColumn.module.scss';
@@ -32,13 +36,23 @@ export const renderInfoColumn = (row: SystemSignature) => {
</span>
</>
)}
{row.description && (
<WdTooltipWrapper content={row.description}>
<span className={clsx(PrimeIcons.EXCLAMATION_CIRCLE, 'text-[12px]')}></span>
</WdTooltipWrapper>
)}
</div>
);
}
if (row.description != null && row.description.length > 0) {
return <span title={row.description}>{row.description}</span>;
}
return renderName(row);
return (
<div className="flex gap-1 items-center">
{renderName(row)}{' '}
{row.description && (
<WdTooltipWrapper content={row.description}>
<span className={clsx(PrimeIcons.EXCLAMATION_CIRCLE, 'text-[12px]')}></span>
</WdTooltipWrapper>
)}
</div>
);
};

View File

@@ -1,13 +1,20 @@
import classes from './Connections.module.scss';
import { Sidebar } from 'primereact/sidebar';
import { useEffect, useMemo, useState } from 'react';
import { useEffect, useMemo, useState, useCallback } from 'react';
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
import { VirtualScroller, VirtualScrollerTemplateOptions } from 'primereact/virtualscroller';
import clsx from 'clsx';
import { ConnectionOutput, OutCommand, Passage, SolarSystemConnection } from '@/hooks/Mapper/types';
import {
ConnectionOutput,
ConnectionInfoOutput,
OutCommand,
Passage,
SolarSystemConnection,
} from '@/hooks/Mapper/types';
import { PassageCard } from './PassageCard';
import { InfoDrawer, SystemView } from '@/hooks/Mapper/components/ui-kit';
import { kgToTons } from '@/hooks/Mapper/utils/kgToTons.ts';
import { TimeAgo } from '@/hooks/Mapper/components/ui-kit';
const sortByDate = (a: string, b: string) => new Date(a).getTime() - new Date(b).getTime();
@@ -69,25 +76,44 @@ export const Connections = ({ selectedConnection, onHide }: OnTheMapProps) => {
}, [connections, selectedConnection]);
const [passages, setPassages] = useState<Passage[]>([]);
const [info, setInfo] = useState<ConnectionInfoOutput>(null);
const loadInfo = useCallback(
async (connection: SolarSystemConnection) => {
const result = await outCommand<ConnectionInfoOutput>({
type: OutCommand.getConnectionInfo,
data: {
from: connection.source,
to: connection.target,
},
});
setInfo(result);
},
[outCommand],
);
const loadPassages = useCallback(
async (connection: SolarSystemConnection) => {
const result = await outCommand<ConnectionOutput>({
type: OutCommand.getPassages,
data: {
from: connection.source,
to: connection.target,
},
});
setPassages(result.passages.sort((a, b) => sortByDate(b.inserted_at, a.inserted_at)));
},
[outCommand],
);
useEffect(() => {
if (!selectedConnection) {
return;
}
const loadInfo = async () => {
const result = await outCommand<ConnectionOutput>({
type: OutCommand.getPassages,
data: {
from: selectedConnection.source,
to: selectedConnection.target,
},
});
setPassages(result.passages.sort((a, b) => sortByDate(b.inserted_at, a.inserted_at)));
};
loadInfo();
loadInfo(selectedConnection);
loadPassages(selectedConnection);
}, [selectedConnection]);
const approximateMass = useMemo(() => {
@@ -132,6 +158,10 @@ export const Connections = ({ selectedConnection, onHide }: OnTheMapProps) => {
{kgToTons(approximateMass)}
</InfoDrawer>
<InfoDrawer title="Mark EOL Time" rightSide>
{info?.marl_eol_time ? <TimeAgo timestamp={info.marl_eol_time} /> : ' unknown '}
</InfoDrawer>
<div className="flex gap-2"></div>
</div>

View File

@@ -11,6 +11,10 @@ export type Passage = {
character: PassageLimitedCharacterType;
};
export type ConnectionInfoOutput = {
marl_eol_time: string;
};
export type ConnectionOutput = {
passages: Passage[];
};

View File

@@ -118,6 +118,7 @@ export enum OutCommand {
getCharacterJumps = 'get_character_jumps',
getSignatures = 'get_signatures',
getSystemStaticInfos = 'get_system_static_infos',
getConnectionInfo = 'get_connection_info',
updateConnectionTimeStatus = 'update_connection_time_status',
updateConnectionMassStatus = 'update_connection_mass_status',
updateConnectionShipSizeType = 'update_connection_ship_size_type',

View File

@@ -172,43 +172,65 @@ config :wanderer_app, WandererApp.Scheduler,
timeout: :infinity
if config_env() == :prod do
database_url =
System.get_env("DATABASE_URL") ||
raise """
environment variable DATABASE_URL is missing.
For example: ecto://USER:PASS@HOST/DATABASE
"""
database_unix_socket =
System.get_env("DATABASE_UNIX_SOCKET")
maybe_ipv6 =
config_dir
|> get_var_from_path_or_env("ECTO_IPV6", "false")
|> String.to_existing_atom()
database =
database_unix_socket
|> case do
true -> [:inet6]
_ -> []
end
nil ->
System.get_env("DATABASE_URL") ||
raise """
environment variable DATABASE_URL is missing.
For example: ecto://USER:PASS@HOST/DATABASE
"""
db_ssl_enabled =
config_dir
|> get_var_from_path_or_env("DATABASE_SSL_ENABLED", "false")
|> String.to_existing_atom()
db_ssl_verify_none =
config_dir
|> get_var_from_path_or_env("DATABASE_SSL_VERIFY_NONE", "false")
|> String.to_existing_atom()
client_opts =
if db_ssl_verify_none do
[verify: :verify_none]
_ ->
System.get_env("DATABASE_NAME") ||
raise """
environment variable DATABASE_NAME is missing.
For example: "wanderer"
"""
end
config :wanderer_app, WandererApp.Repo,
url: database_url,
ssl: db_ssl_enabled,
ssl_opts: client_opts,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
socket_options: maybe_ipv6
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
if not is_nil(database_unix_socket) do
config :wanderer_app, WandererApp.Repo,
socket_dir: database_unix_socket,
database: database
else
db_ssl_enabled =
config_dir
|> get_var_from_path_or_env("DATABASE_SSL_ENABLED", "false")
|> String.to_existing_atom()
db_ssl_verify_none =
config_dir
|> get_var_from_path_or_env("DATABASE_SSL_VERIFY_NONE", "false")
|> String.to_existing_atom()
client_opts =
if db_ssl_verify_none do
[verify: :verify_none]
end
maybe_ipv6 =
config_dir
|> get_var_from_path_or_env("ECTO_IPV6", "false")
|> String.to_existing_atom()
|> case do
true -> [:inet6]
_ -> []
end
config :wanderer_app, WandererApp.Repo,
url: database,
ssl: db_ssl_enabled,
ssl_opts: client_opts,
socket_options: maybe_ipv6
end
# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you

View File

@@ -3,7 +3,7 @@
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'wanderer'
app = 'wanderer-test'
primary_region = 'ams'
kill_signal = 'SIGTERM'
swap_size_mb = 512
@@ -14,18 +14,14 @@ swap_size_mb = 512
release_command = '/app/bin/migrate.sh'
[env]
PHX_HOST = 'wanderer.fly.dev'
PHX_HOST = 'wanderer-test.fly.dev'
PHX_SERVER = 'true'
PORT = '8080'
[metrics]
port = 4021
path = "/metrics"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = false
auto_stop_machines = 'off'
auto_start_machines = false
min_machines_running = 0
processes = ['app']
@@ -36,6 +32,9 @@ path = "/metrics"
soft_limit = 1000
[[vm]]
memory = '256mb'
cpu_kind = 'shared'
cpus = 1
size = 'shared-cpu-1x'
[[metrics]]
port = 4021
path = '/metrics'
https = false

View File

@@ -4,8 +4,6 @@ defmodule WandererApp.Api.Calculations.CalcMapPermissions do
use Ash.Resource.Calculation
require Ash.Query
import Bitwise
@impl true
def load(_query, _opts, _context) do
[
@@ -17,116 +15,8 @@ defmodule WandererApp.Api.Calculations.CalcMapPermissions do
end
@impl true
def calculate([record], _opts, %{actor: actor}) do
characters = actor.characters
character_ids = characters |> Enum.map(& &1.id)
character_eve_ids = characters |> Enum.map(& &1.eve_id)
character_corporation_ids =
characters |> Enum.map(& &1.corporation_id) |> Enum.map(&to_string/1)
character_alliance_ids = characters |> Enum.map(& &1.alliance_id) |> Enum.map(&to_string/1)
result =
record.acls
|> Enum.reduce([0, 0], fn acl, acc ->
is_owner? = acl.owner_id in character_ids
is_character_member? =
acl.members |> Enum.any?(fn member -> member.eve_character_id in character_eve_ids end)
is_corporation_member? =
acl.members
|> Enum.any?(fn member -> member.eve_corporation_id in character_corporation_ids end)
is_alliance_member? =
acl.members
|> Enum.any?(fn member -> member.eve_alliance_id in character_alliance_ids end)
if is_owner? || is_character_member? || is_corporation_member? || is_alliance_member? do
case acc do
[_, -1] ->
[-1, -1]
[-1, char_acc] ->
char_acl_mask =
acl.members
|> Enum.filter(fn member ->
member.eve_character_id in character_eve_ids
end)
|> Enum.reduce(0, fn member, acc ->
case acc do
-1 -> -1
_ -> WandererApp.Permissions.calc_role_mask(member.role, acc)
end
end)
char_acc =
case char_acl_mask do
-1 -> -1
_ -> char_acc ||| char_acl_mask
end
[-1, char_acc]
[any_acc, char_acc] ->
any_acl_mask =
acl.members
|> Enum.filter(fn member ->
member.eve_character_id in character_eve_ids ||
member.eve_corporation_id in character_corporation_ids ||
member.eve_alliance_id in character_alliance_ids
end)
|> Enum.reduce(0, fn member, acc ->
case acc do
-1 -> -1
_ -> WandererApp.Permissions.calc_role_mask(member.role, acc)
end
end)
char_acl_mask =
acl.members
|> Enum.filter(fn member ->
member.eve_character_id in character_eve_ids
end)
|> Enum.reduce(0, fn member, acc ->
case acc do
-1 -> -1
_ -> WandererApp.Permissions.calc_role_mask(member.role, acc)
end
end)
any_acc =
case any_acl_mask do
-1 -> -1
_ -> any_acc ||| any_acl_mask
end
char_acc =
case char_acl_mask do
-1 -> -1
_ -> char_acc ||| char_acl_mask
end
[any_acc, char_acc]
end
else
acc
end
end)
case result do
[_, -1] ->
[-1]
[-1, char_acc] ->
[char_acc]
[any_acc, _char_acc] ->
[any_acc]
end
end
def calculate([record], _opts, %{actor: actor}),
do: WandererApp.Permissions.check_characters_access(actor.characters, record.acls)
@impl true
def calculate(_records, _opts, _context) do

View File

@@ -17,12 +17,12 @@ defmodule WandererApp.Api.MapCharacterSettings do
action: :read_by_map
)
define(:tracked_by_map,
action: :tracked_by_map
define(:tracked_by_map_filtered,
action: :tracked_by_map_filtered
)
define(:tracked_by_map_all,
action: :read_tracked_by_map
action: :tracked_by_map_all
)
define(:track, action: :track)
@@ -38,7 +38,7 @@ defmodule WandererApp.Api.MapCharacterSettings do
defaults [:create, :read, :update, :destroy]
read :tracked_by_map do
read :tracked_by_map_filtered do
argument(:map_id, :string, allow_nil?: false)
argument(:character_ids, {:array, :uuid}, allow_nil?: false)
@@ -52,7 +52,7 @@ defmodule WandererApp.Api.MapCharacterSettings do
filter(expr(map_id == ^arg(:map_id)))
end
read :read_tracked_by_map do
read :tracked_by_map_all do
argument(:map_id, :string, allow_nil?: false)
filter(expr(map_id == ^arg(:map_id) and tracked == true))
end

View File

@@ -16,6 +16,7 @@ defmodule WandererApp.Api.MapSystemSignature do
define(:update, action: :update)
define(:update_linked_system, action: :update_linked_system)
define(:update_type, action: :update_type)
define(:update_group, action: :update_group)
define(:by_id,
get_by: [:id],
@@ -86,6 +87,10 @@ defmodule WandererApp.Api.MapSystemSignature do
accept [:type]
end
update :update_group do
accept [:group]
end
read :by_system_id do
argument(:system_id, :string, allow_nil?: false)

View File

@@ -8,6 +8,7 @@ defmodule WandererApp.Map do
defstruct map_id: nil,
name: nil,
scope: :none,
owner_id: nil,
characters: [],
systems: Map.new(),
hubs: [],
@@ -16,11 +17,12 @@ defmodule WandererApp.Map do
characters_limit: nil,
hubs_limit: nil
def new(%{id: map_id, name: name, scope: scope, acls: acls, hubs: hubs}) do
def new(%{id: map_id, name: name, scope: scope, owner_id: owner_id, acls: acls, hubs: hubs}) do
map =
struct!(__MODULE__,
map_id: map_id,
scope: scope,
owner_id: owner_id,
name: name,
acls: acls,
hubs: hubs

View File

@@ -183,6 +183,12 @@ defmodule WandererApp.Map.Server do
|> map_pid!
|> GenServer.cast({&Impl.delete_connection/2, [connection_info]})
def get_connection_info(map_id, connection_info) when is_binary(map_id),
do:
map_id
|> map_pid!
|> GenServer.call({&Impl.get_connection_info/2, [connection_info]}, :timer.minutes(1))
def update_connection_time_status(map_id, connection_info) when is_binary(map_id),
do:
map_id

View File

@@ -77,6 +77,7 @@ defmodule WandererApp.Map.Server.Impl do
# @unknown 100_100
@systems_cleanup_timeout :timer.minutes(30)
@characters_cleanup_timeout :timer.minutes(1)
@connections_cleanup_timeout :timer.minutes(2)
@connection_time_status_eol 1
@@ -112,20 +113,28 @@ defmodule WandererApp.Map.Server.Impl do
end
def load_state(%__MODULE__{map_id: map_id} = state) do
with {:ok, map} <- WandererApp.MapRepo.get(map_id, [:acls, :characters]),
with {:ok, map} <-
WandererApp.MapRepo.get(map_id, [
:owner,
:characters,
acls: [
:owner_id,
members: [:role, :eve_character_id, :eve_corporation_id, :eve_alliance_id]
]
]),
{:ok, systems} <- WandererApp.MapSystemRepo.get_visible_by_map(map_id),
{:ok, connections} <- WandererApp.MapConnectionRepo.get_by_map(map_id),
{:ok, subscription_settings} <-
WandererApp.Map.SubscriptionManager.get_active_map_subscription(map_id) do
state
|> _init_map(
|> init_map(
map,
subscription_settings,
systems,
connections
)
|> _init_map_systems(systems)
|> _init_map_cache()
|> init_map_systems(systems)
|> init_map_cache()
else
error ->
@logger.error("Failed to load map state: #{inspect(error, pretty: true)}")
@@ -144,7 +153,8 @@ defmodule WandererApp.Map.Server.Impl do
Process.send_after(self(), :update_tracked_characters, 100)
Process.send_after(self(), :update_presence, @update_presence_timeout)
Process.send_after(self(), :cleanup_connections, 5000)
Process.send_after(self(), :cleanup_systems, 10000)
Process.send_after(self(), :cleanup_systems, 10_000)
Process.send_after(self(), :cleanup_characters, :timer.minutes(5))
Process.send_after(self(), :backup_state, @backup_state_timeout)
WandererApp.Cache.insert("map_#{map_id}:started", true)
@@ -169,7 +179,7 @@ defmodule WandererApp.Map.Server.Impl do
:telemetry.execute([:wanderer_app, :map, :stopped], %{count: 1})
state
|> _maybe_stop_rtree()
|> maybe_stop_rtree()
end
def get_map(%{map: map} = _state), do: {:ok, map}
@@ -249,37 +259,37 @@ defmodule WandererApp.Map.Server.Impl do
state,
update
),
do: state |> _update_system(:update_name, [:name], update)
do: state |> update_system(:update_name, [:name], update)
def update_system_description(
state,
update
),
do: state |> _update_system(:update_description, [:description], update)
do: state |> update_system(:update_description, [:description], update)
def update_system_status(
state,
update
),
do: state |> _update_system(:update_status, [:status], update)
do: state |> update_system(:update_status, [:status], update)
def update_system_tag(
state,
update
),
do: state |> _update_system(:update_tag, [:tag], update)
do: state |> update_system(:update_tag, [:tag], update)
def update_system_locked(
state,
update
),
do: state |> _update_system(:update_locked, [:locked], update)
do: state |> update_system(:update_locked, [:locked], update)
def update_system_labels(
state,
update
),
do: state |> _update_system(:update_labels, [:labels], update)
do: state |> update_system(:update_labels, [:labels], update)
def update_system_position(
%{rtree_name: rtree_name} = state,
@@ -287,7 +297,7 @@ defmodule WandererApp.Map.Server.Impl do
),
do:
state
|> _update_system(
|> update_system(
:update_position,
[:position_x, :position_y],
update,
@@ -435,12 +445,34 @@ defmodule WandererApp.Map.Server.Impl do
state
end
def get_connection_info(
%{map_id: map_id} = _state,
%{
solar_system_source_id: solar_system_source_id,
solar_system_target_id: solar_system_target_id
} = _connection_info
) do
WandererApp.Map.find_connection(
map_id,
solar_system_source_id,
solar_system_target_id
)
|> case do
{:ok, %{id: connection_id}} ->
connection_mark_eol_time = get_connection_mark_eol_time(map_id, connection_id, nil)
{:ok, %{marl_eol_time: connection_mark_eol_time}}
_ ->
{:error, :not_found}
end
end
def update_connection_time_status(
%{map_id: map_id} = state,
connection_update
),
do:
_update_connection(state, :update_time_status, [:time_status], connection_update, fn
update_connection(state, :update_time_status, [:time_status], connection_update, fn
%{id: connection_id, time_status: time_status} ->
case time_status == @connection_time_status_eol do
true ->
@@ -459,25 +491,25 @@ defmodule WandererApp.Map.Server.Impl do
state,
connection_update
),
do: _update_connection(state, :update_mass_status, [:mass_status], connection_update)
do: update_connection(state, :update_mass_status, [:mass_status], connection_update)
def update_connection_ship_size_type(
state,
connection_update
),
do: _update_connection(state, :update_ship_size_type, [:ship_size_type], connection_update)
do: update_connection(state, :update_ship_size_type, [:ship_size_type], connection_update)
def update_connection_locked(
state,
connection_update
),
do: _update_connection(state, :update_locked, [:locked], connection_update)
do: update_connection(state, :update_locked, [:locked], connection_update)
def update_connection_custom_info(
state,
connection_update
),
do: _update_connection(state, :update_custom_info, [:custom_info], connection_update)
do: update_connection(state, :update_custom_info, [:custom_info], connection_update)
def import_settings(%{map_id: map_id} = state, settings, user_id) do
WandererApp.Cache.put(
@@ -487,9 +519,9 @@ defmodule WandererApp.Map.Server.Impl do
state =
state
|> _maybe_import_systems(settings, user_id, nil)
|> _maybe_import_connections(settings, user_id)
|> _maybe_import_hubs(settings, user_id)
|> maybe_import_systems(settings, user_id, nil)
|> maybe_import_connections(settings, user_id)
|> maybe_import_hubs(settings, user_id)
WandererApp.Cache.take("map_#{map_id}:importing")
@@ -509,11 +541,11 @@ defmodule WandererApp.Map.Server.Impl do
|> Enum.map(fn character_id ->
Task.start_link(fn ->
character_updates =
_maybe_update_online(map_id, character_id) ++
_maybe_update_location(map_id, character_id) ++
_maybe_update_ship(map_id, character_id) ++
_maybe_update_alliance(map_id, character_id) ++
_maybe_update_corporation(map_id, character_id)
maybe_update_online(map_id, character_id) ++
maybe_update_location(map_id, character_id) ++
maybe_update_ship(map_id, character_id) ++
maybe_update_alliance(map_id, character_id) ++
maybe_update_corporation(map_id, character_id)
character_updates
|> Enum.filter(fn update -> update != :skip end)
@@ -521,7 +553,7 @@ defmodule WandererApp.Map.Server.Impl do
update
|> case do
{:character_location, location_info, old_location_info} ->
_update_location(
update_location(
character_id,
location_info,
old_location_info,
@@ -537,9 +569,25 @@ defmodule WandererApp.Map.Server.Impl do
:broadcast
{:character_alliance, _info} ->
WandererApp.Cache.insert_or_update(
"map_#{map_id}:invalidate_character_ids",
[character_id],
fn ids ->
[character_id | ids]
end
)
:broadcast
{:character_corporation, _info} ->
WandererApp.Cache.insert_or_update(
"map_#{map_id}:invalidate_character_ids",
[character_id],
fn ids ->
[character_id | ids]
end
)
:broadcast
_ ->
@@ -569,17 +617,21 @@ defmodule WandererApp.Map.Server.Impl do
Process.send_after(self(), :update_tracked_characters, @update_tracked_characters_timeout)
Task.start_link(fn ->
map_characters =
{:ok, map_tracked_character_ids} =
map_id
|> WandererApp.Map.get_map!()
|> Map.get(:characters, [])
|> WandererApp.MapCharacterSettingsRepo.get_tracked_by_map_all()
|> case do
{:ok, settings} -> {:ok, settings |> Enum.map(&Map.get(&1, :character_id))}
_ -> {:ok, []}
end
{:ok, tracked_characters} = WandererApp.Cache.lookup("tracked_characters", [])
map_tracked_characters =
map_characters |> Enum.filter(fn character -> character in tracked_characters end)
map_active_tracked_characters =
map_tracked_character_ids
|> Enum.filter(fn character -> character in tracked_characters end)
WandererApp.Cache.insert("maps:#{map_id}:tracked_characters", map_tracked_characters)
WandererApp.Cache.insert("maps:#{map_id}:tracked_characters", map_active_tracked_characters)
:ok
end)
@@ -590,29 +642,37 @@ defmodule WandererApp.Map.Server.Impl do
def handle_event(:update_presence, %{map_id: map_id} = state) do
Process.send_after(self(), :update_presence, @update_presence_timeout)
_update_presence(map_id)
update_presence(map_id)
state
end
def handle_event(:backup_state, state) do
Process.send_after(self(), :backup_state, @backup_state_timeout)
{:ok, _map_state} = state |> _save_map_state()
{:ok, _map_state} = state |> save_map_state()
state
end
def handle_event({:map_acl_updated, added_acls, removed_acls}, %{map: old_map} = state) do
{:ok, map} = WandererApp.MapRepo.get(old_map.map_id, [:acls])
def handle_event(
{:map_acl_updated, added_acls, removed_acls},
%{map_id: map_id, map: old_map} = state
) do
{:ok, map} =
WandererApp.MapRepo.get(map_id,
acls: [
:owner_id,
members: [:role, :eve_character_id, :eve_corporation_id, :eve_alliance_id]
]
)
track_acls(added_acls)
result =
[added_acls | removed_acls]
|> List.flatten()
(added_acls ++ removed_acls)
|> Task.async_stream(
fn acl_id ->
_update_acl(acl_id)
update_acl(acl_id)
end,
max_concurrency: 10,
timeout: :timer.seconds(15)
@@ -641,29 +701,45 @@ defmodule WandererApp.Map.Server.Impl do
}
error ->
@logger.error(
"Failed to update map #{old_map.map_id} acl: #{inspect(error, pretty: true)}"
)
@logger.error("Failed to update map #{map_id} acl: #{inspect(error, pretty: true)}")
acc
end
end
)
_broadcast_acl_updates({:ok, result})
map_update = %{acls: map.acls, scope: map.scope}
%{state | map: %{old_map | acls: map.acls, scope: map.scope}}
WandererApp.Map.update_map(map_id, map_update)
broadcast_acl_updates({:ok, result}, map_id)
%{state | map: Map.merge(old_map, map_update)}
end
def handle_event({:acl_updated, %{acl_id: acl_id}}, %{map: map} = state) do
def handle_event({:acl_updated, %{acl_id: acl_id}}, %{map_id: map_id, map: old_map} = state) do
{:ok, map} =
WandererApp.MapRepo.get(map_id,
acls: [
:owner_id,
members: [:role, :eve_character_id, :eve_corporation_id, :eve_alliance_id]
]
)
if map.acls |> Enum.map(& &1.id) |> Enum.member?(acl_id) do
map_update = %{acls: map.acls}
WandererApp.Map.update_map(map_id, map_update)
:ok =
acl_id
|> _update_acl()
|> _broadcast_acl_updates()
end
|> update_acl()
|> broadcast_acl_updates(map_id)
state
state
else
state
end
end
def handle_event(:cleanup_connections, %{map_id: map_id} = state) do
@@ -752,6 +828,76 @@ defmodule WandererApp.Map.Server.Impl do
state
end
def handle_event(:cleanup_characters, %{map_id: map_id, map: %{owner_id: owner_id}} = state) do
Process.send_after(self(), :cleanup_characters, @characters_cleanup_timeout)
{:ok, invalidate_character_ids} =
WandererApp.Cache.lookup(
"map_#{map_id}:invalidate_character_ids",
[]
)
invalidate_character_ids
|> Task.async_stream(
fn character_id ->
character_id
|> WandererApp.Character.get_character()
|> case do
{:ok, character} ->
acls =
map_id
|> WandererApp.Map.get_map!()
|> Map.get(:acls, [])
[character_permissions] =
WandererApp.Permissions.check_characters_access([character], acls)
map_permissions =
WandererApp.Permissions.get_map_permissions(
character_permissions,
owner_id,
[character_id]
)
case map_permissions do
%{view_system: false} ->
{:remove_character, character_id}
%{track_character: false} ->
{:remove_character, character_id}
_ ->
:ok
end
_ ->
:ok
end
end,
timeout: :timer.seconds(60),
max_concurrency: System.schedulers_online(),
on_timeout: :kill_task
)
|> Enum.each(fn
{:ok, {:remove_character, character_id}} ->
state |> remove_and_untrack_characters([character_id])
:ok
{:ok, _result} ->
:ok
{:error, reason} ->
@logger.error("Error in cleanup_characters: #{inspect(reason)}")
end)
WandererApp.Cache.insert(
"map_#{map_id}:invalidate_character_ids",
[]
)
state
end
def handle_event(:cleanup_systems, %{map_id: map_id} = state) do
Process.send_after(self(), :cleanup_systems, @systems_cleanup_timeout)
@@ -824,36 +970,59 @@ defmodule WandererApp.Map.Server.Impl do
end
def handle_event(msg, state) do
@logger.warning("Unhandled event: #{inspect(msg)}")
Logger.warning("Unhandled event: #{inspect(msg)}")
state
end
def broadcast!(map_id, event, payload \\ nil) do
if _can_broadcast?(map_id) do
if can_broadcast?(map_id) do
@pubsub_client.broadcast!(WandererApp.PubSub, map_id, %{event: event, payload: payload})
end
:ok
end
defp get_connection_mark_eol_time(map_id, connection_id) do
defp remove_and_untrack_characters(%{map_id: map_id} = state, character_ids) do
Logger.warning(fn ->
"Map #{map_id} - remove and untrack characters #{inspect(character_ids)}"
end)
map_id
|> _untrack_characters(character_ids)
map_id
|> WandererApp.MapCharacterSettingsRepo.get_tracked_by_map_filtered(character_ids)
|> case do
{:ok, settings} ->
settings
|> Enum.each(fn s ->
s |> WandererApp.MapCharacterSettingsRepo.untrack()
state |> remove_character(s.character_id)
end)
_ ->
:ok
end
end
defp get_connection_mark_eol_time(map_id, connection_id, default \\ DateTime.utc_now()) do
WandererApp.Cache.get("map_#{map_id}:conn_#{connection_id}:mark_eol_time")
|> case do
nil ->
DateTime.utc_now()
default
value ->
value
end
end
defp _can_broadcast?(map_id),
defp can_broadcast?(map_id),
do:
not WandererApp.Cache.lookup!("map_#{map_id}:importing", false) and
WandererApp.Cache.lookup!("map_#{map_id}:started", false)
defp _update_location(
defp update_location(
character_id,
location,
old_location,
@@ -881,7 +1050,7 @@ defmodule WandererApp.Map.Server.Impl do
end
end
defp _maybe_update_location(map_id, character_id) do
defp maybe_update_location(map_id, character_id) do
WandererApp.Cache.lookup!(
"character:#{character_id}:location_started",
false
@@ -932,7 +1101,7 @@ defmodule WandererApp.Map.Server.Impl do
end
end
defp _maybe_update_alliance(map_id, character_id) do
defp maybe_update_alliance(map_id, character_id) do
with {:ok, old_alliance_id} <-
WandererApp.Cache.lookup("map:#{map_id}:character:#{character_id}:alliance_id"),
{:ok, %{alliance_id: alliance_id}} <-
@@ -956,7 +1125,7 @@ defmodule WandererApp.Map.Server.Impl do
end
end
defp _maybe_update_corporation(map_id, character_id) do
defp maybe_update_corporation(map_id, character_id) do
with {:ok, old_corporation_id} <-
WandererApp.Cache.lookup("map:#{map_id}:character:#{character_id}:corporation_id"),
{:ok, %{corporation_id: corporation_id}} <-
@@ -980,7 +1149,7 @@ defmodule WandererApp.Map.Server.Impl do
end
end
defp _maybe_update_online(map_id, character_id) do
defp maybe_update_online(map_id, character_id) do
with {:ok, old_online} <-
WandererApp.Cache.lookup("map:#{map_id}:character:#{character_id}:online"),
{:ok, %{online: online}} <-
@@ -1004,7 +1173,7 @@ defmodule WandererApp.Map.Server.Impl do
end
end
defp _maybe_update_ship(map_id, character_id) do
defp maybe_update_ship(map_id, character_id) do
with {:ok, old_ship_type_id} <-
WandererApp.Cache.lookup("map:#{map_id}:character:#{character_id}:ship_type_id"),
{:ok, old_ship_name} <-
@@ -1036,7 +1205,7 @@ defmodule WandererApp.Map.Server.Impl do
end
end
defp _update_connection(
defp update_connection(
%{map_id: map_id} = state,
update_method,
attributes,
@@ -1052,7 +1221,7 @@ defmodule WandererApp.Map.Server.Impl do
solar_system_source_id,
solar_system_target_id
),
{:ok, update_map} <- _get_update_map(update, attributes),
{:ok, update_map} <- get_update_map(update, attributes),
:ok <-
WandererApp.Map.update_connection(
map_id,
@@ -1078,7 +1247,7 @@ defmodule WandererApp.Map.Server.Impl do
end
end
defp _update_system(
defp update_system(
%{map_id: map_id} = state,
update_method,
attributes,
@@ -1091,7 +1260,7 @@ defmodule WandererApp.Map.Server.Impl do
map_id,
update.solar_system_id
),
{:ok, update_map} <- _get_update_map(update, attributes) do
{:ok, update_map} <- get_update_map(update, attributes) do
{:ok, updated_system} =
apply(WandererApp.MapSystemRepo, update_method, [
system,
@@ -1102,7 +1271,7 @@ defmodule WandererApp.Map.Server.Impl do
callback_fn.(updated_system)
end
_update_map_system_last_activity(map_id, updated_system)
update_map_system_last_activity(map_id, updated_system)
state
else
@@ -1112,7 +1281,7 @@ defmodule WandererApp.Map.Server.Impl do
end
end
defp _get_update_map(update, attributes),
defp get_update_map(update, attributes),
do:
{:ok,
Enum.reduce(attributes, Map.new(), fn attribute, map ->
@@ -1218,7 +1387,7 @@ defmodule WandererApp.Map.Server.Impl do
state
end
defp _save_map_state(%{map_id: map_id} = _state) do
defp save_map_state(%{map_id: map_id} = _state) do
systems_last_activity =
map_id
|> WandererApp.Map.list_systems!()
@@ -1252,7 +1421,7 @@ defmodule WandererApp.Map.Server.Impl do
})
end
defp _maybe_stop_rtree(%{rtree_name: rtree_name} = state) do
defp maybe_stop_rtree(%{rtree_name: rtree_name} = state) do
case Process.whereis(rtree_name) do
nil ->
:ok
@@ -1264,7 +1433,7 @@ defmodule WandererApp.Map.Server.Impl do
state
end
defp _init_map_cache(%__MODULE__{map_id: map_id} = state) do
defp init_map_cache(%__MODULE__{map_id: map_id} = state) do
case WandererApp.Api.MapState.by_map_id(map_id) do
{:ok,
%{
@@ -1296,9 +1465,9 @@ defmodule WandererApp.Map.Server.Impl do
end
end
defp _init_map(
defp init_map(
state,
%{characters: characters} = initial_map,
%{id: map_id, characters: characters} = initial_map,
subscription_settings,
systems,
connections
@@ -1319,12 +1488,19 @@ defmodule WandererApp.Map.Server.Impl do
map_options |> Map.get("store_custom_labels", "false") |> String.to_existing_atom()
]
character_ids =
map_id
|> WandererApp.Map.get_map!()
|> Map.get(:characters, [])
WandererApp.Cache.insert("map_#{map_id}:invalidate_character_ids", character_ids)
%{state | map: map, map_opts: map_opts}
end
defp _init_map_systems(state, [] = _systems), do: state
defp init_map_systems(state, [] = _systems), do: state
defp _init_map_systems(%__MODULE__{map_id: map_id, rtree_name: rtree_name} = state, systems) do
defp init_map_systems(%__MODULE__{map_id: map_id, rtree_name: rtree_name} = state, systems) do
systems
|> Enum.each(fn %{id: system_id, solar_system_id: solar_system_id} = system ->
@ddrt.insert(
@@ -1342,7 +1518,7 @@ defmodule WandererApp.Map.Server.Impl do
state
end
def _maybe_import_systems(state, %{"systems" => systems} = _settings, user_id, character_id) do
def maybe_import_systems(state, %{"systems" => systems} = _settings, user_id, character_id) do
state =
systems
|> Enum.reduce(state, fn %{
@@ -1386,7 +1562,7 @@ defmodule WandererApp.Map.Server.Impl do
|> delete_systems(removed_system_ids, user_id, character_id)
end
def _maybe_import_connections(state, %{"connections" => connections} = _settings, _user_id) do
def maybe_import_connections(state, %{"connections" => connections} = _settings, _user_id) do
connections
|> Enum.reduce(state, fn %{
"source" => source,
@@ -1422,7 +1598,7 @@ defmodule WandererApp.Map.Server.Impl do
end)
end
def _maybe_import_hubs(state, %{"hubs" => hubs} = _settings, _user_id) do
def maybe_import_hubs(state, %{"hubs" => hubs} = _settings, _user_id) do
hubs
|> Enum.reduce(state, fn hub, acc ->
solar_system_id = hub |> String.to_integer()
@@ -1432,7 +1608,7 @@ defmodule WandererApp.Map.Server.Impl do
end)
end
defp _update_map_system_last_activity(
defp update_map_system_last_activity(
map_id,
updated_system
) do
@@ -1526,7 +1702,7 @@ defmodule WandererApp.Map.Server.Impl do
end
end
defp _update_presence(map_id) do
defp update_presence(map_id) do
case WandererApp.Cache.lookup!("map_#{map_id}:started", false) and
WandererApp.Cache.get_and_remove!("map_#{map_id}:presence_updated", false) do
true ->
@@ -1544,7 +1720,7 @@ defmodule WandererApp.Map.Server.Impl do
not Enum.member?(presence_character_ids, character_id)
end)
_track_characters(presence_character_ids, map_id)
track_characters(presence_character_ids, map_id)
map_id
|> _untrack_characters(not_present_character_ids)
@@ -1566,31 +1742,29 @@ defmodule WandererApp.Map.Server.Impl do
defp track_acls([]), do: :ok
defp track_acls([acl_id | rest]) do
_track_acl(acl_id)
track_acl(acl_id)
track_acls(rest)
end
defp _track_acl(acl_id),
defp track_acl(acl_id),
do: @pubsub_client.subscribe(WandererApp.PubSub, "acls:#{acl_id}")
defp track_characters([], _map_id), do: :ok
defp track_characters([character_id | rest], map_id) do
track_character(character_id, map_id)
track_characters(rest, map_id)
end
defp track_character(character_id, map_id),
do:
WandererApp.PubSub
|> @pubsub_client.subscribe("acls:#{acl_id}")
defp _track_characters([], _map_id), do: :ok
defp _track_characters([character_id | rest], map_id) do
_track_character(character_id, map_id)
_track_characters(rest, map_id)
end
defp _track_character(character_id, map_id) do
WandererApp.Character.TrackerManager.update_track_settings(character_id, %{
map_id: map_id,
track: true,
track_online: true,
track_location: true,
track_ship: true
})
end
WandererApp.Character.TrackerManager.update_track_settings(character_id, %{
map_id: map_id,
track: true,
track_online: true,
track_location: true,
track_ship: true
})
defp _update_character(map_id, character_id) do
{:ok, character} = WandererApp.Character.get_character(character_id)
@@ -1773,13 +1947,14 @@ defmodule WandererApp.Map.Server.Impl do
|> WandererApp.Map.find_system_by_location(old_location)
|> WandererApp.Map.PositionCalculator.get_new_system_position(rtree_name, opts)}
defp _broadcast_acl_updates(
defp broadcast_acl_updates(
{:ok,
%{
eve_character_ids: eve_character_ids,
eve_corporation_ids: eve_corporation_ids,
eve_alliance_ids: eve_alliance_ids
}}
}},
map_id
) do
eve_character_ids
|> Enum.uniq()
@@ -1811,12 +1986,19 @@ defmodule WandererApp.Map.Server.Impl do
)
end)
character_ids =
map_id
|> WandererApp.Map.get_map!()
|> Map.get(:characters, [])
WandererApp.Cache.insert("map_#{map_id}:invalidate_character_ids", character_ids)
:ok
end
defp _broadcast_acl_updates(_), do: :ok
defp broadcast_acl_updates(_, _map_id), do: :ok
defp _update_acl(acl_id) do
defp update_acl(acl_id) do
{:ok, %{owner: owner, members: members}} =
WandererApp.AccessListRepo.get(acl_id, [:owner, :members])

View File

@@ -87,4 +87,113 @@ defmodule WandererApp.Permissions do
delete_map: check_permission(user_permissions, @delete_map)
}
end
def check_characters_access(characters, acls) do
character_ids = characters |> Enum.map(& &1.id)
character_eve_ids = characters |> Enum.map(& &1.eve_id)
character_corporation_ids =
characters |> Enum.map(& &1.corporation_id) |> Enum.map(&to_string/1)
character_alliance_ids = characters |> Enum.map(& &1.alliance_id) |> Enum.map(&to_string/1)
result =
acls
|> Enum.reduce([0, 0], fn acl, acc ->
is_owner? = acl.owner_id in character_ids
is_character_member? =
acl.members |> Enum.any?(fn member -> member.eve_character_id in character_eve_ids end)
is_corporation_member? =
acl.members
|> Enum.any?(fn member -> member.eve_corporation_id in character_corporation_ids end)
is_alliance_member? =
acl.members
|> Enum.any?(fn member -> member.eve_alliance_id in character_alliance_ids end)
if is_owner? || is_character_member? || is_corporation_member? || is_alliance_member? do
case acc do
[_, -1] ->
[-1, -1]
[-1, char_acc] ->
char_acl_mask =
acl.members
|> Enum.filter(fn member ->
member.eve_character_id in character_eve_ids
end)
|> Enum.reduce(0, fn member, acc ->
case acc do
-1 -> -1
_ -> calc_role_mask(member.role, acc)
end
end)
char_acc =
case char_acl_mask do
-1 -> -1
_ -> char_acc ||| char_acl_mask
end
[-1, char_acc]
[any_acc, char_acc] ->
any_acl_mask =
acl.members
|> Enum.filter(fn member ->
member.eve_character_id in character_eve_ids ||
member.eve_corporation_id in character_corporation_ids ||
member.eve_alliance_id in character_alliance_ids
end)
|> Enum.reduce(0, fn member, acc ->
case acc do
-1 -> -1
_ -> calc_role_mask(member.role, acc)
end
end)
char_acl_mask =
acl.members
|> Enum.filter(fn member ->
member.eve_character_id in character_eve_ids
end)
|> Enum.reduce(0, fn member, acc ->
case acc do
-1 -> -1
_ -> calc_role_mask(member.role, acc)
end
end)
any_acc =
case any_acl_mask do
-1 -> -1
_ -> any_acc ||| any_acl_mask
end
char_acc =
case char_acl_mask do
-1 -> -1
_ -> char_acc ||| char_acl_mask
end
[any_acc, char_acc]
end
else
acc
end
end)
case result do
[_, -1] ->
[-1]
[-1, char_acc] ->
[char_acc]
[any_acc, _char_acc] ->
[any_acc]
end
end
end

View File

@@ -3,4 +3,23 @@ defmodule WandererApp.MapCharacterSettingsRepo do
def create(settings),
do: WandererApp.Api.MapCharacterSettings.create(settings)
def get_tracked_by_map_filtered(map_id, character_ids),
do:
WandererApp.Api.MapCharacterSettings.tracked_by_map_filtered(%{
map_id: map_id,
character_ids: character_ids
})
def get_all_by_map(map_id),
do: WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: map_id})
def get_tracked_by_map_all(map_id),
do: WandererApp.Api.MapCharacterSettings.tracked_by_map_all(%{map_id: map_id})
def track(settings), do: settings |> WandererApp.Api.MapCharacterSettings.track()
def untrack(settings), do: settings |> WandererApp.Api.MapCharacterSettings.untrack()
def track!(settings), do: settings |> WandererApp.Api.MapCharacterSettings.track!()
def untrack!(settings), do: settings |> WandererApp.Api.MapCharacterSettings.untrack!()
end

View File

@@ -41,7 +41,7 @@ defmodule WandererAppWeb.CharactersTrackingLive do
selected_map = socket.assigns.maps |> Enum.find(&(&1.slug == map_slug))
{:ok, character_settings} =
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: selected_map.id}) do
case WandererApp.MapCharacterSettingsRepo.get_all_by_map(selected_map.id) do
{:ok, settings} ->
{:ok, settings}
@@ -83,7 +83,7 @@ defmodule WandererAppWeb.CharactersTrackingLive do
case character_settings |> Enum.find(&(&1.character_id == character_id)) do
nil ->
WandererApp.Api.MapCharacterSettings.create(%{
WandererApp.MapCharacterSettingsRepo.create(%{
character_id: character_id,
map_id: selected_map.id,
tracked: true
@@ -95,18 +95,18 @@ defmodule WandererAppWeb.CharactersTrackingLive do
case character_setting.tracked do
true ->
character_setting
|> WandererApp.Api.MapCharacterSettings.untrack!()
|> WandererApp.MapCharacterSettingsRepo.untrack!()
_ ->
character_setting
|> WandererApp.Api.MapCharacterSettings.track!()
|> WandererApp.MapCharacterSettingsRepo.track!()
end
end
%{result: characters} = socket.assigns.characters
{:ok, character_settings} =
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: selected_map.id}) do
case WandererApp.MapCharacterSettingsRepo.get_all_by_map(selected_map.id) do
{:ok, settings} -> {:ok, settings}
_ -> {:ok, []}
end

View File

@@ -75,7 +75,7 @@ defmodule WandererAppWeb.MapCharactersEventHandler do
} = socket
) do
{:ok, character_settings} =
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: map_id}) do
case WandererApp.MapCharacterSettingsRepo.get_all_by_map(map_id) do
{:ok, settings} -> {:ok, settings}
_ -> {:ok, []}
end
@@ -132,7 +132,7 @@ defmodule WandererAppWeb.MapCharactersEventHandler do
case character_settings |> Enum.find(&(&1.character_id == character_id)) do
nil ->
{:ok, map_character_settings} =
WandererApp.Api.MapCharacterSettings.create(%{
WandererApp.MapCharacterSettingsRepo.create(%{
character_id: character_id,
map_id: map_id,
tracked: true
@@ -150,7 +150,7 @@ defmodule WandererAppWeb.MapCharactersEventHandler do
true ->
{:ok, map_character_settings} =
character_setting
|> WandererApp.Api.MapCharacterSettings.untrack()
|> WandererApp.MapCharacterSettingsRepo.untrack()
character = map_character_settings |> Ash.load!(:character) |> Map.get(:character)
@@ -166,7 +166,7 @@ defmodule WandererAppWeb.MapCharactersEventHandler do
_ ->
{:ok, map_character_settings} =
character_setting
|> WandererApp.Api.MapCharacterSettings.track()
|> WandererApp.MapCharacterSettingsRepo.track()
character = map_character_settings |> Ash.load!(:character) |> Map.get(:character)
@@ -184,7 +184,7 @@ defmodule WandererAppWeb.MapCharactersEventHandler do
user_character_eve_ids = map_characters |> Enum.map(& &1.eve_id)
{:ok, character_settings} =
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: map_id}) do
case WandererApp.MapCharacterSettingsRepo.get_all_by_map(map_id) do
{:ok, settings} -> {:ok, settings}
_ -> {:ok, []}
end
@@ -225,10 +225,10 @@ defmodule WandererAppWeb.MapCharactersEventHandler do
def has_tracked_characters?(_user_characters), do: true
def get_tracked_map_characters(map_id, current_user) do
case WandererApp.Api.MapCharacterSettings.tracked_by_map(%{
map_id: map_id,
character_ids: current_user.characters |> Enum.map(& &1.id)
}) do
case WandererApp.MapCharacterSettingsRepo.get_tracked_by_map_filtered(
map_id,
current_user.characters |> Enum.map(& &1.id)
) do
{:ok, settings} ->
{:ok,
settings

View File

@@ -162,6 +162,16 @@ defmodule WandererAppWeb.MapConnectionsEventHandler do
{:noreply, socket}
end
def handle_ui_event(
"get_connection_info",
%{"from" => from, "to" => to} = _event,
%{assigns: %{map_id: map_id}} = socket
) do
{:ok, info} = map_id |> get_connection_info(from, to)
{:reply, info, socket}
end
def handle_ui_event(
"get_passages",
%{"from" => from, "to" => to} = _event,
@@ -194,4 +204,19 @@ defmodule WandererAppWeb.MapConnectionsEventHandler do
{:ok, %{passages: passages}}
end
defp get_connection_info(map_id, from, to) do
map_id
|> WandererApp.Map.Server.get_connection_info(%{
solar_system_source_id: "#{from}" |> String.to_integer(),
solar_system_target_id: "#{to}" |> String.to_integer()
})
|> case do
{:ok, info} ->
{:ok, info}
_ ->
{:ok, %{}}
end
end
end

View File

@@ -41,10 +41,10 @@ defmodule WandererAppWeb.MapCoreEventHandler do
%{track_character: track_character} ->
{:ok, map_characters} =
case WandererApp.Api.MapCharacterSettings.tracked_by_map(%{
map_id: map_id,
character_ids: current_user.characters |> Enum.map(& &1.id)
}) do
case WandererApp.MapCharacterSettingsRepo.get_tracked_by_map_filtered(
map_id,
current_user.characters |> Enum.map(& &1.id)
) do
{:ok, settings} ->
{:ok,
settings
@@ -258,7 +258,7 @@ defmodule WandererAppWeb.MapCoreEventHandler do
)
{:ok, character_settings} =
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: map_id}) do
case WandererApp.MapCharacterSettingsRepo.get_all_by_map(map_id) do
{:ok, settings} -> {:ok, settings}
_ -> {:ok, []}
end
@@ -511,10 +511,10 @@ defmodule WandererAppWeb.MapCoreEventHandler do
end
defp get_tracked_map_characters(map_id, current_user) do
case WandererApp.Api.MapCharacterSettings.tracked_by_map(%{
map_id: map_id,
character_ids: current_user.characters |> Enum.map(& &1.id)
}) do
case WandererApp.MapCharacterSettingsRepo.get_tracked_by_map_filtered(
map_id,
current_user.characters |> Enum.map(& &1.id)
) do
{:ok, settings} ->
{:ok,
settings

View File

@@ -225,6 +225,7 @@ defmodule WandererAppWeb.MapSignaturesEventHandler do
|> Enum.filter(fn s -> s.eve_id == signature_eve_id end)
|> Enum.each(fn s ->
s
|> WandererApp.Api.MapSystemSignature.update_group!(%{group: "Wormhole"})
|> WandererApp.Api.MapSystemSignature.update_linked_system(%{
linked_system_id: solar_system_target
})

View File

@@ -61,6 +61,7 @@ defmodule WandererAppWeb.MapEventHandler do
@map_connection_ui_events [
"manual_add_connection",
"manual_delete_connection",
"get_connection_info",
"get_passages",
"update_connection_time_status",
"update_connection_mass_status",
@@ -153,7 +154,7 @@ defmodule WandererAppWeb.MapEventHandler do
def handle_ui_event(event, body, socket)
when event in @map_characters_ui_events,
do: MapSystemsEventHandler.handle_ui_event(event, body, socket)
do: MapCharactersEventHandler.handle_ui_event(event, body, socket)
def handle_ui_event(event, body, socket)
when event in @map_system_ui_events,

View File

@@ -848,9 +848,9 @@ defmodule WandererAppWeb.MapsLive do
|> Enum.map(fn acl -> acl |> Ash.load!(:members) end)
{:ok, characters_count} =
case WandererApp.Api.MapCharacterSettings.tracked_by_map_all(%{
map_id: map.id
}) do
map.id
|> WandererApp.MapCharacterSettingsRepo.get_tracked_by_map_all()
|> case do
{:ok, settings} ->
{:ok,
settings

View File

@@ -2,7 +2,7 @@ defmodule WandererApp.MixProject do
use Mix.Project
@source_url "https://github.com/wanderer-industries/wanderer"
@version "1.14.0"
@version "1.16.0"
def project do
[

View File

@@ -1,54 +0,0 @@
defmodule WandererApp.Repo.Migrations.InstallAshFunctionsExtension420240922090427 do
@moduledoc """
Installs any extensions that are mentioned in the repo's `installed_extensions/0` callback
This file was autogenerated with `mix ash_postgres.generate_migrations`
"""
use Ecto.Migration
def up do
execute("""
CREATE OR REPLACE FUNCTION uuid_generate_v7()
RETURNS UUID
AS $$
DECLARE
timestamp TIMESTAMPTZ;
microseconds INT;
BEGIN
timestamp = clock_timestamp();
microseconds = (cast(extract(microseconds FROM timestamp)::INT - (floor(extract(milliseconds FROM timestamp))::INT * 1000) AS DOUBLE PRECISION) * 4.096)::INT;
RETURN encode(
set_byte(
set_byte(
overlay(uuid_send(gen_random_uuid()) placing substring(int8send(floor(extract(epoch FROM timestamp) * 1000)::BIGINT) FROM 3) FROM 1 FOR 6
),
6, (b'0111' || (microseconds >> 8)::bit(4))::bit(8)::int
),
7, microseconds::bit(8)::int
),
'hex')::UUID;
END
$$
LANGUAGE PLPGSQL
VOLATILE;
""")
execute("""
CREATE OR REPLACE FUNCTION timestamp_from_uuid_v7(_uuid uuid)
RETURNS TIMESTAMP WITHOUT TIME ZONE
AS $$
SELECT to_timestamp(('x0000' || substr(_uuid::TEXT, 1, 8) || substr(_uuid::TEXT, 10, 4))::BIT(64)::BIGINT::NUMERIC / 1000);
$$
LANGUAGE SQL
IMMUTABLE PARALLEL SAFE STRICT;
""")
end
def down do
# Uncomment this if you actually want to uninstall the extensions
# when this migration is rolled back:
execute("DROP FUNCTION IF EXISTS uuid_generate_v7(), timestamp_from_uuid_v7(uuid)")
end
end