Compare commits
No commits in common. "5c43347710aff474597f872801ed7e89fba4d208" and "7e871f824c4a85cca5f77382ed0f31dd17ccfcb7" have entirely different histories.
5c43347710
...
7e871f824c
8 changed files with 11 additions and 143 deletions
Binary file not shown.
|
@ -46,8 +46,6 @@ public class Configuration {
|
||||||
private String jwt_key;
|
private String jwt_key;
|
||||||
|
|
||||||
private String sql_folder;
|
private String sql_folder;
|
||||||
|
|
||||||
private int event_chapter;
|
|
||||||
|
|
||||||
private File _file;
|
private File _file;
|
||||||
|
|
||||||
|
@ -230,8 +228,4 @@ public class Configuration {
|
||||||
public String getSqlFolder(){
|
public String getSqlFolder(){
|
||||||
return this.sql_folder;
|
return this.sql_folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEventChapter(){
|
|
||||||
return this.event_chapter;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -93,6 +93,7 @@ public class Main{
|
||||||
public void exec(Matcher matcher, Context context, HttpReader reader, HttpWriter writer) throws Exception {
|
public void exec(Matcher matcher, Context context, HttpReader reader, HttpWriter writer) throws Exception {
|
||||||
context.response(200);
|
context.response(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
initRoutes(router, repo, config);
|
initRoutes(router, repo, config);
|
||||||
|
@ -140,36 +141,16 @@ public class Main{
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
new Thread(new Runnable(){
|
|
||||||
public void run(){
|
|
||||||
Key key = new Key();
|
|
||||||
|
|
||||||
Locker<Throwable> locker = router.getExceptionLogger();
|
|
||||||
|
|
||||||
locker.init(key);
|
|
||||||
try {
|
|
||||||
while(true){
|
|
||||||
locker.lock(key);
|
|
||||||
locker.getValue(key).printStackTrace();
|
|
||||||
}
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
locker.remove(key);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
if(config.useSsl()) router.configureSSL(config.getSslKeystore(), config.getSslKeystorePasswd());
|
if(config.useSsl()) router.configureSSL(config.getSslKeystore(), config.getSslKeystorePasswd());
|
||||||
router.listen(config.getTcpPort(), config.useSsl());
|
router.listen(config.getTcpPort(), config.useSsl());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initRoutes(Router<PeerAtUser> router, DatabaseRepository repo, Configuration config) throws Exception{
|
private static void initRoutes(Router<PeerAtUser> router, DatabaseRepository repo, Configuration config) throws Exception{
|
||||||
router.registerPackages("dev.peerat.backend.routes",new DependencyInjector()
|
router.registerPackages(new DependencyInjector()
|
||||||
.of(repo, router, config, new RouteExtracter(router), config.getMail())
|
.of(repo, router, config, new RouteExtracter(router))
|
||||||
.of("waitting", new HashMap<>())
|
.of("waitting", new HashMap<>())
|
||||||
.of("leaderboard", new Locker<>())
|
.of("leaderboard", new Locker<>())
|
||||||
.of("groups", new Locker<>())
|
.of("groups", new Locker<>()));
|
||||||
.of("groupMessages", new Locker<>()));
|
|
||||||
|
|
||||||
// Bot bot = new Bot(config, repo, groupLock);
|
// Bot bot = new Bot(config, repo, groupLock);
|
||||||
// bot.start();
|
// bot.start();
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
package dev.peerat.backend.routes;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
|
|
||||||
import dev.peerat.backend.Configuration;
|
|
||||||
import dev.peerat.backend.model.Group;
|
|
||||||
import dev.peerat.backend.model.PeerAtUser;
|
|
||||||
import dev.peerat.backend.repository.DatabaseGroupRepository;
|
|
||||||
import dev.peerat.backend.repository.DatabaseRepository;
|
|
||||||
import dev.peerat.framework.Context;
|
|
||||||
import dev.peerat.framework.HttpWriter;
|
|
||||||
import dev.peerat.framework.Injection;
|
|
||||||
import dev.peerat.framework.Locker;
|
|
||||||
import dev.peerat.framework.Locker.Key;
|
|
||||||
import dev.peerat.framework.Route;
|
|
||||||
|
|
||||||
public class EventSSE{
|
|
||||||
|
|
||||||
private Locker<GroupMessage> locker;
|
|
||||||
private DatabaseGroupRepository repo;
|
|
||||||
private int eventChapter;
|
|
||||||
|
|
||||||
public EventSSE(@Injection("groupMessages") Locker<GroupMessage> locker, DatabaseRepository repo, Configuration config){
|
|
||||||
this.locker = locker;
|
|
||||||
this.repo = repo.getGroupRepository();
|
|
||||||
this.eventChapter = config.getEventChapter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Route(path = "^/group/event/$", needLogin = true)
|
|
||||||
public void connect(Context context, HttpWriter writer) throws Exception {
|
|
||||||
Group group = repo.getPlayerGroup(context.<PeerAtUser>getUser().getId(), this.eventChapter);
|
|
||||||
if(group == null){
|
|
||||||
context.response(401);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
context.response(200, "Content-Type: text/event-stream");
|
|
||||||
|
|
||||||
Key key = new Key();
|
|
||||||
|
|
||||||
locker.init(key);
|
|
||||||
try {
|
|
||||||
while(true){
|
|
||||||
GroupMessage message = locker.getValue(key);
|
|
||||||
if(message.getGroup() == null || message.getGroup().equals(group.getName())){
|
|
||||||
writer.write("data: "+message.getMessage()+"\n\n");
|
|
||||||
writer.flush();
|
|
||||||
}
|
|
||||||
locker.lock(key);
|
|
||||||
}
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
locker.remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class GroupMessage{
|
|
||||||
|
|
||||||
private String group;
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
public GroupMessage(String group, String message){
|
|
||||||
this.group = group;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGroup(){
|
|
||||||
return this.group;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage(){
|
|
||||||
return this.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,7 +17,7 @@ public class Swagger implements Response{
|
||||||
|
|
||||||
public Swagger(RouteExtracter extracter, Configuration config){
|
public Swagger(RouteExtracter extracter, Configuration config){
|
||||||
try{
|
try{
|
||||||
// this.json = extracter.swagger(config.getTokenIssuer()).toString();
|
this.json = extracter.swagger(config.getTokenIssuer()).toString();
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
json = "{}";
|
json = "{}";
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
package dev.peerat.backend.routes.admins;
|
|
||||||
|
|
||||||
import dev.peerat.backend.routes.EventSSE.GroupMessage;
|
|
||||||
import dev.peerat.framework.Context;
|
|
||||||
import dev.peerat.framework.HttpReader;
|
|
||||||
import dev.peerat.framework.Injection;
|
|
||||||
import dev.peerat.framework.Locker;
|
|
||||||
import dev.peerat.framework.Route;
|
|
||||||
import dev.peerat.framework.utils.json.JsonMap;
|
|
||||||
|
|
||||||
public class GroupController {
|
|
||||||
|
|
||||||
private Locker<GroupMessage> locker;
|
|
||||||
|
|
||||||
public GroupController(@Injection("groupMessages") Locker<GroupMessage> locker){
|
|
||||||
this.locker = locker;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Route(path = "^/admin/event/$", needLogin = true)
|
|
||||||
public void send(Context context, HttpReader reader) throws Exception{
|
|
||||||
JsonMap json = reader.readJson();
|
|
||||||
if(!json.has("message")){
|
|
||||||
context.response(400);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
locker.setValue(new GroupMessage(json.get("group"), json.get("message")));
|
|
||||||
context.response(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -29,7 +29,6 @@ import javax.net.ssl.HttpsURLConnection;
|
||||||
import org.jose4j.json.internal.json_simple.JSONAware;
|
import org.jose4j.json.internal.json_simple.JSONAware;
|
||||||
import org.jose4j.json.internal.json_simple.JSONObject;
|
import org.jose4j.json.internal.json_simple.JSONObject;
|
||||||
|
|
||||||
import dev.peerat.backend.Configuration;
|
|
||||||
import dev.peerat.backend.bonus.extract.RouteDoc;
|
import dev.peerat.backend.bonus.extract.RouteDoc;
|
||||||
import dev.peerat.backend.model.PeerAtUser;
|
import dev.peerat.backend.model.PeerAtUser;
|
||||||
import dev.peerat.backend.repository.DatabaseAuthRepository;
|
import dev.peerat.backend.repository.DatabaseAuthRepository;
|
||||||
|
@ -59,14 +58,15 @@ public class MailConfirmation extends FormResponse{
|
||||||
public MailConfirmation(
|
public MailConfirmation(
|
||||||
DatabaseRepository databaseRepo,
|
DatabaseRepository databaseRepo,
|
||||||
Router<PeerAtUser> router,
|
Router<PeerAtUser> router,
|
||||||
Configuration config,
|
@Injection("usersFiles") String initUsersFilesPath,
|
||||||
|
@Injection("gitToken") String gitToken,
|
||||||
@Injection("waitting") Map<String, String> playersWaiting,
|
@Injection("waitting") Map<String, String> playersWaiting,
|
||||||
Mail mail) throws NoSuchAlgorithmException{
|
Mail mail) throws NoSuchAlgorithmException{
|
||||||
|
|
||||||
this.databaseRepo = databaseRepo.getAuthRepository();
|
this.databaseRepo = databaseRepo.getAuthRepository();
|
||||||
this.router = router;
|
this.router = router;
|
||||||
this.usersFilesPath = config.getUsersFiles();
|
this.usersFilesPath = initUsersFilesPath;
|
||||||
this.gitToken = config.getGitToken();
|
this.gitToken = gitToken;
|
||||||
this.playersWaiting = playersWaiting;
|
this.playersWaiting = playersWaiting;
|
||||||
this.mail = mail;
|
this.mail = mail;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
import dev.peerat.backend.Configuration;
|
|
||||||
import dev.peerat.backend.bonus.extract.RouteDoc;
|
import dev.peerat.backend.bonus.extract.RouteDoc;
|
||||||
import dev.peerat.backend.repository.DatabaseAuthRepository;
|
import dev.peerat.backend.repository.DatabaseAuthRepository;
|
||||||
import dev.peerat.backend.repository.DatabaseRepository;
|
import dev.peerat.backend.repository.DatabaseRepository;
|
||||||
|
@ -32,11 +31,11 @@ public class Register extends FormResponse{
|
||||||
private String host;
|
private String host;
|
||||||
private List<Random> randoms;
|
private List<Random> randoms;
|
||||||
|
|
||||||
public Register(DatabaseRepository databaseRepo, @Injection("waitting") Map<String, String> playersWaiting, Mail mail, Configuration config){
|
public Register(DatabaseRepository databaseRepo, @Injection("waitting") Map<String, String> playersWaiting, Mail mail, @Injection("issuer") String host){
|
||||||
this.databaseRepo = databaseRepo.getAuthRepository();
|
this.databaseRepo = databaseRepo.getAuthRepository();
|
||||||
this.playersWaiting = playersWaiting;
|
this.playersWaiting = playersWaiting;
|
||||||
this.mail = mail;
|
this.mail = mail;
|
||||||
this.host = config.getTokenIssuer();
|
this.host = host;
|
||||||
this.randoms = new ArrayList<>();
|
this.randoms = new ArrayList<>();
|
||||||
|
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|
Loading…
Add table
Reference in a new issue