SuricatoNetwork 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/suricatonetwork.rb +158 -0
- metadata +46 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
require 'thread'
|
5
|
+
require 'timeout'
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
module SuricatoNetwork
|
10
|
+
class Connection
|
11
|
+
def initialize tcp
|
12
|
+
@tcp = tcp
|
13
|
+
@thread = Thread.new {
|
14
|
+
|
15
|
+
self.work
|
16
|
+
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def work
|
21
|
+
puts "Starting work for #{self.to_s}"
|
22
|
+
|
23
|
+
loop {
|
24
|
+
begin
|
25
|
+
|
26
|
+
event = nil
|
27
|
+
n = nil
|
28
|
+
args = nil
|
29
|
+
|
30
|
+
Timeout.timeout (30) {
|
31
|
+
event, n, args = Event.readForm(@tcp)
|
32
|
+
}
|
33
|
+
Event.getHash[event].new(@tcp,args)
|
34
|
+
rescue => e
|
35
|
+
puts "Error on #{self.to_s}:"
|
36
|
+
puts "\t #{e.to_s}"
|
37
|
+
end
|
38
|
+
}
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def close
|
43
|
+
puts "Closing work for #{self.to_s}"
|
44
|
+
@tcp.close
|
45
|
+
@thread.kill
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
class Listener
|
51
|
+
def initialize port
|
52
|
+
|
53
|
+
Listener.logo
|
54
|
+
|
55
|
+
puts "Updating Event Hash:"
|
56
|
+
Event.generateHash
|
57
|
+
obj = Event.getHash
|
58
|
+
|
59
|
+
for i in obj.keys
|
60
|
+
puts "\t...\t"+"#{obj[i]}"
|
61
|
+
end
|
62
|
+
|
63
|
+
@tcp = TCPServer.new port
|
64
|
+
puts "new Network::Listener on #{port} port"
|
65
|
+
@thread = Thread.new {
|
66
|
+
|
67
|
+
self.work
|
68
|
+
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def work
|
73
|
+
|
74
|
+
loop {
|
75
|
+
Connection.new (@tcp.accept)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.logo
|
80
|
+
puts " "
|
81
|
+
puts " "
|
82
|
+
puts " ,'''''-._"
|
83
|
+
puts " SURICATO ; ,. <> `-._ "
|
84
|
+
puts " NETWORK ; \\' _,--'"
|
85
|
+
puts " 1.0 ; ('"
|
86
|
+
puts " ; , ` \\ "
|
87
|
+
puts " ;, , \\ "
|
88
|
+
puts " ; | |"
|
89
|
+
puts " ; |, | |\\ "
|
90
|
+
puts " ; | | | \\ "
|
91
|
+
puts " |.-\\ ,\\ |\\ |"
|
92
|
+
puts " |.- `. `-. | ||"
|
93
|
+
puts " :.- `-. \\ ';;"
|
94
|
+
puts " .- , \\;;|"
|
95
|
+
puts " ; , | ,\\ "
|
96
|
+
puts " ; , ; \\ "
|
97
|
+
puts " ; , /`. , )"
|
98
|
+
puts " __,;, ,' \\ ,|"
|
99
|
+
puts " _,--''__,| / \\ :"
|
100
|
+
puts " ,'_,-'' | ,/ | :"
|
101
|
+
puts " / / | ; ; |"
|
102
|
+
puts " | | __,-| |--..__,--| |---.--....___"
|
103
|
+
puts "___,-| |----'' / | `._`-. `----"
|
104
|
+
puts " \\ \\ `''' ''' --"
|
105
|
+
puts " `.`. --'"
|
106
|
+
puts " marlon `.`-._ _, ,- __,-"
|
107
|
+
puts " henry `-.`."
|
108
|
+
puts " --' `;"
|
109
|
+
|
110
|
+
puts ""
|
111
|
+
puts ""
|
112
|
+
puts ""
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
class Event
|
118
|
+
def initialize client,form
|
119
|
+
@client = client
|
120
|
+
@form = form
|
121
|
+
puts "Solving #{self}"
|
122
|
+
self.solve
|
123
|
+
end
|
124
|
+
|
125
|
+
def solve
|
126
|
+
puts "I'm Alive! ... solve is not implemented on #{self}"
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.readForm tcp
|
130
|
+
event = tcp.gets.to_s.chomp
|
131
|
+
nargs = tcp.gets.to_i
|
132
|
+
args = []
|
133
|
+
nargs.times do |x|
|
134
|
+
args << tcp.gets
|
135
|
+
end
|
136
|
+
|
137
|
+
return event,nargs,args
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.generateHash
|
141
|
+
@@hash = Hash.new
|
142
|
+
obj = ObjectSpace.each_object(Class).select { |klass| klass < self }
|
143
|
+
|
144
|
+
for i in obj
|
145
|
+
@@hash[i.to_s] = i
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.getHash
|
150
|
+
return @@hash
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: SuricatoNetwork
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marlon Henry Schweigert
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-05-26 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Network Event System
|
15
|
+
email: fleyhe0@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/suricatonetwork.rb
|
21
|
+
homepage: http://fleyhe.com
|
22
|
+
licenses:
|
23
|
+
- GPL 3.0
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.23
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Network Event System
|
46
|
+
test_files: []
|