public void RemoveSpectator(PlayerInfo info)
 {
     if (Observers.ContainsKey(info.UserId))
     {
         Observers.Remove(info.UserId);
     }
 }
 public void AddSpectator(PlayerInfo info)
 {
     if (Observers.ContainsKey(info.UserId))
     {
         Observers.Remove(info.UserId);
     }
     Observers.Add(info.UserId, info);
 }
Beispiel #3
0
        /// <summary>
        /// Gets called when an observers is about to be added.  Return false to prevent player from being added.
        /// </summary>
        /// <param name="character">the player to observe</param>
        /// <returns></returns>
        protected virtual bool CanAddObserver(ServerCharacterInfo character, ref string msg)
        {
            msg = "";
            if (Observers.ContainsKey(character.ID))
            {
                msg = character.CharacterName + " is already observing the match.";
                return(false);
            }

            if (ObserverCountSafe + 1 > MaxObservers)
            {
                msg = "Game has no more seats available for observers.  Sorry.";
                return(false);
            }

            return(true);
        }
Beispiel #4
0
 public void OnMessageReceived_Internal(string _, JObject _Message)
 {
     if (_Message != null && _Message.ContainsKey(ACTION_KEY_NAME) && _Message.ContainsKey(SERIALIZED_ACTION_KEY_NAME))
     {
         var Action           = StringActionMap[(string)_Message[ACTION_KEY_NAME]];
         var SerializedAction = (JObject)_Message[SERIALIZED_ACTION_KEY_NAME];
         lock (Observers)
         {
             if (Observers.ContainsKey(Action))
             {
                 var RelevantList = Observers[Action];
                 foreach (var ObserverWeakPtr in RelevantList)
                 {
                     if (ObserverWeakPtr.TryGetTarget(out IPubSubSubscriberInterface Observer))
                     {
                         Observer?.OnMessageReceived(SerializedAction);
                     }
                 }
             }
         }
     }
 }
Beispiel #5
0
 /// <summary>
 /// Checks to see if that player currently an observer
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool IsPlayerObserver(int id)
 {
     return(Observers.ContainsKey(id));
 }