예제 #1
0
파일: RoomClient.cs 프로젝트: poup/MST
        protected virtual void JoinTheRoom()
        {
            Mst.Events.Invoke(MstEventKeys.showLoadingInfo, $"Joinig room {roomAccess.RoomId}... Please wait!");

            // Wait for connection to mirror server
            MstTimer.WaitWhile(() => !NetworkClient.isConnected, isSuccessful =>
            {
                Mst.Events.Invoke(MstEventKeys.hideLoadingInfo);

                if (!isSuccessful)
                {
                    logger.Error("We could not join the room. Please try again later or contact to administrator");
                    RoomNetworkManager.StopClient();
                }
                else
                {
                    OnConnectedToMirrorServerEventHandler(NetworkClient.connection);
                }
            }, roomConnectionTimeout);

            // If we are not connected to mirror server
            if (!NetworkClient.isConnected)
            {
                // Let's set the IP before we start connection
                SetAddress(roomAccess.RoomIp);

                // Let's set the port before we start connection
                SetPort(roomAccess.RoomPort);

                logger.Debug("Connecting to mirror server...");

                // Start mirror client
                RoomNetworkManager.StartClient();
            }
        }
예제 #2
0
        /// <summary>
        /// Sends request to master server to start new room process
        /// </summary>
        /// <param name="spawnOptions"></param>
        public virtual void CreateNewRoom(string regionName, MstProperties spawnOptions)
        {
            Mst.Events.Invoke(MstEventKeys.showLoadingInfo, "Starting room... Please wait!");

            logger.Debug("Starting room... Please wait!");

            // Custom options that will be given to room directly
            var customSpawnOptions = new MstProperties();

            customSpawnOptions.Add(Mst.Args.Names.StartClientConnection);

            Mst.Client.Spawners.RequestSpawn(spawnOptions, customSpawnOptions, regionName, (controller, error) =>
            {
                if (controller == null)
                {
                    Mst.Events.Invoke(MstEventKeys.hideLoadingInfo);
                    Mst.Events.Invoke(MstEventKeys.showOkDialogBox, new OkDialogBoxEventMessage(error, null));
                    return;
                }

                Mst.Events.Invoke(MstEventKeys.showLoadingInfo, "Room started. Finalizing... Please wait!");

                // Wait for spawning status until it is finished
                // This status must be send by room
                MstTimer.WaitWhile(() =>
                {
                    return(controller.Status != SpawnStatus.Finalized);
                }, (isSuccess) =>
                {
                    Mst.Events.Invoke(MstEventKeys.hideLoadingInfo);

                    if (!isSuccess)
                    {
                        Mst.Client.Spawners.AbortSpawn(controller.SpawnTaskId);

                        logger.Error("Failed spawn new room. Time is up!");
                        Mst.Events.Invoke(MstEventKeys.showOkDialogBox, new OkDialogBoxEventMessage("Failed spawn new room. Time is up!", null));

                        OnRoomStartAbortedEvent?.Invoke();

                        return;
                    }

                    OnRoomStartedEvent?.Invoke();

                    logger.Info("You have successfully spawned new room");
                }, matchCreationTimeout);
            });
        }
예제 #3
0
        private static void SendRequestSpawn(CommandArg[] args)
        {
            var options = new MstProperties();

            options.Add(MstDictKeys.roomName, args[0].String.Replace('+', ' '));

            if (args.Length > 1)
            {
                options.Add(MstDictKeys.roomMaxPlayers, args[1].String);
            }

            var customOptions = new MstProperties();

            customOptions.Add("-myName", "\"John Adams\"");
            customOptions.Add("-myAge", 45);
            customOptions.Add("-msfStartClientConnection", string.Empty);

            Mst.Client.Spawners.RequestSpawn(options, customOptions, string.Empty, (controller, error) =>
            {
                if (controller == null)
                {
                    return;
                }

                MstTimer.WaitWhile(() =>
                {
                    return(controller.Status != SpawnStatus.Finalized);
                }, (isSuccess) =>
                {
                    if (!isSuccess)
                    {
                        Mst.Client.Spawners.AbortSpawn(controller.SpawnTaskId);
                        Logs.Error("You have failed to spawn new room");
                    }

                    Logs.Info("You have successfully spawned new room");
                }, 60f);
            });
        }