tedserv 0.0.1a

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a378475eccb7ef108dd215af2f477e696acaca37
4
+ data.tar.gz: c79aca996266df7fc143fcc75214a099762ee5d0
5
+ SHA512:
6
+ metadata.gz: 5e870eea6146e73458b3ee9cca278ae4b9224678b5e5884a632a2538628481733b667e28a3a304332d556198aa12d60126fc7f4f6361bc7f49dc282109a90e24
7
+ data.tar.gz: 16da831339581b61be6f23a3a79cdc3fd1b933aac1bb45f50d6e7c34417690496ae92d85fed5546c3e0d8fb47a4c1d856dc6c33a857f3ed8e6c71945ee2ddd99
data/bin/tedserver ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "tedserv"
4
+ require "socket"
5
+
6
+ @f = TED::Config.new(".tedconfig.txt")
7
+
8
+ def config
9
+ puts "TED Server config tool"
10
+ loop{
11
+ puts "Current: #{@f.getData['port']}"
12
+ puts "------------"
13
+ puts "1. Port"
14
+ puts "99. Exit"
15
+ o = STDIN.gets.chomp.to_i
16
+ if o == 1
17
+ puts "What's the new port?"
18
+ p = STDIN.gets.chomp.to_i
19
+ @f.changePort(p)
20
+ else
21
+ break
22
+ end
23
+ }
24
+ end
25
+
26
+ def runServer
27
+ s = TED::Server.new(@f.getData['port'])
28
+ end
29
+
30
+ def runClient
31
+ c = TED::Client.new
32
+ end
33
+
34
+ def runMini
35
+ @f = TED::Config.new(".config.txt")
36
+ #s = TED::Serverlet.new(ip, port)
37
+ end
38
+
39
+
40
+ anything = false
41
+ ARGV.grep(/^--/).each do |flag|
42
+ if flag == "--config"
43
+ config
44
+ anything = true
45
+ end
46
+ end
47
+
48
+ ARGV.each do |c|
49
+ if c == "server"
50
+ runServer
51
+ anything = true
52
+ elsif c == "client"
53
+ runClient
54
+ anything = true
55
+ elsif c == "node"
56
+ runMini
57
+ anything = true
58
+ end
59
+ end
60
+
61
+
62
+ if !anything
63
+ puts "tedserver [server | client | mini] [--config]"
64
+ puts "server - Run a server with the current configuration"
65
+ puts "client - Run a client to play TED games"
66
+ puts "mini - Run a TED Game and allow players to connect"
67
+ puts "--config - To configure the server"
68
+ end
data/lib/client.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "socket"
2
+ require "proto"
3
+
4
+ class TED::Client
5
+ def intitialze()
6
+ @s = UDPSocket.new
7
+ puts "Welcom to TED Client"
8
+ mainLobby
9
+ end
10
+
11
+ def mainLobby
12
+ loop{
13
+ p = sendAndGet("LIST", Protocol.hubIp, Protocol.hubPort)
14
+ }
15
+ end
16
+
17
+ def inGame
18
+
19
+ end
20
+
21
+ def getMeaning(msg)
22
+ return Protocol.read(msg)
23
+ end
24
+
25
+ def sendAndGet(msg, ip, port)
26
+ p = Protocol.new
27
+ p.msg = msg
28
+ p.kind = Protocol.player
29
+ p.msg = msg
30
+
31
+ @s.send(p, 0, ip, port)
32
+ rep, from = @s.recvfrom(20)
33
+ return getMeaning(rep)
34
+ end
35
+ end
data/lib/config.rb ADDED
@@ -0,0 +1,33 @@
1
+ require "yaml"
2
+
3
+ class TED::Config
4
+
5
+ def initialize(path)
6
+ @path = path
7
+ exist = File.file?(@path)
8
+ if exist
9
+ file = File.open(@path, "r")
10
+ @data = YAML.load(file.read)
11
+ file.close
12
+ else
13
+ @data = {"port"=>"9017"}
14
+ save
15
+ end
16
+ end
17
+
18
+ def save
19
+ file = File.open(@path, "w")
20
+ file.puts(@data.to_yaml)
21
+ file.close
22
+ end
23
+
24
+ def changePort(pt="9017")
25
+ @data["port"]=pt.to_s
26
+ puts "Chnaged config port to: #{pt}"
27
+ save
28
+ end
29
+
30
+ def getData
31
+ return @data
32
+ end
33
+ end
data/lib/proto.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "bindata"
2
+ class TED::Protocol < BinData::Record
3
+
4
+ @@player = 0x00
5
+ @@node = 0x01
6
+ @@hub = 0x10
7
+ @@other = 0x11
8
+
9
+ @@hubIp = "46.101.76.160"
10
+ @@hubPort = 9017
11
+
12
+ stringz :cmd
13
+ bit2 :kind
14
+ end
data/lib/server.rb ADDED
@@ -0,0 +1,36 @@
1
+ require "socket"
2
+ require "proto"
3
+
4
+ class TED::Server
5
+ def initialize(port=9017)
6
+ @port = port
7
+ log("Server ready @ #{port}")
8
+ run()
9
+ end
10
+
11
+ def run
12
+ Socket.udp_server_loop(@port) do |msg, from|
13
+ proto = Protocol.new
14
+ proto.read(msg)
15
+
16
+ ip = from.addr[3]
17
+
18
+ puts proto.msg
19
+
20
+ if proto.kind == Protocol.server
21
+
22
+ elsif proto.kind == Protocol.node
23
+
24
+ elsif proto.kind == Protocol.player
25
+
26
+ else
27
+ log("Unknow user type from: #{ip}")
28
+ from.reply("Not too sure what you are?")
29
+ end
30
+ end
31
+ end
32
+
33
+ def log(msg)
34
+ puts "[#{Time.now.strftime('%H:%M:%S')}]: #{msg}"
35
+ end
36
+ end
data/lib/serverlet.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "socket"
2
+
3
+ class TED::Serverlet
4
+
5
+ def initialize(ip="localhost", port=9017)
6
+ @hub = TCPSocket.open("46.101.76.160", 9018)
7
+ @server = TCPServer.open(ip, port)
8
+ @resp = nil
9
+ @game = nil
10
+ run
11
+ @resp.join
12
+ end
13
+
14
+ def run
15
+ @resp = Thread.new do ## Handle all the messages coming in from the hub and act appropriatly
16
+ loop{
17
+ msg = @hub.gets.chomp
18
+ puts msg
19
+ }
20
+ end
21
+
22
+ Thread.new(@server.accept) do |client|
23
+ client.puts "Connected!"
24
+ end
25
+ end
26
+
27
+ end
data/lib/tedserv.rb ADDED
@@ -0,0 +1,9 @@
1
+ class TED
2
+
3
+ end
4
+
5
+ require 'config'
6
+ require 'proto'
7
+ require 'client'
8
+ require 'server'
9
+ require 'serverlet'
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tedserv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1a
5
+ platform: ruby
6
+ authors:
7
+ - Elliot Lee-Cerrino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: All in one TED gem
14
+ email: "@h2n0"
15
+ executables:
16
+ - tedserver
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/tedserver
21
+ - lib/client.rb
22
+ - lib/config.rb
23
+ - lib/proto.rb
24
+ - lib/server.rb
25
+ - lib/serverlet.rb
26
+ - lib/tedserv.rb
27
+ homepage:
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">"
43
+ - !ruby/object:Gem::Version
44
+ version: 1.3.1
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.5.1
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: All in one TED gem
51
+ test_files: []