move to github

This commit is contained in:
Magnus von Wachenfeldt
2015-12-04 10:23:49 +01:00
commit 2a9d8ce416
252 changed files with 45041 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
</configuration>

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace SpacePew.MasterServer
{
public class GameServer
{
public long Id { get; set; }
public IPEndPoint[] Endpoints { get; set; }
public DateTime Updated { get; set; }
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace SpacePew.MasterServer
{
public class Program
{
static void Main(string[] args)
{
var server = new Server();
server.Run();
}
}
}

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("SpacePew.MasterServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SpacePew.MasterServer")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[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("d8783d9d-5612-4a01-afdf-57a65560d6fd")]
// 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,121 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Lidgren.Network;
using SpacePew.Common;
namespace SpacePew.MasterServer
{
public class Server
{
public void Run()
{
var registeredHosts = new List<GameServer>();
var config = new NetPeerConfiguration("masterserver");
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
config.Port = Constants.MasterServerPort;
var peer = new NetPeer(config);
peer.Start();
Console.WriteLine("Press ESC to quit");
while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape)
{
var removed = registeredHosts.RemoveAll(g => g.Updated <= DateTime.Now.AddSeconds(-50));
if (removed > 0)
{
Console.WriteLine("Removed {0} hosts from master server list", removed);
}
NetIncomingMessage msg;
while ((msg = peer.ReadMessage()) != null)
{
switch (msg.MessageType)
{
case NetIncomingMessageType.UnconnectedData:
switch ((UdpNetworkPacketType)msg.ReadByte())
{
case UdpNetworkPacketType.RegisterHost:
var id = msg.ReadInt64();
Console.WriteLine("Got registration for host " + id);
var host = registeredHosts.FirstOrDefault(s => s.Id == id);
if (host == null)
{
registeredHosts.Add(new GameServer()
{
Id = id,
Endpoints = new IPEndPoint[]
{
msg.ReadIPEndPoint(),
msg.SenderEndPoint
},
Updated = DateTime.Now
});
}
else
{
host.Updated = DateTime.Now;
}
break;
case UdpNetworkPacketType.RequestHostList:
Console.WriteLine("Sending list of " + registeredHosts.Count + " hosts to client " + msg.SenderEndPoint);
foreach (var server in registeredHosts)
{
var message = peer.CreateMessage();
message.Write(server.Id);
message.Write(server.Endpoints[0]);
message.Write(server.Endpoints[1]);
peer.SendUnconnectedMessage(message, msg.SenderEndPoint);
}
break;
case UdpNetworkPacketType.RequestIntroduction:
var clientInternal = msg.ReadIPEndPoint();
long hostId = msg.ReadInt64();
string token = msg.ReadString();
Console.WriteLine(msg.SenderEndPoint + " requesting introduction to " + hostId + " (token " + token + ")");
var host2 = registeredHosts.FirstOrDefault(s => s.Id == hostId);
if (host2 != null)
{
Console.WriteLine("Sending introduction...");
peer.Introduce(
host2.Endpoints[0], // host internal
host2.Endpoints[1], // host external
clientInternal, // client internal
msg.SenderEndPoint, // client external
token // request token
);
}
else
{
Console.WriteLine("Client requested introduction to nonlisted host");
}
break;
}
break;
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.ErrorMessage:
Console.WriteLine(msg.ReadString());
break;
}
}
}
peer.Shutdown("bye");
}
}
}

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9BFE240A-AEE0-4FD6-80B8-5846DCFAE95C}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SpacePew.MasterServer</RootNamespace>
<AssemblyName>SpacePew.MasterServer</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GameServer.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lidgren.Network\Lidgren.Network.csproj">
<Project>{49ba1c69-6104-41ac-a5d8-b54fa9f696e8}</Project>
<Name>Lidgren.Network</Name>
</ProjectReference>
<ProjectReference Include="..\SpacePew.Common\SpacePew.Common.csproj">
<Project>{ba98d4ca-718b-4e50-ad4d-f48e8ca67624}</Project>
<Name>SpacePew.Common</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>