diff --git a/Samples/MasterServerSample/MSClient/Form1.Designer.cs b/Samples/MasterServerSample/MSClient/Form1.Designer.cs index ba0fe2b..81e3748 100644 --- a/Samples/MasterServerSample/MSClient/Form1.Designer.cs +++ b/Samples/MasterServerSample/MSClient/Form1.Designer.cs @@ -33,6 +33,7 @@ this.label1 = new System.Windows.Forms.Label(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.button2 = new System.Windows.Forms.Button(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.SuspendLayout(); // // button1 @@ -68,12 +69,12 @@ this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(15, 44); this.comboBox1.Name = "comboBox1"; - this.comboBox1.Size = new System.Drawing.Size(499, 200); + this.comboBox1.Size = new System.Drawing.Size(499, 122); this.comboBox1.TabIndex = 4; // // button2 // - this.button2.Location = new System.Drawing.Point(241, 250); + this.button2.Location = new System.Drawing.Point(241, 172); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(273, 23); this.button2.TabIndex = 5; @@ -81,11 +82,23 @@ this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // + // richTextBox1 + // + this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.richTextBox1.Location = new System.Drawing.Point(15, 201); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.Size = new System.Drawing.Size(499, 106); + this.richTextBox1.TabIndex = 6; + this.richTextBox1.Text = ""; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(528, 289); + this.ClientSize = new System.Drawing.Size(528, 319); + this.Controls.Add(this.richTextBox1); this.Controls.Add(this.button2); this.Controls.Add(this.comboBox1); this.Controls.Add(this.label1); @@ -106,6 +119,7 @@ public System.Windows.Forms.Label label1; public System.Windows.Forms.ComboBox comboBox1; public System.Windows.Forms.Button button2; + public System.Windows.Forms.RichTextBox richTextBox1; } } diff --git a/Samples/MasterServerSample/MSClient/Program.cs b/Samples/MasterServerSample/MSClient/Program.cs index d143da0..9952be5 100644 --- a/Samples/MasterServerSample/MSClient/Program.cs +++ b/Samples/MasterServerSample/MSClient/Program.cs @@ -26,7 +26,8 @@ namespace MSClient m_hostList = new List(); NetPeerConfiguration config = new NetPeerConfiguration("game"); - config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true); + config.EnableMessageType(NetIncomingMessageType.UnconnectedData); + config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess); m_client = new NetClient(config); m_client.Start(); @@ -43,6 +44,12 @@ namespace MSClient { switch (inc.MessageType) { + case NetIncomingMessageType.VerboseDebugMessage: + case NetIncomingMessageType.DebugMessage: + case NetIncomingMessageType.WarningMessage: + case NetIncomingMessageType.ErrorMessage: + NativeMethods.AppendText(m_mainForm.richTextBox1, inc.ReadString()); + break; case NetIncomingMessageType.UnconnectedData: if (inc.SenderEndpoint.Equals(m_masterServer)) { @@ -56,7 +63,8 @@ namespace MSClient } break; case NetIncomingMessageType.NatIntroductionSuccess: - MessageBox.Show("Nat introduction success; I just received a message from " + inc.SenderEndpoint); + string token = inc.ReadString(); + MessageBox.Show("Nat introduction success to " + inc.SenderEndpoint + " token is: " + token); break; } } @@ -96,7 +104,7 @@ namespace MSClient // write external address of host to request introduction to IPEndPoint hostEp = new IPEndPoint(NetUtility.Resolve(host), CommonConstants.GameServerPort); om.Write(hostEp); - om.Write("randomtoken"); + om.Write("mytoken"); m_client.SendUnconnectedMessage(om, m_masterServer); } diff --git a/Samples/MasterServerSample/MSServer/Program.cs b/Samples/MasterServerSample/MSServer/Program.cs index bbe9727..ac7f7fa 100644 --- a/Samples/MasterServerSample/MSServer/Program.cs +++ b/Samples/MasterServerSample/MSServer/Program.cs @@ -32,6 +32,25 @@ namespace MSServer Console.WriteLine("Sending registration to master server"); server.SendUnconnectedMessage(regMsg, masterServerEndpoint); + while(Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape) + { + NetIncomingMessage inc; + while ((inc = server.ReadMessage()) != null) + { + switch (inc.MessageType) + { + case NetIncomingMessageType.VerboseDebugMessage: + case NetIncomingMessageType.DebugMessage: + case NetIncomingMessageType.WarningMessage: + case NetIncomingMessageType.ErrorMessage: + Console.WriteLine(inc.ReadString()); + break; + } + } + + System.Threading.Thread.Sleep(1); + } + Console.ReadKey(); } } diff --git a/Samples/MasterServerSample/MasterServer/Program.cs b/Samples/MasterServerSample/MasterServer/Program.cs index a2353c5..a4d7ed7 100644 --- a/Samples/MasterServerSample/MasterServer/Program.cs +++ b/Samples/MasterServerSample/MasterServer/Program.cs @@ -76,6 +76,7 @@ namespace MasterServer if (elist[1].Equals(hostExternal)) { // found in list - introduce client and host to eachother + Console.WriteLine("Sending introduction..."); peer.Introduce( elist[0], // host internal elist[1], // host external @@ -83,7 +84,6 @@ namespace MasterServer msg.SenderEndpoint, // client external token // request token ); - Console.WriteLine("Sending..."); break; } }