Forum General GotMessage function being called mysteriously ?

Any issues or discussions relating to Flash development are welcome here.

GotMessage function being called mysteriously ?

Postby Vishwas Gagrani » March 21st, 2013, 8:49 am

Here is the server side code :

Code: Select all
namespace TicTacToe {
   
   public class Player : BasePlayer {
      public Boolean IsReady = true;
       
   }

   public class Tile {
      public String Type;
   }

   [RoomType("TicTacToe")]
   public class GameCode : Game<Player> {
      private Player player1;
      private Player player2;

      
      // This method is called when an instance of your the game is created
      public override void GameStarted() {
      
         Console.WriteLine("Game is started------------------------------");
      }

      // This method is called when the last player leaves the room, and it's closed down.
      public override void GameClosed() {
         Console.WriteLine("RoomId: " + RoomId);
      }

      // This method is called whenever a player joins the game
      public override void UserJoined(Player player) {

            Console.WriteLine("User Joined =>=>");
            Console.WriteLine(player.ConnectUserId);
          joinGame(player);


         //Send info about all already connected users to the newly joined users chat
         Message m = Message.Create("ChatInit");
      

         foreach(Player p in Players) {
            m.Add(p.Id, p.ConnectUserId);
         }

         //player.Send(m);



      }

      // This method is called when a player leaves the game
      public override void UserLeft(Player player) {
      
         if(player == player1) {
            player1 = null;
         } else if(player == player2) {
            player2 = null;
         } else
            return;

         Broadcast("left", player1 != null ? player1.ConnectUserId : "", player2 != null ? player2.ConnectUserId : "");

      }

      // This method is called when a player sends a message into the server code
      public override void GotMessage(Player player, Message message)
        {
            Console.WriteLine("Got Message:");
            Console.WriteLine(player.ConnectUserId);
         switch(message.Type) {

         
            case "join": {
                  joinGame(player);
                  break;
               }

         }
      }

      private void joinGame(Player user) {


         if(player1 == null) {
            user.Send("init", 0, user.ConnectUserId);
            player1 = user;
            
         } else if(player2 == null) {
            user.Send("init", 1, user.ConnectUserId);
            player2 = user;
         
         } else {
         
            
         }

         if(player1 != null && player2 != null) {
                Console.WriteLine("BOTH HAVE JOINED");
                Console.WriteLine(player1.ConnectUserId);
                Console.WriteLine(player2.ConnectUserId);
             Broadcast("join", player1.ConnectUserId, player2.ConnectUserId);
            //user.Send("join", player1.ConnectUserId, player2.ConnectUserId);
            
         }
      }



   }
}



Here is the output :
Code: Select all
=====[  Room Started: TicTacToe  ]=======
Game is started------------------------------
>User testUser0.20 (1): Joined game
User Joined =>=>
testUser0.20
Got Message:
testUser0.20
BOTH HAVE JOINED
testUser0.20
testUser0.20
>User testUser0.20 (1): Left game
RoomId: vn3V08ele0m8azjUOrDHnw

=====[  Room Closed  ]===================


I am confused from where does the "GotMessage" function is called ?? ( I have checked my Actionscript code, and have made sure, that no signal is reflecting back, to call this function) . This is troubling me, because as soon as the 1st player joins in, it calls "GotMessage" and 2nd player ( same as 1st player ) also gets added ! :(
Vishwas Gagrani
 
Posts: 15
Joined: October 9th, 2012, 6:43 pm

Re: GotMessage function being called mysteriously ?

Postby Vishwas Gagrani » March 21st, 2013, 8:19 pm

I temporarily solved it by using "join-2" . But don't know why "join" is still being called, without any caller ?
Vishwas Gagrani
 
Posts: 15
Joined: October 9th, 2012, 6:43 pm

Re: GotMessage function being called mysteriously ?

Postby Benjaminsen » March 21st, 2013, 10:25 pm

Somewhere in your code you are sending join from the client.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: GotMessage function being called mysteriously ?

Postby Perez Turner » July 30th, 2013, 7:58 am

Vishwas Gagrani wrote:I temporarily solved it by using "join-2" . But don't know why "join" is still being called, without any caller ?


What type of result do you find by using this specific trick? Can you show snapshots or screens ?

Scale For Less | Bench Scales
Last edited by Perez Turner on October 22nd, 2013, 7:30 am, edited 2 times in total.
Perez Turner
 
Posts: 1
Joined: July 29th, 2013, 8:30 am

Re: GotMessage function being called mysteriously ?

Postby Vishwas Gagrani » July 30th, 2013, 8:05 am

It had solved the problem..
Join2 is just an another function like Join. So, instead of one, there are 2 functions now acting as callback.
Vishwas Gagrani
 
Posts: 15
Joined: October 9th, 2012, 6:43 pm


Return to General



cron