mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Removed async-websocket, more work on netcode
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
class IMICFPS
|
||||
module Networking
|
||||
class Client
|
||||
attr_reader :uuid,
|
||||
:packets_sent, :packets_received,
|
||||
:data_sent, :data_received
|
||||
def initialize(socket:)
|
||||
@socket = socket
|
||||
@write_queue = []
|
||||
@read_queue = []
|
||||
|
||||
@uuid = "not_defined"
|
||||
|
||||
@packets_sent = 0
|
||||
@packets_received = 0
|
||||
@data_sent = 0
|
||||
@data_received = 0
|
||||
end
|
||||
|
||||
def read
|
||||
@@ -11,7 +23,16 @@ class IMICFPS
|
||||
def write
|
||||
end
|
||||
|
||||
def puts(packet)
|
||||
@write_queue << packet
|
||||
end
|
||||
|
||||
def gets
|
||||
@socket.recvfrom_nonblock(Protocol::MAX_PACKET_SIZE)
|
||||
end
|
||||
|
||||
def close
|
||||
@socket.close if @socket
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
0
lib/networking/packet_handlers/move.rb
Normal file
0
lib/networking/packet_handlers/move.rb
Normal file
39
lib/networking/protocol.rb
Normal file
39
lib/networking/protocol.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
class IMICFPS
|
||||
module Networking
|
||||
module Protocol
|
||||
MAX_CLIENTS = 32
|
||||
MAX_PACKET_SIZE = 1024
|
||||
PROTOCOL_VERSION = 0 # int
|
||||
HEARTBEAT_INTERVAL = 250 # ms
|
||||
TIMEOUT_PERIOD = 30_000 # ms
|
||||
|
||||
packet_types = %w{
|
||||
# protocol packets
|
||||
reliable
|
||||
multipart
|
||||
acknowledgement
|
||||
control
|
||||
data
|
||||
|
||||
# protocol control packets
|
||||
connect
|
||||
disconnect
|
||||
authenticate
|
||||
heartbeat
|
||||
|
||||
# game data packets
|
||||
client_connected
|
||||
client_disconnected
|
||||
entity_move
|
||||
play_sound_effect
|
||||
create_particle
|
||||
}
|
||||
|
||||
# emulate c-like enum
|
||||
packet_types.each_with_index do |type, i|
|
||||
next if type.start_with?("#")
|
||||
self.const_set(:"#{type.upcase}", i)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user