Пример #1
0
        public override void ParseMessage(int index, BgoProtocolReader br)
        {
            ushort msgType = (ushort)br.ReadUInt16();

            switch ((Request)msgType)
            {
            // I'm not sure if the JumpIn request did send the WhoIs of the player, but it works I guess.
            // Also I don't know if it was sent to everyone or just to the client. Probably everyone on the sector,
            // but since we are doing this offline for now, let's keep it still only client.
            case Request.JumpIn:
                SendWhoIsPlayer(index);
                SetTimeOrigin(index);
                PlayerProtocol.GetProtocol().SendStats(index);     // These are the stats of your ship, not the base ones.

                SyncMove(index, SpaceEntityType.Player, (uint)index, new Vector3(0, 100f, 100f));
                break;

            case Request.CompleteJump:
                PlayerProtocol.GetProtocol().SendUnanchor(index);
                StoryProtocol.GetProtocol().EnableGear(index, true);
                break;

            case Request.SetSpeed:
                byte  mode  = br.ReadByte();
                float speed = br.ReadSingle();
                Server.GetClientByIndex(index).Character.shipMode  = mode;
                Server.GetClientByIndex(index).Character.shipSpeed = speed;
                SyncMove(index, SpaceEntityType.Player, (uint)index);
                break;

            case Request.WASD:
                Server.GetClientByIndex(index).Character.qweasd = br.ReadByte();
                SyncMove(index, SpaceEntityType.Player, (uint)index);
                break;

            default:
                Log.Add(LogSeverity.ERROR, string.Format("Unknown msgType \"{0}\" on {1}Protocol.", (Request)msgType, protocolID));
                break;
            }
        }
