Skip to content

Commit

Permalink
Added server commands to check invites and running games
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Oct 6, 2014
1 parent 2ce7c53 commit a440b3e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Consumer;

import org.apache.log4j.LogManager;
Expand Down Expand Up @@ -70,10 +71,24 @@ private void initializeCommands(CommandHandler commandHandler) {
commandHandler.addHandler("play", this::play);
commandHandler.addHandler("say", this::say);
commandHandler.addHandler("chat", this::chatInfo);
commandHandler.addHandler("games", this::showGames);
commandHandler.addHandler("invites", this::showInvites);
commandHandler.addHandler("ai", () -> new AICommandParameters(), new AICommand());
commandHandler.addHandler("threads", cmd -> showAllStackTraces(server, System.out::println));
}

private void showInvites(Command command) {
for (Entry<Integer, GameInvite> ee : server.getInvites().all().entrySet()) {
System.out.println(ee.getKey() + " = " + ee.getValue());
}
}

private void showGames(Command command) {
for (Entry<Integer, ServerGame> ee : server.getGames().entrySet()) {
System.out.println(ee.getKey() + " = " + ee.getValue());
}
}

private void say(Command command) {
ChatArea chat = server.getMainChat();
chat.broadcast(new ChatMessage(chat.getId(), "Server", command.getFullCommand(1)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cardshifter.server.model;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -21,4 +22,8 @@ public T get(int id) {
return map.get(id);
}

public Map<Integer, T> all() {
return Collections.unmodifiableMap(map);
}

}

0 comments on commit a440b3e

Please sign in to comment.