22 changed files with 278 additions and 101 deletions
@ -0,0 +1,96 @@ |
|||||
|
package app.entities; |
||||
|
|
||||
|
import app.entities.other.SteamID; |
||||
|
import app.entities.server.PlayOn; |
||||
|
import app.entities.server.Server; |
||||
|
import app.entities.server.players.DefaultPlayer; |
||||
|
import app.entities.server.players.RCONPlayer; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
||||
|
import com.ibasco.agql.protocols.valve.source.query.SourceQueryClient; |
||||
|
import com.ibasco.agql.protocols.valve.source.query.info.SourceQueryInfoResponse; |
||||
|
import com.ibasco.agql.protocols.valve.source.query.players.SourceQueryPlayerResponse; |
||||
|
import com.ibasco.agql.protocols.valve.source.query.rcon.exceptions.RconException; |
||||
|
import lombok.Data; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.context.ApplicationContext; |
||||
|
import org.springframework.context.annotation.Scope; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.concurrent.CompletionException; |
||||
|
|
||||
|
@Data |
||||
|
@Component |
||||
|
@Scope(value = "singleton") |
||||
|
public class Stats { |
||||
|
long ban_count = 0; |
||||
|
int discord_users = 0; |
||||
|
int freevip_players = 0; |
||||
|
int server_uptime = 0; |
||||
|
int vip_players = 0; |
||||
|
int vk_users = 0; |
||||
|
HashMap<String, Integer> countries = new HashMap<>(); |
||||
|
HashMap<String, Server> servers = new HashMap<>(); |
||||
|
HashMap<String, Long> uniq = new HashMap<>(); |
||||
|
HashMap<String, Long> updates = new HashMap<>(); |
||||
|
|
||||
|
public void UpdateUniq(String key, Long value) { |
||||
|
uniq.merge(key, value, (x,y) -> y); |
||||
|
} |
||||
|
|
||||
|
public void RefreshServerA2SData(ApplicationContext context, String server_name){ |
||||
|
SourceQueryClient sourceQueryClient = context.getBean(SourceQueryClient.class); |
||||
|
try { |
||||
|
SourceQueryInfoResponse info = sourceQueryClient.getInfo(getServers().get(server_name).getInetAddress()).join(); |
||||
|
getServers().get(server_name).UpdateStatusFromA2S(info); |
||||
|
sourceQueryClient.close(); |
||||
|
} catch (IOException err) { |
||||
|
getServers().get(server_name).SetDownStatus(); |
||||
|
return; |
||||
|
} |
||||
|
if (!getServers().get(server_name).isStatus() || getServers().get(server_name).getPlayer_count() < 1) { |
||||
|
return; |
||||
|
} |
||||
|
////////////////////////////////////////////////////////////////////////
|
||||
|
//If player count > 0 make base player request
|
||||
|
////////////////////////////////////////////////////////////////////////
|
||||
|
try { |
||||
|
sourceQueryClient = context.getBean(SourceQueryClient.class); |
||||
|
SourceQueryPlayerResponse players = sourceQueryClient.getPlayers(getServers().get(server_name).getInetAddress()).join(); |
||||
|
getServers().get(server_name).UpdatePlayersFromA2S(players); |
||||
|
sourceQueryClient.close(); |
||||
|
} catch (IOException err) { |
||||
|
return; |
||||
|
} |
||||
|
///////////////////////////////////////////////////////////////////////
|
||||
|
//Extend current players of rcon result
|
||||
|
//////////////////////////////////////////////////////////////////////
|
||||
|
try { |
||||
|
String response = getServers().get(server_name).ExecuteRCON(context,"status"); |
||||
|
getServers().get(server_name).UpdatePlayersFromRCON(response); |
||||
|
} catch (RconException | CompletionException err) { |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/*@JsonIgnore |
||||
|
public PlayOn searchPlayer(SteamID steamID){ |
||||
|
for (Map.Entry<String, Server> stringServerEntry : servers.entrySet()) { |
||||
|
RCONPlayer player = stringServerEntry.getValue().searchPlayer(steamID); |
||||
|
if (player != null) return new PlayOn(stringServerEntry.getKey(), player.getId()); |
||||
|
} |
||||
|
return null; |
||||
|
}*/ |
||||
|
|
||||
|
/*@JsonIgnore |
||||
|
public String kickPlayer(PlayOn playOn){ |
||||
|
if (playOn == null) return ""; |
||||
|
return servers.get(playOn.getServer_id()).ExecuteRCON(applicationContext, "sm_kick #%d kicked from backend".formatted(playOn.getPlayer_id())); |
||||
|
}*/ |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package app.entities.db; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.math.BigInteger; |
||||
|
import java.sql.Time; |
||||
|
import java.sql.Timestamp; |
||||
|
|
||||
|
@Data |
||||
|
public class Ban { |
||||
|
int id; |
||||
|
String steam_id; |
||||
|
BigInteger account_id; |
||||
|
String player_name; |
||||
|
int ban_length; |
||||
|
String ban_reason; |
||||
|
String banned_by; |
||||
|
String banned_by_id; |
||||
|
String ip; |
||||
|
Timestamp timestamp; |
||||
|
boolean active; |
||||
|
String unbanned_by_id; |
||||
|
Timestamp unbanned_timestamp; |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package app.entities.db; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class Permition { |
||||
|
@JsonIgnore |
||||
|
int id; |
||||
|
String flags; |
||||
|
long u_timestamp; |
||||
|
int amount; |
||||
|
int immunity; |
||||
|
String status; |
||||
|
|
||||
|
public Permition(Object[] objects) { |
||||
|
id = (int) objects[0]; |
||||
|
flags = (String) objects[1]; |
||||
|
immunity = (int) objects[2]; |
||||
|
status = (String) objects[3]; |
||||
|
amount = (int) objects[4]; |
||||
|
u_timestamp = (long) objects[5]; |
||||
|
} |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
package app.entities.server; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
@AllArgsConstructor |
||||
|
public class PlayOn { |
||||
|
String server_id; |
||||
|
int player_id; |
||||
|
} |
@ -1,9 +1,12 @@ |
|||||
package app.entities.server.players; |
package app.entities.server.players; |
||||
|
|
||||
|
import app.entities.other.SteamID; |
||||
import lombok.Data; |
import lombok.Data; |
||||
|
|
||||
@Data |
@Data |
||||
public class DefaultPlayer { |
public class DefaultPlayer { |
||||
String name; |
String name; |
||||
int score; |
int score; |
||||
|
|
||||
|
SteamID steam = new SteamID(); |
||||
} |
} |
||||
|
@ -1,31 +0,0 @@ |
|||||
package app.services; |
|
||||
|
|
||||
import app.entities.server.Server; |
|
||||
import lombok.Data; |
|
||||
import org.springframework.context.annotation.Scope; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
import java.util.HashMap; |
|
||||
import java.util.List; |
|
||||
|
|
||||
@Data |
|
||||
@Component |
|
||||
@Scope(value = "singleton") |
|
||||
public class Stats { |
|
||||
long ban_count = 0; |
|
||||
int discord_users = 0; |
|
||||
int freevip_players = 0; |
|
||||
int server_uptime = 0; |
|
||||
int vip_players = 0; |
|
||||
int vk_users = 0; |
|
||||
HashMap<String, Integer> countries = new HashMap<>(); |
|
||||
HashMap<String, Server> servers = new HashMap<>(); |
|
||||
HashMap<String, Long> uniq = new HashMap<>(); |
|
||||
HashMap<String, Long> updates = new HashMap<>(); |
|
||||
|
|
||||
public void UpdateUniq(String key, Long value) { |
|
||||
uniq.merge(key, value, (x,y) -> y); |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,7 @@ |
|||||
|
package app.services.db; |
||||
|
|
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class BanService { |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
package app.services.db; |
||||
|
|
||||
|
import app.entities.db.Permition; |
||||
|
import app.entities.other.SteamID; |
||||
|
import jakarta.persistence.EntityManager; |
||||
|
import jakarta.persistence.PersistenceContext; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Service |
||||
|
public class PermitionService { |
||||
|
@PersistenceContext |
||||
|
EntityManager entityManager; |
||||
|
|
||||
|
public Permition getPermition(SteamID steamID){ |
||||
|
List<Object[]> permitionList = entityManager.createNativeQuery("SELECT id, flags, immunity, status, amount, UNIX_TIMESTAMP(`reg_date`) as u_timestamp FROM sm_admins WHERE `identity` LIKE ?1") |
||||
|
.setParameter(1, steamID.steam2) |
||||
|
.getResultList(); |
||||
|
return permitionList.size() > 0 ? new Permition(permitionList.get(0)) : null; |
||||
|
} |
||||
|
} |
@ -1,7 +1,8 @@ |
|||||
package app.services; |
package app.services.db; |
||||
|
|
||||
import app.entities.other.SteamID; |
import app.entities.other.SteamID; |
||||
import app.entities.server.Server; |
import app.entities.server.Server; |
||||
|
import app.entities.Stats; |
||||
import jakarta.persistence.EntityManager; |
import jakarta.persistence.EntityManager; |
||||
import jakarta.persistence.PersistenceContext; |
import jakarta.persistence.PersistenceContext; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
import org.springframework.beans.factory.annotation.Autowired; |
Loading…
Reference in new issue