Skip to content

Commit 9faa0ae

Browse files
committed
fix: Correctly insert/update player uuids in converters
1 parent 4d91b58 commit 9faa0ae

5 files changed

Lines changed: 37 additions & 3 deletions

File tree

authme-core/src/main/java/fr/xephi/authme/datasource/PostgreSqlDataSource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ public boolean setTotpKey(String user, String totpKey) {
457457
private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
458458
String salt = col.SALT.isEmpty() ? null : row.getString(col.SALT);
459459
int group = col.GROUP.isEmpty() ? -1 : row.getInt(col.GROUP);
460+
UUID uuid = col.PLAYER_UUID.isEmpty()
461+
? null : UuidUtils.parseUuidSafely(row.getString(col.PLAYER_UUID));
460462
UUID premiumUuid = col.PREMIUM_UUID.isEmpty()
461463
? null : UuidUtils.parseUuidSafely(row.getString(col.PREMIUM_UUID));
462464
return PlayerAuth.builder()
@@ -476,6 +478,7 @@ private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
476478
.locZ(row.getDouble(col.LASTLOC_Z))
477479
.locYaw(row.getFloat(col.LASTLOC_YAW))
478480
.locPitch(row.getFloat(col.LASTLOC_PITCH))
481+
.uuid(uuid)
479482
.premiumUuid(premiumUuid)
480483
.build();
481484
}

authme-core/src/main/java/fr/xephi/authme/datasource/SQLite.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ public synchronized boolean setTotpKey(String user, String totpKey) {
378378

379379
private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
380380
String salt = !col.SALT.isEmpty() ? row.getString(col.SALT) : null;
381+
UUID uuid = col.PLAYER_UUID.isEmpty()
382+
? null : UuidUtils.parseUuidSafely(row.getString(col.PLAYER_UUID));
381383
UUID premiumUuid = col.PREMIUM_UUID.isEmpty()
382384
? null : UuidUtils.parseUuidSafely(row.getString(col.PREMIUM_UUID));
383385

@@ -397,6 +399,7 @@ private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
397399
.locWorld(row.getString(col.LASTLOC_WORLD))
398400
.locYaw(row.getFloat(col.LASTLOC_YAW))
399401
.locPitch(row.getFloat(col.LASTLOC_PITCH))
402+
.uuid(uuid)
400403
.premiumUuid(premiumUuid)
401404
.build();
402405
}

authme-core/src/main/java/fr/xephi/authme/datasource/converter/AbstractDataSourceConverter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public void execute(CommandSender sender) {
6666
destination.saveAuth(auth);
6767
destination.updateSession(auth);
6868
destination.updateQuitLoc(auth);
69+
if (auth.getPremiumUuid() != null) {
70+
destination.updatePremiumUuid(auth);
71+
}
6972
}
7073
}
7174

authme-core/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@
1818
import java.sql.SQLException;
1919
import java.sql.Statement;
2020

21+
import java.util.List;
22+
import java.util.UUID;
23+
2124
import static org.hamcrest.MatcherAssert.assertThat;
25+
import static org.hamcrest.Matchers.equalTo;
2226
import static org.hamcrest.Matchers.hasSize;
27+
import static org.hamcrest.Matchers.notNullValue;
2328
import static org.mockito.Mockito.mock;
2429
import static org.mockito.Mockito.when;
2530

@@ -47,6 +52,7 @@ static void initializeSettings() throws IOException, ClassNotFoundException {
4752
TestHelper.returnDefaultsForAllProperties(settings);
4853
set(DatabaseSettings.MYSQL_DATABASE, "sqlite-test");
4954
set(DatabaseSettings.MYSQL_TABLE, "authme");
55+
set(DatabaseSettings.MYSQL_COL_PLAYER_UUID, "playerUUID");
5056
TestHelper.setupLogger();
5157

5258
Path sqlInitFile = TestHelper.getJarPath(TestHelper.PROJECT_ROOT + "datasource/sql-initialize.sql");
@@ -111,6 +117,24 @@ void shouldCreateMissingColumns() throws SQLException {
111117
assertThat(sqLite.getAllAuths(), hasSize(1));
112118
}
113119

120+
@Test
121+
void shouldReadPlayerUuidFromGetAllAuths() {
122+
// given
123+
SQLite sqLite = new SQLite(settings, null, con);
124+
125+
// when
126+
List<PlayerAuth> auths = sqLite.getAllAuths();
127+
128+
// then - bobby has playerUUID set in test data, user does not
129+
PlayerAuth bobby = auths.stream().filter(a -> "bobby".equals(a.getNickname())).findFirst().orElse(null);
130+
assertThat(bobby, notNullValue());
131+
assertThat(bobby.getUuid(), equalTo(UUID.fromString("a8674b3e-7c1a-4cfa-8f37-1c6e7d2b9f44")));
132+
133+
PlayerAuth user = auths.stream().filter(a -> "user".equals(a.getNickname())).findFirst().orElse(null);
134+
assertThat(user, notNullValue());
135+
assertThat(user.getUuid(), equalTo(null));
136+
}
137+
114138
@Override
115139
protected DataSource getDataSource(String saltColumn) {
116140
when(settings.getProperty(DatabaseSettings.MYSQL_COL_SALT)).thenReturn(saltColumn);

authme-core/src/test/resources/fr/xephi/authme/datasource/sql-initialize.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ CREATE TABLE authme (
2020
realname VARCHAR(255) NOT NULL DEFAULT 'Player',
2121
salt varchar(255),
2222
hasSession INT NOT NULL DEFAULT '0',
23-
premiumUUID VARCHAR(36)
23+
premiumUUID VARCHAR(36),
24+
playerUUID VARCHAR(36)
2425
);
2526

26-
INSERT INTO authme (username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt, regdate, regip, totp)
27-
VALUES ('bobby','$SHA$11aa0706173d7272$dbba966','123.45.67.89',1449136800,1.05,2.1,4.2,'world',-0.44,2.77,'your@email.com',0,'Bobby',NULL,1436778723,'127.0.4.22','JBSWY3DPEHPK3PXP');
27+
INSERT INTO authme (username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt, regdate, regip, totp, playerUUID)
28+
VALUES ('bobby','$SHA$11aa0706173d7272$dbba966','123.45.67.89',1449136800,1.05,2.1,4.2,'world',-0.44,2.77,'your@email.com',0,'Bobby',NULL,1436778723,'127.0.4.22','JBSWY3DPEHPK3PXP','a8674b3e-7c1a-4cfa-8f37-1c6e7d2b9f44');
2829
INSERT INTO authme (username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt, regdate)
2930
VALUES ('user','b28c32f624a4eb161d6adc9acb5bfc5b','34.56.78.90',1453242857,124.1,76.3,-127.8,'nether',0.23,4.88,'user@example.org',0,'user','f750ba32',0);

0 commit comments

Comments
 (0)