Fix /ls go not working after restart (Thanks CookieNetwork), cleanup lava survival property loading.

This commit is contained in:
UnknownShadow200 2016-08-28 14:44:38 +10:00
parent fef2aa5457
commit 9e9d369c71

View File

@ -1,180 +1,137 @@
/*
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Timers;
using System;
using System.IO;
using System.Timers;
namespace MCGalaxy.Games
{
public sealed partial class LavaSurvival
{
namespace MCGalaxy.Games {
public sealed partial class LavaSurvival {
public MapData GenerateMapData(MapSettings settings)
{
public MapData GenerateMapData(MapSettings settings) {
MapData data = new MapData(settings);
data.killer = rand.Next(1, 101) <= settings.killer;
data.destroy = rand.Next(1, 101) <= settings.destroy;
data.water = rand.Next(1, 101) <= settings.water;
data.layer = rand.Next(1, 101) <= settings.layer;
data.fast = rand.Next(1, 101) <= settings.fast && !data.water;
data.block = data.water ? (data.killer ? Block.activedeathwater : Block.water) : (data.fast ? (data.killer ? Block.fastdeathlava : Block.lava_fast) : (data.killer ? Block.activedeathlava : Block.lava));
data.block = data.water ? (data.killer ? Block.activedeathwater : Block.water)
: (data.fast ? (data.killer ? Block.fastdeathlava : Block.lava_fast)
: (data.killer ? Block.activedeathlava : Block.lava));
return data;
}
public void LoadSettings()
{
if (!File.Exists("properties/lavasurvival.properties"))
{
SaveSettings();
return;
}
public void LoadSettings() {
if (!File.Exists("properties/lavasurvival.properties")) { SaveSettings(); return; }
foreach (string line in File.ReadAllLines("properties/lavasurvival.properties"))
{
try
{
if (line[0] != '#')
{
string value = line.Substring(line.IndexOf(" = ") + 3);
switch (line.Substring(0, line.IndexOf(" = ")).ToLower())
{
case "start-on-startup":
startOnStartup = bool.Parse(value);
break;
case "send-afk-to-main":
sendAfkMain = bool.Parse(value);
break;
case "vote-count":
voteCount = (byte)Utils.Clamp(decimal.Parse(value), 2, 10);
break;
case "vote-time":
voteTime = double.Parse(value);
break;
case "lives":
lifeNum = int.Parse(value);
break;
case "setup-rank":
if (Group.Find(value.ToLower()) != null)
setupRank = Group.Find(value.ToLower()).Permission;
break;
case "control-rank":
if (Group.Find(value.ToLower()) != null)
controlRank = Group.Find(value.ToLower()).Permission;
break;
case "maps":
foreach (string mapname in value.Split(','))
if(!String.IsNullOrEmpty(mapname) && !maps.Contains(mapname)) maps.Add(mapname);
break;
}
}
}
catch (Exception e) { Server.ErrorLog(e); }
try {
PropertiesFile.Read("properties/lavasurvival.properties", ProcessSettingsLine);
} catch (Exception e) {
Server.ErrorLog(e);
}
}
public void SaveSettings()
{
void ProcessSettingsLine(string key, string value) {
switch (key.ToLower()) {
case "start-on-startup": startOnStartup = bool.Parse(value); break;
case "send-afk-to-main": sendAfkMain = bool.Parse(value); break;
case "vote-count": voteCount = (byte)Utils.Clamp(decimal.Parse(value), 2, 10); break;
case "vote-time": voteTime = double.Parse(value); break;
case "lives": lifeNum = int.Parse(value); break;
case "setup-rank":
if (Group.Find(value) != null)
setupRank = Group.Find(value).Permission;
break;
case "control-rank":
if (Group.Find(value) != null)
controlRank = Group.Find(value).Permission;
break;
case "maps":
foreach (string name in value.Split(',')) {
string map = name.Trim();
if (map != "" && !maps.Contains(map))
maps.Add(map);
}
break;
}
}
public void SaveSettings() {
using (StreamWriter w = new StreamWriter("properties/lavasurvival.properties")) {
w.WriteLine("#Lava Survival main properties");
w.WriteLine("start-on-startup = " + startOnStartup.ToString().ToLower());
w.WriteLine("send-afk-to-main = " + sendAfkMain.ToString().ToLower());
w.WriteLine("vote-count = " + voteCount.ToString());
w.WriteLine("vote-time = " + voteTime.ToString());
w.WriteLine("lives = " + lifeNum.ToString());
w.WriteLine("setup-rank = " + Level.PermissionToName(setupRank).ToLower());
w.WriteLine("control-rank = " + Level.PermissionToName(controlRank).ToLower());
w.WriteLine("start-on-startup = " + startOnStartup);
w.WriteLine("send-afk-to-main = " + sendAfkMain);
w.WriteLine("vote-count = " + voteCount);
w.WriteLine("vote-time = " + voteTime);
w.WriteLine("lives = " + lifeNum);
w.WriteLine("setup-rank = " + Level.PermissionToName(setupRank));
w.WriteLine("control-rank = " + Level.PermissionToName(controlRank));
w.WriteLine("maps = " + maps.Join());
}
}
public MapSettings LoadMapSettings(string name)
{
public MapSettings LoadMapSettings(string name) {
MapSettings settings = new MapSettings(name);
if (!Directory.Exists(propsPath)) Directory.CreateDirectory(propsPath);
if (!File.Exists(propsPath + name + ".properties"))
{
SaveMapSettings(settings);
return settings;
}
string path = propsPath + name + ".properties";
if (!File.Exists(path)) { SaveMapSettings(settings); return settings; }
foreach (string line in File.ReadAllLines(propsPath + name + ".properties"))
{
try
{
if (line[0] != '#')
{
string[] sp;
string value = line.Substring(line.IndexOf(" = ") + 3);
switch (line.Substring(0, line.IndexOf(" = ")).ToLower())
{
case "fast-chance":
settings.fast = (byte)Utils.Clamp(decimal.Parse(value), 0, 100);
break;
case "killer-chance":
settings.killer = (byte)Utils.Clamp(decimal.Parse(value), 0, 100);
break;
case "destroy-chance":
settings.destroy = (byte)Utils.Clamp(decimal.Parse(value), 0, 100);
break;
case "water-chance":
settings.water = (byte)Utils.Clamp(decimal.Parse(value), 0, 100);
break;
case "layer-chance":
settings.layer = (byte)Utils.Clamp(decimal.Parse(value), 0, 100);
break;
case "layer-height":
settings.layerHeight = int.Parse(value);
break;
case "layer-count":
settings.layerCount = int.Parse(value);
break;
case "layer-interval":
settings.layerInterval = double.Parse(value);
break;
case "round-time":
settings.roundTime = double.Parse(value);
break;
case "flood-time":
settings.floodTime = double.Parse(value);
break;
case "block-flood":
sp = value.Split(',');
settings.blockFlood = new Vec3U16(ushort.Parse(sp[0]), ushort.Parse(sp[1]), ushort.Parse(sp[2]));
break;
case "block-layer":
sp = value.Split(',');
settings.blockLayer = new Vec3U16(ushort.Parse(sp[0]), ushort.Parse(sp[1]), ushort.Parse(sp[2]));
break;
case "safe-zone":
sp = value.Split('-');
string[] p1 = sp[0].Split(','), p2 = sp[1].Split(',');
settings.safeZone = new Vec3U16[] { new Vec3U16(ushort.Parse(p1[0]), ushort.Parse(p1[1]), ushort.Parse(p1[2])), new Vec3U16(ushort.Parse(p2[0]), ushort.Parse(p2[1]), ushort.Parse(p2[2])) };
break;
}
}
}
catch (Exception e) { Server.ErrorLog(e); }
try {
PropertiesFile.Read(path, ref settings, ProcessMapLine);
} catch (Exception e) {
Server.ErrorLog(e);
}
return settings;
}
public void SaveMapSettings(MapSettings settings)
{
void ProcessMapLine(string key, string value, ref MapSettings map) {
string[] sp;
switch (key.ToLower()) {
case "fast-chance": map.fast = (byte)Utils.Clamp(decimal.Parse(value), 0, 100); break;
case "killer-chance": map.killer = (byte)Utils.Clamp(decimal.Parse(value), 0, 100); break;
case "destroy-chance": map.destroy = (byte)Utils.Clamp(decimal.Parse(value), 0, 100); break;
case "water-chance": map.water = (byte)Utils.Clamp(decimal.Parse(value), 0, 100); break;
case "layer-chance": map.layer = (byte)Utils.Clamp(decimal.Parse(value), 0, 100); break;
case "layer-height": map.layerHeight = int.Parse(value); break;
case "layer-count": map.layerCount = int.Parse(value); break;
case "layer-interval": map.layerInterval = double.Parse(value); break;
case "round-time": map.roundTime = double.Parse(value); break;
case "flood-time": map.floodTime = double.Parse(value); break;
case "block-flood":
sp = value.Split(',');
map.blockFlood = new Vec3U16(ushort.Parse(sp[0]), ushort.Parse(sp[1]), ushort.Parse(sp[2]));
break;
case "block-layer":
sp = value.Split(',');
map.blockLayer = new Vec3U16(ushort.Parse(sp[0]), ushort.Parse(sp[1]), ushort.Parse(sp[2]));
break;
case "safe-zone":
sp = value.Split('-');
string[] p1 = sp[0].Split(','), p2 = sp[1].Split(',');
map.safeZone = new Vec3U16[] {
new Vec3U16(ushort.Parse(p1[0]), ushort.Parse(p1[1]), ushort.Parse(p1[2])),
new Vec3U16(ushort.Parse(p2[0]), ushort.Parse(p2[1]), ushort.Parse(p2[2])) };
break;
}
}
public void SaveMapSettings(MapSettings settings) {
if (!Directory.Exists(propsPath)) Directory.CreateDirectory(propsPath);
using (StreamWriter w = new StreamWriter(propsPath + settings.name + ".properties")) {
@ -189,8 +146,8 @@ namespace MCGalaxy.Games
w.WriteLine("layer-interval = " + settings.layerInterval);
w.WriteLine("round-time = " + settings.roundTime);
w.WriteLine("flood-time = " + settings.floodTime);
w.WriteLine("block-flood = " + settings.blockFlood.ToString());
w.WriteLine("block-layer = " + settings.blockLayer.ToString());
w.WriteLine("block-flood = " + settings.blockFlood);
w.WriteLine("block-layer = " + settings.blockLayer);
w.WriteLine(String.Format("safe-zone = {0}-{1}", settings.safeZone[0].ToString(), settings.safeZone[1].ToString()));
}
}