Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Commit

Permalink
Added some rules, participants must be online
Browse files Browse the repository at this point in the history
  • Loading branch information
maxammann committed Nov 14, 2014
1 parent f22d54e commit 64f66f2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ protected void configure() {
addRule("rivals.list", 0x60);
addRule("rivals.add", 0x61);
addRule("rivals.remove", 0x62);

addRule("vote.join", 0x70);
addRule("vote.allies", 0x71);
addRule("vote.rivals", 0x72);
}

private void addRule(String rule, int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.catharos.lib.core.command.CommandContext;
import net.catharos.lib.core.command.Executor;
import net.catharos.lib.core.command.reflect.*;
import net.catharos.lib.core.i18n.Dictionary;
import net.catharos.lib.shank.logging.InjectLogger;
import net.catharos.societies.commands.RuleStep;
import net.catharos.societies.member.SocietyMember;
Expand All @@ -36,16 +35,14 @@ public class InviteCommand implements Executor<Member> {

public static final String FAILED = "Invite failed! %s";

private final Dictionary<String> dictionary;
private final RequestFactory<Choices> requests;
private final int maxSize;

@InjectLogger
private Logger logger;

@Inject
public InviteCommand(Dictionary<String> dictionary, RequestFactory<Choices> requests, @Named("society.max-size") int maxSize) {
this.dictionary = dictionary;
public InviteCommand( RequestFactory<Choices> requests, @Named("society.max-size") int maxSize) {
this.requests = requests;
this.maxSize = maxSize;
}
Expand All @@ -64,6 +61,11 @@ public void execute(CommandContext<Member> ctx, final Member sender) {
return;
}

if (!target.isAvailable()) {
sender.send("target-member.not-available");
return;
}

Request<Choices> request = requests.create(sender, new SingleInvolved(target), new InviteRequestMessenger(group));
request.start();

Expand All @@ -77,8 +79,8 @@ public void onSuccess(@Nullable DefaultRequestResult<Choices> result) {
switch (result.getChoice()) {
case ACCEPT:
group.addMember(target);
target.send("You've been added to {0}!", group.getName());
sender.send(target.getName() + " is not a member of your society!");
target.send("target-member.society-added", group.getName());
sender.send("society.member-added", target.getName());
break;
case DENY:
case ABSTAIN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.inject.name.Named;
import net.catharos.groups.Group;
import net.catharos.groups.Member;
import net.catharos.groups.Members;
import net.catharos.groups.request.*;
import net.catharos.groups.request.simple.Choices;
import net.catharos.lib.core.command.CommandContext;
Expand Down Expand Up @@ -54,7 +55,14 @@ public void execute(CommandContext<Member> ctx, final Member sender) {
return;
}

Set<Member> participants = target.getMembers();
Set<Member> participants = target.getMembers("vote.join");
int online = Members.onlineMembers(participants);

//todo
if (online < 1) {
sender.send("participants.not-available");
return;
}

Request<Choices> request = requests.create(sender, new SetInvolved(participants), new JoinRequestMessenger());
request.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.annotation.Nullable;
import javax.inject.Provider;
import java.util.Set;

import static com.google.common.util.concurrent.Futures.addCallback;

Expand Down Expand Up @@ -114,7 +115,16 @@ public void execute(CommandContext<Member> ctx, final Member sender) {
return;
}

SetInvolved involved = new SetInvolved(target.getMembers());
Set<Member> participants = target.getMembers("vote.allies");
int online = Members.onlineMembers(participants);

//todo
if (online < 1) {
sender.send("participants.not-available");
return;
}

SetInvolved involved = new SetInvolved(participants);
Request<Choices> request = requests.create(sender, involved, new AlliesRequestMessenger());
request.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import javax.annotation.Nullable;
import javax.inject.Provider;

import java.util.Set;

import static com.google.common.util.concurrent.Futures.addCallback;

/**
Expand Down Expand Up @@ -82,7 +84,16 @@ public void execute(CommandContext<Member> ctx, final Member sender) {
return;
}

Request<Choices> request = requests.create(sender, new SetInvolved(group.getMembers()), new RivalsRequestMessenger());
Set<Member> participants = group.getMembers("vote.rivals");
int online = Members.onlineMembers(participants);

//todo
if (online < 1) {
sender.send("participants.not-available");
return;
}

Request<Choices> request = requests.create(sender, new SetInvolved(participants), new RivalsRequestMessenger());
request.start();

addCallback(request.result(), new FutureCallback<DefaultRequestResult<Choices>>() {
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ purge {
//
//"rivals.list",
//"rivals.add",
//"rivals.remove"
//"rivals.remove",
//
//"vote.join",
//"vote.allies",
//"vote.rivals"
ranks {
default = "Untrusted"
normal-default = "Trusted"
Expand Down
6 changes: 1 addition & 5 deletions src/main/resources/todo
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
- request opponents must be online
- ignore caption join/find society
- invite/join translations

(- ff.auto ff.deny profile.active lookup.online)
+(- ff.auto ff.deny profile.active lookup.online)

- /rank create problem ??

Expand Down

0 comments on commit 64f66f2

Please sign in to comment.