/// <summary> /// Constructs an instance for management of a world server. /// </summary> /// <param name="domain">The address of the world server (domain or IP address).</param> /// <param name="port">The port of the world server.</param> /// <param name="password">The password required to login to the world server.</param> /// <exception cref="InstanceCreationFailedException">Thrown when the instance failed to be created.</exception> public Instance(string domain, int port, string password) { IntPtr tempInstance; int rc = NativeMethods.aw_server_admin(domain, port, password, out tempInstance); SDKWrapperException <InstanceCreationFailedException> .Assert(rc); _instance = tempInstance; }
/// <summary> /// Constructs an instance for a non-default universe. /// </summary> /// <param name="address">IP address of the universe server represented as a 32-bit unsigned integer. The IP address is stored according to Network Byte Order.</param> /// <param name="port">Port number of the universe server.</param> /// <exception cref="InstanceCreationFailedException">Thrown when the instance failed to be created.</exception> public Instance(int address, int port) { IntPtr tempInstance; int rc = NativeMethods.aw_create_resolved(address, port, out tempInstance); SDKWrapperException <InstanceCreationFailedException> .Assert(rc); _instance = tempInstance; Attributes = new AttributeProvider(this); }
/// <summary> /// Constructs an instance for a non-default universe. /// </summary> /// <param name="domain">Unresolved domain name (i.e. auth.activeworlds.com).</param> /// <param name="port">Port number of the universe server.</param> /// <exception cref="InstanceCreationFailedException">Thrown when the instance failed to be created.</exception> public Instance(string domain, int port) { IntPtr tempInstance; int rc = NativeMethods.aw_create(domain, port, out tempInstance); SDKWrapperException <InstanceCreationFailedException> .Assert(rc); _instance = tempInstance; Attributes = new AttributeProvider(this); }
/// <summary> /// Internal method for setting the current instance being operated on to the class specific instance. /// </summary> private void SetInstance() { if (NativeMethods.aw_instance() == _instance) { return; } int rc = NativeMethods.aw_instance_set(_instance); SDKWrapperException <InstanceSetFailedException> .Assert(rc); }
/// <summary> /// Used to destroy the current <see cref="AW.Instance" />. /// </summary> /// <remarks> /// This will destroy the instance. All references to the instance should be broken after calling this method. /// Any attempts to operate on an instance after it has been disposed will result in an exception being thrown. /// </remarks> public void Dispose() { _disposed = true; if (Disposing != null) { Disposing(this, new EventCancelToken()); } if (Utility.Initialized) { SetInstance(); int rc = NativeMethods.aw_destroy(); SDKWrapperException <InstanceDisposeFailedException> .Assert(rc); } GC.Collect(); }
public void SetData(Attributes attribute, byte[] value) { SetInstance(); IntPtr dest = Marshal.AllocHGlobal(value.Length); int errorCode; try { Marshal.Copy(value, 0, dest, value.Length); errorCode = NativeMethods.aw_data_set(attribute, dest, value.Length); } finally { Marshal.FreeHGlobal(dest); } SDKWrapperException <InstanceAttributeException> .Assert(errorCode); }
#pragma warning restore 169 /// <summary> /// Static constructor. This initializes the SDK the first time an instance is created. /// </summary> static Instance() { SDKWrapperException <SDKWrapperInitializationFailedException> .Assert(Utility.Initialize()); }
/// <summary> /// Sets a floating point attribute for the current instance. /// </summary> /// <param name="attribute">The attribute to be set.</param> /// <param name="value">The value of the attribute being set.</param> /// <exception cref="AW.InstanceAttributeException">Thrown when the instance failed to set the attribute.</exception> /// <exception cref="AW.InstanceSetFailedException">Thrown when the instance cannot be set properly. /// (i.e. the instance has been destroyed or is not valid).</exception> public void SetFloat(Attributes attribute, float value) { SetInstance(); SDKWrapperException <InstanceAttributeException> .Assert(NativeMethods.aw_float_set(attribute, value)); }
/// <summary> /// Sets a boolean attribute for the current instance. /// </summary> /// <param name="attribute">The attribute to be set.</param> /// <param name="value">The value of the attribute being set.</param> /// <exception cref="AW.InstanceAttributeException">Thrown when the instance failed to set the attribute.</exception> /// <exception cref="AW.InstanceSetFailedException">Thrown when the instance cannot be set properly. /// (i.e. the instance has been destroyed or is not valid).</exception> public void SetBool(Attributes attribute, bool value) { SetInstance(); SDKWrapperException <InstanceAttributeException> .Assert(NativeMethods.aw_bool_set(attribute, value)); }
/// <summary> /// Sets a string attribute for the current instance. /// </summary> /// <param name="attribute">The attribute to be set.</param> /// <param name="value">The value of the attribute being set.</param> public void SetString(Attributes attribute, string value) { SetInstance(); SDKWrapperException <InstanceAttributeException> .Assert(NativeMethods.aw_string_set(attribute, value)); }