Ejemplo n.º 1
0
        public ViewController(IntPtr handle) : base(handle)
        {
            connectionStatus          = new System.Timers.Timer(1000);
            connectionStatus.Elapsed += Connection_Elapsed;

            onlineCheckTimer          = new System.Timers.Timer(5000);
            onlineCheckTimer.Elapsed += OnlineCheckTimer_Elapsed;

            ConfigManager = new Common.Config.Manager();

            Manager.ClientListener.OnHostInitalizeConnected += (object sender, Common.EventArgs.Network.Client.HostInitalizeConnectedEventArgs e) =>
            {
                Network.Messages.Connection.Request.HostConnectionMessage ms = new Network.Messages.Connection.Request.HostConnectionMessage();
                ms.HostSystemId   = e.HostSystemId;
                ms.ClientSystemId = e.ClientSystemId;
                ms.Password       = Manager.Manager.Encode(e.HostSystemId, this.password);
                ms.SymmetricKey   = Manager.Manager.Encode(e.HostSystemId, Manager.Manager.getSymmetricKeyForRemoteId(e.HostSystemId));

                Manager.Manager.sendMessage(ms);
            };
            Manager.ClientListener.OnClientConnected += OnClientConnected;

            Manager.ClientListener.onNetworkError        += ClientListener_onNetworkError;
            Manager.ClientListener.onPeerConnected       += ClientListener_onPeerConnected;
            Manager.ClientListener.onPeerDisconnected    += ClientListener_onPeerDisconnected;
            Manager.ClientListener.OnOnlineCheckReceived += ClientListener_OnOnlineCheckReceived;
        }
Ejemplo n.º 2
0
        public MainForm(ClientThread manager)
        {
            this.Manager = manager;
            InitializeComponent();

            connectionStatus          = new System.Timers.Timer(1000);
            connectionStatus.Elapsed += Connection_Elapsed;

            onlineCheckTimer          = new System.Timers.Timer(5000);
            onlineCheckTimer.Elapsed += OnlineCheckTimer_Elapsed;

            ConfigManager = new Common.Config.Manager();

            Manager.ClientListener.OnHostInitalizeConnected += (object sender, Common.EventArgs.Network.Client.HostInitalizeConnectedEventArgs e) =>
            {
                Network.Messages.Connection.Request.HostConnectionMessage ms = new Network.Messages.Connection.Request.HostConnectionMessage();
                ms.HostSystemId   = e.HostSystemId;
                ms.ClientSystemId = e.ClientSystemId;
                ms.Password       = Manager.Manager.Encode(e.HostSystemId, this.txtPassword.Text);
                ms.SymmetricKey   = Manager.Manager.Encode(e.HostSystemId, Manager.Manager.getSymmetricKeyForRemoteId(e.HostSystemId));

                Manager.Manager.sendMessage(ms);
            };
            Manager.ClientListener.OnClientConnected += OnClientConnected;

            Manager.ClientListener.onNetworkError        += ClientListener_onNetworkError;
            Manager.ClientListener.onPeerConnected       += ClientListener_onPeerConnected;
            Manager.ClientListener.onPeerDisconnected    += ClientListener_onPeerDisconnected;
            Manager.ClientListener.OnOnlineCheckReceived += ClientListener_OnOnlineCheckReceived;

            Manager.Start();
        }
Ejemplo n.º 3
0
        public void handleRequestHostConnection(NetPeer peer, Network.Messages.Connection.Request.HostConnectionMessage message)
        {
            NetPeer wpeer;

            if (_hostPeers.TryGetValue(message.HostSystemId, out wpeer))
            {
                wpeer.Send(_messageHandler.encodeMessage(message), SendOptions.Unreliable);
            }
        }
Ejemplo n.º 4
0
        public void handleRequestHostConnection(NetPeer peer, Network.Messages.Connection.Request.HostConnectionMessage message)
        {
            var res = new Network.Messages.Connection.Response.HostConnectionMessage();

            res.HostSystemId   = message.HostSystemId;
            res.ClientSystemId = message.ClientSystemId;
            res.PasswordOk     = false;
            var decrypt = _hostManager.Decode(message.ClientSystemId, message.Password);

            if (this._hostManager.Password == decrypt)
            {
                res.PasswordOk = true;
                var symmetricKey = _hostManager.Decode(message.ClientSystemId, message.SymmetricKey);
                _hostManager.SaveSymmetricKey(message.ClientSystemId, symmetricKey);
            }
            peer.Send(_messageHandler.encodeMessage(res), SendOptions.Unreliable);
            if (OnClientConnected != null)
            {
                OnClientConnected(this, new ClientConnectedEventArgs()
                {
                    SystemId = res.ClientSystemId, PasswordOk = res.PasswordOk
                });
            }
        }