quakeball/Assets/Scripts/Net/Peers/Server.cs

35 lines
1.2 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using System.Net;
namespace NeonTea.Quakeball.Net.Peers {
public class Server : Peer {
private static uint ConnectionUUIDCounter;
private Dictionary<IPEndPoint, Connection> Connections = new Dictionary<IPEndPoint, Connection>();
public override void OnStart(string host, int port) {
MainConnection.Status = ConnectionStatus.Ready;
Debug.Log($"Server started at {host}:{port}!");
}
public override void OnStop(DisconnectReason reason) {
Debug.Log($"Server closed: {reason.Description}");
}
public override void HandlePacket(IPEndPoint endpoint, ByteReader reader) {
if (Connections.ContainsKey(endpoint)) {
Debug.Log("Got stuff from an existing connection!");
} else {
Connections.Add(endpoint, new Connection(endpoint));
Debug.Log($"Initialized new connection from {endpoint.ToString()}");
}
}
private Connection AddConnection(IPEndPoint endpoint) {
Connection conn = new Connection(endpoint);
Connections.Add(endpoint, conn);
return conn;
}
}
}