Exemplo n.º 1
0
        private void _server_DataReceived(object sender, ServerDataRecievedArgs e)
        {
            int _cmd = BitConverter.ToInt32(e.DataRecieved, 0);

            if (_cmd == (int)ServerCommand.NotifyConnected)
            {
                _server.SetLoggedIn();
                Output("Logged in...");
            }
            else if (_cmd == (int)ServerCommand.ClientAlreadyConnected)
            {
                Output("Cannot connect; already connected");
                _server.Disconnect();
            }
            else if (_cmd == (int)ServerCommand.ServerShutdown)
            {
                Output("Disconnected; Server shutting down...");
                _server.OnServerShutdown();
            }
            else if (_cmd == (int)ServerCommand.ChannelList)
            {
                byte[] _serializedlist = new byte[e.DataRecieved.Length - 4];
                Array.Copy(e.DataRecieved, 4, _serializedlist, 0, _serializedlist.Length);
                object s = Serializer.DeserializeObject(_serializedlist);
                ChannelList = s as Packet_ChannelList;
                UpdateUi();
            }
            else if (_cmd == (int)ServerCommand.MessageFromClient)
            {
                byte[] _serialized = new byte[e.DataRecieved.Length - 4];
                Array.Copy(e.DataRecieved, 4, _serialized, 0, _serialized.Length);
                Packet_MessageFromClient _msg = (Packet_MessageFromClient)Serializer.DeserializeObject(_serialized);
                Output(_msg.Dest + ": " + _msg.Message);
            }
        }
Exemplo n.º 2
0
        private void _server_Disconnected(object sender, IPEndPoint e)
        {
            ConnectButton.Visibility    = Visibility.Visible;
            DisconnectButton.Visibility = Visibility.Hidden;

            ChannelList = new Packet_ChannelList(null);
            UpdateUi();
        }
Exemplo n.º 3
0
 void Event_ConnectionFailed(object Sender, IPEndPoint Server)
 {
     _server = null;
     DisconnectButton.Visibility = Visibility.Hidden;
     Output("Failed to connect to " + Server.ToString());
     ChannelList = new Packet_ChannelList(null);
     UpdateUi();
     this.Close();
 }
Exemplo n.º 4
0
        private void _server_ServerShutdown(object sender, IPEndPoint e)
        {
            this.Dispatcher.Invoke(new Action(() =>
            {
                DisconnectButton.Visibility = Visibility.Hidden;
            }));

            ChannelList = new Packet_ChannelList(null);
            UpdateUi();
        }
Exemplo n.º 5
0
        private void _server_Disconnected(object sender, IPEndPoint e)
        {
            ChannelList = new Packet_ChannelList(null);
            UpdateUi();
            BuildContextMenu();
            _server = null;

            try
            {
                this.Close();
            }
            catch (Exception ex) { }
        }
Exemplo n.º 6
0
        private void _server_ConnectionError(object sender, IPEndPoint e)
        {
            System.Windows.MessageBox.Show("Connection lost to " + _server.ConnectedAddress.ToString());
            ChannelList = new Packet_ChannelList(null);
            UpdateUi();
            BuildContextMenu();
            _server = null;

            try
            {
                this.Dispatcher.Invoke(new Action(() =>
                {
                    this.Close();
                }));
            }
            catch (Exception ex) { }
        }
Exemplo n.º 7
0
        private void _server_DataReceived(object sender, ServerDataRecievedArgs e)
        {
            int _cmd = BitConverter.ToInt32(e.DataRecieved, 0);

            Debug.WriteLine("RECEIVED COMMAND " + _cmd);
            if (_cmd == (int)ServerCommand.NotifyConnected)
            {
                _server.SetLoggedIn();
                Output("Logged in...");
            }
            else if (_cmd == (int)ServerCommand.ClientAlreadyConnected)
            {
                Output("Cannot connect; already connected");
                _server.Disconnect();
            }
            else if (_cmd == (int)ServerCommand.ServerShutdown)
            {
                Output("Disconnected; Server shutting down...");
                _server.OnServerShutdown();
            }
            else if (_cmd == (int)ServerCommand.ChannelList)
            {
                byte[] _serializedlist = new byte[e.DataRecieved.Length - 4];
                Array.Copy(e.DataRecieved, 4, _serializedlist, 0, _serializedlist.Length);
                object s = Serializer.DeserializeObject(_serializedlist);
                ChannelList = s as Packet_ChannelList;
                UpdateUi();
            }
            else if (_cmd == (int)ServerCommand.MessageFromClient)
            {
                byte[] _serialized = new byte[e.DataRecieved.Length - 4];
                Array.Copy(e.DataRecieved, 4, _serialized, 0, _serialized.Length);
                Packet_MessageFromClient _msg = (Packet_MessageFromClient)Serializer.DeserializeObject(_serialized);
                Output(_msg.Dest + ": " + _msg.Message);
            }
            else if (_cmd == (int)ServerCommand.ImageFromClient)
            {
                byte[] _serialized = new byte[e.DataRecieved.Length - 4];
                Array.Copy(e.DataRecieved, 4, _serialized, 0, _serialized.Length);
                Packet_ImageFromClient _packet = (Packet_ImageFromClient)Serializer.DeserializeObject(_serialized);
                Output("Recevied " + _packet.Image.Length + " byte image from " + _packet.Sender);


                Bitmap _img = (Bitmap)Serializer.DeserializeObject(_packet.Image);
                ReceivedImagesList.Add(_packet);

                LatestImage = _img;


                Notifications.BalloonTipTitle = GetNameFromId(_packet.Sender);
                Notifications.BalloonTipText  = _packet.ImageName;
                Notifications.Tag             = "img";
                Notifications.ShowBalloonTip(1000);
            }
            else if (_cmd == (int)ServerCommand.ServerMessage)
            {
                byte[] _serialized = new byte[e.DataRecieved.Length - 4];
                Array.Copy(e.DataRecieved, 4, _serialized, 0, _serialized.Length);
                Packet_ServerMessage _packet = (Packet_ServerMessage)Serializer.DeserializeObject(_serialized);
                Output("Server: " + _packet.Message);
            }
            BuildContextMenu();

            Debug.WriteLine("ENDED DATA PARSING");
        }