示例#1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtMessage.Text))
                {
                    return;
                }
                Data msgToSend = new Data
                {
                    userName   = userName,
                    strMessage = txtMessage.Text,
                    cmdCommand = Command.Message
                };

                byte[] byteData = msgToSend.ToByte();

                clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, server, new AsyncCallback(OnSend), null);

                txtMessage.Text = string.Empty;
            }
            catch (Exception)
            {
                MessageBox.Show("An error occured while sending the message.", "Client: " + userName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnConnect_Click(object sender, EventArgs e)
        {
            userName = txtUsername.Text;
            try
            {
                clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                IPAddress  ipAddress  = IPAddress.Parse(txtIp.Text);
                IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 1000);

                epServer = ipEndPoint;

                Data msgToSend = new Data
                {
                    cmdCommand = Command.Login,
                    strMessage = null,
                    userName   = userName
                };

                byte[] byteData = msgToSend.ToByte();

                clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Client",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        private void Client_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;

            this.Text = "Client: " + userName;

            Data msgToSend = new Data
            {
                cmdCommand = Command.List,
                userName   = userName,
                strMessage = null
            };

            byteData = msgToSend.ToByte();

            clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, server,
                                     new AsyncCallback(OnSend), null);

            byteData = new byte[1024];
            clientSocket.BeginReceiveFrom(byteData,
                                          0, byteData.Length,
                                          SocketFlags.None,
                                          ref server,
                                          new AsyncCallback(OnReceive),
                                          null);
        }
示例#4
0
        private void UserForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to leave the chat room?", "Client: " + userName,
                                MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
            {
                e.Cancel = true;
                return;
            }

            try
            {
                Data msgToSend = new Data
                {
                    cmdCommand = Command.Logout,
                    userName   = userName,
                    strMessage = null
                };

                byte[] b = msgToSend.ToByte();
                clientSocket.SendTo(b, 0, b.Length, SocketFlags.None, server);
                clientSocket.Close();
            }
            catch (ObjectDisposedException)
            { }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Client: " + userName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void OnConnect(IAsyncResult ar)
        {
            try
            {
                clientSocket.EndConnect(ar);

                //We are connected so we login into the server
                string l_fhName;
                string l_fhPass;
                Data   msgToSend = new Data();
                msgToSend.cmdCommand = Command.Login;

                //Username
                getNameDelegate fhName = new getNameDelegate(getLoginName);
                l_fhName = (string)this.UserNameTextBox.Dispatcher.Invoke(fhName, null);

                //Pass
                getPassDelegate fhPass = new getPassDelegate(getLoginPass);
                l_fhPass = (string)this.UserNameTextBox.Dispatcher.Invoke(fhPass, null);

                //Data set
                msgToSend.strName    = l_fhName;
                msgToSend.strMessage = l_fhPass;
                msgToSend.strRec     = Data.PUBLIC_ID;

                byte[] b = msgToSend.ToByte();

                //Send the message to the server
                clientSocket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SGSclient");
            }
        }
示例#6
0
文件: LoginForm.cs 项目: jpmac26/AODX
        private void btn_Connect_Click(object sender, EventArgs e)
        {
            btn_Connect.Load("base/misc/btn_connect_pressed.png");
            try
            {
                if (serverList.Items.Count > 0 && serverList.SelectedItem != null && clientSocket != null)
                {
                    Data msgToSend = new Data();
                    msgToSend.cmdCommand = Command.PacketSize;

                    byte[] message = msgToSend.ToByte();

                    clientSocket.BeginSend(message, 0, message.Length, SocketFlags.None, new AsyncCallback(OnSend), null);

                    clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
                }
            }
            catch (Exception ex)
            {
                if (Program.debug)
                {
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace.ToString(), "AODXClient", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#7
0
        private void buttonOpen_Click(object sender, RoutedEventArgs e)
        {
            //Test task list
            //Task.Factory.StartNew(() => TestTask());

            // Configure open file dialog box
            var dialog = new Microsoft.Win32.OpenFileDialog();

            dialog.FileName   = "Picture";              // Default file name
            dialog.DefaultExt = ".png";                 // Default file extension
            dialog.Filter     = "Pictures(.png)|*.png"; // Filter files by extension

            // Show open file dialog box
            bool?result = dialog.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                _filename = dialog.FileName;

                //Send Upload Data
                Data msgToSend = new Data();
                msgToSend.cmdCommand = Command.Upload;
                msgToSend.strName    = LoginName;
                msgToSend.strRec     = _partner;
                msgToSend.strMessage = Path.GetFileName(_filename);
                byte[] b = msgToSend.ToByte();
                ClientSocket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), ClientSocket);

                Task.Factory.StartNew(() => UploadTask());
            }
        }
示例#8
0
        private void buttonDownload_Click(object sender, RoutedEventArgs e)
        {
            //FájlLista lekérés küldése
            Data msgToSend = new Data();

            msgToSend.cmdCommand = Command.DownloadList;
            msgToSend.strName    = LoginName;
            msgToSend.strMessage = null;
            msgToSend.strRec     = _partner;
            byte[] b = msgToSend.ToByte();
            ClientSocket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), ClientSocket);
        }
