Skip to content

Commit

Permalink
🐛 Correct "kick", "banid" commands
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGraversen committed Oct 22, 2023
1 parent 0e12501 commit 31da756
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.concurrent.CompletableFuture;

public interface AdminCodec {
CompletableFuture<RustRconResponse> kickPlayer(@NonNull SteamId64 steamId64, @Nullable PlayerName playerName, @Nullable String reason);
CompletableFuture<RustRconResponse> kickPlayer(@NonNull SteamId64 steamId64, @Nullable String reason);

CompletableFuture<RustRconResponse> kickAllPlayers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ public DefaultAdminCodec(@NonNull RustRconRouter rustRconRouter) {
}

@Override
public CompletableFuture<RustRconResponse> kickPlayer(@NonNull SteamId64 steamId64, @Nullable PlayerName playerName, @Nullable String reason) {
public CompletableFuture<RustRconResponse> kickPlayer(@NonNull SteamId64 steamId64, @Nullable String reason) {
final var rconMessage = compile(
KICK_PLAYER,
Map.of(
stripped(STEAM_ID_64), steamId64.get(),
stripped(PLAYER_NAME), requireNonNullElse(playerName, DEFAULT_PLAYER_NAME).get(),
stripped(REASON), requireNonNullElse(reason, DEFAULT_REASON)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static class SettingsProtocol {
}

public static class AdminProtocol {
public static final String KICK_PLAYER = "global.kick \"" + STEAM_ID_64 + "\" \"" + PLAYER_NAME + " \"" + REASON + "\"";
public static final String KICK_PLAYER = "global.kick \"" + STEAM_ID_64 + "\" \"" + REASON + "\"";
public static final String KICK_ALL_PLAYERS = "global.kickall";
public static final String BAN_PLAYER = "global.banid \"" + STEAM_ID_64 + "\" \"" + PLAYER_NAME + " \"" + REASON + "\"";
public static final String BAN_PLAYER = "global.banid \"" + STEAM_ID_64 + "\" \"" + PLAYER_NAME + "\" \"" + REASON + "\"";
public static final String UNBAN_PLAYER = "global.unban \"" + STEAM_ID_64 + "\"";
public static final String ADD_OWNER = "global.ownerid \"" + STEAM_ID_64 + "\" \"" + PLAYER_NAME + "\"";
public static final String REMOVE_OWNER = "global.removeowner \"" + STEAM_ID_64 + "\"";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.graversen.rust.rcon.protocol;

import io.graversen.rust.rcon.RustRconRouter;
import io.graversen.rust.rcon.protocol.util.PlayerName;
import io.graversen.rust.rcon.protocol.util.SteamId64;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.*;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
class DefaultAdminCodecTest {
@Mock
private RustRconRouter rustRconRouter;

@InjectMocks
private DefaultAdminCodec defaultAdminCodec;

@Captor
private ArgumentCaptor<RustRconMessage> rconMessageCaptor;

@Test
void banPlayer() {
final var steamId = SteamId64.parseOrFail("76561197979952036");
final var playerName = new PlayerName("Doctor Delete");
final var reason = "You are banned m8";
defaultAdminCodec.banPlayer(steamId, playerName, reason);

verify(rustRconRouter).send(rconMessageCaptor.capture());
assertEquals("global.banid \"76561197979952036\" \"Doctor Delete\" \"You are banned m8\"", rconMessageCaptor.getValue().get());
}

@Test
void kickPlayer() {
final var steamId = SteamId64.parseOrFail("76561197979952036");
final var reason = "You are kicked m8";
defaultAdminCodec.kickPlayer(steamId, reason);

verify(rustRconRouter).send(rconMessageCaptor.capture());
assertEquals("global.kick \"76561197979952036\" \"You are kicked m8\"", rconMessageCaptor.getValue().get());
}
}

0 comments on commit 31da756

Please sign in to comment.