diff --git a/INetState.cs b/INetState.cs
new file mode 100644
index 0000000..7e23eca
--- /dev/null
+++ b/INetState.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RedGrin
+{
+ public interface INetState
+ {
+ }
+}
diff --git a/INetworkArena.cs b/INetworkArena.cs
index 60638b7..b9b40cd 100644
--- a/INetworkArena.cs
+++ b/INetworkArena.cs
@@ -22,7 +22,7 @@ public interface INetworkArena
/// The unique ID of the entity to create
/// The initial state of the created entity
/// The created INetworkEntity, which will be tracked by the NetworkManager
- INetworkEntity RequestCreateEntity(long ownerId, long entityId, object entityData);
+ INetworkEntity RequestCreateEntity(object entityData);
///
/// Called by the network manager when a message is received to destroy an entity.
diff --git a/INetworkEntity.cs b/INetworkEntity.cs
index 05a22ff..ffe16f5 100644
--- a/INetworkEntity.cs
+++ b/INetworkEntity.cs
@@ -44,6 +44,6 @@ public interface INetworkEntity
/// A generic object describing an entity state
/// The time this state was received, compare to current network time to understand elapsed time
/// Whether or not this is a dead reckoning update
- void UpdateState(object entityState, double stateTime, bool isReckoningState = false);
+ void UpdateState(object entityState, double stateTime);
}
}
diff --git a/NetworkManager.cs b/NetworkManager.cs
index ca205da..4632f27 100644
--- a/NetworkManager.cs
+++ b/NetworkManager.cs
@@ -17,6 +17,19 @@ public class NetworkManager
public event NetworkEvent Connected;
public event NetworkEvent Disconnected;
+ static NetworkManager self;
+ public static NetworkManager Self
+ {
+ get
+ {
+ if(self == null)
+ {
+ throw new InvalidOperationException("NetworkManager must first be constructed in a class such as Game1");
+ }
+ return self;
+ }
+ }
+
///
/// The seconds the last update happened.
///
@@ -155,6 +168,7 @@ public INetworkArena GameArena
/// An ILogger to write messages to
public NetworkManager(NetworkConfiguration config, ILogger log = null)
{
+ self = this;
Configuration = config;
// if no logger was provided, use NullLogger
mLog = log ?? new NullLogger();
@@ -421,7 +435,7 @@ private void CreateEntity(long ownerId, long entityId, object payload, double ti
if(targetEntity == null)
{
- targetEntity = GameArena.RequestCreateEntity(ownerId, entityId, payload);
+ targetEntity = GameArena.RequestCreateEntity(payload);
}
else
{
@@ -430,9 +444,9 @@ private void CreateEntity(long ownerId, long entityId, object payload, double ti
throw new RedGrinException(msg);
}
+ targetEntity.UpdateState(payload, time);
targetEntity.OwnerId = ownerId;
targetEntity.EntityId = entityId;
- targetEntity.UpdateState(payload, time);
mEntities.Add(targetEntity);
BroadcastIfServer(entityId, ownerId, payload, NetworkMessageType.Create);
@@ -472,7 +486,10 @@ private void UpdateEntity(long entityId, long ownerId, object payload, bool isRe
// ignore if null, entity creation message may not have arrived
if(targetEntity != null)
{
- targetEntity.UpdateState(payload, time, isReckoning);
+ if(targetEntity.OwnerId != this.NetworkId || isReckoning)
+ {
+ targetEntity.UpdateState(payload, time);
+ }
BroadcastIfServer(entityId, targetEntity.OwnerId, payload,
isReckoning ?
@@ -605,6 +622,19 @@ private void SendDataMessage(INetworkEntity entity, NetworkMessageType action, N
SendDataMessage(entity.EntityId, entity.OwnerId, payload, action, recipient);
}
+ public string GetLocalIpAddress()
+ {
+ var host = Dns.GetHostEntry(Dns.GetHostName());
+ foreach (var ip in host.AddressList)
+ {
+ if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
+ {
+ return ip.ToString();
+ }
+ }
+ return null;
+ }
+
///
/// Composes and sends a data message.
///
diff --git a/RedGrin.csproj b/RedGrin.csproj
index f246d96..2057067 100644
--- a/RedGrin.csproj
+++ b/RedGrin.csproj
@@ -66,6 +66,7 @@
+