Beispiel #1
0
 public void SendToAll(NetworkSession networkSession, Microsoft.Xna.Framework.Net.PacketWriter writer, SendDataOptions option)
 {
     foreach (NetworkGamer gamer in networkSession.RemoteGamers)
     {
         networkSession.LocalGamers[0].SendData(writer, option, gamer);
     }
 }
Beispiel #2
0
        public NetGame(NetPlay _netPlay)
        {
            netPlay = _netPlay;

            writer = new PacketWriter();
            reader = new PacketReader();
        }
Beispiel #3
0
 public NetworkManager()
 {
     _maxGamers = 3;
     _maxLocalGamers = 2;
     _reader = new PacketReader();
     _writer = new PacketWriter();
 }
Beispiel #4
0
 public Network(Game1 GameReference)
 {
     game1 = GameReference;
     TimeLastPosUpdate = Environment.TickCount;
     packetWriter = new PacketWriter();
     packetReader = new PacketReader();
     TimeSinceLastJoinGame = Environment.TickCount;
 }
Beispiel #5
0
 public LobbyScreen(NetworkSession networkSession)
 {
     _networkSession = networkSession;
     TransitionOnTime = TimeSpan.FromSeconds(0.5);
     TransitionOffTime = TimeSpan.FromSeconds(0.5);
     _packetReader = new PacketReader();
     _packetWriter = new PacketWriter();
 }
 public static void sendStateToNetwork(this CarActor carActor, PacketWriter writer)
 {
     // read values from carActor and send over network:
     // position, orientation and velocity
     writer.Write(carActor.WorldTransform);
     writer.Write(carActor.LinearVelocity);
     writer.Write(carActor.AngularVelocity);
 }
Beispiel #7
0
 public override void NetWrite(PacketWriter writer)
 {
     writer.Write(NetGame.MSG_PARTICLE);
     writer.Write(Particle.PARTICLE_FOG);
     writer.Write(Background);
     writer.Write(NetPacker.BigFloatToShort(Location.X));
     writer.Write(NetPacker.BigFloatToShort(Location.Y));
 }
        /// <summary>
        /// Send the local gamer's local player count to network.
        /// </summary>
        public static void SendToNetwork(this LocalNetworkGamer localGamer)
        {
            PacketWriter writer = new PacketWriter();
            writer.Write(PacketHeader.LOBBY_DATA);
            writer.Write(localGamer.GetLocalPlayerCount());

            // send in order, since old data must not overwrite the new data.
            localGamer.SendData(writer, SendDataOptions.InOrder);
        }
Beispiel #9
0
        internal LocalGamer(SignedInGamer gamer)
        {
            SignedInGamer = gamer;
            SignedInGamer.Tag = this;

            reader = new PacketReader();
            Writer = new PacketWriter();

            InitializeSystemPackets();
        }
 protected override void SendToNetwork(GameTime gameTime)
 {
     // write input to all players :
     // Packets are sent inorder to make sure the world state never goes backwards in time
     // Packets can still get lost, however.
     PacketWriter writer = new PacketWriter();
     writer.Write(PacketHeader.INGAME_DATA);
     foreach (CarActor carActor in idTocarActorMap_[localGamer_.Id]) carActor.sendToNetwork(writer);
     localGamer_.SendData(writer, SendDataOptions.InOrder);
 }
Beispiel #11
0
 public Reseau()
 {
     downBool = false;
     jumpBool = false;
     setPerso = false;
     perso = "renoi";
     // Receive/Send
     reader = new PacketReader();
     writer = new PacketWriter();
     player2 = new Player2(Ressources.GetPerso(perso).heroTexture, Ressources.GetPerso(perso).heroTextureAnime, Vector2.Zero);
 }
Beispiel #12
0
        /// <summary>
        /// Serialize the current object to a packet.
        /// </summary>
        /// <param name="packetWriter">The packet writer that receives the data.</param>
        public void Serialize(PacketWriter packetWriter)
        {
            // safety-check the parameter, as it must be valid.
            if (packetWriter == null)
            {
                throw new ArgumentNullException("packetWriter");
            }

            //packetWriter.Write(ShipColor);
            //packetWriter.Write(ShipVariation);
        }
Beispiel #13
0
        public override void NetWrite(PacketWriter writer)
        {
            writer.Write(NetGame.MSG_PARTICLE);
            writer.Write(Particle.PARTICLE_SHOCKWAVE);
            writer.Write(Background);
            writer.Write(NetPacker.BigFloatToShort(Location.X));
            writer.Write(NetPacker.BigFloatToShort(Location.Y));

            writer.Write(NetPacker.MidFloatToShort(size));
            writer.Write(refract);
        }
