Пример #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);
            }
        }
Пример #2
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");
        }