Skip to content

Commit

Permalink
Unified the ecsync messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
pallarim committed Oct 7, 2010
1 parent 4b68791 commit 57474ff
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions ModularRex/RexParts/EntityComponentModule.cs
Expand Up @@ -135,12 +135,9 @@ private void HandleGenericBinaryMessage(object sender, string method, byte[][] a
switch (method.ToLower())
{
case "ecsync":
if (args.Length >= 4)
if (args.Length >= 2)
{
entityId = new UUID(Util.FieldToString(args[0]));
componentType = Util.FieldToString(args[1]);
componentName = Util.FieldToString(args[2]);

int rpdLen = 0;
int idx = 0;

Expand All @@ -152,13 +149,37 @@ private void HandleGenericBinaryMessage(object sender, string method, byte[][] a
data = new byte[rpdLen];

//copy rest of the arrays to one arrays
for (int i = 3; i < args.Length; i++)
for (int i = 1; i < args.Length; i++)
{
args[i].CopyTo(data, idx);
idx += args[i].Length;
}
idx = 0;

//parse componentType from array
StringBuilder buffer = new StringBuilder();
while ((idx < data.Length) && (data[idx] != 0))
{
char c = (char)bytes[idx++];
buffer.Append(c);
}
componentType = buffer.ToString();
idx++;

//parse componentName from array
buffer = new StringBuilder();
while ((idx < data.Length) && (data[idx] != 0))
{
char c = (char)bytes[idx++];
buffer.Append(c);
}
componentName = buffer.ToString();
idx++;

byte[] ecdata = new byte[data.Length - idx];
Buffer.BlockCopy(data, idx, ecdata, data.Length - idx);

SaveECData(sender, new ECData(entityId, componentType, componentName, data, false));
SaveECData(sender, new ECData(entityId, componentType, componentName, ecdata, false));
}
break;
default:
Expand Down Expand Up @@ -221,7 +242,7 @@ public void SendECDataToAll(ECData component)
{
((NaaliClientView)client).SendECData(component);
}
}
}, true
);
}
}
Expand All @@ -240,9 +261,9 @@ public void SendECRemovedToAll(UUID entityId, string componentType, string compo
{
if (client is NaaliClientView)
{
((NaaliClientView)client).SendGenericMessage("ecremoved", msgArgs);
((NaaliClientView)client).SendGenericMessage("ecremove", msgArgs);
}
}
}, true
);
}
}
Expand All @@ -260,6 +281,9 @@ public bool SaveECData(object sender, ECData component)
if (save)
{
SaveLocal(component);

SendECDataToAll(component);

if (m_db_initialized)
return m_db.StoreComponent(component);
}
Expand Down Expand Up @@ -292,6 +316,8 @@ public bool RemoveECData(object sender, ECData component)

m_entity_components[component.EntityID].Components.Remove(new KeyValuePair<string, string>(component.ComponentType, component.ComponentName));

SendECRemovedToAll(component.EntityID, component.ComponentType, component.ComponentName);

if (m_db_initialized)
return m_db.RemoveComponent(component);
}
Expand Down

0 comments on commit 57474ff

Please sign in to comment.