Ejemplo n.º 1
0
		public int ReceiveData (
         byte[] data,
         out NetworkGamer sender
)
		{
			throw new NotImplementedException();
		}
Ejemplo n.º 2
0
		public void EnableSendVoice (
         NetworkGamer remoteGamer,
         bool enable
)
		{
			throw new NotImplementedException();
		}
Ejemplo n.º 3
0
        /*
		public void EnableSendVoice (
			NetworkGamer remoteGamer, 
			bool enable)
		{
			throw new NotImplementedException ();
		}
        */

		public int ReceiveData (
			byte[] data, 
			int offset,
			out NetworkGamer sender)
		{
			if (data == null)
				throw new ArgumentNullException("data");
			
			if (receivedData.Count <= 0) {
				sender = null;
				return 0;
			}
			
			lock (receivedData) {

				CommandReceiveData crd;
				
				// we will peek at the value first to see if we can process it
				crd = (CommandReceiveData)receivedData.Peek();
				
				if (offset + crd.data.Length > data.Length)
					throw new ArgumentOutOfRangeException("data","The length + offset is greater than parameter can hold.");
				
				// no exception thrown yet so let's process it
				// take it off the queue
				receivedData.Dequeue();
				
				Array.Copy(crd.data, offset, data, 0, data.Length);
				sender = crd.gamer;
				return data.Length;			
			}
			
		}
Ejemplo n.º 4
0
		public void SendData (
			byte[] data,
			SendDataOptions options,
			NetworkGamer recipient)
		{
			CommandEvent cme = new CommandEvent(new CommandSendData(data, 0, data.Length, options, recipient, this ));
			Session.commandQueue.Enqueue(cme);
		}
Ejemplo n.º 5
0
        internal void SendGamerStateChange(NetworkGamer gamer)
        {
            NetOutgoingMessage message = ((NetPeer)this.peer).CreateMessage();

            message.Write((byte)6);
            message.Write((int)gamer.State);
            this.SendMessage(message, SendDataOptions.Reliable, gamer);
        }
 internal WriteLeaderboardsEventArgs(
     NetworkGamer gamer,
     bool isLeaving
     )
 {
     Gamer     = gamer;
     IsLeaving = isLeaving;
 }
Ejemplo n.º 7
0
 public void SendData(
     byte[] data,
     SendDataOptions options,
     NetworkGamer recipient
     )
 {
     SendData(data, 0, data.Length, options, recipient);
 }
Ejemplo n.º 8
0
 public int ReceiveData(
     byte[] data,
     int offset,
     out NetworkGamer sender
     )
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 9
0
 public void SendData(
     PacketWriter data,
     SendDataOptions options,
     NetworkGamer recipient
     )
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
 public void SendData(
     byte[] data,
     SendDataOptions options,
     NetworkGamer recipient
     )
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
		public void SendData (
			PacketWriter data,
			SendDataOptions options,
			NetworkGamer recipient)
		{
			SendData(data.Data, 0, data.Length, options, recipient);
			data.Reset();
		}
Ejemplo n.º 12
0
 public HostChangedEventArgs(
     NetworkGamer oldHost,
     NetworkGamer newHost
     )
 {
     OldHost = oldHost;
     NewHost = newHost;
 }
Ejemplo n.º 13
0
        internal void SendGamerStateChange(NetworkGamer gamer)
        {
            NetOutgoingMessage om = peer.CreateMessage();

            om.Write((byte)NetworkMessageType.GamerStateChange);
            om.Write((int)gamer.State);

            SendMessage(om, SendDataOptions.Reliable, gamer);
        }
Ejemplo n.º 14
0
        private void ProcessGamerJoined(CommandGamerJoined command)
        {
            NetworkGamer gamer;

            if ((command.State & GamerStates.Local) != 0)
            {
                gamer = new LocalNetworkGamer(this, (byte)command.InternalIndex, command.State);
                _allGamers.AddGamer(gamer);
                _localGamers.AddGamer((LocalNetworkGamer)gamer);

                // Note - This might be in the wrong place for certain connections
                //  Take a look at HoneycombRush tut for debugging later.
                if (Gamer.SignedInGamers.Count >= _localGamers.Count)
                {
                    ((LocalNetworkGamer)gamer).SignedInGamer = Gamer.SignedInGamers[_localGamers.Count - 1];
                }

                // We will attach a property change handler to local gamers
                //  se that we can broadcast the change to other peers.
                gamer.PropertyChanged += HandleGamerPropertyChanged;
            }
            else
            {
                gamer                        = new NetworkGamer(this, (byte)command.InternalIndex, command.State);
                gamer.DisplayName            = command.DisplayName;
                gamer.Gamertag               = command.GamerTag;
                gamer.RemoteUniqueIdentifier = command.remoteUniqueIdentifier;
                _allGamers.AddGamer(gamer);
                _remoteGamers.AddGamer(gamer);
            }

            if ((command.State & GamerStates.Host) != 0)
            {
                hostingGamer = gamer;
            }

            gamer.Machine = new NetworkMachine();
            gamer.Machine.Gamers.AddGamer(gamer);
            //gamer.IsReady = true;

            if (GamerJoined != null)
            {
                GamerJoined(this, new GamerJoinedEventArgs(gamer));
            }

#if !PORTABLE
            if (networkPeer != null && (command.State & GamerStates.Local) == 0)
            {
                networkPeer.SendPeerIntroductions(gamer);
            }

            if (networkPeer != null)
            {
                networkPeer.UpdateLiveSession(this);
            }
#endif
        }
