mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Stubbed files for simplified networking system
This commit is contained in:
3
lib/networking/backend/README.md
Normal file
3
lib/networking/backend/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# I-MIC FPS / CyberarmEngine Networking System
|
||||||
|
End Goal: Reliable and ordered packets of abitrary size
|
||||||
|
Current Goal: Unreliable, unordered packets of limited size
|
||||||
2
lib/networking/backend/channel.rb
Normal file
2
lib/networking/backend/channel.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
class Channel
|
||||||
|
end
|
||||||
27
lib/networking/backend/connection.rb
Normal file
27
lib/networking/backend/connection.rb
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
class Connection
|
||||||
|
def initialize(hostname:, port:, max_clients:, channels: 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Callbacks #
|
||||||
|
def connected
|
||||||
|
end
|
||||||
|
|
||||||
|
def disconnected(reason)
|
||||||
|
end
|
||||||
|
|
||||||
|
def reconnected
|
||||||
|
end
|
||||||
|
|
||||||
|
def packet_received(message, channel)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Functions #
|
||||||
|
def send_packet(message, reliable, channel = 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def broadcast_packet(message, reliable, channel = 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def disconnect(reason = "")
|
||||||
|
end
|
||||||
|
end
|
||||||
10
lib/networking/backend/peer.rb
Normal file
10
lib/networking/backend/peer.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class Peer
|
||||||
|
attr_reader :id, :hostname, :port, :data
|
||||||
|
def initialize(id:, hostname:, port:)
|
||||||
|
@id = id
|
||||||
|
@hostname = hostname
|
||||||
|
@port = port
|
||||||
|
|
||||||
|
@data = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
59
lib/networking/backend/server.rb
Normal file
59
lib/networking/backend/server.rb
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
class Server
|
||||||
|
attr_reader :hostname, :port, :max_clients
|
||||||
|
def initialize(hostname: "0.0.0.0", port: 56789, max_clients: 32, channels: 1)
|
||||||
|
@hostname = hostname
|
||||||
|
@port = port
|
||||||
|
@max_clients = max_clients
|
||||||
|
|
||||||
|
@socket = UDPSocket.new
|
||||||
|
@socket.bind(@hostname, @port)
|
||||||
|
|
||||||
|
@channels = Array(0..channels).map { |id| Channel.new(id: id, server: self) }
|
||||||
|
@peers = []
|
||||||
|
end
|
||||||
|
|
||||||
|
# Helpers #
|
||||||
|
def connected_clients
|
||||||
|
@peers.size
|
||||||
|
end
|
||||||
|
|
||||||
|
def clients
|
||||||
|
@peers
|
||||||
|
end
|
||||||
|
|
||||||
|
# Callbacks #
|
||||||
|
|
||||||
|
# Called when client connects
|
||||||
|
def client_connected(peer)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Called when client times out or explicitly disconnects
|
||||||
|
def client_disconnected(peer, reason)
|
||||||
|
end
|
||||||
|
|
||||||
|
### REMOVE? ###
|
||||||
|
# Called when client was not sending heartbeats or regular packets for a
|
||||||
|
# period of time, but was not logically disconnected and removed, and started
|
||||||
|
# send packets again.
|
||||||
|
#
|
||||||
|
# TLDR: Client was temporarily unreachable but did not timeout.
|
||||||
|
def client_reconnected(peer)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Called when a (logical) packet is received from client
|
||||||
|
def packet_received(peer, message, channel = 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Functions #
|
||||||
|
# Send packet to specified peer
|
||||||
|
def send_packet(peer, message, reliable, channel = 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Send packet to all connected peer
|
||||||
|
def broadcast_packet(message, reliable, channel = 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Disconnect peer
|
||||||
|
def disconnect_client(peer, reason = "")
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user