示例#9
0
        //Send a message
        private void buttonSend_Click(object sender, RoutedEventArgs e)
        {
            Data msgToSend = new Data();

            msgToSend.cmdCommand = Command.Message;
            msgToSend.strName    = LoginName;
            msgToSend.strRec     = _partner;
            msgToSend.strMessage = MessageTextBox.Text;

            byte[] b = msgToSend.ToByte();
            ClientSocket.BeginSend(b, 0, b.Length, SocketFlags.None,
                                   new AsyncCallback(OnSend), ClientSocket);
        }
示例#10
0
文件: CharForm.cs 项目: jpmac26/AODX
        private void btn_Login_Click(object sender, EventArgs e)
        {
            Data msgToSend = new Data();
            msgToSend.cmdCommand = Command.Login;
            msgToSend.strName = strName;

            DialogResult = DialogResult.OK;

            byte[] b = msgToSend.ToByte();

            //Send the message to the server
            clientSocket?.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), null);

            //clientSocket?.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);

            DialogResult = DialogResult.OK;
            Close();
        }
示例#11
0
文件: CharForm.cs 项目: jpmac26/AODX
        private void btn_Login_Click(object sender, EventArgs e)
        {
            Data msgToSend = new Data();

            msgToSend.cmdCommand = Command.Login;
            msgToSend.strName    = strName;

            DialogResult = DialogResult.OK;

            byte[] b = msgToSend.ToByte();

            //Send the message to the server
            clientSocket?.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), null);

            //clientSocket?.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);

            DialogResult = DialogResult.OK;
            Close();
        }
示例#12
0
        void ClientsWindow_Closing(object sender, CancelEventArgs e)
        {
            if (!_safeClose)
            {
                //Event leállítás
                e.Cancel = true;

                //Kilépési adat
                Data msgToSend = new Data();
                msgToSend.cmdCommand = Command.Logout;
                msgToSend.strName    = LoginName;
                msgToSend.strRec     = Data.PUBLIC_ID;
                msgToSend.strMessage = null;

                //Kilépés küldése
                byte[] b = msgToSend.ToByte();
                ClientSocket.Send(b);
            }
        }
示例#13
0
文件: LoginForm.cs 项目: jpmac26/AODX
        private void btn_Connect_Click(object sender, EventArgs e)
        {
            btn_Connect.Load("base/misc/btn_connect_pressed.png");
            try
            {
                if (serverList.Items.Count > 0 && serverList.SelectedItem != null && clientSocket != null)
                {
                    Data msgToSend = new Data();
                    msgToSend.cmdCommand = Command.PacketSize;

                    byte[] message = msgToSend.ToByte();

                    clientSocket.BeginSend(message, 0, message.Length, SocketFlags.None, new AsyncCallback(OnSend), null);

                    clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
                }
            }
            catch (Exception ex)
            {
                if (Program.debug)
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace.ToString(), "AODXClient", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#14
0
        //Broadcast the message typed by the user to everyone
        private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                //Fill the info for the message to be send
                Data msgToSend = new Data();

                msgToSend.strName = strName;
                msgToSend.strMessage = txtMessage.Text;
                msgToSend.cmdCommand = Command.Message;

                byte[] byteData = msgToSend.ToByte();

                //Send it to the server
                clientSocket.BeginSendTo (byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null);

                txtMessage.Text = null;
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to send message to the server.", "SGSclientUDP: " + strName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#15
0
文件: LoginForm.cs 项目: jpmac26/AODX
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                while (byteData[0] == 4 && byteData.Length < incomingSize)
                {
                    //string test = "";
                }

                clientSocket.EndReceive(ar);

                if (byteData[0] == 8)
                {
                    EviData msg = new EviData(byteData);

                    Evidence evi = new Evidence();
                    evi.name = msg.strName;
                    evi.desc = msg.strDesc;
                    evi.note = msg.strNote;
                    evi.index = msg.index;

                    using (MemoryStream ms = new MemoryStream(msg.dataBytes))
                    {
                        evi.icon = Image.FromStream(ms,false,true);
                    }

                    eviList.Add(evi);

                    //string dirName = "";
                    //for (int x = 0; x < msg.strName.Split('/').Length - 1; x++)
                    //{
                    //    dirName = dirName + msg.strName.Split('/')[x];
                    //    if (x < msg.strName.Split('/').Length - 2)
                    //        dirName = dirName + '/';
                    //}
                    //if (!Directory.Exists(dirName))
                    //    Directory.CreateDirectory(dirName);

                    //using (FileStream fs = new FileStream(msg.strName, FileMode.Create))
                    //{
                    //    using (BinaryWriter w = new BinaryWriter(fs))
                    //    {
                    //        if (msg.dataSize > 0)
                    //            w.Write(msg.dataBytes.Take(msg.dataSize).ToArray());
                    //    }
                    //}

                    clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
                }
                else
                {

                    Data msgReceived = new Data(byteData);

                    if (msgReceived.cmdCommand == Command.Disconnect)
                    {
                        MessageBox.Show("You are banned from this server!");
                        btn_Connect.Image = Image.FromFile("base/misc/btn_connect.png");
                        //clientSocket.Close();
                        //Close();
                    }
                    else if (msgReceived.cmdCommand == Command.PacketSize)
                    {
                        incomingSize = Convert.ToInt32(msgReceived.strMessage);
                        byteData = new byte[incomingSize];

                        //DialogResult = DialogResult.OK;
                        Data msgToSend = new Data();
                        msgToSend.cmdCommand = Command.DataInfo;

                        byte[] b = msgToSend.ToByte();

                        //Send the message to the server
                        clientSocket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), null);

                        clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
                        //Close();
                    }
                    else if (msgReceived.cmdCommand == Command.DataInfo)
                    {
                        if (msgReceived.strMessage != null && msgReceived.strMessage != "")
                        {
                            string[] data = msgReceived.strMessage.Split('|');
                            int charCount = Convert.ToInt32(data[0]);
                            if (charCount > 0)
                            {
                                for (int x = 1; x < charCount; x++)
                                {
                                    charList.Add(data[x]);
                                }
                            }

                            int songCount = Convert.ToInt32(data[charCount + 1]);
                            if (songCount > 0)
                            {
                                for (int x = charCount + 2; x < charCount + 2 + songCount; x++)
                                {
                                    musicList.Add(data[x]);
                                }
                            }
                        }

                        byteData = new byte[4194304];
                        //Do stuff with the evidence/extra binary data here

                    }
                    else
                        clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);

                    if (msgReceived.cmdCommand == Command.DataInfo)
                    {
                        //Program.charList = charList;
                        //Program.musicList = musicList;
                        //Program.connection = clientSocket;
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }
            }
            catch (SocketException)
            {
                if (MessageBox.Show("You have been disconnected from the server.", "AODXClient", MessageBoxButtons.OK) == DialogResult.OK | MessageBox.Show("You have been kicked from the server.", "AODXClient", MessageBoxButtons.OK) == DialogResult.Cancel)
                    Close();
            }
            catch (ObjectDisposedException)
            { }
            catch (Exception ex)
            {
                if (Program.debug)
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace.ToString(), "AODXClient", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#16
0
        private void Form1_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
            strName = util.globals.local_name;
            this.Text = "SGSclient: " + strName;

            //The user has logged into the system so we now request the server to send
            //the names of all users who are in the chat room
            Data msgToSend = new Data ();
            msgToSend.cmdCommand = Command.List;
            msgToSend.strName = strName;
            msgToSend.strMessage = null;

            byteData = msgToSend.ToByte();

            clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer,
                new AsyncCallback(OnSend), null);

            byteData = new byte[1024];
            //Start listening to the data asynchronously
            clientSocket.BeginReceiveFrom (byteData,
                                       0, byteData.Length,
                                       SocketFlags.None,
                                       ref epServer,
                                       new AsyncCallback(OnReceive),
                                       null);
        }
