Beispiel #1
0
        private void ReadWin(PacketData data)
        {
            bool hasWinner = data.Data.ReadBoolean();
            byte winnerID = data.Data.ReadByte();

            foreach (Entity ship in Engine.Instance.Scene[PlayerShip.TAG])
                ship.Collidable = false;

            if (hasWinner)
            {
                if (ParentGamer.Id == winnerID)
                    ++ParentGamer[(int)TestProject.GamerProperties.Wins];
                else
                    ++ParentGamer[(int)TestProject.GamerProperties.Losses];
            }
            else
            {
                ++ParentGamer[(int)TestProject.GamerProperties.Wins];
                ++ParentGamer[(int)TestProject.GamerProperties.Losses];
            }
        }
Beispiel #2
0
 private void ReadWinnerData(PacketData data)
 {
     int numWinners = data.Data.ReadByte();
     ParentSession.WinnersSet = true;
     ParentSession.Winners.Clear();
     for (int i = 0; i < numWinners; ++i)
         ParentSession.Winners.Add(ParentSession.GetGamerFromId(data.Data.ReadByte()));
 }
Beispiel #3
0
 private void ReadTimeSync(PacketData data)
 {
     TimeSpan newDifference = Engine.Instance.GameTime.TotalGameTime - TimeSpan.FromSeconds(data.Data.ReadDouble());
     if (data.Sender.hasSetTimeDifference)
         data.Sender.TimeDifference = TimeSpan.FromMilliseconds((data.Sender.TimeDifference.TotalMilliseconds * 0.5f) + (newDifference.TotalMilliseconds * 0.5f));
     else
         data.Sender.TimeDifference = newDifference;
     data.Sender.hasSetTimeDifference = true;
 }
Beispiel #4
0
 private void ReadScore(PacketData data)
 {
     data.Sender.score = data.Data.ReadInt32();
 }
Beispiel #5
0
 private void ReadProperties(PacketData data)
 {
     for (int i = 0; i < 8; ++i)
     {
         bool hasValue = data.Data.ReadBoolean();
         data.Sender.Properties[i] = (hasValue ? (int?)data.Data.ReadInt32() : null);
     }
 }
Beispiel #6
0
 private void ReadNetworksDiagnosticsData(PacketData data)
 {
     Network.ActiveSession.NativeSession.SimulatedPacketLoss = data.Data.ReadAlpha();
     Network.ActiveSession.NativeSession.SimulatedLatency = TimeSpan.FromMilliseconds(5 * (int)data.Data.ReadByte());
     Network.ActiveSession.packetRate = data.Data.ReadAlpha();
     Network.ActiveSession.SystemFlags = data.Data.ReadByte();
 }
Beispiel #7
0
 private void ReadGamerFlags(PacketData data)
 {
     data.Sender.Flags = (int)data.Data.ReadByte();
 }
Beispiel #8
0
        internal void ReadPackets()
        {
            while (LocalNetworkGamer.IsDataAvailable)
            {
                NetworkGamer sender;
                LocalNetworkGamer.ReceiveData(reader, out sender);
                if (sender.IsLocal || sender.IsDisposed)
                    continue;
            #if DEBUG
                Log.Trace(String.Format("{0} received packet of length {1}", GamerTag, reader.Length), 0.2f);
            #endif

                byte type;
                int tempData;
                bool limitById = false;
                byte playerId;
                int length;
                uint timestamp;
                int nextPosition = 0;
                PacketData packetData = new PacketData();
                packetData.Data = reader;

                RemoteGamer gamer = sender.Tag as RemoteGamer;

                packetData.Sender = gamer;
                packetData.PredictionEnabled = ParentSession.PredictionEnabled;
                packetData.SmoothingEnabled = ParentSession.SmoothingEnabled;

                while (reader.Position < reader.Length)
                {
                    //read type
                    type = reader.ReadByte();

                    //read length and use player id
                    tempData = reader.ReadInt16();
                    limitById = Calc.ReadBool(ref tempData);
                    length = Calc.ReadInt(ref tempData, 15);

                    //read player id
                    playerId = reader.ReadByte();

                    //read timestamp
                    timestamp = reader.ReadUInt32();
                    TimeSpan difference = Engine.Instance.GameTime.TotalGameTime - TimeSpan.FromSeconds(timestamp / 100f);
                    difference -= gamer.TimeDifference - ParentSession.NativeSession.SimulatedLatency - gamer.HalfRoundtripTime;

                    packetData.TimeStamp = Engine.Instance.GameTime.TotalGameTime - difference;

                    packetData.Type = type;

                    packetData.LatencyMS = (float)difference.TotalMilliseconds;
                    packetData.LatencyFrames = packetData.LatencyMS / (float)Engine.Instance.TargetElapsedTime.TotalMilliseconds;

                    //increment position
                    nextPosition += length + 8;

            #if DEBUG
                    //Log.Trace(String.Format("Packet of type {0} and length {1}, Latency of {2} frames", type, length, packetData.LatencyFrames), 1.0f);
            #endif

                    if (!limitById || playerId == Id)
                    {
                        bool success = Actions != null && Actions.ProcessPacket(packetData);
                        if ( !success )
                        {
                            foreach(PacketActions action in additionalActions)
                                success = action.ProcessPacket(packetData);
                        }
                        if (!success)
                        {
                            if (!systemActions.ProcessPacket(packetData))
                                Log.Trace(String.Format("Unrecognized Packet Type {0}", type), 1.0f);
                        }
                    }

                    reader.Position = nextPosition;
                }
            }
        }
Beispiel #9
0
        internal bool ProcessPacket(PacketData data)
        {
            PacketAction action = this[data.Type];

            if (action != null)
            {
                action(data);
                return true;
            }
            else
            {
                return false;
            }
        }
 private void ReadGameStart(PacketData data)
 {
     GameStarted = true;
     updateShipAlarm.Start();
     updateBombAlarm.Start();
 }
 private void ReadGameEnd(PacketData data)
 {
 }
 private void ReadBombsAllowed(PacketData data)
 {
     BombsAllowed = data.Data.ReadBoolean();
 }