renet 0.1.0-i386-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,81 @@
1
+ =================================================
2
+ rENet
3
+ Ruby library for games networking
4
+ -------------------------------------------------
5
+ -= Work in Progress =-
6
+ No docs or comments right now :|
7
+ Just this readme ;x
8
+ =================================================
9
+
10
+ Planned:
11
+ - ENet::Connection (client)
12
+ - ENet::Server (server)
13
+ - Others
14
+
15
+ More or less finished:
16
+ - ENet::Connection
17
+ - ENet::Server
18
+
19
+ -------------------------------------------------
20
+ Available binaries:
21
+ - Ruby 1.9 Windows 32bits (Mingw)
22
+
23
+ =================================================
24
+ Under MIT license
25
+ ------------------------------------------------
26
+ Uses ENet as backend < http://enet.bespin.org/ >
27
+ =================================================
28
+
29
+ Library overview
30
+ -------------------------------------------------
31
+ module ENet
32
+ |- ENET_VERSION (string)
33
+ |- RENET_VERSION (string)
34
+ |
35
+ |- Connection (class)
36
+ | |- attr_reader
37
+ | | |- online?
38
+ | | |- connected?
39
+ | |
40
+ | |- attr_accessor
41
+ | | |- total_sent_data
42
+ | | |- total_received_data
43
+ | | |- total_sent_packets
44
+ | | |- total_received_packets
45
+ | |
46
+ | |- methods
47
+ | |- initialize (remote host, remote port, channels to allocate, download bw, upload bw)
48
+ | |- connect (timeout in ms)
49
+ | |- disconnect (timeout in ms)
50
+ | |- send_packet (data to send, reliable or not, channel id)
51
+ | |- send_queued_packets (nothing)
52
+ | |- flush (nothing)
53
+ | |- update (timeout in ms)
54
+ | |- use_compression (true or false)
55
+ | |- on_connection (method to call)
56
+ | |- on_packet_receive (method to call)
57
+ | |- on_disconnection (method to call)
58
+ |
59
+ |- Server (class)
60
+ |- attr_reader
61
+ | |- max_clients
62
+ | |- clients_count
63
+ |
64
+ |- attr_accessor
65
+ | |- total_sent_data
66
+ | |- total_received_data
67
+ | |- total_sent_packets
68
+ | |- total_received_packets
69
+ |
70
+ |- methods
71
+ |- initialize (local port, n� of allowed clients, channels to allocate, download bw, upload bw)
72
+ |- disconnect_client (client id)
73
+ |- send_packet (client id, data to send, reliable or not, channel id)
74
+ |- broadcast_packet (data to send, reliable or not, channel id)
75
+ |- send_queued_packets (nothing)
76
+ |- flush (nothing)
77
+ |- update (timeout in ms)
78
+ |- use_compression (true or false)
79
+ |- on_connection (method to call)
80
+ |- on_packet_receive (method to call)
81
+ |- on_disconnection (method to call)
@@ -0,0 +1,47 @@
1
+ # require the lib!
2
+ require './../bin/renet'
3
+
4
+ # define a custom handler for new client connections, it will be automatically called
5
+ def connections_handler(id, ip)
6
+ # show who connected
7
+ puts "[ID #{id}] connected from #{ip}"
8
+ # delete the hash entry if it already exists
9
+ @clients.delete_if {|key, value| key == id }
10
+ # add the new entry to the clients hash
11
+ @clients[id] = { :ip => ip }
12
+ #show how many clients we have
13
+ puts "Clients connected: #{@server.clients_count} of #{@server.max_clients}"
14
+ end
15
+
16
+ # define a custom handler for incoming data packets, it will be automatically called
17
+ def packets_handler(id, data, channel)
18
+ # show who sent the packet, the data inside and the channel used
19
+ puts "packet from [peer #{id}] -> [#{data}] - [#{channel}]"
20
+ # answer sending the same data to the client (client ID, data, reliable or not, channel ID)
21
+ @server.send_packet(id, data, true, channel)
22
+ end
23
+
24
+ # define a custom handler for client disconnections, it will be automatically called
25
+ def disconnections_handler(id)
26
+ # show who left
27
+ puts "#{@clients[id][:ip]} with ID #{id} disconnected"
28
+ # delete its entry in the clients hash
29
+ @clients.delete_if {|key, value| key == id }
30
+ # sends a packet to all clients informing about the disconnection (data, reliable or not, channel ID)
31
+ @server.broadcast_packet("#{id} disconnected", true, 1)
32
+ end
33
+ # create a hash to store clients information
34
+ @clients = {}
35
+ # create a new server object ( port, clients allowed, number of channels, download bandwidth, upload badnwidth)
36
+ @server = ENet::Server.new(8000, 32, 2, 0, 0)
37
+
38
+ # Set our handlers to the server
39
+ @server.on_connection(method(:connections_handler))
40
+ @server.on_packet_receive(method(:packets_handler))
41
+ @server.on_disconnection(method(:disconnections_handler))
42
+
43
+ # loop forever
44
+ loop do
45
+ # send queued packets and wait for new packets 1000 milliseconds
46
+ @server.update(1000)
47
+ end
@@ -0,0 +1,71 @@
1
+ # require gosu and renet libs!
2
+ require 'gosu'
3
+ require './../bin/renet'
4
+
5
+ # define a new window class
6
+ class GameWindow < Gosu::Window
7
+ def initialize
8
+ super(640, 480, false)
9
+ # set a descriptive caption
10
+ self.caption = "Gosu & ENet Test"
11
+ # create a font to draw the information
12
+ @font = Gosu::Font.new(self, Gosu::default_font_name, 20)
13
+ # create a new connection object (remote host address, remote host port, channels, download bandwidth, upload bandwidth)
14
+ @socket = ENet::Connection.new("localhost", 8000, 2, 0, 0)
15
+ # set the handler for the packets
16
+ @socket.on_packet_receive(method(:on_packet))
17
+ # an array to store the incoming packets
18
+ @packets = []
19
+ end
20
+
21
+ def update
22
+ # send queued packets and receive incoming ones (0 = non-blocking)
23
+ @socket.update(0)
24
+ # show our client FPS
25
+ self.caption = "Gosu & ENet Test - [FPS: #{Gosu::fps.to_s}]"
26
+ end
27
+
28
+ def draw
29
+ # show if we are connected to the server or not (@socket.connected? is valid too)
30
+ @font.draw("Connected: #{@socket.online?}", 10, 10, 0, 1.0, 1.0, 0xffffff00)
31
+ # show the controls
32
+ @font.draw("Press C to connect Press P to send a packet", 10, 440, 0, 1.0, 1.0, 0xffffff00)
33
+ # Show the socket information
34
+ @font.draw("Packets Sent: #{@socket.total_sent_packets}", 450, 380, 0, 1.0, 1.0, 0xffffff00)
35
+ @font.draw("Packets Recv: #{@socket.total_received_packets}", 450, 400, 0, 1.0, 1.0, 0xffffff00)
36
+ @font.draw("Bytes Sent: #{@socket.total_sent_data}", 450, 420, 0, 1.0, 1.0, 0xffffff00)
37
+ @font.draw("Bytes Recv: #{@socket.total_received_data}", 450, 440, 0, 1.0, 1.0, 0xffffff00)
38
+
39
+ # show the storaged packets
40
+ if !@packets.empty?
41
+ @packets.each_index do |i|
42
+ @font.draw("[PACKET] From channel #{@packets[i][1]}, containing \"#{@packets[i][0]}\"", 10, 30*(i+1), 0, 1.0, 1.0, @packets[i][2])
43
+ end
44
+ end
45
+ end
46
+
47
+ def button_down(id)
48
+ case id
49
+ # connect to the server if we press C
50
+ when Gosu::KbC
51
+ # only connects if we are not already connected
52
+ @socket.connect(2000)
53
+ # send a packet if we press P
54
+ when Gosu::KbP
55
+ # send a packet to the server (data, reliable or not, channel ID)
56
+ @socket.send_packet("test packet", true, 0)
57
+ end
58
+ end
59
+
60
+ # define a custom handler to manage the packets
61
+ def on_packet(data, channel)
62
+ # delete the old packets if we get more than 10
63
+ @packets.slice!(0) if @packets.size >= 11
64
+ #storage the packet data, channel and a representative color
65
+ @packets << [data, channel, Gosu::Color.argb(255, rand(100)+155, rand(100)+155, rand(100)+155)]
66
+ end
67
+ end
68
+
69
+ # show the window
70
+ window = GameWindow.new
71
+ window.show
data/lib/renet.1.8.so ADDED
Binary file
data/lib/renet.1.9.so ADDED
Binary file
data/lib/renet.rb ADDED
@@ -0,0 +1,10 @@
1
+ begin
2
+ if defined? RUBY_VERSION and RUBY_VERSION[0..2] == '1.9' then
3
+ version = '1.9'
4
+ else
5
+ version = '1.8'
6
+ end
7
+ require "#{File.dirname(__FILE__)}/renet.#{version}.so"
8
+ rescue LoadError => e
9
+ require "#{File.dirname(__FILE__)}/renet.#{version}.bundle"
10
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: renet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: i386-mingw32
7
+ authors:
8
+ - Dahrkael
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-05 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+ description: Ruby library for games networking. Uses ENet as backend
16
+ email: dark.wolf.warrior@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README
22
+ - lib/renet.rb
23
+ - examples/Console-Server.rb
24
+ - examples/Gosu-Client.rb
25
+ - lib/renet.1.8.so
26
+ - lib/renet.1.9.so
27
+ has_rdoc: true
28
+ homepage: https://github.com/Dahrkael/rENet
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 1.5.2
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Ruby library for games networking. Uses ENet as backend
52
+ test_files: []