/// <summary>
        /// Tries to get an access to a room with a given room id, password,
        /// and some other properties, which will be visible to the room (game server)
        /// </summary>
        public void GetAccess(int roomId, RoomAccessCallback callback, string password,
                              Dictionary <string, string> properties, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected");
                return;
            }

            var packet = new RoomAccessRequestPacket()
            {
                RoomId     = roomId,
                Properties = properties,
                Password   = password
            };

            connection.SendMessage((short)MsfOpCodes.GetRoomAccess, packet, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                var access = response.Deserialize(new RoomAccessPacket());

                LastReceivedAccess = access;

                callback.Invoke(access, null);

                if (AccessReceived != null)
                {
                    AccessReceived.Invoke(access);
                }

                if (RoomConnector.Instance != null)
                {
                    RoomConnector.Connect(access);
                }
            });
        }
Пример #2
0
        public void GetAccess(int id)
        {
            Msf.Client.Rooms.GetAccess(id, (access, error) =>
            {
                if (access == null)
                {
                    Msf.Events.Fire(Msf.EventNames.ShowDialogBox,
                                    DialogBoxData.CreateInfo("Failed to get access to room: " + error));

                    Logs.Error("Failed to get access to room: " + error);

                    return;
                }
                GameObject.Find("Canvas").SetActive(false);
                SceneManager.LoadScene("online");
                this.access = access;
                SceneManager.sceneLoaded += OnSceneLoaded;
                //StartCoroutine(WaitSceneLoaded(access));
            }
                                       );
        }
        /// <summary>
        /// Tries to get access data for room we want to connect to
        /// </summary>
        /// <param name="roomId"></param>
        private void GetRoomAccess(int roomId)
        {
            logger.Debug($"Getting access to room {roomId}");

            Msf.Client.Rooms.GetAccess(roomId, (access, error) =>
            {
                if (access == null)
                {
                    logger.Error(error);
                    OnAccessDiniedEvent?.Invoke();
                    return;
                }

                // Save gotten room access
                roomServerAccessInfo = access;

                // Let's set the IP before we start connection
                roomServerIp = roomServerAccessInfo.RoomIp;

                // Let's set the port before we start connection
                roomServerPort = roomServerAccessInfo.RoomPort;

                logger.Debug($"Access to room {roomId} received");
                logger.Debug(access);
                logger.Debug("Connecting to room server...");

                // Start client connection
                roomServerConnection.Connect(roomServerIp, roomServerPort);

                // Wait a result of client connection
                roomServerConnection.WaitForConnection((clientSocket) =>
                {
                    if (!clientSocket.IsConnected)
                    {
                        logger.Error("Connection attempts to room server timed out");
                        return;
                    }
                }, 4f);
            });
        }
 public void OnRoomAccessReceived(RoomAccessPacket access)
 {
     // We're hoping that something will handle the Msf.Client.Rooms.AccessReceived event
     // (for example, SimpleAccessHandler)
 }
Пример #5
0
 /// <summary>
 ///     Should try to connect to game server with data, provided
 ///     in the access packet
 /// </summary>
 /// <param name="access"></param>
 public abstract void ConnectToGame(RoomAccessPacket access);
Пример #6
0
 protected virtual void OnPassReceived(RoomAccessPacket packet)
 {
     // Hope something handles the event
 }
Пример #7
0
 /// <summary>
 /// This method triggers the <see cref="OnAccessReceivedEvent"/> event. Call this,
 /// if you made some custom functionality to get access to rooms
 /// </summary>
 /// <param name="access"></param>
 public void TriggerAccessReceivedEvent(RoomAccessPacket access)
 {
     LastReceivedAccess = access;
     OnAccessReceivedEvent?.Invoke(access);
 }