Skip to content

Commit

Permalink
Various fixes + Info Server w/ Session Linking
Browse files Browse the repository at this point in the history
  • Loading branch information
Corecii committed Aug 1, 2019
1 parent 80ebc56 commit f483924
Show file tree
Hide file tree
Showing 11 changed files with 1,182 additions and 63 deletions.
30 changes: 21 additions & 9 deletions DistanceServer/DistanceServerBaseExternal/Data/DistanceLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class WorkshopLevelRetreiver
{
public List<string> WorkshopLevelIds;
public Coroutine WebCoroutine = null;
public DistanceLevel[] Levels;
public Dictionary<string, DistanceLevel> LevelsByPublishedFileId = new Dictionary<string, DistanceLevel>();
public List<DistanceLevel> ValidLevels = new List<DistanceLevel>();
public string Error = null;
public bool HasError { get { return Error != null; } }
Expand All @@ -98,7 +98,6 @@ public WorkshopLevelRetreiver(List<string> workshopLevelIds, bool startCoroutine
{
WorkshopLevelIds = workshopLevelIds;
DefaultGameMode = defaultGameMode;
Levels = new DistanceLevel[0];
if (startCoroutine)
{
StartCoroutine();
Expand Down Expand Up @@ -158,8 +157,6 @@ IEnumerator RetrieveLevel()
yield break;
}

Levels = new DistanceLevel[WorkshopLevelIds.Count];

var fileDetails = (object[])response["publishedfiledetails"];
var index = 0;
foreach (var detailBase in fileDetails)
Expand All @@ -169,7 +166,22 @@ IEnumerator RetrieveLevel()
{
continue;
}

if (!detail.ContainsKey("publishedfileid") || detail["publishedfileid"].GetType() != typeof(string) || (string)detail["publishedfileid"] == string.Empty)
{
continue;
}
if (detail["title"].GetType() != typeof(string))
{
continue;
}
if (detail["creator"].GetType() != typeof(string) || (string)detail["creator"] == string.Empty)
{
continue;
}
if (detail["filename"].GetType() != typeof(string) || (string)detail["filename"] == "")
{
continue;
}
string levelVersion = "";
if (detail.ContainsKey("time_updated"))
{
Expand All @@ -190,18 +202,18 @@ IEnumerator RetrieveLevel()
}
}
}

Levels[index] = new DistanceLevel()
var level = new DistanceLevel()
{
Name = (string)detail["title"],
RelativeLevelPath = $"WorkshopLevels/{(string)detail["creator"]}/{(string)detail["filename"]}",
// Example: "WorkshopLevels/76561198145035078/a digital frontier.bytes"
LevelVersion = levelVersion,
WorkshopFileId = WorkshopLevelIds[index],
WorkshopFileId = (string)detail["publishedfileid"],
GameMode = DefaultGameMode,
SupportedModes = supportedModes.ToArray(),
};
ValidLevels.Add(Levels[index]);
ValidLevels.Add(level);
LevelsByPublishedFileId.Add(level.WorkshopFileId, level);
index++;
}
Finished = true;
Expand Down
30 changes: 20 additions & 10 deletions DistanceServer/DistanceServerBaseExternal/DistanceServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public string MasterServerGameModeOverride
}
}

int distanceVersion = Distance::SVNRevision.number_; // Last known good: 6703
int distanceVersion = Distance::SVNRevision.number_; // Last known good: 6842
public int DistanceVersion
{
get
Expand Down Expand Up @@ -360,7 +360,7 @@ public void Update()
{
AttemptToStartLevel();
}
else if (StartingMode && StartingModeTime != -1.0 && Network.time - StartingModeTime >= StartingModeTimeout)
else if (StartingMode && StartingModeTime != -1.0 && Network.time - StartingModeTime >= StartingModeTimeout && !StartingModeDelay)
{
AttemptToStartMode();
}
Expand Down Expand Up @@ -570,6 +570,7 @@ public bool AttemptToStartLevel()
}

public bool StartingMode = false;
public bool StartingModeDelay = false;
public double StartingModeTime = -1.0;
public double StartingModeTimeout = 30.0;
public LocalEventEmpty OnModeStartedEvent = new LocalEventEmpty();
Expand All @@ -585,14 +586,21 @@ public void AttemptToStartMode()
}
}
}
else
StartingModeDelay = true;
// StartModeAfterDelay is a fix for the mode sometimes starting so early that the loading screen won't disappear
DistanceServerMainStarter.Instance.StartCoroutine(StartModeAfterDelay(5.0f));
}

public System.Collections.IEnumerator StartModeAfterDelay(float delayTime)
{
StartingMode = false;
StartingModeDelay = false;

foreach (var player in ValidPlayers)
{
foreach (var player in ValidPlayers)
if (!player.HasLoadedLevel(true))
{
if (!player.HasLoadedLevel(true))
{
player.Stuck = true;
}
player.Stuck = true;
}
}
foreach (var player in ValidPlayers)
Expand All @@ -602,10 +610,12 @@ public void AttemptToStartMode()
player.State = DistancePlayer.PlayerState.StartedMode;
}
}
ModeStartTime = Network.time + 6.0; // TODO: figure out proper time values

ModeStartTime = Network.time + 12.0; // Shift start sooner/later
ModeTimeOffset = -ModeStartTime;
HasModeStarted = true;
StartingMode = false;

yield return new WaitForSeconds(delayTime);
foreach (var player in ValidPlayers)
{
if (player.State == DistancePlayer.PlayerState.StartedMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ public override void Awake()
{
Debug.LogError("Using Error to force Unity log to show...");
ExecutableDirectory = new System.IO.DirectoryInfo(UnityEngine.Application.dataPath).Parent;
Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
Debug.unityLogger.filterLogType = LogType.Log;
ServerDirectory = ExecutableDirectory;
var launchArgs = Environment.GetCommandLineArgs();
if (launchArgs.Length > 0)
Expand Down
41 changes: 28 additions & 13 deletions DistanceServer/PluginProjects/BasicAutoServer/BasicAutoServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ public class BasicAutoServer : DistanceServerPlugin
public override int Priority => -5;
public override SemanticVersion ServerVersion => new SemanticVersion("0.1.3");

enum Stage
public enum Stage
{
Starting,
Started,
Timeout,
AllFinished,
}

int currentLevelIndex = 0;
Stage stage = 0;
public int currentLevelIndex = 0;
public Stage stage = 0;

double allFinishedAt = 0;

///

List<DistanceLevel> OverridePlaylist = new List<DistanceLevel>();
public List<DistanceLevel> OverridePlaylist = new List<DistanceLevel>();

public delegate bool FilterWorkshopSearchDelegate(List<DistanceSearchResultItem> results);
List<FilterWorkshopSearchDelegate> Filters = new List<FilterWorkshopSearchDelegate>();
Expand All @@ -51,18 +51,24 @@ public bool FilterWorkshopLevels(List<DistanceSearchResultItem> results)

///

public delegate string GetLinkCode(DistancePlayer player);

public GetLinkCode LinkCodeGetter = null;

///

string MasterServerGameModeOverride = null;
string ServerName = "Auto Server";
int MaxPlayers = 24;
int Port = 45671;
bool ReportToMasterServer = true;

bool LoadWorkshopLevels = false;
double IdleTimeout = 60;
double LevelTimeout = 7 * 60;
string WelcomeMessage = null;
public double IdleTimeout = 60;
public double LevelTimeout = 7 * 60;
public string WelcomeMessage = null;

List<DistanceLevel> Playlist;
public List<DistanceLevel> Playlist;

public void ReadSettings()
{
Expand Down Expand Up @@ -145,16 +151,22 @@ public override void Start()
{
Server.OnPlayerValidatedEvent.Connect(player =>
{
var message = WelcomeMessage;
message = message.Replace("$player", player.Name);
if (message.Contains("$linkcode") && LinkCodeGetter != null)
{
message.Replace("$linkcode", LinkCodeGetter(player));
}
if (!Server.HasModeStarted || player.Car != null)
{
Server.SayLocalChatMessage(player.UnityPlayer, WelcomeMessage.Replace("$player", player.Name));
Server.SayLocalChatMessage(player.UnityPlayer, message);
}
else
{
LocalEvent<DistanceCar>.EventConnection connection = null;
connection = player.OnCarAddedEvent.Connect(car =>
{
Server.SayLocalChatMessage(player.UnityPlayer, WelcomeMessage.Replace("$player", player.Name));
Server.SayLocalChatMessage(player.UnityPlayer, message);
connection.Disconnect();
});
}
Expand Down Expand Up @@ -216,18 +228,21 @@ void StartAutoServer()

System.Collections.IEnumerator DoLoadWorkshopLevels()
{
Server.SayChatMessage(true, "Generating playlist from Steam Workshop...");
yield return DistanceServerMainStarter.Instance.StartCoroutine(UpdatePlaylist());
// Start players on campaign maps while the workshop maps load
StartAutoServer();
NextLevel();
Server.SayChatMessage(true, "Generating playlist from Steam Workshop...");
Server.OnLevelStartInitiatedEvent.Connect(() =>
{
if (currentLevelIndex == Playlist.Count - 1)
{
// update playlist on last level
// Update the playlist on the last level
DistanceServerMainStarter.Instance.StartCoroutine(UpdatePlaylist());
}
});
// Load maps, but don't wait on them to finish -- it might error!
DistanceServerMainStarter.Instance.StartCoroutine(UpdatePlaylist());
yield break;
}

void AttemptToAdvanceLevel()
Expand Down
1 change: 0 additions & 1 deletion DistanceServer/PluginProjects/HttpConsole/ThreadWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public void Respond(ThreadTask<T>.ThreadTaskDelegate messageDelegate)
}
task = Tasks.Dequeue();
}
Log.Debug("Responding to task");
task.Respond(messageDelegate);
if (task.State == ThreadTask<T>.ThreadTaskState.Error)
{
Expand Down
6 changes: 6 additions & 0 deletions DistanceServer/PluginProjects/HttpInfoServer/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
Loading

0 comments on commit f483924

Please sign in to comment.