Exemplo n.º 1
0
        void client_CommandReceived(object sender, CommandEventArgs e)
        {
            switch (e.Command.CommandType)
            {
            case (CommandType.Message):
                if (e.Command.Target.Equals(IPAddress.Broadcast))
                {
                    this.txtMessages.Text += e.Command.SenderName + ": " + e.Command.MetaData + Environment.NewLine;
                }
                else if (!this.IsPrivateWindowOpened(e.Command.SenderName))
                {
                    this.OpenPrivateWindow(e.Command.SenderIP, e.Command.SenderName, e.Command.MetaData);
                    ShareUtils.PlaySound(ShareUtils.SoundType.NewMessageWithPow);
                }
                break;

            case (CommandType.FreeCommand):
                string [] newInfo = e.Command.MetaData.Split(new char [] { ':' });
                this.AddToList(newInfo [0], newInfo [1]);
                ShareUtils.PlaySound(ShareUtils.SoundType.NewClientEntered);
                break;

            case (CommandType.SendClientList):
                string [] clientInfo = e.Command.MetaData.Split(new char[] { ':' });
                this.AddToList(clientInfo [0], clientInfo [1]);
                break;

            case (CommandType.ClientLogOffInform):
                this.RemoveFromList(e.Command.SenderName);
                break;
            }
        }
Exemplo n.º 2
0
        void client_CommandReceived(object sender, CommandEventArgs e)
        {
            switch (e.Command.CommandType)
            {
            case (CommandType.Message):
                if (e.Command.Target.Equals(IPAddress.Broadcast))
                {
                    this.txtMessages.Text += e.Command.SenderName + ": " + e.Command.MetaData + Environment.NewLine;
                }
                else if (!this.IsPrivateWindowOpened(e.Command.SenderName))
                {
                    this.OpenPrivateWindow(e.Command.SenderIP, e.Command.SenderName, e.Command.MetaData);
                    ShareUtils.PlaySound(ShareUtils.SoundType.NewMessageWithPow);
                }
                break;

            case (CommandType.NewUserJoined):
                txtMessages.Text += e.Command.MetaData + Environment.NewLine;
                //string[] newInfo = e.Command.MetaData.Split(new char[] { ':' });
                //this.txtMessages.Text += "New user joined";
                //this.AddToList(newInfo[0], newInfo[1]);
                //ShareUtils.PlaySound(ShareUtils.SoundType.NewClientEntered);
                break;

            case (CommandType.SendClientList):
                this.lstViwUsers.Items.Clear();
                var userList = JArray.Parse(e.Command.MetaData);
                foreach (var user in userList)
                {
                    this.AddToList(user["UserName"].ToString(), user["Name"].ToString());
                }

                break;

            case (CommandType.GameStatusUpdate):
                var gameState = JObject.Parse(e.Command.MetaData).ToObject <GameState>();
                richTextBox1.Text  = "Guess the word of Length: " + gameState.SelectedWordLength + Environment.NewLine;
                richTextBox1.Text += "Word Resolved as of now:" + gameState.ResolvedWord + Environment.NewLine;
                foreach (var score in gameState.Scores)
                {
                    richTextBox1.Text += score.Key + ":" + score.Value.Value + Environment.NewLine;
                }
                richTextBox1.Text += "Next Turn:" + gameState.NextUserTurn.Name;

                if (gameState.IsGameFinished)
                {
                    var winner = gameState.Scores.OrderByDescending(x => x.Value.Value).FirstOrDefault();
                    richTextBox1.Text = "Winner is: " + winner.Key;
                }

                break;

            case (CommandType.ClientLogOffInform):
                this.RemoveFromList(e.Command.SenderName);
                break;
            }
        }
Exemplo n.º 3
0
        private void RemoveFromList(string name)
        {
            ListViewItem item = this.lstViwUsers.FindItemWithText(name);

            if (item.Text != this.client.IP.ToString())
            {
                this.lstViwUsers.Items.Remove(item);
                ShareUtils.PlaySound(ShareUtils.SoundType.ClientExit);
            }

            frmPrivate target = this.FindPrivateWindow(name);

            if (target != null)
            {
                target.Close();
            }
        }
Exemplo n.º 4
0
 private void private_CommandReceived(object sender, CommandEventArgs e)
 {
     switch (e.Command.CommandType)
     {
     case (CommandType.Message):
         if (!e.Command.Target.Equals(IPAddress.Broadcast) && e.Command.SenderIP.Equals(this.targetIP))
         {
             this.txtMessages.Text += e.Command.SenderName + ": " + e.Command.MetaData + Environment.NewLine;
             if (!this.activated)
             {
                 if (this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized)
                 {
                     ShareUtils.PlaySound(ShareUtils.SoundType.NewMessageReceived);
                 }
                 else
                 {
                     ShareUtils.PlaySound(ShareUtils.SoundType.NewMessageWithPow);
                 }
                 this.Flash(this.Handle, FlashMode.FLASHW_ALL, 3);
             }
         }
         break;
     }
 }