Exemplo n.º 1
0
      private void LoadHelpMessage(BBMessage message)
      {
         this.ChatApplicationBusiness.ChangePlayerName(this.Helper_Nick);
         this.ChatApplicationBusiness.ChangePlayerColor(this.Helper_Color);

         //Description des commandes :
         StringBuilder text = new StringBuilder();

         text.AppendLine(string.Format("Commande : {0} => Affiche l'aide en ligne", BBBotBusiness.Help));
         text.AppendLine(string.Format("Commande : {0} => Affiche les dernières VDM depuis la dernière exécution", BBBotBusiness.AllVDM));
         text.AppendLine(string.Format("Commande : {0} => Affiche la dernière VDM", BBBotBusiness.LastVDM));
         text.AppendLine(string.Format("Commande : {0} => Affiche une VDM au hasard", BBBotBusiness.RandomVDM));
         text.AppendLine(string.Format("Commande : {0} => Affiche les derniers Bash", BBBotBusiness.AllBash));
         text.AppendLine(string.Format("Commande : {0} => Affiche le dernier Bash", BBBotBusiness.LastBash));
         text.AppendLine(string.Format("Commande : {0} => Affiche un Bash au hasard", BBBotBusiness.RandomBash));
         text.AppendLine(string.Format("Commande : {0} => Démarre le jeu du pendu", BBBotBusiness.StartPendu)); 

         this.ChatApplicationBusiness.EnteredHelper(text.ToString(), message);
      }
Exemplo n.º 2
0
      /// <summary>
      /// Recherche si le mot tapé est une lettre ou pas...
      /// </summary>
      private void CatchLetterPendu(string str, BBMessage message)
      {
         if ((str.Length == 1) && (!string.IsNullOrEmpty(this.ActualWord)))
         {
            char[] allChar = str.ToCharArray();
            char ch = allChar[0];

            //Vérifie que c est une lettre authorisé
            if (this.AllLettersAuthorized.Contains(ch))
            {
               if (this.EnfOfGame)
               {
                  if (ch != 'Y')
                     this.DisplayPenduGame(false, "Pendu game is ending, do you want to play an other time ? Press Y", false, message);
                  else
                     this.GetNewPenduWord(message);
               }
               else
               {
                  //Vérifie que la lettre n'a pas déjà été joué
                  if (this.AllLetters.Contains(ch))
                  {
                     this.DisplayPenduGame(false, "Letter already player", true, message);
                  }
                  else
                  {
                     if (!this.ActualWord.Contains(ch))
                        //C'est une erreur
                        this.NbErrors++;

                     this.AllLetters.Add(ch);

                     this.DisplayPenduGame(false, null, true, message);

                     if (this.NbErrors >= 7)
                     {
                        //fin du jeu avec erreurs
                        this.DisplayPenduGame(false, "You lose ! Sorry, but you can play again ? Press Y", false, message);
                        this.EnfOfGame = true;
                     }
                     else
                     {
                        int nbOk = 0;

                        //Vérifie que la partie est gagné ou pas
                        foreach (char ch1 in this.AllLetters)
                        {
                           foreach (char ch2 in this.ActualWord.ToCharArray())
                              if (ch1 == ch2)
                                 nbOk++;
                        }

                        if (nbOk == this.ActualWord.Length)
                        {
                           //fin du jeu sans erreurs
                           this.DisplayPenduGame(false, "Winner ! Do you want to win an other time ? Press Y", false, message);
                           this.EnfOfGame = true;
                        }
                     }
                  }
               }
            }
         }
      }
Exemplo n.º 3
0
      public void JoinConversation(BBConversation convers, string actualnick)
      {
         if (convers != null)
         {
            BBMessage msg = new BBMessage();
            msg.Conversation = convers;

            msg.MsgJoinConversationPlayer(PList.GetPlayer(actualnick, OurID), true);

            Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
         }
      }
