5
5
package api
6
6
7
7
import (
8
+ "encoding/base64"
8
9
"errors"
9
10
"fmt"
10
11
"log"
@@ -71,7 +72,7 @@ func (handler *V1Handler) getLobbies(writer http.ResponseWriter, _ *http.Request
71
72
MaxClientsPerIP : lobby .ClientsPerIPLimit ,
72
73
Wordpack : lobby .Wordpack ,
73
74
State : lobby .State ,
74
- Scoring : lobby .ScoreCalculation . Identifier () ,
75
+ Scoring : lobby .ScoreCalculationIdentifier ,
75
76
})
76
77
}
77
78
@@ -83,6 +84,28 @@ func (handler *V1Handler) getLobbies(writer http.ResponseWriter, _ *http.Request
83
84
}
84
85
}
85
86
87
+ func (handler * V1Handler ) resurrectLobby (writer http.ResponseWriter , request * http.Request ) {
88
+ var data game.LobbyRestoreData
89
+ base64Decoder := base64 .NewDecoder (base64 .StdEncoding , request .Body )
90
+ if err := easyjson .UnmarshalFromReader (base64Decoder , & data ); err != nil {
91
+ log .Println ("Error unmarshalling lobby resurrection data:" , err )
92
+ http .Error (writer , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
93
+ return
94
+ }
95
+
96
+ lobby := data .Lobby
97
+ // We add the lobby, while the lobby mutex is aqcuired. This prevents us
98
+ // from attempting to connect to the lobby, before the internal state has
99
+ // been restored correctly.
100
+ lobby .Synchronized (func () {
101
+ if state .ResurrectLobby (lobby ) {
102
+ lobby .WriteObject = WriteObject
103
+ lobby .WritePreparedMessage = WritePreparedMessage
104
+ lobby .ResurrectUnsynchronized (& data )
105
+ }
106
+ })
107
+ }
108
+
86
109
func (handler * V1Handler ) postLobby (writer http.ResponseWriter , request * http.Request ) {
87
110
if err := request .ParseForm (); err != nil {
88
111
http .Error (writer , err .Error (), http .StatusBadRequest )
0 commit comments