Skip to content

Commit

Permalink
Fix map loading on client side
Browse files Browse the repository at this point in the history
Fix server ports to work
Fix server browser
  • Loading branch information
silentbaws committed Jun 17, 2020
1 parent 35c355b commit c77a719
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
18 changes: 12 additions & 6 deletions XLMultiplayer/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class Main {
public static MethodInfo ModMenuGUIPrefix = null;
public static bool patched = false;

public static float lastConnect = 0f;

static void Load(UnityModManager.ModEntry modEntry) {
settings = MultiplayerSettings.Load<MultiplayerSettings>(modEntry);
Main.modEntry = modEntry;
Expand Down Expand Up @@ -303,11 +305,11 @@ public static IEnumerator StartUpdatingServerList() {
Server newServer = new Server();
foreach (JObject o2 in p.Children<JObject>()) {
foreach (JProperty p2 in o2.Properties()) {
switch (p2.Name) {
switch (p2.Name.ToLower()) {
case "name":
newServer.name = (string)p2.Value;
break;
case "IP":
case "ip":
newServer.ip = (string)p2.Value;
break;
case "port":
Expand All @@ -316,13 +318,13 @@ public static IEnumerator StartUpdatingServerList() {
case "version":
newServer.version = (string)p2.Value;
break;
case "maxPlayers":
case "maxplayers":
newServer.playerMax = (int)p2.Value;
break;
case "currentPlayers":
case "currentplayers":
newServer.playerCurrent = (int)p2.Value;
break;
case "mapName":
case "mapname":
newServer.mapName = (string)p2.Value;
break;
}
Expand All @@ -341,7 +343,11 @@ public static IEnumerator StartUpdatingServerList() {
}

private static void ClickServerItem(ServerListItem target) {
JoinServer(target.ipAddress, target.port, NewMultiplayerMenu.Instance.usernameFields[0].text);
if(Time.realtimeSinceStartup - lastConnect > 1f) {
UnityModManager.Logger.Log($"Attempting to connect to server {target.ServerName.text} with ip {target.ipAddress} port {target.port}");
JoinServer(target.ipAddress, target.port, NewMultiplayerMenu.Instance.usernameFields[0].text);
lastConnect = Time.realtimeSinceStartup;
}
}

private static void OnClickConnect() {
Expand Down
1 change: 1 addition & 0 deletions XLMultiplayer/MultiplayerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ private static void LoadMapHashes() {
files = LevelManager.Instance.CustomLevels.ConvertAll(levelInfo => levelInfo.path);

hashedMaps = files.Count;
loadingMaps = true;

if (files == null || files.Count < 1) {
UnityModManagerNet.UnityModManager.Logger.Log("**WARNING** XLMultiplayer COULD NOT find any maps in " + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\SkaterXL\\Maps\\");
Expand Down
8 changes: 0 additions & 8 deletions XLMultiplayerGUIApp/ServerGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public partial class ServerGUI : Form {
private readonly ContextMenuStrip playerListMenu;
private readonly ContextMenuStrip banListMenu;
Server multiplayerServer;
FileServer fileServer;

public void LogMessageCallbackHandler(string message, ConsoleColor color, params object[] objects) {
if (objects != null && objects.Length > 0)
Expand Down Expand Up @@ -51,15 +50,8 @@ private void ServerGUI_Load(object sender, EventArgs e) {
LogMessage LogMessageCallback = LogMessageCallbackHandler;

multiplayerServer = new Server(LogMessageCallback, LogChatMessageCallback);
fileServer = new FileServer(multiplayerServer);

multiplayerServer.fileServer = fileServer;

var serverTask = Task.Run(() => multiplayerServer.ServerLoop());

Thread fileServerThread = new Thread(fileServer.ServerLoop);
fileServerThread.IsBackground = true;
fileServerThread.Start();
}

private void lsbPlayerList_MouseDown(object sender, MouseEventArgs e) {
Expand Down
4 changes: 4 additions & 0 deletions XLMultiplayerServer/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ public void ServerLoop() {
Console.In.Read();
return;
}

Thread fileServerThread = new Thread(fileServer.ServerLoop);
fileServerThread.IsBackground = true;
fileServerThread.Start();

players = new Player[MAX_PLAYERS];

Expand Down
4 changes: 0 additions & 4 deletions XLMultiplayerServerConsoleApp/ConsoleServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public static int Main(String[] args) {

var serverTask = Task.Run(() => multiplayerServer.ServerLoop());

Thread fileServerThread = new Thread(fileServer.ServerLoop);
fileServerThread.IsBackground = true;
fileServerThread.Start();

Task.Run(() => multiplayerServer.CommandLoop());

serverTask.Wait();
Expand Down

0 comments on commit c77a719

Please sign in to comment.