Esempio n. 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);
         }
     }
 }
Esempio n. 2
0
 public static void update(CTFWebSocketService source)
 {
     lock (updateLock)
     {
         if (!latestUpdate.ContainsKey(source))
         {
             latestUpdate.Add(source, new ServiceInstanceStorage(source));
         }
         else
         {
             latestUpdate[source].update();
         }
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 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);
         }
     }
 }
Esempio n. 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);
         }
     }
 }
Esempio n. 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);
         }
     }
 }
Esempio n. 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);
         }
     }
 }
Esempio n. 9
0
 public ServiceInstanceStorage(CTFWebSocketService source)
 {
     this.source       = source;
     this.lastUpdate   = DateTime.Now;
     this.damageEvents = new List <DamageEvent>();
 }