Ejemplo n.º 1
0
        public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
        {
            SetState(msg.ReadBoolean(), true);
            Stuck = msg.ReadRangedSingle(0.0f, 100.0f, 8);

            predictedState = null;
        }
Ejemplo n.º 2
0
        public void ClientWrite(Lidgren.Network.NetBuffer msg, object[] extraData = null)
        {
            msg.Write(autoPilot);
            msg.Write(dockingNetworkMessagePending);
            dockingNetworkMessagePending = false;

            if (!autoPilot)
            {
                //no need to write steering info if autopilot is controlling
                msg.Write(steeringInput.X);
                msg.Write(steeringInput.Y);
            }
            else
            {
                msg.Write(posToMaintain != null);
                if (posToMaintain != null)
                {
                    msg.Write(((Vector2)posToMaintain).X);
                    msg.Write(((Vector2)posToMaintain).Y);
                }
                else
                {
                    msg.Write(LevelStartSelected);
                }
            }
        }
Ejemplo n.º 3
0
        public void ServerWrite(Lidgren.Network.NetBuffer message, Client client, object[] extraData = null)
        {
            if (GameMain.Server == null)
            {
                return;
            }

            SpawnOrRemove entities = (SpawnOrRemove)extraData[0];

            message.Write(entities.Remove);

            if (entities.Remove)
            {
                message.Write(entities.Entity.ID);
            }
            else
            {
                if (entities.Entity is Item)
                {
                    message.Write((byte)SpawnableType.Item);
                    ((Item)entities.Entity).WriteSpawnData(message);
                }
                else if (entities.Entity is Character)
                {
                    message.Write((byte)SpawnableType.Character);
                    ((Character)entities.Entity).WriteSpawnData(message);
                }
            }
        }
Ejemplo n.º 4
0
        public void ServerWrite(Lidgren.Network.NetBuffer message, Client client, object[] extraData = null)
        {
            if (GameMain.Server == null)
            {
                return;
            }

            SpawnOrRemove entities = (SpawnOrRemove)extraData[0];

            message.Write(entities.Remove);

            if (entities.Remove)
            {
                message.Write(entities.Entity.ID);
            }
            else
            {
                if (entities.Entity is Item)
                {
                    message.Write((byte)SpawnableType.Item);
                    ((Item)entities.Entity).WriteSpawnData(message);
                }
                else if (entities.Entity is Character)
                {
                    message.Write((byte)SpawnableType.Character);
                    //DebugConsole.NewMessage("WRITING CHARACTER DATA: " + (entities.Entity).ToString() + " (ID: " + entities.Entity.ID + ")", Color.Cyan);
                    ((Character)entities.Entity).WriteSpawnData(message);
                }
            }
        }
Ejemplo n.º 5
0
        public void ServerWrite(Lidgren.Network.NetBuffer message, Client client, object[] extraData = null)
        {
            if (GameMain.Server == null)
            {
                return;
            }

            SpawnOrRemove entities = (SpawnOrRemove)extraData[0];

            message.Write(entities.Remove);

            if (entities.Remove)
            {
                message.Write(entities.Entity.ID);
            }
            else
            {
                if (entities.Entity is Item)
                {
                    message.Write((byte)SpawnableType.Item);
                    DebugConsole.Log("Writing item spawn data " + entities.Entity.ToString() + " (ID: " + entities.Entity.ID + ")");
                    ((Item)entities.Entity).WriteSpawnData(message);
                }
                else if (entities.Entity is Character)
                {
                    message.Write((byte)SpawnableType.Character);
                    DebugConsole.Log("Writing character spawn data: " + entities.Entity.ToString() + " (ID: " + entities.Entity.ID + ")");
                    ((Character)entities.Entity).WriteSpawnData(message);
                }
            }
        }
Ejemplo n.º 6
0
        public override void ServerWrite(Lidgren.Network.NetBuffer msg, Client c, object[] extraData = null)
        {
            base.ServerWrite(msg, c, extraData);

            msg.Write(isOpen);
            msg.WriteRangedSingle(stuck, 0.0f, 100.0f, 8);
        }
Ejemplo n.º 7
0
        public static Guid ReadGuid(this Lidgren.Network.NetBuffer target)
        {
            int guidLength = target.ReadInt32();

            byte[] guidBytes = target.ReadBytes(guidLength);
            return(new Guid(guidBytes));
        }
