예제 #1
0
        /// <summary>
        /// Received from the CityServer in response to a CITY_TOKEN packet.
        /// </summary>
        public static CityTransferStatus OnCityTokenResponse(NetworkClient Client, ProcessedPacket Packet)
        {
            LogThis.Log.LogThis("Received OnCityTokenResponse", LogThis.eloglevel.info);

            CityTransferStatus Status = (CityTransferStatus)Packet.ReadByte();

            ushort NumHouses = Packet.ReadUInt16();

            LotTileEntry[] TileEntries = new LotTileEntry[NumHouses];

            if (NumHouses > 0)
            {
                for (int i = 0; i < NumHouses; i++)
                {
                    TileEntries[i] = new LotTileEntry(Packet.ReadInt32(), Packet.ReadString(), (short)Packet.ReadUInt16(),
                                                      (short)Packet.ReadUInt16(), (byte)Packet.ReadByte(), Packet.ReadInt32());
                }
            }

            PlayerAccount.Money = Packet.ReadInt32();

            lock (GameFacade.CDataRetriever.LotTileData)
                GameFacade.CDataRetriever.LotTileData = TileEntries;

            return(Status);
        }
예제 #2
0
        public static LotTileEntry OnLotCostResponse(NetworkClient Client, ProcessedPacket Packet)
        {
            ushort X       = Packet.ReadUInt16();
            ushort Y       = Packet.ReadUInt16();
            int    LotID   = Packet.ReadInt32();
            string LotName = Packet.ReadString();
            //bit 0 = online, bit 1 = spotlight, bit 2 = locked, bit 3 = occupied, other bits free for whatever use
            byte Flags = (byte)Packet.ReadByte();
            int  Cost  = Packet.ReadInt32();

            return(new LotTileEntry(LotID, LotName, (short)X, (short)Y, Flags, Cost));
        }
예제 #3
0
        /// <summary>
        /// Received CharacterCreation packet from CityServer.
        /// </summary>
        /// <returns>The result of the character creation.</returns>
        public static CharacterCreationStatus OnCharacterCreationStatus(NetworkClient Client, ProcessedPacket Packet)
        {
            LogThis.Log.LogThis("Received OnCharacterCreationStatus!", LogThis.eloglevel.info);

            CharacterCreationStatus CCStatus = (CharacterCreationStatus)Packet.ReadByte();

            ushort NumHouses = Packet.ReadUInt16();

            LotTileEntry[] TileEntries = new LotTileEntry[NumHouses];

            if (NumHouses > 0)
            {
                for (int i = 0; i < NumHouses; i++)
                {
                    TileEntries[i] = new LotTileEntry(Packet.ReadInt32(), Packet.ReadString(), (short)Packet.ReadUInt16(),
                                                      (short)Packet.ReadUInt16(), (byte)Packet.ReadByte(), Packet.ReadInt32());
                }
            }

            lock (GameFacade.CDataRetriever.LotTileData)
                GameFacade.CDataRetriever.LotTileData = TileEntries;

            return(CCStatus);
        }
        /// <summary>
        /// Received CharacterCreation packet from CityServer.
        /// </summary>
        /// <returns>The result of the character creation.</returns>
        public static CharacterCreationStatus OnCharacterCreationStatus(NetworkClient Client, ProcessedPacket Packet)
        {
            LogThis.Log.LogThis("Received OnCharacterCreationStatus!", LogThis.eloglevel.info);

            CharacterCreationStatus CCStatus = (CharacterCreationStatus)Packet.ReadByte();

            ushort NumHouses = Packet.ReadUInt16();
            LotTileEntry[] TileEntries = new LotTileEntry[NumHouses];

            if (NumHouses > 0)
            {
                for (int i = 0; i < NumHouses; i++)
                {
                    TileEntries[i] = new LotTileEntry(Packet.ReadInt32(), Packet.ReadString(), (short)Packet.ReadUInt16(),
                        (short)Packet.ReadUInt16(), (byte)Packet.ReadByte(), Packet.ReadInt32());
                }
            }

            lock(TSOClient.Code.GameFacade.CDataRetriever.LotTileData)
                TSOClient.Code.GameFacade.CDataRetriever.LotTileData = TileEntries;

            return CCStatus;
        }