Beispiel #14
0
        public override void NetWrite(PacketWriter writer)
        {
            writer.Write(NetGame.MSG_PARTICLE);
            writer.Write(Particle.PARTICLE_ROCKET);
            writer.Write(Background);
            writer.Write(NetPacker.BigFloatToShort(Location.X));
            writer.Write(NetPacker.BigFloatToShort(Location.Y));

            writer.Write(NetPacker.BigFloatToShort(Trajectory.X));
            writer.Write(NetPacker.BigFloatToShort(Trajectory.Y));

            writer.Write(NetPacker.IntToSbyte(owner));
        }
Beispiel #15
0
        public override void NetWrite(PacketWriter writer)
        {
            writer.Write(NetGame.MSG_PARTICLE);
            writer.Write(Particle.PARTICLE_MUZZLEFLASH);
            writer.Write(Background);
            writer.Write(NetPacker.BigFloatToShort(Location.X));
            writer.Write(NetPacker.BigFloatToShort(Location.Y));

            writer.Write(NetPacker.BigFloatToShort(Trajectory.X));
            writer.Write(NetPacker.BigFloatToShort(Trajectory.Y));

            writer.Write(NetPacker.SmallFloatToShort(size));
        }
        public HideSeek()
            : base()
        {
            graphics = new GraphicsDeviceManager (this);
            graphics.IsFullScreen = false;
            Content.RootDirectory = "Content";

            caixaSaida = new PacketWriter ();
            caixaEntrada = new PacketReader ();

            splashScr = new SplashScreen ();

            this.IsFixedTimeStep = true;
            this.TargetElapsedTime = TimeSpan.FromSeconds (0.33f);
        }
Beispiel #17
0
        public override void NetWrite(PacketWriter writer)
        {
            writer.Write(NetGame.MSG_PARTICLE);
            writer.Write(Particle.PARTICLE_SMOKE);
            writer.Write(Background);
            writer.Write(NetPacker.BigFloatToShort(Location.X));
            writer.Write(NetPacker.BigFloatToShort(Location.Y));

            writer.Write(NetPacker.BigFloatToShort(Trajectory.X));
            writer.Write(NetPacker.BigFloatToShort(Trajectory.Y));

            writer.Write(NetPacker.TinyFloatToByte(r));
            writer.Write(NetPacker.TinyFloatToByte(g));
            writer.Write(NetPacker.TinyFloatToByte(b));
            writer.Write(NetPacker.TinyFloatToByte(a));

            writer.Write(NetPacker.SmallFloatToShort(size));
            writer.Write(NetPacker.IntToSbyte(flag));
        }
Beispiel #18
0
        public NetworkSession CreateSession()
        {
            session = NetworkSession.Create(NetworkSessionType.SystemLink, MAX_LOCAL_PLAYERS, MAX_TOTAL_PLAYERS);

            session.AllowHostMigration = true;
            session.AllowJoinInProgress = true;

            session.GamerJoined += new EventHandler<GamerJoinedEventArgs>(session_GamerJoined);
            session.GamerLeft += new EventHandler<GamerLeftEventArgs>(session_GamerLeft);
            session.GameStarted += new EventHandler<GameStartedEventArgs>(session_GameStarted);
            session.GameEnded += new EventHandler<GameEndedEventArgs>(session_GameEnded);
            session.SessionEnded += new EventHandler<NetworkSessionEndedEventArgs>(session_SessionEnded);

            pr = new PacketReader();
            pw = new PacketWriter();

            sender = session.LocalGamers[0];

            return session;
        }
Beispiel #19
0
        internal void InitializeSystemPackets()
        {
            systemActions = new PacketActions();
            systemActions.isSystem = true;

            systemActions[PacketActions.PacketTypeGamerFlags] = ReadGamerFlags;
            systemActions[PacketActions.PacketTypeNetworkDiagnostics] = ReadNetworksDiagnosticsData;
            systemActions[PacketActions.PacketTypeTimeSync] = ReadTimeSync;
            systemActions[PacketActions.PacketTypeSetWinners] = ReadWinnerData;
            systemActions[PacketActions.PacketTypeSetScore] = ReadScore;
            systemActions[PacketActions.PacketTypeSetProperties] = ReadProperties;

            systemWriter = new PacketWriter();

            secureBuffer = new PacketWriter();
            fastBuffer = new PacketWriter();
            reliableBuffer = new PacketWriter();
            superfastBuffer = new PacketWriter();
        }
