software_challenge_client 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7809a3d6d16c4423f55d59c5841e091167492d5c
|
4
|
+
data.tar.gz: cf93fa514e3d59944f5a25b5c4267c86f02a0842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44aea3599dc16e2b4bc9daba649d1c3079b88b903de986bf4a5db04bdf625b6e6356038725c3e25e0823e1a769819c2e7a3ce1e08bd71327805f4d220f0d71fd
|
7
|
+
data.tar.gz: 278be07a4517f858ced0abdd062e7b22665fffce97bdebdadffe4fcf400deece2dd026946b55644084734e2421c1ae9010200ad3b51ca4e312025748e80ebf0a
|
data/README.md
CHANGED
@@ -67,14 +67,14 @@ to get a live preview of them at [http://localhost:8808](http://localhost:8808).
|
|
67
67
|
## Development
|
68
68
|
|
69
69
|
After checking out the repo, run `bin/setup` to install
|
70
|
-
dependencies. Then, run `
|
70
|
+
dependencies. Then, run `rspec` to run the tests. You can also
|
71
71
|
run `bin/console` for an interactive prompt that will allow you to
|
72
72
|
experiment.
|
73
73
|
|
74
74
|
To install this gem onto your local machine, run `bundle exec rake
|
75
75
|
install`.
|
76
76
|
|
77
|
-
To develop inside a docker container,
|
77
|
+
To develop inside a docker container, make sure you have Docker installed and execute
|
78
78
|
`develop.sh`.
|
79
79
|
|
80
80
|
### Specs
|
data/RELEASES.md
CHANGED
@@ -40,6 +40,7 @@ class Board
|
|
40
40
|
# exisitert (weil der Index ausserhalb von 0..64 liegt), wird ein neues
|
41
41
|
# Feld vom Typ INVALID zurückgegeben.
|
42
42
|
def field(index)
|
43
|
+
return Field.new(FieldType::INVALID, index) if index.negative?
|
43
44
|
fields.fetch(index, Field.new(FieldType::INVALID, index))
|
44
45
|
end
|
45
46
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
|
2
3
|
require 'socket'
|
3
4
|
require 'rexml/document'
|
4
5
|
require 'rexml/element'
|
@@ -9,31 +10,23 @@ require_relative 'client_interface'
|
|
9
10
|
|
10
11
|
# This class handles the socket connection to the server
|
11
12
|
class Network
|
12
|
-
|
13
13
|
include Logging
|
14
14
|
|
15
|
-
@socket
|
16
|
-
@host
|
17
|
-
@port
|
18
|
-
|
19
|
-
@board
|
20
|
-
@client
|
21
|
-
@protocol
|
22
|
-
|
23
|
-
@receiveBuffer
|
24
|
-
@reservationID
|
25
|
-
|
26
15
|
# @!attribute [r] connected
|
27
16
|
# @return [Boolean] true, if the client is connected to a server
|
28
17
|
attr_reader :connected
|
29
18
|
|
30
19
|
def initialize(host, port, board, client, reservation = nil)
|
31
|
-
|
32
|
-
|
20
|
+
logger.debug("New version")
|
21
|
+
@host = host
|
22
|
+
@port = port
|
23
|
+
@board = board
|
24
|
+
@client = client
|
33
25
|
|
26
|
+
@connected = false
|
34
27
|
@protocol = Protocol.new(self, @client)
|
35
|
-
@
|
36
|
-
@
|
28
|
+
@reservation_id = reservation || ''
|
29
|
+
@receive_buffer = ''
|
37
30
|
end
|
38
31
|
|
39
32
|
# connects the client with a given server
|
@@ -44,28 +37,24 @@ class Network
|
|
44
37
|
logger.info 'Connection to server established.'
|
45
38
|
@connected = true
|
46
39
|
|
47
|
-
|
48
|
-
|
49
|
-
|
40
|
+
sendString('<protocol>')
|
41
|
+
document = REXML::Document.new
|
42
|
+
if @reservation_id != ''
|
50
43
|
element = REXML::Element.new('joinPrepared')
|
51
|
-
element.add_attribute('reservationCode', @
|
52
|
-
document.add(element)
|
53
|
-
self.sendXML(document)
|
44
|
+
element.add_attribute('reservationCode', @reservation_id)
|
54
45
|
else
|
55
|
-
document = REXML::Document.new
|
56
46
|
element = REXML::Element.new('join')
|
57
|
-
element.add_attribute('gameType', '
|
58
|
-
document.add(element)
|
59
|
-
self.sendXML(document)
|
47
|
+
element.add_attribute('gameType', 'swc_2018_hase_und_igel')
|
60
48
|
end
|
61
|
-
|
49
|
+
document.add(element)
|
50
|
+
sendXML(document)
|
51
|
+
@connected
|
62
52
|
end
|
63
53
|
|
64
54
|
# disconnects the client from a server
|
65
55
|
def disconnect
|
66
|
-
|
67
56
|
if @connected
|
68
|
-
sendString(
|
57
|
+
sendString('</protocol>')
|
69
58
|
@connected = false
|
70
59
|
@socket.close
|
71
60
|
end
|
@@ -74,72 +63,65 @@ class Network
|
|
74
63
|
|
75
64
|
# reads from the socket until "</room>" is read
|
76
65
|
def readString
|
77
|
-
|
78
|
-
|
79
|
-
if(!@connected)
|
80
|
-
return
|
81
|
-
end
|
82
|
-
|
83
|
-
line =''
|
84
|
-
char = ''
|
85
|
-
while (line != "</room>" && line != "</protocol>") && !(char = @socket.getc).nil?
|
86
|
-
line+=char
|
87
|
-
if char=='\n' || char==' '
|
66
|
+
return false unless @connected
|
67
|
+
sock_msg = ''
|
88
68
|
|
89
|
-
|
90
|
-
|
91
|
-
|
69
|
+
line = ''
|
70
|
+
logger.debug 'reading'
|
71
|
+
@socket.each_char do |char|
|
72
|
+
line += char
|
73
|
+
sock_msg += char
|
74
|
+
line = '' if ['\n', ' '].include? char
|
75
|
+
break if ['</room>', '</protocol>'].include? line
|
92
76
|
end
|
93
77
|
logger.debug 'ended reading'
|
94
|
-
if
|
95
|
-
|
96
|
-
@receiveBuffer.concat(sockMsg)
|
78
|
+
if sock_msg != ''
|
79
|
+
@receive_buffer.concat(sock_msg)
|
97
80
|
|
98
81
|
# Remove <protocol> tag
|
99
|
-
@
|
100
|
-
@
|
82
|
+
@receive_buffer = @receive_buffer.gsub('<protocol>', '')
|
83
|
+
@receive_buffer = @receive_buffer.gsub('</protocol>', '')
|
101
84
|
|
102
|
-
logger.debug "Received XML from server: #{@
|
85
|
+
logger.debug "Received XML from server: #{@receive_buffer}"
|
103
86
|
|
104
87
|
# Process text
|
105
|
-
@protocol.process_string(@
|
106
|
-
|
88
|
+
@protocol.process_string(@receive_buffer)
|
89
|
+
emptyReceiveBuffer
|
107
90
|
end
|
108
|
-
|
91
|
+
true
|
109
92
|
end
|
110
93
|
|
111
|
-
#
|
112
|
-
|
113
|
-
|
94
|
+
# sends a xml Document to the buffer
|
95
|
+
#
|
96
|
+
# @param xml [REXML::Document] the Document, that will be sent
|
97
|
+
def sendXML(xml)
|
98
|
+
text = ''
|
99
|
+
xml.write(text)
|
100
|
+
sendString(text)
|
114
101
|
end
|
115
102
|
|
116
103
|
# processes an incomming message
|
117
104
|
#
|
118
105
|
# @return [Boolean] true, if the processing of a incomming message was successfull
|
119
106
|
def processMessages
|
120
|
-
|
121
|
-
|
122
|
-
end
|
123
|
-
return self.readString
|
107
|
+
return false unless @connected
|
108
|
+
readString
|
124
109
|
end
|
125
110
|
|
126
111
|
# sends a string to the socket
|
127
112
|
#
|
128
113
|
# @param s [String] the message, to be sent
|
129
114
|
def sendString(s)
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
115
|
+
return unless @connected
|
116
|
+
logger.debug "Sending: #{s}"
|
117
|
+
@socket.print(s)
|
134
118
|
end
|
135
119
|
|
136
|
-
|
137
|
-
|
138
|
-
#
|
139
|
-
def
|
140
|
-
|
141
|
-
xml.write(text)
|
142
|
-
self.sendString(text);
|
120
|
+
private
|
121
|
+
|
122
|
+
# empties the receive buffer
|
123
|
+
def emptyReceiveBuffer
|
124
|
+
@receive_buffer = ''
|
143
125
|
end
|
144
126
|
|
145
127
|
end
|
@@ -6,31 +6,29 @@ require_relative 'network'
|
|
6
6
|
class Runner
|
7
7
|
include Logging
|
8
8
|
|
9
|
-
attr_reader :network
|
10
|
-
|
11
9
|
def initialize(host, port, client, reservation = nil)
|
12
|
-
logger.info 'Software Challenge
|
10
|
+
logger.info 'Software Challenge 2018'
|
13
11
|
logger.info 'Ruby Client'
|
14
12
|
logger.info "Host: #{host}"
|
15
13
|
logger.info "Port: #{port}"
|
16
14
|
|
17
|
-
board = Board.new
|
15
|
+
board = Board.new
|
18
16
|
@network = Network.new(host, port, board, client, reservation)
|
19
17
|
end
|
20
18
|
|
21
19
|
def start
|
22
|
-
|
23
|
-
|
20
|
+
@network.connect
|
21
|
+
unless @network.connected
|
24
22
|
logger.error 'Not connected'
|
25
23
|
return
|
26
24
|
end
|
27
25
|
|
28
|
-
while
|
29
|
-
|
26
|
+
while @network.connected
|
27
|
+
@network.processMessages
|
30
28
|
sleep(0.01)
|
31
29
|
end
|
32
30
|
|
33
31
|
logger.info 'Program end...'
|
34
|
-
|
32
|
+
@network.disconnect
|
35
33
|
end
|
36
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: software_challenge_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 'kwollw '
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-09-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: typesafe_enum
|