-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial placeholders support for backend servers
- Loading branch information
1 parent
b93122d
commit 7f9a8d3
Showing
10 changed files
with
450 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/net/elytrium/limboauth/backend/Endpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2021 - 2024 Elytrium | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.elytrium.limboauth.backend; | ||
|
||
import com.google.common.io.ByteArrayDataInput; | ||
import com.google.common.io.ByteArrayDataOutput; | ||
import net.elytrium.limboauth.LimboAuth; | ||
|
||
public abstract class Endpoint { | ||
|
||
protected final LimboAuth plugin; | ||
|
||
public Endpoint(LimboAuth plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public abstract void write(ByteArrayDataOutput output); | ||
|
||
public abstract void read(ByteArrayDataInput input); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/net/elytrium/limboauth/backend/type/LongDatabaseEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2021 - 2024 Elytrium | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.elytrium.limboauth.backend.type; | ||
|
||
import java.util.function.Function; | ||
import net.elytrium.limboauth.LimboAuth; | ||
import net.elytrium.limboauth.handler.AuthSessionHandler; | ||
import net.elytrium.limboauth.model.RegisteredPlayer; | ||
|
||
public class LongDatabaseEndpoint extends LongEndpoint { | ||
|
||
public LongDatabaseEndpoint(LimboAuth plugin, String type, String username, long value) { | ||
super(plugin, type, username, value); | ||
} | ||
|
||
public LongDatabaseEndpoint(LimboAuth plugin, String type, Function<RegisteredPlayer, Long> function) { | ||
super(plugin, type, username -> { | ||
RegisteredPlayer player = AuthSessionHandler.fetchInfo(plugin.getPlayerDao(), username); | ||
if (player == null) { | ||
return Long.MIN_VALUE; | ||
} else { | ||
return function.apply(player); | ||
} | ||
}); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/net/elytrium/limboauth/backend/type/LongEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (C) 2021 - 2024 Elytrium | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.elytrium.limboauth.backend.type; | ||
|
||
import com.google.common.io.ByteArrayDataInput; | ||
import com.google.common.io.ByteArrayDataOutput; | ||
import java.util.function.Function; | ||
import net.elytrium.limboauth.LimboAuth; | ||
import net.elytrium.limboauth.Settings; | ||
import net.elytrium.limboauth.backend.Endpoint; | ||
|
||
public class LongEndpoint extends Endpoint { | ||
|
||
private String type; | ||
private Function<String, Long> function; | ||
private String username; | ||
private long value; | ||
|
||
public LongEndpoint(LimboAuth plugin, String type, Function<String, Long> function) { | ||
super(plugin); | ||
this.type = type; | ||
this.function = function; | ||
} | ||
|
||
public LongEndpoint(LimboAuth plugin, String type, String username, long value) { | ||
super(plugin); | ||
this.type = type; | ||
this.username = username; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public void write(ByteArrayDataOutput output) { | ||
output.writeUTF(this.type); | ||
if (!Settings.IMP.MAIN.BACKEND_API.ENABLED_ENDPOINTS.contains(this.type)) { | ||
output.writeInt(-1); | ||
output.writeUTF(this.username); | ||
return; | ||
} | ||
|
||
output.writeInt(0); | ||
output.writeUTF(this.username); | ||
output.writeLong(this.value); | ||
} | ||
|
||
@Override | ||
public void read(ByteArrayDataInput input) { | ||
int version = input.readInt(); | ||
if (version != 0) { | ||
throw new IllegalStateException("unsupported '" + this.type + "' endpoint version: " + version); | ||
} | ||
|
||
this.username = input.readUTF(); | ||
this.value = this.function.apply(this.username); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LongEndpoint{" | ||
+ "username='" + this.username + '\'' | ||
+ ", value=" + this.value | ||
+ '}'; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/net/elytrium/limboauth/backend/type/StringDatabaseEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2021 - 2024 Elytrium | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.elytrium.limboauth.backend.type; | ||
|
||
import java.util.function.Function; | ||
import net.elytrium.limboauth.LimboAuth; | ||
import net.elytrium.limboauth.handler.AuthSessionHandler; | ||
import net.elytrium.limboauth.model.RegisteredPlayer; | ||
|
||
public class StringDatabaseEndpoint extends StringEndpoint { | ||
|
||
public StringDatabaseEndpoint(LimboAuth plugin, String type, String username, String value) { | ||
super(plugin, type, username, value); | ||
} | ||
|
||
public StringDatabaseEndpoint(LimboAuth plugin, String type, Function<RegisteredPlayer, String> function) { | ||
super(plugin, type, username -> { | ||
RegisteredPlayer player = AuthSessionHandler.fetchInfo(plugin.getPlayerDao(), username); | ||
if (player == null) { | ||
return ""; | ||
} else { | ||
return function.apply(player); | ||
} | ||
}); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/net/elytrium/limboauth/backend/type/StringEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (C) 2021 - 2024 Elytrium | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.elytrium.limboauth.backend.type; | ||
|
||
import com.google.common.io.ByteArrayDataInput; | ||
import com.google.common.io.ByteArrayDataOutput; | ||
import java.util.function.Function; | ||
import net.elytrium.limboauth.LimboAuth; | ||
import net.elytrium.limboauth.Settings; | ||
import net.elytrium.limboauth.backend.Endpoint; | ||
|
||
public class StringEndpoint extends Endpoint { | ||
|
||
private String type; | ||
private Function<String, String> function; | ||
private String username; | ||
private String value; | ||
|
||
public StringEndpoint(LimboAuth plugin, String type, Function<String, String> function) { | ||
super(plugin); | ||
this.type = type; | ||
this.function = function; | ||
} | ||
|
||
public StringEndpoint(LimboAuth plugin, String type, String username, String value) { | ||
super(plugin); | ||
this.type = type; | ||
this.username = username; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public void write(ByteArrayDataOutput output) { | ||
output.writeUTF(this.type); | ||
if (!this.type.equals("available_endpoints") && !Settings.IMP.MAIN.BACKEND_API.ENABLED_ENDPOINTS.contains(this.type)) { | ||
output.writeInt(-1); | ||
output.writeUTF(this.username); | ||
return; | ||
} | ||
|
||
output.writeInt(0); | ||
output.writeUTF(this.username); | ||
output.writeUTF(this.value); | ||
} | ||
|
||
@Override | ||
public void read(ByteArrayDataInput input) { | ||
int version = input.readInt(); | ||
if (version != 0) { | ||
throw new IllegalStateException("unsupported '" + this.type + "' endpoint version: " + version); | ||
} | ||
|
||
this.username = input.readUTF(); | ||
this.value = this.function.apply(this.username); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "StringEndpoint{" | ||
+ "username='" + this.username + '\'' | ||
+ ", value=" + this.value | ||
+ '}'; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/net/elytrium/limboauth/backend/type/UnknownEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2021 - 2024 Elytrium | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.elytrium.limboauth.backend.type; | ||
|
||
import com.google.common.io.ByteArrayDataInput; | ||
import com.google.common.io.ByteArrayDataOutput; | ||
import net.elytrium.limboauth.LimboAuth; | ||
import net.elytrium.limboauth.backend.Endpoint; | ||
|
||
public class UnknownEndpoint extends Endpoint { | ||
|
||
private String type; | ||
|
||
public UnknownEndpoint(LimboAuth plugin) { | ||
super(plugin); | ||
} | ||
|
||
public UnknownEndpoint(LimboAuth plugin, String type) { | ||
super(plugin); | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public void write(ByteArrayDataOutput output) { | ||
output.writeUTF(this.type); | ||
output.writeInt(-2); | ||
} | ||
|
||
@Override | ||
public void read(ByteArrayDataInput input) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "UnknownEndpoint{" | ||
+ "type='" + this.type + '\'' | ||
+ '}'; | ||
} | ||
} |
Oops, something went wrong.