Ejemplo n.º 8
0
        public void ServerWrite(Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c, object[] extraData = null)
        {
            msg.Write(autoPilot);

            if (!autoPilot)
            {
                //no need to write steering info if autopilot is controlling
                msg.Write(steeringInput.X);
                msg.Write(steeringInput.Y);
                msg.Write(targetVelocity.X);
                msg.Write(targetVelocity.Y);
                msg.Write(steeringAdjustSpeed);
            }
            else
            {
                msg.Write(posToMaintain != null);
                if (posToMaintain != null)
                {
                    msg.Write(((Vector2)posToMaintain).X);
                    msg.Write(((Vector2)posToMaintain).Y);
                }
                else
                {
                    msg.Write(LevelStartSelected);
                }
            }
        }
Ejemplo n.º 9
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
        {
            bool    autoPilot         = msg.ReadBoolean();
            Vector2 newTargetVelocity = targetVelocity;
            bool    maintainPos       = false;
            Vector2?newPosToMaintain  = null;
            bool    headingToStart    = false;

            if (autoPilot)
            {
                maintainPos = msg.ReadBoolean();
                if (maintainPos)
                {
                    newPosToMaintain = new Vector2(
                        msg.ReadFloat(),
                        msg.ReadFloat());
                }
                else
                {
                    headingToStart = msg.ReadBoolean();
                }
            }
            else
            {
                newTargetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (!item.CanClientAccess(c))
            {
                return;
            }

            AutoPilot = autoPilot;

            if (!AutoPilot)
            {
                targetVelocity = newTargetVelocity;
            }
            else
            {
                MaintainPos   = newPosToMaintain != null;
                posToMaintain = newPosToMaintain;

                if (posToMaintain == null)
                {
                    LevelStartSelected = headingToStart;
                    LevelEndSelected   = !headingToStart;
                    UpdatePath();
                }
                else
                {
                    LevelStartSelected = false;
                    LevelEndSelected   = false;
                }
            }

            //notify all clients of the changed state
            unsentChanges = true;
        }
Ejemplo n.º 10
0
        public override void ServerWrite(Lidgren.Network.NetBuffer msg, Client c, object[] extraData = null)
        {
            base.ServerWrite(msg, c, extraData);

            msg.Write(isOpen);
            msg.Write(extraData.Length == 3 ? (bool)extraData[2] : false); //forced open
            msg.WriteRangedSingle(stuck, 0.0f, 100.0f, 8);
        }
Ejemplo n.º 11
0
        public override void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
        {
            base.ClientRead(type, msg, sendingTime);

            SetState(msg.ReadBoolean(), isNetworkMessage: true, sendNetworkMessage: false);
            Stuck = msg.ReadRangedSingle(0.0f, 100.0f, 8);

            PredictedState = null;
        }
Ejemplo n.º 12
0
        public void ServerWrite(Lidgren.Network.NetBuffer msg, Client c, object[] extraData = null)
        {
            msg.Write(docked);

            if (docked)
            {
                msg.Write(dockingTarget.item.ID);
                msg.Write(hulls != null && hulls[0] != null && hulls[1] != null && gap != null);
            }
        }
Ejemplo n.º 13
0
        public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
        {
            if (correctionTimer > 0.0f)
            {
                StartDelayedCorrection(type, msg.ExtractBits(1), sendingTime);
                return;
            }

            IsActive = msg.ReadBoolean();
            isActiveTickBox.Selected = IsActive;
        }
Ejemplo n.º 14
0
        public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
        {
            if (correctionTimer > 0.0f)
            {
                StartDelayedCorrection(type, msg.ExtractBits(5 + 1), sendingTime);
                return;
            }

            FlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
            IsActive       = msg.ReadBoolean();
        }
Ejemplo n.º 15
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Client c)
        {
            float newFlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
            bool  newIsActive       = msg.ReadBoolean();

            if (item.CanClientAccess(c))
            {
                if (newFlowPercentage != FlowPercentage)
                {
                    GameServer.Log(c.Character.LogName + " set the pumping speed of " + item.Name + " to " + (int)(newFlowPercentage) + " %", ServerLog.MessageType.ItemInteraction);

                    if (GameMain.NilMod.EnableGriefWatcher && NilMod.NilModGriefWatcher.PumpPositive && newFlowPercentage > FlowPercentage && newFlowPercentage > 0)
                    {
                        //Only blame one client at a time - they started it first.
                        if (!CoroutineManager.IsCoroutineRunning("WarnPump_" + item.ID))
                        {
                            CoroutineManager.StartCoroutine(WarnPump(c), "WarnPump_" + item.ID);
                        }

                        /*
                         * NilMod.NilModGriefWatcher.SendWarning(c.Character.LogName
                         + " Set " + item.Name + " to pump in at "
                         + (int)(newFlowPercentage) + " %"
                         + (newIsActive ? " (On) " : " (Off) "), c);
                         */
                    }
                }
                if (newIsActive != IsActive)
                {
                    GameServer.Log(c.Character.LogName + (newIsActive ? " turned on " : " turned off ") + item.Name, ServerLog.MessageType.ItemInteraction);

                    if (GameMain.NilMod.EnableGriefWatcher && NilMod.NilModGriefWatcher.PumpOff && IsActive)
                    {
                        //Only blame one client at a time - they started it first.
                        if (!CoroutineManager.IsCoroutineRunning("WarnPump_" + item.ID))
                        {
                            CoroutineManager.StartCoroutine(WarnPump(c), "WarnPump_" + item.ID);
                        }

                        /*
                         * NilMod.NilModGriefWatcher.SendWarning(c.Character.LogName
                         + " turned off " + item.Name
                         + " (" + (int)(newFlowPercentage) + " % Speed)", c);
                         */
                    }
                }

                FlowPercentage = newFlowPercentage;
                IsActive       = newIsActive;
            }

            //notify all clients of the changed state
            item.CreateServerEvent(this);
        }
