Skip to content

Commit

Permalink
Implements world.address & friends, adds remaining opendream_unimplem…
Browse files Browse the repository at this point in the history
…ented world vars/procs (#774)

* Implements several world networking meta-vars

world.address
world.port
world.url
world.internet_address

EDIT: Does some various tweaking as per Wixoa's review

* Adds several more world unimplemented vars, defines

This should improve compile-ability, especially movement_mode.

EDIT: MOVEMENT_MODE macros now start at 0 instead of 1, as per parity
EDIT: Forgot to add cache_lifespan, lol
EDIT: Removing cache_lifespan since it now exists on master apparently

* Dials PR back a bit, TODO'd internet_address & url

EDIT: also does Wixoa's new review
  • Loading branch information
Altoids1 authored Oct 26, 2022
1 parent b822731 commit 6e77bf9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
5 changes: 5 additions & 0 deletions DMCompiler/DMStandard/Defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@
#define SIDE_MAP 2
#define TILED_ICON_MAP 32768

//world.movement_mode
#define LEGACY_MOVEMENT_MODE 0
#define TILE_MOVEMENT_MODE 1
#define PIXEL_MOVEMENT_MODE 2

//generator() distributions
#define UNIFORM_RAND 0
#define NORMAL_RAND 1
Expand Down
12 changes: 10 additions & 2 deletions DMCompiler/DMStandard/Types/World.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@
var/cpu = 0 as opendream_unimplemented
var/fps = null
var/tick_usage
var/loop_checks = 0 as opendream_unimplemented

var/maxx = 0
var/maxy = 0
var/maxz = 0
var/icon_size = 32
var/view = 5
var/movement_mode = LEGACY_MOVEMENT_MODE as opendream_unimplemented

var/byond_version = DM_VERSION
var/byond_build = DM_BUILD

var/version = 0 as opendream_unimplemented

var/address
var/port
var/port = 0 as opendream_compiletimereadonly
var/internet_address = "127.0.0.1" as opendream_unimplemented
var/url
var/url as opendream_unimplemented
var/visibility = 0 as opendream_unimplemented
var/status as opendream_unimplemented
var/list/params = list() as opendream_unimplemented

Expand Down Expand Up @@ -59,6 +62,9 @@
set opendream_unimplemented = TRUE
proc/IsSubscribed(player, type)
set opendream_unimplemented = TRUE
proc/IsBanned(key,address,computer_id,type)
set opendream_unimplemented = TRUE
return FALSE;

proc/Reboot()
set opendream_unimplemented = TRUE
Expand All @@ -67,6 +73,8 @@
set opendream_unimplemented = TRUE

proc/Export(Addr, File, Persist, Clients)
proc/Import()
set opendream_unimplemented = TRUE

proc/SetScores()
set opendream_unimplemented = TRUE
Expand Down
2 changes: 2 additions & 0 deletions OpenDreamRuntime/DreamManager.Connections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Robust.Server.Player;
using Robust.Shared.Enums;
using Robust.Shared.Network;
using System.Net;
using System.Net.Sockets;

namespace OpenDreamRuntime
{
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamRuntime/IDreamManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Objects;
using Robust.Server.Player;

namespace OpenDreamRuntime {
Expand Down
63 changes: 57 additions & 6 deletions OpenDreamRuntime/Objects/MetaObjects/DreamMetaObjectWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using Robust.Shared.Network;
using System.Net;
using System.Net.Sockets;

namespace OpenDreamRuntime.Objects.MetaObjects {
sealed class DreamMetaObjectWorld : IDreamMetaObject {
public bool ShouldCallNew => false; // Gets called manually later
public IDreamMetaObject? ParentType { get; set; }

[Dependency] private readonly IDreamManager _dreamManager = default!;
[Dependency] private readonly IServerNetManager _netManager = default!;
[Dependency] private readonly DreamResourceManager _dreamRscMan = default!;
[Dependency] private readonly IDreamMapManager _dreamMapManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
Expand All @@ -19,6 +23,35 @@ sealed class DreamMetaObjectWorld : IDreamMetaObject {
private ViewRange _viewRange;

private double TickLag => _gameTiming.TickPeriod.TotalMilliseconds / 100;
/// <summary> Determines whether we try to show IPv6 or IPv4 to the user during .address and .internet_address queries.</summary>
private bool DisplayIPv6
{
get
{
var binds = _cfg.GetCVar(CVars.NetBindTo).Split(',');
foreach (var bindAddress in binds)
{
if (!IPAddress.TryParse(bindAddress.Trim(), out var address)) // EXTREMELY unlikely since RT does this same check on network startup
{
continue;
}

if (address.AddressFamily == AddressFamily.InterNetworkV6)
{
return true;
}
}
return false;
}
}
/// <summary> Tries to return the address of the server, as it appears over the internet. May return null.</summary>
private IPAddress? InternetAddress
{
get
{
return null; //TODO: Implement this!
}
}

public DreamMetaObjectWorld() {
IoCManager.InjectDependencies(this);
Expand Down Expand Up @@ -100,12 +133,30 @@ public DreamValue OnVariableGet(DreamObject dreamObject, string varName, DreamVa
return new DreamValue(_dreamMapManager.Size.Y);
case "maxz":
return new DreamValue(_dreamMapManager.Levels);
//case "address":
// return new(Runtime.Server.Address.ToString());
//case "port":
// return new(Runtime.Server.Port);
//case "url":
// return new("opendream://" + Runtime.Server.Address + ":" + Runtime.Server.Port);
case "address": // By address they mean, the local address we have on the network, not on the internet.
var host = Dns.GetHostEntry(Dns.GetHostName());
var ipType = DisplayIPv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == ipType)
{
return new DreamValue(ip.ToString());
}
}
return DreamValue.Null;
case "port":
return new DreamValue(_netManager.Port);
case "url":
if (InternetAddress == null)
return DreamValue.Null;
return new(InternetAddress + ":" + _netManager.Port); // RIP "opendream://"
case "internet_address":
IPAddress? address = InternetAddress;
// We don't need to do any logic with DisplayIPv6 since whatever this address is,
// ought to be the address that the boolean's getter is searching for anyways.
if (address == null)
return DreamValue.Null;
return new(address.ToString());
case "system_type": {
//system_type value should match the defines in Defines.dm
if (Environment.OSVersion.Platform is PlatformID.Unix or PlatformID.MacOSX or PlatformID.Other) {
Expand Down

0 comments on commit 6e77bf9

Please sign in to comment.