Пример #1
0
func generateTemplates(filepath string) {
	handler := request_handler.NewRequestHandler()

	message := handler.HandleRequest(dummy_client.BuiltNewRequest)
	writeJson(filepath, message)
	message = handler.HandleRequest(dummy_client.BuiltViewWorldRequest)
	writeJson(filepath, message)
	message = handler.HandleRequest(dummy_client.BuiltViewTerrainRequest)
	writeJson(filepath, message)
	message = handler.HandleRequest(dummy_client.BuiltViewUnitsRequest)
	writeJson(filepath, message)
	message = handler.HandleRequest(dummy_client.BuiltViewPlayersRequest)
	writeJson(filepath, message)
	message = handler.HandleRequest(dummy_client.BuiltMoveRequest)
	writeJson(filepath, message)
	message = handler.HandleRequest(dummy_client.BuiltAttackRequest)
	writeJson(filepath, message)
	message = handler.HandleRequest(dummy_client.BuiltEndTurnRequest)
	writeJson(filepath, message)
}
Пример #2
0
func handleConnection(netConn net.Conn) error {
	conn := connection.NewSocketConn(netConn)
	handler := request_handler.NewRequestHandler()
	for {
		logger.Infof("Handling a connection")
		request, err := conn.Read()
		if err != nil {
			logger.Warnf("Error reading request (%s)", err.Error())
			conn.Close()
			return err
		}
		logger.Debugf("Got request %s", string(request))
		response := handler.HandleRequest(request)
		logger.Debugf("Sent response %s", string(response))
		err = conn.Write(response)
		if err != nil {
			logger.Warnf("Error writing response (%s)", err.Error())
			conn.Close()
			return err
		}
	}
}