Skip to content

Commit

Permalink
Hide kick button if the host isnt a mod
Browse files Browse the repository at this point in the history
  • Loading branch information
kleidis committed Oct 30, 2024
1 parent a2dc49c commit 6016f6a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ class NetPlayDialog(context: Context) : BaseSheetDialog(context) {

init {
itemView.setOnClickListener(null)
binding.itemButtonNetplay.setText(R.string.multiplayer_kick_member)
binding.itemButtonNetplay.apply {
setText(R.string.multiplayer_kick_member)
visibility = if (NetPlayManager.netPlayIsModerator()) View.VISIBLE else View.GONE
}
}

override fun bind(item: NetPlayItems) {
Expand All @@ -138,12 +141,8 @@ class NetPlayDialog(context: Context) : BaseSheetDialog(context) {
}

override fun onClick(clicked: View) {
if (netPlayItems.option == NetPlayItems.MULTIPLAYER_ROOM_MEMBER) {
if (netPlayItems.option == NetPlayItems.MULTIPLAYER_ROOM_MEMBER && NetPlayManager.netPlayIsModerator()) {
var text = netPlayItems.name
val pos = text.indexOf('[')
if (pos > 0) {
text = text.substring(0, pos - 1)
}
NetPlayManager.netPlayKickUser(text)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object NetPlayManager {
external fun netPlayKickUser(username: String)
external fun netPlayLeaveRoom()
external fun netPlayGetConsoleId(): String
external fun netPlayIsModerator(): Boolean

fun showCreateRoomDialog(activity: Activity) {
val dialog = NetPlayDialog(activity)
Expand Down
8 changes: 8 additions & 0 deletions src/android/app/src/main/jni/multiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,11 @@ std::string NetPlayGetConsoleId() {
void NetworkShutdown() {
Network::Shutdown();
}

bool NetPlayIsModerator() {
auto member = Network::GetRoomMember().lock();
if (!member) {
return false;
}
return member->GetState() == Network::RoomMember::State::Moderator;
}
1 change: 1 addition & 0 deletions src/android/app/src/main/jni/multiplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ NetPlayStatus NetPlayJoinRoom(const std::string& ipaddress, int port,
std::vector<std::string> NetPlayRoomInfo();
bool NetPlayIsJoined();
bool NetPlayIsHostedRoom();
bool NetPlayIsModerator();
void NetPlaySendMessage(const std::string& msg);
void NetPlayKickUser(const std::string& username);
void NetPlayLeaveRoom();
Expand Down
6 changes: 6 additions & 0 deletions src/android/app/src/main/jni/native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,4 +800,10 @@ void Java_io_github_mandarine3ds_mandarine_NativeLibrary_logDeviceInfo(
LOG_INFO(Frontend, "Host OS: Android API level {}", android_get_device_api_level());
}

JNIEXPORT jboolean JNICALL
Java_io_github_mandarine3ds_mandarine_utils_NetPlayManager_netPlayIsModerator(
[[maybe_unused]] JNIEnv* env, [[maybe_unused]] jobject obj) {
return NetPlayIsModerator();
}

} // extern "C"

0 comments on commit 6016f6a

Please sign in to comment.