private void FixedUpdate()
 {
     if (Position != transform.localPosition)
     {
         Position = transform.localPosition;
         if (SessionManager.Instance.SendPins)
         {
             ClientSend.SendPinPos(Position);
         }
     }
 }
        public static void Welcome(Packet packet)
        {
            byte   myId = packet.ReadByte();
            string msg  = packet.ReadString();

            Log($"Message from server: {msg}");
            Client.Instance.myId = myId;

            ClientSend.WelcomeReceived();

            Client.Instance.udp.Connect(((IPEndPoint)Client.Instance.tcp.socket.Client.LocalEndPoint).Port);
        }
Beispiel #3
0
        public static void HandleTextureRequest(Packet packet)
        {
            byte[] hash = packet.ReadBytes(20);

            Log("Received request for hash " + BitConverter.ToString(hash));
            if (MultiplayerClient.textureCache.ContainsKey(hash))
            {
                byte[] texture = File.ReadAllBytes(MultiplayerClient.textureCache[hash]);
                Log("Sending texture for hash " + BitConverter.ToString(hash));
                ClientSend.SendTexture(texture);
            }
        }
Beispiel #4
0
        private void AnimationEventDelegate(tk2dSpriteAnimator anim, tk2dSpriteAnimationClip clip, int frameNum)
        {
            if (clip.wrapMode == tk2dSpriteAnimationClip.WrapMode.Loop && clip.name != _storedClip ||
                clip.wrapMode == tk2dSpriteAnimationClip.WrapMode.LoopSection && clip.name != _storedClip ||
                clip.wrapMode == tk2dSpriteAnimationClip.WrapMode.Once)
            {
                _storedClip = clip.name;
                tk2dSpriteAnimationFrame frame = clip.GetFrame(frameNum);

                string clipName = frame.eventInfo;
                ClientSend.EnemyAnimation(clipName);
            }
        }
        /// <summary>Disconnects from the server and stops all network traffic.</summary>
        public void Disconnect()
        {
            isConnected = false;

            if (tcp.socket.Connected)
            {
                ClientSend.PlayerDisconnected(Instance.myId);
                tcp.socket.Close();
                Log("You have been disconnected from the server.");
            }

            SessionManager.Instance.DestroyAllPlayers();
        }
        private void OnTakeDamage(On.HeroController.orig_TakeDamage orig, HeroController hc, GameObject go,
                                  CollisionSide damageSide, int damageAmount, int hazardType)
        {
            int old_health = PlayerData.instance.health;

            orig(hc, go, damageSide, damageAmount, hazardType);

            // OnTakeDamage is called even when the player has iframes.
            // And it is called a LOT, so to avoid spamming the server, we check if the health changed before sending.
            if (PlayerData.instance.health != old_health)
            {
                Log("Took Damage: " + PlayerData.instance.health + " " + PlayerData.instance.maxHealth);
                ClientSend.HealthUpdated(PlayerData.instance.health, PlayerData.instance.maxHealth, PlayerData.instance.healthBlue);
            }
        }
Beispiel #7
0
        public static void Welcome(Packet packet)
        {
            byte   myId = packet.ReadByte();
            string msg  = packet.ReadString();

            Log($"Message from server: {msg}");
            Client.Instance.myId = myId;

            // Ideally you would do this on skin change.
            // For now we only do it when joining the server.
            //var hashes = GetTextureHashes();

            ClientSend.WelcomeReceived(/*hashes, */ Client.Instance.isHost);

            Client.Instance.udp.Connect(((IPEndPoint)Client.Instance.tcp.socket.Client.LocalEndPoint).Port);
        }
Beispiel #8
0
        private void AnimationEventDelegate(tk2dSpriteAnimator anim, tk2dSpriteAnimationClip clip, int frameNum)
        {
            if (clip.wrapMode == tk2dSpriteAnimationClip.WrapMode.Loop && clip.name != _storedClip ||
                clip.wrapMode == tk2dSpriteAnimationClip.WrapMode.LoopSection && clip.name != _storedClip ||
                clip.wrapMode == tk2dSpriteAnimationClip.WrapMode.Once)
            {
                _storedClip = clip.name;
                tk2dSpriteAnimationFrame frame = clip.GetFrame(frameNum);

                string clipName = frame.eventInfo;
                foreach (byte player in SessionManager.Instance.Players.Keys)
                {
                    ClientSend.EnemyAnimation(player, clipName, enemyId);
                }
            }
        }
Beispiel #9
0
        private void FixedUpdate()
        {
            Vector3 pos = transform.position;

            if (pos != _storedPosition)
            {
                ClientSend.EnemyPosition(pos);
                _storedPosition = pos;
            }

            Vector3 scale = transform.localScale;

            if (scale != _storedScale)
            {
                ClientSend.EnemyScale(scale);
                _storedScale = scale;
            }
        }
Beispiel #10
0
        /// <summary>Disconnects from the server and stops all network traffic.</summary>
        public void Disconnect()
        {
            isConnected = false;

            if (tcp.socket.Connected)
            {
                ClientSend.PlayerDisconnected(Instance.myId);
                tcp.socket.Close();
                Log("You have been disconnected from the server.");
            }

            udp.Disconnect();

            SessionManager.Instance.DestroyAllPlayers();

            ConnectionPanel.ConnectButton.UpdateText("Connect");
            ConnectionPanel.ConnectionInfo.UpdateText("Disconnected.");
        }