Ejemplo n.º 15
0
        internal void SendData(
            byte[] data,
            SendDataOptions options,
            NetworkGamer gamer)
        {
#if !PORTABLE
            this.SendMessage(NetworkMessageType.Data, data, options, gamer);
#endif
        }
Ejemplo n.º 16
0
        internal void SendGamerStateChange(NetworkGamer gamer)
        {
            Game.Instance.Log("SendGamerStateChange " + gamer.RemoteUniqueIdentifier);
            NetOutgoingMessage om = peer.CreateMessage();

            om.Write((byte)NetworkMessageType.GamerStateChange);
            om.Write((int)gamer.State);

            SendMessage(om, SendDataOptions.Reliable, gamer);
        }
Ejemplo n.º 17
0
		public void SendData (
			byte[] data,
			int offset,
			int count,
			SendDataOptions options,
			NetworkGamer recipient)
		{
			CommandEvent cme = new CommandEvent(new CommandSendData(data, offset, count, options, recipient,this ));
			Session.commandQueue.Enqueue(cme);
		}
Ejemplo n.º 18
0
        private void HandleGamerPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            NetworkGamer gamer = sender as NetworkGamer;

            if (gamer == null || !gamer.IsLocal)
            {
                return;
            }
            this.commandQueue.Enqueue(new CommandEvent((ICommand) new CommandGamerStateChange(gamer)));
        }
Ejemplo n.º 19
0
 public CommandSendData(byte[] data, int offset, int count, SendDataOptions options, NetworkGamer gamer)
 {
     if (gamer != null)
         gamerInternalIndex = gamer.Id;
     this.data = new byte[count];
     Array.Copy(data, offset, this.data, 0, count);
     this.offset = offset;
     this.count = count;
     this.options = options;
     this.gamer = gamer;
 }
Ejemplo n.º 20
0
        internal void SendGamerStateChange(NetworkGamer gamer)
        {
#if !WINDOWS_PHONE
            System.Console.WriteLine("SendGamerStateChange " + gamer.RemoteUniqueIdentifier);
#endif
            NetOutgoingMessage om = peer.CreateMessage();
            om.Write((byte)NetworkMessageType.GamerStateChange);
            om.Write((int)gamer.State);

            SendMessage(om, SendDataOptions.Reliable, gamer);
        }
Ejemplo n.º 21
0
        private NetworkSession(NetworkSessionType sessionType, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, bool isHost, int hostGamer, AvailableNetworkSession availableSession) : this()
        {
            if (sessionProperties == null)
            {
                throw new ArgumentNullException("sessionProperties");
            }

            _allGamers   = new GamerCollection <NetworkGamer>();
            _localGamers = new GamerCollection <LocalNetworkGamer>();
//			for (int x = 0; x < Gamer.SignedInGamers.Count; x++) {
//				GamerStates states = GamerStates.Local;
//				if (x == 0)
//					states |= GamerStates.Host;
//				LocalNetworkGamer localGamer = new LocalNetworkGamer(this, (byte)x, states);
//				localGamer.SignedInGamer = Gamer.SignedInGamers[x];
//				_allGamers.AddGamer(localGamer);
//				_localGamers.AddGamer(localGamer);
//
//				// We will attach a property change handler to local gamers
//				//  se that we can broadcast the change to other peers.
//				localGamer.PropertyChanged += HandleGamerPropertyChanged;
//
//			}

            _remoteGamers   = new GamerCollection <NetworkGamer>();
            _previousGamers = new GamerCollection <NetworkGamer>();
            hostingGamer    = null;

            commandQueue = new Queue <CommandEvent>();

            this.sessionType       = sessionType;
            this.maxGamers         = maxGamers;
            this.privateGamerSlots = privateGamerSlots;
            this.sessionProperties = sessionProperties;
            this.isHost            = isHost;
            this.hostGamerIndex    = hostGamer;
            if (isHost)
            {
                networkPeer = new MonoGamerPeer(this, null);
            }
            else
            {
                if (networkPeer == null)
                {
                    networkPeer = new MonoGamerPeer(this, availableSession);
                }
            }

            CommandGamerJoined gj = new CommandGamerJoined(hostGamer, this.isHost, true);

            commandQueue.Enqueue(new CommandEvent(gj));
        }
