Exemplo n.º 1
0
        /// <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.");
            }
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
        /// <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);
            }
        }
Exemplo n.º 5
0
 /// <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);
     }
 }
Exemplo n.º 6
0
 /// <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);
     }
 }
Exemplo n.º 7
0
        /// <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();
        }
Exemplo n.º 8
0
        /// <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();
        }
Exemplo n.º 9
0
 /// <summary>
 /// Constructs a LANLobbyClient object.
 /// </summary>
 public LANLobbyClient(LobbyInfo info, ILobbyListener listener)
     : base(info, listener)
 {
 }
Exemplo n.º 10
0
 /// <summary>
 /// Set's a lobby event listener
 /// </summary>
 /// <param name="listener"></param>
 public void SetListener(ILobbyListener listener)
 {
     Listener = listener;
     Listener?.Initialize(this);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Internal function to create a remote lobby.
 /// </summary>
 protected abstract LobbyClient CreateRemoteLobby_i(LobbyInfo info, ILobbyListener listener);
Exemplo n.º 12
0
 /// <summary>
 /// Internal function to create a local lobby.
 /// </summary>
 protected abstract LobbyServer CreateLocalLobby_i(int maxClients, ILobbyListener listener);