Skip to content

Commit

Permalink
Fixed workaround for a mass-messaging bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Sep 3, 2014
1 parent 28be7ca commit 30734fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Expand Up @@ -21,10 +21,12 @@
import com.cardshifter.server.outgoing.NewGameMessage;
import com.cardshifter.server.outgoing.WaitMessage;
import com.cardshifter.server.outgoing.WelcomeMessage;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;

public class NetworkConsoleController {
Expand Down Expand Up @@ -70,9 +72,20 @@ public void play(Scanner input) throws IOException {
private void playLoop(NewGameMessage game, Scanner input) throws JsonParseException, JsonMappingException, IOException {
System.out.printf("Game id %d. You are player index %d.%n", game.getGameId(), game.getPlayerIndex());
while (true) {
Message mess;
Message mess = null;
do {
mess = receive(Message.class);
System.out.println("Start loop");

MappingIterator<Message> values = mapper.readValues(new JsonFactory().createParser(in), Message.class);
while (values.hasNext()) {
mess = values.next();
System.out.println("iterator: " + mess);
if (mess instanceof EndOfSequenceMessage) {
break;
}
}
System.out.println("End of loop, mess is " + mess);
// mess = receive(Message.class);
// System.out.println(mess);
}
while (!(mess instanceof EndOfSequenceMessage));
Expand Down
Expand Up @@ -64,11 +64,11 @@ private ZoneMessage constructZoneMessage(Zone zone, Player player) {

private void sendCard(ClientIO io, Card card) {
io.sendToClient(new CardInfoMessage(card.getZone().getId(), card.getId(), LuaTools.tableToJava(card.data)));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
}

}

0 comments on commit 30734fb

Please sign in to comment.