示例#17
0
        private void ClientForm_Load(object sender, EventArgs e)
        {
            nameLabel.Text = "";

            if (iniParser.GetSide(strName) != "jud")
            {
                btn_crossexamination.Visible = false;
                btn_crossexamination.Enabled = false;
                btn_edit.Visible = false;
                btn_edit.Enabled = false;
                courtRecordPB.Image = Image.FromFile("base/misc/inventory.png");
                btn_testimony.Visible = false;
                btn_testimony.Enabled = false;
                btn_defminus.Visible = false;
                btn_defminus.Enabled = false;
                btn_defplus.Visible = false;
                btn_defplus.Enabled = false;
                btn_prominus.Visible = false;
                btn_prominus.Enabled = false;
                btn_proplus.Visible = false;
                btn_proplus.Enabled = false;
                txtLog.Size = new Size(240, 347);
            }

            fonts.AddFontFile("base/misc/Ace-Attorney-2.ttf");

            musicList.Items.Clear();

            foreach (string song in songs)
                musicList.Items.Add(song);

            Text = "AODXClient: " + strName;

            emoCount = iniParser.GetEmoNum(strName);
            emoMaxPages = (int)Math.Floor((decimal)(emoCount / 10));

            loadEmoButtons();
            loadEviButtons();

            //byteData = new byte[incomingSize];
            byteData = new byte[1048576];

            //The user has logged into the system so we now request the server to send
            //the names of all users who are in the chat room
            Data msgToSend = new Data();
            msgToSend.cmdCommand = Command.List;
            msgToSend.strName = strName;

            byteData = msgToSend.ToByte();

            clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null);

            byteData = new byte[1048576];

            //Start listening to the data asynchronously
            clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
        }
示例#18
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add some name detection from forms.
            strName = "nicktest";
            world = new WorldGraphics();
            model = new GraphicsModel();
            world.SetGraphicsModel(model);

            //Setup ships for players 1 & 2 (offscreen to start)
            //GraphicsObject(int id, float x, float y, float radius, float angle, int spriteID, int colorID)
            GraphicsObject ship1 = new GraphicsObject(1, 0, 0, 16, 0, 1, 5);
            model.Update(ship1);
            shipList.Add(ship1);
            GraphicsObject ship2 = new GraphicsObject(2, -16, -16, 16, 0, 1, 7);
            model.Update(ship2);
            shipList.Add(ship2);

            //Setup planet
            GraphicsObject planet = new GraphicsObject(3, 400, 300, 32, 0, 201, 0);
            model.Update(planet);
            planetList.Add(planet);

            //******** Networking Stuff *************
            //Using UDP sockets
            clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            Console.WriteLine(ipAddress);

            //Server is listening on port 1000
            IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 11000);
            epServer = (EndPoint)ipEndPoint;

            //Get message ready
            Data msgToSend = new Data();
            msgToSend.cmdCommand = Command.Login;
            msgToSend.strMessage = null;
            msgToSend.strName = strName;
            byte[] byteData = msgToSend.ToByte();

            //Login to the server
            clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null);
            byteData = new byte[1024];
            //Start listening to the data asynchronously
            clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epServer, new AsyncCallback(OnReceive), null);
            //******** End Networking Stuff *************
            base.Initialize();
        }
