コード例 #1
0
        public override void ParseMessage(int index, BgoProtocolReader br)
        {
            ushort msgType = (ushort)br.ReadUInt16();

            switch ((Request)msgType)
            {
            // This case is ran when the player selects his faction. It will send to the client an
            // empty Avatar Description, so the customization will be set to default, and sends back
            // the faction, so the game will be sure that the selected faction is real. Also fater that
            // we change the scene to Avatar.
            case Request.SelectFaction:
                SendNewAvatarDescription(index);
                SendFaction(index, (Faction)br.ReadByte());
                Server.GetClientByIndex(index).Character.GameLocation = GameLocation.Avatar;
                break;

            // Since we are not using a real database yet, we can just use the fake database to check if
            // the name is available or not.
            case Request.CheckNameAvailability:
                SendNameAvailability(index, br.ReadString());
                break;

            case Request.ChooseName:
                Server.GetClientByIndex(index).Character.name = br.ReadString();
                SendName(index);
                break;

            case Request.CreateAvatar:
                Dictionary <AvatarItem, string> items = new Dictionary <AvatarItem, string>();

                int num = br.ReadLength();
                for (int i = 0; i < num; i++)
                {
                    items[(AvatarItem)br.ReadByte()] = br.ReadString();
                }

                Client client = Server.GetClientByIndex(index);

                Database.Database.CreateCharacter(client.Character.name, client.playerId.ToString(), (byte)client.Character.Faction, items);

                Server.GetClientByIndex(index).Character.items = items;
                SendAvatar(index);

                SendPlayerId(index);
                SendPlayerShips(index, 100, (uint)22131177);

                Server.GetClientByIndex(index).Character.GameLocation = GameLocation.Space;
                break;

            default:
                Log.Add(LogSeverity.ERROR, string.Format("Unknown msgType \"{0}\" on {1}Protocol.", (Request)msgType, protocolID));
                break;
            }
        }
コード例 #2
0
        private void ReadProperty(IDictionary <UserSetting, object> settings, BgoProtocolReader br)
        {
            UserSetting          property  = (UserSetting)br.ReadByte();
            UserSettingValueType valueType = (UserSettingValueType)br.ReadByte();

            switch (valueType)
            {
            case UserSettingValueType.Byte:
                settings.Add(property, br.ReadByte());
                break;

            case UserSettingValueType.Float:
                settings.Add(property, br.ReadSingle());
                break;

            case UserSettingValueType.Boolean:
                settings.Add(property, br.ReadBoolean());
                break;

            case UserSettingValueType.Integer:
                settings.Add(property, br.ReadInt32());
                break;

            case UserSettingValueType.Float2:
            {
                settings.Add(property, new float2(br.ReadSingle(), br.ReadSingle()));
                break;
            }

            case UserSettingValueType.HelpScreenType:
            {
                List <HelpScreenType> hstList = new List <HelpScreenType>();
                int hstSize = br.ReadUInt16();
                for (int i = 0; i < hstSize; i++)
                {
                    hstList.Add((HelpScreenType)br.ReadUInt16());
                }
                settings.Add(property, hstList);
                break;
            }

            default:
                settings.Add(property, br.ReadByte());
                break;
            }
        }
コード例 #3
0
        private void DebugMessage(BgoProtocolWriter w)
        {
            BgoProtocolReader buffer = new BgoProtocolReader(w.GetBuffer());

            buffer.ReadUInt16();
            byte protocolId = buffer.ReadByte();

            Log.Add(LogSeverity.INFO, Log.LogDir.Out, string.Format("Protocol ID: {0} ({1}) - msgType: {2}", protocolId, (ProtocolID)protocolId, buffer.ReadUInt16()));
        }
コード例 #4
0
        public override void ParseMessage(int index, BgoProtocolReader br)
        {
            ushort msgType = br.ReadUInt16();

            switch ((Request)msgType)
            {
            case Request.SaveSettings:
                IDictionary <UserSetting, object> settings = new Dictionary <UserSetting, object>();
                int num = br.ReadUInt16();

                for (int i = 0; i < num; i++)
                {
                    ReadProperty(settings, br);
                }

                Server.GetClientByIndex(index).Character.settings = settings;
                Database.Database.SaveSettings(Server.GetClientByIndex(index).playerId.ToString(), settings);
                break;

            case Request.SaveKeys:
                List <string> controlKeys = new List <string>();
                int           num2        = br.ReadUInt16();

                for (int j = 0; j < num2; j++)
                {
                    ushort deviceTriggerCode  = br.ReadUInt16();
                    ushort action             = br.ReadUInt16();
                    byte   deviceModifierCode = br.ReadByte();
                    byte   device             = br.ReadByte();
                    byte   flags     = br.ReadByte();
                    byte   profileNo = br.ReadByte();

                    controlKeys.Add(deviceTriggerCode + "|" + action + "|" + deviceModifierCode + "|" + device + "|" + flags + "|" + profileNo);
                }

                Server.GetClientByIndex(index).Character.controlKeys = controlKeys;
                Database.Database.SaveKeys(Server.GetClientByIndex(index).playerId.ToString(), controlKeys);
                break;

            default:
                Log.Add(LogSeverity.ERROR, string.Format("Unknown msgType \"{0}\" on {1}Protocol.", (Request)msgType, protocolID));
                break;
            }
        }
