Beispiel #1
0
// Send a time/keepalive packet
func (game *Game) sendTimeUpdate() {
	buf := new(bytes.Buffer)
	proto.ServerWriteTimeUpdate(buf, game.time)

	// The "keep-alive" packet to client(s) sent here as well, as there
	// seems no particular reason to send time and keep-alive separately
	// for now.
	proto.WriteKeepAlive(buf)

	game.multicastPacket(buf.Bytes(), nil)
}
Beispiel #2
0
// pingNew starts a new "keep-alive" ping.
func (player *Player) pingNew() {
	if player.ping.running {
		log.Printf("%v: Attempted to start a ping while another is running.", player)
	} else {
		if player.ping.timer != nil {
			player.ping.timer.Stop()
		}

		player.ping.running = true
		player.ping.id = rand.Int31()
		if player.ping.id == 0 {
			// Ping ID 0 is used by the client on occasion. Don't use this ID to
			// avoid misreading keep alive IDs.
			player.ping.id = 1
		}
		player.ping.timestampNs = time.Now().UnixNano()

		buf := new(bytes.Buffer)
		proto.WriteKeepAlive(buf, player.ping.id)
		player.TransmitPacket(buf.Bytes())

		player.ping.timer = time.NewTimer(PingTimeoutNs)
	}
}