public static void readLegacyBans() { try { StreamReader reader = File.OpenText(Path.Combine(StarryboundServer.SavePath, "banned-players.txt")); string line; int banCount = 0; while ((line = reader.ReadLine()) != null) { string[] args = line.Split('|'); /* * Ban format: * int ID * string Username * string UUID * string IP Address * timestamp UnixTimestamp (Time of Addition) * string Admin * timestamp Expiry * string Reason * * Example: * 2|User|133bfef193364620513ea1980ba39dc3|127.0.0.1|1387767903|Crashdoom|0|Griefing the spawn * */ if (args.Length != 8) { continue; } try { int banID = int.Parse(args[0]); string username = args[1]; string uuid = args[2]; string ipaddress = args[3]; int timeBanned = int.Parse(args[4]); string admin = args[5]; int expiry = int.Parse(args[6]); string reason = args[7]; Ban ban = new Ban(banID, username, uuid, ipaddress, timeBanned, admin, expiry, reason); legacyBans.Add(banID, ban); nextBanID = banID + 1; banCount++; } catch (Exception) { banCount--; StarryboundServer.logWarn("Invalid ban detected in banned-players.txt"); } } reader.Close(); } catch (Exception e) { StarryboundServer.logWarn("Unable to read bans from legacy banned-players.txt: " + e.Message); } }
void parseOutput(string consoleLine) { try { foreach (string line in filterConsole) { if (consoleLine.Contains(line)) { return; } } if (consoleLine.StartsWith("Error: ") || consoleLine.StartsWith("AssetException:")) { this.parseError = true; } else if ((consoleLine.StartsWith("Warn:") || consoleLine.StartsWith("Info:") || consoleLine.StartsWith("Debug:")) && this.parseError) { logStarboundError(" "); this.parseError = false; } else if (String.IsNullOrWhiteSpace(consoleLine) && this.parseError) { logStarboundError(" "); this.parseError = false; return; } if (consoleLine.StartsWith("Warn: Perf: ")) { string[] perf = consoleLine.Remove(0, 12).Split(' '); string function = perf[0]; float millis = Convert.ToSingle(perf[2]); if (millis > 5000) { StarryboundServer.logWarn("Parent Server [" + function + "] lagged for " + (millis / 1000) + " seconds"); } return; } else if (consoleLine.Contains("Info: Server version")) { string[] versionString = consoleLine.Split('\''); string versionName = versionString[1]; int protocolVersion = int.Parse(versionString[3]); StarryboundServer.starboundVersion.Protocol = protocolVersion; StarryboundServer.starboundVersion.Name = versionName; if (protocolVersion != StarryboundServer.ProtocolVersion) { StarryboundServer.logFatal("Detected protcol version [" + protocolVersion + "] != [" + StarryboundServer.ProtocolVersion + "] to expected protocol version!"); Thread.Sleep(5000); Environment.Exit(4); } StarryboundServer.logInfo("Parent Server Version: [" + versionName + "] Protocol: [" + protocolVersion + "]"); return; } else if (consoleLine.Contains("TcpServer will close, listener thread caught exception")) { StarryboundServer.logFatal("Parent Server TcpServer listener thread caught exception, Forcing a restart."); StarryboundServer.changeState(ServerState.Crashed, "ServerThread::parseOutput", "Starbound Tcp listener has crashed"); } else if (consoleLine.Contains("TcpServer listening on: ")) { StarryboundServer.changeState(ServerState.StarboundReady, "ServerThread::parseOutput"); ServerConfig.RemovePrivateConfig(); } else if (consoleLine.StartsWith("Info: Kicking client ")) { string[] kick = consoleLine.Remove(0, 21).Split(' '); string user = kick[0]; string id = kick[1]; string ip = kick[2]; StarryboundServer.logWarn("Parent Server disconnected " + user + " " + ip + " for inactivity."); return; } if (!this.parseError) { Console.WriteLine("[STAR] " + consoleLine); } else { logStarboundError(consoleLine); } } catch (Exception) { } }