Exemplo n.º 4
0
      public bool MsgOKLogin(PlayerCarac playerCarac)
      {
         BBMessage msg = new BBMessage();
         playerCarac.AssignID();
         msg.PlayerCarac = playerCarac;
         msg.MsgType = BBMsgType.OK_LOGIN;

         return Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
      }
Exemplo n.º 5
0
      public void PrivateMessage(BBConversation convers, string text, string actualnick)
      {
         if (convers != null)
         {
            Player player = PList.GetPlayer(actualnick, OurID);
            if (player != null)
            {
               // Create a message
               BBMessage msg = new BBMessage();
               msg.Conversation = convers;
               msg.PlayerCarac = player.Carac;
               msg.MsgPrivateMessage(text, actualnick);
               msg.Message = text;

               if (msg.PlayerCarac != null)
                  // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
                  Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
            }
         }
      }
Exemplo n.º 6
0
      public void ShootResponse(ShootResponseDesc.Response response, string nick)
      {
         // Create a message
         int id = PList.GetPlayer(nick, OurID).Carac.ActorID;
         BBMessage msg = new BBMessage();
         msg.MsgShootResponse(new ShootResponseDesc(response, id));

         // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
         Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
      }
Exemplo n.º 7
0
      /// <summary>
      /// Envoie un message pour BASH
      /// </summary>
      /// <param name="cmd"></param>
      public void EnteredBASH(string cmd, bool toDisplay, BBMessage message)
      {
         if (Client != null)
         {
            if (Client.Status == NetConnectionStatus.Connected)
            {
               Player player = PList.GetPlayer(OurID);
               if (player != null)
               {
                  // Create a message
                  BBMessage msg = new BBMessage();
                  msg.MsgChatBash(cmd, player.Carac, toDisplay, message);

                  if (msg.PlayerCarac != null)
                     // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
                     Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
               }
            }
         }
      }
Exemplo n.º 8
0
 private void Shooted(BBMessage msg)
 {
    if (msg.Shoot.Cible_ID == OurID)
    {
       // We are the destination
       if (msg.ActorInfo.Id == OurID)
       {
          // Are you dumb ?
          OutputSystemText("You crush your snowball on your head. You feel cold, and somehow alone.", msg);
       }
       else
       {
          //MainForm.ShootSnowBall(PList.GetPlayer(msg.ActorInfo.Id).Carac.Nick);
       }
    }
    else
    {
       if (msg.ActorInfo.Id == msg.Shoot.Cible_ID)
          OutputSystemText(PList.GetPlayer(msg.ActorInfo.Id).Carac.Nick + " crushed a snowball on his own head, and looks dumb.", msg);
       else
          OutputSystemText(PList.GetPlayer(msg.ActorInfo.Id).Carac.Nick + " threw a snowball at " + PList.GetPlayer(msg.Shoot.Cible_ID).Carac.Nick + "'s head!", msg);
    }
 }
Exemplo n.º 9
0
      public void HandleMessage(BBMessage msg, NetConnection sender)
      {
         switch (msg.MsgType)
         {
            case BBMsgType.ASK_LOGIN:
               HdlLogin(msg, sender);
               break;
            case BBMsgType.PRIVATE_MESSAGE:
            case BBMsgType.PRIVATE_CONVERSATION:
            case BBMsgType.JOIN_CONVERSATION:
            case BBMsgType.LEAVE_CONVERSATION:
            case BBMsgType.CHAT:
            case BBMsgType.VDM:
            case BBMsgType.PENDU:
            case BBMsgType.BASH:
            case BBMsgType.TYPING_MSG:
            case BBMsgType.KNOCK:
               HdlMsgReBroadcast(msg, sender);
               break;
            case BBMsgType.COFFEE:
               HdlMsgReBroadcast(msg, sender);
               break;
            case BBMsgType.EAT:
               HdlMsgReBroadcast(msg, sender);
               break;
            case BBMsgType.ACTOR_SHOOT:
               HdlMsgShoot(msg, sender);
               break;

            case BBMsgType.ACTOR_SHOOT_RESPONSE:
               HdlMsgShoot(msg, sender);
               break;

            default:
               Log.Warning("Received unknown message");
               break;
         }
      }
