Esempio n. 1
0
        public void Construct(LitePlayer owner, int entid = -1)
        {
            EntityIndex = EntityManager.RegisterEntity(this);

            GetComponent <NetworkAuthority>().owner = owner;

            SpawnEntityPacket pkt = new SpawnEntityPacket();

            pkt.authority = owner.id;
            pkt.entityId  = (int)EntityIndex;
            pkt.position  = transform.position;
            pkt.prefabId  = GetComponent <UniqueId>().prefabId;

            if (WorldAtlas.enabled)
            {
                this.loadedChunkId = owner.GetChunkId();

                foreach (LitePlayer player in Networking.players.Values)
                {
                    if (player.GetChunkId() == loadedChunkId)
                    {
                        PacketSender.SendSpawnEntityPacket(pkt, player.GetConnectionId());
                    }
                }
            }
            else
            {
                PacketSender.SendSpawnEntityPacket(pkt);
            }
        }
        public void UnequipItem(byte location)
        {
            var item = equippedItems[location];

            equippedItems[location] = null;
            if (item != null && Owner.AddItem(item))
            {
                //Track equipped super gems
                if (item.Gem1 % 10 == 3 || item.Gem2 % 10 == 3)
                {
                    if (superGems.Contains(item.Gem1 / 10))
                    {
                        superGems.Remove(item.Gem1 / 10);
                    }
                }
                Owner.SpawnPacket = SpawnEntityPacket.Create(Owner);
                if (DropManager.TwoHandWeaponTypes.Contains(item.EquipmentType) && equippedItems[5] != null)
                {
                    UnequipItem(5);
                }
                Owner.Send(ItemActionPacket.Create(item.UniqueID, (byte)item.Location, ItemAction.UnequipItem));
                Owner.SendToScreen(Owner.SpawnPacket);
                item.Location = 0;
                item.Save();
            }
        }
Esempio n. 3
0
 static PacketFactory()
 {
     PACKETS[0x01] = new OkPacket();
     PACKETS[0x02] = new MatchInfoPacket();
     PACKETS[0x04] = new BulkEntityStatePacket();
     PACKETS[0x06] = new MatchStatusPacket();
     PACKETS[0x07] = new MatchEndPacket();
     PACKETS[0x09] = new PingPongPacket();
     PACKETS[0x10] = new SpawnEntityPacket();
     PACKETS[0x11] = new DespawnEntityPacket();
     PACKETS[0x12] = new PlayerStatePacket();
     //DEPRECATED 0X19 PING
     PACKETS[0x26] = new MatchRedirectPacket();
     PACKETS[0x29] = new UpdateSessionPacket();
     //DEPRECATED 0X30 OVER EVENT API
     //PACKETS[0x30] = new SpawnEffectPacket();
     PACKETS[0x31] = new StatsUpdatePacket();
     PACKETS[0x32] = new ItemActivatedEffect();
     PACKETS[0x33] = new ItemDeactivatedPackets();
     PACKETS[0x35] = new MapSettingsPacket();
     PACKETS[0x37] = new SpawnLightPacket();
     PACKETS[0x38] = new UpdateInventoryPacket();
     PACKETS[0x40] = new EventPacket();
     PACKETS[0x42] = new DisconnectReasonPacket();
     PACKETS[0x43] = new DisplayTextPacket();
     PACKETS[0x44] = new RemoveTextPacket();
 }
Esempio n. 4
0
 public void _Deserialize(SpawnEntityPacket pkt, MemoryStream m)
 {
     pkt.entityId  = Data_serializers_const.ser_M_liteIntSerializer.Deserialize(m);
     pkt.prefabId  = Data_serializers_const.ser_M_liteLongSerializer.Deserialize(m);
     pkt.uniqueId  = Data_serializers_const.ser_M_liteLongSerializer.Deserialize(m);
     pkt.authority = Data_serializers_const.ser_M_liteIntSerializer.Deserialize(m);
     pkt.position  = Data_serializers_const.ser_ChunkedVectorSerializer.Deserialize(m);
 }
Esempio n. 5
0
        public static void SendSpawnEntityPacket(SpawnEntityPacket pkt, [Optional()][DefaultParameterValue(-1)] int connectionId)
        {
            MemoryStream m = new MemoryStream();

            m.WriteByte(0);
            LiteNetworking.Networking.localPacketPlayer = LiteNetworking.LobbyConnector.ConvertConnectionToPlayer(connectionId);
            ConstRefs.mirror_SpawnEntityPacket._Serialize(pkt, m);
            Networking.TransmitPacket(m, connectionId);
        }
