mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Ran rubocop autocorrect
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
module Networking
|
||||
class Channel
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
module Networking
|
||||
class Connection
|
||||
@@ -63,9 +64,9 @@ module CyberarmEngine
|
||||
@peer.total_data_received += data.length
|
||||
@peer.last_read_time = Networking.milliseconds
|
||||
|
||||
return true
|
||||
true
|
||||
rescue IO::WaitReadable
|
||||
return false
|
||||
false
|
||||
end
|
||||
|
||||
def write(packet:)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
module Networking
|
||||
class Packet
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
module Networking
|
||||
module PacketHandler
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
module Networking
|
||||
class ControlPacket
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
module Networking
|
||||
class RawPacket
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
module Networking
|
||||
class ReliablePacket
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
module Networking
|
||||
class Peer
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
module Networking
|
||||
module Protocol
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CyberarmEngine
|
||||
module Networking
|
||||
class Server
|
||||
@@ -85,7 +86,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def update
|
||||
while(read)
|
||||
while read
|
||||
end
|
||||
|
||||
# handle write queue
|
||||
@@ -117,7 +118,7 @@ module CyberarmEngine
|
||||
)
|
||||
end
|
||||
|
||||
while(packet = peer.write_queue.shift)
|
||||
while (packet = peer.write_queue.shift)
|
||||
write(peer: peer, packet: packet)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
module Networking
|
||||
class Connection
|
||||
attr_reader :address, :port
|
||||
attr_accessor :total_packets_sent, :total_packets_received, :total_data_sent, :total_data_received, :last_read_time, :last_write_time
|
||||
|
||||
def initialize(address:, port:)
|
||||
@address = address
|
||||
@port = port
|
||||
|
||||
|
||||
@read_buffer = ReadBuffer.new
|
||||
@packet_write_queue = []
|
||||
|
||||
@@ -39,50 +40,49 @@ class IMICFPS
|
||||
)
|
||||
end
|
||||
|
||||
def send_packet( packet )
|
||||
def send_packet(packet)
|
||||
Packet.splinter(packet).each do |pkt|
|
||||
@packet_write_queue << pkt
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
while(read)
|
||||
while read
|
||||
end
|
||||
|
||||
write
|
||||
|
||||
# puts "#{Networking.milliseconds} Total sent: #{@total_packets_sent} packets, #{@total_data_sent} data"
|
||||
# puts "#{Networking.milliseconds} Total received: #{@total_packets_received} packets, #{@total_data_received} data"
|
||||
@read_buffer.reconstruct_packets.each do |packet, addr_info|
|
||||
if packet.peer_id == 0 && packet.type == Protocol::VERIFY_CONNECT
|
||||
@peer_id = packet.payload.unpack1("C")
|
||||
end
|
||||
@read_buffer.reconstruct_packets.each do |packet, _addr_info|
|
||||
@peer_id = packet.payload.unpack1("C") if packet.peer_id.zero? && packet.type == Protocol::VERIFY_CONNECT
|
||||
end
|
||||
|
||||
if @peer_id > 0 && Networking.milliseconds - @last_read_time >= Protocol::HEARTBEAT_INTERVAL
|
||||
if @peer_id.positive? && Networking.milliseconds - @last_read_time >= Protocol::HEARTBEAT_INTERVAL
|
||||
send_packet(Packet.new(peer_id: @peer_id, sequence: 0, type: Protocol::HEARTBEAT, payload: ""))
|
||||
end
|
||||
end
|
||||
|
||||
def close
|
||||
@socket.close if @socket
|
||||
@socket&.close
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def read
|
||||
data, addr = @socket.recvfrom_nonblock(Protocol::MAX_PACKET_SIZE)
|
||||
@read_buffer.add(data, addr )
|
||||
@read_buffer.add(data, addr)
|
||||
|
||||
@total_packets_received += 1
|
||||
@total_data_received += data.length
|
||||
@last_read_time = Networking.milliseconds
|
||||
return true
|
||||
true
|
||||
rescue IO::WaitReadable
|
||||
return false
|
||||
false
|
||||
end
|
||||
|
||||
def write
|
||||
while(packet = @packet_write_queue.shift)
|
||||
while (packet = @packet_write_queue.shift)
|
||||
@socket.send(packet.encode, 0, @address, @port)
|
||||
|
||||
@total_data_sent += packet.encode.length
|
||||
@@ -91,4 +91,4 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
module Networking
|
||||
class Director
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
module Networking
|
||||
module Events
|
||||
@@ -9,4 +10,4 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
module Networking
|
||||
class PacketHandler
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
module Networking
|
||||
class SnapshotPacket < CyberarmEngine::Networking::Packet
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
module Networking
|
||||
class ReadBuffer
|
||||
@@ -14,10 +15,11 @@ class IMICFPS
|
||||
pairs = []
|
||||
|
||||
@buffer.each do |hash|
|
||||
buffer, addr = hash[:buffer], hash[:addr_info]
|
||||
buffer = hash[:buffer]
|
||||
addr = hash[:addr_info]
|
||||
packet = Packet.from_stream(buffer)
|
||||
|
||||
if true#packet.valid?
|
||||
if true # packet.valid?
|
||||
pairs << [packet, addr]
|
||||
@buffer.delete(hash)
|
||||
else
|
||||
@@ -26,8 +28,8 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
|
||||
return pairs
|
||||
pairs
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
module Networking
|
||||
class Server < CyberarmEngine::Networking::Server
|
||||
|
||||
Reference in New Issue
Block a user