示例#19
0
        private void btn_testimony_Click(object sender, EventArgs e)
        {
            if (btn_testimony.Visible == true)
            {
                Data calloutMsg = new Data();
                calloutMsg.callout = 4;
                calloutMsg.cmdCommand = Command.Message;

                byte[] msg = calloutMsg.ToByte();
                clientSocket.BeginSend(msg, 0, msg.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
            }
        }
示例#20
0
 private void btn_proplus_Click(object sender, EventArgs e)
 {
     if (btn_proplus.Visible == true)
     {
         if (proHealth < 5)
         {
             Data msg = new Data();
             msg.cmdCommand = Command.ChangeHealth;
             msg.strName = "pro";
             msg.strMessage = "+1";
             byte[] byteMsg = msg.ToByte();
             clientSocket.BeginSend(byteMsg, 0, byteMsg.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
         }
     }
 }
示例#21
0
        private async void DownloadTask(string filename, string sender, string receiver)
        {
            //Wait for others to finish
            if (_isDownloading)
            {
                Thread.Sleep(2000);
            }

            //Set the pooling flag
            _isDownloading = true;

            //Send download starter
            try
            {
                byte[] message;
                Data   msgToSend = new Data();
                msgToSend.cmdCommand = Command.StartDownload;
                msgToSend.strName    = sender;
                msgToSend.strRec     = receiver;
                msgToSend.strMessage = Path.GetFileName(filename);
                message = msgToSend.ToByte();
                ClientSocket.BeginSend(message, 0, message.Length, SocketFlags.None,
                                       new AsyncCallback(OnSend), ClientSocket);
            }
            catch (Exception ex)
            {
                new Thread(() =>
                {
                    MessageBox.Show(ex.Message, "Client Download Start");
                }).Start();
            }

            var listener = new TcpListener(_endPoint.Address, Data.DOWNLOAD_PORT);

            listener.Start();
            try
            {
                using (var client = await listener.AcceptTcpClientAsync())
                    using (var stream = client.GetStream())
                        using (var output = File.Create(filename))
                        {
                            try
                            {
                                //Console.WriteLine("Server connected. Starting to receive the file.");

                                // read the file in chunks of 1KB
                                var buffer = new byte[1024];
                                int bytesRead;
                                while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    output.Write(buffer, 0, bytesRead);
                                }
                            }
                            catch (Exception ex)
                            {
                                new Thread(() =>
                                {
                                    MessageBox.Show(ex.Message, "Client Download");
                                }).Start();
                            }
                        }
            }
            catch (Exception ex)
            {
                new Thread(() =>
                {
                    MessageBox.Show(ex.Message, "Client Download Using");
                }).Start();
            }
            listener.Stop();
            //Console.WriteLine("Server Disconnected.");

            _isDownloading = false;

            //Send an ack message
            try
            {
                byte[] message;
                Data   msgToSend = new Data();
                msgToSend.cmdCommand = Command.DownloadAck;
                msgToSend.strName    = sender;
                msgToSend.strRec     = receiver;
                msgToSend.strMessage = Path.GetFileName(filename);
                message = msgToSend.ToByte();
                ClientSocket.BeginSend(message, 0, message.Length, SocketFlags.None,
                                       new AsyncCallback(OnSend), ClientSocket);
            }
            catch (Exception ex)
            {
                new Thread(() =>
                {
                    MessageBox.Show(ex.Message, "Client Download End");
                }).Start();
            }
        }
示例#22
0
        private void musicList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (musicList.Items.Count > 0 && musicList.SelectedItem != null && (string)musicList.SelectedItem != "")
            {
                Data msgToSend = new Data();
                msgToSend.cmdCommand = Command.ChangeMusic;
                msgToSend.strName = strName;
                msgToSend.strMessage = (string)musicList.Items[musicList.SelectedIndex];
                byte[] msg = msgToSend.ToByte();

                clientSocket.BeginSend(msg, 0, msg.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
                //byteData = new byte[1024];

                //clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
            }
        }
示例#23
0
        /// <summary>
        /// Allows the game gather input from the user.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Capture keyboard input

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            //Turn right
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Right))
            {
                Data msgToSend = new Data();
                msgToSend.strName = strName;
                msgToSend.playerID = playerID;
                msgToSend.strMessage = "right";
                msgToSend.cmdCommand = Command.Move;
                byte[] byteData = msgToSend.ToByte();
                //Send it to the server
                clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null);
            }

            //Turn left
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Left))
            {
                Data msgToSend = new Data();
                msgToSend.strName = strName;
                msgToSend.playerID = playerID;
                msgToSend.strMessage = "left";
                msgToSend.cmdCommand = Command.Move;
                byte[] byteData = msgToSend.ToByte();
                //Send it to the server
                clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null);
            }

            //Speed up
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Up))
            {
                Data msgToSend = new Data();
                msgToSend.strName = strName;
                msgToSend.playerID = playerID;
                msgToSend.strMessage = "up";
                msgToSend.cmdCommand = Command.Move;
                byte[] byteData = msgToSend.ToByte();
                //Send it to the server
                clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null);
            }

            //Slow down
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Down))
            {
                Data msgToSend = new Data();
                msgToSend.strName = strName;
                msgToSend.playerID = playerID;
                msgToSend.strMessage = "down";
                msgToSend.cmdCommand = Command.Move;
                byte[] byteData = msgToSend.ToByte();
                //Send it to the server
                clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null);
            }

            //For shooting, we want to limit the number of bullets that can be created (fire rate)
            double gameTimeNow = gameTime.TotalGameTime.TotalMilliseconds;
            //Check how long it's been since the last shot.
            if (gameTimeNow - dwTimePrevUpdate > 500)
            {
                //Check the shoot button is pressed
                if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Space))
                {
                    Data msgToSend = new Data();
                    msgToSend.strName = strName;
                    dwTimePrevUpdate = gameTime.TotalGameTime.TotalMilliseconds;
                    msgToSend.playerID = playerID;
                    msgToSend.strMessage = "shoot";
                    msgToSend.cmdCommand = Command.Move;
                    byte[] byteData = msgToSend.ToByte();
                    //Send it to the server
                    clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null);

                }
            }

            //Get the list of graphics objects
            List<GraphicsObject> list = model.GetAsList();
            //Call a new update.
            base.Update(gameTime);
        }