Esempio n. 6
0
 public Monster(DbMonstertype _type, SpawnManager _owner, Entity playerOwner = null)
     : base()
 {
     PkMode       = _type.AttackMode == 3 ? PKMode.PK : PKMode.Capture;
     BaseMonster  = _type;
     Owner        = _owner;
     Map          = Owner.Map;
     UID          = (uint)Map.MobCounter.Counter;
     CombatStats  = Structures.CombatStatistics.Create(BaseMonster);
     CombatEngine = new CombatManager(this);
     SpawnPacket  = SpawnEntityPacket.Create(this);
 }
 public Pet(Player owner, DbMonstertype _type) : base(_type)
 {
     PetOwner = owner;
     Map      = owner.Map;
     UID      = (uint)Map.PetCounter.Counter;
     if (_type.SkillType > 0)
     {
         CombatEngine.skills.TryAdd(_type.SkillType, Structures.ConquerSkill.Create(UID, _type.SkillType, 0, 0));
     }
     SpawnPacket = SpawnEntityPacket.Create(this);
     PetManager.ActivePets.TryAdd(UID, this);
 }
Esempio n. 8
0
 public void _Serialize(SpawnEntityPacket pkt, MemoryStream m)
 {
     byte[] entityId = Data_serializers_const.ser_M_liteIntSerializer.Serialize(pkt.entityId);
     m.Write(entityId, 0, entityId.Length);
     byte[] prefabId = Data_serializers_const.ser_M_liteLongSerializer.Serialize(pkt.prefabId);
     m.Write(prefabId, 0, prefabId.Length);
     byte[] uniqueId = Data_serializers_const.ser_M_liteLongSerializer.Serialize(pkt.uniqueId);
     m.Write(uniqueId, 0, uniqueId.Length);
     byte[] authority = Data_serializers_const.ser_M_liteIntSerializer.Serialize(pkt.authority);
     m.Write(authority, 0, authority.Length);
     byte[] position = Data_serializers_const.ser_ChunkedVectorSerializer.Serialize(pkt.position);
     m.Write(position, 0, position.Length);
 }
Esempio n. 9
0
        public void UnequipItem(byte location)
        {
            var item = equippedItems[location];

            equippedItems[location] = null;
            if (item != null && Owner.AddItem(item))
            {
                Owner.SpawnPacket = SpawnEntityPacket.Create(Owner);
                Owner.Send(ItemActionPacket.Create(item.UniqueID, (byte)item.Location, ItemAction.UnequipItem));
                Owner.SendToScreen(Owner.SpawnPacket);
                item.Location = 0;
                item.Save();
            }
        }
Esempio n. 10
0
 public override void Execute()
 {
     WorldAtlas.current.MovePlayerToScene(GetExecutingClient(), sceneId, null, chk =>
     {
         SpawnEntityPacket epkt = new SpawnEntityPacket();
         foreach (NetworkedEntity e in EntityManager.ents.Values)
         {
             if (e.GetComponent <LitePlayer>() == null && e.GetChunkId() == chk.chunk)
             {
                 epkt.authority = e.GetComponent <NetworkAuthority>()?.owner?.id ?? 0;
                 epkt.entityId  = (int)e.EntityIndex;
                 epkt.prefabId  = e.GetComponent <UniqueId>().prefabId;
                 epkt.uniqueId  = e.GetComponent <UniqueId>().uniqueId;
                 epkt.position  = e.transform.position;
                 PacketSender.SendSpawnEntityPacket(epkt, GetExecutingClient().GetConnectionId());
             }
         }
     });
 }
        public bool EquipItem(ConquerItem item, byte location, bool updateClient = true)
        {
            //If we're equipping a 2h weapon we ALWAYS uneq the left hand item
            if (DropManager.TwoHandWeaponTypes.Contains(item.EquipmentType))
            {
                if (equippedItems[5] != null)
                {
                    UnequipItem(5);
                }
            }

            //If we're equipping to left hand then we need to be able to (based on class type and level)
            if (location == 5)
            {
                bool canEq = false;
                switch (Owner.ProfessionType)
                {
                case ProfessionType.Trojan:
                    canEq = Owner.ProfessionLevel >= 2;
                    break;

                case ProfessionType.Archer:
                    canEq = true;
                    break;

                case ProfessionType.Warrior:
                    canEq = Owner.ProfessionLevel > 1;
                    break;
                }
                if (!canEq)
                {
                    return(false);
                }

                //Now that we know it's physically possible to equip to second weapon slot we need to check the type of item
                if (Owner.ProfessionType == ProfessionType.Warrior)
                {
                    canEq = item.EquipmentType == 900;
                }
                else if (Owner.ProfessionType == ProfessionType.Archer)
                {
                    canEq = item.EquipmentType == 1050;
                }

                if (!canEq)
                {
                    return(false);
                }
            }
            else
            {
                byte toLoc = GetDefaultItemLocation(item.EquipmentType);
                if (toLoc != location)
                {
                    location = toLoc;
                }
            }
            //Check all iteminfo req's
            bool success = (item.BaseItem.GenderReq == 0 || !Owner.IsMale) &&
                           Owner.Level >= item.BaseItem.LevelReq &&
                           (Owner.RebornCount > 0 || (Owner.Strength >= item.BaseItem.StrengthReq &&
                                                      Owner.Agility >= item.BaseItem.AgilityReq &&
                                                      Owner.Spirit >= item.BaseItem.SpiritReq &&
                                                      CanEquipProfession(item)));

            if (!success)
            {
                return(false);
            }

            if (equippedItems[location] != null)
            {
                UnequipItem(location);
            }
            item.Location = (ItemLocation)location;
            item.Save();

            //Track equipped super gems
            if (item.Gem1 % 10 == 3 || item.Gem2 % 10 == 3)
            {
                if (!superGems.Contains(item.Gem1 / 10))
                {
                    superGems.Add(item.Gem1 / 10);
                }
            }

            equippedItems[location] = item;
            if (updateClient)
            {
                Owner.SpawnPacket = SpawnEntityPacket.Create(Owner);
                Owner.Send(ItemActionPacket.Create(item.UniqueID, (byte)item.Location, ItemAction.SetEquipItem));
                Owner.SendToScreen(Owner.SpawnPacket, true);
            }
            return(true);
        }