Exemplo n.º 10
0
      public void Server_StatusChanged(object sender, NetStatusEventArgs e)
      {
         // If a client disconnects, delete it from the list
         switch (e.Connection.Status)
         {
            case NetConnectionStatus.Disconnected:
               if (e.Connection.Tag != null)
               {
                  int id = PlayerList.GetPlayerID(e.Connection);
                  Log.Info("Client " + id + " disconnected : " + e.Reason);

                  // Notify other clients
                  BBMessage msg_back = new BBMessage();
                  msg_back.MsgDelPlayer(id, e.Reason);
                  BroadcastMsgExcept(msg_back.GetNetMessage(), NetChannel.ReliableUnordered, id);

                  // Notify
                  NotifyClientDisconnected(e.Connection);
                  // Delete the player from our list
                  PList.DelPlayer(PlayerList.GetPlayerID(e.Connection));
               }
               break;

            default:
               // display changes
               Log.Info(e.Connection + ": " + e.Connection.Status + " - " + e.Reason);
               break;
         }
      }
Exemplo n.º 11
0
 // Send a chat to a user. if nick is an invalid player (null), message will be broadcasted
 public void SendChat(string nick, string msg)
 {
    Player player = PList.GetPlayer(nick, null);
    if (player != null)
    {            
       BBMessage bbmsg = new BBMessage();
       // Set the id of the message sender
       bbmsg.MsgChat(msg, player.Carac);
       bbmsg.ActorInfo = new ActorRTInfo();
       bbmsg.ActorInfo.Id = -1;  // Nobody
       
       if (player == null)
       {
          // Broadcast this message
          Server.Broadcast(bbmsg.GetNetMessage(), NetChannel.ReliableUnordered);
       }
       else
       {
          Server.SendMessage(bbmsg.GetNetMessage(), player.Connection, NetChannel.ReliableUnordered);
       }
    }
 }
Exemplo n.º 12
0
 static void _chatApplicationBusiness_SendingMessage(BBMessage message)
 {
    if (message.Conversation == null)
       MainForm.AppendChatMsg(message.Message, message.PlayerCarac.Nick, message.PlayerCarac.TextColor);
    else
       MainForm.AppendChatMsgBBMessage(message, message.Message, message.PlayerCarac.Nick, message.PlayerCarac.TextColor, message.Conversation.ToString());
 }
