func (p *proxy) handleWebsocket(message []byte, cconn *clientConnection) { logger.Infof("Proxying message from client: %s", message) _, err := p.server.conn.Write(message) if err != nil { logger.Errorf("Error while writing to socket: %s", err) } }
func (gh *game_hub) handleNewGame(message string, cconn *clientConnection) { ng := newGame{} err := json.Unmarshal([]byte(message), &ng) if err != nil { logger.Warnf("Error unmarshalling json: %s", err) return } ng.cconn = cconn logger.Infof("Got new game %s", ng) gh.gameRequests <- &ng }
func (gh *game_hub) handleDisconnection(message string, cconn *clientConnection) { // Find the connection and kill it, cleaning up its game if necessary logger.Info("Client Disconnected. Cleaning up...") for np, game := range gh.uncommittedGames { for i := 0; i < game.currentPlayers; i++ { if game.proxy.proxyConns[i].info.Id == cconn.info.Id { game.proxy.removeClientConnection(i) game.currentPlayers -= 1 if game.currentPlayers == 0 { logger.Infof("%d player uncommitted game empty. Dropping", np) delete(gh.uncommittedGames, np) } break } } } }