예제 #1
0
  @Test
  public void testCreateRoomByUser() {
    when(service.getUserBySession(anyString())).thenReturn(null);
    Room endRoom = gameServer.createRoom("aaa", "aaa", null);
    assertNull(endRoom);

    Room room = new RoomFFA("aaa");
    UserProfile profile = spy(new UserProfile("aa", "bb"));
    when(service.getUserBySession(anyString())).thenReturn(profile);
    when(profile.getCurrentroom()).thenReturn(room);

    endRoom = gameServer.createRoom("aaa", "aaa", null);
    assertNull(endRoom);
  }
  @Test
  public void testPlayerInfoSourceAuthenticated() throws Exception {
    String status = this.readFixture("status_source");

    SteamPlayer user1 = mock(SteamPlayer.class);
    SteamPlayer user2 = mock(SteamPlayer.class);
    HashMap<String, SteamPlayer> playerMap = new HashMap<String, SteamPlayer>();
    playerMap.put("12345678123456789", user1);
    playerMap.put("99999999999999999", user2);
    this.server.playerHash = playerMap;
    this.server.rconAuthenticated = true;

    doNothing().when(this.server).handleResponseForRequest(GameServer.REQUEST_PLAYER);
    when(this.server.rconExec("status")).thenReturn(status);

    HashMap<String, String> user1Data = new HashMap<String, String>();
    user1Data.put("name", "user1");
    user1Data.put("id", "12345678123456789");
    user1Data.put("time", "4449s");
    user1Data.put("ping", "300");
    user1Data.put("addr", "11.2.333.44");
    HashMap<String, String> user2Data = new HashMap<String, String>();
    user2Data.put("name", "user2");
    user2Data.put("id", "99999999999999999");
    user2Data.put("time", "50s");
    user2Data.put("ping", "45");
    user2Data.put("addr", "192.192.192.192");

    mockStatic(GameServer.class);
    ArrayList<String> attributes = new ArrayList<String>();
    // Won't read data about a player if no attributes were found
    attributes.add("someAttribute");
    when(GameServer.getPlayerStatusAttributes(
            "id                name                                  ping  connected   addr"))
        .thenReturn(attributes);
    when(GameServer.splitPlayerStatus(
            attributes,
            "12345678123456789 \"user1\"                               300   4449s       11.2.333.44"))
        .thenReturn(user1Data);
    when(GameServer.splitPlayerStatus(
            attributes,
            "99999999999999999 \"user2\"                               45    50s         192.192.192.192"))
        .thenReturn(user2Data);

    this.server.updatePlayers("password");

    verify(user1).addInformation(user1Data);
    verify(user2).addInformation(user2Data);
  }
예제 #3
0
 @Test
 public void testJoinRoomNoRoom() {
   when(service.getUserBySession(anyString())).thenReturn(new UserProfile("aa", "bb"));
   when(rooms.containsKey(anyString())).thenReturn(false);
   Room room = gameServer.joinRoom("aa", "aa", "aa");
   assertNull(room);
 }
예제 #4
0
  @Test
  public void isCorrectPlayerInGameNoPlayer() {
    when(service.isAuthorized(anyString())).thenReturn(true);
    when(service.getUserBySession(anyString())).thenReturn(null);

    assertFalse(gameServer.isCorrectPlayerInGame("aa"));
  }
예제 #5
0
  @Test
  public void testJoinRoomUserPassToRoom() {
    UserProfile profile = spy(new UserProfile("aa", "bb"));
    when(service.getUserBySession(anyString())).thenReturn(profile);
    when(rooms.containsKey(anyString())).thenReturn(true);
    when(profile.getCurrentroom()).thenReturn(null);
    Room room = new RoomFFA("aaa", "cc");
    when(rooms.get(anyString())).thenReturn(room);

    Room endRoom = gameServer.joinRoom("aaa", "", "aa");

    assertNull(endRoom);

    endRoom = gameServer.joinRoom("aa", null, "aa");

    assertNull(endRoom);
  }
예제 #6
0
 @Before
 public void setUp() {
   new ProjectDB().initBD("hibernate-test.cfg.xml");
   service = mock(AccountService.class);
   rooms = spy(new HashMap<>());
   gameServer = new GameServer(service);
   gameServer.setRooms(rooms);
 }
예제 #7
0
  @Test
  public void testIsGameReady() throws Exception {
    UserProfile profile = new UserProfile("test", "test");

    Room room = new RoomFFA("testRoom");
    room.addUser(profile);
    profile.setCurrentroom(room);

    doReturn(profile).when(service).getUserBySession(anyString());

    assertFalse(gameServer.isGameReady(anyString()));

    UserProfile profile1 = new UserProfile("test1", "test1");
    room.addUser(profile1);

    assertTrue(gameServer.isGameReady(anyString()));
  }