Exemplo n.º 13
0
 static void _chatApplicationBusiness_SendingSystemMessage(string message, BBMessage BBmessage)
 {
    if (BBmessage != null)
    {
       if (BBmessage.Conversation == null)
          MainForm.AppendSysMsg(message);
       else
          MainForm.AppendSysMsgBBMessage(BBmessage, message, true);
    }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Récupére une lettre et calcule
 /// </summary>
 /// <param name="message"></param>
 /// <param name="str"></param>
 public void CatchLetter(BBMessage message, string str)
 {
    if (str.Length == 1)
       this.CatchLetterPendu(str, message);
    else if ((str.Length == BBBotBusiness.RandomVDM.Length) && (str == BBBotBusiness.RandomVDM))
       this.CatchLetterVDMRandom(message);
    else if ((str.Length == BBBotBusiness.LastVDM.Length) && (str == BBBotBusiness.LastVDM))
       this.CatchLetterVDMLast(message);
    else if ((str.Length == BBBotBusiness.AllVDM.Length) && (str == BBBotBusiness.AllVDM))
       this.LoadVDM(message);
    else if ((str.Length == BBBotBusiness.StartPendu.Length) && (str == BBBotBusiness.StartPendu))
       this.GetNewPenduWord(message);
    else if ((str.Length == BBBotBusiness.LastBash.Length) && (str == BBBotBusiness.LastBash))
       this.LoadLastBash(message);
    else if ((str.Length == BBBotBusiness.AllBash.Length) && (str == BBBotBusiness.AllBash))
       this.LoadBash(message);
    else if ((str.Length == BBBotBusiness.RandomBash.Length) && (str == BBBotBusiness.RandomBash))
       this.LoadRandomBash(message);
    else if ((str.Length == BBBotBusiness.Help.Length) && (str == BBBotBusiness.Help))
       this.LoadHelpMessage(message);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Envoie un message d'administration
 /// </summary>
 /// <param name="message"></param>
 public void OutputSystemText(string message, BBMessage conversation)
 {
    this.OnSendingSystemMessage(message, conversation);
 }
Exemplo n.º 16
0
      private void HdlMsgShoot(BBMessage msg, NetConnection sender)
      {
         int id = PlayerList.GetPlayerID(sender);

         if (msg.MsgType == BBMsgType.ACTOR_SHOOT)
         {
            Log.Info("Shoot from " + id + " to " + msg.Shoot.Cible_ID);
            ++PList.GetPlayer(id).score.Shots;
         }
         else if (msg.MsgType == BBMsgType.ACTOR_SHOOT_RESPONSE)
         {
            Log.Info("Shoot response from " + id + " - shooter: " + msg.Resp.SenderID + ". result : " + msg.Resp.ShootResponse.ToString());

            if (msg.Resp.ShootResponse == ShootResponseDesc.Response.AVOIDED || msg.Resp.ShootResponse == ShootResponseDesc.Response.COUNTERED)
            {
               ++PList.GetPlayer(id).score.Hit;
            }
            else if (msg.Resp.ShootResponse == ShootResponseDesc.Response.TAKEN)
            {
               ++PList.GetPlayer(id).score.Hit;
               ++PList.GetPlayer(id).score.Deaths;
               ++PList.GetPlayer(msg.Resp.SenderID).score.Kills;
            }
         }

         // Set the id of the message sender
         msg.ActorInfo = new ActorRTInfo();
         msg.ActorInfo.Id = id;

         // And broadcast this message
         Server.Broadcast(msg.GetNetMessage(), NetChannel.ReliableUnordered);
      }
Exemplo n.º 17
0
      private void ShootResponsed(BBMessage msg)
      {
         string dest = PList.GetPlayer(msg.ActorInfo.Id).Carac.Nick;
         string src = PList.GetPlayer(msg.Resp.SenderID).Carac.Nick;

         switch (msg.Resp.ShootResponse)
         {
            case ShootResponseDesc.Response.AVOIDED:
               OutputSystemText(dest + " avoided " + src + "'s snowball! He's too fast, is he really working ?", msg);
               break;

            case ShootResponseDesc.Response.COUNTERED:
               OutputSystemText(dest + " countered " + src + "'s snowball! Seems like he's working but still got some nerves", msg);
               break;

            case ShootResponseDesc.Response.TAKEN:
               OutputSystemText(dest + " couldn't handle " + src + "'s snowball... What a loser.", msg);
               break;

            case ShootResponseDesc.Response.TOO_MUCH:
               OutputSystemText(dest + " is already dealing with a snowball, " + src + " should calm down a bit.", msg);
               break;
         }
      }
Exemplo n.º 18
0
      protected void HdlLogin(BBMessage msg, NetConnection sender)
      {         
         // Test if login is possible
         if (PList.GetPlayer(msg.PlayerCarac.Nick, null) != null)
         {
            // No : player already exists   
            BBMessage msg_back = new BBMessage();
            msg_back.MsgNoLogin("Player \"" + msg.PlayerCarac.Nick + "\" already exists");
            Server.SendMessage(msg_back.GetNetMessage(), sender, NetChannel.ReliableUnordered);

            // And close the connection
            sender.Disconnect("Player \"" + msg.PlayerCarac.Nick + "\" already exists, Login refused");
         }
         else
         {
            if ((msg.Param1 == null) || (msg.Param1 != BBMessage.Version))
            {
               BBMessage msg_back1 = new BBMessage();
               string str = msg.Param1;
               if (str == null)
                  str = "No version";

               msg_back1.MsgNoLogin("Player \"" + msg.PlayerCarac.Nick + "\" , Login refused. Version Serveur = " + BBMessage.Version + " Version Client = " + str);
               Server.SendMessage(msg_back1.GetNetMessage(), sender, NetChannel.ReliableUnordered);

               //sender.Disconnect("Player \"" + msg.PlayerCarac.Nick + "\" , Login refused. Version Serveur = " + BBMessage.Version + " Version Client = " + msg.Param1.ToString());
            }
            else
            {
               // Yes : Add the player to the list and send OK
               // Now add the player to our list
               int id = PList.CreatePlayer(msg.PlayerCarac, sender);
               Log.Info("Player added : " + msg.PlayerCarac.Nick + ", " + id);

               // Send OK
               msg.MsgOkLogin(id);
               Server.SendMessage(msg.GetNetMessage(), sender, NetChannel.ReliableUnordered);

               // Send connection of other clients to our new client
               IDictionaryEnumerator en = PList.GetPlayerEnum();
               BBMessage msg_notice;
               while (en.MoveNext())
               {
                  if (((Player)en.Value).Carac.ActorID != id)
                  {
                     msg_notice = new BBMessage();
                     msg_notice.MsgAddPlayer((Player)en.Value, false);
                     Server.SendMessage(msg_notice.GetNetMessage(), sender, NetChannel.ReliableUnordered);
                  }

               }

               // Notify other clients
               BBMessage msg_back = new BBMessage();
               msg_back.MsgAddPlayer(PList.GetPlayer(id), true);
               BroadcastMsgExcept(msg_back.GetNetMessage(), NetChannel.ReliableUnordered, id);

               // Notify
               NotifyClientConnected(id);
            }
         }
      }
Exemplo n.º 19
0
 private void OnSendingSystemMessage(string message, BBMessage BBmessage)
 {
    if (this.SendingSystemMessage != null)
       this.SendingSystemMessage(message, BBmessage);
 }
Exemplo n.º 20
0
      protected void HdlMsgReBroadcast(BBMessage msg, NetConnection sender)
      {
         int id = PlayerList.GetPlayerID(sender);

         //if (msg.MsgType == BBMsgType.CHAT)
         //   Log.Info("Chat " + id + " : " + msg.Param1);

         // Set the id of the message sender
         msg.ActorInfo = new ActorRTInfo();
         msg.ActorInfo.Id = id;

         // And broadcast this message
         Server.Broadcast(msg.GetNetMessage(), NetChannel.ReliableUnordered);
      }
Exemplo n.º 21
0
      /// <summary>
      /// Envoie un tir
      /// </summary>
      /// <param name="nick"></param>
      public void Shoot(string nick)
      {
         // Create a message
         BBMessage msg = new BBMessage();
         msg.MsgActorShoot(new ShootDescription(ShootDescription.Type.SNOWBALL, PList.GetPlayer(nick, OurID).Carac.ActorID));

         // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
         Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
      }
Exemplo n.º 22
0
      static void MainForm_TypingStateChanged(object sender, ChatForm.TypingEvent e)
      {
         BBConversation convers = sender as BBConversation;
         // Create istyping message
         BBMessage msg = new BBMessage();
         msg.MsgTypingMsg(e.isTyping);
         msg.Conversation = convers;

         // Send it.
         Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
      }
Exemplo n.º 23
0
      public void Coffee(string nick, BBConversation conversation)
      {
         // Create a message
         BBMessage msg = new BBMessage();
         msg.MsgCoffee("", PList.GetPlayer(nick, OurID).Carac.ActorID);
         msg.Conversation = conversation;

         // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
         Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
      }
Exemplo n.º 24
0
 static void _chatApplicationBusiness_SendingMessage(BBMessage message)
 {
    Program.BBBotBusiness.CatchLetter(message, message.Message);
 }
Exemplo n.º 25
0
      public bool AskLogin(PlayerCarac playerCarac, string version)
      {
         // Create login message
         BBMessage msg = new BBMessage();
         msg.MsgAskLogin(playerCarac, version);

         // Send it.
         return Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
      }
Exemplo n.º 26
0
 private void OnSendingMessage(BBMessage message)
 {
    if (this.SendingMessage != null)
       this.SendingMessage(message);
 }
Exemplo n.º 27
0
      public void LeaveConversation(BBConversation convers, string actualnick)
      {
         if (convers != null)
         {
            if (convers.Players.Contains(actualnick))
            {
               convers.Players.Remove(actualnick);

               if (PList.GetPlayer(actualnick, OurID) != null)
               {
                  BBMessage msg = new BBMessage();
                  msg.Conversation = convers;

                  msg.MsgLeaveConversationPlayer(PList.GetPlayer(actualnick, OurID).Carac.ActorID, string.Empty);

                  Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
               }
            }
         }
      }
Exemplo n.º 28
0
      private void MessageChat(BBMessage msg, bool NotifyMessage)
      {
         if (this.IsPartOfConversation(msg.Conversation))
         {
            string nick;
            Color color;
            if (msg.ActorInfo.Id != -1)
            {
               nick = PList.GetPlayer(msg.ActorInfo.Id).Carac.Nick;
               color = PList.GetPlayer(msg.ActorInfo.Id).Carac.TextColor;
            }
            else
            {
               nick = "";
               color = Color.Black; // Whatever
            }

            this.OnSendingMessage(msg);
            // Notify the user
            if (NotifyMessage)
               this.OnNotifyMessage();
         }
      }
Exemplo n.º 29
0
      public void PrivateConversation(string nick, string text)
      {
         // Create a message
         BBMessage msg = new BBMessage();
         msg.MsgPrivateConversation(text, PList.GetPlayer(nick, OurID).Carac.ActorID);

         // Send use the ReliableUnordered channel; ie. it WILL arrive, but not necessarily in order
         Client.SendMessage(msg.GetNetMessage(), NetChannel.ReliableUnordered);
      }
Exemplo n.º 30
0
      /// <summary>
      /// Affiche le pendu
      /// </summary>
      /// <param name="alert"></param>
      /// <param name="specialMessage"></param>
      public void DisplayPenduGame(bool alert, string specialMessage, bool toDisplayAll, BBMessage message)
      {
         this.ChatApplicationBusiness.ChangePlayerName(this.Pendu_Nick);
         this.ChatApplicationBusiness.ChangePlayerColor(this.Pendu_Color);

         if (!string.IsNullOrEmpty(this.ActualWord))
         {
            if (!string.IsNullOrEmpty(specialMessage))
            {
               //Couleur spéciale temporaraire
               this.ChatApplicationBusiness.ChangePlayerColor(Color.Gold);
               this.ChatApplicationBusiness.EnteredPendu(specialMessage, false, message);
               this.ChatApplicationBusiness.ChangePlayerColor(this.Pendu_Color);
            }

            if (toDisplayAll)
            {

               StringBuilder toDisplay = new StringBuilder();
               //Affiche les mots
               foreach (char ch in this.ActualWord.ToCharArray())
               {
                  if (this.AllLetters.Contains(ch))
                  {
                     toDisplay.Append(ch.ToString());
                  }
                  else
                  {
                     toDisplay.Append("_");
                  }

                  toDisplay.Append(" ");
               }

               //Affiche les lettres utilisées
               toDisplay.Append(" -- Used letters : ");

               foreach (char ch in this.AllLetters)
               {
                  if (!this.ActualWord.Contains(ch))
                     toDisplay.Append(string.Concat(ch.ToString(), " "));
               }

               //Affiche le nombre d'erreurs
               toDisplay.AppendFormat("{0} / 7 errors !", this.NbErrors.ToString());

               this.ChatApplicationBusiness.EnteredPendu(toDisplay.ToString(), alert, message);
            }
         }
      }