Esempio n. 12
0
        public override void Run(Game_Server.Player _client, ushort _linkback)
        {
            Responses = new List <NpcDialogPacket>();
            AddAvatar();
            switch (_linkback)
            {
            case 0:
                AddText("I am the master of all colors. What equipment would you like to dye today?");
                AddOption("Helmet", 1);
                AddOption("Armor", 2);
                AddOption("Shield", 3);
                AddOption("Nevermind", 255);
                break;

            case 1:
            {
                ConquerItem equipment;
                if (_client.TryGetEquipmentByLocation(ItemLocation.Helmet, out equipment) && equipment.EquipmentSort == 1)
                {
                    AddText("What color would you like?");
                    AddOption("White", 13);
                    AddOption("Blue", 14);
                    AddOption("Red", 15);
                    AddOption("Purple", 16);
                    AddOption("Yellow", 17);
                    AddOption("Nevermind", 255);
                }
                else
                {
                    AddText("You are not wearing a helmet. I don't do hair!");
                    AddOption("Sorry", 255);
                }
            }
            break;

            case 2:
            {
                ConquerItem equipment;
                if (_client.TryGetEquipmentByLocation(ItemLocation.Armor, out equipment) && equipment.EquipmentSort == 3)
                {
                    AddText("What color would you like?");
                    AddOption("White", 33);
                    AddOption("Blue", 34);
                    AddOption("Red", 35);
                    AddOption("Purple", 36);
                    AddOption("Yellow", 37);
                    AddOption("Nevermind", 255);
                }
                else
                {
                    AddText("You are not wearing armor. I don't do tattoos!");
                    AddOption("Sorry", 255);
                }
                break;
            }

            case 3:
            {
                ConquerItem equipment;
                if (_client.TryGetEquipmentByLocation(ItemLocation.WeaponL, out equipment) && equipment.EquipmentType == 900)
                {
                    AddText("What color would you like?");
                    AddOption("White", 43);
                    AddOption("Blue", 44);
                    AddOption("Red", 45);
                    AddOption("Purple", 46);
                    AddOption("Yellow", 47);
                    AddOption("Nevermind", 255);
                }
                else
                {
                    AddText("You are not wearing a Shield.");
                    AddOption("Sorry", 255);
                }
                break;
            }

            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            {
                ConquerItem equipment;
                if (_client.TryGetEquipmentByLocation(ItemLocation.Helmet, out equipment) && equipment.EquipmentSort == 1)
                {
                    equipment.Color = (byte)(_linkback % 10);
                    equipment.Save();
                    _client.Send(ItemInformationPacket.Create(equipment, ItemInfoAction.Update));
                    _client.SendToScreen(SpawnEntityPacket.Create(_client));
                }
                else
                {
                    AddText("You are not wearing a helmet. I don't do hair!");
                    AddOption("Sorry", 255);
                }
                break;
            }

            case 33:
            case 34:
            case 35:
            case 36:
            case 37:
            {
                ConquerItem equipment;
                if (_client.TryGetEquipmentByLocation(ItemLocation.Armor, out equipment) && equipment.EquipmentSort == 3)
                {
                    equipment.Color = (byte)(_linkback % 10);
                    equipment.Save();
                    _client.Send(ItemInformationPacket.Create(equipment, ItemInfoAction.Update));
                    _client.SendToScreen(SpawnEntityPacket.Create(_client));
                }
                else
                {
                    AddText("You are not wearing armor. I don't do tattoos!");
                    AddOption("Sorry", 255);
                }
                break;
            }

            case 43:
            case 44:
            case 45:
            case 46:
            case 47:
            {
                ConquerItem equipment;
                if (_client.TryGetEquipmentByLocation(ItemLocation.WeaponL, out equipment) && equipment.EquipmentType == 900)
                {
                    equipment.Color = (byte)(_linkback % 10);
                    equipment.Save();
                    _client.Send(ItemInformationPacket.Create(equipment, ItemInfoAction.Update));
                    _client.SendToScreen(SpawnEntityPacket.Create(_client));
                }
                else
                {
                    AddText("You are not wearing a Shield.");
                    AddOption("Sorry", 255);
                }
                break;
            }
            }
            AddFinish();
            Send();
        }
