SERVER UPDATE: Matchmaking V1.1
ADDS LOBBY CREATION TWEAKS TO REQUEST DELETION TIMING BUGFIXES
This commit is contained in:
parent
5931909fbe
commit
dee6fdbf95
@ -5,10 +5,12 @@ import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
|
||||
import javax.print.Doc;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -66,7 +68,7 @@ public class delegationServices {
|
||||
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)
|
||||
6 - Return de-listing result (return status is deleted:true;false)
|
||||
*/
|
||||
|
||||
public static void delegationProcesser() {
|
||||
@ -79,7 +81,7 @@ public class delegationServices {
|
||||
}
|
||||
int request = (int) Lrequest.get("type");
|
||||
if (request == 1 || request == 3) {
|
||||
if (request ==1 ) {
|
||||
if (request == 1 ) {
|
||||
List<String> lobbyNameList = new ArrayList<>();
|
||||
List<String> lobbyIPList = new ArrayList<>();
|
||||
List<String> lobbyKeyList = new ArrayList<>();
|
||||
@ -132,6 +134,126 @@ public class delegationServices {
|
||||
DeleteTargetRequestByID(ClientID);
|
||||
}
|
||||
}
|
||||
if (request == 3 ) {
|
||||
Document index = new Document();
|
||||
index = lobbyIndex.find(eq("indexref", "ocs_matchmakingidx")).first();
|
||||
List<String> lobbyNameList = new ArrayList<>();
|
||||
List<String> lobbyIPList = new ArrayList<>();
|
||||
List<String> lobbyKeyList = new ArrayList<>();
|
||||
List<String> lobbyVersion = new ArrayList<>();
|
||||
String lobbyPostName = new String();
|
||||
String lobbyPostIP = new String();
|
||||
String lobbyPostVersion = new String();
|
||||
String privateKeyNew = new String();
|
||||
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
boolean genStatus = false;
|
||||
BasicDBObject requestModifier = new BasicDBObject();
|
||||
requestModifier.append("indexref", "ocs_matchmakingidx");
|
||||
BasicDBObject userRequestModifier = new BasicDBObject();
|
||||
userRequestModifier.append("_id", ClientID);
|
||||
//Define Variables ^
|
||||
lobbyNameList = (List<String>) index.get("LobbyName");
|
||||
lobbyIPList = (List<String>) index.get("LobbyIP");
|
||||
lobbyKeyList = (List<String>) index.get("LobbyPrivateKey");
|
||||
lobbyVersion = (List<String>) index.get("LobbyVersion");
|
||||
lobbyPostName = (String) Lrequest.get("LobbyName");
|
||||
lobbyPostIP = (String) Lrequest.get("LobbyIP");
|
||||
lobbyPostVersion = (String) Lrequest.get("LobbyVersion");
|
||||
BasicDBObject keyUpdate = new BasicDBObject();
|
||||
BasicDBObject nameUpdate = new BasicDBObject();
|
||||
BasicDBObject ipUpdate = new BasicDBObject();
|
||||
BasicDBObject versionUpdate = new BasicDBObject();
|
||||
BasicDBObject updateQuery = new BasicDBObject();
|
||||
BasicDBObject nameReturn = new BasicDBObject();
|
||||
BasicDBObject privateKey = new BasicDBObject();
|
||||
BasicDBObject lobbyPostPermissionResponse = new BasicDBObject();
|
||||
BasicDBObject statusUpdate = new BasicDBObject();
|
||||
if (!lobbyNameList.contains(lobbyPostName)) {
|
||||
//Get existing lobby information from the index service, use these to append later ^
|
||||
while (genStatus == false) {
|
||||
int length = 50;
|
||||
for (int i = 0; i < length; i++) {
|
||||
int idIndex = random.nextInt(alphabet.length());
|
||||
char randomChar = alphabet.charAt(idIndex);
|
||||
sb.append(randomChar);
|
||||
}
|
||||
privateKeyNew = sb.toString();
|
||||
if (!lobbyKeyList.contains(privateKeyNew)) {
|
||||
genStatus = true;
|
||||
}
|
||||
}
|
||||
//Generate the "private key" which is used to de-list via client request
|
||||
lobbyKeyList.add(privateKeyNew);
|
||||
lobbyIPList.add(lobbyPostIP);
|
||||
lobbyNameList.add(lobbyPostName);
|
||||
lobbyVersion.add(lobbyPostVersion);
|
||||
keyUpdate.append("$set",
|
||||
new BasicDBObject().append("LobbyPrivateKey", lobbyKeyList));
|
||||
ipUpdate.append("$set",
|
||||
new BasicDBObject().append("LobbyIP", lobbyIPList));
|
||||
nameUpdate.append("$set",
|
||||
new BasicDBObject().append("LobbyName", lobbyNameList));
|
||||
versionUpdate.append("$set",
|
||||
new BasicDBObject().append("LobbyVersion", lobbyVersion));
|
||||
if (lobbyKeyList.stream().count() == lobbyNameList.stream().count() && lobbyVersion.stream().count() == lobbyIPList.stream().count()) {
|
||||
lobbyIndex.updateOne(requestModifier,keyUpdate);
|
||||
lobbyIndex.updateOne(requestModifier,ipUpdate);
|
||||
lobbyIndex.updateOne(requestModifier,nameUpdate);
|
||||
lobbyIndex.updateOne(requestModifier,versionUpdate);
|
||||
//Indexes match up, send new index
|
||||
updateQuery.append("$set",
|
||||
new BasicDBObject().append("type", 4));
|
||||
nameReturn.append("$set",
|
||||
new BasicDBObject().append("lobbyName", lobbyPostName));
|
||||
privateKey.append("$set",
|
||||
new BasicDBObject().append("lobbySecret", privateKeyNew));
|
||||
lobbyPostPermissionResponse.append("$set",
|
||||
new BasicDBObject().append("lobbyPosted", true));
|
||||
statusUpdate.append("$set",
|
||||
new BasicDBObject().append("status", true));
|
||||
dCollection.updateOne(userRequestModifier, updateQuery);
|
||||
dCollection.updateOne(userRequestModifier, nameReturn);
|
||||
dCollection.updateOne(userRequestModifier, privateKey);
|
||||
dCollection.updateOne(userRequestModifier,lobbyPostPermissionResponse);
|
||||
dCollection.updateOne(userRequestModifier, statusUpdate);
|
||||
DeleteTargetRequestByID(ClientID);
|
||||
} else {
|
||||
buildIndex();
|
||||
updateQuery.append("$set",
|
||||
new BasicDBObject().append("type", 4));
|
||||
nameReturn.append("$set",
|
||||
new BasicDBObject().append("info", "The index failed to verify and has been reset, please try again."));
|
||||
lobbyPostPermissionResponse.append("$set",
|
||||
new BasicDBObject().append("lobbyPosted", false));
|
||||
statusUpdate.append("$set",
|
||||
new BasicDBObject().append("status", true));
|
||||
dCollection.updateOne(userRequestModifier, updateQuery);
|
||||
dCollection.updateOne(userRequestModifier, nameReturn);
|
||||
dCollection.updateOne(userRequestModifier,lobbyPostPermissionResponse);
|
||||
dCollection.updateOne(userRequestModifier, statusUpdate);
|
||||
DeleteTargetRequestByID(ClientID);
|
||||
//Something went wrong, the indexes don't match up, reinitialize the index, send client error
|
||||
}
|
||||
|
||||
//Send new index to server before sending response "Good" or "Bad" (if something fails) ^
|
||||
} else {
|
||||
updateQuery.append("$set",
|
||||
new BasicDBObject().append("type", 4));
|
||||
nameReturn.append("$set",
|
||||
new BasicDBObject().append("info", "This lobby name already exists."));
|
||||
lobbyPostPermissionResponse.append("$set",
|
||||
new BasicDBObject().append("lobbyPosted", false));
|
||||
statusUpdate.append("$set",
|
||||
new BasicDBObject().append("status", true));
|
||||
dCollection.updateOne(userRequestModifier, updateQuery);
|
||||
dCollection.updateOne(userRequestModifier, nameReturn);
|
||||
dCollection.updateOne(userRequestModifier,lobbyPostPermissionResponse);
|
||||
dCollection.updateOne(userRequestModifier, statusUpdate);
|
||||
DeleteTargetRequestByID(ClientID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void DeleteTargetRequestByID (Object ID)
|
||||
@ -153,7 +275,7 @@ public class delegationServices {
|
||||
};
|
||||
scheduler.scheduleAtFixedRate(runnable, 0, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
public static void init() {
|
||||
public static void buildIndex() {
|
||||
BasicDBObject searchQueryT = new BasicDBObject();
|
||||
BasicDBObject searchQueryF = new BasicDBObject();
|
||||
BasicDBObject LobbyIndex = new BasicDBObject();
|
||||
@ -170,12 +292,15 @@ public class delegationServices {
|
||||
List<String> lobbyNameList = new ArrayList<>();
|
||||
List<String> lobbyIPList = new ArrayList<>();
|
||||
List<String> lobbyKeyList = new ArrayList<>();
|
||||
List<String> lobbyVersionList = new ArrayList<>();
|
||||
lobbyNameList.add("startatone");
|
||||
lobbyIPList.add("startatone");
|
||||
lobbyKeyList.add("startatone");
|
||||
lobbyVersionList.add("startatone");
|
||||
lobbyIndexTemplate.append("LobbyName",lobbyNameList);
|
||||
lobbyIndexTemplate.append("LobbyIP", lobbyIPList);
|
||||
lobbyIndexTemplate.append("LobbyPrivateKey",lobbyKeyList);
|
||||
lobbyIndexTemplate.append("LobbyVersion",lobbyVersionList);
|
||||
lobbyIndexTemplate.append("indexref", "ocs_matchmakingidx");
|
||||
lobbyIndex.insertOne(lobbyIndexTemplate);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.jamesquinley;
|
||||
|
||||
import static com.jamesquinley.DelegationServices.delegationServices.init;
|
||||
import static com.jamesquinley.DelegationServices.delegationServices.buildIndex;
|
||||
|
||||
/**
|
||||
I/O and lobby management backend for new sandbox multiplayer game, go team (Marci and I!)
|
||||
@ -9,7 +9,7 @@ public class Main {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
com.jamesquinley.DelegationServices.delegationServices.connectionInit();
|
||||
System.out.println("Connected to NetJump server and Matchmaking Storage Server");
|
||||
init();
|
||||
buildIndex();
|
||||
System.out.println("An index has been initialized, matchmaking is now enabled.");
|
||||
while (true) {
|
||||
isolatedTrigger();
|
||||
|
Loading…
x
Reference in New Issue
Block a user