Ejemplo n.º 22
0
        public Player(Game game, NetworkGamer gamer)
            : base(game)
        {
            Gamer = gamer;
            DrawOrder = 100;
            Width = Storage.Sprite("DefenseClass").Width;
            Height = Storage.Sprite("DefenseClass").Height;

            Texture = new Color[(int)(Width * Height)];
            Class = Class.None;

            _previousPositions = new Queue<Tuple<Vector2, float>>(MaxPreviousPositions);
        }
Ejemplo n.º 23
0
 private void ProcessGamerLeft(CommandGamerLeft command)
 {
   for (int index = 0; index < this._remoteGamers.Count; ++index)
   {
     if (this._remoteGamers[index].RemoteUniqueIdentifier == command.remoteUniqueIdentifier)
     {
       NetworkGamer aGamer = this._remoteGamers[index];
       this._remoteGamers.RemoveGamer(aGamer);
       this._allGamers.RemoveGamer(aGamer);
       if (this.GamerLeft != null)
         this.GamerLeft((object) this, new GamerLeftEventArgs(aGamer));
     }
   }
 }
Ejemplo n.º 24
0
 public CommandSendData(byte[] data, int offset, int count, SendDataOptions options, NetworkGamer gamer, LocalNetworkGamer sender)
 {
     if (gamer != null)
     {
         this.gamerInternalIndex = (int)gamer.Id;
     }
     this.data = new byte[count];
     Array.Copy((Array)data, offset, (Array)this.data, 0, count);
     this.offset  = offset;
     this.count   = count;
     this.options = options;
     this.gamer   = gamer;
     this.sender  = sender;
 }
Ejemplo n.º 25
0
 public void SendData(
     PacketWriter data,
     SendDataOptions options,
     NetworkGamer recipient
     )
 {
     // FIXME: Do we want to alloc like this? -flibit
     byte[] mem = (data.BaseStream as System.IO.MemoryStream).ToArray();
     data.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
     NetworkSession.NetworkEvent evt = new NetworkSession.NetworkEvent()
     {
         Type     = NetworkSession.NetworkEventType.PacketSend,
         Gamer    = recipient,
         Packet   = mem,
         Reliable = options
     };
     Session.SendNetworkEvent(evt);
 }
Ejemplo n.º 26
0
        private void ProcessGamerJoined(CommandGamerJoined command)
        {
            NetworkGamer networkGamer;

            if ((command.State & GamerStates.Local) != (GamerStates)0)
            {
                networkGamer = (NetworkGamer) new LocalNetworkGamer(this, (byte)command.InternalIndex, command.State);
                this._allGamers.AddGamer(networkGamer);
                this._localGamers.AddGamer((LocalNetworkGamer)networkGamer);
                if (Gamer.SignedInGamers.Count >= this._localGamers.Count)
                {
                    ((LocalNetworkGamer)networkGamer).SignedInGamer = ((List <SignedInGamer>)Gamer.SignedInGamers)[this._localGamers.Count - 1];
                }
                networkGamer.PropertyChanged += new PropertyChangedEventHandler(this.HandleGamerPropertyChanged);
            }
            else
            {
                networkGamer                        = new NetworkGamer(this, (byte)command.InternalIndex, command.State);
                networkGamer.DisplayName            = command.DisplayName;
                networkGamer.Gamertag               = command.GamerTag;
                networkGamer.RemoteUniqueIdentifier = command.remoteUniqueIdentifier;
                this._allGamers.AddGamer(networkGamer);
                this._remoteGamers.AddGamer(networkGamer);
            }
            if ((command.State & GamerStates.Host) != (GamerStates)0)
            {
                this.hostingGamer = networkGamer;
            }
            networkGamer.Machine = new NetworkMachine();
            networkGamer.Machine.Gamers.AddGamer(networkGamer);
            if (this.GamerJoined != null)
            {
                this.GamerJoined((object)this, new GamerJoinedEventArgs(networkGamer));
            }
            if (this.networkPeer != null && (command.State & GamerStates.Local) == (GamerStates)0)
            {
                this.networkPeer.SendPeerIntroductions(networkGamer);
            }
            if (this.networkPeer == null)
            {
                return;
            }
            this.networkPeer.UpdateLiveSession(this);
        }
Ejemplo n.º 27
0
 private NetworkSession(NetworkSessionType sessionType, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, bool isHost, int hostGamer, AvailableNetworkSession availableSession)
   : this()
 {
   if (sessionProperties == null)
     throw new ArgumentNullException("sessionProperties");
   this._allGamers = new GamerCollection<NetworkGamer>();
   this._localGamers = new GamerCollection<LocalNetworkGamer>();
   this._remoteGamers = new GamerCollection<NetworkGamer>();
   this._previousGamers = new GamerCollection<NetworkGamer>();
   this.hostingGamer = (NetworkGamer) null;
   this.commandQueue = new Queue<CommandEvent>();
   this.sessionType = sessionType;
   this.maxGamers = maxGamers;
   this.privateGamerSlots = privateGamerSlots;
   this.sessionProperties = sessionProperties;
   this.isHost = isHost;
   this.hostGamerIndex = hostGamer;
   this.commandQueue.Enqueue(new CommandEvent((ICommand) new CommandGamerJoined(hostGamer, this.isHost, true)));
 }
Ejemplo n.º 28
0
        void HandleGamerPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            NetworkGamer gamer = sender as NetworkGamer;

            if (gamer == null)
            {
                return;
            }

            // If the gamer is local then we need to broadcast that change to all other
            // connected peers.  This is a double check here as we should only be handling
            //  property changes for local gamers for now.
            if (gamer.IsLocal)
            {
                CommandGamerStateChange sc  = new CommandGamerStateChange(gamer);
                CommandEvent            cmd = new CommandEvent(sc);
                commandQueue.Enqueue(cmd);
            }
        }
Ejemplo n.º 29
0
 public void SendData(
     byte[] data,
     int offset,
     int count,
     SendDataOptions options,
     NetworkGamer recipient
     )
 {
     // FIXME: Do we want to alloc like this? -flibit
     byte[] mem = new byte[count];
     Array.Copy(data, offset, mem, 0, mem.Length);
     NetworkSession.NetworkEvent evt = new NetworkSession.NetworkEvent()
     {
         Type     = NetworkSession.NetworkEventType.PacketSend,
         Gamer    = recipient,
         Packet   = mem,
         Reliable = options
     };
     Session.SendNetworkEvent(evt);
 }
Ejemplo n.º 30
0
        private void SendMessage(NetOutgoingMessage om, SendDataOptions options, NetworkGamer gamer)
        {
            //Console.WriteLine("Data to send: " + data.Length);

            //			foreach (NetConnection player in server.Connections) {
            //				// ... send information about every other player (actually including self)
            //				foreach (NetConnection otherPlayer in server.Connections) {

            //					if (gamer != null && gamer.RemoteUniqueIdentifier != otherPlayer.RemoteUniqueIdentifier) {
            //						continue;
            //					}

            NetDeliveryMethod ndm = NetDeliveryMethod.Unreliable;

            switch (options)
            {
            case SendDataOptions.Reliable:
                ndm = NetDeliveryMethod.ReliableSequenced;
                break;

            case SendDataOptions.ReliableInOrder:
                ndm = NetDeliveryMethod.ReliableOrdered;
                break;

            case SendDataOptions.InOrder:
                ndm = NetDeliveryMethod.UnreliableSequenced;
                break;

            case SendDataOptions.None:
                ndm = NetDeliveryMethod.Unknown;
                break;
            }
            // send message
            //server.SendToAll (om, player, ndm);
            peer.SendToAll(om, ndm);

            //				}
            //			}
        }
Ejemplo n.º 31
0
 public int ReceiveData(byte[] data, int offset, out NetworkGamer sender)
 {
   if (data == null)
     throw new ArgumentNullException("data");
   if (this.receivedData.Count <= 0)
   {
     sender = (NetworkGamer) null;
     return 0;
   }
   else
   {
     lock (this.receivedData)
     {
       CommandReceiveData local_0 = this.receivedData.Peek();
       if (offset + local_0.data.Length > data.Length)
         throw new ArgumentOutOfRangeException("data", "The length + offset is greater than parameter can hold.");
       this.receivedData.Dequeue();
       Array.Copy((Array) local_0.data, offset, (Array) data, 0, data.Length);
       sender = local_0.gamer;
       return data.Length;
     }
   }
 }
Ejemplo n.º 32
0
 public int ReceiveData(PacketReader data, out NetworkGamer sender)
 {
     lock (this.receivedData)
     {
         if (this.receivedData.Count >= 0)
         {
             data.Reset(0);
             CommandReceiveData local_0 = this.receivedData.Dequeue();
             if (data.Length < local_0.data.Length)
             {
                 data.Reset(local_0.data.Length);
             }
             Array.Copy((Array)local_0.data, (Array)data.Data, data.Length);
             sender = local_0.gamer;
             return(data.Length);
         }
         else
         {
             sender = (NetworkGamer)null;
             return(0);
         }
     }
 }
Ejemplo n.º 33
0
        private void SendMessage(NetOutgoingMessage om, SendDataOptions options, NetworkGamer gamer)
        {
            NetDeliveryMethod netDeliveryMethod = (NetDeliveryMethod)1;

            switch (options)
            {
            case SendDataOptions.None:
                netDeliveryMethod = (NetDeliveryMethod)0;
                break;

            case SendDataOptions.Reliable:
                netDeliveryMethod = (NetDeliveryMethod)35;
                break;

            case SendDataOptions.InOrder:
                netDeliveryMethod = (NetDeliveryMethod)2;
                break;

            case SendDataOptions.ReliableInOrder:
                netDeliveryMethod = (NetDeliveryMethod)67;
                break;
            }
            this.peer.SendToAll(om, netDeliveryMethod);
        }
Ejemplo n.º 34
0
        /*
         *      public void EnableSendVoice (
         *              NetworkGamer remoteGamer,
         *              bool enable)
         *      {
         *              throw new NotImplementedException ();
         *      }
         */

        public int ReceiveData(
            byte[] data,
            int offset,
            out NetworkGamer sender)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (receivedData.Count <= 0)
            {
                sender = null;
                return(0);
            }

            lock (receivedData) {
                CommandReceiveData crd;

                // we will peek at the value first to see if we can process it
                crd = (CommandReceiveData)receivedData.Peek();

                if (offset + crd.data.Length > data.Length)
                {
                    throw new ArgumentOutOfRangeException("data", "The length + offset is greater than parameter can hold.");
                }

                // no exception thrown yet so let's process it
                // take it off the queue
                receivedData.Dequeue();

                Array.Copy(crd.data, offset, data, 0, data.Length);
                sender = crd.gamer;
                return(data.Length);
            }
        }
Ejemplo n.º 35
0
		public void SendData (
         byte[] data,
         SendDataOptions options,
         NetworkGamer recipient
)
		{
			throw new NotImplementedException();
		}
Ejemplo n.º 36
0
        internal void ConnectNetworkGamer(NetworkGamer gamer)
        {
            if (LocalNetworkGamer == null && IsNetworkGamer(gamer))
            {
                LocalNetworkGamer = gamer as LocalNetworkGamer;
                LocalNetworkGamer.Tag = this;

                Flags = Calc.BitSet(0, (int)GamerFlags.Lobby);
                flagsIsDirty = true;
            #if DEBUG
                Log.Trace(String.Format("{0} connected to the session", GamerTag), 2.0f);
            #endif
            }
        }
