Skip to content

Commit 2f98750

Browse files
author
raistlinthewiz
committed
Implemented very-primitive NAT support, though enabling it will break support for LAN-clients -- which will be fixed in the future with a proper NAT implementation similar to pvpgn.
Added WARNING file, make sure you read this before start using the software (got the text from Mangos, as their conditions are quite alike). Added license text to source-files that we're missing them. Added CHANGELOG, CREDITS placeholder files.
1 parent e40744b commit 2f98750

15 files changed

+212
-13
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
changelog placeholder

CREDITS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
credits placeholder

WARNING

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
D3Sharp has been built with education as the main purpose and
2+
the we would like to keep it as is.
3+
4+
Since any public and/or commercial use of this software is considered illegal
5+
in many countries (please refer to your local law), the D3Sharp team
6+
will not provide any help nor support with such usage in any way.
7+
Every user of this software is encouraged to make sure no law is being broken
8+
on his/her side.
9+
10+
D3Sharp team will not take any responsibility for any kind of usage of this
11+
software by the end users.

source/D3Sharp/Core/Games/Game.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void ListenForGame(BNetClient client)
5757
// We should actually find the server's public-interface and use that
5858
var connectionInfo =
5959
bnet.protocol.game_master.ConnectInfo.CreateBuilder().SetToonId(client.CurrentToon.BnetEntityID).SetHost
60-
(client.Connection.LocalEndPoint.Address.ToString()).SetPort(Net.Game.Config.Instance.Port).SetToken(ByteString.CopyFrom(new byte[] {0x07, 0x34, 0x02, 0x60, 0x91, 0x93, 0x76, 0x46, 0x28, 0x84}))
60+
(Net.Utils.GetGameServerIPForClient(client)).SetPort(Net.Game.Config.Instance.Port).SetToken(ByteString.CopyFrom(new byte[] {0x07, 0x34, 0x02, 0x60, 0x91, 0x93, 0x76, 0x46, 0x28, 0x84}))
6161
.AddAttribute(bnet.protocol.attribute.Attribute.CreateBuilder().SetName("SGameId").SetValue(bnet.protocol.attribute.Variant.CreateBuilder().SetIntValue((long)this.DynamicId).Build())).Build();
6262

6363
var builder = bnet.protocol.game_master.GameFoundNotification.CreateBuilder();

source/D3Sharp/D3Sharp.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@
133133
<Compile Include="Net\Game\GameServer.cs" />
134134
<Compile Include="Net\Game\IGameClient.cs" />
135135
<Compile Include="Net\IClient.cs" />
136+
<Compile Include="Net\NATConfig.cs" />
137+
<Compile Include="Net\Utils.cs" />
136138
<Compile Include="Program.cs" />
137139
<Compile Include="Net\Connection.cs" />
138140
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -295,4 +297,7 @@
295297
<Name>Gibbed.Helpers</Name>
296298
</ProjectReference>
297299
</ItemGroup>
300+
<ItemGroup>
301+
<Folder Include="Net\NAT\" />
302+
</ItemGroup>
298303
</Project>