Beispiel #20
0
        internal override void Clear()
        {
            base.Clear();

            if ( Actions != null )
                Actions.ClearActions();
            Actions = null;

            ClearActions();
            additionalActions = null;

            systemActions = null;

            secureBuffer.Dispose();
            secureBuffer = null;

            Writer.Dispose();
            Writer = null;

            OnUpdate = null;

            LocalNetworkGamer = null;
            SignedInGamer = null;
        }
Beispiel #21
0
        public void SendPacketSecure(PacketWriter data, byte packetType, RemoteGamer targetGamer)
        {
            //write packet type
            secureBuffer.Write(packetType);

            //write length and use id
            int tempData = 0;
            Calc.WriteInt(ref tempData, 15, data.Length);
            Calc.WriteBool(ref tempData, targetGamer != null);
            secureBuffer.Write((short)tempData);

            //write player id
            byte playerId = (byte)(targetGamer != null ? targetGamer.Id : 0);
            secureBuffer.Write(playerId);

            //write timestamp
            uint timestamp = (uint)(Engine.Instance.GameTime.TotalGameTime.TotalSeconds * 100);
            secureBuffer.Write(timestamp);

            //write data
            data.Position = 0;
            //data.BaseStream.CopyTo(secureBuffer.BaseStream);
            secureBuffer.Write(data.ToByteArray());

            data.Clear();
        }
Beispiel #22
0
 public void SendData(PacketWriter data, SendDataOptions options, NetworkGamer recipient)
 {
     this.SendData(data.Data, 0, data.Length, options, recipient);
     data.Reset();
 }
Beispiel #23
0
 /// <summary>
 /// Helper method to write the network value to the PacketWriter
 /// </summary>
 /// <param name="packetWriter"></param>
 /// <param name="networkValue"></param>
 private static void WriteNetworkValue(ref PacketWriter packetWriter, object networkValue)
 {
     if (networkValue == null)
         throw new CoreException("NetworkValue is null");
     else
     {
         if (networkValue is bool)
             packetWriter.Write((bool) networkValue);
         else if (networkValue is byte)
             packetWriter.Write((byte) networkValue);
         else if (networkValue is byte[])
         {
             var tempByteArray = (byte[]) networkValue;
             packetWriter.Write(tempByteArray.Length);
             packetWriter.Write(tempByteArray);
         }
         else if (networkValue is char)
             packetWriter.Write((char) networkValue);
         else if (networkValue is char[])
         {
             var tempCharArray = (char[]) networkValue;
             packetWriter.Write(tempCharArray.Length);
             packetWriter.Write(tempCharArray);
         }
         else if (networkValue is Color)
             packetWriter.Write((Color) networkValue);
         else if (networkValue is double)
             packetWriter.Write((double) networkValue);
         else if (networkValue is float)
             packetWriter.Write((float) networkValue);
         else if (networkValue is int)
             packetWriter.Write((int) networkValue);
         else if (networkValue is long)
             packetWriter.Write((long) networkValue);
         else if (networkValue is Matrix)
             packetWriter.Write((Matrix) networkValue);
         else if (networkValue is Quaternion)
             packetWriter.Write((Quaternion) networkValue);
         else if (networkValue is sbyte)
             packetWriter.Write((sbyte) networkValue);
         else if (networkValue is short)
             packetWriter.Write((short) networkValue);
         else if (networkValue is string)
             packetWriter.Write((string) networkValue);
         else if (networkValue is uint)
             packetWriter.Write((uint) networkValue);
         else if (networkValue is ulong)
             packetWriter.Write((ulong) networkValue);
         else if (networkValue is ushort)
             packetWriter.Write((ushort) networkValue);
         else if (networkValue is Vector2)
             packetWriter.Write((Vector2) networkValue);
         else if (networkValue is Vector3)
             packetWriter.Write((Vector3) networkValue);
         else if (networkValue is Vector4)
             packetWriter.Write((Vector4) networkValue);
         else
         {
             throw new CoreException("NetworkValue type isn't supported");
         }
     }
 }
