public static void WriteDataUpdate(BinWriter w, BinaryTree values, object obj, bool clear, bool isClient) { try { //Console.WriteLine("Type: "+obj.GetType()); UpdateObjectInfo info = (UpdateObjectInfo)m_updateObjectInfos[obj.GetType()]; if (info == null) { throw new ObjectUpdateManagerException("UpdateObjectInfo is missing for type " + obj.GetType()); } if (!isClient && obj.GetType() == typeof(PlayerObject)) { info.MaxFields = (int)PLAYERFIELDS.MAX_NOTCLIENT; info.BlockSize = (byte)((info.MaxFields + 31) / 32); } w.Write(info.BlockSize); byte[] mask = new byte[info.BlockSize * 4]; IEnumerator e = values.GetEnumerator(); Hashtable tbl = info.tbl; long maskPos = w.BaseStream.Position; w.BaseStream.Position += mask.Length; while (e.MoveNext()) { if ((!isClient && ((int)e.Current <= (int)PLAYERFIELDS.MAX_NOTCLIENT)) || (isClient)) { IUpdateValue updater = (IUpdateValue)tbl[(int)e.Current]; if (updater == null) { throw new ObjectUpdateManagerException("UpdateValue Handler is missing for field " + e.Current + " in " + obj.GetType().ToString()); } updater.WriteValue(obj, w, mask); } } long pos = w.BaseStream.Position; w.BaseStream.Position = maskPos; w.Write(mask, 0, mask.Length); w.BaseStream.Position = pos; if (clear) { values.Clear(); } else { e.Reset(); } } catch (Exception exp) { DebugLogger.Log("", exp); } }
public static void WriteDataUpdate(BinWriter w, BinaryTree values, object obj, bool clear) { UpdateObjectInfo info = (UpdateObjectInfo)m_updateObjectInfos[obj.GetType()]; if (info == null) { throw new ObjectUpdateManagerException("UpdateObjectInfo is missing for type " + obj.GetType()); } w.Write(info.BlockSize); byte[] mask = new byte[info.BlockSize * 4]; IEnumerator e = values.GetEnumerator(); Hashtable tbl = info.tbl; long maskPos = w.BaseStream.Position; w.BaseStream.Position += mask.Length; while (e.MoveNext()) { IUpdateValue updater = (IUpdateValue)tbl[(int)e.Current]; if (updater == null) { throw new ObjectUpdateManagerException("UpdateValue Handler is missing for field " + e.Current + " in " + obj.GetType().ToString()); } updater.WriteValue(obj, w, mask); } long pos = w.BaseStream.Position; w.BaseStream.Position = maskPos; w.Write(mask, 0, mask.Length); w.BaseStream.Position = pos; if (clear) { values.Clear(); } else { e.Reset(); } }
public static void RegisterUpdateObject(Type type) { try { object[] tmp = type.GetCustomAttributes(typeof(UpdateObjectAttribute), true); if (tmp.Length == 0) { throw new ObjectUpdateManagerException(type.ToString() + " has no UpdateObjectAttribute"); } UpdateObjectAttribute updateObjectAttribute = (UpdateObjectAttribute)tmp[0]; if (updateObjectAttribute.MaxFields == -1) { throw new ObjectUpdateManagerException("MaxFields is not set in UpdateObjectAttribute on " + type.ToString()); } Hashtable tbl = new Hashtable(); foreach (MemberValue value in MemberValue.GetMemberValues(type, typeof(UpdateValueAttribute), true, false)) { UpdateValueAttribute attrib = (UpdateValueAttribute)value.Attribute; if (!checkType(attrib, type)) { continue; } Type valueType = value.GetValueType(); if (valueType.IsArray == false) { if (!IsSubClass(valueType)) { if (attrib.Field == -1) { throw new ObjectUpdateManagerException("Field was not set on " + type.Name + value.GetName()); } if (value is IndexMemberValue) { IndexMemberValue indexValue = value as IndexMemberValue; if (valueType == typeof(ulong) || valueType == typeof(long)) { AddUpdateValue(tbl, value, attrib.Field + indexValue.Index * 2); } else { AddUpdateValue(tbl, value, attrib.Field + indexValue.Index); } } else { AddUpdateValue(tbl, value, attrib.Field); } } else { GetSubClassUpdateValues(tbl, value, attrib.Field == -1 ? 0 : attrib.Field, valueType, type); } } else { if (attrib.ArraySize == -1) { throw new ObjectUpdateManagerException("ArraySize was not set on " + type.Name + "." + value.GetName()); } if (attrib.Field == -1) { throw new ObjectUpdateManagerException("Field was not set on the array " + type.Name + "." + value.GetName()); } if (attrib.NumSubFields == -1) { throw new ObjectUpdateManagerException("NumFields was not set on the subclass array " + type.Name + "." + value.GetName()); } valueType = valueType.GetElementType(); for (int i = 0; i < attrib.ArraySize; i++) { IndexMemberValue indexValue = new IndexMemberValue(value, i); GetSubClassUpdateValues(tbl, indexValue, attrib.Field + i * attrib.NumSubFields, valueType, type); } } } if (tbl.Count == 0) { throw new ObjectUpdateManagerException("No update values in " + type.ToString()); } UpdateObjectInfo uoi = new UpdateObjectInfo(tbl, updateObjectAttribute.MaxFields); m_updateObjectInfos[type] = uoi; } catch (Exception exp) { DebugLogger.Log("", exp); } }