Ejemplo n.º 16
0
        public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
        {
            bool isDocked = msg.ReadBoolean();

            for (int i = 0; i < 2; i++)
            {
                if (hulls[i] == null)
                {
                    continue;
                }
                item.linkedTo.Remove(hulls[i]);
                hulls[i].Remove();
                hulls[i] = null;
            }

            if (gap != null)
            {
                item.linkedTo.Remove(gap);
                gap.Remove();
                gap = null;
            }

            if (isDocked)
            {
                ushort dockingTargetID = msg.ReadUInt16();

                bool isLocked = msg.ReadBoolean();

                Entity targetEntity = Entity.FindEntityByID(dockingTargetID);
                if (targetEntity == null || !(targetEntity is Item))
                {
                    DebugConsole.ThrowError("Invalid docking port network event (can't dock to " + targetEntity.ToString() + ")");
                    return;
                }

                dockingTarget = (targetEntity as Item).GetComponent <DockingPort>();
                if (dockingTarget == null)
                {
                    DebugConsole.ThrowError("Invalid docking port network event (" + targetEntity + " doesn't have a docking port component)");
                    return;
                }

                Dock(dockingTarget);

                if (isLocked)
                {
                    Lock(true);
                }
            }
            else
            {
                Undock();
            }
        }
Ejemplo n.º 17
0
 public void ClientWrite(Lidgren.Network.NetBuffer msg, object[] extraData = null)
 {
     msg.Write(IsActive);
     if (IsActive)
     {
         msg.WriteRangedSingle(zoom, MinZoom, MaxZoom, 8);
         msg.Write(useDirectionalPing);
         if (useDirectionalPing)
         {
             msg.WriteRangedSingle(directionalSlider.BarScroll, 0.0f, 1.0f, 8);
         }
     }
 }
Ejemplo n.º 18
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
        {
            bool isActive = msg.ReadBoolean();

            if (!item.CanClientAccess(c))
            {
                return;
            }

            IsActive = isActive;
            isActiveTickBox.Selected = IsActive;

            item.CreateServerEvent(this);
        }
Ejemplo n.º 19
0
 public void ServerWrite(Lidgren.Network.NetBuffer msg, Client c, object[] extraData = null)
 {
     msg.Write(IsActive);
     if (IsActive)
     {
         msg.WriteRangedSingle(zoom, MinZoom, MaxZoom, 8);
         msg.Write(useDirectionalPing);
         if (useDirectionalPing)
         {
             float pingAngle = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(pingDirection));
             msg.WriteRangedSingle(MathUtils.InverseLerp(0.0f, MathHelper.TwoPi, pingAngle), 0.0f, 1.0f, 8);
         }
     }
 }
