// Handle0F handles incoming requests of packet 0x0F: PlayerBlockPlace
769694
func Handle0F(server *Server, sender *player.Player) {
	pkt := new(packet.PlayerBlockPlace)
	pkt.ReadFrom(sender.Conn)

	log.Printf("PlayerBlockPlace: %+v", pkt)

	var bid, meta int16
	if pkt.HeldItem != nil {
		bid = pkt.HeldItem.BlockId
		meta = pkt.HeldItem.Damage
		if pkt.HeldItem.BlockId == -1 {
			bid = int16(material.Stone)
		}
	}

	r := &packet.BlockChange{
		X:         pkt.X,      // int32
		Y:         pkt.Y,      // int8
		Z:         pkt.Z,      // int32
		BlockType: bid,        // int16 // New block type for block
		BlockMeta: int8(meta), // int8
	}
	server.BroadcastPacket(r)
}
704948
func (h Handler) HandleFunc(path string, fn func(w http.ResponseWriter, r *http.Request)) {
	h.mux.HandleFunc(path, fn)
}
522193
func (b *Bot) HandleFunc(cmd string, handler func(s Sender, m *irc.Message)) {
	b.handlers[cmd] = append(b.handlers[cmd], HandlerFunc(handler))
}
1045884
func HandleError(w ResponseWriter, req *http.Request, err error) {
	DefaultServeMux.HandleError(w, req, err)
}
549559
func (tr *Reader) handleSparseFile(hdr *Header, rawHdr *block) error {
	var spd sparseDatas
	var err error
	if hdr.Typeflag == TypeGNUSparse {
		spd, err = tr.readOldGNUSparseMap(hdr, rawHdr)
	} else {
		spd, err = tr.readGNUSparsePAXHeaders(hdr)
	}

	// If sp is non-nil, then this is a sparse file.
	// Note that it is possible for len(sp) == 0.
	if err == nil && spd != nil {
		if isHeaderOnlyType(hdr.Typeflag) || !validateSparseEntries(spd, hdr.Size) {
			return ErrHeader
		}
		sph := invertSparseEntries(spd, hdr.Size)
		tr.curr = &sparseFileReader{tr.curr, sph, 0}
	}
	return err
}
1314593
func (m *mux) handleChannelOpen(packet []byte) error {
	var msg channelOpenMsg
	if err := Unmarshal(packet, &msg); err != nil {
		return err
	}

	if msg.MaxPacketSize < minPacketLength || msg.MaxPacketSize > 1<<31 {
		failMsg := channelOpenFailureMsg{
			PeersId:  msg.PeersId,
			Reason:   ConnectionFailed,
			Message:  "invalid request",
			Language: "en_US.UTF-8",
		}
		return m.sendMessage(failMsg)
	}

	c := m.newChannel(msg.ChanType, channelInbound, msg.TypeSpecificData)
	c.remoteId = msg.PeersId
	c.maxRemotePayload = msg.MaxPacketSize
	c.remoteWin.add(msg.PeersWindow)
	m.incomingChannels <- c
	return nil
}
896069
func (s *Server) handleRequest(str quic.Stream, decoder *qpack.Decoder) error {
	frame, err := parseNextFrame(str)
	if err != nil {
		str.CancelWrite(quic.ErrorCode(errorRequestCanceled))
		return err
	}
	hf, ok := frame.(*headersFrame)
	if !ok {
		str.CancelWrite(quic.ErrorCode(errorUnexpectedFrame))
		return errors.New("expected first frame to be a headers frame")
	}
	// TODO: check length
	headerBlock := make([]byte, hf.Length)
	if _, err := io.ReadFull(str, headerBlock); err != nil {
		str.CancelWrite(quic.ErrorCode(errorIncompleteRequest))
		return err
	}
	hfs, err := decoder.DecodeFull(headerBlock)
	if err != nil {
		// TODO: use the right error code
		str.CancelWrite(quic.ErrorCode(errorGeneralProtocolError))
		return err
	}
	req, err := requestFromHeaders(hfs)
	if err != nil {
		return err
	}
	req.Body = newRequestBody(str)

	if s.logger.Debug() {
		s.logger.Infof("%s %s%s, on stream %d", req.Method, req.Host, req.RequestURI, str.StreamID())
	} else {
		s.logger.Infof("%s %s%s", req.Method, req.Host, req.RequestURI)
	}

	req = req.WithContext(str.Context())
	responseWriter := newResponseWriter(str, s.logger)
	handler := s.Handler
	if handler == nil {
		handler = http.DefaultServeMux
	}

	var panicked, readEOF bool
	func() {
		defer func() {
			if p := recover(); p != nil {
				// Copied from net/http/server.go
				const size = 64 << 10
				buf := make([]byte, size)
				buf = buf[:runtime.Stack(buf, false)]
				s.logger.Errorf("http: panic serving: %v\n%s", p, buf)
				panicked = true
			}
		}()
		handler.ServeHTTP(responseWriter, req)
		// read the eof
		if _, err = str.Read([]byte{}); err == io.EOF {
			readEOF = true
		}
	}()

	if panicked {
		responseWriter.WriteHeader(500)
	} else {
		responseWriter.WriteHeader(200)
	}

	if !readEOF {
		str.CancelRead(quic.ErrorCode(errorEarlyResponse))
	}
	return nil
}
1220554
func (sm *ServeMux) HandlerFunc(handler func(http.ResponseWriter, *http.Request) error) http.Handler {
	if sm.recoverPanic {
		return sm.MWErrorPanic(handler)
	}
	return sm.MWError(handler)
}
1265608
func (m *Mux) HandleFunc(path string, handler http.HandlerFunc) {
	m.Handle(path, handler)
}
273908
func (m *PathRecorderMux) HandleFunc(path string, handler func(http.ResponseWriter, *http.Request)) {
	m.Handle(path, http.HandlerFunc(handler))
}
315537
func (f EventHandlerFunc) HandleEvent(resp http.ResponseWriter, req *http.Request, event *Event) {
	f(resp, req, event)
}
262954
func (n *Negroni) UseHandlerFunc(handlerFunc func(rw http.ResponseWriter, r *http.Request)) {
	n.UseHandler(http.HandlerFunc(handlerFunc))
}
727830
func (r Rule) HandleF(h events.HandlerFunc) Rule {
	return r.Handle(events.Handler(h))
}
99340
func (s *Subrouter) HandleFunc(method string, path string, f func(w http.ResponseWriter, r *http.Request)) {
	s.Handle(method, path, http.HandlerFunc(f))
}
950382
func (c Chain) HandlerF(hf http.HandlerFunc) http.Handler {
	ctx := context.Background()
	return c.HandlerCtx(ctx, HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		hf(w, r)
	}))
}
985422
func (h PfssoHandler) handleUpdate(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	ctx := r.Context()
	defer statsd.NewStatsDTiming(ctx).Send("PfssoHandler.handleUpdate")

	info, timeout, err := h.parseSsoRequest(ctx, r.Body)
	if err != nil {
		http.Error(w, fmt.Sprint(err), http.StatusBadRequest)
		return
	}

	ctx = h.addInfoToContext(ctx, info)

	var shouldStart bool
	for _, firewall := range firewallsso.Firewalls.Structs {
		cacheKey := firewall.GetFirewallSSO(ctx).PfconfigHashNS + "|ip|" + info["ip"] + "|username|" + info["username"] + "|role|" + info["role"]
		// Check whether or not this firewall has cache updates
		// Then check if an entry in the cache exists
		//  If it does exist, we don't send a Start
		//  Otherwise, we add an entry in the cache
		// Note that this has a race condition between the cache.Get and the cache.Set but it is acceptable since worst case will be that 2 SSO will be sent if both requests came in at that same nanosecond
		if firewall.ShouldCacheUpdates(ctx) {
			if _, found := h.updateCache.Get(cacheKey); !found {

				var cacheTimeout int
				if firewall.GetFirewallSSO(ctx).GetCacheTimeout(ctx) != 0 {
					cacheTimeout = firewall.GetFirewallSSO(ctx).GetCacheTimeout(ctx)
				} else if timeout != 0 {
					cacheTimeout = timeout / 2
				} else {
					log.LoggerWContext(ctx).Error("Impossible to cache updates. There is no cache timeout in the firewall and no timeout defined in the request.")
				}

				if cacheTimeout != 0 {
					log.LoggerWContext(ctx).Debug(fmt.Sprintf("Caching SSO for %d seconds", cacheTimeout))
					h.updateCache.Set(cacheKey, 1, time.Duration(cacheTimeout)*time.Second)
				}

				shouldStart = true
			}
		} else {
			shouldStart = true
		}

		if shouldStart {
			//Creating a shallow copy here so the anonymous function has the right reference
			firewall := firewall
			h.spawnSso(ctx, firewall, info, func(info map[string]string) (bool, error) {
				return firewallsso.ExecuteStart(ctx, firewall, info, timeout)
			})
		} else {
			log.LoggerWContext(ctx).Debug("Determined that SSO start was not necessary for this update")
		}

	}

	w.WriteHeader(http.StatusAccepted)
}
611004
func (f *FastHTTPServer) handleMux(ctx *fasthttp.RequestCtx) {
	// TODO limit max size of body that can be read
	//if maxRequestSize := int64(revel.Config.IntDefault("http.maxrequestsize", 0)); maxRequestSize > 0 {
	//   buffer := &bytes.Buffer{}
	//   err := ctx.Request.ReadLimitBody(buffer,maxRequestSize)
	//   if err!=nil {
	//       // Send the error back to the client
	//       ctx.SetStatusCode(http.StatusRequestEntityTooLarge)
	//       return
	//   }
	//}
	context := fastHttpContextStack.Pop().(*FastHttpContext)
	defer func() {
		fastHttpContextStack.Push(context)
	}()
	context.SetContext(ctx)
	f.ServerInit.Callback(context)
}