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

transferred from trunk/Generation3 of lidgren-network

This commit is contained in:
lidgren
2010-05-06 18:30:27 +00:00
commit fbcd550a2a
145 changed files with 17306 additions and 0 deletions

View File

@@ -0,0 +1,122 @@
using System;
using System.Threading;
using Lidgren.Network;
namespace XnaGameServer
{
class Program
{
static void Main(string[] args)
{
NetPeerConfiguration config = new NetPeerConfiguration("xnaapp");
config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
config.Port = 14242;
// create and start server
NetServer server = new NetServer(config);
server.Start();
// schedule initial sending of position updates
double nextSendUpdates = NetTime.Now;
// run until escape is pressed
while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape)
{
NetIncomingMessage msg;
while ((msg = server.ReadMessage()) != null)
{
switch (msg.MessageType)
{
case NetIncomingMessageType.DiscoveryRequest:
//
// Server received a discovery request from a client; send a discovery response (with no extra data attached)
//
server.SendDiscoveryResponse(null, msg.SenderEndpoint);
break;
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.ErrorMessage:
//
// Just print diagnostic messages to console
//
Console.WriteLine(msg.ReadString());
break;
case NetIncomingMessageType.StatusChanged:
NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
if (status == NetConnectionStatus.Connected)
{
//
// A new player just connected!
//
Console.WriteLine(NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier) + " connected!");
// randomize his position and store in connection tag
msg.SenderConnection.Tag = new int[] {
NetRandom.Instance.Next(10, 100),
NetRandom.Instance.Next(10, 100)
};
}
break;
case NetIncomingMessageType.Data:
//
// The client sent input to the server
//
int xinput = msg.ReadInt32();
int yinput = msg.ReadInt32();
int[] pos = msg.SenderConnection.Tag as int[];
// fancy movement logic goes here; we just append input to position
pos[0] += xinput;
pos[1] += yinput;
break;
}
//
// send position updates 30 times per second
//
double now = NetTime.Now;
if (now > nextSendUpdates)
{
// Yes, it's time to send position updates
// for each player...
foreach (NetConnection player in server.Connections)
{
// ... send information about every other player (actually including self)
foreach (NetConnection otherPlayer in server.Connections)
{
// send position update about 'otherPlayer' to 'player'
NetOutgoingMessage om = server.CreateMessage();
// write who this position is for
om.Write(otherPlayer.RemoteUniqueIdentifier);
if (otherPlayer.Tag == null)
otherPlayer.Tag = new int[2];
int[] pos = otherPlayer.Tag as int[];
om.Write(pos[0]);
om.Write(pos[1]);
// send message
server.SendMessage(om, player, NetDeliveryMethod.Unreliable);
}
}
// schedule next update
nextSendUpdates += (1.0 / 30.0);
}
}
// sleep to allow other processes to run smoothly
Thread.Sleep(1);
}
server.Shutdown("app exiting");
}
}
}

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("XnaGameServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("XnaGameServer")]
[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("ad24f34e-32a4-4619-a19f-c16f126d186e")]
// 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")]

View File

@@ -0,0 +1,59 @@
<?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.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2A16EEC3-99B7-45D8-B185-6E1101225540}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>XnaGameServer</RootNamespace>
<AssemblyName>XnaGameServer</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.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>