Ejemplo n.º 37
0
 internal bool IsNetworkGamer(NetworkGamer gamer)
 {
     LocalNetworkGamer local = gamer as LocalNetworkGamer;
     return LocalNetworkGamer == null && local != null && local.SignedInGamer == SignedInGamer;
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Write requests to the host.
 /// </summary>
 /// <param name="gamers">Clients</param>
 /// <param name="host">Host</param>
 public void clientWritePackets(GamerCollection<LocalNetworkGamer> gamers, NetworkGamer host)
 {
     Command cmd;
     foreach (LocalNetworkGamer gamer in gamers)
     {
         // TODO: Reimpliment.
         if(_writer.Length > 0)
             gamer.SendData(_writer, SendDataOptions.ReliableInOrder, host);
     }
 }
Ejemplo n.º 39
0
 internal static Gamer GetGamerFromNetworkGamer(NetworkGamer gamer)
 {
     foreach( LocalGamer local in SignedInGamers )
     {
         if (local.IsNetworkGamer(gamer))
         {
             local.ConnectNetworkGamer(gamer);
             return local;
         }
     }
     return new RemoteGamer(gamer);
 }
Ejemplo n.º 40
0
		internal void SendGamerStateChange (NetworkGamer gamer)
		{
#if !WINDOWS_PHONE
            Game.Instance.Log("SendGamerStateChange " + gamer.RemoteUniqueIdentifier);
#endif
			NetOutgoingMessage om = peer.CreateMessage ();
			om.Write ((byte)NetworkMessageType.GamerStateChange);
			om.Write ((int)gamer.State);

			SendMessage (om, SendDataOptions.Reliable, gamer);
		}
Ejemplo n.º 41
0
 public HostChangedEventArgs(NetworkGamer aNewHost, NetworkGamer aOldHost)
 {
     newHost = aNewHost;
     oldHost = aOldHost;
 }
Ejemplo n.º 42
0
		public void SendData (
			byte[] data,
			SendDataOptions options,
			NetworkGamer recipient)
		{
			CommandEvent cme = new CommandEvent(new CommandSendData(data, 0, data.Length, options, recipient, this ));
			Session.commandQueue.Enqueue(cme);
		}
Ejemplo n.º 43
0
		public void SendData (
			PacketWriter data,
			SendDataOptions options,
			NetworkGamer recipient)
		{
			SendData(data.Data, 0, data.Length, options, recipient);
			data.Reset();
		}
Ejemplo n.º 44
0
		public int ReceiveData (
			PacketReader data,
			out NetworkGamer sender)
		{
			lock (receivedData) {
				if (receivedData.Count >= 0) {
					data.Reset(0);

					// take it off the queue
					CommandReceiveData crd = (CommandReceiveData)receivedData.Dequeue();
					
					// lets make sure that we can handle the data
					if (data.Length < crd.data.Length) {
						data.Reset(crd.data.Length);
					}

					Array.Copy(crd.data, data.Data, data.Length);
					sender = crd.gamer;
					return data.Length;	
					
				}
				else {
					sender = null;
					return 0;
				}
				
			}
		}
Ejemplo n.º 45
0
		public void SendData (
			byte[] data,
			int offset,
			int count,
			SendDataOptions options,
			NetworkGamer recipient)
		{
			CommandEvent cme = new CommandEvent(new CommandSendData(data, offset, count, options, recipient,this ));
			Session.commandQueue.Enqueue(cme);
		}
Ejemplo n.º 46
0
		public int ReceiveData (
			byte[] data,
			out NetworkGamer sender)
		{
			return ReceiveData(data, 0, out sender);
		}
Ejemplo n.º 47
0
        /// <summary>
        /// Helper draws the gamertag and status icons for a single NetworkGamer.
        /// </summary>
        void DrawGamer(NetworkGamer gamer, Vector2 position)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            SpriteFont font = ScreenManager.Font;

            Vector2 iconWidth = new Vector2(34, 0);
            Vector2 iconOffset = new Vector2(0, 12);

            Vector2 iconPosition = position + iconOffset;

            // Draw the "is ready" icon.
            if (gamer.IsReady)
            {
                spriteBatch.Draw(isReadyTexture, iconPosition,
                                 Color.Lime * TransitionAlpha);
            }

            iconPosition += iconWidth;

            // Draw the "is muted", "is talking", or "has voice" icon.
            if (gamer.IsMutedByLocalUser)
            {
                spriteBatch.Draw(voiceMutedTexture, iconPosition,
                                 Color.Red * TransitionAlpha);
            }
            else if (gamer.IsTalking)
            {
                spriteBatch.Draw(isTalkingTexture, iconPosition,
                                 Color.Yellow * TransitionAlpha);
            }
            else if (gamer.HasVoice)
            {
                spriteBatch.Draw(hasVoiceTexture, iconPosition,
                                 Color.White * TransitionAlpha);
            }

            // Draw the gamertag, normally in white, but yellow for local players.
            string text = gamer.Gamertag;

            if (gamer.IsHost)
                text += Resources.HostSuffix;

            Color color = (gamer.IsLocal) ? Color.Yellow : Color.White;

            spriteBatch.DrawString(font, text, position + iconWidth * 2,
                                   color * TransitionAlpha);
        }
Ejemplo n.º 48
0
 public GamerLeftEventArgs(NetworkGamer aGamer)
 {
   this.gamer = aGamer;
 }
Ejemplo n.º 49
0
		public int ReceiveData (
         PacketReader data,
         out NetworkGamer sender
)
		{
			throw new NotImplementedException();
		}
Ejemplo n.º 50
0
		private void SendMessage (NetworkMessageType messageType, byte[] data, SendDataOptions options, NetworkGamer gamer)
		{

			NetOutgoingMessage om = peer.CreateMessage ();

			om.Write ((byte)messageType);
			om.Write (data);

			SendMessage (om, options, gamer);

		}
Ejemplo n.º 51
0
 public GamerLeftEventArgs(NetworkGamer aGamer)
 {
     gamer = aGamer;
 }
Ejemplo n.º 52
0
		public void SendData (
         PacketWriter data,
         SendDataOptions options,
         NetworkGamer recipient
)
		{
			throw new NotImplementedException();
		}
Ejemplo n.º 53
0
 public HostChangedEventArgs(NetworkGamer aNewHost, NetworkGamer aOldHost)
 {
   this.newHost = aNewHost;
   this.oldHost = aOldHost;
 }
