示例#1
0
func (s *Server) FindEntityServer(player *protobuf.Player) (*network.InternalConnection, error) {
	var closestDist float64 = -1
	var closestServer *network.InternalConnection
	for client, _ := range s.Clients {
		if client.EntityServer != nil {
			dist := math.Abs(client.Player.X - player.X)
			if closestDist < 0 || closestDist > dist {
				closestDist = dist
				closestServer = client.EntityServer
			}
		}
	}
	if closestServer != nil {
		return closestServer, nil
	} else {
		entityServers := s.Cluster.EntityNodes
		serverRange := make([]string, len(entityServers))
		i := 0
		for _, node := range entityServers {
			serverRange[i] = node.Meta.Addr
			i++
		}
		if i > 0 {
			addr := serverRange[rand.Intn(i)]
			return network.ConnectInternal(addr, s)
		} else {
			return nil, errors.New("No entity servers available!")
		}
	}
}
示例#2
0
文件: main.go 项目: frustra/fracture
func main() {
	i, err := network.ConnectInternal("127.0.0.1:25566", &H{})
	if err != nil {
		panic(err)
	}
	var x, z int64 = 1, 3
	i.SendMessage(&protobuf.ChunkRequest{
		X: x,
		Z: z,
	})
	var c chan bool
	c <- true
}