Ejemplo n.º 1
0
func (gh *game_hub) handleClientInfo(message string, cconn *clientConnection) {
	ci := clientInfo{}
	// I hate repeating this unmarshalling code, does Go allow something more general?
	err := json.Unmarshal([]byte(message), &ci)
	if err != nil {
		logger.Warnf("Error unmarshalling json: %s", err)
		return
	}
	cconn.info = ci
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
func (gh *game_hub) handleWebsocket(message []byte, cconn *clientConnection) {
	cmds := strings.SplitN(string(message), ":", 2)
	if len(cmds) == 2 {
		if fun, ok := gh.localHandlers[cmds[0]]; ok {
			fun(cmds[1], cconn)
		} else {
			logger.Warnf("Unrecognized command: %s", cmds[0])
			cconn.toClient <- []byte("unrecognized:")
		}
	} else {
		logger.Errorf("Malformed command: %s", cmds)
	}
}