예제 #1
0
        protected override void Awake()
        {
            base.Awake();

            // Create room client connection
            roomServerConnection = Mst.Create.ClientSocket();

            // Listen toconnection statuses
            roomServerConnection.AddConnectionListener(OnClientConnectedToRoomServer, false);
            roomServerConnection.AddDisconnectionListener(OnClientDisconnectedFromRoomServer, false);

            // If master IP is provided via cmd arguments
            if (Mst.Args.IsProvided(Mst.Args.Names.MasterIp))
            {
                masterIp = Mst.Args.MasterIp;
            }

            // If master port is provided via cmd arguments
            if (Mst.Args.IsProvided(Mst.Args.Names.MasterPort))
            {
                masterPort = Mst.Args.MasterPort;
            }

            // Set the scene that player will be sent to is disconnected from server
            if (Mst.Options.Has(MstDictKeys.roomOfflineSceneName))
            {
                offlineScene = Mst.Options.AsString(MstDictKeys.roomOfflineSceneName);
            }
        }
        /// <summary>
        /// Start room server
        /// </summary>
        /// <param name="ignoreForceClientMode"></param>
        public virtual void StartRoomServer(bool ignoreForceClientMode = false)
        {
            if (Msf.Client.Rooms.ForceClientMode && !ignoreForceClientMode)
            {
                return;
            }

            // Set connection of the room server
            masterConnection = ConnectionFactory();

            // Register disconnection listener
            masterConnection.AddDisconnectionListener(OnDisconnectedFromMasterHandler, false);

            // Set this connection to services we want to use
            Msf.Server.Rooms.ChangeConnection(masterConnection);
            Msf.Server.Spawners.ChangeConnection(masterConnection);
            Msf.Server.Auth.ChangeConnection(masterConnection);
            Msf.Server.Profiles.ChangeConnection(masterConnection);

            // Set room oprions
            roomOptions = SetRoomOptions();

            logger.Info($"Starting Room Server... {Msf.Version}. Multithreading is: {(Msf.Runtime.SupportsThreads ? "On" : "Off")}");
            logger.Info($"Start parameters are: {Msf.Args}");

            // Start connecting room server to master server
            ConnectToMaster();
        }
예제 #3
0
파일: RoomClient.cs 프로젝트: Fzcpp/MST
        protected override void OnInitialize()
        {
            // Listen to disconnection from master
            masterConnection.AddDisconnectionListener(OnDisconnectedFromMasterEvent, false);

            MstTimer.WaitForSeconds(1f, () =>
            {
                if (IsInTestMode())
                {
                    StartRoomClient(true);
                }

                if (Mst.Options.Has(MstDictKeys.AUTOSTART_ROOM_CLIENT) || Mst.Args.StartClientConnection)
                {
                    StartRoomClient();
                }
            });
        }
        /// <summary>
        /// Changes the connection object, and sets all of the message handlers of this object
        /// to new connection.
        /// </summary>
        /// <param name="socket"></param>
        public void ChangeConnection(IClientSocket socket)
        {
            // Clear just connection but not handlers
            ClearConnection(false);

            // Change connections
            Connection = socket;

            // Override packet handlers
            foreach (var packetHandler in handlers.Values)
            {
                socket.SetHandler(packetHandler);
            }

            Connection.OnStatusChangedEvent += OnConnectionStatusChanged;
            OnConnectionSocketChanged(Connection);
            Connection.AddConnectionListener(OnClientConnectedToServer, false);
            Connection.AddDisconnectionListener(OnClientDisconnectedFromServer, false);
        }