Stubbed files for simplified networking system

This commit is contained in:
2020-07-20 21:36:56 -05:00
parent e69dd3402d
commit 2a36c58abe
5 changed files with 101 additions and 0 deletions

View 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

View File

@@ -0,0 +1,2 @@
class Channel
end

View 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

View 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

View 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