예제 #1
0
 private bool HandlePopObject(PopObjectMessage pbm)
 {
     if(m_bubbles.ContainsKey(pbm.ObjectID))
     {
         ServerBalloon b = GetBalloon(pbm.ObjectID);
         if((b != null) && (b.Screen != null))
         {
             if (!(pbm.Sender is Screen))
             {
                 b.Screen.Connection.SendMessage(pbm);
             }
             else
             {
                 if (m_bubbles.Count <= (Configuration.MinBalloonsPerScreen * m_screens.Count))
                 {
                     m_feed.Refresh();
                 }
             }
         }
         m_bubbles.Remove(pbm.ObjectID);
     }
     else if (m_planes.ContainsKey(pbm.ObjectID))
     {
         ServerPlane p = GetPlane(pbm.ObjectID);
         if ((p != null) && (p.Screen != null))
         {
             if (!(pbm.Sender is Screen))
             {
                 p.Screen.Connection.SendMessage(pbm);
             }
         }
         m_planes.Remove(pbm.ObjectID);
     }
     return true;
 }
예제 #2
0
        private bool HandleChangeScreen(ChangeScreenMessage csm)
        {
            Screen oldScreen = (Screen)csm.Sender;
            Screen newScreen = ChooseNewScreen(oldScreen, csm.Direction);

            if (newScreen == null)
            {
                return true;
            }

            Direction newDirection = csm.Direction;
            if (csm.Direction == Direction.Left)
            {
                newDirection = Direction.Right;
            }
            else if (csm.Direction == Direction.Right)
            {
                newDirection = Direction.Left;
            }

            if (IsPlane(csm.ObjectID))
            {
                ServerPlane p = GetPlane(csm.ObjectID);
                if (p == null)
                {
                    return true;
                }
                p.Ttl--;

                if (p.Ttl > 0)
                {
                    Trace.WriteLine(String.Format("Plane {0} changed screens and has now TTL={1}.", p.ID, p.Ttl));
                    p.Screen = newScreen;
                    newScreen.Connection.SendMessage(new NewPlaneMessage(
                        csm.ObjectID, p.Type, newDirection, csm.Y, csm.Velocity, csm.Time));
                }
                else
                {
                    // the plane has no time left to live
                    Trace.WriteLine(String.Format("Plane {0}'s time has come.", p.ID));
                    PopObjectMessage pom = new PopObjectMessage(csm.ObjectID);
                    pom.Sender = p.Screen;
                    HandlePopObject(pom);
                }
            }
            else
            {
                ServerBalloon b = GetBalloon(csm.ObjectID);
                if (b == null)
                {
                    return true;
                }
                b.Screen = newScreen;
                newScreen.Connection.SendMessage(new NewBalloonMessage(
                    csm.ObjectID, newDirection, csm.Y, csm.Velocity));
            }
            return true;
        }