Skip to content

Commit

Permalink
allow killing of running sessions via external restrictions file
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Aug 13, 2023
1 parent c67dc69 commit 8730a79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ faucet-store.*
faucet-stats.log
faucet-events.log
faucet-pid.txt
tmp*
11 changes: 10 additions & 1 deletion src/modules/ipinfo/IPInfoModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ export class IPInfoModule extends BaseModule<IIPInfoConfig> {
sessionRestriction = this.getSessionRestriction(session);
session.setSessionModuleRef("ipinfo.restriction.time", Math.floor((new Date()).getTime() / 1000));
session.setSessionModuleRef("ipinfo.restriction.data", sessionRestriction);
if(sessionRestriction.blocked) {
let blockReason = "IP Blocked: " + sessionRestriction.messages.map((msg) => msg.text).join(", ");
if(sessionRestriction.blocked == "kill") {
await session.setSessionFailed("RESTRICTION", blockReason);
} else {
await session.completeSession();
}
return;
}
}
else
sessionRestriction = session.getSessionModuleRef("ipinfo.restriction.data");
Expand Down Expand Up @@ -175,7 +184,7 @@ export class IPInfoModule extends BaseModule<IIPInfoConfig> {
return restriction;
}

public getSessionRestriction(session: FaucetSession): IIPInfoRestriction {
private getSessionRestriction(session: FaucetSession): IIPInfoRestriction {
let restriction: IIPInfoRestriction = {
reward: 100,
messages: [],
Expand Down
9 changes: 6 additions & 3 deletions src/session/FaucetSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ export class FaucetSession {
public setDropAmount(amount: bigint) {
if(this.dropAmount !== -1n)
return;
if(this.status === FaucetSessionStatus.CLAIMING || this.status === FaucetSessionStatus.FINISHED || this.status === FaucetSessionStatus.FAILED)
return;
if(this.getSessionStatus() === FaucetSessionStatus.CLAIMING || this.getSessionStatus() === FaucetSessionStatus.FINISHED || this.getSessionStatus() === FaucetSessionStatus.FAILED)
return 0n;
this.dropAmount = 0n;
if(amount > 0n)
this.addReward(amount);
Expand All @@ -357,7 +357,7 @@ export class FaucetSession {
}

public async addReward(amount: bigint): Promise<bigint> {
if(this.status === FaucetSessionStatus.CLAIMING || this.status === FaucetSessionStatus.FINISHED || this.status === FaucetSessionStatus.FAILED)
if(this.getSessionStatus() === FaucetSessionStatus.CLAIMING || this.getSessionStatus() === FaucetSessionStatus.FINISHED || this.getSessionStatus() === FaucetSessionStatus.FAILED)
return 0n;

let rewardFactors: ISessionRewardFactor[] = [];
Expand All @@ -374,6 +374,9 @@ export class FaucetSession {
let rewardAmount = amount * BigInt(Math.floor(rewardFactor * 100000)) / 100000n;
ServiceManager.GetService(ModuleManager).processActionHooks([], ModuleHookAction.SessionRewarded, [this, rewardAmount, rewardFactors]);

if(this.getSessionStatus() === FaucetSessionStatus.CLAIMING || this.getSessionStatus() === FaucetSessionStatus.FINISHED || this.getSessionStatus() === FaucetSessionStatus.FAILED)
return 0n;

if(this.dropAmount === -1n)
this.dropAmount = 0n;
this.dropAmount += rewardAmount;
Expand Down

0 comments on commit 8730a79

Please sign in to comment.