コード例 #5
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;
            }
        }
コード例 #6
0
        public override void ParseMessage(int index, BgoProtocolReader br)
        {
            ushort msgType = (ushort)br.ReadUInt16();

            switch ((Request)msgType)
            {
            case Request.Init:
                SendInit(index);
                break;

            case Request.Player:
                // This is the ConnectType, but we aren't checking for that yet
                ConnectType connectType = (ConnectType)br.ReadByte();
                // Check if the player exists on our database. We'll have checks for client connected later, but it's
                // not necessary yet
                uint   playerId    = br.ReadUInt32();
                string playerName  = br.ReadString();
                string sessionCode = br.ReadString();

                switch (connectType)
                {
                case ConnectType.Web:
                    if (Database.Database.CheckSessionCodeExistance(sessionCode))
                    {
                        playerId = uint.Parse(Database.Database.GetUserBySession(sessionCode).PlayerId);
                        Server.GetClientByIndex(index).playerId  = playerId;
                        Server.GetClientByIndex(index).Character = new Character(index);
                        SendPlayer(index);

                        if (Database.Database.CheckCharacterExistanceById(playerId.ToString()))
                        {
                        }
                    }
                    else
                    {
                        SendError(index, (byte)LoginError.WrongSession);
                    }
                    break;

                default:
                    Log.Add(LogSeverity.ERROR, "Unknown Connection Type " + connectType + " on Login Protocol");
                    break;
                }

                break;

            default:
                Log.Add(LogSeverity.ERROR, string.Format("Unknown msgType \"{0}\" on {1}Protocol.", (Request)msgType, protocolID));
                break;
            }
        }
コード例 #7
0
        public static void HandleNetworkInformation(int index, BgoProtocolReader buffer)
        {
            byte b = buffer.ReadByte();

            Log.Add(LogSeverity.INFO, Log.LogDir.In, string.Format("Protocol ID: {0} ({1})", b, (Protocol.ProtocolID)b));
            try
            {
                GetProtocol((Protocol.ProtocolID)b).ParseMessage(index, buffer);
            }
            catch (Exception ex)
            {
                string text = "Couldn't handle message for " + (Protocol.ProtocolID)b + " Protocol (msgType:" + buffer.ReadUInt16() + "). ";
                if (GetProtocol((Protocol.ProtocolID)b) == null)
                {
                    text = text + b + " Protocol is not (any more) registered. ";
                }
                text = text + "\nCaught Exception: " + ex.ToString();
                Log.Add(LogSeverity.ERROR, text);
            }
            buffer.Dispose();
        }
コード例 #8
0
        public static void HandleNetworkInformation(int index, byte[] data)
        {
            BgoProtocolReader buffer = new BgoProtocolReader(data);

            buffer.ReadUInt16();
            byte protocolID = buffer.ReadByte();

            Log.Add(LogSeverity.INFO, Log.LogDir.In, string.Format("Protocol ID: {0} ({1})", protocolID, (Protocol.ProtocolID)protocolID));

            try
            {
                GetProtocol((Protocol.ProtocolID)protocolID).ParseMessage(index, buffer);
            }
            catch (Exception ex)
            {
                string text = "";
                try
                {
                    text += "Couldn't handle message for " + (Protocol.ProtocolID)protocolID + " Protocol";
                } catch
                {
                }
                try
                {
                    text += " (msgType: " + buffer.ReadUInt16() + "). ";
                } catch
                {
                }
                if (GetProtocol((Protocol.ProtocolID)protocolID) == null)
                {
                    text = text + protocolID + " Protocol is not (any more) registered. ";
                }
                text = text + "\nCaught Exception: " + ex;
                Log.Add(LogSeverity.ERROR, text);
            }
        }
コード例 #9
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;
            }
        }