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

            var roomAccessRequestPacket = new RoomAccessRequestPacket()
            {
                RoomId        = roomId,
                CustomOptions = customOptions,
                Password      = password
            };

            connection.SendMessage((short)MstMessageCodes.GetRoomAccessRequest, roomAccessRequestPacket, (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);
                OnAccessReceivedEvent?.Invoke(access);
            });
        }
        /// <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);
                }
            });
        }
Beispiel #3
0
        /// <summary>
        /// Sends a request to get access to room, which is assigned to this lobby
        /// </summary>
        public void GetLobbyRoomAccess(Dictionary <string, string> properties, RoomAccessCallback callback)
        {
            if (!Connection.IsConnected)
            {
                callback.Invoke(null, "Not connected");
                return;
            }

            Connection.SendMessage((short)OpCodes.GetLobbyRoomAccess, properties.ToBytes(), (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

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

                _roomPlugin.TriggerAccessReceivedEvent(access);

                callback.Invoke(access, null);
            });
        }
Beispiel #4
0
        /// <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, string password, Dictionary <string, string> properties, RoomAccessCallback callback,
                              ErrorCallback errorCallback)
        {
            if (!Client.IsConnected)
            {
                errorCallback.Invoke("Not connected");
                return;
            }

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

            Client.SendMessage((ushort)OpCodes.GetRoomAccess, packet, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    errorCallback.Invoke(response.AsString("Unknown Error"));
                    return;
                }

                var access = response.Deserialize <RoomAccessPacket>();

                LastReceivedAccess = access;

                callback.Invoke(access);

                AccessReceived?.Invoke(access);

                if (RoomConnector.Instance != null)
                {
                    RoomConnector.Connect(access);
                }
            });
        }