Esempio n. 13
0
        public static IEnumerator SendPacketsLater(int connectionId)
        {
            yield return(new WaitForSeconds(0.1f));

            Debug.Log("OnPlayerJoined");
            //hostId = connectionId;

            // Send the introduction packet to this client
            Debug.Log("Sending out the intro packet");
            LobbyHostIntroductionPacket introPkt = new LobbyHostIntroductionPacket();

            connectedClients.Add(connectionId);
            introPkt.myPlayerId = nextPlayerIndex++;
            List <int> activePlayers = new List <int>();

            foreach (int i in connectedClients)
            {
                if (i != connectionId)
                {
                    activePlayers.Add(connectionToPlayer[i]);
                }
            }
            introPkt.activePlayerIds         = activePlayers.ToArray();
            connectionToPlayer[connectionId] = nextPlayerIndex - 1;

            SpawnEntityPacket epkt = new SpawnEntityPacket();

            foreach (NetworkedEntity e in EntityManager.ents.Values)
            {
                if (e.GetComponent <LitePlayer>() == null)
                {
                    epkt.authority = e.GetComponent <NetworkAuthority>()?.owner?.id ?? 0;
                    epkt.entityId  = (int)e.EntityIndex;
                    epkt.prefabId  = e.GetComponent <UniqueId>().prefabId;
                    epkt.uniqueId  = e.GetComponent <UniqueId>().uniqueId;
                    epkt.position  = e.transform.position;
                    PacketSender.SendSpawnEntityPacket(epkt, connectionId);
                }
            }


            Debug.Log("Spawining player prefab");
            SpawnPlayerPrefab(false, (nextPlayerIndex - 1));

            Debug.Log("Actually sending the packet now");
            introPkt.instanceIdToEntity   = new int[0];
            introPkt.preplacedInstanceIds = new long[0];
            LiteNetworkingGenerated.PacketSender.SendLobbyHostIntroductionPacket(introPkt, connectionId);
            Debug.Log("Done sending packet");
            // Send the player joined packet to all other clients
            foreach (int i in connectedClients)
            {
                if (i != connectionId)
                {
                    LobbyNewPlayerPacket pkt = new LobbyNewPlayerPacket();
                    pkt.newPlayerId = (nextPlayerIndex - 1);
                    Debug.Log("Sending NP Packet");
                    PacketSender.SendLobbyNewPlayerPacket(pkt, i);
                    Debug.Log("Done Sending NP Packet");
                }
            }
            Debug.Log("Done SendPacketsLater");
        }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        if (spawnQueue.Count > 0)
        {
            lock (spawnQueueLock)
            {
                SpawnEntityPacket packet = spawnQueue.Dequeue();
                GameObject        entity = Instantiate(entityPrefab, new Vector3(packet.X, packet.Y), Quaternion.identity);
                entity.GetComponent <NetworkEntity>().Setup(packet.EntityId, packet.IsSelf, lobbyClients.Where(x => x.Name == packet.Owner).SingleOrDefault());

                entityMap.Add(packet.EntityId, entity);

                Debug.Log($"Spawned entity: {packet.EntityId} - Self: {packet.IsSelf}");
                GameObject.Find("RoomManager").GetComponent <RoomManager>().players++;
            }
        }

        if (relocationQueue.Count > 0)
        {
            lock (relocLock)
            {
                RelocationPacket packet = relocationQueue.Dequeue();
                entityMap[packet.EntityId].transform.position = new Vector3(packet.X, packet.Y);
            }
        }

        if (dropQueue.Count > 0)
        {
            lock (dropLock)
            {
                RemoveEntityPacket packet = dropQueue.Dequeue();
                Destroy(entityMap[packet.EntityId]);
                entityMap.Remove(packet.EntityId);
            }
        }

        if (visibilityQueue.Count > 0)
        {
            lock (visibilityLock)
            {
                VisibilityPacket packet = visibilityQueue.Dequeue();
                entityMap[packet.EntityId].GetComponent <SpriteRenderer>().enabled = packet.Visible;
            }
        }

        if (!loadingScene && currentScene.name != requestedScene)
        {
            loadingScene = true;

            Debug.Log($"Loading '{requestedScene}' from '{currentScene.name}'");
            SceneManager.LoadScene(requestedScene);
            currentScene = SceneManager.GetSceneByName(requestedScene);

            loadingScene = false;
        }

        if (allLoaded)
        {
            allLoaded = false;
            GameObject.Find("RoomManager").GetComponent <RoomManager>().AllLoaded();
        }
        if (allFinished)
        {
            allFinished = false;
            GameObject.Find("RoomManager").GetComponent <RoomManager>().AllFinished();
        }
    }
