/// <summary> /// Constructs a LANLobbyServer object. /// </summary> public LANLobbyServer(int maxClients, ILobbyListener listener, List <int> wellKnownBroadcastPorts) : base(maxClients, listener) { /// Copy the list of the well-known broadcast ports this.wellKnownBroadcastPorts = new List <int>(); foreach (int p in wellKnownBroadcastPorts) { this.wellKnownBroadcastPorts.Add(p); } int port; bool listenerStarted = false; for (int i = 0; i < 10; i++) { try { port = RandomService.DefaultGenerator.Next(32768, IPEndPoint.MaxPort); this.connListener = new TcpListener(new IPEndPoint(IPAddress.Any, port)); this.connListener.ExclusiveAddressUse = false; this.connListener.Start(maxClients); listenerStarted = true; break; } catch (Exception ex) { TraceManager.WriteExceptionAllTrace(ex, false); } } if (!listenerStarted) { throw new NetworkingSystemException("Unable to start listener 10 times."); } }
/// <see cref="INetwork.JoinLobby"/> public ILobbyClient JoinLobby(LobbyInfo info, ILobbyListener listener) { if (this.closed) { throw new ObjectDisposedException("Network"); } if (listener == null) { throw new ArgumentNullException("listener"); } if (info == null) { throw new ArgumentNullException("info"); } if (this.localLobby == null && this.remoteLobby == null) { LobbyClient lobbyClient = CreateRemoteLobby_i(info, listener); lobbyClient.Disposed += this.LobbyDisposedHandler; this.remoteLobby = lobbyClient; return(this.remoteLobby); } else { return(null); } }
/// <see cref="INetwork.CreateLobby"/> public ILobbyServer CreateLobby(int maxClients, ILobbyListener listener) { if (this.closed) { throw new ObjectDisposedException("Network"); } if (maxClients < 1) { throw new ArgumentOutOfRangeException("maxClients"); } if (listener == null) { throw new ArgumentNullException("listener"); } if (this.localLobby == null && this.remoteLobby == null) { LobbyServer lobbyServer = CreateLocalLobby_i(maxClients, listener); lobbyServer.Disposed += this.LobbyDisposedHandler; this.localLobby = lobbyServer; return(this.localLobby); } else { return(null); } }
/// <summary> /// Set's a lobby event listener /// </summary> /// <param name="listener"></param> public void SetListener(ILobbyListener listener) { _listener = listener; if (listener != null) { _listener.Initialize(this); } }
/// <see cref="Network.CreateRemoteLobby_i"/> protected override LobbyClient CreateRemoteLobby_i(LobbyInfo info, ILobbyListener listener) { try { LobbyClient client = new LANLobbyClient(info, listener); return(client); } catch (Exception ex) { TraceManager.WriteExceptionAllTrace(ex, false); return(null); } }
/// <see cref="Network.CreateLocalLobby_i"/> protected override LobbyServer CreateLocalLobby_i(int maxClients, ILobbyListener listener) { try { LobbyServer server = new LANLobbyServer(maxClients, listener, this.wellKnownBroadcastPorts); return(server); } catch (Exception ex) { TraceManager.WriteExceptionAllTrace(ex, false); return(null); } }
/// <summary> /// Constructs a LobbyServer object. /// </summary> public LobbyServer(int maxClients, ILobbyListener listener) { this.id = Guid.NewGuid(); this.listener = listener; this.announcer = null; this.tasks = new List <NetworkingTaskType>(); this.manipulators = new Fifo <LineManipulator>(); this.manipulatorParams = new Fifo <int>(); this.outgoingPackages = new Fifo <RCPackage>(); this.outgoingPackageTargets = new Fifo <int[]>(); this.connections = new LobbyConnection[maxClients - 1]; for (int i = 0; i < this.connections.Length; i++) { this.connections[i] = CreateConnection_i(); } this.stopConnectionManagerThread = new ManualResetEvent(false); this.connectionManagerThread = new RCThread(this.ConnectionManagerProc, "Networking"); this.connectionManagerThread.Start(); }
/// <summary> /// Constructs a LobbyClient object. /// </summary> public LobbyClient(LobbyInfo info, ILobbyListener listener) { this.id = info.ID; this.listener = listener; this.memberCount = -1; this.clientID = -1; this.outgoingPackages = new List <RCPackage>(); this.outgoingPackageTargets = new List <int[]>(); IPAddress ipAddress; if (!IPAddress.TryParse(info.IPAddress, out ipAddress)) { throw new NetworkingSystemException("Unable to parse server IP address: " + info.IPAddress); } this.serverEndpoint = new IPEndPoint(ipAddress, info.PortNumber); this.connection = CreateConnection_i(this.serverEndpoint); this.stopConnectionManagerThread = new ManualResetEvent(false); this.connectionManagerThread = new RCThread(this.ConnectionManagerProc, "Networking"); this.connectionManagerThread.Start(); }
/// <summary> /// Constructs a LANLobbyClient object. /// </summary> public LANLobbyClient(LobbyInfo info, ILobbyListener listener) : base(info, listener) { }
/// <summary> /// Set's a lobby event listener /// </summary> /// <param name="listener"></param> public void SetListener(ILobbyListener listener) { Listener = listener; Listener?.Initialize(this); }
/// <summary> /// Internal function to create a remote lobby. /// </summary> protected abstract LobbyClient CreateRemoteLobby_i(LobbyInfo info, ILobbyListener listener);
/// <summary> /// Internal function to create a local lobby. /// </summary> protected abstract LobbyServer CreateLocalLobby_i(int maxClients, ILobbyListener listener);