Ejemplo n.º 20
0
        public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
        {
            bool isDocked = msg.ReadBoolean();

            if (isDocked)
            {
                ushort dockingTargetID = msg.ReadUInt16();

                bool isLocked = msg.ReadBoolean();

                if (isLocked)
                {
                    hullIds[0] = msg.ReadUInt16();
                    hullIds[1] = msg.ReadUInt16();
                    gapId      = msg.ReadUInt16();
                }

                Entity targetEntity = Entity.FindEntityByID(dockingTargetID);
                if (targetEntity == null || !(targetEntity is Item))
                {
                    DebugConsole.ThrowError("Invalid docking port network event (can't dock to " + targetEntity.ToString() + ")");
                    return;
                }

                dockingTarget = (targetEntity as Item).GetComponent <DockingPort>();
                if (dockingTarget == null)
                {
                    DebugConsole.ThrowError("Invalid docking port network event (" + targetEntity + " doesn't have a docking port component)");
                    return;
                }

                Dock(dockingTarget);

                if (isLocked)
                {
                    Lock(true);

                    hulls[0].ID = (ushort)hullIds[0];
                    hulls[1].ID = (ushort)hullIds[1];
                    gap.ID      = (ushort)gapId;
                }
            }
            else
            {
                Undock();
            }
        }
Ejemplo n.º 21
0
        public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
        {
            long msgStartPos = msg.Position;

            bool  isActive        = msg.ReadBoolean();
            float zoomT           = 1.0f;
            bool  directionalPing = useDirectionalPing;
            float directionT      = 0.0f;

            if (isActive)
            {
                zoomT           = msg.ReadRangedSingle(0.0f, 1.0f, 8);
                directionalPing = msg.ReadBoolean();
                if (directionalPing)
                {
                    directionT = msg.ReadRangedSingle(0.0f, 1.0f, 8);
                }
            }

            if (correctionTimer > 0.0f)
            {
                int msgLength = (int)(msg.Position - msgStartPos);
                msg.Position = msgStartPos;
                StartDelayedCorrection(type, msg.ExtractBits(msgLength), sendingTime);
                return;
            }

            IsActive = isActive;
            if (isActive)
            {
                activeTickBox.Selected = true;
                zoomSlider.BarScroll   = zoomT;
                zoom = MathHelper.Lerp(MinZoom, MaxZoom, zoomT);
                if (directionalPing)
                {
                    directionalSlider.BarScroll = directionT;
                    float pingAngle = MathHelper.Lerp(0.0f, MathHelper.TwoPi, directionalSlider.BarScroll);
                    pingDirection = new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle));
                }
                useDirectionalPing = directionalTickBox.Selected = directionalPing;
            }
            else
            {
                passiveTickBox.Selected = true;
            }
        }
Ejemplo n.º 22
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Client c)
        {
            bool  isActive = msg.ReadBoolean();
            bool  directionalPing = useDirectionalPing;
            float zoomT = zoom, pingDirectionT = 0.0f;

            if (isActive)
            {
                zoomT           = msg.ReadRangedSingle(0.0f, 1.0f, 8);
                directionalPing = msg.ReadBoolean();
                if (directionalPing)
                {
                    pingDirectionT = msg.ReadRangedSingle(0.0f, 1.0f, 8);
                }
            }

            if (!item.CanClientAccess(c))
            {
                return;
            }

            IsActive = isActive;

            //TODO: cleanup
#if CLIENT
            activeTickBox.Selected = IsActive;
#endif
            if (isActive)
            {
                zoom = MathHelper.Lerp(MinZoom, MaxZoom, zoomT);
                useDirectionalPing = directionalPing;
                if (useDirectionalPing)
                {
                    float pingAngle = MathHelper.Lerp(0.0f, MathHelper.TwoPi, pingDirectionT);
                    pingDirection = new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle));
                }
#if CLIENT
                zoomSlider.BarScroll        = zoomT;
                directionalTickBox.Selected = useDirectionalPing;
                directionalSlider.BarScroll = pingDirectionT;