Пример #2
0
        public override void ParseMessage(int index, BgoProtocolReader br)
        {
            ushort msgType = br.ReadUInt16();

            switch ((Request)msgType)
            {
            case Request.JumpIn:
                Client c = Server.GetClientByIndex(index);
                Server.GetSectorById(c.Character.PlayerShip.sectorId).JoinSector(c);
                break;

            case Request.CompleteJump:
                PlayerProtocol.GetProtocol().SendUnanchor(index, Server.GetObjectId(index));
                StoryProtocol.GetProtocol().EnableGear(index, true);

                Server.GetClientByIndex(index).Character.PlayerShip.isVisible = false;
                SendChangeVisibility(index, Server.GetObjectId(index), Server.GetClientByIndex(index).Character.PlayerShip.isVisible, 0);
                Server.GetClientByIndex(index).Character.PlayerShip.jumpInTime = DateTime.Now.AddSeconds(10);
                break;

            case Request.SetSpeed:
                Client setSpeedClient = Server.GetClientByIndex(index);
                CheckIfVisibleAndSetIfNot(setSpeedClient);
                byte  mode  = br.ReadByte();
                float speed = br.ReadSingle();
                setSpeedClient.Character.PlayerShip.shipMode              = mode;
                setSpeedClient.Character.PlayerShip.shipSpeed             = speed;
                setSpeedClient.Character.PlayerShip.MovementOptions.speed = setSpeedClient.Character.PlayerShip.shipGear == Gear.Regular ? setSpeedClient.Character.PlayerShip.shipSpeed : setSpeedClient.Character.PlayerShip.currentShipStats.BoostSpeed;
                SyncMove(index, SpaceEntityType.Player, Server.GetObjectId(index));
                break;

            case Request.SetGear:
                Client setGearClient = Server.GetClientByIndex(index);
                CheckIfVisibleAndSetIfNot(setGearClient);
                setGearClient.Character.PlayerShip.shipGear = (Gear)br.ReadByte();
                setGearClient.Character.PlayerShip.MovementOptions.speed = setGearClient.Character.PlayerShip.shipGear == Gear.Regular ? setGearClient.Character.PlayerShip.shipSpeed : setGearClient.Character.PlayerShip.currentShipStats.BoostSpeed;
                SyncMove(index, SpaceEntityType.Player, Server.GetObjectId(index));
                break;

            case Request.WASD:
                Client wasdClient = Server.GetClientByIndex(index);
                Sector wasdServer = Server.GetSectorById(wasdClient.Character.PlayerShip.sectorId);
                CheckIfVisibleAndSetIfNot(wasdClient);
                wasdClient.Character.PlayerShip.qweasd.Bitmask = br.ReadByte();

                wasdClient.Character.PlayerShip.ManeuverController.AddManeuver(new TurnManeuver(ManeuverType.Turn, wasdServer.Tick.Current.value, wasdClient.Character.PlayerShip.qweasd, wasdClient.Character.PlayerShip.MovementOptions));

                SyncMove(index, SpaceEntityType.Player, Server.GetObjectId(index));
                break;

            case Request.MoveToDirection:
                Client directionalClient = Server.GetClientByIndex(index);
                Sector directionalServer = Server.GetSectorById(directionalClient.Character.PlayerShip.sectorId);
                CheckIfVisibleAndSetIfNot(directionalClient);
                directionalClient.Character.PlayerShip.direction = br.ReadEuler();

                directionalClient.Character.PlayerShip.ManeuverController.AddManeuver(new DirectionalManeuver(ManeuverType.Directional, directionalServer.Tick.Current.value, directionalClient.Character.PlayerShip.direction, directionalClient.Character.PlayerShip.MovementOptions));

                SyncMove(index, SpaceEntityType.Player, Server.GetObjectId(index));
                break;

            case Request.MoveToDirectionWithoutRoll:
                Client directionalWrClient = Server.GetClientByIndex(index);
                Sector directionalWrServer = Server.GetSectorById(directionalWrClient.Character.PlayerShip.sectorId);
                CheckIfVisibleAndSetIfNot(directionalWrClient);
                directionalWrClient.Character.PlayerShip.direction = br.ReadEuler();

                directionalWrClient.Character.PlayerShip.ManeuverController.AddManeuver(new DirectionalWithoutRollManeuver(ManeuverType.DirectionalWithoutRoll, directionalWrServer.Tick.Current.value, directionalWrClient.Character.PlayerShip.direction, directionalWrClient.Character.PlayerShip.MovementOptions));

                SyncMove(index, SpaceEntityType.Player, Server.GetObjectId(index));
                break;

            case Request.QWEASD:
                Client qweasdClient = Server.GetClientByIndex(index);
                Sector qweasdServer = Server.GetSectorById(qweasdClient.Character.PlayerShip.sectorId);
                CheckIfVisibleAndSetIfNot(qweasdClient);
                qweasdClient.Character.PlayerShip.qweasd.Bitmask = br.ReadByte();

                qweasdClient.Character.PlayerShip.ManeuverController.AddManeuver(new TurnQweasdManeuver(ManeuverType.TurnQweasd, qweasdServer.Tick.Current.value, qweasdClient.Character.PlayerShip.qweasd, qweasdClient.Character.PlayerShip.MovementOptions));

                SyncMove(index, SpaceEntityType.Player, Server.GetObjectId(index));
                break;

            case Request.Dock:
                uint  objId = br.ReadUInt32();
                float delay = br.ReadSingle();
                SendDock(index, delay);
                break;

            case Request.Quit:
                Client quitClient = Server.GetClientByIndex(index);
                quitClient.Character.PlayerShip.isSpawned = false;
                if (quitClient.Character.PlayerShip.requestedJumpSectorId == -1)
                {
                    quitClient.Character.GameLocation = GameLocation.Room;
                }
                else
                {
                    quitClient.Character.PlayerShip.requestedJumpSectorId = -1;
                    Database.Database.SaveSector(quitClient.playerId.ToString(), quitClient.Character.PlayerShip.sectorId);
                    quitClient.Character.GameLocation         = GameLocation.Space;
                    quitClient.Character.PlayerShip.shipGear  = Gear.Regular;
                    quitClient.Character.PlayerShip.shipSpeed = 0;
                }
                break;

            case Request.Jump:
                Client jumpClient = Server.GetClientByIndex(index);
                CheckIfVisibleAndSetIfNot(jumpClient);

                SendJump(index, br.ReadUInt32(), true);
                break;

            case Request.StopJump:
                Client stopJumpClient = Server.GetClientByIndex(index);
                if (stopJumpClient.Character.PlayerShip.requestedJumpSectorId != -1)
                {
                    SendStopJump(index);
                }
                break;

            default:
                Log.Add(LogSeverity.ERROR, string.Format("Unknown msgType \"{0}\" on {1}Protocol.", (Request)msgType, protocolID));
                break;
            }
        }