Exemplo n.º 1
0
        private ClientGame(string name, MainWindow window, ClientNetwork network)
        {
            MainWindow   = window;
            this.network = network;
            Chat         = new ChatHandler(this);
            Player       = new Player(this, MainWindow.PlayerCard1, MainWindow.PlayerCard2, MainWindow.PlayerCard3, MainWindow.PlayerCard4)
            {
                Name = name
            };
            Opponent = new Player(this, MainWindow.OpponentCard1, MainWindow.OpponentCard2, MainWindow.OpponentCard3, MainWindow.OpponentCard4);

            // Sends init packet to server
            var packet = new Packet(CMSGPackets.CMSG_INIT_PACKET);
            var rsa    = new RsaEncryptor(RSAKey.Modulus, RSAKey.Exponent);

            aes = new AesEncryptor(AesEncryptionType.Aes256Bits)
            {
                PaddingMode = PaddingMode.PKCS7
            };
            network.Encryptor = aes;
            packet.Write(rsa.Encrypt(aes.Encryptors));
            packet.Write(aes.Encrypt(name));
            rsa.Dispose();

            SendPacket(packet, false);
            networkConnectionTask = Task.Run(UpdateAsync, tokenSource.Token);
        }
Exemplo n.º 2
0
        // Creates new instance of game
        public static async Task <ClientGame> CreateAsync(string name, string server, MainWindow window)
        {
            var network = await ClientNetwork.CreateAsync(server, port);

            if (network == null)
            {
                return(null);
            }

            return(new ClientGame(name, window, network));
        }