55package api
66
77import (
8+ "encoding/base64"
89 "errors"
910 "fmt"
1011 "log"
@@ -71,7 +72,7 @@ func (handler *V1Handler) getLobbies(writer http.ResponseWriter, _ *http.Request
7172 MaxClientsPerIP : lobby .ClientsPerIPLimit ,
7273 Wordpack : lobby .Wordpack ,
7374 State : lobby .State ,
74- Scoring : lobby .ScoreCalculation . Identifier () ,
75+ Scoring : lobby .ScoreCalculationIdentifier ,
7576 })
7677 }
7778
@@ -83,6 +84,28 @@ func (handler *V1Handler) getLobbies(writer http.ResponseWriter, _ *http.Request
8384 }
8485}
8586
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+
86109func (handler * V1Handler ) postLobby (writer http.ResponseWriter , request * http.Request ) {
87110 if err := request .ParseForm (); err != nil {
88111 http .Error (writer , err .Error (), http .StatusBadRequest )
0 commit comments