예제 #5
0
        /// <summary>
        /// A player joined a session (game) in progress.
        /// </summary>
        public static LotTileEntry OnPlayerJoinedSession(NetworkClient Client, ProcessedPacket Packet)
        {
            LotTileEntry TileEntry = new LotTileEntry(0, "", 0, 0, 0, 0);

            UISim Avatar = new UISim(Packet.ReadString());

            Avatar.Name              = Packet.ReadString();
            Avatar.Sex               = Packet.ReadString();
            Avatar.Description       = Packet.ReadString();
            Avatar.HeadOutfitID      = Packet.ReadUInt64();
            Avatar.BodyOutfitID      = Packet.ReadUInt64();
            Avatar.Avatar.Appearance = (AppearanceType)Packet.ReadInt32();

            byte HasHouse = (byte)Packet.ReadByte();

            if (HasHouse != 0)
            {
                TileEntry = new LotTileEntry(Packet.ReadInt32(), Packet.ReadString(), (short)Packet.ReadUInt16(),
                                             (short)Packet.ReadUInt16(), (byte)Packet.ReadByte(), Packet.ReadInt32());

                Avatar.LotID  = TileEntry.lotid;
                Avatar.HouseX = TileEntry.x;
                Avatar.HouseY = TileEntry.y;

                LotTileEntry[] TileEntries = new LotTileEntry[GameFacade.CDataRetriever.LotTileData.Length + 1];
                TileEntries[0] = TileEntry;
                GameFacade.CDataRetriever.LotTileData.CopyTo(TileEntries, 1);
            }

            lock (NetworkFacade.AvatarsInSession)
            {
                NetworkFacade.AvatarsInSession.Add(Avatar);
            }

            return(TileEntry);
        }
        /// <summary>
        /// A player sent a lot purchase request!
        /// </summary>
        public static void HandleLotPurchaseRequest(NetworkClient Client, ProcessedPacket Packet)
        {
            int X = Packet.ReadUInt16();
            int Y = Packet.ReadUInt16();

            if (!NetworkFacade.CurrentSession.IsLotOccupied(X, Y))
            {
                using (DataAccess db = DataAccess.Get())
                {
                    //TODO: Enable this later??
                    //if (db.Houses.GetForPosition(X, Y).HouseID != 0)
                    //{
                    if (NetworkFacade.CurrentTerrain.IsLandBuildable(X, Y))
                    {
                        Guid      CharGuid = NetworkFacade.CurrentSession.GetPlayer(Client).GUID;
                        Character Char     = db.Characters.GetForCharacterGUID(CharGuid);

                        if (Char.Money >= NetworkFacade.LOT_COST)
                        {
                            Char.HouseHouse      = new House();
                            Char.HouseHouse.Name = "Yolo";                                     //TODO: Fixme
                            Char.HouseHouse.X    = X;
                            Char.HouseHouse.Y    = Y;

                            switch (db.Houses.CreateHouse(Char.HouseHouse))
                            {
                            case CityDataModel.Entities.HouseCreationStatus.GeneralError:
                                PacketStream UnbuildablePacket = new PacketStream((byte)PacketType.LOT_UNBUILDABLE, 0);
                                UnbuildablePacket.WriteByte(0x00);
                                Client.SendEncrypted((byte)PacketType.LOT_UNBUILDABLE, UnbuildablePacket.ToArray());
                                return;

                            case CityDataModel.Entities.HouseCreationStatus.NameTooLong:
                                PacketStream NameTooLongPacket = new PacketStream((byte)PacketType.LOT_NAME_TOO_LONG, 0);
                                NameTooLongPacket.WriteByte(0x00);
                                Client.SendEncrypted((byte)PacketType.LOT_NAME_TOO_LONG, NameTooLongPacket.ToArray());
                                return;

                            default:
                                break;
                            }

                            Char.Money -= NetworkFacade.LOT_COST;

                            PacketStream SuccessPacket = new PacketStream((byte)PacketType.LOT_PURCHASE_SUCCESSFUL, 0);
                            SuccessPacket.WriteInt32(Char.Money);
                            Client.SendEncrypted((byte)PacketType.LOT_PURCHASE_SUCCESSFUL, SuccessPacket.ToArray());
                        }
                        else
                        {
                            PacketStream OutOfMoneyPacket = new PacketStream((byte)PacketType.LOT_PURCHASE_FAILED, 0);
                            OutOfMoneyPacket.WriteByte(0x00);                                     //Out of money
                            Client.SendEncrypted((byte)PacketType.LOT_PURCHASE_FAILED, OutOfMoneyPacket.ToArray());
                        }
                    }
                    else
                    {
                        PacketStream UnbuildablePacket = new PacketStream((byte)PacketType.LOT_UNBUILDABLE, 0);
                        UnbuildablePacket.WriteByte(0x00);
                        Client.SendEncrypted((byte)PacketType.LOT_UNBUILDABLE, UnbuildablePacket.ToArray());
                    }
                }
                //}
            }
            else
            {
                PacketStream OccupiedPacket = new PacketStream((byte)PacketType.LOT_PURCHASE_OCCUPIED, 0);
                OccupiedPacket.WriteByte(0x00);
                Client.SendEncrypted((byte)PacketType.LOT_PURCHASE_OCCUPIED, OccupiedPacket.ToArray());
            }
        }
        /// <summary>
        /// Player requested the cost of a lot.
        /// </summary>
        public static void HandleLotCostRequest(NetworkClient Client, ProcessedPacket Packet)
        {
            ushort X = Packet.ReadUInt16();
            ushort Y = Packet.ReadUInt16();
            int    LotID;
            string LotName;

            using (DataAccess db = DataAccess.Get())
            {
                LotID   = db.Houses.GetForPosition(X, Y).HouseID;
                LotName = db.Houses.GetForPosition(X, Y).Name;
            }

            PacketStream LotCostPacket = new PacketStream((byte)PacketType.LOT_PURCHASE_OCCUPIED, 0);

            LotCostPacket.WriteUInt16(X);
            LotCostPacket.WriteUInt16(Y);
            LotCostPacket.WriteInt32(LotID);
            LotCostPacket.WriteString(LotName);

            byte Flags = 0;

            using (DataAccess db = DataAccess.Get())
            {
                if (db.Houses.GetForPosition(X, Y).HouseID == 0)
                {
                    if (!NetworkFacade.CurrentSession.IsLotOccupied(X, Y))
                    {
                        ProtoHelpers.SetBit(ref Flags, 0, false);                         //Online.
                        ProtoHelpers.SetBit(ref Flags, 1, false);                         //Spotlight, this will have to be checked against DB.
                        ProtoHelpers.SetBit(ref Flags, 2, false);                         //Locked - is the house locked for public access?
                        ProtoHelpers.SetBit(ref Flags, 3, false);                         //Occupied.
                        LotCostPacket.WriteByte(Flags);
                        LotCostPacket.WriteInt32(NetworkFacade.LOT_COST);                 //TODO: Figure out a way to deal with this...
                    }
                }
                else
                {
                    if (NetworkFacade.CurrentSession.IsLotOccupied(X, Y))
                    {
                        ProtoHelpers.SetBit(ref Flags, 0, true);                          //Online.
                        ProtoHelpers.SetBit(ref Flags, 1, false);                         //Spotlight, this will have to be checked against DB.
                        ProtoHelpers.SetBit(ref Flags, 2, false);                         //Locked - is the house locked for public access?
                        ProtoHelpers.SetBit(ref Flags, 3, true);                          //Occupied.
                        LotCostPacket.WriteByte(Flags);
                        LotCostPacket.WriteInt32(0);
                    }
                    else if (!NetworkFacade.CurrentSession.IsLotOccupied(X, Y))
                    {
                        ProtoHelpers.SetBit(ref Flags, 0, false);                         //Online.
                        ProtoHelpers.SetBit(ref Flags, 1, false);                         //Spotlight, this will have to be checked against DB.
                        ProtoHelpers.SetBit(ref Flags, 2, false);                         //Locked - is the house locked for public access?
                        ProtoHelpers.SetBit(ref Flags, 3, true);                          //Occupied.
                        LotCostPacket.WriteByte(Flags);
                        LotCostPacket.WriteInt32(0);
                    }
                }
            }

            Client.SendEncrypted((byte)PacketType.LOT_COST, LotCostPacket.ToArray());
        }
        /// <summary>
        /// A player joined a session (game) in progress.
        /// </summary>
        public static LotTileEntry OnPlayerJoinedSession(NetworkClient Client, ProcessedPacket Packet)
        {
            LotTileEntry TileEntry = new LotTileEntry(0, "", 0, 0, 0, 0);

            UISim Avatar = new UISim(Packet.ReadString());
            Avatar.Name = Packet.ReadString();
            Avatar.Sex = Packet.ReadString();
            Avatar.Description = Packet.ReadString();
            Avatar.HeadOutfitID = Packet.ReadUInt64();
            Avatar.BodyOutfitID = Packet.ReadUInt64();
            Avatar.Avatar.Appearance = (AppearanceType)Packet.ReadInt32();

            byte HasHouse = (byte)Packet.ReadByte();

            if (HasHouse != 0)
            {
                TileEntry = new LotTileEntry(Packet.ReadInt32(), Packet.ReadString(), (short)Packet.ReadUInt16(),
                    (short)Packet.ReadUInt16(), (byte)Packet.ReadByte(), Packet.ReadInt32());

                Avatar.LotID = TileEntry.lotid;
                Avatar.HouseX = TileEntry.x;
                Avatar.HouseY = TileEntry.y;

                LotTileEntry[] TileEntries = new LotTileEntry[TSOClient.Code.GameFacade.CDataRetriever.LotTileData.Length + 1];
                TileEntries[0] = TileEntry;
                TSOClient.Code.GameFacade.CDataRetriever.LotTileData.CopyTo(TileEntries, 1);
            }

            lock (NetworkFacade.AvatarsInSession)
            {
                NetworkFacade.AvatarsInSession.Add(Avatar);
            }

            return TileEntry;
        }
        public static LotTileEntry OnLotCostResponse(NetworkClient Client, ProcessedPacket Packet)
        {
            ushort X = Packet.ReadUInt16();
            ushort Y = Packet.ReadUInt16();
            int LotID = Packet.ReadInt32();
            string LotName = Packet.ReadString();
            //bit 0 = online, bit 1 = spotlight, bit 2 = locked, bit 3 = occupied, other bits free for whatever use
            byte Flags = (byte)Packet.ReadByte();
            int Cost = Packet.ReadInt32();

            return new LotTileEntry(LotID, LotName, (short)X, (short)Y, Flags, Cost);
        }
        /// <summary>
        /// Received from the CityServer in response to a CITY_TOKEN packet.
        /// </summary>
        public static CityTransferStatus OnCityTokenResponse(NetworkClient Client, ProcessedPacket Packet)
        {
            LogThis.Log.LogThis("Received OnCityTokenResponse", LogThis.eloglevel.info);

            CityTransferStatus Status = (CityTransferStatus)Packet.ReadByte();

            ushort NumHouses = Packet.ReadUInt16();
            LotTileEntry[] TileEntries = new LotTileEntry[NumHouses];

            if (NumHouses > 0)
            {
                for(int i = 0; i < NumHouses; i++)
                {
                    TileEntries[i] = new LotTileEntry(Packet.ReadInt32(), Packet.ReadString(), (short)Packet.ReadUInt16(),
                        (short)Packet.ReadUInt16(), (byte)Packet.ReadByte(), Packet.ReadInt32());
                }
            }

            PlayerAccount.Money = Packet.ReadInt32();

            lock(TSOClient.Code.GameFacade.CDataRetriever.LotTileData)
                TSOClient.Code.GameFacade.CDataRetriever.LotTileData = TileEntries;

            return Status;
        }