Ejemplo n.º 54
0
 /// <summary>
 /// Update the player data for the sender based on the data in the packet.
 /// </summary>
 /// <param name="sender">The sender of the packet.</param>
 private void UpdatePlayerData(NetworkGamer sender)
 {
     if ((networkSession != null) && (networkSession.LocalGamers.Count > 0) &&
         (sender != null))
     {
         PlayerData playerData = sender.Tag as PlayerData;
         if (playerData != null)
         {
             playerData.Deserialize(packetReader);
             // see if we're still unique
             // -- this can happen legitimately as we receive introductory data
             //foreach (LocalNetworkGamer localNetworkGamer in
             //    networkSession.LocalGamers)
             //{
             //    PlayerData localPlayerData =
             //        localNetworkGamer.Tag as PlayerData;
             //    if ((localPlayerData != null) &&
             //        !Ship.HasUniqueColorIndex(localNetworkGamer,
             //           networkSession))
             //    {
             //        localPlayerData.ShipColor = Ship.GetNextUniqueColorIndex(
             //            localPlayerData.ShipColor, networkSession);
             //        packetWriter.Write((int)World.PacketTypes.PlayerData);
             //        localPlayerData.Serialize(packetWriter);
             //        networkSession.LocalGamers[0].SendData(packetWriter,
             //            SendDataOptions.ReliableInOrder);
             //    }
             //}
         }
     }
 }
Ejemplo n.º 55
0
		internal void SendPeerIntroductions (NetworkGamer gamer)
		{

			NetConnection playerConnection = null;

			foreach (NetConnection player in peer.Connections) {
				if (player.RemoteUniqueIdentifier == gamer.RemoteUniqueIdentifier) {
					playerConnection = player;
				}
			}

			if (playerConnection == null) {
				return;
			}

			foreach (NetConnection player in peer.Connections) {
#if !WINDOWS_PHONE
                Game.Instance.Log("Introduction sent to: " + player.RemoteEndpoint);
#endif
				NetOutgoingMessage om = peer.CreateMessage ();
				om.Write ((byte)NetworkMessageType.Introduction);
				om.Write (playerConnection.RemoteEndpoint.ToString ()); 

				peer.SendMessage (om, player, NetDeliveryMethod.ReliableOrdered);
			}
		}
Ejemplo n.º 56
0
 /// <summary>
 /// Update ship state based on the data in the packet.
 /// </summary>
 /// <param name="sender">The sender of the packet.</param>
 private void UpdateShipData(NetworkGamer sender)
 {
     if (sender != null)
     {
         PlayerData playerData = sender.Tag as PlayerData;
         //if ((playerData != null) && (playerData.Ship != null))
         //{
         //    playerData.Ship.Position = packetReader.ReadVector2();
         //    playerData.Ship.Velocity = packetReader.ReadVector2();
         //    playerData.Ship.Rotation = packetReader.ReadSingle();
         //    playerData.Ship.Life = packetReader.ReadSingle();
         //    playerData.Ship.Shield = packetReader.ReadSingle();
         //    playerData.Ship.Score = packetReader.ReadInt32();
         //}
     }
 }
Ejemplo n.º 57
0
		internal void SendData (
			byte[] data,
			SendDataOptions options,
			NetworkGamer gamer)
		{
			this.SendMessage (NetworkMessageType.Data, data, options, gamer);
		}
