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);
      }
      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);
               }
            }
         }
      }
      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);
         }
      }
      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);
      }
      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);
      }
      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);
      }
      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);
            }
         }
      }
      /// <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);
      }
      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);
      }
示例#10
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);
      }
示例#11
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);
               }
            }
         }
      }
示例#12
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);
      }
示例#13
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);
            }
         }
      }
示例#14
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);
      }
示例#15
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;
         }
      }
示例#16
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);
       }
    }
 }