Esempio n. 15
0
    void HandleServerComm(object server)
    {
        TcpClient tcpClient = (TcpClient)server;

        serverStream = tcpClient.GetStream();
        connected    = true;
        Debug.Log($"Connected to server on {tcpClient.Client.RemoteEndPoint}");

        byte[] message = new byte[4096];
        int    bytesRead;

        while (true)
        {
            try
            {
                Debug.Log("Waiting for server");
                //blocks until the server sends a message
                bytesRead = serverStream.Read(message, 0, 4096);
            }
            catch (Exception e)
            {
                Debug.LogError($"ERROR: {e.Message}");
                break;
            }

            if (bytesRead == 0)
            {
                Debug.LogWarning("Lost connection to server");
                break;
            }

            try
            {
                string formattedData = FormatJsonString(Encoding.UTF8.GetString(message));
                Debug.Log(formattedData);
                JObject json = JObject.Parse(formattedData);

                if (!Enum.TryParse(json["type"].ToString(), out PacketType type))
                {
                    Console.WriteLine("Invalid message received");
                    continue;
                }

                switch (type)
                {
                case PacketType.Disconnect:
                    Debug.LogWarning($"Disconnected from host with message: {json["reason"].ToString()}");
                    break;

                case PacketType.LobbyState:
                    requestedScene = "Lobby";

                    lobbyClients = JsonConvert.DeserializeObject <LobbyClient[]>(json["players"].ToString());
                    break;

                case PacketType.Start:
                    requestedScene = "Game 1";
                    break;

                case PacketType.SpawnEntity:
                    SpawnEntityPacket SpawnPacket = new SpawnEntityPacket(int.Parse(json["entityId"].ToString()), json["owner"].ToString(), float.Parse(json["x"].ToString()), float.Parse(json["y"].ToString()), bool.Parse(json["isSelf"].ToString()));

                    lock (spawnQueueLock)
                        spawnQueue.Enqueue(SpawnPacket);

                    break;

                case PacketType.AllLoaded:
                    allLoaded = true;
                    break;

                case PacketType.RemoveEntity:
                    RemoveEntityPacket removePacket = new RemoveEntityPacket(int.Parse(json["entityId"].ToString()));

                    lock (dropLock)
                        dropQueue.Enqueue(removePacket);

                    break;

                case PacketType.Relocation:
                    Vector3          newPosition = new Vector3(float.Parse(json["x"].ToString()), float.Parse(json["y"].ToString()));
                    RelocationPacket relocPacket = new RelocationPacket(int.Parse(json["entityId"].ToString()), newPosition);

                    lock (relocLock)
                        relocationQueue.Enqueue(relocPacket);

                    break;

                case PacketType.Visibility:
                    VisibilityPacket visibilityPacket = new VisibilityPacket(int.Parse(json["entityId"].ToString()), bool.Parse(json["visible"].ToString()));

                    lock (visibilityLock)
                        visibilityQueue.Enqueue(visibilityPacket);

                    break;

                case PacketType.AllFinished:
                    scores      = json["scores"].ToObject <Dictionary <string, TimeStamp> >();
                    allFinished = true;
                    break;

                default:
                    Debug.LogWarning("Invalid packet type received");
                    continue;
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                continue;
            }
        }

        Disconnect();
    }