source/D3Sharp/Net/BNet/Config.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace D3Sharp.Net.BNet
2020
{
2121
public sealed class Config: Core.Config.Config
2222
{
23-
public string BindIP { get { return this.GetString("BindIP", "0.0.0.0"); } set { this.Set("Port", value); } }
23+
public string BindIP { get { return this.GetString("BindIP", "0.0.0.0"); } set { this.Set("BindIP", value); } }
2424
public int Port { get { return this.GetInt("Port", 1345); } set { this.Set("Port", value); } }
2525

2626
private static readonly Config _instance = new Config();

source/D3Sharp/Net/Game/GameAttribute.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
using System;
1+
/*
2+
* Copyright (C) 2011 D3Sharp Project
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
using System;
220
using System.Collections.Generic;
321
using System.Linq;
422
using System.Text;

source/D3Sharp/Net/Game/GameBitBuffer.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
using System;
1+
/*
2+
* Copyright (C) 2011 D3Sharp Project
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
using System;
220
using System.Collections.Generic;
321
using System.Linq;
422
using System.Text;

source/D3Sharp/Net/Game/GameClient.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* along with this program; if not, write to the Free Software
1616
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717
*/
18+
1819
using System;
1920
using System.IO;
2021
using System.Linq;

source/D3Sharp/Net/Game/GameMessage.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
using System;
1+
/*
2+
* Copyright (C) 2011 D3Sharp Project
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
using System;
220
using System.Collections.Generic;
321
using System.Linq;
422
using System.Text;

source/D3Sharp/Net/Game/GameMessageTypes.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
using System;
1+
/*
2+
* Copyright (C) 2011 D3Sharp Project
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
using System;
220
using System.Text;
321

422
namespace D3Sharp.Net.Game

source/D3Sharp/Net/IClient.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
using System;
1+
/*
2+
* Copyright (C) 2011 D3Sharp Project
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
using System;
220
using System.Collections.Generic;
321
using System.Linq;
422
using System.Text;

source/D3Sharp/Net/NATConfig.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2011 D3Sharp Project
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
namespace D3Sharp.Net
20+
{
21+
public sealed class NATConfig: Core.Config.Config
22+
{
23+
public bool Enabled { get { return this.GetBoolean("Enabled", true); } set { this.Set("Enabled", value); } }
24+
public string PublicIP { get { return this.GetString("PublicIP", "0.0.0.0"); } set { this.Set("PublicIP", value); } }
25+
26+
private static readonly NATConfig _instance = new NATConfig();
27+
public static NATConfig Instance { get { return _instance; } }
28+
private NATConfig() : base("NAT") { }
29+
}
30+
}

source/D3Sharp/Net/Utils.cs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2011 D3Sharp Project
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Linq;
22+
using System.Net;
23+
using System.Net.NetworkInformation;
24+
using System.Text;
25+
using D3Sharp.Net.BNet;
26+
27+
namespace D3Sharp.Net
28+
{
29+
public static class Utils
30+
{
31+
public static readonly IPAddress LocalHost = IPAddress.Parse("127.0.0.1");
32+
33+
public static string GetGameServerIPForClient(BNetClient client)
34+
{
35+
if (!NATConfig.Instance.Enabled) // if NAT is not enabled, just return bnetclient's localendpoint address.
36+
return client.Connection.LocalEndPoint.Address.ToString();
37+
else
38+
{
39+
return client.Connection.LocalEndPoint.Address.ToString() == "127.0.0.1"
40+
? client.Connection.LocalEndPoint.ToString()
41+
: NATConfig.Instance.PublicIP; // if client is not connected over localhost, send him public-ip.
42+
43+
// Known problems: If user enables NAT, LAN-clients (and even local-computer if d3 is configured to use lan-ip) will not able to connect in gs.
44+
// That needs a full implementation similar to pvpgn where we currently pretty miss the time for /raist.
45+
}
46+
}
47+
}
48+
}

source/D3Sharp/config.ini

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2-
;
3-
; D3Sharp Configuration File - Usage Placeholder
4-
;
5-
; Replace IPs with your external IP if you want to be able to access D3Sharp remotely
6-
;
2+
; ;
3+
; D3Sharp Configuration File ;
4+
; ;
5+
;-----------------------------------------------------------------------------------------------------------------;
6+
; ;
7+
; This file is an example configuration and may require modification to suit your needs. ;
8+
; ;
79
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
810

9-
; Paths and such
11+
12+
; Persistent storage settings
1013
[Storage]
1114
AssetsRoot=.
1215

@@ -21,3 +24,12 @@ BindIP = 0.0.0.0
2124
Port = 1999
2225
Map = Assets/Maps/001.txt
2326

27+
; Network address translation settings
28+
; You only need to change this if you're running behind a dsl router or so.
29+
; Important: If you enable NAT, LAN-clients will not able to connect in gs.
30+
; (Will be fixed later with a proper implementation similar to one in pvpgn).
31+
[NAT]
32+
Enabled = false
33+
PublicIP = 0.0.0.0 ; You need to change this to your router's public interface IP if you'd like to use NAT.
34+
35+

0 commit comments

Comments
 (0)