Skip to content

Commit c102935

Browse files
committed
First commit with basic functionality, licence and readme
1 parent 776ba9d commit c102935

File tree

9 files changed

+460
-32
lines changed

9 files changed

+460
-32
lines changed

LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Albin Corén
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MLAPI/Class1.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

MLAPI/MLAPI.csproj

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>ee431720-a9ed-43dc-9e74-10b693816d38</ProjectGuid>
7+
<ProjectGuid>{EE431720-A9ED-43DC-9E74-10B693816D38}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>MLAPI</RootNamespace>
1111
<AssemblyName>MLAPI</AssemblyName>
12-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
1415
</PropertyGroup>
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<DebugSymbols>true</DebugSymbols>
1718
<DebugType>full</DebugType>
1819
<Optimize>false</Optimize>
19-
<OutputPath>bin\Debug\</OutputPath>
20+
<OutputPath>..\..\..\..\Documents\MLAPI\Assets\</OutputPath>
2021
<DefineConstants>DEBUG;TRACE</DefineConstants>
2122
<ErrorReport>prompt</ErrorReport>
2223
<WarningLevel>4</WarningLevel>
@@ -30,24 +31,25 @@
3031
<WarningLevel>4</WarningLevel>
3132
</PropertyGroup>
3233
<ItemGroup>
33-
<Reference Include="System"/>
34-
35-
<Reference Include="System.Core"/>
36-
<Reference Include="System.Xml.Linq"/>
37-
<Reference Include="System.Data.DataSetExtensions"/>
38-
39-
40-
<Reference Include="Microsoft.CSharp"/>
41-
42-
<Reference Include="System.Data"/>
43-
44-
<Reference Include="System.Net.Http"/>
45-
46-
<Reference Include="System.Xml"/>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core" />
36+
<Reference Include="System.Xml.Linq" />
37+
<Reference Include="System.Data.DataSetExtensions" />
38+
<Reference Include="Microsoft.CSharp" />
39+
<Reference Include="System.Data" />
40+
<Reference Include="System.Net.Http" />
41+
<Reference Include="System.Xml" />
42+
<Reference Include="UnityEngine">
43+
<HintPath>..\..\..\..\..\..\Program Files\Unity\Editor\Data\Managed\UnityEngine.dll</HintPath>
44+
</Reference>
4745
</ItemGroup>
4846
<ItemGroup>
49-
<Compile Include="Class1.cs" />
47+
<Compile Include="NetworkedBehaviour.cs" />
48+
<Compile Include="NetworkedClient.cs" />
49+
<Compile Include="NetworkedObject.cs" />
50+
<Compile Include="NetworkingConfiguration.cs" />
51+
<Compile Include="NetworkingManager.cs" />
5052
<Compile Include="Properties\AssemblyInfo.cs" />
5153
</ItemGroup>
5254
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
53-
</Project>
55+
</Project>

MLAPI/NetworkedBehaviour.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace MLAPI
6+
{
7+
public abstract class NetworkedBehaviour : MonoBehaviour
8+
{
9+
protected bool isLocalPlayer;
10+
protected bool isServer = NetworkingManager.singleton.isServer;
11+
12+
//Change data type
13+
private Dictionary<string, int> registeredMessageHandlers = new Dictionary<string, int>();
14+
15+
public int RegisterMessageHandler(string name, Action<int, byte[]> action)
16+
{
17+
int counter = NetworkingManager.singleton.AddIncomingMessageHandler(name, action);
18+
registeredMessageHandlers.Add(name, counter);
19+
return counter;
20+
}
21+
22+
public void DeregisterMessageHandler(string name, int counter)
23+
{
24+
NetworkingManager.singleton.RemoveIncomingMessageHandler(name, counter);
25+
}
26+
27+
private void OnDestroy()
28+
{
29+
foreach(KeyValuePair<string, int> pair in registeredMessageHandlers)
30+
{
31+
DeregisterMessageHandler(pair.Key, pair.Value);
32+
}
33+
}
34+
}
35+
}

MLAPI/NetworkedClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace MLAPI
2+
{
3+
public class NetworkedClient
4+
{
5+
public int ClientId;
6+
}
7+
}

MLAPI/NetworkedObject.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using UnityEngine;
2+
3+
namespace MLAPI
4+
{
5+
//TODO
6+
//Will be used for objects which will be spawned automatically across clients
7+
public class NetworkedObject : MonoBehaviour
8+
{
9+
10+
}
11+
}

MLAPI/NetworkingConfiguration.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using UnityEngine.Networking;
4+
5+
namespace MLAPI
6+
{
7+
public class NetworkingConfiguration
8+
{
9+
public ushort ProtocolVersion = 0;
10+
public Dictionary<string, QosType> Channels = new Dictionary<string, QosType>();
11+
public List<string> MessageTypes = new List<string>();
12+
public int MessageBufferSize = 65536;
13+
public int MaxMessagesPerFrame = 150;
14+
public int MaxConnections = 100;
15+
public int Port = 7777;
16+
public int ClientConnectionBufferTimeout = 10;
17+
public bool ConnectionApproval = false;
18+
public Action<byte[], int, Action<int, bool>> ConnectionApprovalCallback;
19+
public byte[] ConnectionData;
20+
}
21+
}

0 commit comments

Comments
 (0)