Beispiel #11
0
        private void FixedUpdate()
        {
            Vector3 heroPos = transform.position;

            if (heroPos != _storedPosition)
            {
                ClientSend.PlayerPosition(heroPos);
                _storedPosition = heroPos;
            }

            Vector3 heroScale = transform.localScale;

            if (heroScale != _storedScale)
            {
                ClientSend.PlayerScale(heroScale);
                _storedScale = heroScale;
            }
        }
        public void ReloadPlayerTextures(PlayerManager player)
        {
            foreach (var row in player.texHashes)
            {
                var hash = row.Key;
                var tt   = row.Value;

                if (loadedTextures.ContainsKey(hash))
                {
                    // Texture already loaded : ezpz
                    player.textures[tt] = loadedTextures[hash];
                }
                else
                {
                    if (MultiplayerClient.textureCache.ContainsKey(hash))
                    {
                        // Texture not loaded but on disk : also ezpz
                        byte[]    texBytes = File.ReadAllBytes(MultiplayerClient.textureCache[hash]);
                        Texture2D texture  = new Texture2D(2, 2);
                        texture.LoadImage(texBytes);

                        loadedTextures[hash] = texture;
                        player.textures[tt]  = texture;
                    }
                    else
                    {
                        // Ask the server for the texture and load it later...
                        ClientSend.RequestTexture(hash);
                    }
                }
            }

            if (player.textures.ContainsKey(TextureType.Knight))
            {
                Log("Knight tex length: " + player.textures[TextureType.Knight].EncodeToPNG().Length);
                var materialPropertyBlock = new MaterialPropertyBlock();
                player.GetComponent <MeshRenderer>().GetPropertyBlock(materialPropertyBlock);
                materialPropertyBlock.SetTexture("_MainTex", player.textures[TextureType.Knight]);
                player.GetComponent <MeshRenderer>().SetPropertyBlock(materialPropertyBlock);;
            }
        }
Beispiel #13
0
        private void FixedUpdate()
        {
            Vector3 pos = transform.position;

            if (pos != _storedPosition)
            {
                foreach (byte player in SessionManager.Instance.Players.Keys)
                {
                    ClientSend.EnemyPosition(player, pos, enemyId);
                }
                _storedPosition = pos;
            }

            Vector3 scale = transform.localScale;

            if (scale != _storedScale)
            {
                foreach (byte player in SessionManager.Instance.Players.Keys)
                {
                    ClientSend.EnemyScale(player, scale, enemyId);
                }
                _storedScale = scale;
            }
        }
        public static void CheckHashes(Packet packet)
        {
            string receivedBaldurHash    = packet.ReadString();
            string receivedFlukeHash     = packet.ReadString();
            string receivedGrimmHash     = packet.ReadString();
            string receivedHatchlingHash = packet.ReadString();
            string receivedKnightHash    = packet.ReadString();
            string receivedShieldHash    = packet.ReadString();
            string receivedSprintHash    = packet.ReadString();
            string receivedUnnHash       = packet.ReadString();
            string receivedVoidHash      = packet.ReadString();
            string receivedVSHash        = packet.ReadString();
            string receivedWeaverHash    = packet.ReadString();
            string receivedWraithsHash   = packet.ReadString();

            Dictionary <string, string> texHashes = Client.Instance.texHashes;
            Dictionary <string, byte[]> texBytes  = Client.Instance.texBytes;

            if (texHashes["Baldur"] != receivedBaldurHash)
            {
                ClientSend.SendTexture(texBytes["Baldur"], (int)ClientPackets.BaldurTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.BaldurTextureUpToDate);
            }

            if (texHashes["Fluke"] != receivedFlukeHash)
            {
                ClientSend.SendTexture(texBytes["Fluke"], (int)ClientPackets.FlukeTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.FlukeTextureUpToDate);
            }

            if (texHashes["Grimm"] != receivedGrimmHash)
            {
                ClientSend.SendTexture(texBytes["Grimm"], (int)ClientPackets.GrimmTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.GrimmTextureUpToDate);
            }

            if (texHashes["Hatchling"] != receivedHatchlingHash)
            {
                ClientSend.SendTexture(texBytes["Hatchling"], (int)ClientPackets.HatchlingTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.HatchlingTextureUpToDate);
            }

            if (texHashes["Knight"] != receivedKnightHash)
            {
                ClientSend.SendTexture(texBytes["Knight"], (int)ClientPackets.KnightTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.KnightTextureUpToDate);
            }

            if (texHashes["Shield"] != receivedShieldHash)
            {
                ClientSend.SendTexture(texBytes["Shield"], (int)ClientPackets.ShieldTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.ShieldTextureUpToDate);
            }

            if (texHashes["Sprint"] != receivedSprintHash)
            {
                ClientSend.SendTexture(texBytes["Sprint"], (int)ClientPackets.SprintTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.SprintTextureUpToDate);
            }

            if (texHashes["Unn"] != receivedUnnHash)
            {
                ClientSend.SendTexture(texBytes["Unn"], (int)ClientPackets.UnnTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.UnnTextureUpToDate);
            }

            if (texHashes["Void"] != receivedVoidHash)
            {
                ClientSend.SendTexture(texBytes["Void"], (int)ClientPackets.VoidTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.VoidTextureUpToDate);
            }

            if (texHashes["VS"] != receivedVSHash)
            {
                ClientSend.SendTexture(texBytes["VS"], (int)ClientPackets.VSTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.VSTextureUpToDate);
            }

            if (texHashes["Weaver"] != receivedWeaverHash)
            {
                ClientSend.SendTexture(texBytes["Weaver"], (int)ClientPackets.WeaverTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.WeaverTextureUpToDate);
            }

            if (texHashes["Wraiths"] != receivedWraithsHash)
            {
                ClientSend.SendTexture(texBytes["Wraiths"], (int)ClientPackets.WraithsTexture);
            }
            else
            {
                ClientSend.SendTextureUpToDate((int)ClientPackets.WraithsTextureUpToDate);
            }
        }