diff --git a/.idea/artifacts/MatchmakingBackend_jar.xml b/.idea/artifacts/MatchmakingBackend_jar.xml
new file mode 100644
index 0000000..380b609
--- /dev/null
+++ b/.idea/artifacts/MatchmakingBackend_jar.xml
@@ -0,0 +1,25 @@
+
+
+ $PROJECT_DIR$/out/artifacts/MatchmakingBackend_jar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e0904b9
--- /dev/null
+++ b/src/main/java/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: com.jamesquinley.Main
+
diff --git a/src/main/java/com/jamesquinley/DelegationServices/delegationServices.java b/src/main/java/com/jamesquinley/DelegationServices/delegationServices.java
index aff5fca..8e3361c 100644
--- a/src/main/java/com/jamesquinley/DelegationServices/delegationServices.java
+++ b/src/main/java/com/jamesquinley/DelegationServices/delegationServices.java
@@ -1,22 +1,17 @@
package com.jamesquinley.DelegationServices;
-import com.mongodb.BasicDBObject;
-import com.mongodb.ConnectionString;
-import com.mongodb.MongoClientSettings;
-import com.mongodb.MongoCommandException;
+import com.mongodb.*;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.text.SimpleDateFormat;
-import java.time.LocalDateTime;
-import java.util.Date;
-import java.util.Random;
+
+import javax.print.Doc;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import static com.mongodb.client.model.Filters.eq;
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -32,7 +27,7 @@ public class delegationServices {
static Document Lrequest = null;
public static void connectionInit() {
- scReadconnectionString = new ConnectionString("mongodb+srv://serverClient:x2sJ8Qu0VVMifNLX@accountdelegation.n06hb.mongodb.net/DelegationRequest?retryWrites=true&w=majority");
+ scReadconnectionString = new ConnectionString("mongodb+srv://edgenetworknode:yUiWfJBYCGwdRayj@matchnethop.hgxv0xd.mongodb.net/?retryWrites=true&w=majority");
//connects to database that production clients can use
System.out.println("This is a production server build (and will only work on that type)");
scReadsettings = MongoClientSettings.builder()
@@ -42,14 +37,12 @@ public class delegationServices {
.readTimeout(6, SECONDS))
.build();
dClient = MongoClients.create(scReadsettings);
- dClientDatabase = dClient.getDatabase("DelegationRequest");
- dCollection = dClientDatabase.getCollection("accountRequest");
- RGFilterDB = dClient.getDatabase("rgcon");
- RGFilter = RGFilterDB.getCollection("blocked");
-
+ dClientDatabase = dClient.getDatabase("edgecomm");
+ dCollection = dClientDatabase.getCollection("nettranslate");
}
- static ConnectionString AccountCon = new ConnectionString("mongodb://accountserver:x2sJ8Qu0VVMifNLX@192.168.1.5:27017/account?retryWrites=true&w=majority");
+ static ConnectionString AccountCon = new ConnectionString("mongodb://matchmakingbackend:erhijew983ruefeyf@192.168.1.5:27017/gameservices?retryWrites=true&w=majority");
//mongodb://localhost:27017
+ //erhijew983ruefeyf
//mongodb://accountserver:x2sJ8Qu0VVMifNLX@192.168.1.5:27017/account?retryWrites=true&w=majority
static MongoClientSettings AccountSettings = MongoClientSettings.builder()
.applyConnectionString(AccountCon)
@@ -58,49 +51,137 @@ public class delegationServices {
.readTimeout(6, SECONDS))
.build();
static MongoClient accountGetClient = MongoClients.create(AccountSettings);
- static MongoDatabase accountDatabase = accountGetClient.getDatabase("account");
- static MongoCollection accountS = accountDatabase.getCollection("UserPass");
- static MongoDatabase database = accountGetClient.getDatabase("guilds");
-
- static MongoCollection scCollection = database.getCollection("userCredits");
+ static MongoDatabase gameServices = accountGetClient.getDatabase("gameservices");
+ static MongoCollection lobbyIndex = gameServices.getCollection("matchmaking");
+ static MongoDatabase database = accountGetClient.getDatabase("service");
+ static MongoCollection servicesStatus = database.getCollection("config");
static int RequestR;
//still need to config
+ /*
+ Request (Simple) Index
+
+ 1 - Get all active lobbies
+ 2 - Return All lobbies request
+ 3 - Submit Lobby for posting
+ 4 - Return posting and lobby key
+ 5 - Submit Lobby de-listing request
+ 6 - Return de-lisitng result (return status is deleted:true;false)
+ */
public static void delegationProcesser() {
Document Filter;
Object ClientID = null;
- String RG = (String) Lrequest.get("filter");
- Filter = RGFilter.find(eq("rgkey", "UAROCKS")).first();
+ try {
+ ClientID = Lrequest.get("_id");
+ } catch (Exception exrp) {
+ System.out.println("This request has opted out of CID.");
}
+ int request = (int) Lrequest.get("type");
+ if (request == 1 || request == 3) {
+ if (request ==1 ) {
+ List lobbyNameList = new ArrayList<>();
+ List lobbyIPList = new ArrayList<>();
+ List lobbyKeyList = new ArrayList<>();
+ BasicDBObject requestModifier = new BasicDBObject();
+ requestModifier.append("_id", ClientID);
+ BasicDBObject updateQuery = new BasicDBObject();
+ BasicDBObject nameUpdate = new BasicDBObject();
+ BasicDBObject ipUpdate = new BasicDBObject();
+ BasicDBObject statusUpdate = new BasicDBObject();
+ BasicDBObject lobbyNum = new BasicDBObject();
- public static void Purge() {
+
+ Document index = new Document();
+ index = lobbyIndex.find(eq("indexref", "ocs_matchmakingidx")).first();
+ lobbyNameList = (List) index.get("LobbyName");
+ lobbyIPList = (List) index.get("LobbyIP");
+ //lobbyKeyList = (List) index.get("LobbyPrivateKey");
+ System.out.println(lobbyNameList);
+ System.out.println(lobbyIPList);
+ if (lobbyNameList.stream().count() -1 ==0) {
+ nameUpdate.append("$set",
+ new BasicDBObject().append("lobbies", "No lobbies are available..."));
+ updateQuery.append("$set",
+ new BasicDBObject().append("type", 2));
+ lobbyNum.append("$set",
+ new BasicDBObject().append("LobbyCount", 0));
+ statusUpdate.append("$set",
+ new BasicDBObject().append("status", true));
+ dCollection.updateOne(requestModifier, updateQuery);
+ dCollection.updateOne(requestModifier,nameUpdate);
+ dCollection.updateOne(requestModifier,lobbyNum);
+ dCollection.updateOne(requestModifier, statusUpdate);
+ DeleteTargetRequestByID(ClientID);
+ } else {
+ updateQuery.append("$set",
+ new BasicDBObject().append("type", 2));
+ nameUpdate.append("$set",
+ new BasicDBObject().append("lobbies", lobbyNameList));
+ ipUpdate.append("$set",
+ new BasicDBObject().append("ip", lobbyIPList));
+ lobbyNum.append("$set",
+ new BasicDBObject().append("LobbyCount", (int) lobbyNameList.stream().count() -1));
+ statusUpdate.append("$set",
+ new BasicDBObject().append("status", true));
+ dCollection.updateOne(requestModifier, updateQuery);
+ dCollection.updateOne(requestModifier, nameUpdate);
+ dCollection.updateOne(requestModifier, ipUpdate);
+ dCollection.updateOne(requestModifier,lobbyNum);
+ dCollection.updateOne(requestModifier, statusUpdate);
+ DeleteTargetRequestByID(ClientID);
+ }
+ }
+ }
+ }
+ public static void DeleteTargetRequestByID (Object ID)
+ {
+ final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
+ final Runnable runnable = new Runnable() {
+ int countdownStarter = 5;
+ public void run() {
+ countdownStarter--;
+ if (countdownStarter <= 0) {
+ countdownStarter = 5;
+ BasicDBObject searchQuery = new BasicDBObject();
+ searchQuery.append("_id", ID);
+ dCollection.deleteMany(searchQuery);
+ System.out.println("Flushed a targeted request (CID) from the server");
+ scheduler.shutdown();
+ }
+ }
+ };
+ scheduler.scheduleAtFixedRate(runnable, 0, 1, TimeUnit.SECONDS);
+ }
+ public static void init() {
BasicDBObject searchQueryT = new BasicDBObject();
BasicDBObject searchQueryF = new BasicDBObject();
+ BasicDBObject LobbyIndex = new BasicDBObject();
searchQueryT.append("status", true);
searchQueryF.append("status", false);
+ LobbyIndex.append("indexref", "ocs_matchmakingidx");
dCollection.deleteMany(searchQueryT);
dCollection.deleteMany(searchQueryF);
- System.out.println("Flushed Server");
- }
-
- public static void TargetDelete(Object ID) {
- BasicDBObject searchQuery = new BasicDBObject();
- searchQuery.append("_id", ID);
- dCollection.deleteMany(searchQuery);
- System.out.println("Flushed a targeted request (CID) from the server");
+ System.out.println("Flushed NetJump Server");
+ lobbyIndex.deleteMany(LobbyIndex);
+ System.out.println("Flushed Matchmaking Index Server");
+ System.out.println("Creating Matchmaking Storage Index...");
+ Document lobbyIndexTemplate = new Document();
+ List lobbyNameList = new ArrayList<>();
+ List lobbyIPList = new ArrayList<>();
+ List lobbyKeyList = new ArrayList<>();
+ lobbyNameList.add("startatone");
+ lobbyIPList.add("startatone");
+ lobbyKeyList.add("startatone");
+ lobbyIndexTemplate.append("LobbyName",lobbyNameList);
+ lobbyIndexTemplate.append("LobbyIP", lobbyIPList);
+ lobbyIndexTemplate.append("LobbyPrivateKey",lobbyKeyList);
+ lobbyIndexTemplate.append("indexref", "ocs_matchmakingidx");
+ lobbyIndex.insertOne(lobbyIndexTemplate);
}
- public static void TargetDeleteByID(Object ID) {
- BasicDBObject searchQuery = new BasicDBObject();
- searchQuery.append("_id", ID);
- dCollection.deleteMany(searchQuery);
- System.out.println("Flushed a targeted request (CID) from the server");
-
-
- }
- public static void userAuthetication() {
+ public static void matchmakingService() {
Lrequest = dCollection.find(eq("status", false)).first();
if (!(Lrequest == null)) {
delegationProcesser();
diff --git a/src/main/java/com/jamesquinley/Main.java b/src/main/java/com/jamesquinley/Main.java
index 7431578..3ec00a2 100644
--- a/src/main/java/com/jamesquinley/Main.java
+++ b/src/main/java/com/jamesquinley/Main.java
@@ -1,14 +1,16 @@
package com.jamesquinley;
+import static com.jamesquinley.DelegationServices.delegationServices.init;
+
/**
I/O and lobby management backend for new sandbox multiplayer game, go team (Marci and I!)
*/
public class Main {
public static void main(String[] args) throws InterruptedException {
com.jamesquinley.DelegationServices.delegationServices.connectionInit();
- com.jamesquinley.DelegationServices.delegationServices.Purge();
- System.out.println("We're starting the login delegation server, please wait one moment while we check a few things.");
- System.out.println("We've started everything, requests are now being served");
+ System.out.println("Connected to NetJump server and Matchmaking Storage Server");
+ init();
+ System.out.println("An index has been initialized, matchmaking is now enabled.");
while (true) {
isolatedTrigger();
Thread.sleep(500);
@@ -17,9 +19,9 @@ public class Main {
static void isolatedTrigger() {
try {
- com.jamesquinley.DelegationServices.delegationServices.userAuthetication();
+ com.jamesquinley.DelegationServices.delegationServices.matchmakingService();
} catch (Exception e) {
- System.out.println("We ran into an issue, this is a known issue and will be fixed once I can figure it out. " + e.getCause());
+ System.out.println("Something went wrong, DEBUG: " + e);
}
}
}
\ No newline at end of file
diff --git a/src/main/java/com/jamesquinley/testing/splitFNet.java b/src/main/java/com/jamesquinley/testing/splitFNet.java
deleted file mode 100644
index bc73732..0000000
--- a/src/main/java/com/jamesquinley/testing/splitFNet.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.jamesquinley.testing;
-
-public class splitFNet {
- public static void splitNet ()
- {
- String s1 = "['This', 'Is', 'Split', 'Get', 'It?']";
-
- String[] array = s1.split(",");
- for(int i=0;i