public override void HandleMessage(Message message)
        {
            switch (message.id)
            {
                case MessageId.PlayerBackup:
                    Message playerSerialize = new Message(MessageId.PlayerSerialize, string.Empty);
                    inbox.Enqueue(playerSerialize);
                    break;
                case MessageId.PlayerSerialized:
                    Message playerSave = new Message(MessageId.PlayerSave, message.data);
                    inbox.Enqueue(playerSave);
                    break;

                case MessageId.PlayerRestore:
                    Message playerLoad = new Message(MessageId.PlayerLoad, string.Empty);
                    inbox.Enqueue(playerLoad);
                    break;
                case MessageId.PlayerLoaded:
                    Message playerDeserialized = new Message(MessageId.PlayerDeserialized, message.data);
                    inbox.Enqueue(playerDeserialized);
                    break;
                default:
                    break;
            }
            base.HandleMessage(message);
        }
Beispiel #2
0
 public virtual void HandleMessage(Message message)
 {
     switch (message.id)
     {
         case MessageId.Quit:
             done = true;
             break;
         default:
             break;
     }
 }
 public override void HandleMessage(Message message)
 {
     switch (message.id)
     {
         case MessageId.ConsoleMessage:
             Console.WriteLine(message.data);
             break;
         default:
             break;
     }
     base.HandleMessage(message);
 }
 public void Flush()
 {
     Message logEntry = new Message(MessageId.ConsoleMessage, sb.ToString());
     outbox.Enqueue(logEntry);
     sb.Clear();
 }
        private Message TriggerEvent(ClientState State)
        {
            Message trigger = null;

            switch (command)
            {
                case "":
                    break;

                case @"\a":
                    string actorNr = data;
                    trigger = new Message(MessageId.ChangeActor, actorNr);
                    break;
                case @"\u":
                    string userId = data;
                    trigger = new Message(MessageId.GetUser, userId);
                    break;
                case @"\t":
                    trigger = new Message(MessageId.CurrentState, string.Empty);
                    break;
                case @"\i":
                    trigger = new Message(MessageId.ShowRoomActor, string.Empty);
                    break;


                case @"\r":
                    string roomname = string.Empty;
                    if (!string.IsNullOrEmpty(data))
                    {
                        roomname = data;
                        trigger = new Message(MessageId.ChangeRoomName, roomname);
                    }
                    else
                    {
                        Console.WriteLine("missing room name");
                    }
                    break;
                case @"\s":
                    string index = data;
                    trigger = new Message(MessageId.SetRoomAndActor, index);
                    break;

                case @"\o":
                    if (State == ClientState.JoinedLobby)
                    {
                        trigger = new Message(MessageId.ListRooms, string.Empty);
                    }
                    break;

                case @"\c":
                    if (State == ClientState.JoinedLobby)
                    {
                        trigger = new Message(MessageId.CreateRoom, string.Empty);
                    }
                    else
                    {
                        Console.WriteLine("CreateRoom only allowed when in Lobby");
                    }
                    break;
                case @"\j":
                    if (State == ClientState.JoinedLobby)
                    {
                        trigger = new Message(MessageId.JoinRoom, string.Empty);
                    }
                    else
                    {
                        Console.WriteLine("JoinRoom only allowed when in Lobby");
                    }
                    break;

                case @"\l":
                    if (State == ClientState.Joined)
                    {
                        trigger = new Message(MessageId.LeaveRoom, string.Empty);
                    }
                    else
                    {
                        Console.WriteLine("LeaveRoom only allowed when in a Room");
                    }
                    break;

                case @"\n":
                    trigger = new Message(MessageId.Connect, string.Empty);
                    break;
                case @"\d":
                    if (State == ClientState.Joined)
                    {
                        trigger = new Message(MessageId.Disconnect, string.Empty);
                    }
                    else
                    {
                        Console.WriteLine("Disconnect only allowed when in a Room. Use Quit.");
                    }                 
                    break;
                case @"\q":
                    if (State == ClientState.JoinedLobby || State == ClientState.Joined)
                    {
                        trigger = new Message(MessageId.Quit, string.Empty);
                        this.done = true;
                    }
                    break;


                case @"\m":
                    if (State == ClientState.JoinedLobby || State == ClientState.Joined)
                    {
                        trigger = new Message(MessageId.GetMyGameList, string.Empty);
                    }
                    break;

                case @"\g":
                    if (State == ClientState.JoinedLobby || State == ClientState.Joined)
                    {
                        trigger = new Message(MessageId.GetGameList, string.Empty);
                    }
                    break;

                case @"\p":
                    if (State == ClientState.JoinedLobby || State == ClientState.Joined)
                    {
                        trigger = new Message(MessageId.PlayerSave, string.Empty);
                    }
                    break;

                case @"\v":
                    if (State == ClientState.JoinedLobby || State == ClientState.Joined)
                    {
                        trigger = new Message(MessageId.PlayerLoad, string.Empty);
                    }
                    break;

                case @"\x":
                    if (State == ClientState.Joined)
                    {
                        trigger = new Message(MessageId.UpdateGameState, string.Empty);
                    }
                    else
                    {
                        Console.WriteLine("UpdateGameState only allowed when in a Room");
                    }
                    break;

                case @"\y":
                    if (State == ClientState.JoinedLobby || State == ClientState.Joined)
                    {
                        trigger = new Message(MessageId.GetGameState, string.Empty);
                    }
                    break;


                case @"\e":
                    if (State == ClientState.Joined && !string.IsNullOrEmpty(data))
                    {
                        trigger = new Message(MessageId.OperationRequest, data);
                    }
                    break;


                case @"\h":
                    PrintHelp();
                    break;

                default:
                    break;
            }

            return trigger;
        }
 private void route(Message message)
 { 
     if (routes.ContainsKey(message.id))
     {
         foreach (var route in routes[message.id])
         {
             route.Enqueue(message);
         }
     }
     else // default route
     {
         photonInbox.Enqueue(message);
     }
 }
        public override void HandleMessage(Message message)
        {
            base.HandleMessage(message);

            int actorNr = 0;
            string roomname = string.Empty;

            switch (message.id)
            {
                case MessageId.ListRooms:
                    PrintOpenRoomList();
                    break;

                case MessageId.ChangeRoomName:
                    roomname = message.data;
                    if (photonClient.ChangeRoomName(roomname))
                    {
                        outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("changed to room {0}", photonClient.RoomName)));
                    }
                    else
                    {
                        outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("unchanged room {0}", photonClient.RoomName)));
                    }
                    break;

                case MessageId.CreateRoom:
                    roomname = message.data;
                    photonClient.CreateRoomForMatchmaking(roomname);
                    break;

                case MessageId.JoinRoom:
                    outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("joining room:{0} with actor#:{1}", photonClient.RoomName, photonClient.ActorNr)));
                    photonClient.JoinRoom();
                    break;

                case MessageId.LeaveRoom:
                    photonClient.LeaveRoom();
                    outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("leaving room:{0}", photonClient.CurrentRoom)));
                    break;


                case MessageId.GetMyGameList:
                    photonClient.GetMyGameList();
                    break;

                case MessageId.GetGameList:
                    photonClient.GetGameList();
                    break;

                case MessageId.GetGameState:
                    photonClient.GetGameState();
                    break;

                case MessageId.UpdateGameState:
                    photonClient.UpdateGameState();
                    break;

                case MessageId.PlayerSave:
                    photonClient.SaveMyPlayer(photonClient.LocalPlayer);
                    break;

                case MessageId.PlayerLoad:
                    photonClient.GetMyPlayer();
                    break;

                case MessageId.OperationRequest:
                    photonClient.OpRequest(message.data);
                    break;


                case MessageId.ChangeActor:
                    int.TryParse(message.data, out actorNr);
                    outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("actorNr: {0}", actorNr)));
                    if (photonClient.ChangeActor(actorNr))
                    {
                        outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("set to actor#: {0}", photonClient.ActorNr)));
                    }
                    else
                    {
                        outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("stay as actor#: {0}", photonClient.ActorNr)));
                    }
                    break;

                case MessageId.GetUser:
                    outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("user: {0}", photonClient.PlayerName)));
                    break;

                case MessageId.ShowRoomActor:
                    outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("room: {0}, actor#: {1}", photonClient.RoomName, photonClient.ActorNr)));
                    break;

                case MessageId.SetRoomAndActor:
                    int index = -1;
                    int.TryParse(message.data, out index);
                    outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("index: {0}", index)));
                    if (photonClient.SetRoomAndActorBy(index))
                    {
                        outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("set to room:{0} actor#:{1}", photonClient.RoomName, photonClient.ActorNr)));
                    }
                    else
                    {
                        outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("stay in room:{0} actor#:{1}", photonClient.RoomName, photonClient.ActorNr)));
                    }
                    break;

                case MessageId.CurrentState:
                    outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("state: {0}", photonClient.State)));
                    break;


                case MessageId.Quit:
                    photonClient.QuitRoom();
                    break;
                case MessageId.Connect:
                    photonClient.ConnectToMaster();
                    break;
                case MessageId.Disconnect:
                    photonClient.Disconnect();
                    break;

                default:
                    outbox.Enqueue(new Message(MessageId.ConsoleMessage, String.Format("photon received unknown message: {0}", message.id.ToString())));
                    break;
            }
        }