Пример #1
0
 public static bool isDisconnected(CTFWebSocketService source, int dcTimeMs)
 {
     lock (updateLock)
     {
         if (latestUpdate.ContainsKey(source))
         {
             return((latestUpdate[source].lastUpdate.AddMilliseconds(dcTimeMs)) < DateTime.Now);
         }
         else
         {
             return(true);
         }
     }
 }
Пример #2
0
 public static void update(CTFWebSocketService source)
 {
     lock (updateLock)
     {
         if (!latestUpdate.ContainsKey(source))
         {
             latestUpdate.Add(source, new ServiceInstanceStorage(source));
         }
         else
         {
             latestUpdate[source].update();
         }
     }
 }
Пример #3
0
 public static void playerDisconnect(CTFWebSocketService source)
 {
     lock (playerLock)
     {
         foreach (CTFWebSocketService service in activeSessions)
         {
             if (service.Equals(source))
             {
                 continue;
             }
             service.NotifyDisconnect(source.me);
         }
         players.Remove(source.me); //cya
         activeSessions.Remove(source);
     }
 }
Пример #4
0
 public static void updateDamage(CTFWebSocketService source, String origin, int damage)
 {
     lock (playerLock)
     {
         update(source);
         Player player = players.Where((x) =>
         {
             return(x.name.Equals(origin));
         }).FirstOrDefault();
         if (player == null)
         {
             return;
         }
         player.kills++;
         latestUpdate[source].addEvent(player, damage);
     }
 }
Пример #5
0
 public static void updateProjectile(CTFWebSocketService source, Vector3 origin, Vector3 target)
 {
     lock (playerLock)
     {
         if (source == null || source.me == null)
         {
             return;
         }
         update(source);
         foreach (CTFWebSocketService service in activeSessions)
         {
             if (service.Equals(source))
             {
                 continue;
             }
             service.UpdateProjectile(source.me, origin, target);
         }
     }
 }
Пример #6
0
 public static void updatePosition(CTFWebSocketService source)
 {
     lock (playerLock)
     {
         if (source == null || source.me == null)
         {
             return;
         }
         update(source);
         foreach (CTFWebSocketService service in activeSessions)
         {
             if (service.Equals(source))
             {
                 continue;
             }
             service.UpdatePlayerPosition(source.me);
         }
     }
 }
Пример #7
0
 public static void updateDied(CTFWebSocketService source)
 {
     lock (playerLock)
     {
         if (source == null || source.me == null)
         {
             return;
         }
         update(source);
         Player killer = latestUpdate[source].getMostRecentKiller();
         foreach (CTFWebSocketService service in activeSessions)
         {
             if (service.Equals(source))
             {
                 service.me.deaths++;
                 continue;
             }
             service.NotifyDied(killer, source.me);
         }
     }
 }
Пример #8
0
 public static void addPlayer(CTFWebSocketService source, Player player) //welcome!
 {
     lock (playerLock)
     {
         if (player == null || playerExists(player.name))
         {
             return; //1 job
         }
         players.Add(player);
         update(source);
         ThreadPool.QueueUserWorkItem((s) =>
         {
             while (!isDisconnected(s as CTFWebSocketService, disconnectTime))
             {
                 Thread.Sleep(disconnectTime);
             }
             UserStore.playerDisconnect(s as CTFWebSocketService);
         }, source);
         foreach (CTFWebSocketService service in activeSessions)
         {
             service.NotifyNewPlayer(player);
         }
     }
 }
Пример #9
0
 public ServiceInstanceStorage(CTFWebSocketService source)
 {
     this.source       = source;
     this.lastUpdate   = DateTime.Now;
     this.damageEvents = new List <DamageEvent>();
 }