#endif
            }
#if SERVER
            item.CreateServerEvent(this);
#endif
        }
Ejemplo n.º 23
0
        public void WriteToMessage(Lidgren.Network.NetBuffer message)
        {
            //Client count
            message.Write(Clients.Count);                   //Int32
            //Clients
            for (int i = 0; i < Clients.Count; i++)
            {
                MatchClientState c = Clients[i];
                //Write guid (as byte array)
                message.Write(c.Guid);                      //Byte array w size
                //Write name
                message.Write(c.Name);                      //String
            }
            //Player count
            message.Write(Players.Count);
            //Players
            for (int i = 0; i < Players.Count; i++)
            {
                MatchPlayerState p = Players[i];
                //Client GUID (as byte array)
                message.Write(p.ClientGuid);                //Byte array w size
                //Control type enum as int
                message.Write((int)p.CtrlType);             //Int32 (Cast to ControlType)
                //Ready to race bool
                message.Write(p.ReadyToRace);               //Bool
                //Character id
                message.Write(p.CharacterId);               //Int32
            }
            //Match settings properties, written in the order they appear in code
            message.Write(Settings.StageId);                //Int32
            message.Write(Settings.Laps);                   //Int32
            message.Write(Settings.AICount);                //Int32
            message.Write((int)Settings.AISkill);           //Int32 (Cast to AISkillLevel)
            message.Write(Settings.AutoStartTime);          //Int32
            message.Write(Settings.AutoStartMinPlayers);    //Int32
            message.Write(Settings.AutoReturnTime);         //Int32
            message.Write(Settings.VoteRatio);              //Float
            message.Write((int)Settings.StageRotationMode); //Int32 (Cast to StageRotationMode)

            //In race
            message.Write(InRace);
            //Cur auto start time
            message.Write(CurAutoStartTime);
        }
Ejemplo n.º 24
0
        public static MatchState ReadFromMessage(Lidgren.Network.NetBuffer message)
        {
            //Clients
            int clientCount = message.ReadInt32();
            List <MatchClientState> clients = new List <MatchClientState>();

            for (int i = 0; i < clientCount; i++)
            {
                System.Guid guid = message.ReadGuid();
                string      name = message.ReadString();

                clients.Add(new MatchClientState(guid, name));
            }
            //Players
            int playerCount = message.ReadInt32();
            List <MatchPlayerState> players = new List <MatchPlayerState>();

            for (int i = 0; i < playerCount; i++)
            {
                System.Guid clientGuid  = message.ReadGuid();
                ControlType ctrlType    = (ControlType)message.ReadInt32();
                bool        readyToRace = message.ReadBoolean();
                int         characterId = message.ReadInt32();

                players.Add(new MatchPlayerState(clientGuid, ctrlType, readyToRace, characterId));
            }
            //Match settings
            MatchSettings settings = new MatchSettings()
            {
                StageId             = message.ReadInt32(),
                Laps                = message.ReadInt32(),
                AICount             = message.ReadInt32(),
                AISkill             = (AISkillLevel)message.ReadInt32(),
                AutoStartTime       = message.ReadInt32(),
                AutoStartMinPlayers = message.ReadInt32(),
                AutoReturnTime      = message.ReadInt32(),
                VoteRatio           = message.ReadFloat(),
                StageRotationMode   = (StageRotationMode)message.ReadInt32()
            };
            bool  inRace           = message.ReadBoolean();
            float curAutoStartTime = message.ReadFloat();

            return(new MatchState(clients, players, settings, inRace, curAutoStartTime));
        }
Ejemplo n.º 25
0
        public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer message, float sendingTime)
        {
            if (GameMain.Server != null)
            {
                return;
            }

            bool remove = message.ReadBoolean();

            if (remove)
            {
                ushort entityId = message.ReadUInt16();

                var entity = FindEntityByID(entityId);
                if (entity != null)
                {
                    DebugConsole.Log("Received entity removal message for \"" + entity.ToString() + "\".");
                    entity.Remove();
                }
                else
                {
                    DebugConsole.Log("Received entity removal message for ID " + entityId + ". Entity with a matching ID not found.");
                }
            }
            else
            {
                switch (message.ReadByte())
                {
                case (byte)SpawnableType.Item:
                    Item.ReadSpawnData(message, true);
                    break;

                case (byte)SpawnableType.Character:
                    Character.ReadSpawnData(message, true);
                    break;

                default:
                    DebugConsole.ThrowError("Received invalid entity spawn message (unknown spawnable type)");
                    break;
                }
            }
        }
