rong-server 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- require 'rong/server/game'
1
+ require 'rong/server/daemon'
@@ -0,0 +1,36 @@
1
+ module Rong
2
+ module Server
3
+ class Daemon
4
+ attr_accessor :listener
5
+
6
+ def run
7
+ open_listening_socket
8
+ puts "Server is running..."
9
+ loop do
10
+ wait_for_connections do |clients|
11
+ Thread.new do
12
+ Rong::Elements::Game.new(clients).start
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ def open_listening_socket
19
+ self.listener = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM)
20
+ address = Socket.pack_sockaddr_in(7664, Socket::INADDR_LOOPBACK)
21
+ listener.bind(address)
22
+ listener.listen(3)
23
+ end
24
+
25
+ def wait_for_connections
26
+ clients = []
27
+ until clients.count == 2
28
+ client, addr = listener.accept
29
+ clients << client
30
+ end
31
+ yield clients if block_given?
32
+ clients
33
+ end
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matt Yoho
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-07 00:00:00 +01:00
17
+ date: 2011-08-20 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,13 +23,13 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - "="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 0
30
30
  - 2
31
- - 1
32
- version: 0.2.1
31
+ - 2
32
+ version: 0.2.2
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -42,11 +42,99 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  segments:
44
44
  - 2
45
- - 5
45
+ - 6
46
46
  - 0
47
- version: 2.5.0
47
+ version: 2.6.0
48
48
  type: :development
49
49
  version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: guard
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ - 6
61
+ - 1
62
+ version: 0.6.1
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: guard-rspec
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ - 4
76
+ - 2
77
+ version: 0.4.2
78
+ type: :development
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: rb-fsevent
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ - 4
91
+ - 3
92
+ version: 0.4.3
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: growl
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 1
105
+ - 0
106
+ - 3
107
+ version: 1.0.3
108
+ type: :development
109
+ version_requirements: *id006
110
+ - !ruby/object:Gem::Dependency
111
+ name: growl_notify
112
+ prerelease: false
113
+ requirement: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ - 0
121
+ - 1
122
+ version: 0.0.1
123
+ type: :development
124
+ version_requirements: *id007
125
+ - !ruby/object:Gem::Dependency
126
+ name: ruby-debug19
127
+ prerelease: false
128
+ requirement: &id008 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ type: :development
137
+ version_requirements: *id008
50
138
  description: Rong-server is the server component for Rong, a Ruby implementation of Pong that consists of a server module for managing games, a client module for for interfacing with the server, and hopefully a few client implementations for playing some rad Pong, brah.
51
139
  email: mby@mattyoho.com
52
140
  executables: []
@@ -56,7 +144,7 @@ extensions: []
56
144
  extra_rdoc_files: []
57
145
 
58
146
  files:
59
- - lib/rong/server/game.rb
147
+ - lib/rong/server/daemon.rb
60
148
  - lib/rong/server.rb
61
149
  has_rdoc: true
62
150
  homepage: http://github.com/mattyoho/rong
@@ -1,40 +0,0 @@
1
- require 'rong/elements/entities'
2
-
3
- module Rong
4
- module Server
5
- class Game
6
- attr_reader :ball,
7
- :board_height,
8
- :board_length,
9
- :listeners,
10
- :paddles,
11
- :scores
12
-
13
- def initialize(length, height, state=Rong::Elements::Entities::GameState.new)
14
- @ball = Rong::Elements::Entities::Ball.new(state.ball_position.first, state.ball_position.last)
15
- @board_length = length
16
- @board_height = height
17
- @paddles = [Rong::Elements::Entities::Paddle.new(state.first_paddle_position),
18
- Rong::Elements::Entities::Paddle.new(state.second_paddle_position)]
19
- @scores = [0, 0]
20
- @listeners = []
21
- @game_state = state
22
- end
23
-
24
- def add_listener(listener)
25
- @listeners << listener
26
- end
27
-
28
- def current_game_state
29
- @game_state
30
- end
31
-
32
- def update_listeners
33
- listeners.each do |l|
34
- l.update_game_state(current_game_state)
35
- end
36
- end
37
-
38
- end
39
- end
40
- end