示例#24
0
        private void ClientForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            /* if (MessageBox.Show("Are you sure you want to leave the courtroom?", "AODXClient: " + strName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
            {
                e.Cancel = true;
                return;
            } */

            try
            {
                //Send a message to logout of the server
                Data msgToSend = new Data();
                msgToSend.cmdCommand = Command.Logout;
                msgToSend.strName = strName;
                msgToSend.strMessage = null;

                byte[] b = msgToSend.ToByte();
                if (clientSocket.Connected)
                    clientSocket.Send(b, 0, b.Length, SocketFlags.None);
                clientSocket.Close();
                if (sfxPlayer != null)
                    sfxPlayer.Dispose();
                if (wr != null)
                    wr.Dispose();
                if (blipPlayer != null)
                    blipPlayer.Dispose();
                if (blipReader != null)
                    blipReader.Dispose();
                if (musicPlayer != null)
                    musicPlayer.Dispose();
                if (musicReader != null)
                    musicReader.Dispose();

                if (Directory.Exists("base/cases"))
                    Directory.Delete("base/cases", true);
            }
            catch (SocketException)
            { }
            catch (ObjectDisposedException)
            { }
            catch (Exception ex)
            {
                if (Program.debug)
                    MessageBox.Show(ex.Message + ".\r\n" + ex.StackTrace.ToString(), "AODXClient: " + strName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#25
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                clientSocket.EndReceive(ar);

                if (byteData[0] == 8)
                {
                    EviData data = new EviData(byteData);

                    Evidence evi = new Evidence();
                    evi.name = data.strName;
                    evi.desc = data.strDesc;
                    evi.note = data.strNote;
                    evi.index = data.index;

                    using (MemoryStream ms = new MemoryStream(data.dataBytes))
                    {
                        evi.icon = Image.FromStream(ms, false, true);
                    }

                    bool found = false;
                    foreach (Evidence item in eviList)
                    {
                        if (item.index == evi.index)
                        {
                            found = true;
                            item.name = evi.name;
                            item.note = evi.note;
                            item.desc = evi.desc;
                            item.icon = evi.icon;
                            break;
                        }
                    }
                    if (found == false)
                        eviList.Add(evi);

                    testimonyPB.Location = new Point(257, 3);
                    testimonyPB.BringToFront();
                    PictureBox icon = new PictureBox();
                    icon.Image = evi.icon;
                    icon.Location = new Point(6, 5);
                    icon.Size = new Size(70, 70);
                    icon.BringToFront();
                    testimonyPB.Invoke((MethodInvoker)delegate
                    {
                        //perform on the UI thread
                        testimonyPB.Controls.Add(icon);
                    });
                    Label name = new Label();
                    name.Text = evi.name;
                    name.Location = new Point(91, 8);
                    name.Size = new Size(155, 17);
                    name.TextAlign = ContentAlignment.MiddleCenter;
                    name.ForeColor = Color.DarkOrange;
                    name.BackColor = Color.Transparent;
                    //name.Font = new Font(fonts.Families[0], 12.0f, FontStyle.Bold);
                    name.BringToFront();
                    testimonyPB.Invoke((MethodInvoker)delegate
                    {
                        //perform on the UI thread
                        testimonyPB.Controls.Add(name);
                    });
                    Label note = new Label();
                    note.Text = evi.note;
                    note.Location = new Point(92, 26);
                    note.Size = new Size(153, 44);
                    //note.Font = new Font(fonts.Families[0], 12.0f);
                    note.BackColor = Color.Transparent;
                    note.BringToFront();
                    testimonyPB.Invoke((MethodInvoker)delegate
                    {
                        //perform on the UI thread
                        testimonyPB.Controls.Add(note);
                    });
                    Label desc = new Label();
                    desc.Text = evi.desc;
                    desc.Location = new Point(9, 81);
                    desc.Size = new Size(238, 45);
                    //desc.Font = new Font(fonts.Families[0], 12.0f);
                    desc.BackColor = Color.Transparent;
                    desc.ForeColor = Color.White;
                    desc.BringToFront();
                    testimonyPB.Invoke((MethodInvoker)delegate
                    {
                        //perform on the UI thread
                        testimonyPB.Controls.Add(desc);
                    });
                    testimonyPB.Size = new Size(256, 127);
                    testimonyPB.Image = Image.FromFile("base/misc/inventory_update.png");
                    wr = new WaveFileReader("base/sounds/general/sfx-selectjingle.wav");

                    sfxPlayer.Initialize(wr);
                    if (!mute)
                        sfxPlayer.Play();

                    for (int x = 0; x <= 64; x++)
                    {
                        testimonyPB.Location = new Point(256 - (4 * x), 3);
                        //icon.Location = new Point(256 + 6 - (2 * x), 3 + 5);
                        //name.Location = new Point(256 + 91 - (2 * x), 3 + 8);
                        //note.Location = new Point(256 + 92 - (2 * x), 3 + 26);
                        //desc.Location = new Point(256 + 9 - (2 * x), 3 + 81);
                        icon.Refresh();
                        name.Refresh();
                        note.Refresh();
                        desc.Refresh();
                    }

                    System.Threading.Thread.Sleep(3000);

                    for (int x = 0; x <= 64; x++)
                    {
                        testimonyPB.Location = new Point(0 - (4 * x), 3);
                        //icon.Location = new Point(6 - (2 * x), 3 + 5);
                        //name.Location = new Point(91 - (2 * x), 3 + 8);
                        //note.Location = new Point(92 - (2 * x), 3 + 26);
                        //desc.Location = new Point(9 - (2 * x), 3 + 81);
                        icon.Refresh();
                        name.Refresh();
                        note.Refresh();
                        desc.Refresh();
                    }

                    testimonyPB.Image = null;
                    name.Dispose();
                    icon.Dispose();
                    desc.Dispose();
                    note.Dispose();
                }
                else
                {
                    Data msgReceived = new Data(byteData);

                    //Accordingly process the message received
                    switch (msgReceived.cmdCommand)
                    {
                        case Command.Login:
                            break;

                        case Command.Logout:
                            break;

                        case Command.ChangeMusic:
                            if (msgReceived.strMessage != null && msgReceived.strMessage != "" & msgReceived.strName != null)
                            {
                                appendTxtLogSafe("<<<" + msgReceived.strName + " changed the music to " + msgReceived.strMessage + ">>>\r\n");
                                musicReader = new DmoMp3Decoder("base/sounds/music/" + msgReceived.strMessage);

                                if (musicPlayer.PlaybackState != PlaybackState.Stopped)
                                    musicPlayer.Stop();
                                musicPlayer.Initialize(musicReader);
                                if (!mute)
                                    musicPlayer.Play();
                            }
                            break;

                        case Command.ChangeHealth:
                            if (msgReceived.strName == "def")
                            {
                                if (msgReceived.strMessage == "-1")
                                    defHealth--;
                                else if (msgReceived.strMessage == "+1")
                                    defHealth++;
                            }
                            else if (msgReceived.strName == "pro")
                            {
                                if (msgReceived.strMessage == "-1")
                                    proHealth--;
                                else if (msgReceived.strMessage == "+1")
                                    proHealth++;
                            }

                            updateHealth();
                            break;

                        case Command.Message:
                        case Command.Present:
                            if (latestMsg != null && msgReceived.strName == latestMsg.strName)
                            {
                                newGuy = false;
                            }
                            else
                            {
                                newGuy = true;
                                testimonyPB.Image = null;
                            }

                            latestMsg = msgReceived;
                            objectLayerPB.Image = null;
                            objectLayerPB.Location = new Point(0, 0);
                            objectLayerPB.Size = new Size(256, 192);

                            if (msgReceived.callout <= 3)
                            {
                                sendEnabled = false;
                                curPreAnimTime = 0;
                                curPreAnimTime = 0;
                                curPreAnim = null;
                                soundTime = 0;
                                curSoundTime = 0;

                                if (msgReceived.callout > 0)
                                    performCallout();

                                if (iniParser.GetSoundName(msgReceived.strName, msgReceived.anim) != "1" && iniParser.GetSoundTime(msgReceived.strName, msgReceived.anim) > 0 & File.Exists("base/sounds/general/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav"))
                                {
                                    sfxPlayer.Stop();
                                    wr = new WaveFileReader("base/sounds/general/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav");
                                    sfxPlayer.Initialize(wr);
                                    soundTime = iniParser.GetSoundTime(msgReceived.strName, msgReceived.anim);
                                }

                                /*  if (iniParser.GetSoundName(msgReceived.strName, msgReceived.anim) != "1" && iniParser.GetSoundTime(msgReceived.strName, msgReceived.anim) > 0 & (File.Exists("base/sounds/general/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav") | File.Exists("base/characters/" + latestMsg.strName + "/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav")))
                                {
                                    sfxPlayer.Stop();
                                    if (File.Exists("base/characters/" + latestMsg.strName + "/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav"))
                                        wr = new WaveFileReader("base/characters/" + latestMsg.strName + "/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav");
                                    else
                                        wr = new WaveFileReader("base/sounds/general/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav");
                                    sfxPlayer.Initialize(wr);
                                    soundTime = iniParser.GetSoundTime(msgReceived.strName, msgReceived.anim);
                                } */

                                if (iniParser.GetAnimType(msgReceived.strName, msgReceived.anim) == 5)
                                    ChangeSides(true);
                                else
                                    ChangeSides();

                                //If there is no pre-animation
                                if (iniParser.GetAnimType(msgReceived.strName, msgReceived.anim) == 5 | iniParser.GetPreAnim(msgReceived.strName, msgReceived.anim) == null | iniParser.GetPreAnimTime(msgReceived.strName, msgReceived.anim) <= 0)
                                {
                                    charLayerPB.Enabled = true;
                                    setCharSprite("base/characters/" + msgReceived.strName + "/(b)" + iniParser.GetAnim(msgReceived.strName, msgReceived.anim) + ".gif");
                                    if (msgReceived.cmdCommand == Command.Present)
                                    {
                                        sfxPlayer.Stop();
                                        wr = new WaveFileReader("base/sounds/general/sfx-shooop.wav");
                                        sfxPlayer.Initialize(wr);
                                        if (!mute)
                                            sfxPlayer.Play();

                                        switch (iniParser.GetSide(msgReceived.strName))
                                        {
                                            case "def":
                                                testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceRight.gif");
                                                System.Threading.Thread.Sleep(100);
                                                testimonyPB.Location = new Point(173, 13);
                                                testimonyPB.Size = new Size(70, 70);
                                                testimonyPB.Image = eviList[Convert.ToInt32(msgReceived.strMessage.Split('|').Last())].icon;
                                                break;
                                            case "pro":
                                                testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceLeft.gif");
                                                System.Threading.Thread.Sleep(100);
                                                testimonyPB.Location = new Point(13, 13);
                                                testimonyPB.Size = new Size(70, 70);
                                                testimonyPB.Image = eviList[Convert.ToInt32(msgReceived.strMessage.Split('|').Last())].icon;
                                                break;
                                            case "hld":
                                                testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceLeft.gif");
                                                System.Threading.Thread.Sleep(100);
                                                testimonyPB.Location = new Point(13, 13);
                                                testimonyPB.Size = new Size(70, 70);
                                                testimonyPB.Image = eviList[Convert.ToInt32(msgReceived.strMessage.Split('|').Last())].icon;
                                                break;
                                            case "hlp":
                                                testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceRight.gif");
                                                System.Threading.Thread.Sleep(100);
                                                testimonyPB.Location = new Point(173, 13);
                                                testimonyPB.Size = new Size(70, 70);
                                                testimonyPB.Image = eviList[Convert.ToInt32(msgReceived.strMessage.Split('|').Last())].icon;
                                                break;
                                            default:
                                                testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceRight.gif");
                                                System.Threading.Thread.Sleep(100);
                                                testimonyPB.Location = new Point(173, 13);
                                                testimonyPB.Size = new Size(70, 70);
                                                testimonyPB.Image = eviList[Convert.ToInt32(msgReceived.strMessage.Split('|').Last())].icon;
                                                break;
                                        }

                                        msgReceived.strMessage = msgReceived.strMessage.Split('|')[0];
                                    }
                                    prepWriteDispBoxes(msgReceived, msgReceived.textColor);
                                }
                                else //if there is a pre-animation
                                {
                                    //charLayerPB.Enabled = false;
                                    setCharSprite("base/characters/" + msgReceived.strName + "/" + iniParser.GetPreAnim(msgReceived.strName, msgReceived.anim) + ".gif");
                                    preAnimTime = iniParser.GetPreAnimTime(msgReceived.strName, msgReceived.anim);
                                    curPreAnim = iniParser.GetPreAnim(msgReceived.strName, msgReceived.anim);
                                }
                                //dispTextRedraw.Enabled = true;
                            }
                            else
                            {
                                performCallout();
                            }
                            break;

                        case Command.List:
                            appendTxtLogSafe("<<<" + strName + " has entered the courtroom>>>\r\n");
                            break;

                        case Command.DataInfo:
                            //Do the stuff with the incoming server data here

                            //The user has logged into the system so we now request the server to send
                            //the names of all users who are in the chat room
                            Data msgToSend = new Data();
                            msgToSend.cmdCommand = Command.Login;
                            msgToSend.strName = strName;

                            byteData = new byte[1048576];
                            byteData = msgToSend.ToByte();

                            clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null);

                            byteData = new byte[1048576];
                            break;

                        case Command.PacketSize:
                            break;
                    }

                    if (msgReceived.strMessage != null & msgReceived.cmdCommand == Command.Message | msgReceived.cmdCommand == Command.Login | msgReceived.cmdCommand == Command.Logout)
                    {
                        if (msgReceived.callout <= 3)
                            appendTxtLogSafe(msgReceived.strMessage + "\r\n");
                    }

                    if (msgReceived.cmdCommand != Command.PacketSize)
                        byteData = new byte[1048576];
                    else
                        byteData = new byte[Convert.ToInt32(msgReceived.strMessage)];
                }

                clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);

            }
            catch (SocketException)
            {
                if (MessageBox.Show("You have been kicked from the server.", "AODXClient", MessageBoxButtons.OK) == DialogResult.OK)
                {
                    Close();
                }
            }
            catch (ObjectDisposedException)
            { }
            catch (Exception ex)
            {
                if (Program.debug)
                    MessageBox.Show(ex.Message + ".\r\n" + ex.StackTrace.ToString(), "AODXClient: " + strName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#26
0
文件: LoginForm.cs 项目: jpmac26/AODX
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                while (byteData[0] == 4 && byteData.Length < incomingSize)
                {
                    //string test = "";
                }

                clientSocket.EndReceive(ar);

                if (byteData[0] == 8)
                {
                    EviData msg = new EviData(byteData);

                    Evidence evi = new Evidence();
                    evi.name  = msg.strName;
                    evi.desc  = msg.strDesc;
                    evi.note  = msg.strNote;
                    evi.index = msg.index;

                    using (MemoryStream ms = new MemoryStream(msg.dataBytes))
                    {
                        evi.icon = Image.FromStream(ms, false, true);
                    }

                    eviList.Add(evi);

                    //string dirName = "";
                    //for (int x = 0; x < msg.strName.Split('/').Length - 1; x++)
                    //{
                    //    dirName = dirName + msg.strName.Split('/')[x];
                    //    if (x < msg.strName.Split('/').Length - 2)
                    //        dirName = dirName + '/';
                    //}
                    //if (!Directory.Exists(dirName))
                    //    Directory.CreateDirectory(dirName);

                    //using (FileStream fs = new FileStream(msg.strName, FileMode.Create))
                    //{
                    //    using (BinaryWriter w = new BinaryWriter(fs))
                    //    {
                    //        if (msg.dataSize > 0)
                    //            w.Write(msg.dataBytes.Take(msg.dataSize).ToArray());
                    //    }
                    //}

                    clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
                }
                else
                {
                    Data msgReceived = new Data(byteData);

                    if (msgReceived.cmdCommand == Command.Disconnect)
                    {
                        MessageBox.Show("You are banned from this server!");
                        btn_Connect.Image = Image.FromFile("base/misc/btn_connect.png");
                        //clientSocket.Close();
                        //Close();
                    }
                    else if (msgReceived.cmdCommand == Command.PacketSize)
                    {
                        incomingSize = Convert.ToInt32(msgReceived.strMessage);
                        byteData     = new byte[incomingSize];

                        //DialogResult = DialogResult.OK;
                        Data msgToSend = new Data();
                        msgToSend.cmdCommand = Command.DataInfo;

                        byte[] b = msgToSend.ToByte();

                        //Send the message to the server
                        clientSocket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), null);

                        clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
                        //Close();
                    }
                    else if (msgReceived.cmdCommand == Command.DataInfo)
                    {
                        if (msgReceived.strMessage != null && msgReceived.strMessage != "")
                        {
                            string[] data      = msgReceived.strMessage.Split('|');
                            int      charCount = Convert.ToInt32(data[0]);
                            if (charCount > 0)
                            {
                                for (int x = 1; x < charCount; x++)
                                {
                                    charList.Add(data[x]);
                                }
                            }

                            int songCount = Convert.ToInt32(data[charCount + 1]);
                            if (songCount > 0)
                            {
                                for (int x = charCount + 2; x < charCount + 2 + songCount; x++)
                                {
                                    musicList.Add(data[x]);
                                }
                            }
                        }

                        byteData = new byte[4194304];
                        //Do stuff with the evidence/extra binary data here
                    }
                    else
                    {
                        clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
                    }

                    if (msgReceived.cmdCommand == Command.DataInfo)
                    {
                        //Program.charList = charList;
                        //Program.musicList = musicList;
                        //Program.connection = clientSocket;
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }
            }
            catch (SocketException)
            {
                if (MessageBox.Show("You have been disconnected from the server.", "AODXClient", MessageBoxButtons.OK) == DialogResult.OK | MessageBox.Show("You have been kicked from the server.", "AODXClient", MessageBoxButtons.OK) == DialogResult.Cancel)
                {
                    Close();
                }
            }
            catch (ObjectDisposedException)
            { }
            catch (Exception ex)
            {
                if (Program.debug)
                {
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace.ToString(), "AODXClient", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#27
0
        private void txtMessage_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter & sendEnabled)
            {
                e.SuppressKeyPress = true;
                if (redraw == false)
                {
                    try
                    {
                        //Fill the info for the message to be send
                        Data msgToSend = new Data();

                        msgToSend.strName = strName;
                        msgToSend.anim = selectedAnim;
                        msgToSend.textColor = selectedColor;
                        msgToSend.strMessage = txtMessage.Text;
                        msgToSend.callout = callout;
                        if (!presenting)
                            msgToSend.cmdCommand = Command.Message;
                        else
                        {
                            msgToSend.cmdCommand = Command.Present;
                            msgToSend.strMessage = msgToSend.strMessage + "|" + selectedEvidence;

                            btn_back_PerformClick();
                        }

                        byte[] byteData = msgToSend.ToByte();

                        //prepWriteDispBoxes(msgToSend);

                        //Send it to the server
                        clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null);

                        txtMessage.Clear();
                    }
                    catch (Exception ex)
                    {
                        if (Program.debug)
                            MessageBox.Show("Unable to send message to the server.\r\n" + ex.Message + ".\r\n" + ex.StackTrace.ToString(), "AODXClient: " + strName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
示例#28
0
        private void SGSClient_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to leave the chat room?", "SGSclient: " + strName,
                MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
            {
                e.Cancel = true;
                return;
            }

            try
            {
                //Send a message to logout of the server
                Data msgToSend = new Data ();
                msgToSend.cmdCommand = Command.Logout;
                msgToSend.strName = strName;
                msgToSend.strMessage = null;

                byte[] b = msgToSend.ToByte ();
                clientSocket.SendTo(b, 0, b.Length, SocketFlags.None, epServer);
                clientSocket.Close();
            }
            catch (ObjectDisposedException)
            { }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SGSclient: " + strName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }