1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-15 14:46:29 +09:00

Nat introduction added; sample added (not finished yet)

This commit is contained in:
lidgren
2010-05-10 09:43:45 +00:00
parent 0810dfc1c5
commit 66802928b6
12 changed files with 269 additions and 5 deletions

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{47E2AC9A-F375-47A7-A4E6-9814D3A2954B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MasterServer</RootNamespace>
<AssemblyName>MasterServer</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Lidgren.Network\Lidgren.Network.csproj">
<Project>{FA245447-5F23-4AA1-BD5F-8D2DDF33CFBD}</Project>
<Name>Lidgren.Network</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using Lidgren.Network;
using System.Net;
namespace MasterServer
{
public enum MasterServerMessageType
{
RegisterHost,
RequestHostList,
RequestIntroduction,
}
public class Program
{
static void Main(string[] args)
{
List<IPEndPoint> registeredHosts = new List<IPEndPoint>();
NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
NetPeer peer = new NetPeer(config);
peer.Start();
// keep going until ESCAPE is pressed
Console.WriteLine("Press ESC to quit");
while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape)
{
NetIncomingMessage msg;
while((msg = peer.ReadMessage()) != null)
{
switch (msg.MessageType)
{
case NetIncomingMessageType.UnconnectedData:
//
// We've received a message from a client or a host
//
// by design, the first byte always indicates action
switch ((MasterServerMessageType)msg.ReadByte())
{
case MasterServerMessageType.RegisterHost:
// It's a host wanting to register its presence
registeredHosts.Add(msg.SenderEndpoint);
break;
case MasterServerMessageType.RequestHostList:
// It's a client wanting a list of registered hosts
foreach (IPEndPoint ep in registeredHosts)
{
// send registered host to client
NetOutgoingMessage om = peer.CreateMessage();
om.Write(ep);
peer.SendUnconnectedMessage(om, msg.SenderEndpoint);
}
break;
case MasterServerMessageType.RequestIntroduction:
// It's a client wanting to connect to a specific host
IPEndPoint rh = msg.ReadIPEndpoint();
peer.Introduce(rh, msg.SenderEndpoint);
break;
}
break;
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.ErrorMessage:
// print diagnostics message
Console.WriteLine(msg.ReadString());
break;
}
}
}
peer.Shutdown("shutting down");
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MasterServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("MasterServer")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("649338d3-b80b-4710-b801-21e593935c21")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]