Example #1
0
        /// <summary>
        /// Sends a request to join a lobby
        /// </summary>
        public void JoinLobby(int lobbyId, JoinLobbyCallback callback, ErrorCallback errorCallback)
        {
            if (!Client.IsConnected)
            {
                errorCallback.Invoke("Not connected");
                return;
            }

            // Send the message
            Client.SendMessage((ushort)OpCodes.JoinLobby, lobbyId, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    errorCallback.Invoke(response.AsString("Unknown Error"));
                    return;
                }

                var data = response.Deserialize <LobbyDataPacket>();

                var joinedLobby = new JoinedLobby(this, data, Client);

                LastJoinedLobby = joinedLobby;

                callback.Invoke(joinedLobby);

                LobbyJoined?.Invoke(joinedLobby);
            });
        }
Example #2
0
        /// <summary>
        /// Sends a request to join a lobby
        /// </summary>
        public void JoinLobby(int lobbyId, JoinLobbyCallback callback)
        {
            if (!Connection.IsConnected)
            {
                callback.Invoke(null, "Not connected");
                return;
            }

            // Send the message
            Connection.SendMessage((short)OpCodes.JoinLobby, lobbyId, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                var data = response.Deserialize(new LobbyDataPacket());

                var key = data.LobbyId + ":" + Connection.PeerId;

                if (_joinedLobbies.ContainsKey(key))
                {
                    // If there's already a lobby
                    callback.Invoke(_joinedLobbies[key], null);
                    return;
                }

                var joinedLobby = new JoinedLobby(this, data, Connection);

                LastJoinedLobby = joinedLobby;

                // Save the lobby
                _joinedLobbies[key] = joinedLobby;

                callback.Invoke(joinedLobby, null);

                LobbyJoined?.Invoke(joinedLobby);
            });
        }
Example #3
0
        /// <summary>
        /// Sends a request to join a lobby
        /// </summary>
        public void JoinLobby(int lobbyId, JoinLobbyCallback callback, IClientSocket connection)
        {
            // Send the message
            connection.SendMessage((short)MsfOpCodes.JoinLobby, lobbyId, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                var data = response.Deserialize(new LobbyDataPacket());

                var key = data.LobbyId + ":" + connection.Peer.Id;

                if (_joinedLobbies.ContainsKey(key))
                {
                    // If there's already a lobby
                    callback.Invoke(_joinedLobbies[key], null);
                    return;
                }

                var joinedLobby = new JoinedLobby(data, connection);

                LastJoinedLobby = joinedLobby;

                // Save the lobby
                _joinedLobbies[key] = joinedLobby;

                callback.Invoke(joinedLobby, null);

                if (LobbyJoined != null)
                {
                    LobbyJoined.Invoke(joinedLobby);
                }
            });
        }