Beispiel #24
0
        /*
         * Sends a game packet
         */
        void sendGamePacket(bool stalled)
        {
            if (stalled)
                return;
            writer.Write((byte)2);
            writer.Write(stallCounter);
            writer.Write(owd);
            writer.Write(frameNumber + latency);
            byte events = 0;

            //Count how many events we will send
            for (int i = secondLRF; i <= frameNumber; i++)
                events += frames[i].events;

            writer.Write(events);

            //Write each of those frames to the packet
            for (int i = secondLRF; i <= frameNumber; i++)
                writeFrame(frames[i]);

            //If we are not stalled send the packet to everyone
            if (!stalled)
            {
                networkSession.SimulatedPacketLoss = .1f;
                networkSession.LocalGamers[0].SendData(writer, SendDataOptions.None);
            }
            else
            {
                PacketWriter w2 = writer;
                for (int i = 0; i < others.Length; i++)
                {
                    if (others[i].framesOfPlayer.ContainsKey(frameNumber) == false && others[i] != myPlayer)
                    {
                        writer = w2;
                        networkSession.LocalGamers[0].SendData(writer, SendDataOptions.None);
                    }
                }
            }
        }
Beispiel #25
0
 private OutputQueue()
 {
     outQueue = new Queue<QueueHdr>();
     packetWriter = new PacketWriter();
 }
Beispiel #26
0
		public void SendData (
         PacketWriter data,
         SendDataOptions options,
         NetworkGamer recipient
)
		{
			throw new NotImplementedException();
		}
Beispiel #27
0
		public void SendData (
         PacketWriter data,
         SendDataOptions options
)
		{
			throw new NotImplementedException();
		}
Beispiel #28
0
 public void SendData(PacketWriter data, SendDataOptions options)
 {
     this.SendData(data.Data, 0, data.Length, options, (NetworkGamer)null);
     data.Reset();
 }
 /// <summary>
 /// Write all sendable particles to the network packet writer.
 /// </summary>
 /// <param name="writer">PacketWriter to write to</param>
 public void NetWriteParticles(PacketWriter writer)
 {
     for (int i = 0; i < particle.Length; i++)
         if (particle[i] != null)
         {
             if (particle[i].netSend)
             {
                 particle[i].NetWrite(writer);
                 particle[i].netSend = false;
             }
         }
 }
Beispiel #30
0
        // Constructor
        public Game06()
        {
            musicControl = new MusicControl();


            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Make the game object.  The game is currently called 'DuckSlaughterGame'.

            deterministicGame = new DuckSlaughterGame();

            // Debugging setup

            lastPressedKeys = new List<Keys>();
            activePlayer = playerIdentifiers[0];
            paused = false;
            gameStarted = false;


            //Added
            Components.Add(new GamerServicesComponent(this));
            isHost = false;
            chatText = "";
            reader = new PacketReader();
            writer = new PacketWriter();
            chatlines = 0;
            isChatting = false;
            mouseChange = false;
            buttonPressed = false;
            others = new player[4];
            update = true;

            inMenu = true;
            releasedKeys = new List<Keys>();


        }
Beispiel #31
0
		public void SendData (
			PacketWriter data,
			SendDataOptions options)
		{
			SendData(data.Data, 0, data.Length, options, null);
			data.Reset();
		}
Beispiel #32
0
        void restart()
        {
            youLoseSound.Play();
            deterministicGame.currentLevel.gameRestart = false;

            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferredBackBufferWidth = 800;
            graphics.ApplyChanges();


            musicControl.Restart();


            // Make the game object.  The game is currently called 'DuckSlaughterGame'
            deterministicGame = new DuckSlaughterGame();
            deterministicGame.ResetGame(playerIdentifiers, playerIdentifiers[0]);
            deterministicGame.LoadContent(Content);
            deterministicGame.Initialize();

            // Debugging setup
            lastPressedKeys = new List<Keys>();
            activePlayer = playerIdentifiers[0];
            paused = false;
            gameStarted = false;


            //Added
            isHost = false;
            chatText = "";

            reader.Close();
            writer.Close();

            networkSession.Dispose();

            networkSession = null;

            reader = new PacketReader();
            writer = new PacketWriter();
            chatlines = 0;
            isChatting = false;
            mouseChange = false;
            buttonPressed = false;
            others = new player[4];
            update = true;
            gameStarted = false;

            inMenu = true;
            startS.Show();
            helpS.Hide();
            activeS = startS;
            releasedKeys = new List<Keys>();
        }
Beispiel #33
0
		public void SendData (
			PacketWriter data,
			SendDataOptions options,
			NetworkGamer recipient)
		{
			SendData(data.Data, 0, data.Length, options, recipient);
			data.Reset();
		}