Skip to content

Commit 681107b

Browse files
committed
Fix devrank
1 parent dcd043e commit 681107b

11 files changed

Lines changed: 530 additions & 164 deletions

File tree

TaskDaemon.Core/src/me/aa07/paradise/taskdaemon/core/modules/devrank/DevRankJob.java

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import me.aa07.paradise.taskdaemon.core.database.DbCore;
1212
import me.aa07.paradise.taskdaemon.database.forums.Tables;
1313
import me.aa07.paradise.taskdaemon.database.gamedb.tables.Admin;
14+
import me.aa07.paradise.taskdaemon.database.gamedb.tables.records.AdminRecord;
1415
import org.apache.logging.log4j.Logger;
1516
import org.jooq.DSLContext;
1617
import org.jooq.Record;
@@ -28,7 +29,8 @@
2829
@DisallowConcurrentExecution // NO
2930
public class DevRankJob implements Job {
3031
private static final int DEV_TEAM_GROUP = 39;
31-
private static final int DEV_TEAM_BITFLAG = 262144;
32+
private static final int DEV_RANK = 100;
33+
private static final int REMOVED_RANK = 105;
3234

3335
@Override
3436
public void execute(JobExecutionContext context) throws JobExecutionException {
@@ -80,7 +82,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
8082
if (all_groups.contains(DEV_TEAM_GROUP)) {
8183
if (ckey == null || ckey.isBlank()) {
8284
logger.warn("[DevRank] Forums user {} (ID {}) has no linked ckey",
83-
rec.get(Tables.CORE_MEMBERS.NAME), rec.get(Tables.CORE_MEMBERS.MEMBER_ID));
85+
rec.get(Tables.CORE_MEMBERS.NAME), rec.get(Tables.CORE_MEMBERS.MEMBER_ID));
8486
continue;
8587
}
8688

@@ -92,18 +94,16 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
9294
// Load all ingame admins
9395
Map<String, AdminEntry> ingame_admins = new HashMap<>();
9496

95-
Result<? extends Record> admin_records = game_db.select(
96-
Admin.ADMIN.ID,
97-
Admin.ADMIN.CKEY,
98-
Admin.ADMIN.ADMIN_RANK,
99-
Admin.ADMIN.FLAGS).from(Admin.ADMIN).fetch();
97+
Result<AdminRecord> admin_records = game_db.selectFrom(Admin.ADMIN).fetch();
10098

101-
for (Record rec : admin_records) {
99+
for (AdminRecord rec : admin_records) {
102100
String ckey = rec.get(Admin.ADMIN.CKEY);
103-
ingame_admins.put(ckey, new AdminEntry(
104-
rec.get(Admin.ADMIN.ID),
105-
rec.get(Admin.ADMIN.ADMIN_RANK),
106-
rec.get(Admin.ADMIN.FLAGS)));
101+
int perm_rank = REMOVED_RANK;
102+
if (rec.getPermissionsRank() != null) {
103+
perm_rank = rec.getPermissionsRank();
104+
}
105+
106+
ingame_admins.put(ckey, new AdminEntry(rec.get(Admin.ADMIN.ID), perm_rank));
107107
}
108108

109109
// Apply permissions to those who need them
@@ -114,21 +114,13 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
114114
logger.info("[DevRank] Ckey {} not in admin table, adding new dev", ckey);
115115
game_db.insertInto(Admin.ADMIN)
116116
.set(Admin.ADMIN.CKEY, ckey)
117-
.set(Admin.ADMIN.ADMIN_RANK, "Developer")
118-
.set(Admin.ADMIN.FLAGS, DEV_TEAM_BITFLAG)
117+
.set(Admin.ADMIN.PERMISSIONS_RANK, DEV_RANK)
119118
.execute();
120119
} else {
121-
if ("Removed".equals(entry.rank()) || entry.flags() == 0) {
120+
if (entry.rank() == REMOVED_RANK) {
122121
logger.info("[DevRank] Resetting {} to dev team with new flag", ckey);
123122
game_db.update(Admin.ADMIN)
124-
.set(Admin.ADMIN.ADMIN_RANK, "Developer")
125-
.set(Admin.ADMIN.FLAGS, DEV_TEAM_BITFLAG)
126-
.where(Admin.ADMIN.ID.eq(entry.id()))
127-
.execute();
128-
} else if ((entry.flags() & DEV_TEAM_BITFLAG) == 0) {
129-
logger.info("[DevRank] Adding dev flag to {}", ckey);
130-
game_db.update(Admin.ADMIN)
131-
.set(Admin.ADMIN.FLAGS, entry.flags() + DEV_TEAM_BITFLAG)
123+
.set(Admin.ADMIN.PERMISSIONS_RANK, DEV_RANK)
132124
.where(Admin.ADMIN.ID.eq(entry.id()))
133125
.execute();
134126
} else {
@@ -143,17 +135,10 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
143135
AdminEntry admin = entry.getValue();
144136

145137
if (!dev_team_ckeys.contains(ckey)) {
146-
if (admin.flags() == DEV_TEAM_BITFLAG) {
138+
if (admin.rank() == DEV_RANK) {
147139
logger.info("[DevRank] {} only had dev flag, removing rank and flags", ckey);
148140
game_db.update(Admin.ADMIN)
149-
.set(Admin.ADMIN.ADMIN_RANK, "Removed")
150-
.set(Admin.ADMIN.FLAGS, 0)
151-
.where(Admin.ADMIN.ID.eq(admin.id()))
152-
.execute();
153-
} else if ((admin.flags() & DEV_TEAM_BITFLAG) != 0) {
154-
logger.info("[DevRank] {} no longer in dev team, removing dev flag only", ckey);
155-
game_db.update(Admin.ADMIN)
156-
.set(Admin.ADMIN.FLAGS, admin.flags() - DEV_TEAM_BITFLAG)
141+
.set(Admin.ADMIN.PERMISSIONS_RANK, REMOVED_RANK)
157142
.where(Admin.ADMIN.ID.eq(admin.id()))
158143
.execute();
159144
}
@@ -168,6 +153,6 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
168153
}
169154
}
170155

171-
private record AdminEntry(int id, String rank, int flags) {
156+
private record AdminEntry(int id, int rank) {
172157
}
173158
}

TaskDaemon.Database.GameDb/src/me/aa07/paradise/taskdaemon/database/gamedb/Indexes.java

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TaskDaemon.Database.GameDb/src/me/aa07/paradise/taskdaemon/database/gamedb/Keys.java

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TaskDaemon.Database.GameDb/src/me/aa07/paradise/taskdaemon/database/gamedb/ParadiseGamedb.java

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TaskDaemon.Database.GameDb/src/me/aa07/paradise/taskdaemon/database/gamedb/Tables.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TaskDaemon.Database.GameDb/src/me/aa07/paradise/taskdaemon/database/gamedb/tables/Admin.java

Lines changed: 16 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)