Skip to content
This repository was archived by the owner on Sep 5, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class Config
public ushort EndpointPort = 7070;
public bool ShowDebugLogs = false;
public int RandomlyGeneratedIDLength = 5;
public bool RandomlyGeneratedIDNumerical = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ public long GetTotalServers()

return temp;
}

public string GenerateServerID()


public string GenerateServerID(string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
chars = conf.RandomlyGeneratedIDNumerical ? "0123456789" : chars;
var randomID = "";
var random = _cachedRandom;

do
{
randomID = new string(Enumerable.Repeat(chars, conf.RandomlyGeneratedIDLength)
.Select(s => s[random.Next(s.Length)]).ToArray());
.Select(s => s[random.Next(s.Length)])
.ToArray());
}
while (cachedRooms.ContainsKey(randomID));

Expand Down
1 change: 1 addition & 0 deletions ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Config
// this wont be used if you are using load balancer
// load balancer will generate instead.
public int RandomlyGeneratedIDLength = 5;
public bool RandomlyGeneratedIDNumerical = false;

//========================
// Endpoint REST API Settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ public RelayHandler(int maxPacketSize)
/// <param name="id">The ID to check for</param>
/// <returns></returns>
private bool DoesServerIdExist(string id) => _cachedRooms.ContainsKey(id);

private string GenerateRoomID()
private string GenerateRoomID(string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
chars = Program.conf.RandomlyGeneratedIDNumerical ? "0123456789" : chars;
var randomID = "";
var random = _cachedRandom;
var length = Program.conf.RandomlyGeneratedIDLength;

do
{
randomID = new string(Enumerable.Repeat(chars, Program.conf.RandomlyGeneratedIDLength)
.Select(s => s[random.Next(s.Length)]).ToArray());
randomID = new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
}
while (DoesServerIdExist(randomID));

Expand Down