Ejemplo n.º 58
0
        /// <summary>
        /// Draw the specified player's data in the screen - gamertag, etc.
        /// </summary>
        /// <param name="totalTime">The total time spent in the game.</param>
        /// <param name="networkGamer">The player to be drawn.</param>
        /// <param name="position">The center of the desired location.</param>
        /// <param name="spriteBatch">The SpriteBatch object used to draw.</param>
        /// <param name="lobby">If true, drawn "lobby style"</param>
        public void DrawPlayerData(float totalTime, NetworkGamer networkGamer,
            Vector2 position, SpriteBatch spriteBatch, bool lobby)
        {
            // safety-check the parameters, as they must be valid
            if (networkGamer == null)
            {
                throw new ArgumentNullException("networkGamer");
            }
            if (spriteBatch == null)
            {
                throw new ArgumentNullException("spriteBatch");
            }

            // get the player data
            PlayerData playerData = networkGamer.Tag as PlayerData;
            if (playerData == null)
            {
                return;
            }

            // draw the gamertag
            float playerStringScale = 1.0f;
            if (networkGamer.IsLocal)
            {
                // pulse the scale of local gamers
                playerStringScale = 1f + 0.08f * (1f + (float)Math.Sin(totalTime * 4f));
            }
            string playerString = networkGamer.Gamertag;
            //TODO divide colors
            Color playerColor = Color.Green;
            Vector2 playerStringSize = playerFont.MeasureString(playerString);
            Vector2 playerStringPosition = position;
            spriteBatch.DrawString(playerFont, playerString, playerStringPosition,
                playerColor, 0f,
                new Vector2(playerStringSize.X / 2f, playerStringSize.Y / 2f),
                playerStringScale, SpriteEffects.None, 0f);

            // draw the chat texture
            Texture2D chatTexture = null;
            if (networkGamer.IsMutedByLocalUser)
            {
                chatTexture = chatMuteTexture;
            }
            else if (networkGamer.IsTalking)
            {
                chatTexture = chatTalkingTexture;
            }
            else if (networkGamer.HasVoice)
            {
                chatTexture = chatAbleTexture;
            }
            if (chatTexture != null)
            {
                float chatTextureScale = 0.9f * playerStringSize.Y /
                    (float)chatTexture.Height;
                Vector2 chatTexturePosition = new Vector2(playerStringPosition.X -
                    1.2f * playerStringSize.X / 2f -
                    1.1f * chatTextureScale * (float)chatTexture.Width / 2f,
                    playerStringPosition.Y);
                spriteBatch.Draw(chatTexture, chatTexturePosition, null,
                    Color.White, 0f, new Vector2((float)chatTexture.Width / 2f,
                    (float)chatTexture.Height / 2f), chatTextureScale,
                    SpriteEffects.None, 0f);
            }

            // if we're in "lobby mode", draw a sample version of the ship,
            // and the ready texture
            if (lobby)
            {
                // draw the ship

                // draw the ready texture
                if ((readyTexture != null) && networkGamer.IsReady)
                {
                    float readyTextureScale = 0.9f * playerStringSize.Y /
                        (float)readyTexture.Height;
                    Vector2 readyTexturePosition = new Vector2(playerStringPosition.X +
                        1.2f * playerStringSize.X / 2f +
                        2.2f  +
                        1.1f * readyTextureScale * (float)readyTexture.Width / 2f,
                        playerStringPosition.Y);
                    spriteBatch.Draw(readyTexture, readyTexturePosition, null,
                        Color.White, 0f, new Vector2((float)readyTexture.Width / 2f,
                        (float)readyTexture.Height / 2f), readyTextureScale,
                        SpriteEffects.None, 0f);
                }

            }
            else
            {

            }
        }
Ejemplo n.º 59
0
		private void SendMessage (NetOutgoingMessage om, SendDataOptions options, NetworkGamer gamer)
		{
			//Console.WriteLine("Data to send: " + data.Length);

			//			foreach (NetConnection player in server.Connections) {
			//				// ... send information about every other player (actually including self)
			//				foreach (NetConnection otherPlayer in server.Connections) {

			//					if (gamer != null && gamer.RemoteUniqueIdentifier != otherPlayer.RemoteUniqueIdentifier) {
			//						continue;
			//					}

			NetDeliveryMethod ndm = NetDeliveryMethod.Unreliable;
			switch (options) {
			case SendDataOptions.Reliable:
				ndm = NetDeliveryMethod.ReliableSequenced;
				break;
			case SendDataOptions.ReliableInOrder:
				ndm = NetDeliveryMethod.ReliableOrdered;
				break;
			case SendDataOptions.InOrder:
				ndm = NetDeliveryMethod.UnreliableSequenced;
				break;
			case SendDataOptions.None:
				ndm = NetDeliveryMethod.Unknown;
				break;
			}
			// send message
			//server.SendToAll (om, player, ndm);
			peer.SendToAll (om, ndm);

			//				}
			//			}				
		}		
Ejemplo n.º 60
0
 /// <summary>
 /// Kill the sender's ship based on data in the packet.
 /// </summary>
 /// <param name="sender">The sender of the packet.</param>
 private void KillShip(NetworkGamer sender)
 {
     if (sender != null)
     {
         PlayerData playerData = sender.Tag as PlayerData;
         if ((playerData != null))
         {
             //GameplayObject source = null;
             //// read the index of the source of the last damage taken
             //int sourcePlayerIndex = packetReader.ReadInt32();
             //if ((sourcePlayerIndex >= 0) &&
             //    (sourcePlayerIndex < networkSession.AllGamers.Count))
             //{
             //    PlayerData sourcePlayerData =
             //        networkSession.AllGamers[sourcePlayerIndex].Tag
             //        as PlayerData;
             //    source = sourcePlayerData != null ? sourcePlayerData.Ship :
             //        null;
             //}
             //// kill the ship
             //playerData.Ship.Die(source, false);
         }
     }
 }