Ejemplo n.º 26
0
        public void ServerWrite(Lidgren.Network.NetBuffer msg, Client c, object[] extraData = null)
        {
            msg.Write(docked);

            if (docked)
            {
                msg.Write(dockingTarget.item.ID);

                if (hullIds[0] != null && hullIds[1] != null && gapId != null)
                {
                    msg.Write(true);
                    msg.Write((ushort)hullIds[0]);
                    msg.Write((ushort)hullIds[1]);
                    msg.Write((ushort)gapId);
                }
                else
                {
                    msg.Write(false);
                }
            }
        }
Ejemplo n.º 27
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Client c)
        {
            float newFlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
            bool  newIsActive       = msg.ReadBoolean();

            if (item.CanClientAccess(c))
            {
                if (newFlowPercentage != FlowPercentage)
                {
                    GameServer.Log(c.Character + " set the pumping speed of " + item.Name + " to " + (int)(newFlowPercentage) + " %", ServerLog.MessageType.ItemInteraction);
                }
                if (newIsActive != IsActive)
                {
                    GameServer.Log(c.Character + (newIsActive ? " turned on " : " turned off ") + item.Name, ServerLog.MessageType.ItemInteraction);
                }

                FlowPercentage = newFlowPercentage;
                IsActive       = newIsActive;
            }

            //notify all clients of the changed state
            item.CreateServerEvent(this);
        }
Ejemplo n.º 28
0
        public void ClientWrite(Lidgren.Network.NetBuffer msg, object[] extraData = null)
        {
            msg.Write(autoPilot);

            if (!autoPilot)
            {
                //no need to write steering info if autopilot is controlling
                msg.Write(targetVelocity.X);
                msg.Write(targetVelocity.Y);
            }
            else
            {
                msg.Write(posToMaintain != null);
                if (posToMaintain != null)
                {
                    msg.Write(((Vector2)posToMaintain).X);
                    msg.Write(((Vector2)posToMaintain).Y);
                }
                else
                {
                    msg.Write(levelStartTickBox.Selected);
                }
            }
        }
Ejemplo n.º 29
0
        public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
        {
            long msgStartPos = msg.Position;

            bool    autoPilot         = msg.ReadBoolean();
            Vector2 newTargetVelocity = targetVelocity;
            bool    maintainPos       = false;
            Vector2?newPosToMaintain  = null;
            bool    headingToStart    = false;

            if (autoPilot)
            {
                maintainPos = msg.ReadBoolean();
                if (maintainPos)
                {
                    newPosToMaintain = new Vector2(
                        msg.ReadFloat(),
                        msg.ReadFloat());
                }
                else
                {
                    headingToStart = msg.ReadBoolean();
                }
            }
            else
            {
                newTargetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (correctionTimer > 0.0f)
            {
                int msgLength = (int)(msg.Position - msgStartPos);
                msg.Position = msgStartPos;
                StartDelayedCorrection(type, msg.ExtractBits(msgLength), sendingTime);
                return;
            }

            AutoPilot = autoPilot;

            if (!AutoPilot)
            {
                targetVelocity = newTargetVelocity;
            }
            else
            {
                MaintainPos   = newPosToMaintain != null;
                posToMaintain = newPosToMaintain;

                if (posToMaintain == null)
                {
                    LevelStartSelected = headingToStart;
                    LevelEndSelected   = !headingToStart;
                    UpdatePath();
                }
                else
                {
                    LevelStartSelected = false;
                    LevelEndSelected   = false;
                }
            }
        }
Ejemplo n.º 30
0
 public void ServerWrite(Lidgren.Network.NetBuffer msg, Client c, object[] extraData = null)
 {
     //flowpercentage can only be adjusted at 10% intervals -> no need for more accuracy than this
     msg.WriteRangedInteger(-10, 10, (int)(flowPercentage / 10.0f));
     msg.Write(IsActive);
 }