Пример #1
0
        /// <summary>
        /// Registers the connected client to listen on the events on the specified map. Is called from the client.
        /// </summary>
        /// <param name="serverId">The server identifier.</param>
        /// <param name="mapId">The map identifier.</param>
        /// <remarks>
        /// This is a bit dirty... the AdminPanel should not have the reference to  GameLogic.
        /// Instead we need to extract some interfaces.
        /// TODO: It should also be possible to observe multiple maps through one connection.
        /// </remarks>
        public void Subscribe(byte serverId, ushort mapId)
        {
            IGameServer gameServer = this.servers.OfType <IGameServer>().FirstOrDefault(g => g.Id == serverId);

            if (gameServer == null)
            {
                throw new ArgumentException($"unknown server id {serverId}", nameof(serverId));
            }

            if (!FreeIds.TryDequeue(out ushort observerKey))
            {
                throw new OutOfObserverKeysException();
            }

            var clientProxy = this.Clients.Client(this.Context.ConnectionId);

            WorldObserverToHubAdapter observer = new WorldObserverToHubAdapter(observerKey, serverId, mapId, clientProxy);

            Observers.Add(this.Context.ConnectionId, observer);

            try
            {
                gameServer.RegisterMapObserver(mapId, observer);
            }
            catch (ArgumentException)
            {
                Observers.Remove(this.Context.ConnectionId);
                observer.Dispose();
                throw;
            }
        }
Пример #2
0
 public ViewContainer(WorldObserverToHubAdapter adapter)
 {
     this.adapter = adapter;
 }