コード例 #1
0
ファイル: view_reporter.go プロジェクト: kir-dev/torpedo
func (v *viewReporter) send(aType messageType, payload interface{}) {
	// try to write in the socket
	err := v.conn.WriteJSON(viewMsg{aType, payload})

	if err != nil {
		if v.errorCount >= MAX_VIEW_ERROR_COUNT {
			currentGame.DiscardView(v)
			util.LogWarn("Discarded view for %s after %d errors", v.remoteAddr, v.errorCount)
			return
		}

		util.LogWarn("Could not send data to %s. Error msg: %s", v.remoteAddr, err)
		v.errorCount += 1
	}
}
コード例 #2
0
ファイル: web.go プロジェクト: kir-dev/torpedo
// join handler
func joinHandler(rw http.ResponseWriter, req *http.Request) {
	if !canJoin(req) {
		renderError(rw, util.Errorf("You are already playing! You cannot join twice."))
		return
	}

	player := engine.NewPlayer(req.FormValue("username"))
	player.IsBot = covertCheckboxValueToBool(req.FormValue("is_robot"))

	err := player.Join(currentGame)
	if err != nil {
		util.LogWarn("Player could not join. Cause: %s", err.Error())
		renderTemplate(rw, ERROR_TEMPLATE, errorView{
			// TODO: move to properties file
			"Játékos nem tudott csatlakozni.",
			err.Error(),
			util.IsDev(),
		})
	} else {
		http.SetCookie(rw, &http.Cookie{Name: PLAYER_ID_COOKIE, Value: player.Id, HttpOnly: true})
		http.Redirect(rw, req, "/shoot", http.StatusFound)
	}
}