mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-22 18:25:27 +01:00
#815 Save yaw & pitch for last login in SQL data sources
This commit is contained in:
parent
70298a830b
commit
e56a3c0ab6
@ -129,7 +129,7 @@ public class AuthMeApi {
|
||||
PlayerAuth auth = playerCache.getAuth(player.getName());
|
||||
if (auth != null) {
|
||||
return new Location(Bukkit.getWorld(auth.getWorld()),
|
||||
auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
|
||||
auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getYaw(), auth.getPitch());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ public class PlayerAuth {
|
||||
private double y;
|
||||
private double z;
|
||||
private String world;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
/**
|
||||
* @param serialized String
|
||||
@ -35,33 +37,11 @@ public class PlayerAuth {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. Instantiate objects with the {@link #builder() builder}.
|
||||
* Hidden constructor.
|
||||
*
|
||||
* @param nickname all lowercase name of the player
|
||||
* @param password password
|
||||
* @param groupId the group id
|
||||
* @param ip the associated ip address
|
||||
* @param lastLogin player's last login (timestamp)
|
||||
* @param x quit location: x coordinate
|
||||
* @param y quit location: y coordinate
|
||||
* @param z quit location: z coordinate
|
||||
* @param world quit location: world name
|
||||
* @param email the associated email
|
||||
* @param realName the player's name with proper casing
|
||||
* @see #builder()
|
||||
*/
|
||||
private PlayerAuth(String nickname, HashedPassword password, int groupId, String ip, long lastLogin,
|
||||
double x, double y, double z, String world, String email, String realName) {
|
||||
this.nickname = nickname.toLowerCase();
|
||||
this.password = password;
|
||||
this.ip = ip;
|
||||
this.lastLogin = lastLogin;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.world = world;
|
||||
this.groupId = groupId;
|
||||
this.email = email;
|
||||
this.realName = realName;
|
||||
private PlayerAuth() {
|
||||
}
|
||||
|
||||
|
||||
@ -124,6 +104,14 @@ public class PlayerAuth {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
@ -235,26 +223,34 @@ public class PlayerAuth {
|
||||
private String realName;
|
||||
private HashedPassword password;
|
||||
private String ip;
|
||||
private String world;
|
||||
private String email;
|
||||
private int groupId = -1;
|
||||
private double x = 0.0f;
|
||||
private double y = 0.0f;
|
||||
private double z = 0.0f;
|
||||
private long lastLogin = System.currentTimeMillis();
|
||||
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private String world;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
public PlayerAuth build() {
|
||||
return new PlayerAuth(
|
||||
checkNotNull(name),
|
||||
firstNonNull(password, new HashedPassword("")),
|
||||
groupId,
|
||||
firstNonNull(ip, "127.0.0.1"),
|
||||
lastLogin,
|
||||
x, y, z,
|
||||
firstNonNull(world, "world"),
|
||||
firstNonNull(email, "your@email.com"),
|
||||
firstNonNull(realName, "Player")
|
||||
);
|
||||
PlayerAuth auth = new PlayerAuth();
|
||||
auth.nickname = checkNotNull(name).toLowerCase();
|
||||
auth.realName = firstNonNull(realName, "Player");
|
||||
auth.password = firstNonNull(password, new HashedPassword(""));
|
||||
auth.email = firstNonNull(email, "your@email.com");
|
||||
auth.ip = firstNonNull(ip, "127.0.0.1");
|
||||
auth.groupId = groupId;
|
||||
auth.lastLogin = lastLogin;
|
||||
|
||||
auth.x = x;
|
||||
auth.y = y;
|
||||
auth.z = z;
|
||||
auth.world = firstNonNull(world, "world");
|
||||
auth.yaw = yaw;
|
||||
auth.pitch = pitch;
|
||||
return auth;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
@ -286,11 +282,8 @@ public class PlayerAuth {
|
||||
this.y = location.getY();
|
||||
this.z = location.getZ();
|
||||
this.world = location.getWorld().getName();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder locWorld(String world) {
|
||||
this.world = world;
|
||||
this.yaw = location.getYaw();
|
||||
this.pitch = location.getPitch();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -309,6 +302,21 @@ public class PlayerAuth {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder locWorld(String world) {
|
||||
this.world = world;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder locYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder locPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lastLogin(long lastLogin) {
|
||||
this.lastLogin = lastLogin;
|
||||
return this;
|
||||
|
@ -21,6 +21,8 @@ public final class Columns {
|
||||
public final String LASTLOC_Y;
|
||||
public final String LASTLOC_Z;
|
||||
public final String LASTLOC_WORLD;
|
||||
public final String LASTLOC_YAW;
|
||||
public final String LASTLOC_PITCH;
|
||||
public final String EMAIL;
|
||||
public final String ID;
|
||||
public final String IS_LOGGED;
|
||||
@ -37,6 +39,8 @@ public final class Columns {
|
||||
LASTLOC_Y = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Y);
|
||||
LASTLOC_Z = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_Z);
|
||||
LASTLOC_WORLD = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_WORLD);
|
||||
LASTLOC_YAW = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_YAW);
|
||||
LASTLOC_PITCH = settings.getProperty(DatabaseSettings.MYSQL_COL_LASTLOC_PITCH);
|
||||
EMAIL = settings.getProperty(DatabaseSettings.MYSQL_COL_EMAIL);
|
||||
ID = settings.getProperty(DatabaseSettings.MYSQL_COL_ID);
|
||||
IS_LOGGED = settings.getProperty(DatabaseSettings.MYSQL_COL_ISLOGGED);
|
||||
|
@ -218,6 +218,16 @@ public class MySQL implements DataSource {
|
||||
+ col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + col.LASTLOC_Z);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_YAW)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_YAW + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_PITCH)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_PITCH + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.EMAIL)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + col.LASTLOC_WORLD);
|
||||
@ -714,14 +724,17 @@ public class MySQL implements DataSource {
|
||||
@Override
|
||||
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||
String sql = "UPDATE " + tableName
|
||||
+ " SET " + col.LASTLOC_X + " =?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, " + col.LASTLOC_WORLD + "=?"
|
||||
+ " SET " + col.LASTLOC_X + " =?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, " + col.LASTLOC_WORLD + "=?, "
|
||||
+ col.LASTLOC_YAW + "=?, " + col.LASTLOC_PITCH + "=?"
|
||||
+ " WHERE " + col.NAME + "=?;";
|
||||
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setDouble(1, auth.getQuitLocX());
|
||||
pst.setDouble(2, auth.getQuitLocY());
|
||||
pst.setDouble(3, auth.getQuitLocZ());
|
||||
pst.setString(4, auth.getWorld());
|
||||
pst.setString(5, auth.getNickname());
|
||||
pst.setFloat(5, auth.getYaw());
|
||||
pst.setFloat(6, auth.getPitch());
|
||||
pst.setString(7, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
@ -959,6 +972,8 @@ public class MySQL implements DataSource {
|
||||
.locX(row.getDouble(col.LASTLOC_X))
|
||||
.locY(row.getDouble(col.LASTLOC_Y))
|
||||
.locZ(row.getDouble(col.LASTLOC_Z))
|
||||
.locYaw(row.getFloat(col.LASTLOC_YAW))
|
||||
.locPitch(row.getFloat(col.LASTLOC_PITCH))
|
||||
.email(row.getString(col.EMAIL))
|
||||
.groupId(group)
|
||||
.build();
|
||||
|
@ -21,10 +21,10 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static fr.xephi.authme.datasource.SqlDataSourceUtils.close;
|
||||
import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException;
|
||||
|
||||
/**
|
||||
* SQLite data source.
|
||||
*/
|
||||
public class SQLite implements DataSource {
|
||||
|
||||
@ -118,6 +118,16 @@ public class SQLite implements DataSource {
|
||||
+ " ADD COLUMN " + col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_YAW)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_YAW + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.LASTLOC_PITCH)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.LASTLOC_PITCH + " FLOAT;");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.EMAIL)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com';");
|
||||
@ -352,12 +362,17 @@ public class SQLite implements DataSource {
|
||||
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.LASTLOC_X + "=?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, " + col.LASTLOC_WORLD + "=? WHERE " + col.NAME + "=?;");
|
||||
pst = con.prepareStatement("UPDATE " + tableName + " SET "
|
||||
+ col.LASTLOC_X + "=?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, "
|
||||
+ col.LASTLOC_WORLD + "=?, " + col.LASTLOC_YAW + "=?, " + col.LASTLOC_PITCH + "=? "
|
||||
+ "WHERE " + col.NAME + "=?;");
|
||||
pst.setDouble(1, auth.getQuitLocX());
|
||||
pst.setDouble(2, auth.getQuitLocY());
|
||||
pst.setDouble(3, auth.getQuitLocZ());
|
||||
pst.setString(4, auth.getWorld());
|
||||
pst.setString(5, auth.getNickname());
|
||||
pst.setFloat(5, auth.getYaw());
|
||||
pst.setFloat(6, auth.getPitch());
|
||||
pst.setString(7, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
@ -586,7 +601,9 @@ public class SQLite implements DataSource {
|
||||
.locX(row.getDouble(col.LASTLOC_X))
|
||||
.locY(row.getDouble(col.LASTLOC_Y))
|
||||
.locZ(row.getDouble(col.LASTLOC_Z))
|
||||
.locWorld(row.getString(col.LASTLOC_WORLD));
|
||||
.locWorld(row.getString(col.LASTLOC_WORLD))
|
||||
.locYaw(row.getFloat(col.LASTLOC_YAW))
|
||||
.locPitch(row.getFloat(col.LASTLOC_PITCH));
|
||||
|
||||
String ip = row.getString(col.IP);
|
||||
if (!ip.isEmpty()) {
|
||||
@ -594,4 +611,35 @@ public class SQLite implements DataSource {
|
||||
}
|
||||
return authBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
private static void close(Statement st) {
|
||||
if (st != null) {
|
||||
try {
|
||||
st.close();
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void close(Connection con) {
|
||||
if (con != null) {
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void close(ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +134,8 @@ public class TeleportationService implements Reloadable {
|
||||
if (world == null) {
|
||||
world = player.getWorld();
|
||||
}
|
||||
return new Location(world, auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
|
||||
return new Location(world, auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(),
|
||||
auth.getYaw(), auth.getPitch());
|
||||
}
|
||||
|
||||
private void teleportBackFromSpawn(final Player player, final Location location) {
|
||||
|
@ -98,6 +98,14 @@ public final class DatabaseSettings implements SettingsHolder {
|
||||
public static final Property<String> MYSQL_COL_LASTLOC_WORLD =
|
||||
newProperty("DataSource.mySQLlastlocWorld", "world");
|
||||
|
||||
@Comment("Column for storing player LastLocation - Yaw")
|
||||
public static final Property<String> MYSQL_COL_LASTLOC_YAW =
|
||||
newProperty("DataSource.mySQLlastlocYaw", "yaw");
|
||||
|
||||
@Comment("Column for storing player LastLocation - Pitch")
|
||||
public static final Property<String> MYSQL_COL_LASTLOC_PITCH =
|
||||
newProperty("DataSource.mySQLlastlocPitch", "pitch");
|
||||
|
||||
@Comment("Column for storing players groups")
|
||||
public static final Property<String> MYSQL_COL_GROUP =
|
||||
newProperty("ExternalBoardOptions.mySQLColumnGroup", "");
|
||||
|
@ -16,15 +16,15 @@ public final class AuthMeMatchers {
|
||||
private AuthMeMatchers() {
|
||||
}
|
||||
|
||||
public static Matcher<? super HashedPassword> equalToHash(final String hash) {
|
||||
public static Matcher<? super HashedPassword> equalToHash(String hash) {
|
||||
return equalToHash(new HashedPassword(hash));
|
||||
}
|
||||
|
||||
public static Matcher<? super HashedPassword> equalToHash(final String hash, final String salt) {
|
||||
public static Matcher<? super HashedPassword> equalToHash(String hash, String salt) {
|
||||
return equalToHash(new HashedPassword(hash, salt));
|
||||
}
|
||||
|
||||
public static Matcher<? super HashedPassword> equalToHash(final HashedPassword hash) {
|
||||
public static Matcher<? super HashedPassword> equalToHash(HashedPassword hash) {
|
||||
return new TypeSafeMatcher<HashedPassword>() {
|
||||
@Override
|
||||
public boolean matchesSafely(HashedPassword item) {
|
||||
@ -43,8 +43,8 @@ public final class AuthMeMatchers {
|
||||
};
|
||||
}
|
||||
|
||||
public static Matcher<? super PlayerAuth> hasAuthBasicData(final String name, final String realName,
|
||||
final String email, final String ip) {
|
||||
public static Matcher<? super PlayerAuth> hasAuthBasicData(String name, String realName,
|
||||
String email, String ip) {
|
||||
return new TypeSafeMatcher<PlayerAuth>() {
|
||||
@Override
|
||||
public boolean matchesSafely(PlayerAuth item) {
|
||||
@ -59,29 +59,43 @@ public final class AuthMeMatchers {
|
||||
description.appendValue(String.format("PlayerAuth with name %s, realname %s, email %s, ip %s",
|
||||
name, realName, email, ip));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeMismatchSafely(PlayerAuth item, Description description) {
|
||||
description.appendValue(String.format("PlayerAuth with name %s, realname %s, email %s, ip %s",
|
||||
item.getNickname(), item.getRealName(), item.getEmail(), item.getIp()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Matcher<? super PlayerAuth> hasAuthLocation(final double x, final double y, final double z,
|
||||
final String world) {
|
||||
public static Matcher<? super PlayerAuth> hasAuthLocation(PlayerAuth auth) {
|
||||
return hasAuthLocation(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(),
|
||||
auth.getYaw(), auth.getPitch());
|
||||
}
|
||||
|
||||
public static Matcher<? super PlayerAuth> hasAuthLocation(double x, double y, double z,
|
||||
String world, float yaw, float pitch) {
|
||||
return new TypeSafeMatcher<PlayerAuth>() {
|
||||
@Override
|
||||
public boolean matchesSafely(PlayerAuth item) {
|
||||
return Objects.equals(x, item.getQuitLocX())
|
||||
&& Objects.equals(y, item.getQuitLocY())
|
||||
&& Objects.equals(z, item.getQuitLocZ())
|
||||
&& Objects.equals(world, item.getWorld());
|
||||
&& Objects.equals(world, item.getWorld())
|
||||
&& Objects.equals(yaw, item.getYaw())
|
||||
&& Objects.equals(pitch, item.getPitch());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendValue(String.format("PlayerAuth with quit location (x: %f, y: %f, z: %f, world: %s)",
|
||||
x, y, z, world));
|
||||
description.appendValue(
|
||||
String.format("PlayerAuth with quit location (x: %f, y: %f, z: %f, world: %s, yaw: %f, pitch: %f)",
|
||||
x, y, z, world, yaw, pitch));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Matcher<String> stringWithLength(final int length) {
|
||||
public static Matcher<String> stringWithLength(int length) {
|
||||
return new TypeSafeMatcher<String>() {
|
||||
@Override
|
||||
protected boolean matchesSafely(String item) {
|
||||
|
@ -1,13 +1,12 @@
|
||||
package fr.xephi.authme.api.v3;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.service.PluginHookService;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.service.PluginHookService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -43,8 +42,6 @@ public class AuthMeApiTest {
|
||||
@InjectMocks
|
||||
private AuthMeApi api;
|
||||
|
||||
@Mock
|
||||
private AuthMe authMe;
|
||||
@Mock
|
||||
private PluginHookService pluginHookService;
|
||||
@Mock
|
||||
@ -120,6 +117,8 @@ public class AuthMeApiTest {
|
||||
.locX(12.4)
|
||||
.locY(24.6)
|
||||
.locZ(-438.2)
|
||||
.locYaw(3.41f)
|
||||
.locPitch(0.29f)
|
||||
.build();
|
||||
given(playerCache.getAuth(name)).willReturn(auth);
|
||||
Server server = mock(Server.class);
|
||||
@ -136,6 +135,8 @@ public class AuthMeApiTest {
|
||||
assertThat(result.getY(), equalTo(auth.getQuitLocY()));
|
||||
assertThat(result.getZ(), equalTo(auth.getQuitLocZ()));
|
||||
assertThat(result.getWorld(), equalTo(world));
|
||||
assertThat(result.getYaw(), equalTo(auth.getYaw()));
|
||||
assertThat(result.getPitch(), equalTo(auth.getPitch()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -96,12 +96,12 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
assertThat(invalidAuth, nullValue());
|
||||
|
||||
assertThat(bobbyAuth, hasAuthBasicData("bobby", "Bobby", "your@email.com", "123.45.67.89"));
|
||||
assertThat(bobbyAuth, hasAuthLocation(1.05, 2.1, 4.2, "world"));
|
||||
assertThat(bobbyAuth, hasAuthLocation(1.05, 2.1, 4.2, "world", -0.44f, 2.77f));
|
||||
assertThat(bobbyAuth.getLastLogin(), equalTo(1449136800L));
|
||||
assertThat(bobbyAuth.getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966"));
|
||||
|
||||
assertThat(userAuth, hasAuthBasicData("user", "user", "user@example.org", "34.56.78.90"));
|
||||
assertThat(userAuth, hasAuthLocation(124.1, 76.3, -127.8, "nether"));
|
||||
assertThat(userAuth, hasAuthLocation(124.1, 76.3, -127.8, "nether", 0.23f, 4.88f));
|
||||
assertThat(userAuth.getLastLogin(), equalTo(1453242857L));
|
||||
assertThat(userAuth.getPassword(), equalToHash("b28c32f624a4eb161d6adc9acb5bfc5b", "f750ba32"));
|
||||
}
|
||||
@ -229,14 +229,14 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
DataSource dataSource = getDataSource();
|
||||
PlayerAuth user = PlayerAuth.builder()
|
||||
.name("user").locX(143).locY(-42.12).locZ(29.47)
|
||||
.locWorld("the_end").build();
|
||||
.locWorld("the_end").locYaw(2.2f).locPitch(0.45f).build();
|
||||
|
||||
// when
|
||||
boolean response = dataSource.updateQuitLoc(user);
|
||||
|
||||
// then
|
||||
assertThat(response, equalTo(true));
|
||||
assertThat(dataSource.getAuth("user"), hasAuthLocation(143, -42.12, 29.47, "the_end"));
|
||||
assertThat(dataSource.getAuth("user"), hasAuthLocation(user));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -62,15 +62,15 @@ public class FlatFileIntegrationTest {
|
||||
// then
|
||||
assertThat(authList, hasSize(7));
|
||||
assertThat(getName("bobby", authList), hasAuthBasicData("bobby", "bobby", "your@email.com", "123.45.67.89"));
|
||||
assertThat(getName("bobby", authList), hasAuthLocation(1.05, 2.1, 4.2, "world"));
|
||||
assertThat(getName("bobby", authList), hasAuthLocation(1.05, 2.1, 4.2, "world", 0, 0));
|
||||
assertThat(getName("bobby", authList).getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966"));
|
||||
assertThat(getName("twofields", authList), hasAuthBasicData("twofields", "twofields", "your@email.com", "127.0.0.1"));
|
||||
assertThat(getName("twofields", authList).getPassword(), equalToHash("hash1234"));
|
||||
assertThat(getName("threefields", authList), hasAuthBasicData("threefields", "threefields", "your@email.com", "33.33.33.33"));
|
||||
assertThat(getName("fourfields", authList), hasAuthBasicData("fourfields", "fourfields", "your@email.com", "4.4.4.4"));
|
||||
assertThat(getName("fourfields", authList).getLastLogin(), equalTo(404040404L));
|
||||
assertThat(getName("sevenfields", authList), hasAuthLocation(7.7, 14.14, 21.21, "world"));
|
||||
assertThat(getName("eightfields", authList), hasAuthLocation(8.8, 17.6, 26.4, "eightworld"));
|
||||
assertThat(getName("sevenfields", authList), hasAuthLocation(7.7, 14.14, 21.21, "world", 0, 0));
|
||||
assertThat(getName("eightfields", authList), hasAuthLocation(8.8, 17.6, 26.4, "eightworld", 0, 0));
|
||||
assertThat(getName("eightfields", authList).getLastLogin(), equalTo(1234567888L));
|
||||
assertThat(getName("eightfields", authList).getPassword(), equalToHash("hash8168"));
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import fr.xephi.authme.datasource.AbstractResourceClosingTest;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.MySQL;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import fr.xephi.authme.datasource.AbstractResourceClosingTest;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
|
@ -64,11 +64,11 @@ public class ForceFlatToSqliteTest {
|
||||
verify(dataSource, times(7)).saveAuth(authCaptor.capture());
|
||||
List<PlayerAuth> auths = authCaptor.getAllValues();
|
||||
assertThat(auths, hasItem(hasAuthBasicData("bobby", "Player", "your@email.com", "123.45.67.89")));
|
||||
assertThat(auths, hasItem(hasAuthLocation(1.05, 2.1, 4.2, "world")));
|
||||
assertThat(auths, hasItem(hasAuthLocation(1.05, 2.1, 4.2, "world", 0, 0)));
|
||||
assertThat(auths, hasItem(hasAuthBasicData("user", "Player", "user@example.org", "34.56.78.90")));
|
||||
assertThat(auths, hasItem(hasAuthLocation(124.1, 76.3, -127.8, "nether")));
|
||||
assertThat(auths, hasItem(hasAuthLocation(124.1, 76.3, -127.8, "nether", 0, 0)));
|
||||
assertThat(auths, hasItem(hasAuthBasicData("eightfields", "Player", "your@email.com", "6.6.6.66")));
|
||||
assertThat(auths, hasItem(hasAuthLocation(8.8, 17.6, 26.4, "eightworld")));
|
||||
assertThat(auths, hasItem(hasAuthLocation(8.8, 17.6, 26.4, "eightworld", 0, 0)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public class EmailRegisterExecutorProviderTest {
|
||||
|
||||
// then
|
||||
assertThat(auth, hasAuthBasicData("veronica", "Veronica", "test@example.com", "123.45.67.89"));
|
||||
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld"));
|
||||
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 0, 0));
|
||||
assertThat(auth.getPassword().getHash(), stringWithLength(12));
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ public class PasswordRegisterExecutorTest {
|
||||
TestHelper.mockPlayerIp(player, "123.45.67.89");
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("someWorld");
|
||||
given(player.getLocation()).willReturn(new Location(world, 48, 96, 144));
|
||||
given(player.getLocation()).willReturn(new Location(world, 48, 96, 144, 1.1f, 0.28f));
|
||||
PasswordRegisterParams params = PasswordRegisterParams.of(player, "pass", "mail@example.org");
|
||||
|
||||
// when
|
||||
@ -108,7 +108,7 @@ public class PasswordRegisterExecutorTest {
|
||||
|
||||
// then
|
||||
assertThat(auth, hasAuthBasicData("s1m0n", "S1m0N", "mail@example.org", "123.45.67.89"));
|
||||
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld"));
|
||||
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 1.1f, 0.28f));
|
||||
assertThat(auth.getPassword(), equalToHash("pass"));
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class PlayerAuthBuilderHelperTest {
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("worldName");
|
||||
Location location = new Location(world, 123, 80, -99);
|
||||
Location location = new Location(world, 123, 80, -99, 2.45f, 7.61f);
|
||||
given(player.getLocation()).willReturn(location);
|
||||
HashedPassword hashedPassword = new HashedPassword("myHash0001");
|
||||
String email = "test@example.org";
|
||||
@ -38,7 +38,7 @@ public class PlayerAuthBuilderHelperTest {
|
||||
|
||||
// then
|
||||
assertThat(auth, hasAuthBasicData("noah", "Noah", email, ip));
|
||||
assertThat(auth, hasAuthLocation(123, 80, -99, "worldName"));
|
||||
assertThat(auth, hasAuthLocation(123, 80, -99, "worldName", 2.45f, 7.61f));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -10,6 +10,8 @@ CREATE TABLE authme (
|
||||
y DOUBLE NOT NULL DEFAULT '0.0',
|
||||
z DOUBLE NOT NULL DEFAULT '0.0',
|
||||
world VARCHAR(255) NOT NULL DEFAULT 'world',
|
||||
yaw FLOAT,
|
||||
pitch FLOAT,
|
||||
email VARCHAR(255) DEFAULT 'your@email.com',
|
||||
isLogged INT DEFAULT '0', realname VARCHAR(255) NOT NULL DEFAULT 'Player',
|
||||
salt varchar(255),
|
||||
@ -18,7 +20,7 @@ CREATE TABLE authme (
|
||||
CONSTRAINT table_const_prim PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, email, isLogged, realname, salt)
|
||||
VALUES (1,'bobby','$SHA$11aa0706173d7272$dbba966','123.45.67.89',1449136800,1.05,2.1,4.2,'world','your@email.com',0,'Bobby',NULL);
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, email, isLogged, realname, salt)
|
||||
VALUES (NULL,'user','b28c32f624a4eb161d6adc9acb5bfc5b','34.56.78.90',1453242857,124.1,76.3,-127.8,'nether','user@example.org',0,'user','f750ba32');
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt)
|
||||
VALUES (1,'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);
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt)
|
||||
VALUES (NULL,'user','b28c32f624a4eb161d6adc9acb5bfc5b','34.56.78.90',1453242857,124.1,76.3,-127.8,'nether',0.23,4.88,'user@example.org',0,'user','f750ba32');
|
||||
|
Loading…
Reference in New Issue
Block a user