Server Update:

Matchmaking V1.0
THIS VERSION INCLUDES THE FOLLOWING ITEMS:
- Dynamic Fetching of indexed lobbies
- Flushing and rebuilding of indexes on start.
This commit is contained in:
James Quinley 2023-06-22 12:10:08 -07:00
parent 9d7fd0e04f
commit c744414f56
5 changed files with 161 additions and 65 deletions

View File

@ -0,0 +1,25 @@
<component name="ArtifactManager">
<artifact type="jar" build-on-make="true" name="MatchmakingBackend:jar">
<output-path>$PROJECT_DIR$/out/artifacts/MatchmakingBackend_jar</output-path>
<root id="archive" name="MatchmakingBackend.jar">
<element id="module-output" name="MatchmakingBackend" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.32/slf4j-api-1.7.32.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jsoup/jsoup/1.14.2/jsoup-1.14.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/javax/activation/activation/1.1/activation-1.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/apache/logging/log4j/log4j-api/2.17.0/log4j-api-2.17.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/controlsfx/controlsfx/11.1.1/controlsfx-11.1.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/net/lingala/zip4j/zip4j/2.6.1/zip4j-2.6.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/mongodb/bson/4.3.2/bson-4.3.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/junit/junit/4.10/junit-4.10.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/apache/logging/log4j/log4j-core/2.17.0/log4j-core-2.17.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/theokanning/openai-gpt3-java/api/0.4.0/api-0.4.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/mongodb/mongodb-driver-core/4.3.2/mongodb-driver-core-4.3.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/sun/mail/javax.mail/1.6.2/javax.mail-1.6.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/javax/mail/javax.mail-api/1.6.2/javax.mail-api-1.6.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/mongodb/mongodb-driver-sync/4.3.2/mongodb-driver-sync-4.3.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/jfoenix/jfoenix/8.0.10/jfoenix-8.0.10.jar" path-in-jar="/" />
</root>
</artifact>
</component>

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.jamesquinley.Main

View File

