~widelands-dev/widelands-metaserver/ircbridge

« back to all changes in this revision

Viewing changes to wlms/game.go

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
        INITIAL_SETUP GameState = iota
12
12
        NOT_CONNECTABLE
13
13
        CONNECTABLE
 
14
        RUNNING
14
15
)
15
16
 
16
17
type Game struct {
44
45
                success, ok := <-pinger.C
45
46
                if success && ok {
46
47
                        log.Printf("Successfull ping reply from game %s.", game.Name())
47
 
                        if game.state == INITIAL_SETUP {
 
48
                        switch game.state {
 
49
                        case INITIAL_SETUP:
48
50
                                host.SendPacket("GAME_OPEN")
 
51
                                game.SetState(*server, CONNECTABLE)
 
52
                        case NOT_CONNECTABLE:
 
53
                                game.SetState(*server, CONNECTABLE)
 
54
                        case CONNECTABLE, RUNNING:
 
55
                                // Do nothing
 
56
                        default:
 
57
                                log.Fatalf("Unhandled game.state: %v", game.state)
49
58
                        }
50
 
                        game.SetState(*server, CONNECTABLE)
51
59
                } else {
52
60
                        log.Printf("Failed ping reply from game %s.", game.Name())
53
61
                        switch game.state {
54
62
                        case INITIAL_SETUP:
55
63
                                host.SendPacket("ERROR", "GAME_OPEN", "GAME_TIMEOUT")
56
 
                        case CONNECTABLE:
 
64
                                game.SetState(*server, NOT_CONNECTABLE)
 
65
                        case NOT_CONNECTABLE:
 
66
                                // Do nothing.
 
67
                        case CONNECTABLE, RUNNING:
57
68
                                return
 
69
                        default:
 
70
                                log.Fatalf("Unhandled game.state: %v", game.state)
58
71
                        }
59
 
                        game.SetState(*server, NOT_CONNECTABLE)
60
72
                }
61
73
                time.Sleep(server.GamePingTimeout())
62
74
        }