Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CSM.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
# Visual Studio Version 16
VisualStudioVersion = 16.0.30615.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSM", "src\CSM.csproj", "{63933537-DA87-4026-A44C-382298FBB399}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StandaloneServer", "StandaloneServer\StandaloneServer.csproj", "{DC22F5F0-10C1-4798-A032-355880E12954}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{63933537-DA87-4026-A44C-382298FBB399}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63933537-DA87-4026-A44C-382298FBB399}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63933537-DA87-4026-A44C-382298FBB399}.Release|Any CPU.Build.0 = Release|Any CPU
{DC22F5F0-10C1-4798-A032-355880E12954}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC22F5F0-10C1-4798-A032-355880E12954}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC22F5F0-10C1-4798-A032-355880E12954}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC22F5F0-10C1-4798-A032-355880E12954}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
54 changes: 54 additions & 0 deletions StandaloneServer/Networking/Host.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using CSM.Networking;
using CSM.Networking.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace CSM.StandaloneServer.Networking
{
public class Host
{
/// <summary>
/// The current player list as server or client.
/// </summary>
public HashSet<string> PlayerList { get; } = new HashSet<string>();

/// <summary>
/// The current game server (Use only when this game acts as server!)
/// </summary>
private Server CurrentServer { get; } = new Server();

public void ProcessEvents()
{
CurrentServer.ProcessEvents();
}

/// <summary>
/// Starts the game server on the given port.
/// </summary>
/// <param name="config">The ServerConfig</param>
/// <param name="callback">This callback returns if the server was started successfully.</param>
public void StartGameServer(ServerConfig config, Action callback)
{
new Thread(() =>
{
// Create the server and start it
CurrentServer.StartServer(config);

callback();
}).Start();
}

/// <summary>
/// Stops the client or server, depending on the current role
/// </summary>
public void StopEverything()
{
CurrentServer.StopServer();
}

private static Host _multiplayerInstance;
public static Host Instance => _multiplayerInstance ?? (_multiplayerInstance = new Host());
}
}
20 changes: 20 additions & 0 deletions StandaloneServer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using CSM.StandaloneServer.Networking;
using CSM.Networking.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSM.StandaloneServer
{
class Program
{
static void Main(string[] args)
{
BaseServerConfig baseServerConfig = new ServerConfig(4230, null, "", 10);
Host.Instance.StartGameServer((ServerConfig)baseServerConfig, () => {
Console.WriteLine("Server started");
});
}
}
}
36 changes: 36 additions & 0 deletions StandaloneServer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("StandaloneServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StandaloneServer")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[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("dc22f5f0-10c1-4798-a032-355880e12954")]

// 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")]
57 changes: 57 additions & 0 deletions StandaloneServer/StandaloneServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{DC22F5F0-10C1-4798-A032-355880E12954}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>StandaloneServer</RootNamespace>
<AssemblyName>StandaloneServer</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</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>
<PropertyGroup>
<StartupObject>CSM.StandaloneServer.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Networking\Host.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\CSM.csproj">
<Project>{63933537-da87-4026-a44c-382298fbb399}</Project>
<Name>CSM</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
2 changes: 2 additions & 0 deletions src/CSM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@
<Compile Include="Models\QuaternionSurrogate.cs" />
<Compile Include="Models\ControlPointSurrogate.cs" />
<Compile Include="Models\Vector3Surrogate.cs" />
<Compile Include="Networking\BaseServer.cs" />
<Compile Include="Networking\Client.cs" />
<Compile Include="Networking\Config\BaseServerConfig.cs" />
<Compile Include="Networking\Config\ClientConfig.cs" />
<Compile Include="Networking\Config\ConfigData.cs" />
<Compile Include="Networking\Config\ServerConfig.cs" />
Expand Down
Loading