Skip to content

Commit

Permalink
Merge branch 'development' into more-perf-indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele authored Oct 31, 2024
2 parents cd3775f + db44f30 commit 81c5fcf
Show file tree
Hide file tree
Showing 26 changed files with 948 additions and 71 deletions.
2 changes: 1 addition & 1 deletion packages/app-api/src/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class UserController {
}

@Get('/me')
@UseBefore(AuthService.getAuthMiddleware([]))
@UseBefore(AuthService.getAuthMiddleware([], false))
@ResponseSchema(MeOutoutDTOAPI)
@OpenAPI({
summary: 'Get the current logged in user',
Expand Down
18 changes: 16 additions & 2 deletions packages/app-api/src/service/AuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Routes, RESTGetAPICurrentUserGuildsResult } from 'discord-api-types/v10
import oauth from 'passport-oauth2';
import { DiscordService } from './DiscordService.js';
import { domainStateMiddleware } from '../middlewares/domainStateMiddleware.js';
import { DomainService } from './DomainService.js';
import { DOMAIN_STATES, DomainService } from './DomainService.js';

interface DiscordUserInfo {
id: string;
Expand Down Expand Up @@ -193,7 +193,15 @@ export class AuthService extends DomainScoped {
log.warn(`No domain found for identity ${identity.id}`);
throw new errors.UnauthorizedError();
}
domainId = domains[0].id;
// Find the first active domain
domainId = domains.find((d) => d.state === DOMAIN_STATES.ACTIVE)?.id;

if (!domainId && domains.length) {
log.warn(
`No active domain found for identity (but domains found: ${domains.map((d) => ({ id: d.id, state: d.state })).join(',')})`,
);
throw new errors.BadRequestError('Domain is disabled. Please contact support.');
}

// Set the domain cookie
if (req.res?.cookie)
Expand All @@ -215,6 +223,9 @@ export class AuthService extends DomainScoped {
} catch (error) {
// Not an ory session, throw a sanitized error
log.warn(error);
// If we explicitly throw a BadRequestError, we want to pass it through
// So the client gets a meaningful error message
if (error instanceof errors.BadRequestError) throw error;
throw new errors.UnauthorizedError();
}
}
Expand Down Expand Up @@ -250,6 +261,9 @@ export class AuthService extends DomainScoped {
if (domainStateCheck) return domainStateMiddleware(req, _res, next);
return next();
} catch (error) {
// If we explicitly throw a BadRequestError, we want to pass it through
// So the client gets a meaningful error message
if (error instanceof errors.BadRequestError) return next(error);
log.error('Unexpected error in auth middleware', error);
return next(new errors.ForbiddenError());
}
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - 03616c08df7ea6ffdaf381a9d38509a21fc1d5ff
* The version of the OpenAPI document: development - 7216ffc45f80fa8a42b6b7af120a0e6bb69a2064
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - 03616c08df7ea6ffdaf381a9d38509a21fc1d5ff
* The version of the OpenAPI document: development - 7216ffc45f80fa8a42b6b7af120a0e6bb69a2064
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - 03616c08df7ea6ffdaf381a9d38509a21fc1d5ff
* The version of the OpenAPI document: development - 7216ffc45f80fa8a42b6b7af120a0e6bb69a2064
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - 03616c08df7ea6ffdaf381a9d38509a21fc1d5ff
* The version of the OpenAPI document: development - 7216ffc45f80fa8a42b6b7af120a0e6bb69a2064
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - 03616c08df7ea6ffdaf381a9d38509a21fc1d5ff
* The version of the OpenAPI document: development - 7216ffc45f80fa8a42b6b7af120a0e6bb69a2064
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as topojson from 'topojson-client';
import topology from './world.json';
import { Graticule, Mercator } from '@visx/geo';
import { scaleLinear } from '@visx/scale';
import { ParentSize } from '@visx/responsive';

import { getDefaultTooltipStyles, InnerChartProps, Margin } from '../util';
Expand All @@ -9,7 +10,6 @@ import { useTooltip, Tooltip } from '@visx/tooltip';
import { Zoom } from '@visx/zoom';
import { useCallback } from 'react';
import { localPoint } from '@visx/event';
import { shade } from 'polished';
import { ZoomControls } from '../ZoomControls';
import { alpha2ToAlpha3 } from './iso3166-alpha2-to-alpha3';

Expand Down Expand Up @@ -88,6 +88,11 @@ const Chart = <T,>({
const centerY = height / 2 + 150;
const scale = (width / 1000) * 100;

const colorScale = scaleLinear({
domain: [Math.min(...data.map((d) => yAccessor(d))), Math.max(...data.map((d) => yAccessor(d)))],
range: [theme.colors.backgroundAlt, theme.colors.primary],
});

const handleTooltip = useCallback(
(event: React.TouchEvent<SVGPathElement> | React.MouseEvent<SVGPathElement>, countryData: T | undefined) => {
const eventSvgCoords = localPoint(event);
Expand Down Expand Up @@ -139,13 +144,15 @@ const Chart = <T,>({
return xAccessor(d) === feature.id;
});

const fillColor = countryData ? colorScale(yAccessor(countryData)) : theme.colors.backgroundAlt;

return (
<path
key={`map-feature-${i}`}
d={path || ''}
stroke={countryData ? theme.colors.primary : theme.colors.backgroundAccent}
strokeWidth={countryData ? 1 : 0.5}
fill={countryData ? shade(0.5, theme.colors.primary) : theme.colors.backgroundAlt}
stroke={theme.colors.backgroundAccent}
strokeWidth={0.35}
fill={fillColor}
onMouseLeave={hideTooltip}
onMouseMove={(e) => handleTooltip(e, countryData)}
onTouchStart={(e) => handleTooltip(e, countryData)}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
58 changes: 57 additions & 1 deletion packages/web-docs/docs/modules/chatBridge.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,60 @@ export function Module() {
<Module />

---
{/* END AUTO-GENERATED CONTENT */}
{/* END AUTO-GENERATED CONTENT */}

## Step-by-step guide

### Step 1: Connect Discord in Global Settings
- Go to **Global Game Server Settings > Discord**
![ChatBridge Settings](../../assets/images/chatBridge/chatBridge_1_Takaro_settings.png)
- Click **Add connection**
- Complete Discord authorization to allow Takaro to:
- Access your username, avatar and banner
- Access your email address
- Know what servers you're in
![ChatBridge Settings](../../assets/images/chatBridge/chatbridge_2_Takaro_Discord.png)
### Step 2: Add Takaro Bot to Your Server
1. Click **Invite Discord bot** in the same Global Settings page
2. Select your server from the dropdown
3. Authorize the bot permissions:
- Add a bot to a server
- Create commands
![ChatBridge Settings](../../assets/images/chatBridge/chatBridge_3_Discord_bot.png)
### Step 3: Enable Your Discord Server
1. Still in Global Settings, find the "Guilds" section
2. Toggle ON your Discord server (e.g., "Limon's server")

### Step 4: Get Discord Channel ID

1. Go to your Discord server
2. Right-click on the channel you want to use for the chat bridge
3. Click **Copy Channel ID** at the bottom of the menu
- If you don't see this option, make sure Developer Mode is enabled in Discord settings
![ChatBridge Settings](../../assets/images/chatBridge/chatBridge_4_DiscordChannelID.png)
### Step 5: Install and Configure ChatBridge

1. Go to your game server's modules
2. Find and click "Install" on the ChatBridge module
3. Configure the settings:

#### User Config

- **Send Player Connected**: Toggle to announce joins
- **Send Player Disconnected**: Toggle to announce leaves
- **Only Global Chat**: Toggle to filter private/team chat

#### System Config

- Enable the module
- Set up Hooks:
- **DiscordToGame**: Enable and paste your copied Discord Channel ID
- **PlayerDisconnected**: Enable to track disconnects
- **GameToDiscord**: Enable game-to-Discord chat
- **PlayerConnected**: Enable to track connects

![ChatBridge Settings](../../assets/images/chatBridge/chatBridge_5_Module_Channelid.png)

### Step 6: Save Configuration

- Click "Install module" to save all settings
148 changes: 147 additions & 1 deletion packages/web-docs/docs/modules/economyUtils.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,150 @@ export function Module() {
<Module />

---
{/* END AUTO-GENERATED CONTENT */}
{/* END AUTO-GENERATED CONTENT */}

## Features
- Balance checking and transfers
- Administrative currency controls
- Automated kill rewards
- Shop integration
- Currency leaderboard

## Permissions

### ECONOMY_UTILS_MANAGE_CURRENCY
- Allows granting and revoking currency
- Typically for admins/moderators

### ZOMBIE_KILL_REWARD_OVERRIDE
- Overrides default kill reward amount
- Can set different amounts per role
- Count value determines reward amount

## Variables

### Currency Related
- `lastZombieKillReward`
- Tracks last reward distribution time
- Used by automatic reward system
- Scoped to gameserver and module

### Shop Related
- `lottery_tickets_bought`
- Stores ticket quantity
- Format: `{ "amount": number }`
- Scoped to player, gameserver, and module

### Transfer Related
- `confirmTransfer`
- Stores pending transfer details
- Temporary storage for large transfers

## Automatic Rewards

### Kill Rewards System
- Auto-processes every 5 minutes
- Awards currency for entity kills
- Default amount configurable
- Role-based override example:
```
Default Player: 1 coin per kill
VIP Role: 3 coins per kill
Elite Role: 5 coins per kill
```

### Setting Up Role Rewards
1. Navigate to Roles
2. Enable ZOMBIE_KILL_REWARD_OVERRIDE
3. Set count value for reward amount
4. Assign role to players

## Commands & Usage Examples

### Basic Currency Commands
```
# Check your balance
/balance
> balance: 500 coins
# View richest players
/topcurrency
> Richest players:
> 1. PlayerOne - 10000 coins
> 2. PlayerTwo - 8500 coins
> [...]
```

### Transfer System
```
# Simple transfer
/transfer John 100
> You successfully transferred 100 coins to John
> (John receives: You received 100 coins from PlayerName)
# Large transfer requiring confirmation
/transfer Jane 1000
> You are about to send 1000 coins to Jane. (Please confirm by typing /confirmtransfer)
/confirmtransfer
> You successfully transferred 1000 coins to Jane
```

### Shop System
```
# Browse shop
/shop
> Available items:
> 1. Diamond Sword - 500 coins
> 2. Golden Apple - 100 coins
> [...]
# View item details
/shop 1 2
> Golden Apple - 100 coins
> Restores health instantly
> Type '/shop 1 2 buy' to purchase
# Purchase item
/shop 1 2 buy
> You have purchased Golden Apple for 100 coins
# Claim purchased items
/claim
> Claimed all pending orders: 3 items
```

### Admin Commands
```
# Grant currency
/grantcurrency PlayerName 500
> You successfully granted 500 coins to PlayerName
# Remove currency
/revokecurrency PlayerName 200
> You successfully revoked 200 coins from PlayerName's balance
```


## Best Practices

### Economy Management
- Set reasonable transfer confirmation thresholds
- Monitor currency circulation
- Adjust reward values based on server activity

### Role Configuration
- Create clear reward tiers
- Balance rewards across different roles
- Consider server economy when setting values
## Troubleshooting
1. Transfer Failed
- Check sender's balance
- Verify player names
- Confirm if confirmation needed
- Check for pending transfer variable

2. Rewards Not Processing
- Verify kill events recording
- Check role permissions
- Confirm cron job running
- Check lastZombieKillReward timestamp
Loading

0 comments on commit 81c5fcf

Please sign in to comment.