Add prevention of duplicate legion entries.

This commit is contained in:
Michael 2017-02-03 21:13:51 -05:00
parent 318fef283e
commit ce300026cb
3 changed files with 37 additions and 8 deletions

View file

@ -420,14 +420,36 @@ Contents:
}));
}
break;
case "legion_create":
case "legion_createnew":
List<Legion> legions = new List<Legion>();
if (File.Exists("legions.json"))
legions = JsonConvert.DeserializeObject<List<Legion>>(File.ReadAllText("legions.json"));
var l = JsonConvert.DeserializeObject<Legion>(msg.Contents);
bool legionExists = false;
legions.Add(l);
foreach (var legion in legions)
if (legion.ShortName == l.ShortName)
legionExists = true;
if (legionExists == false)
{
legions.Add(l);
server.DispatchTo(new Guid(msg.GUID), new NetObject("test", new ServerMessage
{
Name = "legion_create_ok",
GUID = "server"
}));
}
else
{
server.DispatchTo(new Guid(msg.GUID), new NetObject("test", new ServerMessage
{
Name = "legion_alreadyexists",
GUID = "server"
}));
}
File.WriteAllText("legions.json", JsonConvert.SerializeObject(legions, Formatting.Indented));
break;

View file

@ -305,9 +305,9 @@ namespace ShiftOS.WinForms.Applications
//
// toolStripContainer1.ContentPanel
//
this.toolStripContainer1.ContentPanel.Controls.Add(this.lgn_create);
this.toolStripContainer1.ContentPanel.Controls.Add(this.job_current);
this.toolStripContainer1.ContentPanel.Controls.Add(this.shop_view);
this.toolStripContainer1.ContentPanel.Controls.Add(this.lgn_create);
this.toolStripContainer1.ContentPanel.Controls.Add(this.lgn_view);
this.toolStripContainer1.ContentPanel.Controls.Add(this.lgn_join);
this.toolStripContainer1.ContentPanel.Controls.Add(this.you_memos);

View file

@ -66,6 +66,17 @@ namespace ShiftOS.WinForms.Applications
BannerColor = ConsoleColor.DarkRed
});
}
else if(msg.Name == "legion_create_ok")
{
SaveSystem.CurrentSave.CurrentLegions.Clear();
SaveSystem.CurrentSave.CurrentLegions.Add(editingLegion.ShortName);
SaveSystem.SaveGame();
myLegionToolStripMenuItem_Click(this, EventArgs.Empty);
}
else if(msg.Name == "legion_alreadyexists")
{
Infobox.Show("Legion already exists", "A legion with the short name you provided already exists. Please choose another.");
}
else if(msg.Name == "legion_users_found")
{
lvusers.Items.Clear();
@ -421,11 +432,7 @@ Current legions: {legionname}";
private void btncreate_Click(object sender, EventArgs e)
{
ServerManager.SendMessage("legion_create", JsonConvert.SerializeObject(editingLegion));
SaveSystem.CurrentSave.CurrentLegions.Clear();
SaveSystem.CurrentSave.CurrentLegions.Add(editingLegion.ShortName);
SaveSystem.SaveGame();
myLegionToolStripMenuItem_Click(sender, e);
ServerManager.SendMessage("legion_createnew", JsonConvert.SerializeObject(editingLegion));
}
private void txtnewlegiondescription_TextChanged(object sender, EventArgs e)