FUNZIONAAAAAHAHHA
This commit is contained in:
parent
e1b02284b6
commit
3305d6500b
10 changed files with 508 additions and 309 deletions
|
|
@ -44,8 +44,8 @@ public class Match {
|
|||
public Integer multicastId;
|
||||
|
||||
//True if happen timeout, false otherwise
|
||||
public boolean matchTimeout;
|
||||
public boolean joinTimeout;
|
||||
public boolean matchTimeout = false;
|
||||
public boolean joinTimeout = false;
|
||||
|
||||
//Letters of the match
|
||||
public DefaultListModel<String> letters;
|
||||
|
|
@ -109,6 +109,7 @@ public class Match {
|
|||
}
|
||||
|
||||
public void setScore(String player, Integer score){
|
||||
|
||||
Match m = findMatchByPlayerName(player);
|
||||
if(m!=null) {
|
||||
for (int i = 0; i < m.playersScore.size(); i++) {
|
||||
|
|
@ -121,6 +122,7 @@ public class Match {
|
|||
|
||||
public Boolean allPlayersSendedHisScore(){
|
||||
for (Pair<String, Integer> player : playersScore) {
|
||||
System.out.println(player.getValue());
|
||||
if (player.getValue() == -1) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -129,6 +131,7 @@ public class Match {
|
|||
}
|
||||
|
||||
public void setUndefinedScorePlayersToZero(){
|
||||
|
||||
for (int i = 0; i < playersScore.size(); i++) {
|
||||
if (playersScore.get(i).getValue() == -1) {
|
||||
playersScore.set(i, new Pair<>(playersScore.get(i).getKey(), 0));
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.texttwist.server.servers;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Bool;
|
||||
import com.texttwist.server.services.SessionsService;
|
||||
import com.texttwist.server.models.Match;
|
||||
import com.texttwist.server.tasks.*;
|
||||
import javafx.util.Pair;
|
||||
import models.Message;
|
||||
|
||||
import javax.swing.*;
|
||||
|
|
@ -71,11 +73,13 @@ public class ProxyDispatcher implements Callable<Boolean> {
|
|||
socketChannel.write(bufferMessage);
|
||||
}
|
||||
|
||||
|
||||
Future<Boolean> joinTimeout = threadPool.submit(new JoinTimeout(match));
|
||||
joinTimeout.get();
|
||||
if(match.joinTimeout){
|
||||
Boolean joinTimeoutRes = joinTimeout.get();
|
||||
if(joinTimeoutRes){
|
||||
Future<Boolean> sendMessageJoinTimeout = threadPool.submit(
|
||||
new SendMessageToAllPlayers(match, new Message("JOIN_TIMEOUT", "", "", new DefaultListModel<>()), socketChannel));
|
||||
|
||||
Boolean sendMessageJoinTimeoutRes = sendMessageJoinTimeout.get();
|
||||
if(!sendMessageJoinTimeoutRes){
|
||||
activeMatches.remove(Match.findMatchIndex(activeMatches, match.matchCreator));
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.texttwist.server.tasks;
|
|||
import com.texttwist.server.services.AccountsService;
|
||||
import com.texttwist.server.models.Dictionary;
|
||||
import com.texttwist.server.models.Match;
|
||||
import javafx.util.Pair;
|
||||
import models.User;
|
||||
|
||||
import javax.swing.*;
|
||||
|
|
@ -37,8 +38,13 @@ public class ComputeScore implements Callable<Integer> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
System.out.println(sender +" totalize SCORE = " + score);
|
||||
match.setScore(sender, score);
|
||||
for (Pair<String, Integer> player : match.playersScore) {
|
||||
System.out.println(player.getValue());
|
||||
|
||||
}
|
||||
System.out.println(score);
|
||||
|
||||
User u = AccountsService.getInstance().findUser(sender);
|
||||
|
|
@ -54,8 +60,6 @@ public class ComputeScore implements Callable<Integer> {
|
|||
|
||||
}
|
||||
return score;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Boolean isValid(String word, DefaultListModel<String> letters) {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ public class JoinMatch implements Callable<Boolean> {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
match.joinTimeout=false;
|
||||
match.printAll();
|
||||
match.joinTimeout = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,15 +17,16 @@ public class JoinTimeout implements Callable<Boolean> {
|
|||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
try {
|
||||
Thread.currentThread().sleep(1*60*1000);
|
||||
System.out.println("TIMEOUTTTT");
|
||||
match.joinTimeout=true;
|
||||
Thread.currentThread().sleep(5000);
|
||||
|
||||
if(match.joinTimeout) {
|
||||
match.joinTimeout = false;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
match.joinTimeout = false;
|
||||
return false;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -21,10 +21,9 @@ public class MatchTimeout implements Callable<Boolean> {
|
|||
public Boolean call() throws Exception {
|
||||
try {
|
||||
Thread.currentThread().sleep(Config.sendWordsTimeout);
|
||||
match.setUndefinedScorePlayersToZero();
|
||||
|
||||
if(match.matchTimeout) {
|
||||
System.out.println("SEND BROADCAST BECAUSE TIMEOUT");
|
||||
match.setUndefinedScorePlayersToZero();
|
||||
new SendScores(match).call();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.texttwist.server.tasks;
|
|||
import com.texttwist.server.services.SessionsService;
|
||||
import com.texttwist.server.models.Match;
|
||||
import constants.Config;
|
||||
import javafx.util.Pair;
|
||||
import models.Message;
|
||||
|
||||
import java.net.*;
|
||||
|
|
@ -40,16 +41,18 @@ public class ReceiveWords implements Callable<Boolean>{
|
|||
|
||||
Message msg;
|
||||
DatagramSocket s = new DatagramSocket(Config.WordsReceiverServerPort);
|
||||
|
||||
DatagramPacket packet;
|
||||
|
||||
while(true) {
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
System.out.println("RECEIVIN WORDS");
|
||||
|
||||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||
packet = new DatagramPacket(buf, buf.length);
|
||||
s.receive(packet);
|
||||
|
||||
System.out.println("WORDS RECEIVED");
|
||||
|
||||
String rcv = new String(packet.getData());
|
||||
System.out.println(rcv);
|
||||
if (rcv.startsWith("MESSAGE")) {
|
||||
|
|
@ -60,13 +63,8 @@ public class ReceiveWords implements Callable<Boolean>{
|
|||
threadPool.submit(new ComputeScore(msg.sender, msg.data, match));
|
||||
} else {
|
||||
threadPool.submit(new TokenInvalid(msg.sender, socketChannel, bufferMessages));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue