Skip to content

Commit f483924

Browse files
committed
Various fixes + Info Server w/ Session Linking
1 parent 80ebc56 commit f483924

File tree

11 files changed

+1182
-63
lines changed

11 files changed

+1182
-63
lines changed

DistanceServer/DistanceServerBaseExternal/Data/DistanceLevel.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class WorkshopLevelRetreiver
8787
{
8888
public List<string> WorkshopLevelIds;
8989
public Coroutine WebCoroutine = null;
90-
public DistanceLevel[] Levels;
90+
public Dictionary<string, DistanceLevel> LevelsByPublishedFileId = new Dictionary<string, DistanceLevel>();
9191
public List<DistanceLevel> ValidLevels = new List<DistanceLevel>();
9292
public string Error = null;
9393
public bool HasError { get { return Error != null; } }
@@ -98,7 +98,6 @@ public WorkshopLevelRetreiver(List<string> workshopLevelIds, bool startCoroutine
9898
{
9999
WorkshopLevelIds = workshopLevelIds;
100100
DefaultGameMode = defaultGameMode;
101-
Levels = new DistanceLevel[0];
102101
if (startCoroutine)
103102
{
104103
StartCoroutine();
@@ -158,8 +157,6 @@ IEnumerator RetrieveLevel()
158157
yield break;
159158
}
160159

161-
Levels = new DistanceLevel[WorkshopLevelIds.Count];
162-
163160
var fileDetails = (object[])response["publishedfiledetails"];
164161
var index = 0;
165162
foreach (var detailBase in fileDetails)
@@ -169,7 +166,22 @@ IEnumerator RetrieveLevel()
169166
{
170167
continue;
171168
}
172-
169+
if (!detail.ContainsKey("publishedfileid") || detail["publishedfileid"].GetType() != typeof(string) || (string)detail["publishedfileid"] == string.Empty)
170+
{
171+
continue;
172+
}
173+
if (detail["title"].GetType() != typeof(string))
174+
{
175+
continue;
176+
}
177+
if (detail["creator"].GetType() != typeof(string) || (string)detail["creator"] == string.Empty)
178+
{
179+
continue;
180+
}
181+
if (detail["filename"].GetType() != typeof(string) || (string)detail["filename"] == "")
182+
{
183+
continue;
184+
}
173185
string levelVersion = "";
174186
if (detail.ContainsKey("time_updated"))
175187
{
@@ -190,18 +202,18 @@ IEnumerator RetrieveLevel()
190202
}
191203
}
192204
}
193-
194-
Levels[index] = new DistanceLevel()
205+
var level = new DistanceLevel()
195206
{
196207
Name = (string)detail["title"],
197208
RelativeLevelPath = $"WorkshopLevels/{(string)detail["creator"]}/{(string)detail["filename"]}",
198209
// Example: "WorkshopLevels/76561198145035078/a digital frontier.bytes"
199210
LevelVersion = levelVersion,
200-
WorkshopFileId = WorkshopLevelIds[index],
211+
WorkshopFileId = (string)detail["publishedfileid"],
201212
GameMode = DefaultGameMode,
202213
SupportedModes = supportedModes.ToArray(),
203214
};
204-
ValidLevels.Add(Levels[index]);
215+
ValidLevels.Add(level);
216+
LevelsByPublishedFileId.Add(level.WorkshopFileId, level);
205217
index++;
206218
}
207219
Finished = true;

DistanceServer/DistanceServerBaseExternal/DistanceServer.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public string MasterServerGameModeOverride
8686
}
8787
}
8888

89-
int distanceVersion = Distance::SVNRevision.number_; // Last known good: 6703
89+
int distanceVersion = Distance::SVNRevision.number_; // Last known good: 6842
9090
public int DistanceVersion
9191
{
9292
get
@@ -360,7 +360,7 @@ public void Update()
360360
{
361361
AttemptToStartLevel();
362362
}
363-
else if (StartingMode && StartingModeTime != -1.0 && Network.time - StartingModeTime >= StartingModeTimeout)
363+
else if (StartingMode && StartingModeTime != -1.0 && Network.time - StartingModeTime >= StartingModeTimeout && !StartingModeDelay)
364364
{
365365
AttemptToStartMode();
366366
}
@@ -570,6 +570,7 @@ public bool AttemptToStartLevel()
570570
}
571571

