1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-17 23:56:30 +09:00

MasterServer sample fixed

This commit is contained in:
lidgren
2012-09-13 07:10:52 +00:00
parent fd224b88d8
commit af4f77a8a5
5 changed files with 12 additions and 19 deletions

View File

@@ -93,7 +93,6 @@
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
</Compile> </Compile>
<None Include="app.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@@ -51,11 +51,11 @@ namespace MSClient
NativeMethods.AppendText(m_mainForm.richTextBox1, inc.ReadString()); NativeMethods.AppendText(m_mainForm.richTextBox1, inc.ReadString());
break; break;
case NetIncomingMessageType.UnconnectedData: case NetIncomingMessageType.UnconnectedData:
if (inc.SenderEndpoint.Equals(m_masterServer)) if (inc.SenderEndPoint.Equals(m_masterServer))
{ {
// it's from the master server - must be a host // it's from the master server - must be a host
IPEndPoint hostInternal = inc.ReadIPEndpoint(); IPEndPoint hostInternal = inc.ReadIPEndPoint();
IPEndPoint hostExternal = inc.ReadIPEndpoint(); IPEndPoint hostExternal = inc.ReadIPEndPoint();
m_hostList.Add(new IPEndPoint[] { hostInternal, hostExternal }); m_hostList.Add(new IPEndPoint[] { hostInternal, hostExternal });
@@ -64,7 +64,7 @@ namespace MSClient
break; break;
case NetIncomingMessageType.NatIntroductionSuccess: case NetIncomingMessageType.NatIntroductionSuccess:
string token = inc.ReadString(); string token = inc.ReadString();
MessageBox.Show("Nat introduction success to " + inc.SenderEndpoint + " token is: " + token); MessageBox.Show("Nat introduction success to " + inc.SenderEndPoint + " token is: " + token);
break; break;
} }
} }

View File

@@ -105,9 +105,6 @@
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -99,9 +99,6 @@
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -42,8 +42,8 @@ namespace MasterServer
// It's a host wanting to register its presence // It's a host wanting to register its presence
IPEndPoint[] eps = new IPEndPoint[] IPEndPoint[] eps = new IPEndPoint[]
{ {
msg.ReadIPEndpoint(), // internal msg.ReadIPEndPoint(), // internal
msg.SenderEndpoint // external msg.SenderEndPoint // external
}; };
Console.WriteLine("Got registration for host " + eps[1]); Console.WriteLine("Got registration for host " + eps[1]);
registeredHosts.Add(eps); registeredHosts.Add(eps);
@@ -51,24 +51,24 @@ namespace MasterServer
case MasterServerMessageType.RequestHostList: case MasterServerMessageType.RequestHostList:
// It's a client wanting a list of registered hosts // It's a client wanting a list of registered hosts
Console.WriteLine("Sending list of " + registeredHosts.Count + " hosts to client " + msg.SenderEndpoint); Console.WriteLine("Sending list of " + registeredHosts.Count + " hosts to client " + msg.SenderEndPoint);
foreach (IPEndPoint[] ep in registeredHosts) foreach (IPEndPoint[] ep in registeredHosts)
{ {
// send registered host to client // send registered host to client
NetOutgoingMessage om = peer.CreateMessage(); NetOutgoingMessage om = peer.CreateMessage();
om.Write(ep[0]); om.Write(ep[0]);
om.Write(ep[1]); om.Write(ep[1]);
peer.SendUnconnectedMessage(om, msg.SenderEndpoint); peer.SendUnconnectedMessage(om, msg.SenderEndPoint);
} }
break; break;
case MasterServerMessageType.RequestIntroduction: case MasterServerMessageType.RequestIntroduction:
// It's a client wanting to connect to a specific (external) host // It's a client wanting to connect to a specific (external) host
IPEndPoint clientInternal = msg.ReadIPEndpoint(); IPEndPoint clientInternal = msg.ReadIPEndPoint();
IPEndPoint hostExternal = msg.ReadIPEndpoint(); IPEndPoint hostExternal = msg.ReadIPEndPoint();
string token = msg.ReadString(); string token = msg.ReadString();
Console.WriteLine(msg.SenderEndpoint + " requesting introduction to " + hostExternal + " (token " + token + ")"); Console.WriteLine(msg.SenderEndPoint + " requesting introduction to " + hostExternal + " (token " + token + ")");
// find in list // find in list
foreach (IPEndPoint[] elist in registeredHosts) foreach (IPEndPoint[] elist in registeredHosts)
@@ -81,7 +81,7 @@ namespace MasterServer
elist[0], // host internal elist[0], // host internal
elist[1], // host external elist[1], // host external
clientInternal, // client internal clientInternal, // client internal
msg.SenderEndpoint, // client external msg.SenderEndPoint, // client external
token // request token token // request token
); );
break; break;