diff --git a/EduNetworkBuilder/ActionClass.cs b/EduNetworkBuilder/ActionClass.cs index 73d1a80..207988c 100644 --- a/EduNetworkBuilder/ActionClass.cs +++ b/EduNetworkBuilder/ActionClass.cs @@ -13,8 +13,11 @@ namespace EduNetworkBuilder public List NetActions = new List(); NetworkAction CurrentNetAction = null; + public Network GetNet { get { return StartingState; } } + public void RegisterNet(Network starting) { + StartingState = Network.DeepClone(starting); CurrentNetAction = new NetworkAction(starting); } @@ -29,6 +32,17 @@ namespace EduNetworkBuilder CurrentNetAction.Add(What); } + public bool RunAction(int WhichIndex) + { + if (CurrentNetAction == null) return false; + if (WhichIndex < CurrentNetAction.Actions.Count) + { + CurrentNetAction.Actions[WhichIndex].DoAction(); + return true; + } + return false; + } + /// /// Take the current actionlist and save it to the stored actionlists. /// We use this when we have successfully solved a network and want to store diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index 7cce2c9..890140b 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -380,6 +380,8 @@ namespace EduNetworkBuilder public static string AllowedPasswordCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=!~@#$%^&*()_+{}[]/?<>,."; public static string AllowedUsernameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890._"; + + public static int MillisecondsBetweenReplays = 500; /// /// Find the global random number generator. /// @@ -496,6 +498,9 @@ namespace EduNetworkBuilder myWin.UnregisterInvisibleNet(); } + /// + /// Make sure we update the visuals when we have the opportunity to do so + /// public static void MarkToUpdate() { BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"]; diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index 94560ee..d61a986 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -81,6 +81,10 @@ namespace EduNetworkBuilder private List Animations = new List(); + public bool ReplayInProgress = false; + public DateTime NextReplayAction = DateTime.UtcNow; + public int NextReplayIndex = -1; + /// /// WhatFrom: If we are launched from a homework, we remember it here. /// @@ -1642,6 +1646,28 @@ namespace EduNetworkBuilder } } } + if(ReplayInProgress && myPackets.Count == 0) + { + if(DateTime.UtcNow >= NextReplayAction) + { + //We are doing a replay and enough time has passed from the last replay... + NBSettings Settings = NB.GetSettings(); + ActionCollection AC = Settings.GetUserActionCollection(); + bool Success = AC.RunAction(NextReplayIndex++); + + NextReplayAction = DateTime.UtcNow.AddMilliseconds(NB.MillisecondsBetweenReplays); + if(Success) + { + //we did something. keep replaying + NB.MarkToUpdate(); + } + else + { + //replay finished + ReplayInProgress = false; + } + } + } //if (myPackets.Count > 50) //Console.WriteLine("Packets: " + myPackets.Count.ToString()); if (myPackets.Count > 0) diff --git a/EduNetworkBuilder/NetworkBuilder.Designer.cs b/EduNetworkBuilder/NetworkBuilder.Designer.cs index f4952b6..43e3c4f 100644 --- a/EduNetworkBuilder/NetworkBuilder.Designer.cs +++ b/EduNetworkBuilder/NetworkBuilder.Designer.cs @@ -78,6 +78,7 @@ this.myProgressBar = new System.Windows.Forms.ProgressBar(); this.cbLineColor = new System.Windows.Forms.ComboBox(); this.cbFillColor = new System.Windows.Forms.ComboBox(); + this.replayToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.msMainMenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pbNetworkView)).BeginInit(); this.HelpPanel.SuspendLayout(); @@ -107,7 +108,8 @@ this.reloadToolStripMenuItem, this.saveToolStripMenuItem, this.logoutToolStripMenuItem, - this.exitToolStripMenuItem}); + this.exitToolStripMenuItem, + this.replayToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(44, 24); this.fileToolStripMenuItem.Text = "File"; @@ -115,42 +117,42 @@ // newToolStripMenuItem // this.newToolStripMenuItem.Name = "newToolStripMenuItem"; - this.newToolStripMenuItem.Size = new System.Drawing.Size(131, 26); + this.newToolStripMenuItem.Size = new System.Drawing.Size(181, 26); this.newToolStripMenuItem.Text = "New"; this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click); // // loadToolStripMenuItem // this.loadToolStripMenuItem.Name = "loadToolStripMenuItem"; - this.loadToolStripMenuItem.Size = new System.Drawing.Size(131, 26); + this.loadToolStripMenuItem.Size = new System.Drawing.Size(181, 26); this.loadToolStripMenuItem.Text = "Load"; this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click); // // reloadToolStripMenuItem // this.reloadToolStripMenuItem.Name = "reloadToolStripMenuItem"; - this.reloadToolStripMenuItem.Size = new System.Drawing.Size(131, 26); + this.reloadToolStripMenuItem.Size = new System.Drawing.Size(181, 26); this.reloadToolStripMenuItem.Text = "Reload"; this.reloadToolStripMenuItem.Click += new System.EventHandler(this.reloadToolStripMenuItem_Click); // // saveToolStripMenuItem // this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.Size = new System.Drawing.Size(131, 26); + this.saveToolStripMenuItem.Size = new System.Drawing.Size(181, 26); this.saveToolStripMenuItem.Text = "Save"; this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); // // logoutToolStripMenuItem // this.logoutToolStripMenuItem.Name = "logoutToolStripMenuItem"; - this.logoutToolStripMenuItem.Size = new System.Drawing.Size(131, 26); + this.logoutToolStripMenuItem.Size = new System.Drawing.Size(181, 26); this.logoutToolStripMenuItem.Text = "Logout"; this.logoutToolStripMenuItem.Click += new System.EventHandler(this.logoutToolStripMenuItem_Click); // // exitToolStripMenuItem // this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(131, 26); + this.exitToolStripMenuItem.Size = new System.Drawing.Size(181, 26); this.exitToolStripMenuItem.Text = "Exit"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // @@ -533,6 +535,13 @@ this.cbFillColor.Size = new System.Drawing.Size(80, 24); this.cbFillColor.TabIndex = 13; // + // replayToolStripMenuItem + // + this.replayToolStripMenuItem.Name = "replayToolStripMenuItem"; + this.replayToolStripMenuItem.Size = new System.Drawing.Size(181, 26); + this.replayToolStripMenuItem.Text = "Replay"; + this.replayToolStripMenuItem.Click += new System.EventHandler(this.replayToolStripMenuItem_Click); + // // BuilderWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); @@ -620,6 +629,7 @@ private System.Windows.Forms.Button btnCaptions; private System.Windows.Forms.ComboBox cbLineColor; private System.Windows.Forms.ComboBox cbFillColor; + private System.Windows.Forms.ToolStripMenuItem replayToolStripMenuItem; } } diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index b38aa71..f707f0b 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -139,7 +139,7 @@ namespace EduNetworkBuilder UpdateVisuals(); NeedsUpdate = false; } - myNetwork.Tick(); + myNetwork.Tick(false); } private void LanguagifyComponents() @@ -1419,7 +1419,8 @@ namespace EduNetworkBuilder todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Ping"),true); if(todo) { - ItemClickedOn.PingFromHere(destination); + //ItemClickedOn.PingFromHere(destination); + NB.DoActionPingDevice(ItemClickedOn.GetUniqueIdentifier, destination); myNetwork.ProcessPackets(); UpdateMessages(); } @@ -1433,7 +1434,8 @@ namespace EduNetworkBuilder todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Traceroute"), true); if (todo) { - ItemClickedOn.TracerouteFromHere(destination); + //ItemClickedOn.TracerouteFromHere(destination); + NB.DoActionTracertDevice(ItemClickedOn.GetUniqueIdentifier, destination); myNetwork.ProcessPackets(); UpdateMessages(); } @@ -2794,5 +2796,32 @@ namespace EduNetworkBuilder #endregion Random Map Stuff + + private void replayToolStripMenuItem_Click(object sender, EventArgs e) + { + //Prepare for replay + // reset to original map + // Go through each step and do the actions again in order + NBSettings ourSettings = NB.GetSettings(); + if (OurSettings == null) return; //nothing to do + ActionCollection actions = OurSettings.GetUserActionCollection(); + if (actions == null) return; //nothing to do + + if (actions.GetNet == null) return; //Nothing to do + //If we get here, we have a valid network in the current state. + + ChangeToPastState(actions.GetNet); + //Make a boolean that says we are in a replaying state + //make an index that shows the index we are to replay + //make a time for when the next replay happens (.5 sec from now or after all packets are gone) + // On tick. If we are in replay mode. + // Check to see if we need to replay an action + // If so, do it. + // If not, keep ticking + //Disable menuitems & right-click if in replay mode + myNetwork.ReplayInProgress = true; + myNetwork.NextReplayIndex = 0; + myNetwork.NextReplayAction = DateTime.UtcNow.AddMilliseconds(NB.MillisecondsBetweenReplays); + } } } \ No newline at end of file