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); } }
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); } }
public static bool addNewBan(string username, string uuid, string ipaddress, int timeBanned, string admin, int expiry, string reason) { string[] args = new string[8]; args[0] = nextBanID.ToString(); args[1] = username; args[2] = uuid; args[3] = ipaddress; args[4] = timeBanned.ToString(); args[5] = admin; args[6] = expiry.ToString(); args[7] = reason; try { Ban ban = new Ban(nextBanID, username, uuid, ipaddress, timeBanned, admin, expiry, reason); allBans.Add(nextBanID, ban); Write(Path.Combine(StarryboundServer.SavePath, "bans.json")); nextBanID++; } catch (Exception e) { StarryboundServer.logException("Unable to write ban to banned-players.txt: " + e.Message); return false; } return true; }
public static bool addNewBan(string username, string uuid, string ipaddress, int timeBanned, string admin, int expiry, string reason) { string[] args = new string[8]; args[0] = nextBanID.ToString(); args[1] = username; args[2] = uuid; args[3] = ipaddress; args[4] = timeBanned.ToString(); args[5] = admin; args[6] = expiry.ToString(); args[7] = reason; try { FileStream fs = new FileStream(Path.Combine(StarryboundServer.SavePath, "banned-players.txt"), FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(String.Join("|", args)); sw.Flush(); sw.Close(); Ban ban = new Ban(nextBanID, username, uuid, ipaddress, timeBanned, admin, expiry, reason); allBans.Add(nextBanID, ban); nextBanID++; } catch (Exception e) { StarryboundServer.logException("Unable to write ban to banned-players.txt: " + e.Message); return false; } return true; }