Пример #1
0
        protected override void EstablishConnection(NetworkMessage message)
        {
            //Generate symmetric key + IV, save it and encrypt it with the given public assymetric key and send it to the client.
            try
            {
                if (message.TryGetObject <string>(out string publicKey))
                {
                    AsymmetricCipher asymmetric = new AsymmetricCipher();
                    asymmetric.LoadPublicKey(publicKey);
                    cipher = new SymmetricCipher();

                    SymmetricKey key = new SymmetricKey {
                        Key = asymmetric.Encrypt(cipher.Key), IV = asymmetric.Encrypt(cipher.IV)
                    };

                    Send(MessageProtocols.Setup, key, false);
                    Send(MessageProtocols.SetUsername, Username);
                    server.Broadcast(MessageProtocols.Connect, this, Username); // Tell users that it connected
                    Send(MessageProtocols.Users, server.ConnectedUsers().ToArray());
                }
                else
                {
                    throw new Exception("Failed to load the public key");
                }
            }
            catch (Exception)
            {
                Terminate();
            }
        }
Пример #2
0
 private void KickSelectedUser()
 {
     _server.Broadcast(MessageProtocols.KickUser, _users[SelectedUserIndex]);
     _server.Broadcast(MessageProtocols.Disconnect, _users[SelectedUserIndex]);
 }
Пример #3
0
 private static void server_OnSocketReceive(SocketReceiveEventArgs e)
 {
     server.Broadcast(string.Format("客户端{0}:{1}", e.Sender.EndPoint, e.Content));
 }