572572
public bool StartingMode = false;
573+
public bool StartingModeDelay = false;
573574
public double StartingModeTime = -1.0;
574575
public double StartingModeTimeout = 30.0;
575576
public LocalEventEmpty OnModeStartedEvent = new LocalEventEmpty();
@@ -585,14 +586,21 @@ public void AttemptToStartMode()
585586
}
586587
}
587588
}
588-
else
589+
StartingModeDelay = true;
590+
// StartModeAfterDelay is a fix for the mode sometimes starting so early that the loading screen won't disappear
591+
DistanceServerMainStarter.Instance.StartCoroutine(StartModeAfterDelay(5.0f));
592+
}
593+
594+
public System.Collections.IEnumerator StartModeAfterDelay(float delayTime)
595+
{
596+
StartingMode = false;
597+
StartingModeDelay = false;
598+
599+
foreach (var player in ValidPlayers)
589600
{
590-
foreach (var player in ValidPlayers)
601+
if (!player.HasLoadedLevel(true))
591602
{
592-
if (!player.HasLoadedLevel(true))
593-
{
594-
player.Stuck = true;
595-
}
603+
player.Stuck = true;
596604
}
597605
}
598606
foreach (var player in ValidPlayers)
@@ -602,10 +610,12 @@ public void AttemptToStartMode()
602610
player.State = DistancePlayer.PlayerState.StartedMode;
603611
}
604612
}
605-
ModeStartTime = Network.time + 6.0; // TODO: figure out proper time values
613+
614+
ModeStartTime = Network.time + 12.0; // Shift start sooner/later
606615
ModeTimeOffset = -ModeStartTime;
607616
HasModeStarted = true;
608-
StartingMode = false;
617+
618+
yield return new WaitForSeconds(delayTime);
609619
foreach (var player in ValidPlayers)
610620
{
611621
if (player.State == DistancePlayer.PlayerState.StartedMode)

DistanceServer/DistanceServerBaseExternal/DistanceServerMain.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ public override void Awake()
277277
{
278278
Debug.LogError("Using Error to force Unity log to show...");
279279
ExecutableDirectory = new System.IO.DirectoryInfo(UnityEngine.Application.dataPath).Parent;
280+
Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
281+
Debug.unityLogger.filterLogType = LogType.Log;
280282
ServerDirectory = ExecutableDirectory;
281283
var launchArgs = Environment.GetCommandLineArgs();
282284
if (launchArgs.Length > 0)

DistanceServer/PluginProjects/BasicAutoServer/BasicAutoServer.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ public class BasicAutoServer : DistanceServerPlugin
1616
public override int Priority => -5;
1717
public override SemanticVersion ServerVersion => new SemanticVersion("0.1.3");
1818

19-
enum Stage
19+
public enum Stage
2020
{
2121
Starting,
2222
Started,
2323
Timeout,
2424
AllFinished,
2525
}
2626

27-
int currentLevelIndex = 0;
28-
Stage stage = 0;
27+
public int currentLevelIndex = 0;
28+
public Stage stage = 0;
2929

3030
double allFinishedAt = 0;
3131

3232
///
3333

34-
List<DistanceLevel> OverridePlaylist = new List<DistanceLevel>();
34+
public List<DistanceLevel> OverridePlaylist = new List<DistanceLevel>();
3535

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

5252
///
5353

54+
public delegate string GetLinkCode(DistancePlayer player);
55+
56+
public GetLinkCode LinkCodeGetter = null;
57+
58+
///
59+
5460
string MasterServerGameModeOverride = null;
5561
string ServerName = "Auto Server";
5662
int MaxPlayers = 24;
5763
int Port = 45671;
5864
bool ReportToMasterServer = true;
5965

6066
bool LoadWorkshopLevels = false;
61-
double IdleTimeout = 60;
62-
double LevelTimeout = 7 * 60;
63-
string WelcomeMessage = null;
67+
public double IdleTimeout = 60;
68+
public double LevelTimeout = 7 * 60;
69+
public string WelcomeMessage = null;
6470

65-
List<DistanceLevel> Playlist;
71+
public List<DistanceLevel> Playlist;
6672

6773
public void ReadSettings()
6874
{
@@ -145,16 +151,22 @@ public override void Start()
145151
{
146152
Server.OnPlayerValidatedEvent.Connect(player =>
147153
{
154+
var message = WelcomeMessage;
155+
message = message.Replace("$player", player.Name);
156+
if (message.Contains("$linkcode") && LinkCodeGetter != null)
157+
{
158+
message.Replace("$linkcode", LinkCodeGetter(player));
159+
}
148160
if (!Server.HasModeStarted || player.Car != null)
149161
{
150-
Server.SayLocalChatMessage(player.UnityPlayer, WelcomeMessage.Replace("$player", player.Name));
162+
Server.SayLocalChatMessage(player.UnityPlayer, message);
151163
}
152164
else
153165
{
154166
LocalEvent<DistanceCar>.EventConnection connection = null;
155167
connection = player.OnCarAddedEvent.Connect(car =>
156168
{
157-
Server.SayLocalChatMessage(player.UnityPlayer, WelcomeMessage.Replace("$player", player.Name));
169+
Server.SayLocalChatMessage(player.UnityPlayer, message);
158170
connection.Disconnect();
159171
});
160172
}
@@ -216,18 +228,21 @@ void StartAutoServer()
216228

217229
System.Collections.IEnumerator DoLoadWorkshopLevels()
218230
{
219-
Server.SayChatMessage(true, "Generating playlist from Steam Workshop...");
220-
yield return DistanceServerMainStarter.Instance.StartCoroutine(UpdatePlaylist());
231+
// Start players on campaign maps while the workshop maps load
221232
StartAutoServer();
222233
NextLevel();
234+
Server.SayChatMessage(true, "Generating playlist from Steam Workshop...");
223235
Server.OnLevelStartInitiatedEvent.Connect(() =>
224236
{
225237
if (currentLevelIndex == Playlist.Count - 1)
226238
{
227-
// update playlist on last level
239+
// Update the playlist on the last level
228240
DistanceServerMainStarter.Instance.StartCoroutine(UpdatePlaylist());
229241
}
230242
});
243+
// Load maps, but don't wait on them to finish -- it might error!
244+
DistanceServerMainStarter.Instance.StartCoroutine(UpdatePlaylist());
245+
yield break;
231246
}
232247

233248
void AttemptToAdvanceLevel()

DistanceServer/PluginProjects/HttpConsole/ThreadWorker.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ public void Respond(ThreadTask<T>.ThreadTaskDelegate messageDelegate)
141141
}
142142
task = Tasks.Dequeue();
143143
}
144-
Log.Debug("Responding to task");
145144
task.Respond(messageDelegate);
146145
if (task.State == ThreadTask<T>.ThreadTaskState.Error)
147146
{
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>

0 commit comments

Comments
 (0)