Exemplo n.º 1
0
func new_packet(data []byte, flags Flag) *C.ENetPacket {
	c_packet := C.enet_packet_create(unsafe.Pointer(&data[0]), C.size_t(len(data)), C.enet_uint32(flags))
	if c_packet == nil {
		panic("Allocation failure inside ENet")
	}
	return c_packet
}
Exemplo n.º 2
0
// enet_host_create
func CreateHost(address *net.UDPAddr, peerCount uint, channelLimit uint, incomingBandwidth uint32, outgoingBandwith uint32) (*Host, error) {
	var c_host *C.ENetHost
	if address != nil {
		c_addr := conv_addr(address)
		c_host = C.enet_host_create(&c_addr, C.size_t(peerCount), C.size_t(channelLimit),
			C.enet_uint32(incomingBandwidth), C.enet_uint32(outgoingBandwith))
	} else {
		c_host = C.enet_host_create(nil, C.size_t(peerCount), C.size_t(channelLimit),
			C.enet_uint32(incomingBandwidth), C.enet_uint32(outgoingBandwith))
	}

	if c_host == nil {
		return nil, errors.New("ENet failed to create an ENetHost.")
	}
	C.enet_host_compress(c_host, nil)
	return &Host{c_host, make(map[*C.ENetPeer]*Peer)}, nil
}
Exemplo n.º 3
0
Arquivo: peer.go Projeto: hycxa/waiter
func (p *Peer) Send(payload []byte, flags PacketFlag, channel uint8) {
	if len(payload) == 0 {
		return
	}

	packet := C.enet_packet_create(unsafe.Pointer(&payload[0]), C.size_t(len(payload)), C.enet_uint32(flags))
	p.out <- outgoingPacket{packet, channel}
}
Exemplo n.º 4
0
// enet_host_service
func (host *Host) Service(timeout time.Duration) (*Event, error) {
	if timeout < 0 {
		return nil, errors.New("Timeout duration was negative")
	}

	var c_event C.ENetEvent

	ret := C.enet_host_service(host.host, &c_event, C.enet_uint32(timeout/time.Millisecond))

	return host.ret_to_error(&c_event, ret)
}
Exemplo n.º 5
0
// enet_host_connect
func (host *Host) Connect(address *net.UDPAddr, channelCount uint, data uint) (*Peer, error) {
	c_addr := conv_addr(address)
	c_peer := C.enet_host_connect(host.host, &c_addr, C.size_t(channelCount), C.enet_uint32(data))

	if c_peer == nil {
		return nil, errors.New("No available peers for initiating an ENet connection.")
	}

	peer := &Peer{c_peer}
	host.peers[c_peer] = peer

	return peer, nil
}
Exemplo n.º 6
0
Arquivo: peer.go Projeto: boj/goenet
func (p *ENetPeer) Timeout(timeoutLimit, timeoutMinimum, timeoutMaximum int) {
	C.enet_peer_timeout((*C.ENetPeer)(p), C.enet_uint32(timeoutLimit), C.enet_uint32(timeoutMinimum), C.enet_uint32(timeoutMaximum))
}
Exemplo n.º 7
0
Arquivo: packet.go Projeto: boj/goenet
// Currently this method requires that the data be written in byte form.
// Ideally it would be nice to write arbitrary data such as one can do in the C ENet library.
func NewPacket(data []byte, dataLength int, flags ENetPacketFlag) *ENetPacket {
	return (*ENetPacket)(C.enet_packet_create(unsafe.Pointer(&data[0]), C.size_t(dataLength), C.enet_uint32(flags)))
}
Exemplo n.º 8
0
Arquivo: host.go Projeto: boj/goenet
func (h *ENetHost) Connect(a *ENetAddress, channelCount int, data int) *ENetPeer {
	return (*ENetPeer)(C.enet_host_connect((*C.ENetHost)(h), (*C.ENetAddress)(a), C.size_t(channelCount), C.enet_uint32(data)))
}
Exemplo n.º 9
0
Arquivo: peer.go Projeto: boj/goenet
func (p *ENetPeer) ThrottleConfigure(interval, acceleration, deceleration int) {
	C.enet_peer_throttle_configure((*C.ENetPeer)(p), C.enet_uint32(interval), C.enet_uint32(acceleration), C.enet_uint32(deceleration))
}
Exemplo n.º 10
0
func (a *ENetAddress) SetHost(h uint) {
	a.host = C.enet_uint32(h)
}
Exemplo n.º 11
0
Arquivo: host.go Projeto: boj/goenet
func NewHost(a *ENetAddress, peerCount, channelLimit int, incomingBandwidth, outgoingBandwidth int) *ENetHost {
	return (*ENetHost)(C.enet_host_create((*C.ENetAddress)(a), C.size_t(peerCount), C.size_t(channelLimit), C.enet_uint32(incomingBandwidth), C.enet_uint32(outgoingBandwidth)))
}
Exemplo n.º 12
0
Arquivo: peer.go Projeto: boj/goenet
func (p *ENetPeer) DisconnectLater(data int) {
	C.enet_peer_disconnect_later((*C.ENetPeer)(p), C.enet_uint32(data))
}
Exemplo n.º 13
0
Arquivo: host.go Projeto: boj/goenet
func (h *ENetHost) Service(event *ENetEvent, timeout int) int {
	return int(C.enet_host_service((*C.ENetHost)(h), (*C.ENetEvent)(event), C.enet_uint32(timeout)))
}
Exemplo n.º 14
0
Arquivo: peer.go Projeto: boj/goenet
func (p *ENetPeer) PingInterval(pingInterval int) {
	C.enet_peer_ping_interval((*C.ENetPeer)(p), C.enet_uint32(pingInterval))
}
Exemplo n.º 15
0
// enet_peer_disconnect_later
func (peer *Peer) DisconnectLater(data uint) {
	C.enet_peer_disconnect_later(peer.peer, C.enet_uint32(data))
}
Exemplo n.º 16
0
// enet_peer_disconnect
func (peer *Peer) Disconnect(data uint) {
	C.enet_peer_disconnect(peer.peer, C.enet_uint32(data))
}
Exemplo n.º 17
0
Arquivo: host.go Projeto: boj/goenet
func (h *ENetHost) BandwidthLimit(incomingBandwidth, outgoingBandwidth int) {
	C.enet_host_bandwidth_limit((*C.ENetHost)(h), C.enet_uint32(incomingBandwidth), C.enet_uint32(incomingBandwidth))
}
Exemplo n.º 18
0
Arquivo: peer.go Projeto: hycxa/waiter
func (p *Peer) Disconnect(reason uint32) {
	delete(peers, p.cPeer)
	C.enet_peer_disconnect(p.cPeer, C.enet_uint32(reason))
}
Exemplo n.º 19
0
Arquivo: peer.go Projeto: boj/goenet
func (p *ENetPeer) DisconnectNow(data int) {
	C.enet_peer_disconnect_now((*C.ENetPeer)(p), C.enet_uint32(data))
}