예제 #8
0
  @Test
  public void testGetPlayerRoomBySession() throws Exception {
    UserProfile profile = new UserProfile("test", "test");
    Room room = new RoomFFA("testRoom");
    room.addUser(profile);
    profile.setCurrentroom(room);

    when(service.getUserBySession(anyString())).thenReturn(profile);

    Room testingRoom = gameServer.getPlayerRoomBySession(anyString());

    assertNotNull(testingRoom);
    assertTrue(testingRoom.checkUser(profile));

    when(service.getUserBySession(anyString())).thenReturn(null);

    assertNull(gameServer.getPlayerRoomBySession(anyString()));
  }
예제 #9
0
  @Test
  public void testIsCorrectPlayerInGameAlready() throws Exception {
    when(service.isAuthorized(anyString())).thenReturn(true);
    UserProfile profile = new UserProfile("test", "test");
    Room room = new RoomFFA("testRoom");
    profile.setCurrentroom(room);
    when(service.getUserBySession(anyString())).thenReturn(profile);

    assertTrue(gameServer.isCorrectPlayerInGame("aa"));
  }
  @Test
  public void testHandleChallengeRequests() throws Exception {
    S2C_CHALLENGE_Packet packet = mock(S2C_CHALLENGE_Packet.class);
    when(packet.getChallengeNumber()).thenReturn(1234);
    when(server.getReply()).thenReturn(packet);

    this.server.handleResponseForRequest(GameServer.REQUEST_CHALLENGE);

    assertEquals(1234, this.server.challengeNumber);
    verify(this.server).sendRequest(any(A2S_PLAYER_Packet.class));
  }
예제 #11
0
  @Test
  public void testCreateRoomAlreadyExist() {
    UserProfile profile = spy(new UserProfile("aa", "bb"));
    when(service.getUserBySession(anyString())).thenReturn(profile);
    when(profile.getCurrentroom()).thenReturn(null);
    when(rooms.containsKey(anyString())).thenReturn(true);

    Room room = gameServer.createRoom("aaa", "aaa", null);

    assertNull(room);
  }
  @Test
  public void testHandleRulesRequests() throws Exception {
    S2A_RULES_Packet packet = mock(S2A_RULES_Packet.class);
    HashMap<String, String> rulesMap = new HashMap<String, String>();
    rulesMap.put("test", "test");
    when(packet.getRulesHash()).thenReturn(rulesMap);
    when(server.getReply()).thenReturn(packet);

    this.server.handleResponseForRequest(GameServer.REQUEST_RULES);

    assertEquals("test", this.server.rulesHash.get("test"));
    verify(this.server).sendRequest(any(A2S_RULES_Packet.class));
  }
  @Test
  public void testHandleInfoRequests() throws Exception {
    S2A_INFO2_Packet packet = mock(S2A_INFO2_Packet.class);
    HashMap<String, Object> infoMap = new HashMap<String, Object>();
    infoMap.put("test", "test");
    when(packet.getInfo()).thenReturn(infoMap);
    when(server.getReply()).thenReturn(packet);

    this.server.handleResponseForRequest(GameServer.REQUEST_INFO);

    assertEquals("test", this.server.serverInfo.get("test"));
    verify(this.server).sendRequest(any(A2S_INFO_Packet.class));
  }
  @Test
  public void testHandlePlayerRequests() throws Exception {
    SteamPlayer player = mock(SteamPlayer.class);
    S2A_PLAYER_Packet packet = mock(S2A_PLAYER_Packet.class);
    HashMap<String, SteamPlayer> playerMap = new HashMap<String, SteamPlayer>();
    playerMap.put("test", player);
    when(packet.getPlayerHash()).thenReturn(playerMap);
    when(server.getReply()).thenReturn(packet);

    this.server.handleResponseForRequest(GameServer.REQUEST_PLAYER);

    // Asserting null because we do not populate our list of players
    // from S2A Player Packets at the moment because it seems like Rust game servers
    // do not implement the ability to return valid data from those packets
    // Instead player data is fully retrieved from the RCON status command, instead
    // of a mixture of that command plus the S2A Player Packet
    assertNull(this.server.playerHash);
    verify(this.server).sendRequest(any(A2S_PLAYER_Packet.class));
  }
예제 #15
0
 @Test
 public void testJoinRoomNoPlayer() {
   when(service.getUserBySession(anyString())).thenReturn(null);
   Room room = gameServer.joinRoom("aa", "aa", "aa");
   assertNull(room);
 }
예제 #16
0
  @Test
  public void testIsCorrectPlayerInGameNoAuth() throws Exception {
    when(service.isAuthorized(anyString())).thenReturn(false);

    assertFalse(gameServer.isCorrectPlayerInGame("aa"));
  }