@ -1,22 +1,17 @@
package com.jamesquinley.DelegationServices; package com.jamesquinley.DelegationServices;
import com.mongodb.BasicDBObject; import com.mongodb.*;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoCommandException;
import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase; import com.mongodb.client.MongoDatabase;
import org.bson.Document; import org.bson.Document;
import java.io.File;
import java.io.FileWriter; import javax.print.Doc;
import java.io.IOException; import java.util.ArrayList;
import java.nio.file.Files; import java.util.List;
import java.nio.file.Path; import java.util.concurrent.Executors;
import java.text.SimpleDateFormat; import java.util.concurrent.ScheduledExecutorService;
import java.time.LocalDateTime; import java.util.concurrent.TimeUnit;
import java.util.Date;
import java.util.Random;
import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Filters.eq;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
@ -32,7 +27,7 @@ public class delegationServices {
static Document Lrequest = null; static Document Lrequest = null;
public static void connectionInit() { 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 //connects to database that production clients can use
System.out.println("This is a production server build (and will only work on that type)"); System.out.println("This is a production server build (and will only work on that type)");
scReadsettings = MongoClientSettings.builder() scReadsettings = MongoClientSettings.builder()
@ -42,14 +37,12 @@ public class delegationServices {
.readTimeout(6, SECONDS)) .readTimeout(6, SECONDS))
.build(); .build();
dClient = MongoClients.create(scReadsettings); dClient = MongoClients.create(scReadsettings);
dClientDatabase = dClient.getDatabase("DelegationRequest"); dClientDatabase = dClient.getDatabase("edgecomm");
dCollection = dClientDatabase.getCollection("accountRequest"); dCollection = dClientDatabase.getCollection("nettranslate");
RGFilterDB = dClient.getDatabase("rgcon");
RGFilter = RGFilterDB.getCollection("blocked");
} }
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 //mongodb://localhost:27017
//erhijew983ruefeyf
//mongodb://accountserver:x2sJ8Qu0VVMifNLX@192.168.1.5:27017/account?retryWrites=true&w=majority //mongodb://accountserver:x2sJ8Qu0VVMifNLX@192.168.1.5:27017/account?retryWrites=true&w=majority
static MongoClientSettings AccountSettings = MongoClientSettings.builder() static MongoClientSettings AccountSettings = MongoClientSettings.builder()
.applyConnectionString(AccountCon) .applyConnectionString(AccountCon)
@ -58,49 +51,137 @@ public class delegationServices {
.readTimeout(6, SECONDS)) .readTimeout(6, SECONDS))
.build(); .build();
static MongoClient accountGetClient = MongoClients.create(AccountSettings); static MongoClient accountGetClient = MongoClients.create(AccountSettings);
static MongoDatabase accountDatabase = accountGetClient.getDatabase("account"); static MongoDatabase gameServices = accountGetClient.getDatabase("gameservices");
static MongoCollection<Document> accountS = accountDatabase.getCollection("UserPass"); static MongoCollection<Document> lobbyIndex = gameServices.getCollection("matchmaking");
static MongoDatabase database = accountGetClient.getDatabase("guilds"); static MongoDatabase database = accountGetClient.getDatabase("service");
static MongoCollection<Document> servicesStatus = database.getCollection("config");
static MongoCollection<Document> scCollection = database.getCollection("userCredits");
static int RequestR; static int RequestR;
//still need to config //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() { public static void delegationProcesser() {
Document Filter; Document Filter;
Object ClientID = null; Object ClientID = null;
String RG = (String) Lrequest.get("filter"); try {
Filter = RGFilter.find(eq("rgkey", "UAROCKS")).first(); 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<String> lobbyNameList = new ArrayList<>();
List<String> lobbyIPList = new ArrayList<>();
List<String> 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<String>) index.get("LobbyName");
lobbyIPList = (List<String>) index.get("LobbyIP");
//lobbyKeyList = (List<String>) 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 searchQueryT = new BasicDBObject();
BasicDBObject searchQueryF = new BasicDBObject(); BasicDBObject searchQueryF = new BasicDBObject();
BasicDBObject LobbyIndex = new BasicDBObject();
searchQueryT.append("status", true); searchQueryT.append("status", true);
searchQueryF.append("status", false); searchQueryF.append("status", false);
LobbyIndex.append("indexref", "ocs_matchmakingidx");
dCollection.deleteMany(searchQueryT); dCollection.deleteMany(searchQueryT);
dCollection.deleteMany(searchQueryF); dCollection.deleteMany(searchQueryF);
System.out.println("Flushed Server"); System.out.println("Flushed NetJump Server");
} lobbyIndex.deleteMany(LobbyIndex);
System.out.println("Flushed Matchmaking Index Server");
public static void TargetDelete(Object ID) { System.out.println("Creating Matchmaking Storage Index...");
BasicDBObject searchQuery = new BasicDBObject(); Document lobbyIndexTemplate = new Document();
searchQuery.append("_id", ID); List<String> lobbyNameList = new ArrayList<>();
dCollection.deleteMany(searchQuery); List<String> lobbyIPList = new ArrayList<>();
System.out.println("Flushed a targeted request (CID) from the server"); List<String> 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) { public static void matchmakingService() {
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() {
Lrequest = dCollection.find(eq("status", false)).first(); Lrequest = dCollection.find(eq("status", false)).first();
if (!(Lrequest == null)) { if (!(Lrequest == null)) {
delegationProcesser(); delegationProcesser();

View File

@ -1,14 +1,16 @@
package com.jamesquinley; 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!) I/O and lobby management backend for new sandbox multiplayer game, go team (Marci and I!)
*/ */
public class Main { public class Main {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
com.jamesquinley.DelegationServices.delegationServices.connectionInit(); com.jamesquinley.DelegationServices.delegationServices.connectionInit();
com.jamesquinley.DelegationServices.delegationServices.Purge(); System.out.println("Connected to NetJump server and Matchmaking Storage Server");
System.out.println("We're starting the login delegation server, please wait one moment while we check a few things."); init();
System.out.println("We've started everything, requests are now being served"); System.out.println("An index has been initialized, matchmaking is now enabled.");
while (true) { while (true) {
isolatedTrigger(); isolatedTrigger();
Thread.sleep(500); Thread.sleep(500);
@ -17,9 +19,9 @@ public class Main {
static void isolatedTrigger() { static void isolatedTrigger() {
try { try {
com.jamesquinley.DelegationServices.delegationServices.userAuthetication(); com.jamesquinley.DelegationServices.delegationServices.matchmakingService();
} catch (Exception e) { } 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);
} }
} }
} }

View File

@ -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<array.length;i++)
{
// System.out.println(array[i]);
//testing for larger fNetLists
}
}
}