websiteWebsite
baggle B@ggle
Jeu de boggle multi-joueurs en réseau - A free online multiplayer boggle game

 

Browse the code

Differences between 176 and 177 on /trunk.
Number of edited files: 10 (0 added, 0 deleted and 10 modified)
Author: inouire
Log message: correction de bugs de timing server/masterserver
Date: 2010-08-27 16:20:33

Added file(s) Deleted file(s) Modified file(s)

 

Old New Code
  1
application.args=-v
1 2
compile.on.save=false
2 3
do.depend=false
3 4
do.jar=true
4 5

                                        

 

Old New Code
35 35
    private BufferedReader in;
36 36
    private Socket socket;
37 37

                                        
38  
    public int nbRequest=0;
39  
    public int watchdog=0;
40  
    public boolean destroyConnection = false;
41  

                                    
42 38
    public ClientConnection(Socket s) throws IOException{
43 39
        out = new PrintWriter(s.getOutputStream(), true);
44 40
        in = new BufferedReader(new InputStreamReader(s.getInputStream()));
45 41

                                        

 

Old New Code
32 32
    public static boolean VERBOSE=false;
33 33
    public static boolean EXIT;
34 34
    public static int DELAY=5;//monitoring delay
35  
    public static int LIMIT=35;//watchdog limit for registered servers
  35
    public static int LIMIT=35000;//(msec)heartbeat limit for registered servers
36 36

                                        
37 37
    public static Register register;
38 38

                                        
39 39

                                        

 

Old New Code
59 59
        m.P(false);
60 60
        try{
61 61
            for(RegisteredServer rs : listOfServers){
62  
                if(rs.getIP().equals(RS.getIP())){
63  
                    if(rs.getPort() == RS.getPort()){
  62
                if(rs.IP.equals(RS.IP)){
  63
                    if(rs.port == RS.port){
64 64
                        a=rs;
65 65
                    }
66 66
                }
74 74
        if(a==null){//the server was not already in the list
75 75
            RS.setActive(true);
76 76
            addServer(RS);
77  
            RS.rearmWatchdog();
  77
            RS.updateLastHeartbeatTime();
78 78
        }else{//the server was already listed
79 79
            a.setActive(true);
80 80
            a.reAffect(RS);
81  
            a.rearmWatchdog();
  81
            a.updateLastHeartbeatTime();
82 82
        }
83 83
        printRegisterList();
84 84
    }
90 90
     */
91 91
    public boolean testConnection(RegisteredServer RS){
92 92
        //true if connection is valid, false if not
93  
        Main.printLogIfVerbose("PING on "+RS.getIP()+":"+RS.getPort());
  93
        Main.printLogIfVerbose("PING on "+RS.IP+":"+RS.port);
94 94
        Socket socket = null;
95 95
        try {
96  
            socket = new Socket(RS.getIP(), RS.getPort());
  96
            socket = new Socket(RS.IP, RS.port);
97 97
            PrintWriter out =  new PrintWriter(socket.getOutputStream(), true);
98 98
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
99 99
            if(out != null){
113 113
    }
114 114

                                        
115 115
    public void heartBeat(RegisteredServer RS){
116  
         Main.printLogIfVerbose("HEARTBEAT received from "+RS.getIP().toString()+":"+RS.getPort());
  116
         Main.printLogIfVerbose("HEARTBEAT received from "+RS.IP.toString()+":"+RS.port);
117 117
         RegisteredServer A = Main.register.getServer(RS);
118 118
         if(A!=null){
119  
             A.rearmWatchdog();
  119
             A.updateLastHeartbeatTime();
120 120
             A.reAffect(RS);
121 121
         }
122 122
    }
134 134
        m.P(false);
135 135
        try{
136 136
            for(RegisteredServer rs : listOfServers){
137  
                if(rs.isActive()&& rs.getIP().equals(RS.getIP())){
138  
                    if(rs.getPort() == RS.getPort()){
  137
                if(rs.is_active&& rs.IP.equals(RS.IP)){
  138
                    if(rs.port == RS.port){
139 139
                        a=rs;
140 140
                    }
141 141
                }
153 153
        m.P(false);
154 154
        try{
155 155
            for(RegisteredServer rs : listOfServers){
156  
                if(rs.isActive()){
  156
                if(rs.is_active){
157 157
                    nb++;
158 158
                }
159 159
            }
177 177
        try{
178 178
            if(!this.isEmpty()){
179 179
                for(RegisteredServer rs : listOfServers){
180  
                    if(rs.isActive()){
181  
                        tmp="| "+rs.getIP()+":"+rs.getPort()+" | "+rs.getMode()+" | "+rs.getNumberOfPlayers()+"/"+rs.getMaxNumberOfPlayers()+" | "+rs.getDescription()+"\n";
  180
                    if(rs.is_active){
  181
                        tmp="| "+rs.IP+":"+rs.port+" | "+rs.mode+" | "+rs.nbPlayers+"/"+rs.maxPlayers+" | "+rs.description+"\n";
182 182
                        s+=tmp;
183 183
                        if(tmp.length()>max){
184 184
                            max=tmp.length();
208 208
        try{
209 209
            if(!isEmpty()){
210 210
                for(RegisteredServer rs : listOfServers){
211  
                    if(rs.isActive()){
212  
                        s+=rs.getIP()+":"+rs.getPort()+":"+rs.getMode()+":"+rs.getNumberOfPlayers()+":"+rs.getMaxNumberOfPlayers()+":"+rs.getDescription()+"\n";
  211
                    if(rs.is_active){
  212
                        s+=rs.IP+":"+rs.port+":"+rs.mode+":"+rs.nbPlayers+":"+rs.maxPlayers+":"+rs.description+"\n";
213 213
                    }
214 214
                }
215 215
                s=s.substring(0, s.length()-1);
224 224

                                        
225 225
    public void incrementAllWatchdogs() {
226 226
        boolean changed=false;
  227
        double time=System.currentTimeMillis();
227 228
        m.P(false);
228 229
        try{
229 230
            for(RegisteredServer RS: Main.register.listOfServers){
230  
                if(RS.isActive()){
231  
                    RS.incrementWatchdog(Main.DELAY);
232  
                    if(RS.getWatchdogvalue()>=Main.LIMIT){
  231
                if(RS.is_active){
  232
                    if((time-RS.time_of_last_heartbeat)>Main.LIMIT){
233 233
                        RS.setActive(false);
234 234
                        changed=true;
235 235
                    }
236 236

                                        

 

Old New Code
24 24
 */
25 25
public class RegisteredServer {
26 26

                                        
27  
    private String IP;
28  
    private int port;
29  
    private String description;
30  
    private int mode;
31  
    private int nbPlayers;
32  
    private int maxPlayers;
  27
    public String IP;
  28
    public int port;
  29
    public String description;
  30
    public int mode;
  31
    public int nbPlayers;
  32
    public int maxPlayers;
  33
    public boolean is_active;
33 34

                                        
34  
    private int watchdog;
35  
    public int counter;//to verify every 10 heartbeat that the server is still accessible
36  
    private boolean activate;
  35
    public double time_of_last_heartbeat=0;
37 36

                                        
  37

                                    
38 38
    public RegisteredServer(String IP,int port,int mode,int nbPlayers,int maxPlayers, String description){
39 39
        this.IP=IP;
40 40
        this.port=port;
42 42
        this.mode=mode;
43 43
        this.nbPlayers=nbPlayers;
44 44
        this.maxPlayers=maxPlayers;
45  
        this.watchdog=0;
46  
        this.activate=false;
  45
        this.time_of_last_heartbeat=0;
  46
        this.is_active=false;
47 47
    }
48 48

                                        
49  
    public synchronized void rearmWatchdog(){
50  
        this.watchdog=0;
  49
    public synchronized void updateLastHeartbeatTime(){
  50
        this.time_of_last_heartbeat=System.currentTimeMillis();
51 51
    }
52  
    public synchronized void incrementWatchdog(int inc){
53  
        this.watchdog+=inc;
54  
    }
55  
    public int getWatchdogvalue(){
56  
        return watchdog;
57  
    }
58 52

                                        
59 53
    public void setActive(boolean activate){
60  
        this.activate=activate;
  54
        this.is_active=activate;
61 55
    }
62 56

                                        
63  
    public boolean isActive(){
64  
        return activate;
65  
    }
66  

                                    
67  
    public String getIP(){
68  
        return IP;
69  
    }
70  

                                    
71  
    public int getPort(){
72  
        return port;
73  
    }
74  

                                    
75  
    public String getDescription() {
76  
        return description;
77  
    }
78  

                                    
79  
    public int getNumberOfPlayers(){
80  
        return nbPlayers;
81  
    }
82  

                                    
83  
    public int getMaxNumberOfPlayers(){
84  
        return maxPlayers;
85  
    }
86  

                                    
87  
    public int getMode(){
88  
        return mode;
89  
    }
90  
    
  57
    /**
  58
     * Update the registered server parameters with those of the server in argument
  59
     * @param RS
  60
     */
91 61
    public void reAffect(RegisteredServer RS){
92 62
        this.description=RS.description;
93 63
        this.nbPlayers=RS.nbPlayers;
94 64

                                        

 

Old New Code
1  
 /* Copyright 2010 Edouard Garnier de Labareyre
  1
 /* Copyright 2009-2010 Edouard Garnier de Labareyre
2 2
  *
3 3
  * This file is part of B@ggle.
4 4
  *
5 5

                                        

 

Old New Code
1  
 /* Copyright 2010 Edouard Garnier de Labareyre
  1
 /* Copyright 2009-2010 Edouard Garnier de Labareyre
2 2
  *
3 3
  * This file is part of B@ggle.
4 4
  *
514 514
    public String testName(ClientConnection T, String n){
515 515
        String final_name=n;
516 516
        int k=2;
  517
        m.P(false);
517 518
        try{
518  
            m.P(false);
519 519
            for(ClientConnection c : players_list){
520 520
                if( !c.equals(T) && c.PLAYER_NAME.equals(final_name)){
521 521
                    final_name=n+"_"+k;
534 534
     * Erase the list of words found of all the players
535 535
     */
536 536
    void resetWordsFound() {
  537
        m.P(false);
537 538
        try{
538  
            m.P(false);
539 539
            for(ClientConnection c : players_list){
540 540
                c.resetWordsFound();
541 541
            }
546 546
        }
547 547
    }
548 548

                                        
  549
    /**
  550
     * Decrement the watchdog of each player. If a watchdog's value is less than 0, the player is set to pause
  551
     * @param i the value with which to decrement the watchdog
  552
     */
549 553
    public void decrementPlayersWatchdogs(int i) {
  554
        m.P(false);
550 555
        try{
551  
            m.P(false);
552 556
            for(ClientConnection c : players_list){
553 557
                c.watchdog-=i;
554 558
                if(c.watchdog<0){
555 559

                                        

 

Old New Code
23 23
import boggle.GameBoard;
24 24
import java.util.ArrayList;
25 25
import threads.ListenningThread;
  26
import threads.RegisterThread;
26 27

                                        
27 28

                                        
28 29
/**
142 143
        //start of the thread that listen to all the connections on the listenning port
143 144
        new ListenningThread().start();
144 145

                                        
145  
        int count=0;//counter for registering thread
146  
        Utils.register();
  146
        //start the register thread (+monitor the clients)
  147
        new RegisterThread().start();
  148

                                    
147 149
        //main loop
148 150
        while(true){
149 151
            try {
150 152
                if(!was_reset){
151 153
                    Utils.printLog("Waiting for players to be ready");
152 154
                    while(!clients.hasEnoughReadyPlayers()){
153  
                        if(count>30000){
154  
                            Utils.register();
155  
                            Main.clients.decrementPlayersWatchdogs(30);
156  
                            count=0;
157  
                        }
158  
                        Thread.sleep(500);
159  
                        count+=500;
  155
                        Thread.sleep(800);
160 156
                    }
161 157
                }
162 158
                was_reset=false;
163  
                Utils.printLog("Starting a new game");
  159
                Utils.printLog("Starting a new game ("+clients.getNumberOfPlayers()+" players)");
164 160
                grid_solver.getSolution();
165 161
                total_number_of_words_found = 0;
166 162
                clients.broadcastGrid();
168 164
                Utils.printLogIfVerbose("Solutions: "+solutions);
169 165
                grid_solver.solveGrid();
170 166
                Thread.sleep(1000);
171  
                count+=1300;
172 167
                Main.is_playing=true;
173 168
                clients.resetWordsFound();
174 169
                clients.broadcastStartSignal();
175 170
                long start_date=System.currentTimeMillis();
176  

                                    
177 171
                int progress=100;
178 172
                int time=0;
179 173
                while(time<GAME_TIME){
180 174
                    Thread.sleep(1000);
181  
                    count+=1000;
182  
                    if(count>30000){
183  
                        Utils.register();
184  
                        Main.clients.decrementPlayersWatchdogs(30);
185  
                        count=0;
186  
                    }
187 175
                    time=(int)((System.currentTimeMillis()-start_date)/1000);
188 176
                    progress = 100 - (100*time)/GAME_TIME;
189 177
                    clients.broadcast(Key.PROGRESS+":"+progress);
200 188
                if(!was_reset){
201 189
                    Utils.printLog("Sending results");
202 190
                    clients.broadcastResults();
203  
                }      
  191
                }
204 192
            } catch (Exception ex) {
205 193
                ex.printStackTrace();
206 194
            }
207 195

                                        

 

Old New Code
1  
 /* Copyright 2010 Edouard Garnier de Labareyre
  1
 /* Copyright 2009-2010 Edouard Garnier de Labareyre
2 2
  *
3 3
  * This file is part of B@ggle.
4 4
  *
5 5

                                        

 

Old New Code
34 34

                                        
35 35
    @Override
36 36
    public void run(){
  37
        if(Main.REGISTER){
  38
           register();
  39
        }
  40
        while(true){
  41
            try {
  42
                sleep(25000);
  43
                if(Main.REGISTER){
  44
                   register();
  45
                }
  46
                Main.clients.decrementPlayersWatchdogs(25);
  47
            } catch (InterruptedException ex) {
  48
                ex.printStackTrace();
  49
            }
  50
        }
  51
    }
  52

                                    
  53
    private void register(){
37 54
        if(!first_time && !keep_registering){
38 55
            return;
39 56
        }
40 57