#W# Initial Commit: Avatars Conquest
This commit is contained in:
commit
5df497787a
7510 changed files with 416048 additions and 0 deletions
212
Source/AggressorInfo.cs
Normal file
212
Source/AggressorInfo.cs
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
/***************************************************************************
|
||||
* AggressorInfo.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public class AggressorInfo
|
||||
{
|
||||
private Mobile m_Attacker, m_Defender;
|
||||
private DateTime m_LastCombatTime;
|
||||
private bool m_CanReportMurder;
|
||||
private bool m_Reported;
|
||||
private bool m_CriminalAggression;
|
||||
|
||||
private bool m_Queued;
|
||||
|
||||
private static Queue<AggressorInfo> m_Pool = new Queue<AggressorInfo>();
|
||||
|
||||
public static AggressorInfo Create( Mobile attacker, Mobile defender, bool criminal )
|
||||
{
|
||||
AggressorInfo info;
|
||||
|
||||
if ( m_Pool.Count > 0 )
|
||||
{
|
||||
info = m_Pool.Dequeue();
|
||||
|
||||
info.m_Attacker = attacker;
|
||||
info.m_Defender = defender;
|
||||
|
||||
info.m_CanReportMurder = criminal;
|
||||
info.m_CriminalAggression = criminal;
|
||||
|
||||
info.m_Queued = false;
|
||||
|
||||
info.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
info = new AggressorInfo( attacker, defender, criminal );
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public void Free()
|
||||
{
|
||||
if ( m_Queued )
|
||||
return;
|
||||
|
||||
m_Queued = true;
|
||||
m_Pool.Enqueue( this );
|
||||
}
|
||||
|
||||
private AggressorInfo( Mobile attacker, Mobile defender, bool criminal )
|
||||
{
|
||||
m_Attacker = attacker;
|
||||
m_Defender = defender;
|
||||
|
||||
m_CanReportMurder = criminal;
|
||||
m_CriminalAggression = criminal;
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private static TimeSpan m_ExpireDelay = TimeSpan.FromMinutes( 2.0 );
|
||||
|
||||
public static TimeSpan ExpireDelay
|
||||
{
|
||||
get{ return m_ExpireDelay; }
|
||||
set{ m_ExpireDelay = value; }
|
||||
}
|
||||
|
||||
public static void DumpAccess()
|
||||
{
|
||||
using ( StreamWriter op = new StreamWriter( "warnings.log", true ) )
|
||||
{
|
||||
op.WriteLine( "Warning: Access to queued AggressorInfo:" );
|
||||
op.WriteLine( new System.Diagnostics.StackTrace() );
|
||||
op.WriteLine();
|
||||
op.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Expired
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
return ( m_Attacker.Deleted || m_Defender.Deleted || DateTime.Now >= (m_LastCombatTime + m_ExpireDelay) );
|
||||
}
|
||||
}
|
||||
|
||||
public bool CriminalAggression
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
return m_CriminalAggression;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
m_CriminalAggression = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Mobile Attacker
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
return m_Attacker;
|
||||
}
|
||||
}
|
||||
|
||||
public Mobile Defender
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
return m_Defender;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime LastCombatTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
return m_LastCombatTime;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Reported
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
return m_Reported;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
m_Reported = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanReportMurder
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
return m_CanReportMurder;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
m_CanReportMurder = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if ( m_Queued )
|
||||
DumpAccess();
|
||||
|
||||
m_LastCombatTime = DateTime.Now;
|
||||
m_Reported = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
81
Source/AssemblyInfo.cs
Normal file
81
Source/AssemblyInfo.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/***************************************************************************
|
||||
* AssemblyInfo.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
//
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
//
|
||||
[assembly: AssemblyTitle("Ultima Server")] //Having just RunUO there is reundant, ie, RunUO.exe with the word 'RunUO' under it
|
||||
[assembly: AssemblyDescription("World of Adventure")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
//
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("2.1.*")]
|
||||
|
||||
//
|
||||
// In order to sign your assembly you must specify a key to use. Refer to the
|
||||
// Microsoft .NET Framework documentation for more information on assembly signing.
|
||||
//
|
||||
// Use the attributes below to control which key is used for signing.
|
||||
//
|
||||
// Notes:
|
||||
// (*) If no key is specified, the assembly is not signed.
|
||||
// (*) KeyName refers to a key that has been installed in the Crypto Service
|
||||
// Provider (CSP) on your machine. KeyFile refers to a file which contains
|
||||
// a key.
|
||||
// (*) If the KeyFile and the KeyName values are both specified, the
|
||||
// following processing occurs:
|
||||
// (1) If the KeyName can be found in the CSP, that key is used.
|
||||
// (2) If the KeyName does not exist and the KeyFile does exist, the key
|
||||
// in the KeyFile is installed into the CSP and used.
|
||||
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
|
||||
// When specifying the KeyFile, the location of the KeyFile should be
|
||||
// relative to the project output directory which is
|
||||
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
|
||||
// located in the project directory, you would specify the AssemblyKeyFile
|
||||
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
|
||||
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
|
||||
// documentation for more information on this.
|
||||
//
|
||||
[assembly: AssemblyDelaySign(false)]
|
||||
[assembly: AssemblyKeyFile("")]
|
||||
[assembly: AssemblyKeyName("")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
224
Source/Attributes.cs
Normal file
224
Source/Attributes.cs
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
/***************************************************************************
|
||||
* Attributes.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
[AttributeUsage( AttributeTargets.Property )]
|
||||
public class HueAttribute : Attribute
|
||||
{
|
||||
public HueAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage( AttributeTargets.Property )]
|
||||
public class BodyAttribute : Attribute
|
||||
{
|
||||
public BodyAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage( AttributeTargets.Class | AttributeTargets.Struct )]
|
||||
public class PropertyObjectAttribute : Attribute
|
||||
{
|
||||
public PropertyObjectAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage( AttributeTargets.Class | AttributeTargets.Struct )]
|
||||
public class NoSortAttribute : Attribute
|
||||
{
|
||||
public NoSortAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage( AttributeTargets.Method )]
|
||||
public class CallPriorityAttribute : Attribute
|
||||
{
|
||||
private int m_Priority;
|
||||
|
||||
public int Priority
|
||||
{
|
||||
get{ return m_Priority; }
|
||||
set{ m_Priority = value; }
|
||||
}
|
||||
|
||||
public CallPriorityAttribute( int priority )
|
||||
{
|
||||
m_Priority = priority;
|
||||
}
|
||||
}
|
||||
|
||||
public class CallPriorityComparer : IComparer<MethodInfo>
|
||||
{
|
||||
public int Compare( MethodInfo x, MethodInfo y )
|
||||
{
|
||||
if ( x == null && y == null )
|
||||
return 0;
|
||||
|
||||
if ( x == null )
|
||||
return 1;
|
||||
|
||||
if ( y == null )
|
||||
return -1;
|
||||
|
||||
return GetPriority( x ) - GetPriority( y );
|
||||
}
|
||||
|
||||
private int GetPriority( MethodInfo mi )
|
||||
{
|
||||
object[] objs = mi.GetCustomAttributes( typeof( CallPriorityAttribute ), true );
|
||||
|
||||
if ( objs == null )
|
||||
return 0;
|
||||
|
||||
if ( objs.Length == 0 )
|
||||
return 0;
|
||||
|
||||
CallPriorityAttribute attr = objs[0] as CallPriorityAttribute;
|
||||
|
||||
if ( attr == null )
|
||||
return 0;
|
||||
|
||||
return attr.Priority;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage( AttributeTargets.Class )]
|
||||
public class TypeAliasAttribute : Attribute
|
||||
{
|
||||
private string[] m_Aliases;
|
||||
|
||||
public string[] Aliases
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Aliases;
|
||||
}
|
||||
}
|
||||
|
||||
public TypeAliasAttribute( params string[] aliases )
|
||||
{
|
||||
m_Aliases = aliases;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage( AttributeTargets.Class | AttributeTargets.Struct )]
|
||||
public class ParsableAttribute : Attribute
|
||||
{
|
||||
public ParsableAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage( AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum )]
|
||||
public class CustomEnumAttribute : Attribute
|
||||
{
|
||||
private string[] m_Names;
|
||||
|
||||
public string[] Names
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Names;
|
||||
}
|
||||
}
|
||||
|
||||
public CustomEnumAttribute( string[] names )
|
||||
{
|
||||
m_Names = names;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage( AttributeTargets.Constructor )]
|
||||
public class ConstructableAttribute : Attribute
|
||||
{
|
||||
private AccessLevel m_AccessLevel;
|
||||
|
||||
public AccessLevel AccessLevel
|
||||
{
|
||||
get { return m_AccessLevel; }
|
||||
set { m_AccessLevel = value; }
|
||||
}
|
||||
|
||||
public ConstructableAttribute() : this( AccessLevel.Player ) //Lowest accesslevel for current functionality (Level determined by access to [add)
|
||||
{
|
||||
}
|
||||
|
||||
public ConstructableAttribute( AccessLevel accessLevel )
|
||||
{
|
||||
m_AccessLevel = accessLevel;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage( AttributeTargets.Property )]
|
||||
public class CommandPropertyAttribute : Attribute
|
||||
{
|
||||
private AccessLevel m_ReadLevel, m_WriteLevel;
|
||||
private bool m_ReadOnly;
|
||||
|
||||
public AccessLevel ReadLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ReadLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public AccessLevel WriteLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_WriteLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ReadOnly;
|
||||
}
|
||||
}
|
||||
|
||||
public CommandPropertyAttribute( AccessLevel level, bool readOnly )
|
||||
{
|
||||
m_ReadLevel = level;
|
||||
m_ReadOnly = readOnly;
|
||||
}
|
||||
|
||||
public CommandPropertyAttribute( AccessLevel level ) : this( level, level )
|
||||
{
|
||||
}
|
||||
|
||||
public CommandPropertyAttribute( AccessLevel readLevel, AccessLevel writeLevel )
|
||||
{
|
||||
m_ReadLevel = readLevel;
|
||||
m_WriteLevel = writeLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
214
Source/BaseVendor.cs
Normal file
214
Source/BaseVendor.cs
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
/***************************************************************************
|
||||
* BaseVendor.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
using Server.ContextMenus;
|
||||
using Server.Mobiles;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Mobiles
|
||||
{
|
||||
public class BuyItemStateComparer : IComparer<BuyItemState>
|
||||
{
|
||||
public int Compare( BuyItemState l, BuyItemState r )
|
||||
{
|
||||
if ( l == null && r == null ) return 0;
|
||||
if ( l == null ) return -1;
|
||||
if ( r == null ) return 1;
|
||||
|
||||
return l.MySerial.CompareTo( r.MySerial );
|
||||
}
|
||||
}
|
||||
|
||||
public class BuyItemResponse
|
||||
{
|
||||
private Serial m_Serial;
|
||||
private int m_Amount;
|
||||
|
||||
public BuyItemResponse( Serial serial, int amount )
|
||||
{
|
||||
m_Serial = serial;
|
||||
m_Amount = amount;
|
||||
}
|
||||
|
||||
public Serial Serial
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Serial;
|
||||
}
|
||||
}
|
||||
|
||||
public int Amount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SellItemResponse
|
||||
{
|
||||
private Item m_Item;
|
||||
private int m_Amount;
|
||||
|
||||
public SellItemResponse( Item i, int amount )
|
||||
{
|
||||
m_Item = i;
|
||||
m_Amount = amount;
|
||||
}
|
||||
|
||||
public Item Item
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Item;
|
||||
}
|
||||
}
|
||||
|
||||
public int Amount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SellItemState
|
||||
{
|
||||
private Item m_Item;
|
||||
private int m_Price;
|
||||
private string m_Name;
|
||||
|
||||
public SellItemState( Item item, int price, string name )
|
||||
{
|
||||
m_Item = item;
|
||||
m_Price = price;
|
||||
m_Name = name;
|
||||
}
|
||||
|
||||
public Item Item
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Item;
|
||||
}
|
||||
}
|
||||
|
||||
public int Price
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Price;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class BuyItemState
|
||||
{
|
||||
private Serial m_ContSer;
|
||||
private Serial m_MySer;
|
||||
private int m_ItemID;
|
||||
private int m_Amount;
|
||||
private int m_Hue;
|
||||
private int m_Price;
|
||||
private string m_Desc;
|
||||
|
||||
public BuyItemState( string name, Serial cont, Serial serial, int price, int amount, int itemID, int hue )
|
||||
{
|
||||
m_Desc = name;
|
||||
m_ContSer = cont;
|
||||
m_MySer = serial;
|
||||
m_Price = price;
|
||||
m_Amount = amount;
|
||||
m_ItemID = itemID;
|
||||
m_Hue = hue;
|
||||
}
|
||||
|
||||
public int Price
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Price;
|
||||
}
|
||||
}
|
||||
|
||||
public Serial MySerial
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_MySer;
|
||||
}
|
||||
}
|
||||
|
||||
public Serial ContainerSerial
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ContSer;
|
||||
}
|
||||
}
|
||||
|
||||
public int ItemID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ItemID;
|
||||
}
|
||||
}
|
||||
|
||||
public int Amount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Amount;
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Hue;
|
||||
}
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
269
Source/Body.cs
Normal file
269
Source/Body.cs
Normal file
|
|
@ -0,0 +1,269 @@
|
|||
/***************************************************************************
|
||||
* Body.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public enum BodyType : byte
|
||||
{
|
||||
Empty,
|
||||
Monster,
|
||||
Sea,
|
||||
Animal,
|
||||
Human,
|
||||
Equipment
|
||||
}
|
||||
|
||||
public struct Body
|
||||
{
|
||||
private int m_BodyID;
|
||||
|
||||
private static BodyType[] m_Types;
|
||||
|
||||
static Body()
|
||||
{
|
||||
if ( File.Exists( "Data/Config/bodyTable.cfg" ) )
|
||||
{
|
||||
using ( StreamReader ip = new StreamReader( "Data/Config/bodyTable.cfg" ) )
|
||||
{
|
||||
m_Types = new BodyType[1000];
|
||||
|
||||
string line;
|
||||
|
||||
while ( (line = ip.ReadLine()) != null )
|
||||
{
|
||||
if ( line.Length == 0 || line.StartsWith( "#" ) )
|
||||
continue;
|
||||
|
||||
string[] split = line.Split( '\t' );
|
||||
|
||||
try
|
||||
{
|
||||
int bodyID = int.Parse( split[0] );
|
||||
BodyType type = (BodyType)Enum.Parse( typeof( BodyType ), split[1], true );
|
||||
|
||||
if ( bodyID >= 0 && bodyID < m_Types.Length )
|
||||
m_Types[bodyID] = type;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine( "Warning: Invalid bodyTable entry:" );
|
||||
Console.WriteLine( line );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine( "Warning: Data/Config/bodyTable.cfg does not exist" );
|
||||
|
||||
m_Types = new BodyType[0];
|
||||
}
|
||||
}
|
||||
|
||||
public Body( int bodyID )
|
||||
{
|
||||
m_BodyID = bodyID;
|
||||
}
|
||||
|
||||
public BodyType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_BodyID >= 0 && m_BodyID < m_Types.Length )
|
||||
return m_Types[m_BodyID];
|
||||
else
|
||||
return BodyType.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsHuman
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BodyID >= 0
|
||||
&& m_BodyID < m_Types.Length
|
||||
&& m_Types[m_BodyID] == BodyType.Human
|
||||
&& m_BodyID != 402
|
||||
&& m_BodyID != 403
|
||||
&& m_BodyID != 607
|
||||
&& m_BodyID != 608
|
||||
&& m_BodyID != 970;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsMale
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BodyID == 183
|
||||
|| m_BodyID == 185
|
||||
|| m_BodyID == 400
|
||||
|| m_BodyID == 402
|
||||
|| m_BodyID == 605
|
||||
|| m_BodyID == 607
|
||||
|| m_BodyID == 750;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFemale
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BodyID == 184
|
||||
|| m_BodyID == 186
|
||||
|| m_BodyID == 401
|
||||
|| m_BodyID == 403
|
||||
|| m_BodyID == 606
|
||||
|| m_BodyID == 608
|
||||
|| m_BodyID == 751;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsGhost
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BodyID == 402
|
||||
|| m_BodyID == 403
|
||||
|| m_BodyID == 607
|
||||
|| m_BodyID == 608
|
||||
|| m_BodyID == 970;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsMonster
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BodyID >= 0
|
||||
&& m_BodyID < m_Types.Length
|
||||
&& m_Types[m_BodyID] == BodyType.Monster;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsAnimal
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BodyID >= 0
|
||||
&& m_BodyID < m_Types.Length
|
||||
&& m_Types[m_BodyID] == BodyType.Animal;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BodyID >= 0
|
||||
&& m_BodyID < m_Types.Length
|
||||
&& m_Types[m_BodyID] == BodyType.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSea
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BodyID >= 0
|
||||
&& m_BodyID < m_Types.Length
|
||||
&& m_Types[m_BodyID] == BodyType.Sea;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEquipment
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BodyID >= 0
|
||||
&& m_BodyID < m_Types.Length
|
||||
&& m_Types[m_BodyID] == BodyType.Equipment;
|
||||
}
|
||||
}
|
||||
|
||||
public int BodyID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_BodyID;
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator int( Body a )
|
||||
{
|
||||
return a.m_BodyID;
|
||||
}
|
||||
|
||||
public static implicit operator Body( int a )
|
||||
{
|
||||
return new Body( a );
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format( "0x{0:X}", m_BodyID );
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return m_BodyID;
|
||||
}
|
||||
|
||||
public override bool Equals( object o )
|
||||
{
|
||||
if ( o == null || !(o is Body) ) return false;
|
||||
|
||||
return ((Body)o).m_BodyID == m_BodyID;
|
||||
}
|
||||
|
||||
public static bool operator == ( Body l, Body r )
|
||||
{
|
||||
return l.m_BodyID == r.m_BodyID;
|
||||
}
|
||||
|
||||
public static bool operator != ( Body l, Body r )
|
||||
{
|
||||
return l.m_BodyID != r.m_BodyID;
|
||||
}
|
||||
|
||||
public static bool operator > ( Body l, Body r )
|
||||
{
|
||||
return l.m_BodyID > r.m_BodyID;
|
||||
}
|
||||
|
||||
public static bool operator >= ( Body l, Body r )
|
||||
{
|
||||
return l.m_BodyID >= r.m_BodyID;
|
||||
}
|
||||
|
||||
public static bool operator < ( Body l, Body r )
|
||||
{
|
||||
return l.m_BodyID < r.m_BodyID;
|
||||
}
|
||||
|
||||
public static bool operator <= ( Body l, Body r )
|
||||
{
|
||||
return l.m_BodyID <= r.m_BodyID;
|
||||
}
|
||||
}
|
||||
}
|
||||
300
Source/ClientVersion.cs
Normal file
300
Source/ClientVersion.cs
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
/***************************************************************************
|
||||
* ClientVersion.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public enum ClientType
|
||||
{
|
||||
Regular,
|
||||
UOTD,
|
||||
God,
|
||||
SA
|
||||
}
|
||||
|
||||
public class ClientVersion : IComparable, IComparer
|
||||
{
|
||||
private int m_Major, m_Minor, m_Revision, m_Patch;
|
||||
private ClientType m_Type;
|
||||
private string m_SourceString;
|
||||
|
||||
public int Major
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Major;
|
||||
}
|
||||
}
|
||||
|
||||
public int Minor
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Minor;
|
||||
}
|
||||
}
|
||||
|
||||
public int Revision
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Revision;
|
||||
}
|
||||
}
|
||||
|
||||
public int Patch
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Patch;
|
||||
}
|
||||
}
|
||||
|
||||
public ClientType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
}
|
||||
|
||||
public string SourceString
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_SourceString;
|
||||
}
|
||||
}
|
||||
|
||||
public ClientVersion( int maj, int min, int rev, int pat ) : this( maj, min, rev, pat, ClientType.Regular )
|
||||
{
|
||||
}
|
||||
|
||||
public ClientVersion( int maj, int min, int rev, int pat, ClientType type )
|
||||
{
|
||||
m_Major = maj;
|
||||
m_Minor = min;
|
||||
m_Revision = rev;
|
||||
m_Patch = pat;
|
||||
m_Type = type;
|
||||
|
||||
m_SourceString = ToString();
|
||||
}
|
||||
|
||||
public static bool operator == ( ClientVersion l, ClientVersion r )
|
||||
{
|
||||
return ( Compare( l, r ) == 0 );
|
||||
}
|
||||
|
||||
public static bool operator != ( ClientVersion l, ClientVersion r )
|
||||
{
|
||||
return ( Compare( l, r ) != 0 );
|
||||
}
|
||||
|
||||
public static bool operator >= ( ClientVersion l, ClientVersion r )
|
||||
{
|
||||
return ( Compare( l, r ) >= 0 );
|
||||
}
|
||||
|
||||
public static bool operator > ( ClientVersion l, ClientVersion r )
|
||||
{
|
||||
return ( Compare( l, r ) > 0 );
|
||||
}
|
||||
|
||||
public static bool operator <= ( ClientVersion l, ClientVersion r )
|
||||
{
|
||||
return ( Compare( l, r ) <= 0 );
|
||||
}
|
||||
|
||||
public static bool operator < ( ClientVersion l, ClientVersion r )
|
||||
{
|
||||
return ( Compare( l, r ) < 0 );
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return m_Major ^ m_Minor ^ m_Revision ^ m_Patch ^ (int)m_Type;
|
||||
}
|
||||
|
||||
public override bool Equals( object obj )
|
||||
{
|
||||
if ( obj == null )
|
||||
return false;
|
||||
|
||||
ClientVersion v = obj as ClientVersion;
|
||||
|
||||
if ( v == null )
|
||||
return false;
|
||||
|
||||
return m_Major == v.m_Major
|
||||
&& m_Minor == v.m_Minor
|
||||
&& m_Revision == v.m_Revision
|
||||
&& m_Patch == v.m_Patch
|
||||
&& m_Type == v.m_Type;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder( 16 );
|
||||
|
||||
builder.Append( m_Major );
|
||||
builder.Append( '.' );
|
||||
builder.Append( m_Minor );
|
||||
builder.Append( '.' );
|
||||
builder.Append( m_Revision );
|
||||
|
||||
if( m_Major <= 5 && m_Minor <= 0 && m_Revision <= 6 ) //Anything before 5.0.7
|
||||
{
|
||||
if( m_Patch > 0 )
|
||||
builder.Append( (char)('a' + (m_Patch - 1)) );
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Append( '.' );
|
||||
builder.Append( m_Patch );
|
||||
}
|
||||
|
||||
if ( m_Type != ClientType.Regular )
|
||||
{
|
||||
builder.Append( ' ' );
|
||||
builder.Append( m_Type.ToString() );
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public ClientVersion( string fmt )
|
||||
{
|
||||
m_SourceString = fmt;
|
||||
|
||||
try
|
||||
{
|
||||
fmt = fmt.ToLower();
|
||||
|
||||
int br1 = fmt.IndexOf( '.' );
|
||||
int br2 = fmt.IndexOf( '.', br1 + 1 );
|
||||
|
||||
int br3 = br2 + 1;
|
||||
while ( br3 < fmt.Length && Char.IsDigit( fmt, br3 ) )
|
||||
br3++;
|
||||
|
||||
m_Major = Utility.ToInt32( fmt.Substring( 0, br1 ) );
|
||||
m_Minor = Utility.ToInt32( fmt.Substring( br1 + 1, br2 - br1 - 1 ) );
|
||||
m_Revision = Utility.ToInt32( fmt.Substring( br2 + 1, br3 - br2 - 1 ) );
|
||||
|
||||
if( br3 < fmt.Length )
|
||||
{
|
||||
if( m_Major <= 5 && m_Minor <= 0 && m_Revision <= 6 ) //Anything before 5.0.7
|
||||
{
|
||||
if( !Char.IsWhiteSpace( fmt, br3 ) )
|
||||
m_Patch = (fmt[br3] - 'a') + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Patch = Utility.ToInt32( fmt.Substring( br3+1, fmt.Length - br3 - 1 ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( fmt.IndexOf( "god" ) >= 0 || fmt.IndexOf( "gq" ) >= 0 )
|
||||
m_Type = ClientType.God;
|
||||
else if ( fmt.IndexOf( "third dawn" ) >= 0 || fmt.IndexOf( "uo:td" ) >= 0 || fmt.IndexOf( "uotd" ) >= 0 || fmt.IndexOf( "uo3d" ) >= 0 || fmt.IndexOf( "uo:3d" ) >= 0 )
|
||||
m_Type = ClientType.UOTD;
|
||||
else
|
||||
m_Type = ClientType.Regular;
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_Major = 0;
|
||||
m_Minor = 0;
|
||||
m_Revision = 0;
|
||||
m_Patch = 0;
|
||||
m_Type = ClientType.Regular;
|
||||
}
|
||||
}
|
||||
|
||||
public int CompareTo( object obj )
|
||||
{
|
||||
if ( obj == null )
|
||||
return 1;
|
||||
|
||||
ClientVersion o = obj as ClientVersion;
|
||||
|
||||
if ( o == null )
|
||||
throw new ArgumentException();
|
||||
|
||||
if ( m_Major > o.m_Major )
|
||||
return 1;
|
||||
else if ( m_Major < o.m_Major )
|
||||
return -1;
|
||||
else if ( m_Minor > o.m_Minor )
|
||||
return 1;
|
||||
else if ( m_Minor < o.m_Minor )
|
||||
return -1;
|
||||
else if ( m_Revision > o.m_Revision )
|
||||
return 1;
|
||||
else if ( m_Revision < o.m_Revision )
|
||||
return -1;
|
||||
else if ( m_Patch > o.m_Patch )
|
||||
return 1;
|
||||
else if ( m_Patch < o.m_Patch )
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static bool IsNull( object x )
|
||||
{
|
||||
return Object.ReferenceEquals( x, null );
|
||||
}
|
||||
|
||||
public int Compare( object x, object y )
|
||||
{
|
||||
if ( IsNull( x ) && IsNull( y ) )
|
||||
return 0;
|
||||
else if ( IsNull( x ) )
|
||||
return -1;
|
||||
else if ( IsNull( y ) )
|
||||
return 1;
|
||||
|
||||
ClientVersion a = x as ClientVersion;
|
||||
ClientVersion b = y as ClientVersion;
|
||||
|
||||
if ( IsNull( a ) || IsNull( b ) )
|
||||
throw new ArgumentException();
|
||||
|
||||
return a.CompareTo( b );
|
||||
}
|
||||
|
||||
public static int Compare( ClientVersion a, ClientVersion b )
|
||||
{
|
||||
if ( IsNull( a ) && IsNull( b ) )
|
||||
return 0;
|
||||
else if ( IsNull( a ) )
|
||||
return -1;
|
||||
else if ( IsNull( b ) )
|
||||
return 1;
|
||||
|
||||
return a.CompareTo( b );
|
||||
}
|
||||
}
|
||||
}
|
||||
347
Source/Commands.cs
Normal file
347
Source/Commands.cs
Normal file
|
|
@ -0,0 +1,347 @@
|
|||
/***************************************************************************
|
||||
* Commands.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Server.Guilds;
|
||||
using Server.Gumps;
|
||||
using Server.Menus;
|
||||
using Server.Menus.ItemLists;
|
||||
using Server.Menus.Questions;
|
||||
using Server.Network;
|
||||
using Server.Items;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Commands
|
||||
{
|
||||
public delegate void CommandEventHandler( CommandEventArgs e );
|
||||
|
||||
public class CommandEventArgs : EventArgs
|
||||
{
|
||||
private Mobile m_Mobile;
|
||||
private string m_Command, m_ArgString;
|
||||
private string[] m_Arguments;
|
||||
|
||||
public Mobile Mobile
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Mobile;
|
||||
}
|
||||
}
|
||||
|
||||
public string Command
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Command;
|
||||
}
|
||||
}
|
||||
|
||||
public string ArgString
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ArgString;
|
||||
}
|
||||
}
|
||||
|
||||
public string[] Arguments
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Arguments;
|
||||
}
|
||||
}
|
||||
|
||||
public int Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Arguments.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetString( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Arguments.Length )
|
||||
return "";
|
||||
|
||||
return m_Arguments[index];
|
||||
}
|
||||
|
||||
public int GetInt32( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Arguments.Length )
|
||||
return 0;
|
||||
|
||||
return Utility.ToInt32( m_Arguments[index] );
|
||||
}
|
||||
|
||||
public bool GetBoolean( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Arguments.Length )
|
||||
return false;
|
||||
|
||||
return Utility.ToBoolean( m_Arguments[index] );
|
||||
}
|
||||
|
||||
public double GetDouble( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Arguments.Length )
|
||||
return 0.0;
|
||||
|
||||
return Utility.ToDouble( m_Arguments[index] );
|
||||
}
|
||||
|
||||
public TimeSpan GetTimeSpan( int index )
|
||||
{
|
||||
if ( index < 0 || index >= m_Arguments.Length )
|
||||
return TimeSpan.Zero;
|
||||
|
||||
return Utility.ToTimeSpan( m_Arguments[index] );
|
||||
}
|
||||
|
||||
public CommandEventArgs( Mobile mobile, string command, string argString, string[] arguments )
|
||||
{
|
||||
m_Mobile = mobile;
|
||||
m_Command = command;
|
||||
m_ArgString = argString;
|
||||
m_Arguments = arguments;
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandEntry : IComparable
|
||||
{
|
||||
private string m_Command;
|
||||
private CommandEventHandler m_Handler;
|
||||
private AccessLevel m_AccessLevel;
|
||||
|
||||
public string Command
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Command;
|
||||
}
|
||||
}
|
||||
|
||||
public CommandEventHandler Handler
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Handler;
|
||||
}
|
||||
}
|
||||
|
||||
public AccessLevel AccessLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_AccessLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public CommandEntry( string command, CommandEventHandler handler, AccessLevel accessLevel )
|
||||
{
|
||||
m_Command = command;
|
||||
m_Handler = handler;
|
||||
m_AccessLevel = accessLevel;
|
||||
}
|
||||
|
||||
public int CompareTo( object obj )
|
||||
{
|
||||
if ( obj == this )
|
||||
return 0;
|
||||
else if ( obj == null )
|
||||
return 1;
|
||||
|
||||
CommandEntry e = obj as CommandEntry;
|
||||
|
||||
if ( e == null )
|
||||
throw new ArgumentException();
|
||||
|
||||
return m_Command.CompareTo( e.m_Command );
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommandSystem
|
||||
{
|
||||
private static string m_Prefix = "[";
|
||||
|
||||
public static string Prefix
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Prefix;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Prefix = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static string[] Split( string value )
|
||||
{
|
||||
char[] array = value.ToCharArray();
|
||||
List<string> list = new List<string>();
|
||||
|
||||
int start = 0, end = 0;
|
||||
|
||||
while ( start < array.Length )
|
||||
{
|
||||
char c = array[start];
|
||||
|
||||
if ( c == '"' )
|
||||
{
|
||||
++start;
|
||||
end = start;
|
||||
|
||||
while ( end < array.Length )
|
||||
{
|
||||
if ( array[end] != '"' || array[end - 1] == '\\' )
|
||||
++end;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
list.Add( value.Substring( start, end - start ) );
|
||||
|
||||
start = end + 2;
|
||||
}
|
||||
else if ( c != ' ' )
|
||||
{
|
||||
end = start;
|
||||
|
||||
while ( end < array.Length )
|
||||
{
|
||||
if ( array[end] != ' ' )
|
||||
++end;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
list.Add( value.Substring( start, end - start ) );
|
||||
|
||||
start = end + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
++start;
|
||||
}
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static Dictionary<string, CommandEntry> m_Entries;
|
||||
|
||||
public static Dictionary<string, CommandEntry> Entries
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Entries;
|
||||
}
|
||||
}
|
||||
|
||||
static CommandSystem()
|
||||
{
|
||||
m_Entries = new Dictionary<string, CommandEntry>( StringComparer.OrdinalIgnoreCase );
|
||||
}
|
||||
|
||||
public static void Register( string command, AccessLevel access, CommandEventHandler handler )
|
||||
{
|
||||
m_Entries[command] = new CommandEntry( command, handler, access );
|
||||
}
|
||||
|
||||
private static AccessLevel m_BadCommandIngoreLevel = AccessLevel.Player;
|
||||
|
||||
public static AccessLevel BadCommandIgnoreLevel{ get{ return m_BadCommandIngoreLevel; } set{ m_BadCommandIngoreLevel = value; } }
|
||||
|
||||
public static bool Handle( Mobile from, string text )
|
||||
{
|
||||
return Handle( from, text, MessageType.Regular );
|
||||
}
|
||||
|
||||
public static bool Handle( Mobile from, string text, MessageType type )
|
||||
{
|
||||
if ( text.StartsWith( m_Prefix ) || type == MessageType.Command )
|
||||
{
|
||||
if( type != MessageType.Command )
|
||||
text = text.Substring( m_Prefix.Length );
|
||||
|
||||
int indexOf = text.IndexOf( ' ' );
|
||||
|
||||
string command;
|
||||
string[] args;
|
||||
string argString;
|
||||
|
||||
if ( indexOf >= 0 )
|
||||
{
|
||||
argString = text.Substring( indexOf + 1 );
|
||||
|
||||
command = text.Substring( 0, indexOf );
|
||||
args = Split( argString );
|
||||
}
|
||||
else
|
||||
{
|
||||
argString = "";
|
||||
command = text.ToLower();
|
||||
args = new string[0];
|
||||
}
|
||||
|
||||
CommandEntry entry = null;
|
||||
m_Entries.TryGetValue( command, out entry );
|
||||
|
||||
if ( entry != null )
|
||||
{
|
||||
if ( from.AccessLevel >= entry.AccessLevel )
|
||||
{
|
||||
if ( entry.Handler != null )
|
||||
{
|
||||
CommandEventArgs e = new CommandEventArgs( from, command, argString, args );
|
||||
entry.Handler( e );
|
||||
EventSink.InvokeCommand( e );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( from.AccessLevel <= m_BadCommandIngoreLevel )
|
||||
return false;
|
||||
|
||||
from.SendMessage( "You do not have access to that command." );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( from.AccessLevel <= m_BadCommandIngoreLevel )
|
||||
return false;
|
||||
|
||||
from.SendMessage( "That is not a valid command." );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
98
Source/ContextMenus/ContextMenu.cs
Normal file
98
Source/ContextMenus/ContextMenu.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/***************************************************************************
|
||||
* ContextMenu.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.ContextMenus
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the state of an active context menu. This includes who opened the menu, the menu's focus object, and a list of <see cref="ContextMenuEntry">entries</see> that the menu is composed of.
|
||||
/// <seealso cref="ContextMenuEntry" />
|
||||
/// </summary>
|
||||
public class ContextMenu
|
||||
{
|
||||
private Mobile m_From;
|
||||
private object m_Target;
|
||||
private ContextMenuEntry[] m_Entries;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Mobile" /> who opened this ContextMenu.
|
||||
/// </summary>
|
||||
public Mobile From
|
||||
{
|
||||
get{ return m_From; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an object of the <see cref="Mobile" /> or <see cref="Item" /> for which this ContextMenu is on.
|
||||
/// </summary>
|
||||
public object Target
|
||||
{
|
||||
get{ return m_Target; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of <see cref="ContextMenuEntry">entries</see> contained in this ContextMenu.
|
||||
/// </summary>
|
||||
public ContextMenuEntry[] Entries
|
||||
{
|
||||
get{ return m_Entries; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new ContextMenu instance.
|
||||
/// </summary>
|
||||
/// <param name="from">
|
||||
/// The <see cref="Mobile" /> who opened this ContextMenu.
|
||||
/// <seealso cref="From" />
|
||||
/// </param>
|
||||
/// <param name="target">
|
||||
/// The <see cref="Mobile" /> or <see cref="Item" /> for which this ContextMenu is on.
|
||||
/// <seealso cref="Target" />
|
||||
/// </param>
|
||||
public ContextMenu( Mobile from, object target )
|
||||
{
|
||||
m_From = from;
|
||||
m_Target = target;
|
||||
|
||||
List<ContextMenuEntry> list = new List<ContextMenuEntry>();
|
||||
|
||||
if ( target is Mobile )
|
||||
{
|
||||
((Mobile)target).GetContextMenuEntries( from, list );
|
||||
}
|
||||
else if ( target is Item )
|
||||
{
|
||||
((Item)target).GetContextMenuEntries( from, list );
|
||||
}
|
||||
|
||||
//m_Entries = (ContextMenuEntry[])list.ToArray( typeof( ContextMenuEntry ) );
|
||||
|
||||
m_Entries = list.ToArray();
|
||||
|
||||
for ( int i = 0; i < m_Entries.Length; ++i )
|
||||
{
|
||||
m_Entries[i].Owner = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
139
Source/ContextMenus/ContextMenuEntry.cs
Normal file
139
Source/ContextMenus/ContextMenuEntry.cs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/***************************************************************************
|
||||
* ContextMenuEntry.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.ContextMenus
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a single entry of a <see cref="ContextMenu">context menu</see>.
|
||||
/// <seealso cref="ContextMenu" />
|
||||
/// </summary>
|
||||
public class ContextMenuEntry
|
||||
{
|
||||
private int m_Number;
|
||||
private int m_Color;
|
||||
private bool m_Enabled;
|
||||
private int m_Range;
|
||||
private CMEFlags m_Flags;
|
||||
private ContextMenu m_Owner;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets additional <see cref="CMEFlags">flags</see> used in client communication.
|
||||
/// </summary>
|
||||
public CMEFlags Flags
|
||||
{
|
||||
get{ return m_Flags; }
|
||||
set{ m_Flags = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ContextMenu" /> that owns this entry.
|
||||
/// </summary>
|
||||
public ContextMenu Owner
|
||||
{
|
||||
get{ return m_Owner; }
|
||||
set{ m_Owner = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the localization number containing the name of this entry.
|
||||
/// </summary>
|
||||
public int Number
|
||||
{
|
||||
get{ return m_Number; }
|
||||
set{ m_Number = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum range at which this entry may be used, in tiles. A value of -1 signifies no maximum range.
|
||||
/// </summary>
|
||||
public int Range
|
||||
{
|
||||
get{ return m_Range; }
|
||||
set{ m_Range = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color for this entry. Format is A1-R5-G5-B5.
|
||||
/// </summary>
|
||||
public int Color
|
||||
{
|
||||
get{ return m_Color; }
|
||||
set{ m_Color = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this entry is enabled. When false, the entry will appear in a gray hue and <see cref="OnClick" /> will never be invoked.
|
||||
/// </summary>
|
||||
public bool Enabled
|
||||
{
|
||||
get{ return m_Enabled; }
|
||||
set{ m_Enabled = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating if non local use of this entry is permitted.
|
||||
/// </summary>
|
||||
public virtual bool NonLocalUse
|
||||
{
|
||||
get{ return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new ContextMenuEntry with a given <see cref="Number">localization number</see> (<paramref name="number" />). No <see cref="Range">maximum range</see> is used.
|
||||
/// </summary>
|
||||
/// <param name="number">
|
||||
/// The localization number containing the name of this entry.
|
||||
/// <seealso cref="Number" />
|
||||
/// </param>
|
||||
public ContextMenuEntry( int number ) : this( number, -1 )
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new ContextMenuEntry with a given <see cref="Number">localization number</see> (<paramref name="number" />) and <see cref="Range">maximum range</see> (<paramref name="range" />).
|
||||
/// </summary>
|
||||
/// <param name="number">
|
||||
/// The localization number containing the name of this entry.
|
||||
/// <seealso cref="Number" />
|
||||
/// </param>
|
||||
/// <param name="range">
|
||||
/// The maximum range at which this entry can be used.
|
||||
/// <seealso cref="Range" />
|
||||
/// </param>
|
||||
public ContextMenuEntry( int number, int range )
|
||||
{
|
||||
m_Number = number;
|
||||
m_Range = range;
|
||||
m_Enabled = true;
|
||||
m_Color = 0xFFFF;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overridable. Virtual event invoked when the entry is clicked.
|
||||
/// </summary>
|
||||
public virtual void OnClick()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Source/ContextMenus/OpenBackpackEntry.cs
Normal file
40
Source/ContextMenus/OpenBackpackEntry.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/***************************************************************************
|
||||
* OpenBackpackEntry.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.ContextMenus
|
||||
{
|
||||
public class OpenBackpackEntry : ContextMenuEntry
|
||||
{
|
||||
private Mobile m_Mobile;
|
||||
|
||||
public OpenBackpackEntry( Mobile m ) : base( 6145 )
|
||||
{
|
||||
m_Mobile = m;
|
||||
}
|
||||
|
||||
public override void OnClick()
|
||||
{
|
||||
m_Mobile.Use( m_Mobile.Backpack );
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Source/ContextMenus/PaperdollEntry.cs
Normal file
40
Source/ContextMenus/PaperdollEntry.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/***************************************************************************
|
||||
* PaperdollEntry.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server.ContextMenus
|
||||
{
|
||||
public class PaperdollEntry : ContextMenuEntry
|
||||
{
|
||||
private Mobile m_Mobile;
|
||||
|
||||
public PaperdollEntry( Mobile m ) : base( 6123, 18 )
|
||||
{
|
||||
m_Mobile = m;
|
||||
}
|
||||
|
||||
public override void OnClick()
|
||||
{
|
||||
if ( m_Mobile.CanPaperdollBeOpenedBy( Owner.From ) )
|
||||
m_Mobile.DisplayPaperdollTo( Owner.From );
|
||||
}
|
||||
}
|
||||
}
|
||||
112
Source/Diagnostics/BaseProfile.cs
Normal file
112
Source/Diagnostics/BaseProfile.cs
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/***************************************************************************
|
||||
* PacketProfile.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Server.Diagnostics {
|
||||
public abstract class BaseProfile {
|
||||
public static void WriteAll<T>( TextWriter op, IEnumerable<T> profiles ) where T : BaseProfile {
|
||||
List<T> list = new List<T>( profiles );
|
||||
|
||||
list.Sort( delegate( T a, T b ) {
|
||||
return -a.TotalTime.CompareTo( b.TotalTime );
|
||||
} );
|
||||
|
||||
foreach ( T prof in list ) {
|
||||
prof.WriteTo( op );
|
||||
op.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
private string _name;
|
||||
|
||||
private long _count;
|
||||
|
||||
private TimeSpan _totalTime;
|
||||
private TimeSpan _peakTime;
|
||||
|
||||
private Stopwatch _stopwatch;
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
||||
public long Count {
|
||||
get {
|
||||
return _count;
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan AverageTime {
|
||||
get {
|
||||
return TimeSpan.FromTicks( _totalTime.Ticks / Math.Max( 1, _count ) );
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan PeakTime {
|
||||
get {
|
||||
return _peakTime;
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan TotalTime {
|
||||
get {
|
||||
return _totalTime;
|
||||
}
|
||||
}
|
||||
|
||||
protected BaseProfile( string name ) {
|
||||
_name = name;
|
||||
|
||||
_stopwatch = new Stopwatch();
|
||||
}
|
||||
|
||||
public virtual void Start() {
|
||||
if ( _stopwatch.IsRunning ) {
|
||||
_stopwatch.Reset();
|
||||
}
|
||||
|
||||
_stopwatch.Start();
|
||||
}
|
||||
|
||||
public virtual void Finish() {
|
||||
TimeSpan elapsed = _stopwatch.Elapsed;
|
||||
|
||||
_totalTime += elapsed;
|
||||
|
||||
if ( elapsed > _peakTime ) {
|
||||
_peakTime = elapsed;
|
||||
}
|
||||
|
||||
_count++;
|
||||
|
||||
_stopwatch.Reset();
|
||||
}
|
||||
|
||||
public virtual void WriteTo( TextWriter op ) {
|
||||
op.Write( "{0,-100} {1,12:N0} {2,12:F5} {3,-12:F5} {4,12:F5}", Name, Count, AverageTime.TotalSeconds, PeakTime.TotalSeconds, TotalTime.TotalSeconds );
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Source/Diagnostics/GumpProfile.cs
Normal file
53
Source/Diagnostics/GumpProfile.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/***************************************************************************
|
||||
* PacketProfile.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Server.Diagnostics {
|
||||
public class GumpProfile : BaseProfile {
|
||||
private static Dictionary<Type, GumpProfile> _profiles = new Dictionary<Type, GumpProfile>();
|
||||
|
||||
public static IEnumerable<GumpProfile> Profiles {
|
||||
get {
|
||||
return _profiles.Values;
|
||||
}
|
||||
}
|
||||
|
||||
public static GumpProfile Acquire( Type type ) {
|
||||
if ( !Core.Profiling ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
GumpProfile prof;
|
||||
|
||||
if ( !_profiles.TryGetValue( type, out prof ) ) {
|
||||
_profiles.Add( type, prof = new GumpProfile( type ) );
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
|
||||
public GumpProfile( Type type )
|
||||
: base( type.FullName ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
131
Source/Diagnostics/PacketProfile.cs
Normal file
131
Source/Diagnostics/PacketProfile.cs
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/***************************************************************************
|
||||
* PacketProfile.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Server.Diagnostics {
|
||||
public abstract class BasePacketProfile : BaseProfile {
|
||||
private long _totalLength;
|
||||
|
||||
public long TotalLength {
|
||||
get {
|
||||
return _totalLength;
|
||||
}
|
||||
}
|
||||
|
||||
public double AverageLength {
|
||||
get {
|
||||
return ( double ) _totalLength / Math.Max( 1, this.Count );
|
||||
}
|
||||
}
|
||||
|
||||
protected BasePacketProfile(string name)
|
||||
: base( name ) {
|
||||
}
|
||||
|
||||
public void Finish( int length ) {
|
||||
Finish();
|
||||
|
||||
_totalLength += length;
|
||||
}
|
||||
|
||||
public override void WriteTo( TextWriter op ) {
|
||||
base.WriteTo( op );
|
||||
|
||||
op.Write( "\t{0,12:F2} {1,-12:N0}", AverageLength, TotalLength );
|
||||
}
|
||||
}
|
||||
|
||||
public class PacketSendProfile : BasePacketProfile {
|
||||
private static Dictionary<Type, PacketSendProfile> _profiles = new Dictionary<Type, PacketSendProfile>();
|
||||
|
||||
public static IEnumerable<PacketSendProfile> Profiles {
|
||||
get {
|
||||
return _profiles.Values;
|
||||
}
|
||||
}
|
||||
|
||||
public static PacketSendProfile Acquire( Type type ) {
|
||||
if ( !Core.Profiling ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PacketSendProfile prof;
|
||||
|
||||
if ( !_profiles.TryGetValue( type, out prof ) ) {
|
||||
_profiles.Add( type, prof = new PacketSendProfile( type ) );
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
|
||||
private long _created;
|
||||
|
||||
public long Created {
|
||||
get {
|
||||
return _created;
|
||||
}
|
||||
set {
|
||||
_created = value;
|
||||
}
|
||||
}
|
||||
|
||||
public PacketSendProfile( Type type )
|
||||
: base( type.FullName ) {
|
||||
}
|
||||
|
||||
public override void WriteTo( TextWriter op ) {
|
||||
base.WriteTo( op );
|
||||
|
||||
op.Write( "\t{0,12:N0}", Created );
|
||||
}
|
||||
}
|
||||
|
||||
public class PacketReceiveProfile : BasePacketProfile {
|
||||
private static Dictionary<int, PacketReceiveProfile> _profiles = new Dictionary<int, PacketReceiveProfile>();
|
||||
|
||||
public static IEnumerable<PacketReceiveProfile> Profiles {
|
||||
get {
|
||||
return _profiles.Values;
|
||||
}
|
||||
}
|
||||
|
||||
public static PacketReceiveProfile Acquire( int packetId ) {
|
||||
if ( !Core.Profiling ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PacketReceiveProfile prof;
|
||||
|
||||
if ( !_profiles.TryGetValue( packetId, out prof ) ) {
|
||||
_profiles.Add( packetId, prof = new PacketReceiveProfile( packetId ) );
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
|
||||
public PacketReceiveProfile( int packetId )
|
||||
: base( String.Format( "0x{0:X2}", packetId ) ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Source/Diagnostics/TargetProfile.cs
Normal file
53
Source/Diagnostics/TargetProfile.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/***************************************************************************
|
||||
* PacketProfile.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Server.Diagnostics {
|
||||
public class TargetProfile : BaseProfile {
|
||||
private static Dictionary<Type, TargetProfile> _profiles = new Dictionary<Type, TargetProfile>();
|
||||
|
||||
public static IEnumerable<TargetProfile> Profiles {
|
||||
get {
|
||||
return _profiles.Values;
|
||||
}
|
||||
}
|
||||
|
||||
public static TargetProfile Acquire( Type type ) {
|
||||
if ( !Core.Profiling ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TargetProfile prof;
|
||||
|
||||
if ( !_profiles.TryGetValue( type, out prof ) ) {
|
||||
_profiles.Add( type, prof = new TargetProfile( type ) );
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
|
||||
public TargetProfile( Type type )
|
||||
: base( type.FullName ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
89
Source/Diagnostics/TimerProfile.cs
Normal file
89
Source/Diagnostics/TimerProfile.cs
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/***************************************************************************
|
||||
* PacketProfile.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Server.Diagnostics {
|
||||
public class TimerProfile : BaseProfile {
|
||||
private static Dictionary<string, TimerProfile> _profiles = new Dictionary<string, TimerProfile>();
|
||||
|
||||
public static IEnumerable<TimerProfile> Profiles {
|
||||
get {
|
||||
return _profiles.Values;
|
||||
}
|
||||
}
|
||||
|
||||
public static TimerProfile Acquire( string name ) {
|
||||
if ( !Core.Profiling ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TimerProfile prof;
|
||||
|
||||
if ( !_profiles.TryGetValue( name, out prof ) ) {
|
||||
_profiles.Add( name, prof = new TimerProfile( name ) );
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
|
||||
private long _created, _started, _stopped;
|
||||
|
||||
public long Created {
|
||||
get {
|
||||
return _created;
|
||||
}
|
||||
set {
|
||||
_created = value;
|
||||
}
|
||||
}
|
||||
|
||||
public long Started {
|
||||
get {
|
||||
return _started;
|
||||
}
|
||||
set {
|
||||
_started = value;
|
||||
}
|
||||
}
|
||||
|
||||
public long Stopped {
|
||||
get {
|
||||
return _stopped;
|
||||
}
|
||||
set {
|
||||
_stopped = value;
|
||||
}
|
||||
}
|
||||
|
||||
public TimerProfile( string name )
|
||||
: base( name ) {
|
||||
}
|
||||
|
||||
public override void WriteTo( TextWriter op ) {
|
||||
base.WriteTo( op );
|
||||
|
||||
op.Write( "\t{0,12:N0} {1,12:N0} {2,-12:N0}", _created, _started, _stopped );
|
||||
}
|
||||
}
|
||||
}
|
||||
405
Source/Effects.cs
Normal file
405
Source/Effects.cs
Normal file
|
|
@ -0,0 +1,405 @@
|
|||
/***************************************************************************
|
||||
* Effects.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public enum EffectLayer
|
||||
{
|
||||
Head = 0,
|
||||
RightHand = 1,
|
||||
LeftHand = 2,
|
||||
Waist = 3,
|
||||
LeftFoot = 4,
|
||||
RightFoot = 5,
|
||||
CenterFeet = 7
|
||||
}
|
||||
|
||||
public enum ParticleSupportType
|
||||
{
|
||||
Full,
|
||||
Detect,
|
||||
None
|
||||
}
|
||||
|
||||
public static class Effects
|
||||
{
|
||||
private static ParticleSupportType m_ParticleSupportType = ParticleSupportType.Detect;
|
||||
|
||||
public static ParticleSupportType ParticleSupportType
|
||||
{
|
||||
get{ return m_ParticleSupportType; }
|
||||
set{ m_ParticleSupportType = value; }
|
||||
}
|
||||
|
||||
public static bool SendParticlesTo( NetState state )
|
||||
{
|
||||
return ( m_ParticleSupportType == ParticleSupportType.Full || (m_ParticleSupportType == ParticleSupportType.Detect && state.IsUOTDClient) );
|
||||
}
|
||||
|
||||
public static void PlaySound( IPoint3D p, Map map, int soundID )
|
||||
{
|
||||
if ( soundID <= -1 )
|
||||
return;
|
||||
|
||||
if ( map != null )
|
||||
{
|
||||
Packet playSound = null;
|
||||
|
||||
IPooledEnumerable eable = map.GetClientsInRange( new Point3D( p ) );
|
||||
|
||||
foreach ( NetState state in eable )
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
if ( playSound == null )
|
||||
playSound = Packet.Acquire( new PlaySound( soundID, p ) );
|
||||
|
||||
state.Send( playSound );
|
||||
}
|
||||
|
||||
Packet.Release( playSound );
|
||||
|
||||
eable.Free();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendBoltEffect( IEntity e )
|
||||
{
|
||||
SendBoltEffect( e, true, 0 );
|
||||
}
|
||||
|
||||
public static void SendBoltEffect( IEntity e, bool sound )
|
||||
{
|
||||
SendBoltEffect( e, sound, 0 );
|
||||
}
|
||||
|
||||
public static void SendBoltEffect( IEntity e, bool sound, int hue )
|
||||
{
|
||||
Map map = e.Map;
|
||||
|
||||
if ( map == null )
|
||||
return;
|
||||
|
||||
e.ProcessDelta();
|
||||
|
||||
Packet preEffect = null, boltEffect = null, playSound = null;
|
||||
|
||||
IPooledEnumerable eable = map.GetClientsInRange( e.Location );
|
||||
|
||||
foreach ( NetState state in eable )
|
||||
{
|
||||
if ( state.Mobile.CanSee( e ) )
|
||||
{
|
||||
if ( SendParticlesTo( state ) )
|
||||
{
|
||||
if ( preEffect == null )
|
||||
preEffect = Packet.Acquire( new TargetParticleEffect( e, 0, 10, 5, 0, 0, 5031, 3, 0 ) );
|
||||
|
||||
state.Send( preEffect );
|
||||
}
|
||||
|
||||
if ( boltEffect == null )
|
||||
boltEffect = Packet.Acquire( new BoltEffect( e, hue ) );
|
||||
|
||||
state.Send( boltEffect );
|
||||
|
||||
if ( sound )
|
||||
{
|
||||
if ( playSound == null )
|
||||
playSound = Packet.Acquire( new PlaySound( 0x29, e ) );
|
||||
|
||||
state.Send( playSound );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Packet.Release( preEffect );
|
||||
Packet.Release( boltEffect );
|
||||
Packet.Release( playSound );
|
||||
|
||||
eable.Free();
|
||||
}
|
||||
|
||||
public static void SendLocationEffect( IPoint3D p, Map map, int itemID, int duration )
|
||||
{
|
||||
SendLocationEffect( p, map, itemID, duration, 10, 0, 0 );
|
||||
}
|
||||
|
||||
public static void SendLocationEffect( IPoint3D p, Map map, int itemID, int duration, int speed )
|
||||
{
|
||||
SendLocationEffect( p, map, itemID, duration, speed, 0, 0 );
|
||||
}
|
||||
|
||||
public static void SendLocationEffect( IPoint3D p, Map map, int itemID, int duration, int hue, int renderMode )
|
||||
{
|
||||
SendLocationEffect( p, map, itemID, duration, 10, hue, renderMode );
|
||||
}
|
||||
|
||||
public static void SendLocationEffect( IPoint3D p, Map map, int itemID, int duration, int speed, int hue, int renderMode )
|
||||
{
|
||||
SendPacket( p, map, new LocationEffect( p, itemID, speed, duration, hue, renderMode ) );
|
||||
}
|
||||
|
||||
public static void SendLocationParticles( IEntity e, int itemID, int speed, int duration, int effect )
|
||||
{
|
||||
SendLocationParticles( e, itemID, speed, duration, 0, 0, effect, 0 );
|
||||
}
|
||||
|
||||
public static void SendLocationParticles( IEntity e, int itemID, int speed, int duration, int effect, int unknown )
|
||||
{
|
||||
SendLocationParticles( e, itemID, speed, duration, 0, 0, effect, unknown );
|
||||
}
|
||||
|
||||
public static void SendLocationParticles( IEntity e, int itemID, int speed, int duration, int hue, int renderMode, int effect, int unknown )
|
||||
{
|
||||
Map map = e.Map;
|
||||
|
||||
if ( map != null )
|
||||
{
|
||||
Packet particles = null, regular = null;
|
||||
|
||||
IPooledEnumerable eable = map.GetClientsInRange( e.Location );
|
||||
|
||||
foreach ( NetState state in eable )
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
if ( SendParticlesTo( state ) )
|
||||
{
|
||||
if ( particles == null )
|
||||
particles = Packet.Acquire( new LocationParticleEffect( e, itemID, speed, duration, hue, renderMode, effect, unknown ) );
|
||||
|
||||
state.Send( particles );
|
||||
}
|
||||
else if ( itemID != 0 )
|
||||
{
|
||||
if ( regular == null )
|
||||
regular = Packet.Acquire( new LocationEffect( e, itemID, speed, duration, hue, renderMode ) );
|
||||
|
||||
state.Send( regular );
|
||||
}
|
||||
}
|
||||
|
||||
Packet.Release( particles );
|
||||
Packet.Release( regular );
|
||||
|
||||
eable.Free();
|
||||
}
|
||||
//SendPacket( e.Location, e.Map, new LocationParticleEffect( e, itemID, speed, duration, hue, renderMode, effect, unknown ) );
|
||||
}
|
||||
|
||||
public static void SendTargetEffect( IEntity target, int itemID, int duration )
|
||||
{
|
||||
SendTargetEffect( target, itemID, duration, 0, 0 );
|
||||
}
|
||||
|
||||
public static void SendTargetEffect( IEntity target, int itemID, int speed, int duration )
|
||||
{
|
||||
SendTargetEffect( target, itemID, speed, duration, 0, 0 );
|
||||
}
|
||||
|
||||
public static void SendTargetEffect( IEntity target, int itemID, int duration, int hue, int renderMode )
|
||||
{
|
||||
SendTargetEffect( target, itemID, 10, duration, hue, renderMode );
|
||||
}
|
||||
|
||||
public static void SendTargetEffect( IEntity target, int itemID, int speed, int duration, int hue, int renderMode )
|
||||
{
|
||||
if ( target is Mobile )
|
||||
((Mobile)target).ProcessDelta();
|
||||
|
||||
SendPacket( target.Location, target.Map, new TargetEffect( target, itemID, speed, duration, hue, renderMode ) );
|
||||
}
|
||||
|
||||
public static void SendTargetParticles( IEntity target, int itemID, int speed, int duration, int effect, EffectLayer layer )
|
||||
{
|
||||
SendTargetParticles( target, itemID, speed, duration, 0, 0, effect, layer, 0 );
|
||||
}
|
||||
|
||||
public static void SendTargetParticles( IEntity target, int itemID, int speed, int duration, int effect, EffectLayer layer, int unknown )
|
||||
{
|
||||
SendTargetParticles( target, itemID, speed, duration, 0, 0, effect, layer, unknown );
|
||||
}
|
||||
|
||||
public static void SendTargetParticles( IEntity target, int itemID, int speed, int duration, int hue, int renderMode, int effect, EffectLayer layer, int unknown )
|
||||
{
|
||||
if ( target is Mobile )
|
||||
((Mobile)target).ProcessDelta();
|
||||
|
||||
Map map = target.Map;
|
||||
|
||||
if ( map != null )
|
||||
{
|
||||
Packet particles = null, regular = null;
|
||||
|
||||
IPooledEnumerable eable = map.GetClientsInRange( target.Location );
|
||||
|
||||
foreach ( NetState state in eable )
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
if ( SendParticlesTo( state ) )
|
||||
{
|
||||
if ( particles == null )
|
||||
particles = Packet.Acquire( new TargetParticleEffect( target, itemID, speed, duration, hue, renderMode, effect, (int)layer, unknown ) );
|
||||
|
||||
state.Send( particles );
|
||||
}
|
||||
else if ( itemID != 0 )
|
||||
{
|
||||
if ( regular == null )
|
||||
regular = Packet.Acquire( new TargetEffect( target, itemID, speed, duration, hue, renderMode ) );
|
||||
|
||||
state.Send( regular );
|
||||
}
|
||||
}
|
||||
|
||||
Packet.Release( particles );
|
||||
Packet.Release( regular );
|
||||
|
||||
eable.Free();
|
||||
}
|
||||
|
||||
//SendPacket( target.Location, target.Map, new TargetParticleEffect( target, itemID, speed, duration, hue, renderMode, effect, (int)layer, unknown ) );
|
||||
}
|
||||
|
||||
public static void SendMovingEffect( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes )
|
||||
{
|
||||
SendMovingEffect( from, to, itemID, speed, duration, fixedDirection, explodes, 0, 0 );
|
||||
}
|
||||
|
||||
public static void SendMovingEffect( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes, int hue, int renderMode )
|
||||
{
|
||||
if ( from is Mobile )
|
||||
((Mobile)from).ProcessDelta();
|
||||
|
||||
if ( to is Mobile )
|
||||
((Mobile)to).ProcessDelta();
|
||||
|
||||
SendPacket( from.Location, from.Map, new MovingEffect( from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode ) );
|
||||
}
|
||||
|
||||
public static void SendMovingParticles( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes, int effect, int explodeEffect, int explodeSound )
|
||||
{
|
||||
SendMovingParticles( from, to, itemID, speed, duration, fixedDirection, explodes, 0, 0, effect, explodeEffect, explodeSound, 0 );
|
||||
}
|
||||
|
||||
public static void SendMovingParticles( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes, int effect, int explodeEffect, int explodeSound, int unknown )
|
||||
{
|
||||
SendMovingParticles( from, to, itemID, speed, duration, fixedDirection, explodes, 0, 0, effect, explodeEffect, explodeSound, unknown );
|
||||
}
|
||||
|
||||
public static void SendMovingParticles( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes, int hue, int renderMode, int effect, int explodeEffect, int explodeSound, int unknown )
|
||||
{
|
||||
SendMovingParticles( from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode, effect, explodeEffect, explodeSound, (EffectLayer)255, unknown );
|
||||
}
|
||||
|
||||
public static void SendMovingParticles( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes, int hue, int renderMode, int effect, int explodeEffect, int explodeSound, EffectLayer layer, int unknown )
|
||||
{
|
||||
if ( from is Mobile )
|
||||
((Mobile)from).ProcessDelta();
|
||||
|
||||
if ( to is Mobile )
|
||||
((Mobile)to).ProcessDelta();
|
||||
|
||||
Map map = from.Map;
|
||||
|
||||
if ( map != null )
|
||||
{
|
||||
Packet particles = null, regular = null;
|
||||
|
||||
IPooledEnumerable eable = map.GetClientsInRange( from.Location );
|
||||
|
||||
foreach ( NetState state in eable )
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
if ( SendParticlesTo( state ) )
|
||||
{
|
||||
if ( particles == null )
|
||||
particles = Packet.Acquire( new MovingParticleEffect( from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode, effect, explodeEffect, explodeSound, layer, unknown ) );
|
||||
|
||||
state.Send( particles );
|
||||
}
|
||||
else if ( itemID > 1 )
|
||||
{
|
||||
if ( regular == null )
|
||||
regular = Packet.Acquire( new MovingEffect( from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode ) );
|
||||
|
||||
state.Send( regular );
|
||||
}
|
||||
}
|
||||
|
||||
Packet.Release( particles );
|
||||
Packet.Release( regular );
|
||||
|
||||
eable.Free();
|
||||
}
|
||||
|
||||
//SendPacket( from.Location, from.Map, new MovingParticleEffect( from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode, effect, explodeEffect, explodeSound, unknown ) );
|
||||
}
|
||||
|
||||
public static void SendPacket( Point3D origin, Map map, Packet p )
|
||||
{
|
||||
if ( map != null )
|
||||
{
|
||||
IPooledEnumerable eable = map.GetClientsInRange( origin );
|
||||
|
||||
p.Acquire();
|
||||
|
||||
foreach ( NetState state in eable )
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
state.Send( p );
|
||||
}
|
||||
|
||||
p.Release();
|
||||
|
||||
eable.Free();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendPacket( IPoint3D origin, Map map, Packet p )
|
||||
{
|
||||
if ( map != null )
|
||||
{
|
||||
IPooledEnumerable eable = map.GetClientsInRange( new Point3D( origin ) );
|
||||
|
||||
p.Acquire();
|
||||
|
||||
foreach ( NetState state in eable )
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
state.Send( p );
|
||||
}
|
||||
|
||||
p.Release();
|
||||
|
||||
eable.Free();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
67
Source/EventLog.cs
Normal file
67
Source/EventLog.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/***************************************************************************
|
||||
* EventLog.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using DiagELog = System.Diagnostics.EventLog;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public static class EventLog
|
||||
{
|
||||
static EventLog()
|
||||
{
|
||||
if ( !DiagELog.SourceExists( "Ultima" ) )
|
||||
{
|
||||
DiagELog.CreateEventSource( "Ultima", "Application" );
|
||||
}
|
||||
}
|
||||
|
||||
public static void Error( int eventID, string text )
|
||||
{
|
||||
DiagELog.WriteEntry( "Ultima", text, EventLogEntryType.Error, eventID );
|
||||
}
|
||||
|
||||
public static void Error( int eventID, string format, params object[] args )
|
||||
{
|
||||
Error( eventID, String.Format( format, args ) );
|
||||
}
|
||||
|
||||
public static void Warning( int eventID, string text )
|
||||
{
|
||||
DiagELog.WriteEntry( "Ultima", text, EventLogEntryType.Warning, eventID );
|
||||
}
|
||||
|
||||
public static void Warning( int eventID, string format, params object[] args )
|
||||
{
|
||||
Warning( eventID, String.Format( format, args ) );
|
||||
}
|
||||
|
||||
public static void Inform( int eventID, string text )
|
||||
{
|
||||
DiagELog.WriteEntry( "Ultima", text, EventLogEntryType.Information, eventID );
|
||||
}
|
||||
|
||||
public static void Inform( int eventID, string format, params object[] args )
|
||||
{
|
||||
Inform( eventID, String.Format( format, args ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
1059
Source/EventSink.cs
Normal file
1059
Source/EventSink.cs
Normal file
File diff suppressed because it is too large
Load diff
192
Source/ExpansionInfo.cs
Normal file
192
Source/ExpansionInfo.cs
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
/***************************************************************************
|
||||
* ExpansionInfo.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public enum Expansion
|
||||
{
|
||||
None,
|
||||
T2A,
|
||||
UOR,
|
||||
UOTD,
|
||||
LBR,
|
||||
AOS,
|
||||
SE,
|
||||
ML,
|
||||
SA
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ClientFlags
|
||||
{
|
||||
None = 0x00000000,
|
||||
Felucca = 0x00000001,
|
||||
Trammel = 0x00000002,
|
||||
Ilshenar = 0x00000004,
|
||||
Malas = 0x00000008,
|
||||
Tokuno = 0x00000010,
|
||||
TerMur = 0x00000020,
|
||||
Unk1 = 0x00000040,
|
||||
Unk2 = 0x00000080,
|
||||
UOTD = 0x00000100
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum FeatureFlags
|
||||
{
|
||||
None = 0x00000000,
|
||||
T2A = 0x00000001,
|
||||
UOR = 0x00000002,
|
||||
UOTD = 0x00000004,
|
||||
LBR = 0x00000008,
|
||||
AOS = 0x00000010,
|
||||
SixthCharacterSlot = 0x00000020,
|
||||
SE = 0x00000040,
|
||||
ML = 0x00000080,
|
||||
Unk1 = 0x00000100,
|
||||
Unk2 = 0x00000200,
|
||||
Unk3 = 0x00000400,
|
||||
Unk4 = 0x00000800,
|
||||
SeventhCharacterSlot = 0x00001000,
|
||||
Unk5 = 0x00002000,
|
||||
Unk6 = 0x00004000,
|
||||
Unk7 = 0x00008000,
|
||||
SA = 0x00010000,
|
||||
|
||||
|
||||
ExpansionNone = None,
|
||||
ExpansionT2A = T2A,
|
||||
ExpansionUOR = ExpansionT2A | UOR,
|
||||
ExpansionUOTD = ExpansionUOR | UOTD,
|
||||
ExpansionLBR = ExpansionUOTD | LBR,
|
||||
ExpansionAOS = ExpansionLBR | AOS | Unk7,
|
||||
ExpansionSE = ExpansionAOS | SE,
|
||||
ExpansionML = ExpansionSE | ML | Unk2,
|
||||
ExpansionSA = ExpansionML | SA
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum CharacterListFlags
|
||||
{
|
||||
None = 0x00000000,
|
||||
Unk1 = 0x00000001,
|
||||
Unk2 = 0x00000002,
|
||||
OneCharacterSlot = 0x00000004,
|
||||
ContextMenus = 0x00000008,
|
||||
SlotLimit = 0x00000010,
|
||||
AOS = 0x00000020,
|
||||
SixthCharacterSlot = 0x00000040,
|
||||
SE = 0x00000080,
|
||||
ML = 0x00000100,
|
||||
Unk4 = 0x00000200,
|
||||
Unk5 = 0x00000400,
|
||||
Unk6 = 0x00000800,
|
||||
SeventhCharacterSlot = 0x00001000,
|
||||
Unk7 = 0x00002000,
|
||||
|
||||
ExpansionNone = ContextMenus, //
|
||||
ExpansionT2A = ContextMenus, //
|
||||
ExpansionUOR = ContextMenus, // None
|
||||
ExpansionUOTD = ContextMenus, //
|
||||
ExpansionLBR = ContextMenus, //
|
||||
ExpansionAOS = ContextMenus | AOS,
|
||||
ExpansionSE = ExpansionAOS | SE,
|
||||
ExpansionML = ExpansionSE | ML,
|
||||
ExpansionSA = ExpansionML
|
||||
}
|
||||
|
||||
public class ExpansionInfo
|
||||
{
|
||||
public static ExpansionInfo[] Table { get { return m_Table; } }
|
||||
private static ExpansionInfo[] m_Table = new ExpansionInfo[]
|
||||
{
|
||||
new ExpansionInfo( 0, "None", ClientFlags.None, FeatureFlags.ExpansionNone, CharacterListFlags.ExpansionNone, 0x0000 ),
|
||||
new ExpansionInfo( 1, "The Second Age", ClientFlags.Felucca, FeatureFlags.ExpansionT2A, CharacterListFlags.ExpansionT2A, 0x0000 ),
|
||||
new ExpansionInfo( 2, "Renaissance", ClientFlags.Trammel, FeatureFlags.ExpansionUOR, CharacterListFlags.ExpansionUOR, 0x0000 ),
|
||||
new ExpansionInfo( 3, "Third Dawn", ClientFlags.Ilshenar, FeatureFlags.ExpansionUOTD, CharacterListFlags.ExpansionUOTD, 0x0000 ),
|
||||
new ExpansionInfo( 4, "Blackthorn's Revenge", ClientFlags.Ilshenar, FeatureFlags.ExpansionLBR, CharacterListFlags.ExpansionLBR, 0x0000 ),
|
||||
new ExpansionInfo( 5, "Age of Shadows", ClientFlags.Malas, FeatureFlags.ExpansionAOS, CharacterListFlags.ExpansionAOS, 0x0000 ),
|
||||
new ExpansionInfo( 6, "Samurai Empire", ClientFlags.Tokuno, FeatureFlags.ExpansionSE, CharacterListFlags.ExpansionSE, 0x00C0 ), // 0x20 | 0x80
|
||||
new ExpansionInfo( 7, "Mondain's Legacy", new ClientVersion( "5.0.0a" ), FeatureFlags.ExpansionML, CharacterListFlags.ExpansionML, 0x02C0 ), // 0x20 | 0x80 | 0x200
|
||||
new ExpansionInfo( 8, "Stygian Abyss", ClientFlags.TerMur, FeatureFlags.ExpansionSA, CharacterListFlags.ExpansionSA, 0x102C0 ) // 0x20 | 0x80 | 0x200 | 0x10000
|
||||
};
|
||||
|
||||
private string m_Name;
|
||||
private int m_ID, m_CustomHousingFlag;
|
||||
|
||||
private ClientFlags m_ClientFlags;
|
||||
private FeatureFlags m_SupportedFeatures;
|
||||
private CharacterListFlags m_CharListFlags;
|
||||
|
||||
private ClientVersion m_RequiredClient; // Used as an alternative to the flags
|
||||
|
||||
public string Name{ get{ return m_Name; } }
|
||||
public int ID{ get{ return m_ID; } }
|
||||
public ClientFlags ClientFlags{ get{ return m_ClientFlags; } }
|
||||
public FeatureFlags SupportedFeatures{ get{ return m_SupportedFeatures; } }
|
||||
public CharacterListFlags CharacterListFlags { get { return m_CharListFlags; } }
|
||||
public int CustomHousingFlag { get{ return m_CustomHousingFlag; } }
|
||||
public ClientVersion RequiredClient { get { return m_RequiredClient; } }
|
||||
|
||||
public ExpansionInfo( int id, string name, ClientFlags clientFlags, FeatureFlags supportedFeatures, CharacterListFlags charListFlags, int customHousingFlag )
|
||||
{
|
||||
m_Name = name;
|
||||
m_ID = id;
|
||||
m_ClientFlags = clientFlags;
|
||||
m_SupportedFeatures = supportedFeatures;
|
||||
m_CharListFlags = charListFlags;
|
||||
m_CustomHousingFlag = customHousingFlag;
|
||||
}
|
||||
|
||||
public ExpansionInfo( int id, string name, ClientVersion requiredClient, FeatureFlags supportedFeatures, CharacterListFlags charListFlags, int customHousingFlag )
|
||||
{
|
||||
m_Name = name;
|
||||
m_ID = id;
|
||||
m_SupportedFeatures = supportedFeatures;
|
||||
m_CharListFlags = charListFlags;
|
||||
m_CustomHousingFlag = customHousingFlag;
|
||||
m_RequiredClient = requiredClient;
|
||||
}
|
||||
|
||||
public static ExpansionInfo GetInfo( Expansion ex )
|
||||
{
|
||||
return GetInfo( (int)ex );
|
||||
}
|
||||
|
||||
public static ExpansionInfo GetInfo( int ex )
|
||||
{
|
||||
int v = (int)ex;
|
||||
|
||||
if( v < 0 || v >= m_Table.Length )
|
||||
v = 0;
|
||||
|
||||
return m_Table[v];
|
||||
}
|
||||
|
||||
public static ExpansionInfo CurrentExpansion { get { return GetInfo( Core.Expansion ); } }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
638
Source/Geometry.cs
Normal file
638
Source/Geometry.cs
Normal file
|
|
@ -0,0 +1,638 @@
|
|||
/***************************************************************************
|
||||
* Geometry.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
[Parsable]
|
||||
public struct Point2D : IPoint2D, IComparable, IComparable<Point2D>
|
||||
{
|
||||
internal int m_X;
|
||||
internal int m_Y;
|
||||
|
||||
public static readonly Point2D Zero = new Point2D( 0, 0 );
|
||||
|
||||
public Point2D( int x, int y )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
}
|
||||
|
||||
public Point2D( IPoint2D p ) : this( p.X, p.Y )
|
||||
{
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_X = value;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Y = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format( "({0}, {1})", m_X, m_Y );
|
||||
}
|
||||
|
||||
public static Point2D Parse( string value )
|
||||
{
|
||||
int start = value.IndexOf( '(' );
|
||||
int end = value.IndexOf( ',', start + 1 );
|
||||
|
||||
string param1 = value.Substring( start + 1, end - (start + 1) ).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf( ')', start + 1 );
|
||||
|
||||
string param2 = value.Substring( start + 1, end - (start + 1) ).Trim();
|
||||
|
||||
return new Point2D( Convert.ToInt32( param1 ), Convert.ToInt32( param2 ) );
|
||||
}
|
||||
|
||||
public int CompareTo( Point2D other )
|
||||
{
|
||||
int v = ( m_X.CompareTo( other.m_X ) );
|
||||
|
||||
if ( v == 0 )
|
||||
v = ( m_Y.CompareTo( other.m_Y ) );
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public int CompareTo( object other )
|
||||
{
|
||||
if ( other is Point2D )
|
||||
return this.CompareTo( (Point2D) other );
|
||||
else if ( other == null )
|
||||
return -1;
|
||||
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
public override bool Equals( object o )
|
||||
{
|
||||
if ( o == null || !(o is IPoint2D) ) return false;
|
||||
|
||||
IPoint2D p = (IPoint2D)o;
|
||||
|
||||
return m_X == p.X && m_Y == p.Y;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return m_X ^ m_Y;
|
||||
}
|
||||
|
||||
public static bool operator == ( Point2D l, Point2D r )
|
||||
{
|
||||
return l.m_X == r.m_X && l.m_Y == r.m_Y;
|
||||
}
|
||||
|
||||
public static bool operator != ( Point2D l, Point2D r )
|
||||
{
|
||||
return l.m_X != r.m_X || l.m_Y != r.m_Y;
|
||||
}
|
||||
|
||||
public static bool operator == ( Point2D l, IPoint2D r )
|
||||
{
|
||||
if ( Object.ReferenceEquals( r, null ) )
|
||||
return false;
|
||||
|
||||
return l.m_X == r.X && l.m_Y == r.Y;
|
||||
}
|
||||
|
||||
public static bool operator != ( Point2D l, IPoint2D r )
|
||||
{
|
||||
if ( Object.ReferenceEquals( r, null ) )
|
||||
return false;
|
||||
|
||||
return l.m_X !=r.X || l.m_Y != r.Y;
|
||||
}
|
||||
|
||||
public static bool operator > ( Point2D l, Point2D r )
|
||||
{
|
||||
return l.m_X > r.m_X && l.m_Y > r.m_Y;
|
||||
}
|
||||
|
||||
public static bool operator > ( Point2D l, Point3D r )
|
||||
{
|
||||
return l.m_X > r.m_X && l.m_Y > r.m_Y;
|
||||
}
|
||||
|
||||
public static bool operator > ( Point2D l, IPoint2D r )
|
||||
{
|
||||
if ( Object.ReferenceEquals( r, null ) )
|
||||
return false;
|
||||
|
||||
return l.m_X > r.X && l.m_Y > r.Y;
|
||||
}
|
||||
|
||||
public static bool operator < ( Point2D l, Point2D r )
|
||||
{
|
||||
return l.m_X < r.m_X && l.m_Y < r.m_Y;
|
||||
}
|
||||
|
||||
public static bool operator < ( Point2D l, Point3D r )
|
||||
{
|
||||
return l.m_X < r.m_X && l.m_Y < r.m_Y;
|
||||
}
|
||||
|
||||
public static bool operator < ( Point2D l, IPoint2D r )
|
||||
{
|
||||
if ( Object.ReferenceEquals( r, null ) )
|
||||
return false;
|
||||
|
||||
return l.m_X < r.X && l.m_Y < r.Y;
|
||||
}
|
||||
|
||||
public static bool operator >= ( Point2D l, Point2D r )
|
||||
{
|
||||
return l.m_X >= r.m_X && l.m_Y >= r.m_Y;
|
||||
}
|
||||
|
||||
public static bool operator >= ( Point2D l, Point3D r )
|
||||
{
|
||||
return l.m_X >= r.m_X && l.m_Y >= r.m_Y;
|
||||
}
|
||||
|
||||
public static bool operator >= ( Point2D l, IPoint2D r )
|
||||
{
|
||||
if ( Object.ReferenceEquals( r, null ) )
|
||||
return false;
|
||||
|
||||
return l.m_X >= r.X && l.m_Y >= r.Y;
|
||||
}
|
||||
|
||||
public static bool operator <= ( Point2D l, Point2D r )
|
||||
{
|
||||
return l.m_X <= r.m_X && l.m_Y <= r.m_Y;
|
||||
}
|
||||
|
||||
public static bool operator <= ( Point2D l, Point3D r )
|
||||
{
|
||||
return l.m_X <= r.m_X && l.m_Y <= r.m_Y;
|
||||
}
|
||||
|
||||
public static bool operator <= ( Point2D l, IPoint2D r )
|
||||
{
|
||||
if ( Object.ReferenceEquals( r, null ) )
|
||||
return false;
|
||||
|
||||
return l.m_X <= r.X && l.m_Y <= r.Y;
|
||||
}
|
||||
}
|
||||
|
||||
[Parsable]
|
||||
public struct Point3D : IPoint3D, IComparable, IComparable<Point3D>
|
||||
{
|
||||
internal int m_X;
|
||||
internal int m_Y;
|
||||
internal int m_Z;
|
||||
|
||||
public static readonly Point3D Zero = new Point3D( 0, 0, 0 );
|
||||
|
||||
public Point3D( int x, int y, int z )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Z = z;
|
||||
}
|
||||
|
||||
public Point3D( IPoint3D p )
|
||||
: this( p.X, p.Y, p.Z )
|
||||
{
|
||||
}
|
||||
|
||||
public Point3D( IPoint2D p, int z )
|
||||
: this( p.X, p.Y, z )
|
||||
{
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_X = value;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Y = value;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int Z
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Z;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Z = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format( "({0}, {1}, {2})", m_X, m_Y, m_Z );
|
||||
}
|
||||
|
||||
public override bool Equals( object o )
|
||||
{
|
||||
if ( o == null || !( o is IPoint3D ) )
|
||||
return false;
|
||||
|
||||
IPoint3D p = (IPoint3D) o;
|
||||
|
||||
return m_X == p.X && m_Y == p.Y && m_Z == p.Z;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return m_X ^ m_Y ^ m_Z;
|
||||
}
|
||||
|
||||
public static Point3D Parse( string value )
|
||||
{
|
||||
int start = value.IndexOf( '(' );
|
||||
int end = value.IndexOf( ',', start + 1 );
|
||||
|
||||
string param1 = value.Substring( start + 1, end - ( start + 1 ) ).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf( ',', start + 1 );
|
||||
|
||||
string param2 = value.Substring( start + 1, end - ( start + 1 ) ).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf( ')', start + 1 );
|
||||
|
||||
string param3 = value.Substring( start + 1, end - ( start + 1 ) ).Trim();
|
||||
|
||||
return new Point3D( Convert.ToInt32( param1 ), Convert.ToInt32( param2 ), Convert.ToInt32( param3 ) );
|
||||
}
|
||||
|
||||
public static bool operator ==( Point3D l, Point3D r )
|
||||
{
|
||||
return l.m_X == r.m_X && l.m_Y == r.m_Y && l.m_Z == r.m_Z;
|
||||
}
|
||||
|
||||
public static bool operator !=( Point3D l, Point3D r )
|
||||
{
|
||||
return l.m_X != r.m_X || l.m_Y != r.m_Y || l.m_Z != r.m_Z;
|
||||
}
|
||||
|
||||
public static bool operator ==( Point3D l, IPoint3D r )
|
||||
{
|
||||
if ( Object.ReferenceEquals( r, null ) )
|
||||
return false;
|
||||
|
||||
return l.m_X == r.X && l.m_Y == r.Y && l.m_Z == r.Z;
|
||||
}
|
||||
|
||||
public static bool operator !=( Point3D l, IPoint3D r )
|
||||
{
|
||||
if ( Object.ReferenceEquals( r, null ) )
|
||||
return false;
|
||||
|
||||
return l.m_X != r.X || l.m_Y != r.Y || l.m_Z != r.Z;
|
||||
}
|
||||
|
||||
public int CompareTo( Point3D other )
|
||||
{
|
||||
int v = ( m_X.CompareTo( other.m_X ) );
|
||||
|
||||
if ( v == 0 )
|
||||
{
|
||||
v = ( m_Y.CompareTo( other.m_Y ) );
|
||||
|
||||
if ( v == 0 )
|
||||
v = ( m_Z.CompareTo( other.m_Z ) );
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public int CompareTo( object other )
|
||||
{
|
||||
if ( other is Point3D )
|
||||
return this.CompareTo( (Point3D) other );
|
||||
else if ( other == null )
|
||||
return -1;
|
||||
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
[NoSort]
|
||||
[Parsable]
|
||||
[PropertyObject]
|
||||
public struct Rectangle2D
|
||||
{
|
||||
private Point2D m_Start;
|
||||
private Point2D m_End;
|
||||
|
||||
public Rectangle2D( IPoint2D start, IPoint2D end )
|
||||
{
|
||||
m_Start = new Point2D( start );
|
||||
m_End = new Point2D( end );
|
||||
}
|
||||
|
||||
public Rectangle2D( int x, int y, int width, int height )
|
||||
{
|
||||
m_Start = new Point2D( x, y );
|
||||
m_End = new Point2D( x + width, y + height );
|
||||
}
|
||||
|
||||
public void Set( int x, int y, int width, int height )
|
||||
{
|
||||
m_Start = new Point2D( x, y );
|
||||
m_End = new Point2D( x + width, y + height );
|
||||
}
|
||||
|
||||
public static Rectangle2D Parse( string value )
|
||||
{
|
||||
int start = value.IndexOf( '(' );
|
||||
int end = value.IndexOf( ',', start + 1 );
|
||||
|
||||
string param1 = value.Substring( start + 1, end - (start + 1) ).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf( ',', start + 1 );
|
||||
|
||||
string param2 = value.Substring( start + 1, end - (start + 1) ).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf( ',', start + 1 );
|
||||
|
||||
string param3 = value.Substring( start + 1, end - (start + 1) ).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf( ')', start + 1 );
|
||||
|
||||
string param4 = value.Substring( start + 1, end - (start + 1) ).Trim();
|
||||
|
||||
return new Rectangle2D( Convert.ToInt32( param1 ), Convert.ToInt32( param2 ), Convert.ToInt32( param3 ), Convert.ToInt32( param4 ) );
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public Point2D Start
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Start;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Start = value;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public Point2D End
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_End;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_End = value;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Start.m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Start.m_X = value;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Start.m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Start.m_Y = value;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_End.m_X - m_Start.m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_End.m_X = m_Start.m_X + value;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_End.m_Y - m_Start.m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_End.m_Y = m_Start.m_Y + value;
|
||||
}
|
||||
}
|
||||
|
||||
public void MakeHold( Rectangle2D r )
|
||||
{
|
||||
if ( r.m_Start.m_X < m_Start.m_X )
|
||||
m_Start.m_X = r.m_Start.m_X;
|
||||
|
||||
if ( r.m_Start.m_Y < m_Start.m_Y )
|
||||
m_Start.m_Y = r.m_Start.m_Y;
|
||||
|
||||
if ( r.m_End.m_X > m_End.m_X )
|
||||
m_End.m_X = r.m_End.m_X;
|
||||
|
||||
if ( r.m_End.m_Y > m_End.m_Y )
|
||||
m_End.m_Y = r.m_End.m_Y;
|
||||
}
|
||||
|
||||
public bool Contains( Point3D p )
|
||||
{
|
||||
return ( m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y );
|
||||
//return ( m_Start <= p && m_End > p );
|
||||
}
|
||||
|
||||
public bool Contains( Point2D p )
|
||||
{
|
||||
return ( m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y );
|
||||
//return ( m_Start <= p && m_End > p );
|
||||
}
|
||||
|
||||
public bool Contains( IPoint2D p )
|
||||
{
|
||||
return ( m_Start <= p && m_End > p );
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format( "({0}, {1})+({2}, {3})", X, Y, Width, Height );
|
||||
}
|
||||
}
|
||||
|
||||
[NoSort]
|
||||
[PropertyObject]
|
||||
public struct Rectangle3D
|
||||
{
|
||||
private Point3D m_Start;
|
||||
private Point3D m_End;
|
||||
|
||||
public Rectangle3D( Point3D start, Point3D end )
|
||||
{
|
||||
m_Start = start;
|
||||
m_End = end;
|
||||
}
|
||||
|
||||
public Rectangle3D( int x, int y, int z, int width, int height, int depth )
|
||||
{
|
||||
m_Start = new Point3D( x, y, z );
|
||||
m_End = new Point3D( x + width, y + height, z + depth );
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public Point3D Start
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Start;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Start = value;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public Point3D End
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_End;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_End = value;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_End.X - m_Start.X;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_End.Y - m_Start.Y;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int Depth
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_End.Z - m_Start.Z;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Contains( Point3D p )
|
||||
{
|
||||
return ( p.m_X >= m_Start.m_X )
|
||||
&& ( p.m_X < m_End.m_X )
|
||||
&& ( p.m_Y >= m_Start.m_Y )
|
||||
&& ( p.m_Y < m_End.m_Y )
|
||||
&& ( p.m_Z >= m_Start.m_Z )
|
||||
&& ( p.m_Z < m_End.m_Z );
|
||||
}
|
||||
|
||||
public bool Contains( IPoint3D p )
|
||||
{
|
||||
return ( p.X >= m_Start.m_X )
|
||||
&& ( p.X < m_End.m_X )
|
||||
&& ( p.Y >= m_Start.m_Y )
|
||||
&& ( p.Y < m_End.m_Y )
|
||||
&& ( p.Z >= m_Start.m_Z )
|
||||
&& ( p.Z < m_End.m_Z );
|
||||
}
|
||||
}
|
||||
}
|
||||
145
Source/Guild.cs
Normal file
145
Source/Guild.cs
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/***************************************************************************
|
||||
* Guild.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Guilds
|
||||
{
|
||||
public enum GuildType
|
||||
{
|
||||
Regular,
|
||||
Chaos,
|
||||
Order
|
||||
}
|
||||
|
||||
public abstract class BaseGuild : ISerializable
|
||||
{
|
||||
private int m_Id;
|
||||
|
||||
protected BaseGuild( int Id )//serialization ctor
|
||||
{
|
||||
m_Id = Id;
|
||||
m_GuildList.Add( m_Id, this );
|
||||
if ( m_Id+1 > m_NextID )
|
||||
m_NextID = m_Id + 1;
|
||||
}
|
||||
|
||||
protected BaseGuild()
|
||||
{
|
||||
m_Id = m_NextID++;
|
||||
m_GuildList.Add( m_Id, this );
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.Counselor )]
|
||||
public int Id { get { return m_Id; } }
|
||||
|
||||
int ISerializable.TypeReference {
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
int ISerializable.SerialIdentity {
|
||||
get { return m_Id; }
|
||||
}
|
||||
|
||||
public abstract void Deserialize( GenericReader reader );
|
||||
public abstract void Serialize( GenericWriter writer );
|
||||
|
||||
public abstract string Abbreviation { get; set; }
|
||||
public abstract string Name { get; set; }
|
||||
public abstract GuildType Type { get; set; }
|
||||
public abstract bool Disbanded{ get; }
|
||||
public abstract void OnDelete( Mobile mob );
|
||||
|
||||
private static Dictionary<int, BaseGuild> m_GuildList = new Dictionary<int, BaseGuild>();
|
||||
private static int m_NextID = 1;
|
||||
|
||||
public static Dictionary<int, BaseGuild> List
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_GuildList;
|
||||
}
|
||||
}
|
||||
|
||||
public static BaseGuild Find( int id )
|
||||
{
|
||||
BaseGuild g;
|
||||
|
||||
m_GuildList.TryGetValue( id, out g );
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
public static BaseGuild FindByName( string name )
|
||||
{
|
||||
foreach ( BaseGuild g in m_GuildList.Values )
|
||||
{
|
||||
if ( g.Name == name )
|
||||
return g;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static BaseGuild FindByAbbrev( string abbr )
|
||||
{
|
||||
foreach ( BaseGuild g in m_GuildList.Values )
|
||||
{
|
||||
if ( g.Abbreviation == abbr )
|
||||
return g;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<BaseGuild> Search( string find )
|
||||
{
|
||||
string[] words = find.ToLower().Split( ' ' );
|
||||
List<BaseGuild> results = new List<BaseGuild>();
|
||||
|
||||
foreach ( BaseGuild g in m_GuildList.Values )
|
||||
{
|
||||
bool match = true;
|
||||
string name = g.Name.ToLower();
|
||||
for (int i=0;i<words.Length;i++)
|
||||
{
|
||||
if ( name.IndexOf( words[i] ) == -1 )
|
||||
{
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( match )
|
||||
results.Add( g );
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format( "0x{0:X} \"{1} [{2}]\"", m_Id, Name, Abbreviation );
|
||||
}
|
||||
}
|
||||
}
|
||||
423
Source/Gumps/Gump.cs
Normal file
423
Source/Gumps/Gump.cs
Normal file
|
|
@ -0,0 +1,423 @@
|
|||
/***************************************************************************
|
||||
* Gump.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Server;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class Gump
|
||||
{
|
||||
private List<GumpEntry> m_Entries;
|
||||
private List<string> m_Strings;
|
||||
|
||||
internal int m_TextEntries, m_Switches;
|
||||
|
||||
private static int m_NextSerial = 1;
|
||||
|
||||
private int m_Serial;
|
||||
private int m_TypeID;
|
||||
private int m_X, m_Y;
|
||||
|
||||
private bool m_Dragable = true;
|
||||
private bool m_Closable = true;
|
||||
private bool m_Resizable = true;
|
||||
private bool m_Disposable = true;
|
||||
|
||||
public static int GetTypeID( Type type )
|
||||
{
|
||||
return type.FullName.GetHashCode();
|
||||
}
|
||||
|
||||
public Gump( int x, int y )
|
||||
{
|
||||
do
|
||||
{
|
||||
m_Serial = m_NextSerial++;
|
||||
} while ( m_Serial == 0 ); // standard client apparently doesn't send a gump response packet if serial == 0
|
||||
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
|
||||
m_TypeID = GetTypeID( this.GetType() );
|
||||
|
||||
m_Entries = new List<GumpEntry>();
|
||||
m_Strings = new List<string>();
|
||||
}
|
||||
|
||||
public void Invalidate()
|
||||
{
|
||||
//if ( m_Strings.Count > 0 )
|
||||
// m_Strings.Clear();
|
||||
}
|
||||
|
||||
public int TypeID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_TypeID;
|
||||
}
|
||||
}
|
||||
|
||||
public List<GumpEntry> Entries
|
||||
{
|
||||
get{ return m_Entries; }
|
||||
}
|
||||
|
||||
public int Serial
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Serial;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Serial != value )
|
||||
{
|
||||
m_Serial = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_X != value )
|
||||
{
|
||||
m_X = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Y != value )
|
||||
{
|
||||
m_Y = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Disposable
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Disposable;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Disposable != value )
|
||||
{
|
||||
m_Disposable = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Resizable
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Resizable;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Resizable != value )
|
||||
{
|
||||
m_Resizable = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Dragable
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Dragable;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Dragable != value )
|
||||
{
|
||||
m_Dragable = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Closable
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Closable;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Closable != value )
|
||||
{
|
||||
m_Closable = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddPage( int page )
|
||||
{
|
||||
Add( new GumpPage( page ) );
|
||||
}
|
||||
|
||||
public void AddAlphaRegion( int x, int y, int width, int height )
|
||||
{
|
||||
Add( new GumpAlphaRegion( x, y, width, height ) );
|
||||
}
|
||||
|
||||
public void AddBackground( int x, int y, int width, int height, int gumpID )
|
||||
{
|
||||
Add( new GumpBackground( x, y, width, height, gumpID ) );
|
||||
}
|
||||
|
||||
public void AddButton( int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param )
|
||||
{
|
||||
Add( new GumpButton( x, y, normalID, pressedID, buttonID, type, param ) );
|
||||
}
|
||||
|
||||
public void AddCheck( int x, int y, int inactiveID, int activeID, bool initialState, int switchID )
|
||||
{
|
||||
Add( new GumpCheck( x, y, inactiveID, activeID, initialState, switchID ) );
|
||||
}
|
||||
|
||||
public void AddGroup( int group )
|
||||
{
|
||||
Add( new GumpGroup( group ) );
|
||||
}
|
||||
|
||||
public void AddTooltip( int number )
|
||||
{
|
||||
Add( new GumpTooltip( number ) );
|
||||
}
|
||||
|
||||
public void AddHtml( int x, int y, int width, int height, string text, bool background, bool scrollbar )
|
||||
{
|
||||
Add( new GumpHtml( x, y, width, height, text, background, scrollbar ) );
|
||||
}
|
||||
|
||||
public void AddHtmlLocalized( int x, int y, int width, int height, int number, bool background, bool scrollbar )
|
||||
{
|
||||
Add( new GumpHtmlLocalized( x, y, width, height, number, background, scrollbar ) );
|
||||
}
|
||||
|
||||
public void AddHtmlLocalized( int x, int y, int width, int height, int number, int color, bool background, bool scrollbar )
|
||||
{
|
||||
Add( new GumpHtmlLocalized( x, y, width, height, number, color, background, scrollbar ) );
|
||||
}
|
||||
|
||||
public void AddHtmlLocalized( int x, int y, int width, int height, int number, string args, int color, bool background, bool scrollbar )
|
||||
{
|
||||
Add( new GumpHtmlLocalized( x, y, width, height, number, args, color, background, scrollbar ) );
|
||||
}
|
||||
|
||||
public void AddImage( int x, int y, int gumpID )
|
||||
{
|
||||
Add( new GumpImage( x, y, gumpID ) );
|
||||
}
|
||||
|
||||
public void AddImage( int x, int y, int gumpID, int hue )
|
||||
{
|
||||
Add( new GumpImage( x, y, gumpID, hue ) );
|
||||
}
|
||||
|
||||
public void AddImageTiled( int x, int y, int width, int height, int gumpID )
|
||||
{
|
||||
Add( new GumpImageTiled( x, y, width, height, gumpID ) );
|
||||
}
|
||||
|
||||
public void AddImageTiledButton( int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param, int itemID, int hue, int width, int height )
|
||||
{
|
||||
Add( new GumpImageTileButton( x, y, normalID, pressedID, buttonID, type, param, itemID, hue, width, height ) );
|
||||
}
|
||||
public void AddImageTiledButton( int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param, int itemID, int hue, int width, int height, int localizedTooltip )
|
||||
{
|
||||
Add( new GumpImageTileButton( x, y, normalID, pressedID, buttonID, type, param, itemID, hue, width, height, localizedTooltip ) );
|
||||
}
|
||||
|
||||
public void AddItem( int x, int y, int itemID )
|
||||
{
|
||||
Add( new GumpItem( x, y, itemID ) );
|
||||
}
|
||||
|
||||
public void AddItem( int x, int y, int itemID, int hue )
|
||||
{
|
||||
Add( new GumpItem( x, y, itemID, hue ) );
|
||||
}
|
||||
|
||||
public void AddLabel( int x, int y, int hue, string text )
|
||||
{
|
||||
Add( new GumpLabel( x, y, hue, text ) );
|
||||
}
|
||||
|
||||
public void AddLabelCropped( int x, int y, int width, int height, int hue, string text )
|
||||
{
|
||||
Add( new GumpLabelCropped( x, y, width, height, hue, text ) );
|
||||
}
|
||||
|
||||
public void AddRadio( int x, int y, int inactiveID, int activeID, bool initialState, int switchID )
|
||||
{
|
||||
Add( new GumpRadio( x, y, inactiveID, activeID, initialState, switchID ) );
|
||||
}
|
||||
|
||||
public void AddTextEntry( int x, int y, int width, int height, int hue, int entryID, string initialText )
|
||||
{
|
||||
Add( new GumpTextEntry( x, y, width, height, hue, entryID, initialText ) );
|
||||
}
|
||||
|
||||
public void AddTextEntry( int x, int y, int width, int height, int hue, int entryID, string initialText, int size ) {
|
||||
Add( new GumpTextEntryLimited( x, y, width, height, hue, entryID, initialText, size ) );
|
||||
}
|
||||
|
||||
public void Add( GumpEntry g )
|
||||
{
|
||||
if ( g.Parent != this )
|
||||
{
|
||||
g.Parent = this;
|
||||
}
|
||||
else if ( !m_Entries.Contains( g ) )
|
||||
{
|
||||
Invalidate();
|
||||
m_Entries.Add( g );
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove( GumpEntry g )
|
||||
{
|
||||
Invalidate();
|
||||
m_Entries.Remove( g );
|
||||
g.Parent = null;
|
||||
}
|
||||
|
||||
public int Intern( string value )
|
||||
{
|
||||
int indexOf = m_Strings.IndexOf( value );
|
||||
|
||||
if ( indexOf >= 0 )
|
||||
{
|
||||
return indexOf;
|
||||
}
|
||||
else
|
||||
{
|
||||
Invalidate();
|
||||
m_Strings.Add( value );
|
||||
return m_Strings.Count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void SendTo( NetState state )
|
||||
{
|
||||
state.AddGump( this );
|
||||
state.Send( Compile( state ) );
|
||||
}
|
||||
|
||||
public static byte[] StringToBuffer( string str )
|
||||
{
|
||||
return Encoding.ASCII.GetBytes( str );
|
||||
}
|
||||
|
||||
private static byte[] m_BeginLayout = StringToBuffer( "{ " );
|
||||
private static byte[] m_EndLayout = StringToBuffer( " }" );
|
||||
|
||||
private static byte[] m_NoMove = StringToBuffer( "{ nomove }" );
|
||||
private static byte[] m_NoClose = StringToBuffer( "{ noclose }" );
|
||||
private static byte[] m_NoDispose = StringToBuffer( "{ nodispose }" );
|
||||
private static byte[] m_NoResize = StringToBuffer( "{ noresize }" );
|
||||
|
||||
private Packet Compile()
|
||||
{
|
||||
return Compile( null );
|
||||
}
|
||||
|
||||
private Packet Compile( NetState ns )
|
||||
{
|
||||
IGumpWriter disp;
|
||||
|
||||
if ( ns != null && ns.Unpack )
|
||||
disp = new DisplayGumpPacked( this );
|
||||
else
|
||||
disp = new DisplayGumpFast( this );
|
||||
|
||||
if ( !m_Dragable )
|
||||
disp.AppendLayout( m_NoMove );
|
||||
|
||||
if ( !m_Closable )
|
||||
disp.AppendLayout( m_NoClose );
|
||||
|
||||
if ( !m_Disposable )
|
||||
disp.AppendLayout( m_NoDispose );
|
||||
|
||||
if ( !m_Resizable )
|
||||
disp.AppendLayout( m_NoResize );
|
||||
|
||||
int count = m_Entries.Count;
|
||||
GumpEntry e;
|
||||
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
e = m_Entries[i];
|
||||
|
||||
disp.AppendLayout( m_BeginLayout );
|
||||
e.AppendTo( disp );
|
||||
disp.AppendLayout( m_EndLayout );
|
||||
}
|
||||
|
||||
disp.WriteStrings( m_Strings );
|
||||
|
||||
disp.Flush();
|
||||
|
||||
m_TextEntries = disp.TextEntries;
|
||||
m_Switches = disp.Switches;
|
||||
|
||||
return disp as Packet;
|
||||
}
|
||||
|
||||
public virtual void OnResponse( NetState sender, RelayInfo info )
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnServerClose( NetState owner ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
103
Source/Gumps/GumpAlphaRegion.cs
Normal file
103
Source/Gumps/GumpAlphaRegion.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/***************************************************************************
|
||||
* GumpAlphaRegion.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpAlphaRegion : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_Width, m_Height;
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Width;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Width, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Height;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Height, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpAlphaRegion( int x, int y, int width, int height )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ checkertrans {0} {1} {2} {3} }}", m_X, m_Y, m_Width, m_Height );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "checkertrans" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
}
|
||||
}
|
||||
}
|
||||
118
Source/Gumps/GumpBackground.cs
Normal file
118
Source/Gumps/GumpBackground.cs
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/***************************************************************************
|
||||
* GumpBackground.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpBackground : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_Width, m_Height;
|
||||
private int m_GumpID;
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Width;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Width, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Height;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Height, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int GumpID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_GumpID;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_GumpID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpBackground( int x, int y, int width, int height, int gumpID )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_GumpID = gumpID;
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ resizepic {0} {1} {2} {3} {4} }}", m_X, m_Y, m_GumpID, m_Width, m_Height );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "resizepic" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_GumpID );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
}
|
||||
}
|
||||
}
|
||||
164
Source/Gumps/GumpButton.cs
Normal file
164
Source/Gumps/GumpButton.cs
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
/***************************************************************************
|
||||
* GumpButton.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public enum GumpButtonType
|
||||
{
|
||||
Page = 0,
|
||||
Reply = 1
|
||||
}
|
||||
|
||||
public class GumpButton : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_ID1, m_ID2;
|
||||
private int m_ButtonID;
|
||||
private GumpButtonType m_Type;
|
||||
private int m_Param;
|
||||
|
||||
public GumpButton( int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_ID1 = normalID;
|
||||
m_ID2 = pressedID;
|
||||
m_ButtonID = buttonID;
|
||||
m_Type = type;
|
||||
m_Param = param;
|
||||
}
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int NormalID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ID1;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ID1, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int PressedID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ID2;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ID2, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int ButtonID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ButtonID;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ButtonID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpButtonType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Type != value )
|
||||
{
|
||||
m_Type = value;
|
||||
|
||||
Gump parent = Parent;
|
||||
|
||||
if ( parent != null )
|
||||
{
|
||||
parent.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Param
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Param;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Param, value );
|
||||
}
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ button {0} {1} {2} {3} {4} {5} {6} }}", m_X, m_Y, m_ID1, m_ID2, (int)m_Type, m_Param, m_ButtonID );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "button" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_ID1 );
|
||||
disp.AppendLayout( m_ID2 );
|
||||
disp.AppendLayout( (int)m_Type );
|
||||
disp.AppendLayout( m_Param );
|
||||
disp.AppendLayout( m_ButtonID );
|
||||
}
|
||||
}
|
||||
}
|
||||
135
Source/Gumps/GumpCheck.cs
Normal file
135
Source/Gumps/GumpCheck.cs
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
/***************************************************************************
|
||||
* GumpCheck.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpCheck : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_ID1, m_ID2;
|
||||
private bool m_InitialState;
|
||||
private int m_SwitchID;
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int InactiveID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ID1;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ID1, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int ActiveID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ID2;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ID2, value );
|
||||
}
|
||||
}
|
||||
|
||||
public bool InitialState
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_InitialState;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_InitialState, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int SwitchID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_SwitchID;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_SwitchID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpCheck( int x, int y, int inactiveID, int activeID, bool initialState, int switchID )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_ID1 = inactiveID;
|
||||
m_ID2 = activeID;
|
||||
m_InitialState = initialState;
|
||||
m_SwitchID = switchID;
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ checkbox {0} {1} {2} {3} {4} {5} }}", m_X, m_Y, m_ID1, m_ID2, m_InitialState ? 1 : 0, m_SwitchID );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "checkbox" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_ID1 );
|
||||
disp.AppendLayout( m_ID2 );
|
||||
disp.AppendLayout( m_InitialState );
|
||||
disp.AppendLayout( m_SwitchID );
|
||||
|
||||
disp.Switches++;
|
||||
}
|
||||
}
|
||||
}
|
||||
98
Source/Gumps/GumpEntry.cs
Normal file
98
Source/Gumps/GumpEntry.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/***************************************************************************
|
||||
* GumpEntry.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public abstract class GumpEntry
|
||||
{
|
||||
private Gump m_Parent;
|
||||
|
||||
protected GumpEntry()
|
||||
{
|
||||
}
|
||||
|
||||
protected void Delta( ref int var, int val )
|
||||
{
|
||||
if ( var != val )
|
||||
{
|
||||
var = val;
|
||||
|
||||
if ( m_Parent != null )
|
||||
{
|
||||
m_Parent.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void Delta( ref bool var, bool val )
|
||||
{
|
||||
if ( var != val )
|
||||
{
|
||||
var = val;
|
||||
|
||||
if ( m_Parent != null )
|
||||
{
|
||||
m_Parent.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void Delta( ref string var, string val )
|
||||
{
|
||||
if ( var != val )
|
||||
{
|
||||
var = val;
|
||||
|
||||
if ( m_Parent != null )
|
||||
{
|
||||
m_Parent.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Gump Parent
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Parent;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Parent != value )
|
||||
{
|
||||
if ( m_Parent != null )
|
||||
{
|
||||
m_Parent.Remove( this );
|
||||
}
|
||||
|
||||
m_Parent = value;
|
||||
|
||||
m_Parent.Add( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract string Compile();
|
||||
public abstract void AppendTo( IGumpWriter disp );
|
||||
}
|
||||
}
|
||||
60
Source/Gumps/GumpGroup.cs
Normal file
60
Source/Gumps/GumpGroup.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/***************************************************************************
|
||||
* GumpGroup.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpGroup : GumpEntry
|
||||
{
|
||||
private int m_Group;
|
||||
|
||||
public GumpGroup( int group )
|
||||
{
|
||||
m_Group = group;
|
||||
}
|
||||
|
||||
public int Group
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Group;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Group, value );
|
||||
}
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ group {0} }}", m_Group );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "group" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_Group );
|
||||
}
|
||||
}
|
||||
}
|
||||
147
Source/Gumps/GumpHtml.cs
Normal file
147
Source/Gumps/GumpHtml.cs
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
/***************************************************************************
|
||||
* GumpHtml.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpHtml : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_Width, m_Height;
|
||||
private string m_Text;
|
||||
private bool m_Background, m_Scrollbar;
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Width;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Width, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Height;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Height, value );
|
||||
}
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Text, value );
|
||||
}
|
||||
}
|
||||
|
||||
public bool Background
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Background;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Background, value );
|
||||
}
|
||||
}
|
||||
|
||||
public bool Scrollbar
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Scrollbar;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Scrollbar, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpHtml( int x, int y, int width, int height, string text, bool background, bool scrollbar )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_Text = text;
|
||||
m_Background = background;
|
||||
m_Scrollbar = scrollbar;
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ htmlgump {0} {1} {2} {3} {4} {5} {6} }}", m_X, m_Y, m_Width, m_Height, Parent.Intern( m_Text ), m_Background ? 1 : 0, m_Scrollbar ? 1 : 0 );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "htmlgump" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
disp.AppendLayout( Parent.Intern( m_Text ) );
|
||||
disp.AppendLayout( m_Background );
|
||||
disp.AppendLayout( m_Scrollbar );
|
||||
}
|
||||
}
|
||||
}
|
||||
287
Source/Gumps/GumpHtmlLocalized.cs
Normal file
287
Source/Gumps/GumpHtmlLocalized.cs
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
/***************************************************************************
|
||||
* GumpHtmlLocalized.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public enum GumpHtmlLocalizedType
|
||||
{
|
||||
Plain,
|
||||
Color,
|
||||
Args
|
||||
}
|
||||
|
||||
public class GumpHtmlLocalized : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_Width, m_Height;
|
||||
private int m_Number;
|
||||
private string m_Args;
|
||||
private int m_Color;
|
||||
private bool m_Background, m_Scrollbar;
|
||||
|
||||
private GumpHtmlLocalizedType m_Type;
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Width;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Width, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Height;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Height, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Number
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Number;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Number, value );
|
||||
}
|
||||
}
|
||||
|
||||
public string Args
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Args;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Args, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Color
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Color;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Color, value );
|
||||
}
|
||||
}
|
||||
|
||||
public bool Background
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Background;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Background, value );
|
||||
}
|
||||
}
|
||||
|
||||
public bool Scrollbar
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Scrollbar;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Scrollbar, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpHtmlLocalizedType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ( m_Type != value )
|
||||
{
|
||||
m_Type = value;
|
||||
|
||||
if ( Parent != null )
|
||||
Parent.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GumpHtmlLocalized( int x, int y, int width, int height, int number, bool background, bool scrollbar )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_Number = number;
|
||||
m_Background = background;
|
||||
m_Scrollbar = scrollbar;
|
||||
|
||||
m_Type = GumpHtmlLocalizedType.Plain;
|
||||
}
|
||||
|
||||
public GumpHtmlLocalized( int x, int y, int width, int height, int number, int color, bool background, bool scrollbar )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_Number = number;
|
||||
m_Color = color;
|
||||
m_Background = background;
|
||||
m_Scrollbar = scrollbar;
|
||||
|
||||
m_Type = GumpHtmlLocalizedType.Color;
|
||||
}
|
||||
|
||||
public GumpHtmlLocalized( int x, int y, int width, int height, int number, string args, int color, bool background, bool scrollbar )
|
||||
{
|
||||
// Are multiple arguments unsupported? And what about non ASCII arguments?
|
||||
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_Number = number;
|
||||
m_Args = args;
|
||||
m_Color = color;
|
||||
m_Background = background;
|
||||
m_Scrollbar = scrollbar;
|
||||
|
||||
m_Type = GumpHtmlLocalizedType.Args;
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
switch ( m_Type )
|
||||
{
|
||||
case GumpHtmlLocalizedType.Plain:
|
||||
return String.Format( "{{ xmfhtmlgump {0} {1} {2} {3} {4} {5} {6} }}", m_X, m_Y, m_Width, m_Height, m_Number, m_Background ? 1 : 0, m_Scrollbar ? 1 : 0 );
|
||||
|
||||
case GumpHtmlLocalizedType.Color:
|
||||
return String.Format( "{{ xmfhtmlgumpcolor {0} {1} {2} {3} {4} {5} {6} {7} }}", m_X, m_Y, m_Width, m_Height, m_Number, m_Background ? 1 : 0, m_Scrollbar ? 1 : 0, m_Color );
|
||||
|
||||
default: // GumpHtmlLocalizedType.Args
|
||||
return String.Format( "{{ xmfhtmltok {0} {1} {2} {3} {4} {5} {6} {7} @{8}@ }}", m_X, m_Y, m_Width, m_Height, m_Background ? 1 : 0, m_Scrollbar ? 1 : 0, m_Color, m_Number, m_Args );
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutNamePlain = Gump.StringToBuffer( "xmfhtmlgump" );
|
||||
private static byte[] m_LayoutNameColor = Gump.StringToBuffer( "xmfhtmlgumpcolor" );
|
||||
private static byte[] m_LayoutNameArgs = Gump.StringToBuffer( "xmfhtmltok" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
switch ( m_Type )
|
||||
{
|
||||
case GumpHtmlLocalizedType.Plain:
|
||||
{
|
||||
disp.AppendLayout( m_LayoutNamePlain );
|
||||
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
disp.AppendLayout( m_Number );
|
||||
disp.AppendLayout( m_Background );
|
||||
disp.AppendLayout( m_Scrollbar );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GumpHtmlLocalizedType.Color:
|
||||
{
|
||||
disp.AppendLayout( m_LayoutNameColor );
|
||||
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
disp.AppendLayout( m_Number );
|
||||
disp.AppendLayout( m_Background );
|
||||
disp.AppendLayout( m_Scrollbar );
|
||||
disp.AppendLayout( m_Color );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GumpHtmlLocalizedType.Args:
|
||||
{
|
||||
disp.AppendLayout( m_LayoutNameArgs );
|
||||
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
disp.AppendLayout( m_Background );
|
||||
disp.AppendLayout( m_Scrollbar );
|
||||
disp.AppendLayout( m_Color );
|
||||
disp.AppendLayout( m_Number );
|
||||
disp.AppendLayout( m_Args );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Source/Gumps/GumpImage.cs
Normal file
117
Source/Gumps/GumpImage.cs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/***************************************************************************
|
||||
* GumpImage.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpImage : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_GumpID;
|
||||
private int m_Hue;
|
||||
|
||||
public GumpImage( int x, int y, int gumpID ) : this( x, y, gumpID, 0 )
|
||||
{
|
||||
}
|
||||
|
||||
public GumpImage( int x, int y, int gumpID, int hue )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_GumpID = gumpID;
|
||||
m_Hue = hue;
|
||||
}
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int GumpID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_GumpID;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_GumpID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Hue, value );
|
||||
}
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
if ( m_Hue == 0 )
|
||||
return String.Format( "{{ gumppic {0} {1} {2} }}", m_X, m_Y, m_GumpID );
|
||||
else
|
||||
return String.Format( "{{ gumppic {0} {1} {2} hue={3} }}", m_X, m_Y, m_GumpID, m_Hue );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "gumppic" );
|
||||
private static byte[] m_HueEquals = Gump.StringToBuffer( " hue=" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_GumpID );
|
||||
|
||||
if ( m_Hue != 0 )
|
||||
{
|
||||
disp.AppendLayout( m_HueEquals );
|
||||
disp.AppendLayoutNS( m_Hue );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
251
Source/Gumps/GumpImageTileButton.cs
Normal file
251
Source/Gumps/GumpImageTileButton.cs
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
/***************************************************************************
|
||||
* GumpImageTileButton.cs
|
||||
* -------------------
|
||||
* begin : April 26, 2005
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpImageTileButton : GumpEntry
|
||||
{
|
||||
//Note, on OSI, The tooltip supports ONLY clilocs as far as I can figure out, and the tooltip ONLY works after the buttonTileArt (as far as I can tell from testing)
|
||||
private int m_X, m_Y;
|
||||
private int m_ID1, m_ID2;
|
||||
private int m_ButtonID;
|
||||
private GumpButtonType m_Type;
|
||||
private int m_Param;
|
||||
|
||||
private int m_ItemID;
|
||||
private int m_Hue;
|
||||
private int m_Width;
|
||||
private int m_Height;
|
||||
|
||||
private int m_LocalizedTooltip;
|
||||
|
||||
public GumpImageTileButton( int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param, int itemID, int hue, int width, int height ) : this(x, y, normalID, pressedID, buttonID, type, param, itemID, hue, width, height, -1 )
|
||||
{
|
||||
}
|
||||
public GumpImageTileButton( int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param, int itemID, int hue, int width, int height, int localizedTooltip )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_ID1 = normalID;
|
||||
m_ID2 = pressedID;
|
||||
m_ButtonID = buttonID;
|
||||
m_Type = type;
|
||||
m_Param = param;
|
||||
|
||||
m_ItemID = itemID;
|
||||
m_Hue = hue;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
|
||||
m_LocalizedTooltip = localizedTooltip;
|
||||
}
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int NormalID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ID1;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ID1, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int PressedID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ID2;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ID2, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int ButtonID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ButtonID;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ButtonID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpButtonType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
set
|
||||
{
|
||||
if( m_Type != value )
|
||||
{
|
||||
m_Type = value;
|
||||
|
||||
Gump parent = Parent;
|
||||
|
||||
if( parent != null )
|
||||
{
|
||||
parent.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Param
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Param;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Param, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int ItemID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ItemID;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ItemID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Hue, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Width;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Width, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Height;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Height, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int LocalizedTooltip
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_LocalizedTooltip;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_LocalizedTooltip = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
if( m_LocalizedTooltip > 0 )
|
||||
return String.Format( "{{ buttontileart {0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} }}{{ tooltip {11} }}", m_X, m_Y, m_ID1, m_ID2, (int)m_Type, m_Param, m_ButtonID, m_ItemID, m_Hue, m_Width, m_Height, m_LocalizedTooltip );
|
||||
else
|
||||
return String.Format( "{{ buttontileart {0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} }}", m_X, m_Y, m_ID1, m_ID2, (int)m_Type, m_Param, m_ButtonID, m_ItemID, m_Hue, m_Width, m_Height );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "buttontileart" );
|
||||
private static byte[] m_LayoutTooltip = Gump.StringToBuffer( " }{ tooltip" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_ID1 );
|
||||
disp.AppendLayout( m_ID2 );
|
||||
disp.AppendLayout( (int)m_Type );
|
||||
disp.AppendLayout( m_Param );
|
||||
disp.AppendLayout( m_ButtonID );
|
||||
|
||||
disp.AppendLayout( m_ItemID );
|
||||
disp.AppendLayout( m_Hue );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
|
||||
if( m_LocalizedTooltip > 0 )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutTooltip );
|
||||
disp.AppendLayout( m_LocalizedTooltip );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
118
Source/Gumps/GumpImageTiled.cs
Normal file
118
Source/Gumps/GumpImageTiled.cs
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/***************************************************************************
|
||||
* GumpImageTiled.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpImageTiled : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_Width, m_Height;
|
||||
private int m_GumpID;
|
||||
|
||||
public GumpImageTiled( int x, int y, int width, int height, int gumpID )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_GumpID = gumpID;
|
||||
}
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Width;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Width, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Height;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Height, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int GumpID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_GumpID;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_GumpID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ gumppictiled {0} {1} {2} {3} {4} }}", m_X, m_Y, m_Width, m_Height, m_GumpID );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "gumppictiled" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
disp.AppendLayout( m_GumpID );
|
||||
}
|
||||
}
|
||||
}
|
||||
114
Source/Gumps/GumpItem.cs
Normal file
114
Source/Gumps/GumpItem.cs
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/***************************************************************************
|
||||
* GumpItem.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpItem : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_ItemID;
|
||||
private int m_Hue;
|
||||
|
||||
public GumpItem( int x, int y, int itemID ) : this( x, y, itemID, 0 )
|
||||
{
|
||||
}
|
||||
|
||||
public GumpItem( int x, int y, int itemID, int hue )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_ItemID = itemID;
|
||||
m_Hue = hue;
|
||||
}
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int ItemID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ItemID;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ItemID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Hue, value );
|
||||
}
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
if ( m_Hue == 0 )
|
||||
return String.Format( "{{ tilepic {0} {1} {2} }}", m_X, m_Y, m_ItemID );
|
||||
else
|
||||
return String.Format( "{{ tilepichue {0} {1} {2} {3} }}", m_X, m_Y, m_ItemID, m_Hue );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "tilepic" );
|
||||
private static byte[] m_LayoutNameHue = Gump.StringToBuffer( "tilepichue" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_Hue == 0 ? m_LayoutName : m_LayoutNameHue );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_ItemID );
|
||||
|
||||
if ( m_Hue != 0 )
|
||||
disp.AppendLayout( m_Hue );
|
||||
}
|
||||
}
|
||||
}
|
||||
104
Source/Gumps/GumpLabel.cs
Normal file
104
Source/Gumps/GumpLabel.cs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/***************************************************************************
|
||||
* GumpLabel.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpLabel : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_Hue;
|
||||
private string m_Text;
|
||||
|
||||
public GumpLabel( int x, int y, int hue, string text )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Hue = hue;
|
||||
m_Text = text;
|
||||
}
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Hue, value );
|
||||
}
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Text, value );
|
||||
}
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ text {0} {1} {2} {3} }}", m_X, m_Y, m_Hue, Parent.Intern( m_Text ) );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "text" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_Hue );
|
||||
disp.AppendLayout( Parent.Intern( m_Text ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
133
Source/Gumps/GumpLabelCropped.cs
Normal file
133
Source/Gumps/GumpLabelCropped.cs
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
/***************************************************************************
|
||||
* GumpLabelCropped.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpLabelCropped : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_Width, m_Height;
|
||||
private int m_Hue;
|
||||
private string m_Text;
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Width;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Width, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Height;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Height, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Hue, value );
|
||||
}
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Text, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpLabelCropped( int x, int y, int width, int height, int hue, string text )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_Hue = hue;
|
||||
m_Text = text;
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ croppedtext {0} {1} {2} {3} {4} {5} }}", m_X, m_Y, m_Width, m_Height, m_Hue, Parent.Intern( m_Text ) );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "croppedtext" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
disp.AppendLayout( m_Hue );
|
||||
disp.AppendLayout( Parent.Intern( m_Text ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
60
Source/Gumps/GumpPage.cs
Normal file
60
Source/Gumps/GumpPage.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/***************************************************************************
|
||||
* GumpPage.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpPage : GumpEntry
|
||||
{
|
||||
private int m_Page;
|
||||
|
||||
public GumpPage( int page )
|
||||
{
|
||||
m_Page = page;
|
||||
}
|
||||
|
||||
public int Page
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Page;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Page, value );
|
||||
}
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ page {0} }}", m_Page );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "page" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_Page );
|
||||
}
|
||||
}
|
||||
}
|
||||
135
Source/Gumps/GumpRadio.cs
Normal file
135
Source/Gumps/GumpRadio.cs
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
/***************************************************************************
|
||||
* GumpRadio.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpRadio : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_ID1, m_ID2;
|
||||
private bool m_InitialState;
|
||||
private int m_SwitchID;
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int InactiveID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ID1;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ID1, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int ActiveID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ID2;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_ID2, value );
|
||||
}
|
||||
}
|
||||
|
||||
public bool InitialState
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_InitialState;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_InitialState, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int SwitchID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_SwitchID;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_SwitchID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpRadio( int x, int y, int inactiveID, int activeID, bool initialState, int switchID )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_ID1 = inactiveID;
|
||||
m_ID2 = activeID;
|
||||
m_InitialState = initialState;
|
||||
m_SwitchID = switchID;
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ radio {0} {1} {2} {3} {4} {5} }}", m_X, m_Y, m_ID1, m_ID2, m_InitialState ? 1 : 0, m_SwitchID );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "radio" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_ID1 );
|
||||
disp.AppendLayout( m_ID2 );
|
||||
disp.AppendLayout( m_InitialState );
|
||||
disp.AppendLayout( m_SwitchID );
|
||||
|
||||
disp.Switches++;
|
||||
}
|
||||
}
|
||||
}
|
||||
150
Source/Gumps/GumpTextEntry.cs
Normal file
150
Source/Gumps/GumpTextEntry.cs
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
/***************************************************************************
|
||||
* GumpTextEntry.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpTextEntry : GumpEntry
|
||||
{
|
||||
private int m_X, m_Y;
|
||||
private int m_Width, m_Height;
|
||||
private int m_Hue;
|
||||
private int m_EntryID;
|
||||
private string m_InitialText;
|
||||
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_X;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Width;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Width, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Height;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Height, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Hue, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int EntryID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EntryID;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_EntryID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public string InitialText
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_InitialText;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_InitialText, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpTextEntry( int x, int y, int width, int height, int hue, int entryID, string initialText )
|
||||
{
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_Hue = hue;
|
||||
m_EntryID = entryID;
|
||||
m_InitialText = initialText;
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ textentry {0} {1} {2} {3} {4} {5} {6} }}", m_X, m_Y, m_Width, m_Height, m_Hue, m_EntryID, Parent.Intern( m_InitialText ) );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "textentry" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
disp.AppendLayout( m_Hue );
|
||||
disp.AppendLayout( m_EntryID );
|
||||
disp.AppendLayout( Parent.Intern( m_InitialText ) );
|
||||
|
||||
disp.TextEntries++;
|
||||
}
|
||||
}
|
||||
}
|
||||
136
Source/Gumps/GumpTextEntryLimited.cs
Normal file
136
Source/Gumps/GumpTextEntryLimited.cs
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/***************************************************************************
|
||||
* GumpTextEntryLimited.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps {
|
||||
public class GumpTextEntryLimited : GumpEntry {
|
||||
private int m_X, m_Y;
|
||||
private int m_Width, m_Height;
|
||||
private int m_Hue;
|
||||
private int m_EntryID;
|
||||
private string m_InitialText;
|
||||
private int m_Size;
|
||||
|
||||
public int X {
|
||||
get {
|
||||
return m_X;
|
||||
}
|
||||
set {
|
||||
Delta( ref m_X, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Y {
|
||||
get {
|
||||
return m_Y;
|
||||
}
|
||||
set {
|
||||
Delta( ref m_Y, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Width {
|
||||
get {
|
||||
return m_Width;
|
||||
}
|
||||
set {
|
||||
Delta( ref m_Width, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Height {
|
||||
get {
|
||||
return m_Height;
|
||||
}
|
||||
set {
|
||||
Delta( ref m_Height, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue {
|
||||
get {
|
||||
return m_Hue;
|
||||
}
|
||||
set {
|
||||
Delta( ref m_Hue, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int EntryID {
|
||||
get {
|
||||
return m_EntryID;
|
||||
}
|
||||
set {
|
||||
Delta( ref m_EntryID, value );
|
||||
}
|
||||
}
|
||||
|
||||
public string InitialText {
|
||||
get {
|
||||
return m_InitialText;
|
||||
}
|
||||
set {
|
||||
Delta( ref m_InitialText, value );
|
||||
}
|
||||
}
|
||||
|
||||
public int Size {
|
||||
get {
|
||||
return m_Size;
|
||||
}
|
||||
set {
|
||||
Delta( ref m_Size, value );
|
||||
}
|
||||
}
|
||||
|
||||
public GumpTextEntryLimited( int x, int y, int width, int height, int hue, int entryID, string initialText, int size ) {
|
||||
m_X = x;
|
||||
m_Y = y;
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
m_Hue = hue;
|
||||
m_EntryID = entryID;
|
||||
m_InitialText = initialText;
|
||||
m_Size = size;
|
||||
}
|
||||
|
||||
public override string Compile() {
|
||||
return String.Format( "{{ textentrylimited {0} {1} {2} {3} {4} {5} {6} {7} }}", m_X, m_Y, m_Width, m_Height, m_Hue, m_EntryID, Parent.Intern( m_InitialText ), m_Size );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "textentrylimited" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp ) {
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_X );
|
||||
disp.AppendLayout( m_Y );
|
||||
disp.AppendLayout( m_Width );
|
||||
disp.AppendLayout( m_Height );
|
||||
disp.AppendLayout( m_Hue );
|
||||
disp.AppendLayout( m_EntryID );
|
||||
disp.AppendLayout( Parent.Intern( m_InitialText ) );
|
||||
disp.AppendLayout( m_Size );
|
||||
|
||||
disp.TextEntries++;
|
||||
}
|
||||
}
|
||||
}
|
||||
60
Source/Gumps/GumpTooltip.cs
Normal file
60
Source/Gumps/GumpTooltip.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/***************************************************************************
|
||||
* GumpTooltip.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpTooltip : GumpEntry
|
||||
{
|
||||
private int m_Number;
|
||||
|
||||
public GumpTooltip( int number )
|
||||
{
|
||||
m_Number = number;
|
||||
}
|
||||
|
||||
public int Number
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Number;
|
||||
}
|
||||
set
|
||||
{
|
||||
Delta( ref m_Number, value );
|
||||
}
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
{
|
||||
return String.Format( "{{ tooltip {0} }}", m_Number );
|
||||
}
|
||||
|
||||
private static byte[] m_LayoutName = Gump.StringToBuffer( "tooltip" );
|
||||
|
||||
public override void AppendTo( IGumpWriter disp )
|
||||
{
|
||||
disp.AppendLayout( m_LayoutName );
|
||||
disp.AppendLayout( m_Number );
|
||||
}
|
||||
}
|
||||
}
|
||||
116
Source/Gumps/RelayInfo.cs
Normal file
116
Source/Gumps/RelayInfo.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/***************************************************************************
|
||||
* RelayInfo.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class TextRelay
|
||||
{
|
||||
private int m_EntryID;
|
||||
private string m_Text;
|
||||
|
||||
public TextRelay( int entryID, string text )
|
||||
{
|
||||
m_EntryID = entryID;
|
||||
m_Text = text;
|
||||
}
|
||||
|
||||
public int EntryID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EntryID;
|
||||
}
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RelayInfo
|
||||
{
|
||||
private int m_ButtonID;
|
||||
private int[] m_Switches;
|
||||
private TextRelay[] m_TextEntries;
|
||||
|
||||
public RelayInfo( int buttonID, int[] switches, TextRelay[] textEntries )
|
||||
{
|
||||
m_ButtonID = buttonID;
|
||||
m_Switches = switches;
|
||||
m_TextEntries = textEntries;
|
||||
}
|
||||
|
||||
public int ButtonID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ButtonID;
|
||||
}
|
||||
}
|
||||
|
||||
public int[] Switches
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Switches;
|
||||
}
|
||||
}
|
||||
|
||||
public TextRelay[] TextEntries
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_TextEntries;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSwitched( int switchID )
|
||||
{
|
||||
for ( int i = 0; i < m_Switches.Length; ++i )
|
||||
{
|
||||
if ( m_Switches[i] == switchID )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public TextRelay GetTextEntry( int entryID )
|
||||
{
|
||||
for ( int i = 0; i < m_TextEntries.Length; ++i )
|
||||
{
|
||||
if ( m_TextEntries[i].EntryID == entryID )
|
||||
{
|
||||
return m_TextEntries[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
69
Source/HuePicker.cs
Normal file
69
Source/HuePicker.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/***************************************************************************
|
||||
* HuePicker.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.HuePickers
|
||||
{
|
||||
public class HuePicker
|
||||
{
|
||||
private static int m_NextSerial = 1;
|
||||
|
||||
private int m_Serial;
|
||||
private int m_ItemID;
|
||||
|
||||
public int Serial
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Serial;
|
||||
}
|
||||
}
|
||||
|
||||
public int ItemID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ItemID;
|
||||
}
|
||||
}
|
||||
|
||||
public HuePicker( int itemID )
|
||||
{
|
||||
do
|
||||
{
|
||||
m_Serial = m_NextSerial++;
|
||||
} while ( m_Serial == 0 );
|
||||
|
||||
m_ItemID = itemID;
|
||||
}
|
||||
|
||||
public virtual void OnResponse( int hue )
|
||||
{
|
||||
}
|
||||
|
||||
public void SendTo( NetState state )
|
||||
{
|
||||
state.Send( new DisplayHuePicker( this ) );
|
||||
state.AddHuePicker( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Source/IAccount.cs
Normal file
39
Source/IAccount.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/***************************************************************************
|
||||
* IAccount.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server.Accounting
|
||||
{
|
||||
public interface IAccount
|
||||
{
|
||||
string Username { get; set; }
|
||||
AccessLevel AccessLevel { get; set; }
|
||||
|
||||
int Length { get; }
|
||||
int Limit { get; }
|
||||
int Count { get; }
|
||||
Mobile this[int index] { get; set; }
|
||||
|
||||
void Delete();
|
||||
void SetPassword( string password );
|
||||
bool CheckPassword( string password );
|
||||
}
|
||||
}
|
||||
113
Source/IEntity.cs
Normal file
113
Source/IEntity.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/***************************************************************************
|
||||
* IEntity.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public interface IEntity : IPoint3D, IComparable, IComparable<IEntity>
|
||||
{
|
||||
Serial Serial{ get; }
|
||||
Point3D Location{ get; }
|
||||
Map Map{ get; }
|
||||
|
||||
void Delete();
|
||||
void ProcessDelta();
|
||||
}
|
||||
|
||||
public class Entity : IEntity, IComparable<Entity>
|
||||
{
|
||||
public int CompareTo( IEntity other )
|
||||
{
|
||||
if ( other == null )
|
||||
return -1;
|
||||
|
||||
return m_Serial.CompareTo( other.Serial );
|
||||
}
|
||||
|
||||
public int CompareTo( Entity other )
|
||||
{
|
||||
return this.CompareTo( (IEntity) other );
|
||||
}
|
||||
|
||||
public int CompareTo( object other )
|
||||
{
|
||||
if ( other == null || other is IEntity )
|
||||
return this.CompareTo( (IEntity) other );
|
||||
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
private Serial m_Serial;
|
||||
private Point3D m_Location;
|
||||
private Map m_Map;
|
||||
|
||||
public Entity( Serial serial, Point3D loc, Map map )
|
||||
{
|
||||
m_Serial = serial;
|
||||
m_Location = loc;
|
||||
m_Map = map;
|
||||
}
|
||||
|
||||
public Serial Serial {
|
||||
get {
|
||||
return m_Serial;
|
||||
}
|
||||
}
|
||||
|
||||
public Point3D Location {
|
||||
get {
|
||||
return m_Location;
|
||||
}
|
||||
}
|
||||
|
||||
public int X {
|
||||
get {
|
||||
return m_Location.X;
|
||||
}
|
||||
}
|
||||
|
||||
public int Y {
|
||||
get {
|
||||
return m_Location.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public int Z {
|
||||
get {
|
||||
return m_Location.Z;
|
||||
}
|
||||
}
|
||||
|
||||
public Map Map {
|
||||
get {
|
||||
return m_Map;
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
}
|
||||
|
||||
public void ProcessDelta()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
77
Source/Insensitive.cs
Normal file
77
Source/Insensitive.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/***************************************************************************
|
||||
* Insensitive.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public static class Insensitive
|
||||
{
|
||||
private static IComparer m_Comparer = CaseInsensitiveComparer.Default;
|
||||
|
||||
public static IComparer Comparer
|
||||
{
|
||||
get{ return m_Comparer; }
|
||||
}
|
||||
|
||||
public static int Compare( string a, string b )
|
||||
{
|
||||
return m_Comparer.Compare( a, b );
|
||||
}
|
||||
|
||||
public static bool Equals( string a, string b )
|
||||
{
|
||||
if ( a == null && b == null )
|
||||
return true;
|
||||
else if ( a == null || b == null || a.Length != b.Length )
|
||||
return false;
|
||||
|
||||
return ( m_Comparer.Compare( a, b ) == 0 );
|
||||
}
|
||||
|
||||
public static bool StartsWith( string a, string b )
|
||||
{
|
||||
if ( a == null || b == null || a.Length < b.Length )
|
||||
return false;
|
||||
|
||||
return ( m_Comparer.Compare( a.Substring( 0, b.Length ), b ) == 0 );
|
||||
}
|
||||
|
||||
public static bool EndsWith( string a, string b )
|
||||
{
|
||||
if ( a == null || b == null || a.Length < b.Length )
|
||||
return false;
|
||||
|
||||
return ( m_Comparer.Compare( a.Substring( a.Length - b.Length ), b ) == 0 );
|
||||
}
|
||||
|
||||
public static bool Contains( string a, string b )
|
||||
{
|
||||
if ( a == null || b == null || a.Length < b.Length )
|
||||
return false;
|
||||
|
||||
a = a.ToLower();
|
||||
b = b.ToLower();
|
||||
|
||||
return ( a.IndexOf( b ) >= 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
116
Source/Interfaces.cs
Normal file
116
Source/Interfaces.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/***************************************************************************
|
||||
* Interfaces.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Mobiles
|
||||
{
|
||||
public interface IMount
|
||||
{
|
||||
Mobile Rider{ get; set; }
|
||||
void OnRiderDamaged( int amount, Mobile from, bool willKill );
|
||||
}
|
||||
|
||||
public interface IMountItem
|
||||
{
|
||||
IMount Mount{ get; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public interface IVendor
|
||||
{
|
||||
bool OnBuyItems( Mobile from, List<BuyItemResponse> list );
|
||||
bool OnSellItems( Mobile from, List<SellItemResponse> list );
|
||||
|
||||
DateTime LastRestock{ get; set; }
|
||||
TimeSpan RestockDelay{ get; }
|
||||
void Restock();
|
||||
}
|
||||
|
||||
public interface IPoint2D
|
||||
{
|
||||
int X{ get; }
|
||||
int Y{ get; }
|
||||
}
|
||||
|
||||
public interface IPoint3D : IPoint2D
|
||||
{
|
||||
int Z{ get; }
|
||||
}
|
||||
|
||||
public interface ICarvable
|
||||
{
|
||||
void Carve( Mobile from, Item item );
|
||||
}
|
||||
|
||||
public interface IWeapon
|
||||
{
|
||||
int MaxRange{ get; }
|
||||
void OnBeforeSwing( Mobile attacker, Mobile defender );
|
||||
TimeSpan OnSwing( Mobile attacker, Mobile defender );
|
||||
void GetStatusDamage( Mobile from, out int min, out int max );
|
||||
}
|
||||
|
||||
public interface IHued
|
||||
{
|
||||
int HuedItemID{ get; }
|
||||
}
|
||||
|
||||
public interface ISpell
|
||||
{
|
||||
bool IsCasting{ get; }
|
||||
void OnCasterHurt();
|
||||
void OnCasterKilled();
|
||||
void OnConnectionChanged();
|
||||
bool OnCasterMoving( Direction d );
|
||||
bool OnCasterEquiping( Item item );
|
||||
bool OnCasterUsingObject( object o );
|
||||
bool OnCastInTown( Region r );
|
||||
}
|
||||
|
||||
public interface IParty
|
||||
{
|
||||
void OnStamChanged( Mobile m );
|
||||
void OnManaChanged( Mobile m );
|
||||
void OnStatsQuery( Mobile beholder, Mobile beheld );
|
||||
}
|
||||
|
||||
public interface ISpawner
|
||||
{
|
||||
bool UnlinkOnTaming { get; }
|
||||
Point3D HomeLocation { get; }
|
||||
int HomeRange { get; }
|
||||
|
||||
void Remove(ISpawnable spawn);
|
||||
}
|
||||
|
||||
public interface ISpawnable : IEntity
|
||||
{
|
||||
void OnBeforeSpawn(Point3D location, Map map);
|
||||
void MoveToWorld(Point3D location, Map map);
|
||||
void OnAfterSpawn();
|
||||
|
||||
ISpawner Spawner { get; set; }
|
||||
}
|
||||
}
|
||||
4770
Source/Item.cs
Normal file
4770
Source/Item.cs
Normal file
File diff suppressed because it is too large
Load diff
69
Source/ItemBounds.cs
Normal file
69
Source/ItemBounds.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/***************************************************************************
|
||||
* ItemBounds.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public static class ItemBounds
|
||||
{
|
||||
private static Rectangle2D[] m_Bounds;
|
||||
|
||||
public static Rectangle2D[] Table
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Bounds;
|
||||
}
|
||||
}
|
||||
|
||||
static ItemBounds()
|
||||
{
|
||||
if ( File.Exists( "Data/Binary/Bounds.bin" ) )
|
||||
{
|
||||
using ( FileStream fs = new FileStream( "Data/Binary/Bounds.bin", FileMode.Open, FileAccess.Read, FileShare.Read ) )
|
||||
{
|
||||
BinaryReader bin = new BinaryReader( fs );
|
||||
|
||||
m_Bounds = new Rectangle2D[0x4000];
|
||||
|
||||
for ( int i = 0; i < 0x4000; ++i )
|
||||
{
|
||||
int xMin = bin.ReadInt16();
|
||||
int yMin = bin.ReadInt16();
|
||||
int xMax = bin.ReadInt16();
|
||||
int yMax = bin.ReadInt16();
|
||||
|
||||
m_Bounds[i].Set( xMin, yMin, (xMax - xMin) + 1, (yMax - yMin) + 1 );
|
||||
}
|
||||
|
||||
bin.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine( "Warning: Data/Binary/Bounds.bin does not exist" );
|
||||
|
||||
m_Bounds = new Rectangle2D[0x4000];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
174
Source/Items/BaseMulti.cs
Normal file
174
Source/Items/BaseMulti.cs
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
/***************************************************************************
|
||||
* BaseMulti.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server.Items
|
||||
{
|
||||
public class BaseMulti : Item
|
||||
{
|
||||
[Constructable]
|
||||
public BaseMulti( int itemID ) : base( itemID )
|
||||
{
|
||||
Movable = false;
|
||||
}
|
||||
|
||||
public BaseMulti( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster )]
|
||||
public override int ItemID {
|
||||
get {
|
||||
return base.ItemID;
|
||||
}
|
||||
set {
|
||||
if ( base.ItemID != value ) {
|
||||
Map facet = ( this.Parent == null ? this.Map : null );
|
||||
|
||||
if ( facet != null ) {
|
||||
facet.OnLeave( this );
|
||||
}
|
||||
|
||||
base.ItemID = value;
|
||||
|
||||
if ( facet != null ) {
|
||||
facet.OnEnter( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete( "Replace with calls to OnLeave and OnEnter surrounding component invalidation.", true )]
|
||||
public virtual void RefreshComponents()
|
||||
{
|
||||
if ( this.Parent == null ) {
|
||||
Map facet = this.Map;
|
||||
|
||||
if ( facet != null ) {
|
||||
facet.OnLeave( this );
|
||||
facet.OnEnter( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override int LabelNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
MultiComponentList mcl = this.Components;
|
||||
|
||||
if ( mcl.List.Length > 0 ) {
|
||||
int id = mcl.List[0].m_ItemID;
|
||||
|
||||
if ( id < 0x4000 )
|
||||
return 1020000 + id;
|
||||
else
|
||||
return 1078872 + id;
|
||||
}
|
||||
|
||||
return base.LabelNumber;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetMaxUpdateRange()
|
||||
{
|
||||
return 22;
|
||||
}
|
||||
|
||||
public override int GetUpdateRange( Mobile m )
|
||||
{
|
||||
return 22;
|
||||
}
|
||||
|
||||
public virtual MultiComponentList Components
|
||||
{
|
||||
get
|
||||
{
|
||||
return MultiData.GetComponents( ItemID );
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Contains( Point2D p )
|
||||
{
|
||||
return Contains( p.m_X, p.m_Y );
|
||||
}
|
||||
|
||||
public virtual bool Contains( Point3D p )
|
||||
{
|
||||
return Contains( p.m_X, p.m_Y );
|
||||
}
|
||||
|
||||
public virtual bool Contains( IPoint3D p )
|
||||
{
|
||||
return Contains( p.X, p.Y );
|
||||
}
|
||||
|
||||
public virtual bool Contains( int x, int y )
|
||||
{
|
||||
MultiComponentList mcl = this.Components;
|
||||
|
||||
x -= this.X + mcl.Min.m_X;
|
||||
y -= this.Y + mcl.Min.m_Y;
|
||||
|
||||
return x >= 0
|
||||
&& x < mcl.Width
|
||||
&& y >= 0
|
||||
&& y < mcl.Height
|
||||
&& mcl.Tiles[x][y].Length > 0;
|
||||
}
|
||||
|
||||
public bool Contains( Mobile m )
|
||||
{
|
||||
if ( m.Map == this.Map )
|
||||
return Contains( m.X, m.Y );
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Contains( Item item )
|
||||
{
|
||||
if ( item.Map == this.Map )
|
||||
return Contains( item.X, item.Y );
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Serialize( GenericWriter writer )
|
||||
{
|
||||
base.Serialize( writer );
|
||||
|
||||
writer.Write( (int) 1 ); // version
|
||||
}
|
||||
|
||||
public override void Deserialize( GenericReader reader )
|
||||
{
|
||||
base.Deserialize( reader );
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
if ( version == 0 ) {
|
||||
if ( ItemID >= 0x4000 ) {
|
||||
ItemID -= 0x4000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1826
Source/Items/Container.cs
Normal file
1826
Source/Items/Container.cs
Normal file
File diff suppressed because it is too large
Load diff
166
Source/Items/Containers.cs
Normal file
166
Source/Items/Containers.cs
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
/***************************************************************************
|
||||
* Containers.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Items
|
||||
{
|
||||
public class InnBox : Container
|
||||
{
|
||||
private Mobile m_Owner;
|
||||
private bool m_Open;
|
||||
|
||||
public override int DefaultMaxWeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsVirtualItem
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public InnBox( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
|
||||
public Mobile Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Owner;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Opened
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Open;
|
||||
}
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
m_Open = true;
|
||||
|
||||
if ( m_Owner != null )
|
||||
{
|
||||
//m_Owner.PrivateOverheadMessage( MessageType.Regular, 0x3B2, true, String.Format( "Inn Chest has {0} items, {1} stones", TotalItems, TotalWeight ), m_Owner.NetState );
|
||||
m_Owner.Send( new EquipUpdate( this ) );
|
||||
DisplayTo( m_Owner );
|
||||
}
|
||||
}
|
||||
|
||||
public override void Serialize( GenericWriter writer )
|
||||
{
|
||||
base.Serialize( writer );
|
||||
|
||||
writer.Write( (int) 0 ); // version
|
||||
|
||||
writer.Write( (Mobile) m_Owner );
|
||||
writer.Write( (bool) m_Open );
|
||||
}
|
||||
|
||||
public override void Deserialize( GenericReader reader )
|
||||
{
|
||||
base.Deserialize( reader );
|
||||
|
||||
int version = reader.ReadInt();
|
||||
|
||||
switch ( version )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
m_Owner = reader.ReadMobile();
|
||||
m_Open = reader.ReadBool();
|
||||
|
||||
if ( m_Owner == null )
|
||||
Delete();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( this.ItemID == 0xE41 )
|
||||
this.ItemID = 0xE7C;
|
||||
}
|
||||
|
||||
private static bool m_SendRemovePacket;
|
||||
|
||||
public static bool SendDeleteOnClose{ get{ return m_SendRemovePacket; } set{ m_SendRemovePacket = value; } }
|
||||
|
||||
public void Close()
|
||||
{
|
||||
m_Open = false;
|
||||
|
||||
if ( m_Owner != null && m_SendRemovePacket )
|
||||
m_Owner.Send( this.RemovePacket );
|
||||
}
|
||||
|
||||
public override void OnSingleClick( Mobile from )
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnDoubleClick( Mobile from )
|
||||
{
|
||||
}
|
||||
|
||||
public override DeathMoveResult OnParentDeath( Mobile parent )
|
||||
{
|
||||
return DeathMoveResult.RemainEquiped;
|
||||
}
|
||||
|
||||
public InnBox( Mobile owner ) : base( 0x0E42 )
|
||||
{
|
||||
Layer = Layer.Inn;
|
||||
Movable = false;
|
||||
m_Owner = owner;
|
||||
}
|
||||
|
||||
public override bool IsAccessibleTo(Mobile check)
|
||||
{
|
||||
if ( ( check == m_Owner && m_Open ) || check.AccessLevel >= AccessLevel.GameMaster )
|
||||
return base.IsAccessibleTo (check);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool OnDragDrop( Mobile from, Item dropped )
|
||||
{
|
||||
if ( ( from == m_Owner && m_Open ) || from.AccessLevel >= AccessLevel.GameMaster )
|
||||
return base.OnDragDrop( from, dropped );
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
|
||||
{
|
||||
if ( ( from == m_Owner && m_Open ) || from.AccessLevel >= AccessLevel.GameMaster )
|
||||
return base.OnDragDropInto (from, item, p);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
119
Source/Items/SecureTradeContainer.cs
Normal file
119
Source/Items/SecureTradeContainer.cs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/***************************************************************************
|
||||
* SecureTradeContainer.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Items
|
||||
{
|
||||
public class SecureTradeContainer : Container
|
||||
{
|
||||
private SecureTrade m_Trade;
|
||||
|
||||
public SecureTrade Trade
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Trade;
|
||||
}
|
||||
}
|
||||
|
||||
public SecureTradeContainer( SecureTrade trade ) : base( 0x1E5E )
|
||||
{
|
||||
m_Trade = trade;
|
||||
|
||||
Movable = false;
|
||||
}
|
||||
|
||||
public SecureTradeContainer( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
|
||||
public override bool CheckHold( Mobile m, Item item, bool message, bool checkItems, int plusItems, int plusWeight )
|
||||
{
|
||||
Mobile to;
|
||||
|
||||
if ( this.Trade.From.Container != this )
|
||||
to = this.Trade.From.Mobile;
|
||||
else
|
||||
to = this.Trade.To.Mobile;
|
||||
|
||||
return m.CheckTrade( to, item, this, message, checkItems, plusItems, plusWeight );
|
||||
}
|
||||
|
||||
public override bool CheckLift( Mobile from, Item item, ref LRReason reject )
|
||||
{
|
||||
reject = LRReason.CannotLift;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool IsAccessibleTo( Mobile check )
|
||||
{
|
||||
if ( !IsChildOf( check ) )
|
||||
return false;
|
||||
|
||||
return base.IsAccessibleTo( check );
|
||||
}
|
||||
|
||||
public override void OnItemAdded( Item item )
|
||||
{
|
||||
ClearChecks();
|
||||
}
|
||||
|
||||
public override void OnItemRemoved( Item item )
|
||||
{
|
||||
ClearChecks();
|
||||
}
|
||||
|
||||
public override void OnSubItemAdded( Item item )
|
||||
{
|
||||
ClearChecks();
|
||||
}
|
||||
|
||||
public override void OnSubItemRemoved( Item item )
|
||||
{
|
||||
ClearChecks();
|
||||
}
|
||||
|
||||
public void ClearChecks()
|
||||
{
|
||||
if ( m_Trade != null )
|
||||
{
|
||||
m_Trade.From.Accepted = false;
|
||||
m_Trade.To.Accepted = false;
|
||||
m_Trade.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Serialize( GenericWriter writer )
|
||||
{
|
||||
base.Serialize( writer );
|
||||
|
||||
writer.Write( (int) 0 ); // version
|
||||
}
|
||||
|
||||
public override void Deserialize( GenericReader reader )
|
||||
{
|
||||
base.Deserialize( reader );
|
||||
|
||||
int version = reader.ReadInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
177
Source/Items/VirtualHair.cs
Normal file
177
Source/Items/VirtualHair.cs
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
/***************************************************************************
|
||||
* VirtualHair.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public abstract class BaseHairInfo
|
||||
{
|
||||
private int m_ItemID;
|
||||
private int m_Hue;
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster )]
|
||||
public int ItemID { get { return m_ItemID; } set { m_ItemID = value; } }
|
||||
|
||||
[CommandProperty( AccessLevel.GameMaster )]
|
||||
public int Hue { get { return m_Hue; } set { m_Hue = value; } }
|
||||
|
||||
protected BaseHairInfo( int itemid )
|
||||
: this( itemid, 0 )
|
||||
{
|
||||
}
|
||||
|
||||
protected BaseHairInfo( int itemid, int hue )
|
||||
{
|
||||
m_ItemID = itemid;
|
||||
m_Hue = hue;
|
||||
}
|
||||
|
||||
protected BaseHairInfo( GenericReader reader )
|
||||
{
|
||||
int version = reader.ReadInt();
|
||||
|
||||
switch( version )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
m_ItemID = reader.ReadInt();
|
||||
m_Hue = reader.ReadInt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Serialize( GenericWriter writer )
|
||||
{
|
||||
writer.Write( (int)0 ); //version
|
||||
writer.Write( (int)m_ItemID );
|
||||
writer.Write( (int)m_Hue );
|
||||
}
|
||||
}
|
||||
|
||||
public class HairInfo : BaseHairInfo
|
||||
{
|
||||
public HairInfo( int itemid )
|
||||
: base( itemid, 0 )
|
||||
{
|
||||
}
|
||||
|
||||
public HairInfo( int itemid, int hue )
|
||||
: base( itemid, hue )
|
||||
{
|
||||
}
|
||||
|
||||
public HairInfo( GenericReader reader )
|
||||
: base( reader )
|
||||
{
|
||||
}
|
||||
|
||||
public static int FakeSerial( Mobile parent )
|
||||
{
|
||||
return (0x7FFFFFFF - 0x400 - (parent.Serial * 4));
|
||||
}
|
||||
}
|
||||
|
||||
public class FacialHairInfo : BaseHairInfo
|
||||
{
|
||||
public FacialHairInfo( int itemid )
|
||||
: base( itemid, 0 )
|
||||
{
|
||||
}
|
||||
|
||||
public FacialHairInfo( int itemid, int hue )
|
||||
: base( itemid, hue )
|
||||
{
|
||||
}
|
||||
|
||||
public FacialHairInfo( GenericReader reader )
|
||||
: base( reader )
|
||||
{
|
||||
}
|
||||
|
||||
public static int FakeSerial( Mobile parent )
|
||||
{
|
||||
return (0x7FFFFFFF - 0x400 - 1 - (parent.Serial * 4));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HairEquipUpdate : Packet
|
||||
{
|
||||
public HairEquipUpdate( Mobile parent )
|
||||
: base( 0x2E, 15 )
|
||||
{
|
||||
int hue = parent.HairHue;
|
||||
|
||||
if( parent.SolidHueOverride >= 0 )
|
||||
hue = parent.SolidHueOverride;
|
||||
|
||||
int hairSerial = HairInfo.FakeSerial( parent );
|
||||
|
||||
m_Stream.Write( (int)hairSerial );
|
||||
m_Stream.Write( (short)parent.HairItemID );
|
||||
m_Stream.Write( (byte)0 );
|
||||
m_Stream.Write( (byte)Layer.Hair );
|
||||
m_Stream.Write( (int)parent.Serial );
|
||||
m_Stream.Write( (short)hue );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FacialHairEquipUpdate : Packet
|
||||
{
|
||||
public FacialHairEquipUpdate( Mobile parent )
|
||||
: base( 0x2E, 15 )
|
||||
{
|
||||
int hue = parent.FacialHairHue;
|
||||
|
||||
if( parent.SolidHueOverride >= 0 )
|
||||
hue = parent.SolidHueOverride;
|
||||
|
||||
int hairSerial = FacialHairInfo.FakeSerial( parent );
|
||||
|
||||
m_Stream.Write( (int)hairSerial );
|
||||
m_Stream.Write( (short)parent.FacialHairItemID );
|
||||
m_Stream.Write( (byte)0 );
|
||||
m_Stream.Write( (byte)Layer.FacialHair );
|
||||
m_Stream.Write( (int)parent.Serial );
|
||||
m_Stream.Write( (short)hue );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class RemoveHair : Packet
|
||||
{
|
||||
public RemoveHair( Mobile parent )
|
||||
: base( 0x1D, 5 )
|
||||
{
|
||||
m_Stream.Write( (int)HairInfo.FakeSerial( parent ) );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class RemoveFacialHair : Packet
|
||||
{
|
||||
public RemoveFacialHair( Mobile parent )
|
||||
: base( 0x1D, 5 )
|
||||
{
|
||||
m_Stream.Write( (int)FacialHairInfo.FakeSerial( parent ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
85
Source/KeywordList.cs
Normal file
85
Source/KeywordList.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/***************************************************************************
|
||||
* KeywordList.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public class KeywordList
|
||||
{
|
||||
private int[] m_Keywords;
|
||||
private int m_Count;
|
||||
|
||||
public KeywordList()
|
||||
{
|
||||
m_Keywords = new int[8];
|
||||
m_Count = 0;
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Count;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Contains( int keyword )
|
||||
{
|
||||
bool contains = false;
|
||||
|
||||
for ( int i = 0; !contains && i < m_Count; ++i )
|
||||
contains = ( keyword == m_Keywords[i] );
|
||||
|
||||
return contains;
|
||||
}
|
||||
|
||||
public void Add( int keyword )
|
||||
{
|
||||
if ( (m_Count + 1) > m_Keywords.Length )
|
||||
{
|
||||
int[] old = m_Keywords;
|
||||
m_Keywords = new int[old.Length * 2];
|
||||
|
||||
for ( int i = 0; i < old.Length; ++i )
|
||||
m_Keywords[i] = old[i];
|
||||
}
|
||||
|
||||
m_Keywords[m_Count++] = keyword;
|
||||
}
|
||||
|
||||
private static int[] m_EmptyInts = new int[0];
|
||||
|
||||
public int[] ToArray()
|
||||
{
|
||||
if ( m_Count == 0 )
|
||||
return m_EmptyInts;
|
||||
|
||||
int[] keywords = new int[m_Count];
|
||||
|
||||
for ( int i = 0; i < m_Count; ++i )
|
||||
keywords[i] = m_Keywords[i];
|
||||
|
||||
m_Count = 0;
|
||||
|
||||
return keywords;
|
||||
}
|
||||
}
|
||||
}
|
||||
781
Source/Main.cs
Normal file
781
Source/Main.cs
Normal file
|
|
@ -0,0 +1,781 @@
|
|||
/***************************************************************************
|
||||
* Main.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
#if Framework_4_0
|
||||
using System.Threading.Tasks;
|
||||
#endif
|
||||
|
||||
using Server;
|
||||
using Server.Accounting;
|
||||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
using System.Runtime;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public delegate void Slice();
|
||||
|
||||
public static class Core
|
||||
{
|
||||
private static bool m_Crashed;
|
||||
private static Thread timerThread;
|
||||
private static string m_BaseDirectory;
|
||||
private static string m_ExePath;
|
||||
private static List<string> m_DataDirectories = new List<string>();
|
||||
private static Assembly m_Assembly;
|
||||
private static Process m_Process;
|
||||
private static Thread m_Thread;
|
||||
private static bool m_Service;
|
||||
private static bool m_Debug;
|
||||
private static bool m_Cache = true;
|
||||
private static bool m_HaltOnWarning;
|
||||
private static bool m_VBdotNET;
|
||||
private static MultiTextWriter m_MultiConOut;
|
||||
|
||||
private static bool m_Profiling;
|
||||
private static DateTime m_ProfileStart;
|
||||
private static TimeSpan m_ProfileTime;
|
||||
|
||||
private static MessagePump m_MessagePump;
|
||||
|
||||
public static MessagePump MessagePump
|
||||
{
|
||||
get { return m_MessagePump; }
|
||||
set { m_MessagePump = value; }
|
||||
}
|
||||
|
||||
public static Slice Slice;
|
||||
|
||||
public static bool Profiling
|
||||
{
|
||||
get { return m_Profiling; }
|
||||
set
|
||||
{
|
||||
if( m_Profiling == value )
|
||||
return;
|
||||
|
||||
m_Profiling = value;
|
||||
|
||||
if( m_ProfileStart > DateTime.MinValue )
|
||||
m_ProfileTime += DateTime.Now - m_ProfileStart;
|
||||
|
||||
m_ProfileStart = (m_Profiling ? DateTime.Now : DateTime.MinValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static TimeSpan ProfileTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if( m_ProfileStart > DateTime.MinValue )
|
||||
return m_ProfileTime + (DateTime.Now - m_ProfileStart);
|
||||
|
||||
return m_ProfileTime;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Service { get { return m_Service; } }
|
||||
public static bool Debug { get { return m_Debug; } }
|
||||
internal static bool HaltOnWarning { get { return m_HaltOnWarning; } }
|
||||
internal static bool VBdotNet { get { return m_VBdotNET; } }
|
||||
public static List<string> DataDirectories { get { return m_DataDirectories; } }
|
||||
public static Assembly Assembly { get { return m_Assembly; } set { m_Assembly = value; } }
|
||||
public static Version Version { get { return m_Assembly.GetName().Version; } }
|
||||
public static Process Process { get { return m_Process; } }
|
||||
public static Thread Thread { get { return m_Thread; } }
|
||||
public static MultiTextWriter MultiConsoleOut { get { return m_MultiConOut; } }
|
||||
|
||||
#if Framework_4_0
|
||||
public static readonly bool Is64Bit = Environment.Is64BitProcess;
|
||||
#else
|
||||
public static readonly bool Is64Bit = (IntPtr.Size == 8); //Returns the size for the current /process/
|
||||
#endif
|
||||
|
||||
private static bool m_MultiProcessor;
|
||||
private static int m_ProcessorCount;
|
||||
|
||||
public static bool MultiProcessor { get { return m_MultiProcessor; } }
|
||||
public static int ProcessorCount { get { return m_ProcessorCount; } }
|
||||
|
||||
private static bool m_Unix;
|
||||
|
||||
public static bool Unix { get { return m_Unix; } }
|
||||
|
||||
public static string FindDataFile( string path )
|
||||
{
|
||||
if( m_DataDirectories.Count == 0 )
|
||||
throw new InvalidOperationException( "Attempted to FindDataFile before DataDirectories list has been filled." );
|
||||
|
||||
string fullPath = null;
|
||||
|
||||
for( int i = 0; i < m_DataDirectories.Count; ++i )
|
||||
{
|
||||
fullPath = Path.Combine( m_DataDirectories[i], path );
|
||||
|
||||
if( File.Exists( fullPath ) )
|
||||
break;
|
||||
|
||||
fullPath = null;
|
||||
}
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
public static string FindDataFile( string format, params object[] args )
|
||||
{
|
||||
return FindDataFile( String.Format( format, args ) );
|
||||
}
|
||||
|
||||
#region Expansions
|
||||
|
||||
private static Expansion m_Expansion;
|
||||
public static Expansion Expansion
|
||||
{
|
||||
get { return m_Expansion; }
|
||||
set { m_Expansion = value; }
|
||||
}
|
||||
|
||||
public static bool T2A
|
||||
{
|
||||
get { return m_Expansion >= Expansion.T2A; }
|
||||
}
|
||||
|
||||
public static bool UOR
|
||||
{
|
||||
get { return m_Expansion >= Expansion.UOR; }
|
||||
}
|
||||
|
||||
public static bool UOTD
|
||||
{
|
||||
get { return m_Expansion >= Expansion.UOTD; }
|
||||
}
|
||||
|
||||
public static bool LBR
|
||||
{
|
||||
get { return m_Expansion >= Expansion.LBR; }
|
||||
}
|
||||
|
||||
public static bool AOS
|
||||
{
|
||||
get { return m_Expansion >= Expansion.AOS; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static string ExePath
|
||||
{
|
||||
get
|
||||
{
|
||||
if( m_ExePath == null )
|
||||
{
|
||||
m_ExePath = Assembly.Location;
|
||||
//m_ExePath = Process.GetCurrentProcess().MainModule.FileName;
|
||||
}
|
||||
|
||||
return m_ExePath;
|
||||
}
|
||||
}
|
||||
|
||||
public static string BaseDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
if( m_BaseDirectory == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
m_BaseDirectory = ExePath;
|
||||
|
||||
if( m_BaseDirectory.Length > 0 )
|
||||
m_BaseDirectory = Path.GetDirectoryName( m_BaseDirectory );
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_BaseDirectory = "";
|
||||
}
|
||||
}
|
||||
|
||||
return m_BaseDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
private static void CurrentDomain_UnhandledException( object sender, UnhandledExceptionEventArgs e )
|
||||
{
|
||||
Console.WriteLine( e.IsTerminating ? "Error:" : "Warning:" );
|
||||
Console.WriteLine( e.ExceptionObject );
|
||||
|
||||
if( e.IsTerminating )
|
||||
{
|
||||
m_Crashed = true;
|
||||
|
||||
bool close = false;
|
||||
|
||||
try
|
||||
{
|
||||
CrashedEventArgs args = new CrashedEventArgs( e.ExceptionObject as Exception );
|
||||
|
||||
EventSink.InvokeCrashed( args );
|
||||
|
||||
close = args.Close;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
if( !close && !m_Service )
|
||||
{
|
||||
try
|
||||
{
|
||||
for( int i = 0; i < m_MessagePump.Listeners.Length; i++ )
|
||||
{
|
||||
m_MessagePump.Listeners[i].Dispose();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
if ( m_Service ) {
|
||||
Console.WriteLine( "This exception is fatal." );
|
||||
} else {
|
||||
Console.WriteLine( "This exception is fatal, press return to exit" );
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
m_Closing = true;
|
||||
}
|
||||
}
|
||||
|
||||
private enum ConsoleEventType
|
||||
{
|
||||
CTRL_C_EVENT,
|
||||
CTRL_BREAK_EVENT,
|
||||
CTRL_CLOSE_EVENT,
|
||||
CTRL_LOGOFF_EVENT=5,
|
||||
CTRL_SHUTDOWN_EVENT
|
||||
}
|
||||
|
||||
private delegate bool ConsoleEventHandler( ConsoleEventType type );
|
||||
private static ConsoleEventHandler m_ConsoleEventHandler;
|
||||
|
||||
[DllImport( "Kernel32" )]
|
||||
private static extern bool SetConsoleCtrlHandler( ConsoleEventHandler callback, bool add );
|
||||
|
||||
private static bool OnConsoleEvent( ConsoleEventType type )
|
||||
{
|
||||
if( World.Saving || ( m_Service && type == ConsoleEventType.CTRL_LOGOFF_EVENT ) )
|
||||
return true;
|
||||
|
||||
Kill(); //Kill -> HandleClosed will hadnle waiting for the completion of flushign to disk
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void CurrentDomain_ProcessExit( object sender, EventArgs e )
|
||||
{
|
||||
HandleClosed();
|
||||
}
|
||||
|
||||
private static bool m_Closing;
|
||||
public static bool Closing { get { return m_Closing; } }
|
||||
|
||||
private static long m_CycleIndex = 1;
|
||||
private static float[] m_CyclesPerSecond = new float[100];
|
||||
|
||||
public static float CyclesPerSecond
|
||||
{
|
||||
get { return m_CyclesPerSecond[(m_CycleIndex - 1) % m_CyclesPerSecond.Length]; }
|
||||
}
|
||||
|
||||
public static float AverageCPS
|
||||
{
|
||||
get
|
||||
{
|
||||
float t = 0.0f;
|
||||
int c = 0;
|
||||
|
||||
for( int i = 0; i < m_CycleIndex && i < m_CyclesPerSecond.Length; ++i )
|
||||
{
|
||||
t += m_CyclesPerSecond[i];
|
||||
++c;
|
||||
}
|
||||
|
||||
return (t / Math.Max( c, 1 ));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Kill()
|
||||
{
|
||||
Kill( false );
|
||||
}
|
||||
|
||||
public static void Kill( bool restart )
|
||||
{
|
||||
HandleClosed();
|
||||
|
||||
if ( restart )
|
||||
Process.Start( ExePath, Arguments );
|
||||
|
||||
m_Process.Kill();
|
||||
}
|
||||
|
||||
private static void HandleClosed()
|
||||
{
|
||||
if( m_Closing )
|
||||
return;
|
||||
|
||||
m_Closing = true;
|
||||
|
||||
Console.Write( "Exiting..." );
|
||||
|
||||
World.WaitForWriteCompletion();
|
||||
|
||||
if( !m_Crashed )
|
||||
EventSink.InvokeShutdown( new ShutdownEventArgs() );
|
||||
|
||||
Timer.TimerThread.Set();
|
||||
|
||||
Console.WriteLine( "done" );
|
||||
}
|
||||
|
||||
private static AutoResetEvent m_Signal = new AutoResetEvent( true );
|
||||
public static void Set() { m_Signal.Set(); }
|
||||
|
||||
public static void Main( string[] args )
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
|
||||
AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );
|
||||
|
||||
for( int i = 0; i < args.Length; ++i )
|
||||
{
|
||||
if ( Insensitive.Equals( args[i], "-debug" ) )
|
||||
m_Debug = true;
|
||||
else if ( Insensitive.Equals( args[i], "-service" ) )
|
||||
m_Service = true;
|
||||
else if ( Insensitive.Equals( args[i], "-profile" ) )
|
||||
Profiling = true;
|
||||
else if ( Insensitive.Equals( args[i], "-nocache" ) )
|
||||
m_Cache = false;
|
||||
else if ( Insensitive.Equals( args[i], "-haltonwarning" ) )
|
||||
m_HaltOnWarning = true;
|
||||
else if ( Insensitive.Equals( args[i], "-vb" ) )
|
||||
m_VBdotNET = true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( m_Service )
|
||||
{
|
||||
if( !Directory.Exists( "Data/Logs" ) )
|
||||
Directory.CreateDirectory( "Data/Logs" );
|
||||
|
||||
Console.SetOut( m_MultiConOut = new MultiTextWriter( new FileLogger( "Data/Logs/Console.log" ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.SetOut( m_MultiConOut = new MultiTextWriter( Console.Out ) );
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
m_Thread = Thread.CurrentThread;
|
||||
m_Process = Process.GetCurrentProcess();
|
||||
m_Assembly = Assembly.GetEntryAssembly();
|
||||
|
||||
if( m_Thread != null )
|
||||
m_Thread.Name = "Core Thread";
|
||||
|
||||
if( BaseDirectory.Length > 0 )
|
||||
Directory.SetCurrentDirectory( BaseDirectory );
|
||||
|
||||
Timer.TimerThread ttObj = new Timer.TimerThread();
|
||||
timerThread = new Thread( new ThreadStart( ttObj.TimerMain ) );
|
||||
timerThread.Name = "Timer Thread";
|
||||
|
||||
Version ver = m_Assembly.GetName().Version;
|
||||
|
||||
// Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not
|
||||
//Console.WriteLine( "RunUO - [www.runuo.com] Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision );
|
||||
Console.WriteLine( "Ultima Adventure Game", ver.Major, ver.Minor, ver.Build, ver.Revision );
|
||||
Console.WriteLine( "Core: Running on .NET Framework Version {0}.{1}.{2}", Environment.Version.Major, Environment.Version.Minor, Environment.Version.Build );
|
||||
|
||||
string s = Arguments;
|
||||
|
||||
if( s.Length > 0 )
|
||||
Console.WriteLine( "Core: Running with arguments: {0}", s );
|
||||
|
||||
m_ProcessorCount = Environment.ProcessorCount;
|
||||
|
||||
if( m_ProcessorCount > 1 )
|
||||
m_MultiProcessor = true;
|
||||
|
||||
if( m_MultiProcessor || Is64Bit )
|
||||
Console.WriteLine( "Core: Optimizing for {0} {2}processor{1}", m_ProcessorCount, m_ProcessorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : "" );
|
||||
|
||||
int platform = (int)Environment.OSVersion.Platform;
|
||||
if( platform == 4 || platform == 128 ) { // MS 4, MONO 128
|
||||
m_Unix = true;
|
||||
Console.WriteLine( "Core: Unix environment detected" );
|
||||
}
|
||||
else {
|
||||
m_ConsoleEventHandler = new ConsoleEventHandler( OnConsoleEvent );
|
||||
SetConsoleCtrlHandler( m_ConsoleEventHandler, true );
|
||||
}
|
||||
|
||||
if ( GCSettings.IsServerGC )
|
||||
Console.WriteLine("Core: Server garbage collection mode enabled");
|
||||
|
||||
while( !ScriptCompiler.Compile( m_Debug, m_Cache ) )
|
||||
{
|
||||
Console.WriteLine( "Scripts: One or more scripts failed to compile or no script files were found." );
|
||||
|
||||
if( m_Service )
|
||||
return;
|
||||
|
||||
Console.WriteLine( " - Press return to exit, or R to try again." );
|
||||
|
||||
if( Console.ReadKey( true ).Key != ConsoleKey.R )
|
||||
return;
|
||||
}
|
||||
|
||||
ScriptCompiler.Invoke( "Configure" );
|
||||
|
||||
Region.Load();
|
||||
World.Load();
|
||||
|
||||
ScriptCompiler.Invoke( "Initialize" );
|
||||
|
||||
MessagePump messagePump = new MessagePump();
|
||||
|
||||
timerThread.Start();
|
||||
|
||||
for( int i = 0; i < Map.AllMaps.Count; ++i )
|
||||
Map.AllMaps[i].Tiles.Force();
|
||||
|
||||
NetState.Initialize();
|
||||
|
||||
EventSink.InvokeServerStarted();
|
||||
|
||||
try
|
||||
{
|
||||
DateTime now, last = DateTime.Now;
|
||||
|
||||
const int sampleInterval = 100;
|
||||
const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval);
|
||||
|
||||
long sample = 0;
|
||||
|
||||
while( m_Signal.WaitOne() )
|
||||
{
|
||||
Mobile.ProcessDeltaQueue();
|
||||
Item.ProcessDeltaQueue();
|
||||
|
||||
Timer.Slice();
|
||||
messagePump.Slice();
|
||||
|
||||
NetState.FlushAll();
|
||||
NetState.ProcessDisposedQueue();
|
||||
|
||||
if( Slice != null )
|
||||
Slice();
|
||||
|
||||
if( (++sample % sampleInterval) == 0 )
|
||||
{
|
||||
now = DateTime.Now;
|
||||
m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] =
|
||||
ticksPerSecond / (now.Ticks - last.Ticks);
|
||||
last = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
|
||||
}
|
||||
}
|
||||
|
||||
public static string Arguments
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if( Core.Debug )
|
||||
Utility.Separate( sb, "-debug", " " );
|
||||
|
||||
if( Core.Service )
|
||||
Utility.Separate( sb, "-service", " " );
|
||||
|
||||
if( Core.Profiling )
|
||||
Utility.Separate( sb, "-profile", " " );
|
||||
|
||||
if( !m_Cache )
|
||||
Utility.Separate( sb, "-nocache", " " );
|
||||
|
||||
if( m_HaltOnWarning )
|
||||
Utility.Separate( sb, "-haltonwarning", " " );
|
||||
|
||||
if ( m_VBdotNET )
|
||||
Utility.Separate( sb, "-vb", " " );
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private static int m_GlobalMaxUpdateRange = 24;
|
||||
|
||||
public static int GlobalMaxUpdateRange
|
||||
{
|
||||
get { return m_GlobalMaxUpdateRange; }
|
||||
set { m_GlobalMaxUpdateRange = value; }
|
||||
}
|
||||
|
||||
private static int m_ItemCount, m_MobileCount;
|
||||
|
||||
public static int ScriptItems { get { return m_ItemCount; } }
|
||||
public static int ScriptMobiles { get { return m_MobileCount; } }
|
||||
|
||||
public static void VerifySerialization()
|
||||
{
|
||||
m_ItemCount = 0;
|
||||
m_MobileCount = 0;
|
||||
|
||||
VerifySerialization( Assembly.GetCallingAssembly() );
|
||||
|
||||
for( int a = 0; a < ScriptCompiler.Assemblies.Length; ++a )
|
||||
VerifySerialization( ScriptCompiler.Assemblies[a] );
|
||||
}
|
||||
|
||||
private static readonly Type[] m_SerialTypeArray = new Type[1] { typeof(Serial) };
|
||||
|
||||
private static void VerifyType( Type t )
|
||||
{
|
||||
bool isItem = t.IsSubclassOf(typeof(Item));
|
||||
|
||||
if (isItem || t.IsSubclassOf(typeof(Mobile)))
|
||||
{
|
||||
if (isItem)
|
||||
{
|
||||
//++m_ItemCount;
|
||||
Interlocked.Increment(ref m_ItemCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
//++m_MobileCount;
|
||||
Interlocked.Increment(ref m_MobileCount);
|
||||
}
|
||||
|
||||
StringBuilder warningSb = null;
|
||||
|
||||
try
|
||||
{
|
||||
/*
|
||||
if( isItem && t.IsPublic && !t.IsAbstract )
|
||||
{
|
||||
ConstructorInfo cInfo = t.GetConstructor( Type.EmptyTypes );
|
||||
|
||||
if( cInfo == null )
|
||||
{
|
||||
if (warningSb == null)
|
||||
warningSb = new StringBuilder();
|
||||
|
||||
warningSb.AppendLine(" - No zero paramater constructor");
|
||||
}
|
||||
}*/
|
||||
|
||||
if (t.GetConstructor(m_SerialTypeArray) == null)
|
||||
{
|
||||
if (warningSb == null)
|
||||
warningSb = new StringBuilder();
|
||||
|
||||
warningSb.AppendLine(" - No serialization constructor");
|
||||
}
|
||||
|
||||
if (t.GetMethod("Serialize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) == null)
|
||||
{
|
||||
if (warningSb == null)
|
||||
warningSb = new StringBuilder();
|
||||
|
||||
warningSb.AppendLine(" - No Serialize() method");
|
||||
}
|
||||
|
||||
if (t.GetMethod("Deserialize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) == null)
|
||||
{
|
||||
if (warningSb == null)
|
||||
warningSb = new StringBuilder();
|
||||
|
||||
warningSb.AppendLine(" - No Deserialize() method");
|
||||
}
|
||||
|
||||
if (warningSb != null && warningSb.Length > 0)
|
||||
{
|
||||
Console.WriteLine("Warning: {0}\n{1}", t, warningSb.ToString());
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Warning: Exception in serialization verification of type {0}", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void VerifySerialization( Assembly a )
|
||||
{
|
||||
if( a == null )
|
||||
return;
|
||||
|
||||
#if Framework_4_0
|
||||
Parallel.ForEach(a.GetTypes(), t =>
|
||||
{
|
||||
VerifyType(t);
|
||||
});
|
||||
#else
|
||||
foreach (Type t in a.GetTypes())
|
||||
{
|
||||
VerifyType(t);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public class FileLogger : TextWriter, IDisposable
|
||||
{
|
||||
private string m_FileName;
|
||||
private bool m_NewLine;
|
||||
public const string DateFormat = "[MMMM dd hh:mm:ss.f tt]: ";
|
||||
|
||||
public string FileName { get { return m_FileName; } }
|
||||
|
||||
public FileLogger( string file )
|
||||
: this( file, false )
|
||||
{
|
||||
}
|
||||
|
||||
public FileLogger( string file, bool append )
|
||||
{
|
||||
m_FileName = file;
|
||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, append ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.Read ) ) )
|
||||
{
|
||||
writer.WriteLine( ">>>Logging started on {0}.", DateTime.Now.ToString( "f" ) ); //f = Tuesday, April 10, 2001 3:51 PM
|
||||
}
|
||||
m_NewLine = true;
|
||||
}
|
||||
|
||||
public override void Write( char ch )
|
||||
{
|
||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) )
|
||||
{
|
||||
if( m_NewLine )
|
||||
{
|
||||
writer.Write( DateTime.Now.ToString( DateFormat ) );
|
||||
m_NewLine = false;
|
||||
}
|
||||
writer.Write( ch );
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write( string str )
|
||||
{
|
||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) )
|
||||
{
|
||||
if( m_NewLine )
|
||||
{
|
||||
writer.Write( DateTime.Now.ToString( DateFormat ) );
|
||||
m_NewLine = false;
|
||||
}
|
||||
writer.Write( str );
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteLine( string line )
|
||||
{
|
||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) )
|
||||
{
|
||||
if( m_NewLine )
|
||||
writer.Write( DateTime.Now.ToString( DateFormat ) );
|
||||
writer.WriteLine( line );
|
||||
m_NewLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override System.Text.Encoding Encoding
|
||||
{
|
||||
get { return System.Text.Encoding.Default; }
|
||||
}
|
||||
}
|
||||
|
||||
public class MultiTextWriter : TextWriter
|
||||
{
|
||||
private List<TextWriter> m_Streams;
|
||||
|
||||
public MultiTextWriter( params TextWriter[] streams )
|
||||
{
|
||||
m_Streams = new List<TextWriter>( streams );
|
||||
|
||||
if( m_Streams.Count < 0 )
|
||||
throw new ArgumentException( "You must specify at least one stream." );
|
||||
}
|
||||
|
||||
public void Add( TextWriter tw )
|
||||
{
|
||||
m_Streams.Add( tw );
|
||||
}
|
||||
|
||||
public void Remove( TextWriter tw )
|
||||
{
|
||||
m_Streams.Remove( tw );
|
||||
}
|
||||
|
||||
public override void Write( char ch )
|
||||
{
|
||||
for( int i = 0; i < m_Streams.Count; i++ )
|
||||
m_Streams[i].Write( ch );
|
||||
}
|
||||
|
||||
public override void WriteLine( string line )
|
||||
{
|
||||
for( int i = 0; i < m_Streams.Count; i++ )
|
||||
m_Streams[i].WriteLine( line );
|
||||
}
|
||||
|
||||
public override void WriteLine( string line, params object[] args )
|
||||
{
|
||||
WriteLine( String.Format( line, args ) );
|
||||
}
|
||||
|
||||
public override Encoding Encoding
|
||||
{
|
||||
get { return Encoding.Default; }
|
||||
}
|
||||
}
|
||||
}
|
||||
2090
Source/Map.cs
Normal file
2090
Source/Map.cs
Normal file
File diff suppressed because it is too large
Load diff
34
Source/Menus/IMenu.cs
Normal file
34
Source/Menus/IMenu.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/***************************************************************************
|
||||
* IMenu.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Menus
|
||||
{
|
||||
public interface IMenu
|
||||
{
|
||||
int Serial{ get; }
|
||||
int EntryLength{ get; }
|
||||
void SendTo( NetState state );
|
||||
void OnCancel( NetState state );
|
||||
void OnResponse( NetState state, int index );
|
||||
}
|
||||
}
|
||||
140
Source/Menus/ItemListMenu.cs
Normal file
140
Source/Menus/ItemListMenu.cs
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/***************************************************************************
|
||||
* ItemListMenu.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Menus.ItemLists
|
||||
{
|
||||
public class ItemListEntry
|
||||
{
|
||||
private string m_Name;
|
||||
private int m_ItemID;
|
||||
private int m_Hue;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
}
|
||||
|
||||
public int ItemID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ItemID;
|
||||
}
|
||||
}
|
||||
|
||||
public int Hue
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Hue;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemListEntry( string name, int itemID ) : this( name, itemID, 0 )
|
||||
{
|
||||
}
|
||||
|
||||
public ItemListEntry( string name, int itemID, int hue )
|
||||
{
|
||||
m_Name = name;
|
||||
m_ItemID = itemID;
|
||||
m_Hue = hue;
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemListMenu : IMenu
|
||||
{
|
||||
private string m_Question;
|
||||
private ItemListEntry[] m_Entries;
|
||||
|
||||
private int m_Serial;
|
||||
private static int m_NextSerial;
|
||||
|
||||
int IMenu.Serial
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Serial;
|
||||
}
|
||||
}
|
||||
|
||||
int IMenu.EntryLength
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Entries.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public string Question
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Question;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemListEntry[] Entries
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Entries;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Entries = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemListMenu( string question, ItemListEntry[] entries )
|
||||
{
|
||||
m_Question = question;
|
||||
m_Entries = entries;
|
||||
|
||||
do
|
||||
{
|
||||
m_Serial = m_NextSerial++;
|
||||
m_Serial &= 0x7FFFFFFF;
|
||||
} while ( m_Serial == 0 );
|
||||
|
||||
m_Serial = (int)((uint)m_Serial | 0x80000000);
|
||||
}
|
||||
|
||||
public virtual void OnCancel( NetState state )
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnResponse( NetState state, int index )
|
||||
{
|
||||
}
|
||||
|
||||
public void SendTo( NetState state )
|
||||
{
|
||||
state.AddMenu( this );
|
||||
state.Send( new DisplayItemListMenu( this ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
96
Source/Menus/QuestionMenu.cs
Normal file
96
Source/Menus/QuestionMenu.cs
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/***************************************************************************
|
||||
* QuestionMenu.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Menus.Questions
|
||||
{
|
||||
public class QuestionMenu : IMenu
|
||||
{
|
||||
private string m_Question;
|
||||
private string[] m_Answers;
|
||||
|
||||
private int m_Serial;
|
||||
private static int m_NextSerial;
|
||||
|
||||
int IMenu.Serial
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Serial;
|
||||
}
|
||||
}
|
||||
|
||||
int IMenu.EntryLength
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Answers.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public string Question
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Question;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Question = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string[] Answers
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Answers;
|
||||
}
|
||||
}
|
||||
|
||||
public QuestionMenu( string question, string[] answers )
|
||||
{
|
||||
m_Question = question;
|
||||
m_Answers = answers;
|
||||
|
||||
do
|
||||
{
|
||||
m_Serial = ++m_NextSerial;
|
||||
m_Serial &= 0x7FFFFFFF;
|
||||
} while ( m_Serial == 0 );
|
||||
}
|
||||
|
||||
public virtual void OnCancel( NetState state )
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnResponse( NetState state, int index )
|
||||
{
|
||||
}
|
||||
|
||||
public void SendTo( NetState state )
|
||||
{
|
||||
state.AddMenu( this );
|
||||
state.Send( new DisplayQuestionMenu( this ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
11247
Source/Mobile.cs
Normal file
11247
Source/Mobile.cs
Normal file
File diff suppressed because it is too large
Load diff
75
Source/Movement.cs
Normal file
75
Source/Movement.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/***************************************************************************
|
||||
* Movement.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Server.Movement
|
||||
{
|
||||
public static class Movement
|
||||
{
|
||||
private static IMovementImpl m_Impl;
|
||||
|
||||
public static IMovementImpl Impl
|
||||
{
|
||||
get{ return m_Impl; }
|
||||
set{ m_Impl = value; }
|
||||
}
|
||||
|
||||
public static bool CheckMovement( Mobile m, Direction d, out int newZ )
|
||||
{
|
||||
if ( m_Impl != null )
|
||||
return m_Impl.CheckMovement( m, d, out newZ );
|
||||
|
||||
newZ = m.Z;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool CheckMovement( Mobile m, Map map, Point3D loc, Direction d, out int newZ )
|
||||
{
|
||||
if ( m_Impl != null )
|
||||
return m_Impl.CheckMovement( m, map, loc, d, out newZ );
|
||||
|
||||
newZ = m.Z;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Offset( Direction d, ref int x, ref int y )
|
||||
{
|
||||
switch ( d & Direction.Mask )
|
||||
{
|
||||
case Direction.North: --y; break;
|
||||
case Direction.South: ++y; break;
|
||||
case Direction.West: --x; break;
|
||||
case Direction.East: ++x; break;
|
||||
case Direction.Right: ++x; --y; break;
|
||||
case Direction.Left: --x; ++y; break;
|
||||
case Direction.Down: ++x; ++y; break;
|
||||
case Direction.Up: --x; --y; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMovementImpl
|
||||
{
|
||||
bool CheckMovement( Mobile m, Direction d, out int newZ );
|
||||
bool CheckMovement( Mobile m, Map map, Point3D loc, Direction d, out int newZ );
|
||||
}
|
||||
}
|
||||
596
Source/MultiData.cs
Normal file
596
Source/MultiData.cs
Normal file
|
|
@ -0,0 +1,596 @@
|
|||
/***************************************************************************
|
||||
* MultiData.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public static class MultiData
|
||||
{
|
||||
private static MultiComponentList[] m_Components;
|
||||
|
||||
private static FileStream m_Index, m_Stream;
|
||||
private static BinaryReader m_IndexReader, m_StreamReader;
|
||||
|
||||
public static MultiComponentList GetComponents( int multiID )
|
||||
{
|
||||
MultiComponentList mcl;
|
||||
|
||||
if ( multiID >= 0 && multiID < m_Components.Length )
|
||||
{
|
||||
mcl = m_Components[multiID];
|
||||
|
||||
if ( mcl == null )
|
||||
m_Components[multiID] = mcl = Load( multiID );
|
||||
}
|
||||
else
|
||||
{
|
||||
mcl = MultiComponentList.Empty;
|
||||
}
|
||||
|
||||
return mcl;
|
||||
}
|
||||
|
||||
public static MultiComponentList Load( int multiID )
|
||||
{
|
||||
try
|
||||
{
|
||||
m_IndexReader.BaseStream.Seek( multiID * 12, SeekOrigin.Begin );
|
||||
|
||||
int lookup = m_IndexReader.ReadInt32();
|
||||
int length = m_IndexReader.ReadInt32();
|
||||
|
||||
if ( lookup < 0 || length <= 0 )
|
||||
return MultiComponentList.Empty;
|
||||
|
||||
m_StreamReader.BaseStream.Seek( lookup, SeekOrigin.Begin );
|
||||
|
||||
return new MultiComponentList( m_StreamReader, length / ( MultiComponentList.PostHSFormat ? 16 : 12 ) );
|
||||
}
|
||||
catch
|
||||
{
|
||||
return MultiComponentList.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
static MultiData()
|
||||
{
|
||||
string idxPath = Core.FindDataFile( "multi.idx" );
|
||||
string mulPath = Core.FindDataFile( "multi.mul" );
|
||||
|
||||
if ( File.Exists( idxPath ) && File.Exists( mulPath ) )
|
||||
{
|
||||
m_Index = new FileStream( idxPath, FileMode.Open, FileAccess.Read, FileShare.Read );
|
||||
m_IndexReader = new BinaryReader( m_Index );
|
||||
|
||||
m_Stream = new FileStream( mulPath, FileMode.Open, FileAccess.Read, FileShare.Read );
|
||||
m_StreamReader = new BinaryReader( m_Stream );
|
||||
|
||||
m_Components = new MultiComponentList[(int)(m_Index.Length / 12)];
|
||||
|
||||
string vdPath = Core.FindDataFile( "verdata.mul" );
|
||||
|
||||
if ( File.Exists( vdPath ) )
|
||||
{
|
||||
using ( FileStream fs = new FileStream( vdPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
|
||||
{
|
||||
BinaryReader bin = new BinaryReader( fs );
|
||||
|
||||
int count = bin.ReadInt32();
|
||||
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
int file = bin.ReadInt32();
|
||||
int index = bin.ReadInt32();
|
||||
int lookup = bin.ReadInt32();
|
||||
int length = bin.ReadInt32();
|
||||
int extra = bin.ReadInt32();
|
||||
|
||||
if ( file == 14 && index >= 0 && index < m_Components.Length && lookup >= 0 && length > 0 )
|
||||
{
|
||||
bin.BaseStream.Seek( lookup, SeekOrigin.Begin );
|
||||
|
||||
m_Components[index] = new MultiComponentList( bin, length / 12 );
|
||||
|
||||
bin.BaseStream.Seek( 24 + (i * 20), SeekOrigin.Begin );
|
||||
}
|
||||
}
|
||||
|
||||
bin.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine( "Warning: Multi data files not found" );
|
||||
|
||||
m_Components = new MultiComponentList[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct MultiTileEntry
|
||||
{
|
||||
public ushort m_ItemID;
|
||||
public short m_OffsetX, m_OffsetY, m_OffsetZ;
|
||||
public int m_Flags;
|
||||
|
||||
public MultiTileEntry( ushort itemID, short xOffset, short yOffset, short zOffset, int flags )
|
||||
{
|
||||
m_ItemID = itemID;
|
||||
m_OffsetX = xOffset;
|
||||
m_OffsetY = yOffset;
|
||||
m_OffsetZ = zOffset;
|
||||
m_Flags = flags;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MultiComponentList
|
||||
{
|
||||
public static bool PostHSFormat {
|
||||
get { return _PostHSFormat; }
|
||||
set { _PostHSFormat = value; }
|
||||
}
|
||||
|
||||
private static bool _PostHSFormat = false;
|
||||
|
||||
private Point2D m_Min, m_Max, m_Center;
|
||||
private int m_Width, m_Height;
|
||||
private StaticTile[][][] m_Tiles;
|
||||
private MultiTileEntry[] m_List;
|
||||
|
||||
public static readonly MultiComponentList Empty = new MultiComponentList();
|
||||
|
||||
public Point2D Min{ get{ return m_Min; } }
|
||||
public Point2D Max{ get{ return m_Max; } }
|
||||
|
||||
public Point2D Center{ get{ return m_Center; } }
|
||||
|
||||
public int Width{ get{ return m_Width; } }
|
||||
public int Height{ get{ return m_Height; } }
|
||||
|
||||
public StaticTile[][][] Tiles{ get{ return m_Tiles; } }
|
||||
public MultiTileEntry[] List{ get{ return m_List; } }
|
||||
|
||||
public void Add( int itemID, int x, int y, int z )
|
||||
{
|
||||
int vx = x + m_Center.m_X;
|
||||
int vy = y + m_Center.m_Y;
|
||||
|
||||
if ( vx >= 0 && vx < m_Width && vy >= 0 && vy < m_Height )
|
||||
{
|
||||
StaticTile[] oldTiles = m_Tiles[vx][vy];
|
||||
|
||||
for ( int i = oldTiles.Length - 1; i >= 0; --i )
|
||||
{
|
||||
ItemData data = TileData.ItemTable[itemID & TileData.MaxItemValue];
|
||||
|
||||
if ( oldTiles[i].Z == z && (oldTiles[i].Height > 0 == data.Height > 0 ) )
|
||||
{
|
||||
bool newIsRoof = ( data.Flags & TileFlag.Roof) != 0;
|
||||
bool oldIsRoof = (TileData.ItemTable[oldTiles[i].ID & TileData.MaxItemValue].Flags & TileFlag.Roof ) != 0;
|
||||
|
||||
if ( newIsRoof == oldIsRoof )
|
||||
Remove( oldTiles[i].ID, x, y, z );
|
||||
}
|
||||
}
|
||||
|
||||
oldTiles = m_Tiles[vx][vy];
|
||||
|
||||
StaticTile[] newTiles = new StaticTile[oldTiles.Length + 1];
|
||||
|
||||
for ( int i = 0; i < oldTiles.Length; ++i )
|
||||
newTiles[i] = oldTiles[i];
|
||||
|
||||
newTiles[oldTiles.Length] = new StaticTile( (ushort)itemID, (sbyte)z );
|
||||
|
||||
m_Tiles[vx][vy] = newTiles;
|
||||
|
||||
MultiTileEntry[] oldList = m_List;
|
||||
MultiTileEntry[] newList = new MultiTileEntry[oldList.Length + 1];
|
||||
|
||||
for ( int i = 0; i < oldList.Length; ++i )
|
||||
newList[i] = oldList[i];
|
||||
|
||||
newList[oldList.Length] = new MultiTileEntry( (ushort)itemID, (short)x, (short)y, (short)z, 1 );
|
||||
|
||||
m_List = newList;
|
||||
|
||||
if ( x < m_Min.m_X )
|
||||
m_Min.m_X = x;
|
||||
|
||||
if ( y < m_Min.m_Y )
|
||||
m_Min.m_Y = y;
|
||||
|
||||
if ( x > m_Max.m_X )
|
||||
m_Max.m_X = x;
|
||||
|
||||
if ( y > m_Max.m_Y )
|
||||
m_Max.m_Y = y;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveXYZH( int x, int y, int z, int minHeight )
|
||||
{
|
||||
int vx = x + m_Center.m_X;
|
||||
int vy = y + m_Center.m_Y;
|
||||
|
||||
if ( vx >= 0 && vx < m_Width && vy >= 0 && vy < m_Height )
|
||||
{
|
||||
StaticTile[] oldTiles = m_Tiles[vx][vy];
|
||||
|
||||
for ( int i = 0; i < oldTiles.Length; ++i )
|
||||
{
|
||||
StaticTile tile = oldTiles[i];
|
||||
|
||||
if ( tile.Z == z && tile.Height >= minHeight )
|
||||
{
|
||||
StaticTile[] newTiles = new StaticTile[oldTiles.Length - 1];
|
||||
|
||||
for ( int j = 0; j < i; ++j )
|
||||
newTiles[j] = oldTiles[j];
|
||||
|
||||
for ( int j = i + 1; j < oldTiles.Length; ++j )
|
||||
newTiles[j - 1] = oldTiles[j];
|
||||
|
||||
m_Tiles[vx][vy] = newTiles;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MultiTileEntry[] oldList = m_List;
|
||||
|
||||
for ( int i = 0; i < oldList.Length; ++i )
|
||||
{
|
||||
MultiTileEntry tile = oldList[i];
|
||||
|
||||
if ( tile.m_OffsetX == (short)x && tile.m_OffsetY == (short)y && tile.m_OffsetZ == (short)z && TileData.ItemTable[tile.m_ItemID & TileData.MaxItemValue].Height >= minHeight )
|
||||
{
|
||||
MultiTileEntry[] newList = new MultiTileEntry[oldList.Length - 1];
|
||||
|
||||
for ( int j = 0; j < i; ++j )
|
||||
newList[j] = oldList[j];
|
||||
|
||||
for ( int j = i + 1; j < oldList.Length; ++j )
|
||||
newList[j - 1] = oldList[j];
|
||||
|
||||
m_List = newList;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove( int itemID, int x, int y, int z )
|
||||
{
|
||||
int vx = x + m_Center.m_X;
|
||||
int vy = y + m_Center.m_Y;
|
||||
|
||||
if ( vx >= 0 && vx < m_Width && vy >= 0 && vy < m_Height )
|
||||
{
|
||||
StaticTile[] oldTiles = m_Tiles[vx][vy];
|
||||
|
||||
for ( int i = 0; i < oldTiles.Length; ++i )
|
||||
{
|
||||
StaticTile tile = oldTiles[i];
|
||||
|
||||
if ( tile.ID == itemID && tile.Z == z )
|
||||
{
|
||||
StaticTile[] newTiles = new StaticTile[oldTiles.Length - 1];
|
||||
|
||||
for ( int j = 0; j < i; ++j )
|
||||
newTiles[j] = oldTiles[j];
|
||||
|
||||
for ( int j = i + 1; j < oldTiles.Length; ++j )
|
||||
newTiles[j - 1] = oldTiles[j];
|
||||
|
||||
m_Tiles[vx][vy] = newTiles;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MultiTileEntry[] oldList = m_List;
|
||||
|
||||
for ( int i = 0; i < oldList.Length; ++i )
|
||||
{
|
||||
MultiTileEntry tile = oldList[i];
|
||||
|
||||
if ( tile.m_ItemID == itemID && tile.m_OffsetX == (short)x && tile.m_OffsetY == (short)y && tile.m_OffsetZ == (short)z )
|
||||
{
|
||||
MultiTileEntry[] newList = new MultiTileEntry[oldList.Length - 1];
|
||||
|
||||
for ( int j = 0; j < i; ++j )
|
||||
newList[j] = oldList[j];
|
||||
|
||||
for ( int j = i + 1; j < oldList.Length; ++j )
|
||||
newList[j - 1] = oldList[j];
|
||||
|
||||
m_List = newList;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Resize( int newWidth, int newHeight )
|
||||
{
|
||||
int oldWidth = m_Width, oldHeight = m_Height;
|
||||
StaticTile[][][] oldTiles = m_Tiles;
|
||||
|
||||
int totalLength = 0;
|
||||
|
||||
StaticTile[][][] newTiles = new StaticTile[newWidth][][];
|
||||
|
||||
for ( int x = 0; x < newWidth; ++x )
|
||||
{
|
||||
newTiles[x] = new StaticTile[newHeight][];
|
||||
|
||||
for ( int y = 0; y < newHeight; ++y )
|
||||
{
|
||||
if ( x < oldWidth && y < oldHeight )
|
||||
newTiles[x][y] = oldTiles[x][y];
|
||||
else
|
||||
newTiles[x][y] = new StaticTile[0];
|
||||
|
||||
totalLength += newTiles[x][y].Length;
|
||||
}
|
||||
}
|
||||
|
||||
m_Tiles = newTiles;
|
||||
m_List = new MultiTileEntry[totalLength];
|
||||
m_Width = newWidth;
|
||||
m_Height = newHeight;
|
||||
|
||||
m_Min = Point2D.Zero;
|
||||
m_Max = Point2D.Zero;
|
||||
|
||||
int index = 0;
|
||||
|
||||
for ( int x = 0; x < newWidth; ++x )
|
||||
{
|
||||
for ( int y = 0; y < newHeight; ++y )
|
||||
{
|
||||
StaticTile[] tiles = newTiles[x][y];
|
||||
|
||||
for ( int i = 0; i < tiles.Length; ++i )
|
||||
{
|
||||
StaticTile tile = tiles[i];
|
||||
|
||||
int vx = x - m_Center.X;
|
||||
int vy = y - m_Center.Y;
|
||||
|
||||
if ( vx < m_Min.m_X )
|
||||
m_Min.m_X = vx;
|
||||
|
||||
if ( vy < m_Min.m_Y )
|
||||
m_Min.m_Y = vy;
|
||||
|
||||
if ( vx > m_Max.m_X )
|
||||
m_Max.m_X = vx;
|
||||
|
||||
if ( vy > m_Max.m_Y )
|
||||
m_Max.m_Y = vy;
|
||||
|
||||
m_List[index++] = new MultiTileEntry( (ushort)tile.ID, (short)vx, (short)vy, (short)tile.Z, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MultiComponentList( MultiComponentList toCopy )
|
||||
{
|
||||
m_Min = toCopy.m_Min;
|
||||
m_Max = toCopy.m_Max;
|
||||
|
||||
m_Center = toCopy.m_Center;
|
||||
|
||||
m_Width = toCopy.m_Width;
|
||||
m_Height = toCopy.m_Height;
|
||||
|
||||
m_Tiles = new StaticTile[m_Width][][];
|
||||
|
||||
for ( int x = 0; x < m_Width; ++x )
|
||||
{
|
||||
m_Tiles[x] = new StaticTile[m_Height][];
|
||||
|
||||
for ( int y = 0; y < m_Height; ++y )
|
||||
{
|
||||
m_Tiles[x][y] = new StaticTile[toCopy.m_Tiles[x][y].Length];
|
||||
|
||||
for ( int i = 0; i < m_Tiles[x][y].Length; ++i )
|
||||
m_Tiles[x][y][i] = toCopy.m_Tiles[x][y][i];
|
||||
}
|
||||
}
|
||||
|
||||
m_List = new MultiTileEntry[toCopy.m_List.Length];
|
||||
|
||||
for ( int i = 0; i < m_List.Length; ++i )
|
||||
m_List[i] = toCopy.m_List[i];
|
||||
}
|
||||
|
||||
public void Serialize( GenericWriter writer )
|
||||
{
|
||||
writer.Write( (int) 1 ); // version;
|
||||
|
||||
writer.Write( m_Min );
|
||||
writer.Write( m_Max );
|
||||
writer.Write( m_Center );
|
||||
|
||||
writer.Write( (int) m_Width );
|
||||
writer.Write( (int) m_Height );
|
||||
|
||||
writer.Write( (int) m_List.Length );
|
||||
|
||||
for ( int i = 0; i < m_List.Length; ++i )
|
||||
{
|
||||
MultiTileEntry ent = m_List[i];
|
||||
|
||||
writer.Write( (ushort) ent.m_ItemID );
|
||||
writer.Write( (short) ent.m_OffsetX );
|
||||
writer.Write( (short) ent.m_OffsetY );
|
||||
writer.Write( (short) ent.m_OffsetZ );
|
||||
writer.Write( (int) ent.m_Flags );
|
||||
}
|
||||
}
|
||||
|
||||
public MultiComponentList( GenericReader reader )
|
||||
{
|
||||
int version = reader.ReadInt();
|
||||
|
||||
m_Min = reader.ReadPoint2D();
|
||||
m_Max = reader.ReadPoint2D();
|
||||
m_Center = reader.ReadPoint2D();
|
||||
m_Width = reader.ReadInt();
|
||||
m_Height = reader.ReadInt();
|
||||
|
||||
int length = reader.ReadInt();
|
||||
|
||||
MultiTileEntry[] allTiles = m_List = new MultiTileEntry[length];
|
||||
|
||||
if ( version == 0 ) {
|
||||
for ( int i = 0; i < length; ++i )
|
||||
{
|
||||
int id = reader.ReadShort();
|
||||
if ( id >= 0x4000 )
|
||||
id -= 0x4000;
|
||||
|
||||
allTiles[i].m_ItemID = (ushort)id;
|
||||
allTiles[i].m_OffsetX = reader.ReadShort();
|
||||
allTiles[i].m_OffsetY = reader.ReadShort();
|
||||
allTiles[i].m_OffsetZ = reader.ReadShort();
|
||||
allTiles[i].m_Flags = reader.ReadInt();
|
||||
}
|
||||
} else {
|
||||
for ( int i = 0; i < length; ++i )
|
||||
{
|
||||
allTiles[i].m_ItemID = reader.ReadUShort();
|
||||
allTiles[i].m_OffsetX = reader.ReadShort();
|
||||
allTiles[i].m_OffsetY = reader.ReadShort();
|
||||
allTiles[i].m_OffsetZ = reader.ReadShort();
|
||||
allTiles[i].m_Flags = reader.ReadInt();
|
||||
}
|
||||
}
|
||||
|
||||
TileList[][] tiles = new TileList[m_Width][];
|
||||
m_Tiles = new StaticTile[m_Width][][];
|
||||
|
||||
for ( int x = 0; x < m_Width; ++x )
|
||||
{
|
||||
tiles[x] = new TileList[m_Height];
|
||||
m_Tiles[x] = new StaticTile[m_Height][];
|
||||
|
||||
for ( int y = 0; y < m_Height; ++y )
|
||||
tiles[x][y] = new TileList();
|
||||
}
|
||||
|
||||
for ( int i = 0; i < allTiles.Length; ++i )
|
||||
{
|
||||
if ( i == 0 || allTiles[i].m_Flags != 0 )
|
||||
{
|
||||
int xOffset = allTiles[i].m_OffsetX + m_Center.m_X;
|
||||
int yOffset = allTiles[i].m_OffsetY + m_Center.m_Y;
|
||||
|
||||
tiles[xOffset][yOffset].Add( (ushort)allTiles[i].m_ItemID, (sbyte)allTiles[i].m_OffsetZ );
|
||||
}
|
||||
}
|
||||
|
||||
for ( int x = 0; x < m_Width; ++x )
|
||||
for ( int y = 0; y < m_Height; ++y )
|
||||
m_Tiles[x][y] = tiles[x][y].ToArray();
|
||||
}
|
||||
|
||||
public MultiComponentList( BinaryReader reader, int count )
|
||||
{
|
||||
MultiTileEntry[] allTiles = m_List = new MultiTileEntry[count];
|
||||
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
allTiles[i].m_ItemID = reader.ReadUInt16();
|
||||
allTiles[i].m_OffsetX = reader.ReadInt16();
|
||||
allTiles[i].m_OffsetY = reader.ReadInt16();
|
||||
allTiles[i].m_OffsetZ = reader.ReadInt16();
|
||||
allTiles[i].m_Flags = reader.ReadInt32();
|
||||
|
||||
if ( _PostHSFormat )
|
||||
reader.ReadInt32(); // ??
|
||||
|
||||
MultiTileEntry e = allTiles[i];
|
||||
|
||||
if ( i == 0 || e.m_Flags != 0 )
|
||||
{
|
||||
if ( e.m_OffsetX < m_Min.m_X )
|
||||
m_Min.m_X = e.m_OffsetX;
|
||||
|
||||
if ( e.m_OffsetY < m_Min.m_Y )
|
||||
m_Min.m_Y = e.m_OffsetY;
|
||||
|
||||
if ( e.m_OffsetX > m_Max.m_X )
|
||||
m_Max.m_X = e.m_OffsetX;
|
||||
|
||||
if ( e.m_OffsetY > m_Max.m_Y )
|
||||
m_Max.m_Y = e.m_OffsetY;
|
||||
}
|
||||
}
|
||||
|
||||
m_Center = new Point2D( -m_Min.m_X, -m_Min.m_Y );
|
||||
m_Width = (m_Max.m_X - m_Min.m_X) + 1;
|
||||
m_Height = (m_Max.m_Y - m_Min.m_Y) + 1;
|
||||
|
||||
TileList[][] tiles = new TileList[m_Width][];
|
||||
m_Tiles = new StaticTile[m_Width][][];
|
||||
|
||||
for ( int x = 0; x < m_Width; ++x )
|
||||
{
|
||||
tiles[x] = new TileList[m_Height];
|
||||
m_Tiles[x] = new StaticTile[m_Height][];
|
||||
|
||||
for ( int y = 0; y < m_Height; ++y )
|
||||
tiles[x][y] = new TileList();
|
||||
}
|
||||
|
||||
for ( int i = 0; i < allTiles.Length; ++i )
|
||||
{
|
||||
if ( i == 0 || allTiles[i].m_Flags != 0 )
|
||||
{
|
||||
int xOffset = allTiles[i].m_OffsetX + m_Center.m_X;
|
||||
int yOffset = allTiles[i].m_OffsetY + m_Center.m_Y;
|
||||
|
||||
tiles[xOffset][yOffset].Add( (ushort)allTiles[i].m_ItemID, (sbyte)allTiles[i].m_OffsetZ );
|
||||
}
|
||||
}
|
||||
|
||||
for ( int x = 0; x < m_Width; ++x )
|
||||
for ( int y = 0; y < m_Height; ++y )
|
||||
m_Tiles[x][y] = tiles[x][y].ToArray();
|
||||
}
|
||||
|
||||
private MultiComponentList()
|
||||
{
|
||||
m_Tiles = new StaticTile[0][][];
|
||||
m_List = new MultiTileEntry[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
68
Source/NativeReader.cs
Normal file
68
Source/NativeReader.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/***************************************************************************
|
||||
* NativeReader.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Server {
|
||||
public static class NativeReader {
|
||||
|
||||
private static readonly INativeReader m_NativeReader;
|
||||
|
||||
static NativeReader() {
|
||||
if ( Core.Unix )
|
||||
m_NativeReader = new NativeReaderUnix();
|
||||
else
|
||||
m_NativeReader = new NativeReaderWin32();
|
||||
}
|
||||
|
||||
public static unsafe void Read( IntPtr ptr, void *buffer, int length ) {
|
||||
m_NativeReader.Read( ptr, buffer, length );
|
||||
}
|
||||
}
|
||||
|
||||
public interface INativeReader {
|
||||
unsafe void Read( IntPtr ptr, void *buffer, int length );
|
||||
}
|
||||
|
||||
public sealed class NativeReaderWin32 : INativeReader {
|
||||
[DllImport( "kernel32" )]
|
||||
private unsafe static extern int _lread( IntPtr hFile, void *lpBuffer, int wBytes );
|
||||
|
||||
public NativeReaderWin32() {
|
||||
}
|
||||
|
||||
public unsafe void Read( IntPtr ptr, void *buffer, int length ) {
|
||||
_lread( ptr, buffer, length );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NativeReaderUnix : INativeReader {
|
||||
[DllImport( "libc" )]
|
||||
private unsafe static extern int read( IntPtr ptr, void *buffer, int length );
|
||||
|
||||
public NativeReaderUnix() {
|
||||
}
|
||||
|
||||
public unsafe void Read( IntPtr ptr, void *buffer, int length ) {
|
||||
read( ptr, buffer, length );
|
||||
}
|
||||
}
|
||||
}
|
||||
102
Source/Network/BufferPool.cs
Normal file
102
Source/Network/BufferPool.cs
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/***************************************************************************
|
||||
* BufferPool.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public class BufferPool
|
||||
{
|
||||
private static List<BufferPool> m_Pools = new List<BufferPool>();
|
||||
|
||||
public static List<BufferPool> Pools{ get{ return m_Pools; } set{ m_Pools = value; } }
|
||||
|
||||
private string m_Name;
|
||||
|
||||
private int m_InitialCapacity;
|
||||
private int m_BufferSize;
|
||||
|
||||
private int m_Misses;
|
||||
|
||||
private Queue<byte[]> m_FreeBuffers;
|
||||
|
||||
public void GetInfo( out string name, out int freeCount, out int initialCapacity, out int currentCapacity, out int bufferSize, out int misses )
|
||||
{
|
||||
lock ( this )
|
||||
{
|
||||
name = m_Name;
|
||||
freeCount = m_FreeBuffers.Count;
|
||||
initialCapacity = m_InitialCapacity;
|
||||
currentCapacity = m_InitialCapacity * (1 + m_Misses);
|
||||
bufferSize = m_BufferSize;
|
||||
misses = m_Misses;
|
||||
}
|
||||
}
|
||||
|
||||
public BufferPool( string name, int initialCapacity, int bufferSize )
|
||||
{
|
||||
m_Name = name;
|
||||
|
||||
m_InitialCapacity = initialCapacity;
|
||||
m_BufferSize = bufferSize;
|
||||
|
||||
m_FreeBuffers = new Queue<byte[]>( initialCapacity );
|
||||
|
||||
for ( int i = 0; i < initialCapacity; ++i )
|
||||
m_FreeBuffers.Enqueue( new byte[bufferSize] );
|
||||
|
||||
lock ( m_Pools )
|
||||
m_Pools.Add( this );
|
||||
}
|
||||
|
||||
public byte[] AcquireBuffer()
|
||||
{
|
||||
lock ( this )
|
||||
{
|
||||
if ( m_FreeBuffers.Count > 0 )
|
||||
return m_FreeBuffers.Dequeue();
|
||||
|
||||
++m_Misses;
|
||||
|
||||
for ( int i = 0; i < m_InitialCapacity; ++i )
|
||||
m_FreeBuffers.Enqueue( new byte[m_BufferSize] );
|
||||
|
||||
return m_FreeBuffers.Dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
public void ReleaseBuffer( byte[] buffer )
|
||||
{
|
||||
if ( buffer == null )
|
||||
return;
|
||||
|
||||
lock ( this )
|
||||
m_FreeBuffers.Enqueue( buffer );
|
||||
}
|
||||
|
||||
public void Free()
|
||||
{
|
||||
lock ( m_Pools )
|
||||
m_Pools.Remove( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
153
Source/Network/ByteQueue.cs
Normal file
153
Source/Network/ByteQueue.cs
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
/***************************************************************************
|
||||
* ByteQueue.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public class ByteQueue
|
||||
{
|
||||
private int m_Head;
|
||||
private int m_Tail;
|
||||
private int m_Size;
|
||||
|
||||
private byte[] m_Buffer;
|
||||
|
||||
public int Length{ get{ return m_Size; } }
|
||||
|
||||
public ByteQueue()
|
||||
{
|
||||
m_Buffer = new byte[2048];
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_Head = 0;
|
||||
m_Tail = 0;
|
||||
m_Size = 0;
|
||||
}
|
||||
|
||||
private void SetCapacity( int capacity )
|
||||
{
|
||||
byte[] newBuffer = new byte[capacity];
|
||||
|
||||
if ( m_Size > 0 )
|
||||
{
|
||||
if ( m_Head < m_Tail )
|
||||
{
|
||||
Buffer.BlockCopy( m_Buffer, m_Head, newBuffer, 0, m_Size );
|
||||
}
|
||||
else
|
||||
{
|
||||
Buffer.BlockCopy( m_Buffer, m_Head, newBuffer, 0, m_Buffer.Length - m_Head );
|
||||
Buffer.BlockCopy( m_Buffer, 0, newBuffer, m_Buffer.Length - m_Head, m_Tail );
|
||||
}
|
||||
}
|
||||
|
||||
m_Head = 0;
|
||||
m_Tail = m_Size;
|
||||
m_Buffer = newBuffer;
|
||||
}
|
||||
|
||||
public byte GetPacketID()
|
||||
{
|
||||
if ( m_Size >= 1 )
|
||||
return m_Buffer[m_Head];
|
||||
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
public int GetPacketLength()
|
||||
{
|
||||
if ( m_Size >= 3 )
|
||||
return (m_Buffer[(m_Head + 1) % m_Buffer.Length] << 8) | m_Buffer[(m_Head + 2) % m_Buffer.Length];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int Dequeue( byte[] buffer, int offset, int size )
|
||||
{
|
||||
if ( size > m_Size )
|
||||
size = m_Size;
|
||||
|
||||
if ( size == 0 )
|
||||
return 0;
|
||||
|
||||
if ( m_Head < m_Tail )
|
||||
{
|
||||
Buffer.BlockCopy( m_Buffer, m_Head, buffer, offset, size );
|
||||
}
|
||||
else
|
||||
{
|
||||
int rightLength = ( m_Buffer.Length - m_Head );
|
||||
|
||||
if ( rightLength >= size )
|
||||
{
|
||||
Buffer.BlockCopy( m_Buffer, m_Head, buffer, offset, size );
|
||||
}
|
||||
else
|
||||
{
|
||||
Buffer.BlockCopy( m_Buffer, m_Head, buffer, offset, rightLength );
|
||||
Buffer.BlockCopy( m_Buffer, 0, buffer, offset + rightLength, size - rightLength );
|
||||
}
|
||||
}
|
||||
|
||||
m_Head = ( m_Head + size ) % m_Buffer.Length;
|
||||
m_Size -= size;
|
||||
|
||||
if ( m_Size == 0 )
|
||||
{
|
||||
m_Head = 0;
|
||||
m_Tail = 0;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public void Enqueue( byte[] buffer, int offset, int size )
|
||||
{
|
||||
if ( (m_Size + size) > m_Buffer.Length )
|
||||
SetCapacity( (m_Size + size + 2047) & ~2047 );
|
||||
|
||||
if ( m_Head < m_Tail )
|
||||
{
|
||||
int rightLength = ( m_Buffer.Length - m_Tail );
|
||||
|
||||
if ( rightLength >= size )
|
||||
{
|
||||
Buffer.BlockCopy( buffer, offset, m_Buffer, m_Tail, size );
|
||||
}
|
||||
else
|
||||
{
|
||||
Buffer.BlockCopy( buffer, offset, m_Buffer, m_Tail, rightLength );
|
||||
Buffer.BlockCopy( buffer, offset + rightLength, m_Buffer, 0, size - rightLength );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Buffer.BlockCopy( buffer, offset, m_Buffer, m_Tail, size );
|
||||
}
|
||||
|
||||
m_Tail = ( m_Tail + size ) % m_Buffer.Length;
|
||||
m_Size += size;
|
||||
}
|
||||
}
|
||||
}
|
||||
388
Source/Network/Compression.cs
Normal file
388
Source/Network/Compression.cs
Normal file
|
|
@ -0,0 +1,388 @@
|
|||
/***************************************************************************
|
||||
* Compression.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Server.Network {
|
||||
/// <summary>
|
||||
/// Handles outgoing packet compression for the network.
|
||||
/// </summary>
|
||||
public static class Compression {
|
||||
private static int[] _huffmanTable = new int[514]
|
||||
{
|
||||
0x2, 0x000, 0x5, 0x01F, 0x6, 0x022, 0x7, 0x034, 0x7, 0x075, 0x6, 0x028, 0x6, 0x03B, 0x7, 0x032,
|
||||
0x8, 0x0E0, 0x8, 0x062, 0x7, 0x056, 0x8, 0x079, 0x9, 0x19D, 0x8, 0x097, 0x6, 0x02A, 0x7, 0x057,
|
||||
0x8, 0x071, 0x8, 0x05B, 0x9, 0x1CC, 0x8, 0x0A7, 0x7, 0x025, 0x7, 0x04F, 0x8, 0x066, 0x8, 0x07D,
|
||||
0x9, 0x191, 0x9, 0x1CE, 0x7, 0x03F, 0x9, 0x090, 0x8, 0x059, 0x8, 0x07B, 0x8, 0x091, 0x8, 0x0C6,
|
||||
0x6, 0x02D, 0x9, 0x186, 0x8, 0x06F, 0x9, 0x093, 0xA, 0x1CC, 0x8, 0x05A, 0xA, 0x1AE, 0xA, 0x1C0,
|
||||
0x9, 0x148, 0x9, 0x14A, 0x9, 0x082, 0xA, 0x19F, 0x9, 0x171, 0x9, 0x120, 0x9, 0x0E7, 0xA, 0x1F3,
|
||||
0x9, 0x14B, 0x9, 0x100, 0x9, 0x190, 0x6, 0x013, 0x9, 0x161, 0x9, 0x125, 0x9, 0x133, 0x9, 0x195,
|
||||
0x9, 0x173, 0x9, 0x1CA, 0x9, 0x086, 0x9, 0x1E9, 0x9, 0x0DB, 0x9, 0x1EC, 0x9, 0x08B, 0x9, 0x085,
|
||||
0x5, 0x00A, 0x8, 0x096, 0x8, 0x09C, 0x9, 0x1C3, 0x9, 0x19C, 0x9, 0x08F, 0x9, 0x18F, 0x9, 0x091,
|
||||
0x9, 0x087, 0x9, 0x0C6, 0x9, 0x177, 0x9, 0x089, 0x9, 0x0D6, 0x9, 0x08C, 0x9, 0x1EE, 0x9, 0x1EB,
|
||||
0x9, 0x084, 0x9, 0x164, 0x9, 0x175, 0x9, 0x1CD, 0x8, 0x05E, 0x9, 0x088, 0x9, 0x12B, 0x9, 0x172,
|
||||
0x9, 0x10A, 0x9, 0x08D, 0x9, 0x13A, 0x9, 0x11C, 0xA, 0x1E1, 0xA, 0x1E0, 0x9, 0x187, 0xA, 0x1DC,
|
||||
0xA, 0x1DF, 0x7, 0x074, 0x9, 0x19F, 0x8, 0x08D, 0x8, 0x0E4, 0x7, 0x079, 0x9, 0x0EA, 0x9, 0x0E1,
|
||||
0x8, 0x040, 0x7, 0x041, 0x9, 0x10B, 0x9, 0x0B0, 0x8, 0x06A, 0x8, 0x0C1, 0x7, 0x071, 0x7, 0x078,
|
||||
0x8, 0x0B1, 0x9, 0x14C, 0x7, 0x043, 0x8, 0x076, 0x7, 0x066, 0x7, 0x04D, 0x9, 0x08A, 0x6, 0x02F,
|
||||
0x8, 0x0C9, 0x9, 0x0CE, 0x9, 0x149, 0x9, 0x160, 0xA, 0x1BA, 0xA, 0x19E, 0xA, 0x39F, 0x9, 0x0E5,
|
||||
0x9, 0x194, 0x9, 0x184, 0x9, 0x126, 0x7, 0x030, 0x8, 0x06C, 0x9, 0x121, 0x9, 0x1E8, 0xA, 0x1C1,
|
||||
0xA, 0x11D, 0xA, 0x163, 0xA, 0x385, 0xA, 0x3DB, 0xA, 0x17D, 0xA, 0x106, 0xA, 0x397, 0xA, 0x24E,
|
||||
0x7, 0x02E, 0x8, 0x098, 0xA, 0x33C, 0xA, 0x32E, 0xA, 0x1E9, 0x9, 0x0BF, 0xA, 0x3DF, 0xA, 0x1DD,
|
||||
0xA, 0x32D, 0xA, 0x2ED, 0xA, 0x30B, 0xA, 0x107, 0xA, 0x2E8, 0xA, 0x3DE, 0xA, 0x125, 0xA, 0x1E8,
|
||||
0x9, 0x0E9, 0xA, 0x1CD, 0xA, 0x1B5, 0x9, 0x165, 0xA, 0x232, 0xA, 0x2E1, 0xB, 0x3AE, 0xB, 0x3C6,
|
||||
0xB, 0x3E2, 0xA, 0x205, 0xA, 0x29A, 0xA, 0x248, 0xA, 0x2CD, 0xA, 0x23B, 0xB, 0x3C5, 0xA, 0x251,
|
||||
0xA, 0x2E9, 0xA, 0x252, 0x9, 0x1EA, 0xB, 0x3A0, 0xB, 0x391, 0xA, 0x23C, 0xB, 0x392, 0xB, 0x3D5,
|
||||
0xA, 0x233, 0xA, 0x2CC, 0xB, 0x390, 0xA, 0x1BB, 0xB, 0x3A1, 0xB, 0x3C4, 0xA, 0x211, 0xA, 0x203,
|
||||
0x9, 0x12A, 0xA, 0x231, 0xB, 0x3E0, 0xA, 0x29B, 0xB, 0x3D7, 0xA, 0x202, 0xB, 0x3AD, 0xA, 0x213,
|
||||
0xA, 0x253, 0xA, 0x32C, 0xA, 0x23D, 0xA, 0x23F, 0xA, 0x32F, 0xA, 0x11C, 0xA, 0x384, 0xA, 0x31C,
|
||||
0xA, 0x17C, 0xA, 0x30A, 0xA, 0x2E0, 0xA, 0x276, 0xA, 0x250, 0xB, 0x3E3, 0xA, 0x396, 0xA, 0x18F,
|
||||
0xA, 0x204, 0xA, 0x206, 0xA, 0x230, 0xA, 0x265, 0xA, 0x212, 0xA, 0x23E, 0xB, 0x3AC, 0xB, 0x393,
|
||||
0xB, 0x3E1, 0xA, 0x1DE, 0xB, 0x3D6, 0xA, 0x31D, 0xB, 0x3E5, 0xB, 0x3E4, 0xA, 0x207, 0xB, 0x3C7,
|
||||
0xA, 0x277, 0xB, 0x3D4, 0x8, 0x0C0, 0xA, 0x162, 0xA, 0x3DA, 0xA, 0x124, 0xA, 0x1B4, 0xA, 0x264,
|
||||
0xA, 0x33D, 0xA, 0x1D1, 0xA, 0x1AF, 0xA, 0x39E, 0xA, 0x24F, 0xB, 0x373, 0xA, 0x249, 0xB, 0x372,
|
||||
0x9, 0x167, 0xA, 0x210, 0xA, 0x23A, 0xA, 0x1B8, 0xB, 0x3AF, 0xA, 0x18E, 0xA, 0x2EC, 0x7, 0x062,
|
||||
0x4, 0x00D
|
||||
};
|
||||
|
||||
private const int CountIndex = 0;
|
||||
private const int ValueIndex = 1;
|
||||
|
||||
// UO packets may not exceed 64kb in length
|
||||
private const int BufferSize = 0x10000;
|
||||
|
||||
// Optimal compression ratio is 2 / 8; worst compression ratio is 11 / 8
|
||||
private const int MinimalCodeLength = 2;
|
||||
private const int MaximalCodeLength = 11;
|
||||
|
||||
// Fixed overhead, in bits, per compression call
|
||||
private const int TerminalCodeLength = 4;
|
||||
|
||||
// If our input exceeds this length, we cannot possibly compress it within the buffer
|
||||
private const int DefiniteOverflow = ( ( BufferSize * 8 ) - TerminalCodeLength ) / MinimalCodeLength;
|
||||
|
||||
// If our input exceeds this length, we may potentially overflow the buffer
|
||||
private const int PossibleOverflow = ( ( BufferSize * 8 ) - TerminalCodeLength ) / MaximalCodeLength;
|
||||
|
||||
private static object _syncRoot = new object();
|
||||
|
||||
private static byte[] _outputBuffer = new byte[BufferSize];
|
||||
|
||||
[Obsolete( "Use Compress( byte[], int, int, ref int ) instead.", false )]
|
||||
public static void Compress( byte[] input, int length, out byte[] output, out int outputLength ) {
|
||||
outputLength = 0;
|
||||
output = Compress( input, 0, length, ref outputLength );
|
||||
}
|
||||
|
||||
public unsafe static byte[] Compress( byte[] input, int offset, int count, ref int length ) {
|
||||
if ( input == null ) {
|
||||
throw new ArgumentNullException( "input" );
|
||||
} else if ( offset < 0 || offset >= input.Length ) {
|
||||
throw new ArgumentOutOfRangeException( "offset" );
|
||||
} else if ( count < 0 || count > input.Length ) {
|
||||
throw new ArgumentOutOfRangeException( "count" );
|
||||
} else if ( ( input.Length - offset ) < count ) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
length = 0;
|
||||
|
||||
if ( count > DefiniteOverflow ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
lock ( _syncRoot ) {
|
||||
int bitCount = 0;
|
||||
int bitValue = 0;
|
||||
|
||||
fixed ( int* pTable = _huffmanTable ) {
|
||||
int* pEntry;
|
||||
|
||||
fixed ( byte* pInputBuffer = input ) {
|
||||
byte* pInput = pInputBuffer + offset, pInputEnd = pInput + count;
|
||||
|
||||
fixed ( byte* pOutputBuffer = _outputBuffer ) {
|
||||
byte* pOutput = pOutputBuffer, pOutputEnd = pOutput + BufferSize;
|
||||
|
||||
while ( pInput < pInputEnd ) {
|
||||
pEntry = &pTable[*pInput++ << 1];
|
||||
|
||||
bitCount += pEntry[CountIndex];
|
||||
|
||||
bitValue <<= pEntry[CountIndex];
|
||||
bitValue |= pEntry[ValueIndex];
|
||||
|
||||
while ( bitCount >= 8 ) {
|
||||
bitCount -= 8;
|
||||
|
||||
if ( pOutput < pOutputEnd ) {
|
||||
*pOutput++ = ( byte ) ( bitValue >> bitCount );
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// terminal code
|
||||
pEntry = &pTable[0x200];
|
||||
|
||||
bitCount += pEntry[CountIndex];
|
||||
|
||||
bitValue <<= pEntry[CountIndex];
|
||||
bitValue |= pEntry[ValueIndex];
|
||||
|
||||
// align on byte boundary
|
||||
if ( ( bitCount & 7 ) != 0 ) {
|
||||
bitValue <<= ( 8 - ( bitCount & 7 ) );
|
||||
bitCount += ( 8 - ( bitCount & 7 ) );
|
||||
}
|
||||
|
||||
while ( bitCount >= 8 ) {
|
||||
bitCount -= 8;
|
||||
|
||||
if ( pOutput < pOutputEnd ) {
|
||||
*pOutput++ = ( byte ) ( bitValue >> bitCount );
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
length = ( int ) ( pOutput - pOutputBuffer );
|
||||
return _outputBuffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly ICompressor Compressor;
|
||||
|
||||
static Compression() {
|
||||
if ( Core.Unix ) {
|
||||
if ( Core.Is64Bit ) {
|
||||
Compressor = new CompressorUnix64();
|
||||
} else {
|
||||
Compressor = new CompressorUnix32();
|
||||
}
|
||||
} else if ( Core.Is64Bit ) {
|
||||
Compressor = new Compressor64();
|
||||
} else {
|
||||
Compressor = new Compressor32();
|
||||
}
|
||||
}
|
||||
|
||||
public static ZLibError Pack( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return Compressor.Compress( dest, ref destLength, source, sourceLength );
|
||||
}
|
||||
|
||||
public static ZLibError Pack( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ) {
|
||||
return Compressor.Compress( dest, ref destLength, source, sourceLength, quality );
|
||||
}
|
||||
|
||||
public static ZLibError Unpack( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return Compressor.Decompress( dest, ref destLength, source, sourceLength );
|
||||
}
|
||||
}
|
||||
|
||||
public interface ICompressor {
|
||||
string Version {
|
||||
get;
|
||||
}
|
||||
|
||||
ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength );
|
||||
ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality );
|
||||
|
||||
ZLibError Decompress( byte[] dest, ref int destLength, byte[] source, int sourceLength );
|
||||
}
|
||||
|
||||
public sealed class Compressor32 : ICompressor {
|
||||
[DllImport( "zlib32" )]
|
||||
private static extern string zlibVersion();
|
||||
|
||||
[DllImport( "zlib32" )]
|
||||
private static extern ZLibError compress( byte[] dest, ref int destLength, byte[] source, int sourceLength );
|
||||
|
||||
[DllImport( "zlib32" )]
|
||||
private static extern ZLibError compress2( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality );
|
||||
|
||||
[DllImport( "zlib32" )]
|
||||
private static extern ZLibError uncompress( byte[] dest, ref int destLen, byte[] source, int sourceLen );
|
||||
|
||||
public Compressor32() {
|
||||
}
|
||||
|
||||
public string Version {
|
||||
get {
|
||||
return zlibVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return compress( dest, ref destLength, source, sourceLength );
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ) {
|
||||
return compress2( dest, ref destLength, source, sourceLength, quality );
|
||||
}
|
||||
|
||||
public ZLibError Decompress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return uncompress( dest, ref destLength, source, sourceLength );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Compressor64 : ICompressor {
|
||||
[DllImport( "zlib64" )]
|
||||
private static extern string zlibVersion();
|
||||
|
||||
[DllImport( "zlib64" )]
|
||||
private static extern ZLibError compress( byte[] dest, ref int destLength, byte[] source, int sourceLength );
|
||||
|
||||
[DllImport( "zlib64" )]
|
||||
private static extern ZLibError compress2( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality );
|
||||
|
||||
[DllImport( "zlib64" )]
|
||||
private static extern ZLibError uncompress( byte[] dest, ref int destLen, byte[] source, int sourceLen );
|
||||
|
||||
public Compressor64() {
|
||||
}
|
||||
|
||||
public string Version {
|
||||
get {
|
||||
return zlibVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return compress( dest, ref destLength, source, sourceLength );
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ) {
|
||||
return compress2( dest, ref destLength, source, sourceLength, quality );
|
||||
}
|
||||
|
||||
public ZLibError Decompress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return uncompress( dest, ref destLength, source, sourceLength );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CompressorUnix32 : ICompressor {
|
||||
[DllImport( "libz" )]
|
||||
private static extern string zlibVersion();
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError compress( byte[] dest, ref int destLength, byte[] source, int sourceLength );
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError compress2( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality );
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError uncompress( byte[] dest, ref int destLen, byte[] source, int sourceLen );
|
||||
|
||||
public CompressorUnix32() {
|
||||
}
|
||||
|
||||
public string Version {
|
||||
get {
|
||||
return zlibVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return compress( dest, ref destLength, source, sourceLength );
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ) {
|
||||
return compress2( dest, ref destLength, source, sourceLength, quality );
|
||||
}
|
||||
|
||||
public ZLibError Decompress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
return uncompress( dest, ref destLength, source, sourceLength );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CompressorUnix64 : ICompressor {
|
||||
[DllImport( "libz" )]
|
||||
private static extern string zlibVersion();
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError compress( byte[] dest, ref ulong destLength, byte[] source, int sourceLength );
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError compress2( byte[] dest, ref ulong destLength, byte[] source, int sourceLength, ZLibQuality quality );
|
||||
|
||||
[DllImport( "libz" )]
|
||||
private static extern ZLibError uncompress( byte[] dest, ref ulong destLen, byte[] source, int sourceLen );
|
||||
|
||||
public CompressorUnix64() {
|
||||
}
|
||||
|
||||
public string Version {
|
||||
get {
|
||||
return zlibVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
ulong destLengthLong = (ulong)destLength;
|
||||
ZLibError z = compress( dest, ref destLengthLong, source, sourceLength );
|
||||
destLength = (int)destLengthLong;
|
||||
return z;
|
||||
}
|
||||
|
||||
public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ) {
|
||||
ulong destLengthLong = (ulong)destLength;
|
||||
ZLibError z = compress2( dest, ref destLengthLong, source, sourceLength, quality );
|
||||
destLength = (int)destLengthLong;
|
||||
return z;
|
||||
}
|
||||
|
||||
public ZLibError Decompress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) {
|
||||
ulong destLengthLong = (ulong)destLength;
|
||||
ZLibError z = uncompress( dest, ref destLengthLong, source, sourceLength );
|
||||
destLength = (int)destLengthLong;
|
||||
return z;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ZLibError : int {
|
||||
VersionError = -6,
|
||||
BufferError = -5,
|
||||
MemoryError = -4,
|
||||
DataError = -3,
|
||||
StreamError = -2,
|
||||
FileError = -1,
|
||||
|
||||
Okay = 0,
|
||||
|
||||
StreamEnd = 1,
|
||||
NeedDictionary = 2
|
||||
}
|
||||
|
||||
public enum ZLibQuality : int {
|
||||
Default = -1,
|
||||
|
||||
None = 0,
|
||||
|
||||
Speed = 1,
|
||||
Size = 9
|
||||
}
|
||||
}
|
||||
64
Source/Network/EncodedPacketHandler.cs
Normal file
64
Source/Network/EncodedPacketHandler.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/***************************************************************************
|
||||
* EncodedPacketHandler.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public delegate void OnEncodedPacketReceive( NetState state, IEntity ent, EncodedReader pvSrc );
|
||||
|
||||
public class EncodedPacketHandler
|
||||
{
|
||||
private int m_PacketID;
|
||||
private bool m_Ingame;
|
||||
private OnEncodedPacketReceive m_OnReceive;
|
||||
|
||||
public EncodedPacketHandler( int packetID, bool ingame, OnEncodedPacketReceive onReceive )
|
||||
{
|
||||
m_PacketID = packetID;
|
||||
m_Ingame = ingame;
|
||||
m_OnReceive = onReceive;
|
||||
}
|
||||
|
||||
public int PacketID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_PacketID;
|
||||
}
|
||||
}
|
||||
|
||||
public OnEncodedPacketReceive OnReceive
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_OnReceive;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Ingame
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Ingame;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
85
Source/Network/EncodedReader.cs
Normal file
85
Source/Network/EncodedReader.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/***************************************************************************
|
||||
* EncodedReader.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public class EncodedReader
|
||||
{
|
||||
private PacketReader m_Reader;
|
||||
|
||||
public EncodedReader( PacketReader reader )
|
||||
{
|
||||
m_Reader = reader;
|
||||
}
|
||||
|
||||
public byte[] Buffer
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Reader.Buffer;
|
||||
}
|
||||
}
|
||||
|
||||
public void Trace( NetState state )
|
||||
{
|
||||
m_Reader.Trace( state );
|
||||
}
|
||||
|
||||
public int ReadInt32()
|
||||
{
|
||||
if ( m_Reader.ReadByte() != 0 )
|
||||
return 0;
|
||||
|
||||
return m_Reader.ReadInt32();
|
||||
}
|
||||
|
||||
public Point3D ReadPoint3D()
|
||||
{
|
||||
if ( m_Reader.ReadByte() != 3 )
|
||||
return Point3D.Zero;
|
||||
|
||||
return new Point3D( m_Reader.ReadInt16(), m_Reader.ReadInt16(), m_Reader.ReadByte() );
|
||||
}
|
||||
|
||||
public string ReadUnicodeStringSafe()
|
||||
{
|
||||
if ( m_Reader.ReadByte() != 2 )
|
||||
return "";
|
||||
|
||||
int length = m_Reader.ReadUInt16();
|
||||
|
||||
return m_Reader.ReadUnicodeStringSafe( length );
|
||||
}
|
||||
|
||||
public string ReadUnicodeString()
|
||||
{
|
||||
if ( m_Reader.ReadByte() != 2 )
|
||||
return "";
|
||||
|
||||
int length = m_Reader.ReadUInt16();
|
||||
|
||||
return m_Reader.ReadUnicodeString( length );
|
||||
}
|
||||
}
|
||||
}
|
||||
279
Source/Network/Listener.cs
Normal file
279
Source/Network/Listener.cs
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
/***************************************************************************
|
||||
* Listener.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using Server;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public class Listener : IDisposable
|
||||
{
|
||||
private Socket m_Listener;
|
||||
|
||||
private Queue<Socket> m_Accepted;
|
||||
private object m_AcceptedSyncRoot;
|
||||
|
||||
#if Framework_4_0
|
||||
private SocketAsyncEventArgs m_EventArgs;
|
||||
#else
|
||||
private AsyncCallback m_OnAccept;
|
||||
#endif
|
||||
|
||||
private static Socket[] m_EmptySockets = new Socket[0];
|
||||
|
||||
private static IPEndPoint[] m_EndPoints;
|
||||
|
||||
public static IPEndPoint[] EndPoints {
|
||||
get { return m_EndPoints; }
|
||||
set { m_EndPoints = value; }
|
||||
}
|
||||
|
||||
public Listener( IPEndPoint ipep )
|
||||
{
|
||||
m_Accepted = new Queue<Socket>();
|
||||
m_AcceptedSyncRoot = ((ICollection)m_Accepted).SyncRoot;
|
||||
|
||||
m_Listener = Bind( ipep );
|
||||
|
||||
if ( m_Listener == null )
|
||||
return;
|
||||
|
||||
DisplayListener();
|
||||
|
||||
#if Framework_4_0
|
||||
m_EventArgs = new SocketAsyncEventArgs();
|
||||
m_EventArgs.Completed += new EventHandler<SocketAsyncEventArgs>( Accept_Completion );
|
||||
Accept_Start();
|
||||
#else
|
||||
m_OnAccept = new AsyncCallback( OnAccept );
|
||||
try {
|
||||
IAsyncResult res = m_Listener.BeginAccept( m_OnAccept, m_Listener );
|
||||
} catch ( SocketException ex ) {
|
||||
NetState.TraceException( ex );
|
||||
} catch ( ObjectDisposedException ) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private Socket Bind( IPEndPoint ipep )
|
||||
{
|
||||
Socket s = new Socket( ipep.AddressFamily, SocketType.Stream, ProtocolType.Tcp );
|
||||
|
||||
try
|
||||
{
|
||||
s.LingerState.Enabled = false;
|
||||
#if !MONO
|
||||
s.ExclusiveAddressUse = false;
|
||||
#endif
|
||||
s.Bind( ipep );
|
||||
s.Listen( 8 );
|
||||
|
||||
return s;
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
if ( e is SocketException ) {
|
||||
SocketException se = (SocketException)e;
|
||||
|
||||
if ( se.ErrorCode == 10048 ) { // WSAEADDRINUSE
|
||||
Console.WriteLine( "Listener Failed: {0}:{1} (In Use)", ipep.Address, ipep.Port );
|
||||
}
|
||||
else if ( se.ErrorCode == 10049 ) { // WSAEADDRNOTAVAIL
|
||||
Console.WriteLine( "Listener Failed: {0}:{1} (Unavailable)", ipep.Address, ipep.Port );
|
||||
}
|
||||
else {
|
||||
Console.WriteLine( "Listener Exception:" );
|
||||
Console.WriteLine( e );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayListener()
|
||||
{
|
||||
IPEndPoint ipep = m_Listener.LocalEndPoint as IPEndPoint;
|
||||
|
||||
if ( ipep == null )
|
||||
return;
|
||||
|
||||
if ( ipep.Address.Equals( IPAddress.Any ) || ipep.Address.Equals( IPAddress.IPv6Any ) ) {
|
||||
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
|
||||
foreach ( NetworkInterface adapter in adapters ) {
|
||||
IPInterfaceProperties properties = adapter.GetIPProperties();
|
||||
foreach ( IPAddressInformation unicast in properties.UnicastAddresses ) {
|
||||
if ( ipep.AddressFamily == unicast.Address.AddressFamily )
|
||||
Console.WriteLine( "Listening: {0}:{1}", unicast.Address, ipep.Port );
|
||||
}
|
||||
}
|
||||
/*
|
||||
try {
|
||||
Console.WriteLine( "Listening: {0}:{1}", IPAddress.Loopback, ipep.Port );
|
||||
IPHostEntry iphe = Dns.GetHostEntry( Dns.GetHostName() );
|
||||
IPAddress[] ip = iphe.AddressList;
|
||||
for ( int i = 0; i < ip.Length; ++i )
|
||||
Console.WriteLine( "Listening: {0}:{1}", ip[i], ipep.Port );
|
||||
}
|
||||
catch { }
|
||||
*/
|
||||
}
|
||||
else {
|
||||
Console.WriteLine( "Listening: {0}:{1}", ipep.Address, ipep.Port );
|
||||
}
|
||||
}
|
||||
|
||||
#if Framework_4_0
|
||||
private void Accept_Start()
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
do {
|
||||
try {
|
||||
result = !m_Listener.AcceptAsync( m_EventArgs );
|
||||
} catch ( SocketException ex ) {
|
||||
NetState.TraceException( ex );
|
||||
break;
|
||||
} catch ( ObjectDisposedException ) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ( result )
|
||||
Accept_Process( m_EventArgs );
|
||||
} while ( result );
|
||||
}
|
||||
|
||||
private void Accept_Completion( object sender, SocketAsyncEventArgs e )
|
||||
{
|
||||
Accept_Process( e );
|
||||
|
||||
Accept_Start();
|
||||
}
|
||||
|
||||
private void Accept_Process( SocketAsyncEventArgs e )
|
||||
{
|
||||
if ( e.SocketError == SocketError.Success && VerifySocket( e.AcceptSocket ) ) {
|
||||
Enqueue( e.AcceptSocket );
|
||||
} else {
|
||||
Release( e.AcceptSocket );
|
||||
}
|
||||
|
||||
e.AcceptSocket = null;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
private void OnAccept( IAsyncResult asyncResult ) {
|
||||
Socket listener = (Socket) asyncResult.AsyncState;
|
||||
|
||||
Socket accepted = null;
|
||||
|
||||
try {
|
||||
accepted = listener.EndAccept( asyncResult );
|
||||
} catch ( SocketException ex ) {
|
||||
NetState.TraceException( ex );
|
||||
} catch ( ObjectDisposedException ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( accepted != null ) {
|
||||
if ( VerifySocket( accepted ) ) {
|
||||
Enqueue( accepted );
|
||||
} else {
|
||||
Release( accepted );
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
listener.BeginAccept( m_OnAccept, listener );
|
||||
} catch ( SocketException ex ) {
|
||||
NetState.TraceException( ex );
|
||||
} catch ( ObjectDisposedException ) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private bool VerifySocket( Socket socket ) {
|
||||
try {
|
||||
SocketConnectEventArgs args = new SocketConnectEventArgs( socket );
|
||||
|
||||
EventSink.InvokeSocketConnect( args );
|
||||
|
||||
return args.AllowConnection;
|
||||
} catch ( Exception ex ) {
|
||||
NetState.TraceException( ex );
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Enqueue( Socket socket ) {
|
||||
lock ( m_AcceptedSyncRoot ) {
|
||||
m_Accepted.Enqueue( socket );
|
||||
}
|
||||
|
||||
Core.Set();
|
||||
}
|
||||
|
||||
private void Release( Socket socket ) {
|
||||
try {
|
||||
socket.Shutdown( SocketShutdown.Both );
|
||||
} catch ( SocketException ex ) {
|
||||
NetState.TraceException( ex );
|
||||
}
|
||||
|
||||
try {
|
||||
socket.Close();
|
||||
} catch ( SocketException ex ) {
|
||||
NetState.TraceException( ex );
|
||||
}
|
||||
}
|
||||
|
||||
public Socket[] Slice()
|
||||
{
|
||||
Socket[] array;
|
||||
|
||||
lock ( m_AcceptedSyncRoot )
|
||||
{
|
||||
if ( m_Accepted.Count == 0 )
|
||||
return m_EmptySockets;
|
||||
|
||||
array = m_Accepted.ToArray();
|
||||
m_Accepted.Clear();
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Socket socket = Interlocked.Exchange<Socket>( ref m_Listener, null );
|
||||
|
||||
if ( socket != null ) {
|
||||
socket.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
282
Source/Network/MessagePump.cs
Normal file
282
Source/Network/MessagePump.cs
Normal file
|
|
@ -0,0 +1,282 @@
|
|||
/***************************************************************************
|
||||
* MessagePump.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using Server;
|
||||
using Server.Diagnostics;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public class MessagePump
|
||||
{
|
||||
private Listener[] m_Listeners;
|
||||
private Queue<NetState> m_Queue;
|
||||
private Queue<NetState> m_WorkingQueue;
|
||||
private Queue<NetState> m_Throttled;
|
||||
private byte[] m_Peek;
|
||||
|
||||
public MessagePump()
|
||||
{
|
||||
IPEndPoint[] ipep = Listener.EndPoints;
|
||||
|
||||
m_Listeners = new Listener[ipep.Length];
|
||||
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
for ( int i = 0; i < ipep.Length; i++ ) {
|
||||
Listener l = new Listener( ipep[i] );
|
||||
if ( !success && l != null )
|
||||
success = true;
|
||||
m_Listeners[i] = l;
|
||||
}
|
||||
|
||||
if ( !success ) {
|
||||
Console.WriteLine( "Retrying..." );
|
||||
Thread.Sleep( 10000 );
|
||||
}
|
||||
} while ( !success );
|
||||
|
||||
m_Queue = new Queue<NetState>();
|
||||
m_WorkingQueue = new Queue<NetState>();
|
||||
m_Throttled = new Queue<NetState>();
|
||||
m_Peek = new byte[4];
|
||||
}
|
||||
|
||||
public Listener[] Listeners
|
||||
{
|
||||
get{ return m_Listeners; }
|
||||
set{ m_Listeners = value; }
|
||||
}
|
||||
|
||||
public void AddListener( Listener l )
|
||||
{
|
||||
Listener[] old = m_Listeners;
|
||||
|
||||
m_Listeners = new Listener[old.Length + 1];
|
||||
|
||||
for ( int i = 0; i < old.Length; ++i )
|
||||
m_Listeners[i] = old[i];
|
||||
|
||||
m_Listeners[old.Length] = l;
|
||||
}
|
||||
|
||||
private void CheckListener()
|
||||
{
|
||||
for ( int j = 0; j < m_Listeners.Length; ++j )
|
||||
{
|
||||
Socket[] accepted = m_Listeners[j].Slice();
|
||||
|
||||
for ( int i = 0; i < accepted.Length; ++i )
|
||||
{
|
||||
NetState ns = new NetState( accepted[i], this );
|
||||
ns.Start();
|
||||
|
||||
if ( ns.Running )
|
||||
Console.WriteLine( "Client: {0}: Connected. [{1} Online]", ns, NetState.Instances.Count );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReceive( NetState ns )
|
||||
{
|
||||
lock ( this )
|
||||
m_Queue.Enqueue( ns );
|
||||
|
||||
Core.Set();
|
||||
}
|
||||
|
||||
public void Slice()
|
||||
{
|
||||
CheckListener();
|
||||
|
||||
lock ( this )
|
||||
{
|
||||
Queue<NetState> temp = m_WorkingQueue;
|
||||
m_WorkingQueue = m_Queue;
|
||||
m_Queue = temp;
|
||||
}
|
||||
|
||||
while ( m_WorkingQueue.Count > 0 )
|
||||
{
|
||||
NetState ns = m_WorkingQueue.Dequeue();
|
||||
|
||||
if ( ns.Running )
|
||||
HandleReceive( ns );
|
||||
}
|
||||
|
||||
lock ( this )
|
||||
{
|
||||
while ( m_Throttled.Count > 0 )
|
||||
m_Queue.Enqueue( m_Throttled.Dequeue() );
|
||||
}
|
||||
}
|
||||
|
||||
private const int BufferSize = 4096;
|
||||
private BufferPool m_Buffers = new BufferPool( "Processor", 4, BufferSize );
|
||||
|
||||
public bool HandleReceive( NetState ns )
|
||||
{
|
||||
ByteQueue buffer = ns.Buffer;
|
||||
|
||||
if ( buffer == null || buffer.Length <= 0 )
|
||||
return true;
|
||||
|
||||
lock ( buffer )
|
||||
{
|
||||
int length = buffer.Length;
|
||||
|
||||
if ( !ns.Seeded )
|
||||
{
|
||||
if ( buffer.GetPacketID() == 0xEF )
|
||||
{
|
||||
// new packet in client 6.0.5.0 replaces the traditional seed method with a seed packet
|
||||
// 0xEF = 239 = multicast IP, so this should never appear in a normal seed. So this is backwards compatible with older clients.
|
||||
ns.Seeded = true;
|
||||
}
|
||||
else if ( buffer.Length >= 4 )
|
||||
{
|
||||
buffer.Dequeue( m_Peek, 0, 4 );
|
||||
|
||||
int seed = (m_Peek[0] << 24) | (m_Peek[1] << 16) | (m_Peek[2] << 8) | m_Peek[3];
|
||||
|
||||
if ( seed == 0 )
|
||||
{
|
||||
Console.WriteLine( "Login: {0}: Invalid client detected, disconnecting", ns );
|
||||
ns.Dispose();
|
||||
return false;
|
||||
}
|
||||
|
||||
ns.m_Seed = seed;
|
||||
ns.Seeded = true;
|
||||
|
||||
length = buffer.Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
while ( length > 0 && ns.Running )
|
||||
{
|
||||
int packetID = buffer.GetPacketID();
|
||||
|
||||
PacketHandler handler = ns.GetHandler( packetID );
|
||||
|
||||
if ( handler == null )
|
||||
{
|
||||
byte[] data = new byte[length];
|
||||
length = buffer.Dequeue( data, 0, length );
|
||||
|
||||
new PacketReader( data, length, false ).Trace( ns );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
int packetLength = handler.Length;
|
||||
|
||||
if ( packetLength <= 0 )
|
||||
{
|
||||
if ( length >= 3 )
|
||||
{
|
||||
packetLength = buffer.GetPacketLength();
|
||||
|
||||
if ( packetLength < 3 )
|
||||
{
|
||||
ns.Dispose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( length >= packetLength )
|
||||
{
|
||||
if ( handler.Ingame && ns.Mobile == null )
|
||||
{
|
||||
Console.WriteLine( "Client: {0}: Sent ingame packet (0x{1:X2}) before having been attached to a mobile", ns, packetID );
|
||||
ns.Dispose();
|
||||
break;
|
||||
}
|
||||
else if ( handler.Ingame && ns.Mobile.Deleted )
|
||||
{
|
||||
ns.Dispose();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrottlePacketCallback throttler = handler.ThrottleCallback;
|
||||
|
||||
if ( throttler != null && !throttler( ns ) )
|
||||
{
|
||||
m_Throttled.Enqueue( ns );
|
||||
return false;
|
||||
}
|
||||
|
||||
PacketReceiveProfile prof = PacketReceiveProfile.Acquire( packetID );
|
||||
|
||||
if ( prof != null ) {
|
||||
prof.Start();
|
||||
}
|
||||
|
||||
byte[] packetBuffer;
|
||||
|
||||
if ( BufferSize >= packetLength )
|
||||
packetBuffer = m_Buffers.AcquireBuffer();
|
||||
else
|
||||
packetBuffer = new byte[packetLength];
|
||||
|
||||
packetLength = buffer.Dequeue( packetBuffer, 0, packetLength );
|
||||
|
||||
PacketReader r = new PacketReader( packetBuffer, packetLength, handler.Length != 0 );
|
||||
|
||||
handler.OnReceive( ns, r );
|
||||
length = buffer.Length;
|
||||
|
||||
if ( BufferSize >= packetLength )
|
||||
m_Buffers.ReleaseBuffer( packetBuffer );
|
||||
|
||||
if ( prof != null ) {
|
||||
prof.Finish( packetLength );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
1221
Source/Network/NetState.cs
Normal file
1221
Source/Network/NetState.cs
Normal file
File diff suppressed because it is too large
Load diff
82
Source/Network/PacketHandler.cs
Normal file
82
Source/Network/PacketHandler.cs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/***************************************************************************
|
||||
* PacketHandler.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public delegate void OnPacketReceive( NetState state, PacketReader pvSrc );
|
||||
public delegate bool ThrottlePacketCallback( NetState state );
|
||||
|
||||
public class PacketHandler
|
||||
{
|
||||
private int m_PacketID;
|
||||
private int m_Length;
|
||||
private bool m_Ingame;
|
||||
private OnPacketReceive m_OnReceive;
|
||||
private ThrottlePacketCallback m_ThrottleCallback;
|
||||
|
||||
public PacketHandler( int packetID, int length, bool ingame, OnPacketReceive onReceive )
|
||||
{
|
||||
m_PacketID = packetID;
|
||||
m_Length = length;
|
||||
m_Ingame = ingame;
|
||||
m_OnReceive = onReceive;
|
||||
}
|
||||
|
||||
public int PacketID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_PacketID;
|
||||
}
|
||||
}
|
||||
|
||||
public int Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Length;
|
||||
}
|
||||
}
|
||||
|
||||
public OnPacketReceive OnReceive
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_OnReceive;
|
||||
}
|
||||
}
|
||||
|
||||
public ThrottlePacketCallback ThrottleCallback
|
||||
{
|
||||
get{ return m_ThrottleCallback; }
|
||||
set{ m_ThrottleCallback = value; }
|
||||
}
|
||||
|
||||
public bool Ingame
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Ingame;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2464
Source/Network/PacketHandlers.cs
Normal file
2464
Source/Network/PacketHandlers.cs
Normal file
File diff suppressed because it is too large
Load diff
457
Source/Network/PacketReader.cs
Normal file
457
Source/Network/PacketReader.cs
Normal file
|
|
@ -0,0 +1,457 @@
|
|||
/***************************************************************************
|
||||
* PacketReader.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public class PacketReader
|
||||
{
|
||||
private byte[] m_Data;
|
||||
private int m_Size;
|
||||
private int m_Index;
|
||||
|
||||
public PacketReader( byte[] data, int size, bool fixedSize )
|
||||
{
|
||||
m_Data = data;
|
||||
m_Size = size;
|
||||
m_Index = fixedSize ? 1 : 3;
|
||||
}
|
||||
|
||||
public byte[] Buffer
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
}
|
||||
|
||||
public int Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Size;
|
||||
}
|
||||
}
|
||||
|
||||
public void Trace( NetState state )
|
||||
{
|
||||
try
|
||||
{
|
||||
using ( StreamWriter sw = new StreamWriter( "Packets.log", true ) )
|
||||
{
|
||||
byte[] buffer = m_Data;
|
||||
|
||||
if ( buffer.Length > 0 )
|
||||
sw.WriteLine( "Client: {0}: Unhandled packet 0x{1:X2}", state, buffer[0] );
|
||||
|
||||
using ( MemoryStream ms = new MemoryStream( buffer ) )
|
||||
Utility.FormatBuffer( sw, ms, buffer.Length );
|
||||
|
||||
sw.WriteLine();
|
||||
sw.WriteLine();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public int Seek( int offset, SeekOrigin origin )
|
||||
{
|
||||
switch ( origin )
|
||||
{
|
||||
case SeekOrigin.Begin: m_Index = offset; break;
|
||||
case SeekOrigin.Current: m_Index += offset; break;
|
||||
case SeekOrigin.End: m_Index = m_Size - offset; break;
|
||||
}
|
||||
|
||||
return m_Index;
|
||||
}
|
||||
|
||||
public int ReadInt32()
|
||||
{
|
||||
if ( (m_Index + 4) > m_Size )
|
||||
return 0;
|
||||
|
||||
return (m_Data[m_Index++] << 24)
|
||||
| (m_Data[m_Index++] << 16)
|
||||
| (m_Data[m_Index++] << 8)
|
||||
| m_Data[m_Index++];
|
||||
}
|
||||
|
||||
public short ReadInt16()
|
||||
{
|
||||
if ( (m_Index + 2) > m_Size )
|
||||
return 0;
|
||||
|
||||
return (short)((m_Data[m_Index++] << 8) | m_Data[m_Index++]);
|
||||
}
|
||||
|
||||
public byte ReadByte()
|
||||
{
|
||||
if ( (m_Index + 1) > m_Size )
|
||||
return 0;
|
||||
|
||||
return m_Data[m_Index++];
|
||||
}
|
||||
|
||||
public uint ReadUInt32()
|
||||
{
|
||||
if ( (m_Index + 4) > m_Size )
|
||||
return 0;
|
||||
|
||||
return (uint)((m_Data[m_Index++] << 24) | (m_Data[m_Index++] << 16) | (m_Data[m_Index++] << 8) | m_Data[m_Index++]);
|
||||
}
|
||||
|
||||
public ushort ReadUInt16()
|
||||
{
|
||||
if ( (m_Index + 2) > m_Size )
|
||||
return 0;
|
||||
|
||||
return (ushort)((m_Data[m_Index++] << 8) | m_Data[m_Index++]);
|
||||
}
|
||||
|
||||
public sbyte ReadSByte()
|
||||
{
|
||||
if ( (m_Index + 1) > m_Size )
|
||||
return 0;
|
||||
|
||||
return (sbyte)m_Data[m_Index++];
|
||||
}
|
||||
|
||||
public bool ReadBoolean()
|
||||
{
|
||||
if ( (m_Index + 1) > m_Size )
|
||||
return false;
|
||||
|
||||
return ( m_Data[m_Index++] != 0 );
|
||||
}
|
||||
|
||||
public string ReadUnicodeStringLE()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( (m_Index + 1) < m_Size && (c = (m_Data[m_Index++] | (m_Data[m_Index++] << 8))) != 0 )
|
||||
sb.Append( (char)c );
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadUnicodeStringLESafe( int fixedLength )
|
||||
{
|
||||
int bound = m_Index + (fixedLength << 1);
|
||||
int end = bound;
|
||||
|
||||
if ( bound > m_Size )
|
||||
bound = m_Size;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( (m_Index + 1) < bound && (c = (m_Data[m_Index++] | (m_Data[m_Index++] << 8))) != 0 )
|
||||
{
|
||||
if ( IsSafeChar( c ) )
|
||||
sb.Append( (char)c );
|
||||
}
|
||||
|
||||
m_Index = end;
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadUnicodeStringLESafe()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( (m_Index + 1) < m_Size && (c = (m_Data[m_Index++] | (m_Data[m_Index++] << 8))) != 0 )
|
||||
{
|
||||
if ( IsSafeChar( c ) )
|
||||
sb.Append( (char)c );
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadUnicodeStringSafe()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( (m_Index + 1) < m_Size && (c = ((m_Data[m_Index++] << 8) | m_Data[m_Index++])) != 0 )
|
||||
{
|
||||
if ( IsSafeChar( c ) )
|
||||
sb.Append( (char)c );
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadUnicodeString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( (m_Index + 1) < m_Size && (c = ((m_Data[m_Index++] << 8) | m_Data[m_Index++])) != 0 )
|
||||
sb.Append( (char)c );
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public bool IsSafeChar( int c )
|
||||
{
|
||||
return ( c >= 0x20 && c < 0xFFFE );
|
||||
}
|
||||
|
||||
public string ReadUTF8StringSafe( int fixedLength )
|
||||
{
|
||||
if ( m_Index >= m_Size )
|
||||
{
|
||||
m_Index += fixedLength;
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
int bound = m_Index + fixedLength;
|
||||
//int end = bound;
|
||||
|
||||
if ( bound > m_Size )
|
||||
bound = m_Size;
|
||||
|
||||
int count = 0;
|
||||
int index = m_Index;
|
||||
int start = m_Index;
|
||||
|
||||
while ( index < bound && m_Data[index++] != 0 )
|
||||
++count;
|
||||
|
||||
index = 0;
|
||||
|
||||
byte[] buffer = new byte[count];
|
||||
int value = 0;
|
||||
|
||||
while ( m_Index < bound && (value = m_Data[m_Index++]) != 0 )
|
||||
buffer[index++] = (byte)value;
|
||||
|
||||
string s = Utility.UTF8.GetString( buffer );
|
||||
|
||||
bool isSafe = true;
|
||||
|
||||
for ( int i = 0; isSafe && i < s.Length; ++i )
|
||||
isSafe = IsSafeChar( (int) s[i] );
|
||||
|
||||
m_Index = start + fixedLength;
|
||||
|
||||
if ( isSafe )
|
||||
return s;
|
||||
|
||||
StringBuilder sb = new StringBuilder( s.Length );
|
||||
|
||||
for ( int i = 0; i < s.Length; ++i )
|
||||
if ( IsSafeChar( (int) s[i] ) )
|
||||
sb.Append( s[i] );
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadUTF8StringSafe()
|
||||
{
|
||||
if ( m_Index >= m_Size )
|
||||
return String.Empty;
|
||||
|
||||
int count = 0;
|
||||
int index = m_Index;
|
||||
|
||||
while ( index < m_Size && m_Data[index++] != 0 )
|
||||
++count;
|
||||
|
||||
index = 0;
|
||||
|
||||
byte[] buffer = new byte[count];
|
||||
int value = 0;
|
||||
|
||||
while ( m_Index < m_Size && (value = m_Data[m_Index++]) != 0 )
|
||||
buffer[index++] = (byte)value;
|
||||
|
||||
string s = Utility.UTF8.GetString( buffer );
|
||||
|
||||
bool isSafe = true;
|
||||
|
||||
for ( int i = 0; isSafe && i < s.Length; ++i )
|
||||
isSafe = IsSafeChar( (int) s[i] );
|
||||
|
||||
if ( isSafe )
|
||||
return s;
|
||||
|
||||
StringBuilder sb = new StringBuilder( s.Length );
|
||||
|
||||
for ( int i = 0; i < s.Length; ++i )
|
||||
{
|
||||
if ( IsSafeChar( (int) s[i] ) )
|
||||
sb.Append( s[i] );
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadUTF8String()
|
||||
{
|
||||
if ( m_Index >= m_Size )
|
||||
return String.Empty;
|
||||
|
||||
int count = 0;
|
||||
int index = m_Index;
|
||||
|
||||
while ( index < m_Size && m_Data[index++] != 0 )
|
||||
++count;
|
||||
|
||||
index = 0;
|
||||
|
||||
byte[] buffer = new byte[count];
|
||||
int value = 0;
|
||||
|
||||
while ( m_Index < m_Size && (value = m_Data[m_Index++]) != 0 )
|
||||
buffer[index++] = (byte)value;
|
||||
|
||||
return Utility.UTF8.GetString( buffer );
|
||||
}
|
||||
|
||||
public string ReadString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( m_Index < m_Size && (c = m_Data[m_Index++]) != 0 )
|
||||
sb.Append( (char)c );
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadStringSafe()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( m_Index < m_Size && (c = m_Data[m_Index++]) != 0 )
|
||||
{
|
||||
if ( IsSafeChar( c ) )
|
||||
sb.Append( (char)c );
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadUnicodeStringSafe( int fixedLength )
|
||||
{
|
||||
int bound = m_Index + (fixedLength << 1);
|
||||
int end = bound;
|
||||
|
||||
if ( bound > m_Size )
|
||||
bound = m_Size;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( (m_Index + 1) < bound && (c = ((m_Data[m_Index++] << 8) | m_Data[m_Index++])) != 0 )
|
||||
{
|
||||
if ( IsSafeChar( c ) )
|
||||
sb.Append( (char)c );
|
||||
}
|
||||
|
||||
m_Index = end;
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadUnicodeString( int fixedLength )
|
||||
{
|
||||
int bound = m_Index + (fixedLength << 1);
|
||||
int end = bound;
|
||||
|
||||
if ( bound > m_Size )
|
||||
bound = m_Size;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( (m_Index + 1) < bound && (c = ((m_Data[m_Index++] << 8) | m_Data[m_Index++])) != 0 )
|
||||
sb.Append( (char)c );
|
||||
|
||||
m_Index = end;
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadStringSafe( int fixedLength )
|
||||
{
|
||||
int bound = m_Index + fixedLength;
|
||||
int end = bound;
|
||||
|
||||
if ( bound > m_Size )
|
||||
bound = m_Size;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( m_Index < bound && (c = m_Data[m_Index++]) != 0 )
|
||||
{
|
||||
if ( IsSafeChar( c ) )
|
||||
sb.Append( (char)c );
|
||||
}
|
||||
|
||||
m_Index = end;
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string ReadString( int fixedLength )
|
||||
{
|
||||
int bound = m_Index + fixedLength;
|
||||
int end = bound;
|
||||
|
||||
if ( bound > m_Size )
|
||||
bound = m_Size;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int c;
|
||||
|
||||
while ( m_Index < bound && (c = m_Data[m_Index++]) != 0 )
|
||||
sb.Append( (char)c );
|
||||
|
||||
m_Index = end;
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
470
Source/Network/PacketWriter.cs
Normal file
470
Source/Network/PacketWriter.cs
Normal file
|
|
@ -0,0 +1,470 @@
|
|||
/***************************************************************************
|
||||
* PacketWriter.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides functionality for writing primitive binary data.
|
||||
/// </summary>
|
||||
public class PacketWriter
|
||||
{
|
||||
private static Stack<PacketWriter> m_Pool = new Stack<PacketWriter>();
|
||||
|
||||
public static PacketWriter CreateInstance()
|
||||
{
|
||||
return CreateInstance( 32 );
|
||||
}
|
||||
|
||||
public static PacketWriter CreateInstance( int capacity )
|
||||
{
|
||||
PacketWriter pw = null;
|
||||
|
||||
lock ( m_Pool )
|
||||
{
|
||||
if ( m_Pool.Count > 0 )
|
||||
{
|
||||
pw = m_Pool.Pop();
|
||||
|
||||
if ( pw != null )
|
||||
{
|
||||
pw.m_Capacity = capacity;
|
||||
pw.m_Stream.SetLength( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( pw == null )
|
||||
pw = new PacketWriter( capacity );
|
||||
|
||||
return pw;
|
||||
}
|
||||
|
||||
public static void ReleaseInstance( PacketWriter pw )
|
||||
{
|
||||
lock ( m_Pool )
|
||||
{
|
||||
if ( !m_Pool.Contains( pw ) )
|
||||
{
|
||||
m_Pool.Push( pw );
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
using ( StreamWriter op = new StreamWriter( "neterr.log" ) )
|
||||
{
|
||||
op.WriteLine( "{0}\tInstance pool contains writer", DateTime.Now );
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine( "net error" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal stream which holds the entire packet.
|
||||
/// </summary>
|
||||
private MemoryStream m_Stream;
|
||||
|
||||
private int m_Capacity;
|
||||
|
||||
/// <summary>
|
||||
/// Internal format buffer.
|
||||
/// </summary>
|
||||
private static byte[] m_Buffer = new byte[4];
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new PacketWriter instance with the default capacity of 4 bytes.
|
||||
/// </summary>
|
||||
public PacketWriter() : this( 32 )
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new PacketWriter instance with a given capacity.
|
||||
/// </summary>
|
||||
/// <param name="capacity">Initial capacity for the internal stream.</param>
|
||||
public PacketWriter( int capacity )
|
||||
{
|
||||
m_Stream = new MemoryStream( capacity );
|
||||
m_Capacity = capacity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 1-byte boolean value to the underlying stream. False is represented by 0, true by 1.
|
||||
/// </summary>
|
||||
public void Write( bool value )
|
||||
{
|
||||
m_Stream.WriteByte( (byte)(value ? 1 : 0) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 1-byte unsigned integer value to the underlying stream.
|
||||
/// </summary>
|
||||
public void Write( byte value )
|
||||
{
|
||||
m_Stream.WriteByte( value );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 1-byte signed integer value to the underlying stream.
|
||||
/// </summary>
|
||||
public void Write( sbyte value )
|
||||
{
|
||||
m_Stream.WriteByte( (byte) value );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 2-byte signed integer value to the underlying stream.
|
||||
/// </summary>
|
||||
public void Write( short value )
|
||||
{
|
||||
m_Buffer[0] = (byte)(value >> 8);
|
||||
m_Buffer[1] = (byte) value;
|
||||
|
||||
m_Stream.Write( m_Buffer, 0, 2 );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 2-byte unsigned integer value to the underlying stream.
|
||||
/// </summary>
|
||||
public void Write( ushort value )
|
||||
{
|
||||
m_Buffer[0] = (byte)(value >> 8);
|
||||
m_Buffer[1] = (byte) value;
|
||||
|
||||
m_Stream.Write( m_Buffer, 0, 2 );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 4-byte signed integer value to the underlying stream.
|
||||
/// </summary>
|
||||
public void Write( int value )
|
||||
{
|
||||
m_Buffer[0] = (byte)(value >> 24);
|
||||
m_Buffer[1] = (byte)(value >> 16);
|
||||
m_Buffer[2] = (byte)(value >> 8);
|
||||
m_Buffer[3] = (byte) value;
|
||||
|
||||
m_Stream.Write( m_Buffer, 0, 4 );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 4-byte unsigned integer value to the underlying stream.
|
||||
/// </summary>
|
||||
public void Write( uint value )
|
||||
{
|
||||
m_Buffer[0] = (byte)(value >> 24);
|
||||
m_Buffer[1] = (byte)(value >> 16);
|
||||
m_Buffer[2] = (byte)(value >> 8);
|
||||
m_Buffer[3] = (byte) value;
|
||||
|
||||
m_Stream.Write( m_Buffer, 0, 4 );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a sequence of bytes to the underlying stream
|
||||
/// </summary>
|
||||
public void Write( byte[] buffer, int offset, int size )
|
||||
{
|
||||
m_Stream.Write( buffer, offset, size );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a fixed-length ASCII-encoded string value to the underlying stream. To fit (size), the string content is either truncated or padded with null characters.
|
||||
/// </summary>
|
||||
public void WriteAsciiFixed( string value, int size )
|
||||
{
|
||||
if ( value == null )
|
||||
{
|
||||
Console.WriteLine( "Network: Attempted to WriteAsciiFixed() with null value" );
|
||||
value = String.Empty;
|
||||
}
|
||||
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + size );
|
||||
|
||||
if ( length >= size )
|
||||
m_Stream.Position += Encoding.ASCII.GetBytes( value, 0, size, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
else
|
||||
{
|
||||
Encoding.ASCII.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += size;
|
||||
}
|
||||
|
||||
/*byte[] buffer = Encoding.ASCII.GetBytes( value );
|
||||
|
||||
if ( buffer.Length >= size )
|
||||
{
|
||||
m_Stream.Write( buffer, 0, size );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
Fill( size - buffer.Length );
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a dynamic-length ASCII-encoded string value to the underlying stream, followed by a 1-byte null character.
|
||||
/// </summary>
|
||||
public void WriteAsciiNull( string value )
|
||||
{
|
||||
if ( value == null )
|
||||
{
|
||||
Console.WriteLine( "Network: Attempted to WriteAsciiNull() with null value" );
|
||||
value = String.Empty;
|
||||
}
|
||||
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + length + 1 );
|
||||
|
||||
Encoding.ASCII.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += length + 1;
|
||||
|
||||
/*byte[] buffer = Encoding.ASCII.GetBytes( value );
|
||||
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
m_Stream.WriteByte( 0 );*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a dynamic-length little-endian unicode string value to the underlying stream, followed by a 2-byte null character.
|
||||
/// </summary>
|
||||
public void WriteLittleUniNull( string value )
|
||||
{
|
||||
if ( value == null )
|
||||
{
|
||||
Console.WriteLine( "Network: Attempted to WriteLittleUniNull() with null value" );
|
||||
value = String.Empty;
|
||||
}
|
||||
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + ( ( length + 1 ) * 2 ) );
|
||||
|
||||
m_Stream.Position += Encoding.Unicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += 2;
|
||||
|
||||
/*byte[] buffer = Encoding.Unicode.GetBytes( value );
|
||||
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
|
||||
m_Buffer[0] = 0;
|
||||
m_Buffer[1] = 0;
|
||||
m_Stream.Write( m_Buffer, 0, 2 );*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a fixed-length little-endian unicode string value to the underlying stream. To fit (size), the string content is either truncated or padded with null characters.
|
||||
/// </summary>
|
||||
public void WriteLittleUniFixed( string value, int size )
|
||||
{
|
||||
if ( value == null )
|
||||
{
|
||||
Console.WriteLine( "Network: Attempted to WriteLittleUniFixed() with null value" );
|
||||
value = String.Empty;
|
||||
}
|
||||
|
||||
size *= 2;
|
||||
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + size );
|
||||
|
||||
if ( ( length * 2 ) >= size )
|
||||
m_Stream.Position += Encoding.Unicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
else
|
||||
{
|
||||
Encoding.Unicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += size;
|
||||
}
|
||||
|
||||
/*size *= 2;
|
||||
|
||||
byte[] buffer = Encoding.Unicode.GetBytes( value );
|
||||
|
||||
if ( buffer.Length >= size )
|
||||
{
|
||||
m_Stream.Write( buffer, 0, size );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
Fill( size - buffer.Length );
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a dynamic-length big-endian unicode string value to the underlying stream, followed by a 2-byte null character.
|
||||
/// </summary>
|
||||
public void WriteBigUniNull( string value )
|
||||
{
|
||||
if ( value == null )
|
||||
{
|
||||
Console.WriteLine( "Network: Attempted to WriteBigUniNull() with null value" );
|
||||
value = String.Empty;
|
||||
}
|
||||
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + ( ( length + 1 ) * 2 ) );
|
||||
|
||||
m_Stream.Position += Encoding.BigEndianUnicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += 2;
|
||||
|
||||
/*byte[] buffer = Encoding.BigEndianUnicode.GetBytes( value );
|
||||
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
|
||||
m_Buffer[0] = 0;
|
||||
m_Buffer[1] = 0;
|
||||
m_Stream.Write( m_Buffer, 0, 2 );*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a fixed-length big-endian unicode string value to the underlying stream. To fit (size), the string content is either truncated or padded with null characters.
|
||||
/// </summary>
|
||||
public void WriteBigUniFixed( string value, int size )
|
||||
{
|
||||
if ( value == null )
|
||||
{
|
||||
Console.WriteLine( "Network: Attempted to WriteBigUniFixed() with null value" );
|
||||
value = String.Empty;
|
||||
}
|
||||
|
||||
size *= 2;
|
||||
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + size );
|
||||
|
||||
if ( ( length * 2 ) >= size )
|
||||
m_Stream.Position += Encoding.BigEndianUnicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
else
|
||||
{
|
||||
Encoding.BigEndianUnicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += size;
|
||||
}
|
||||
|
||||
/*size *= 2;
|
||||
|
||||
byte[] buffer = Encoding.BigEndianUnicode.GetBytes( value );
|
||||
|
||||
if ( buffer.Length >= size )
|
||||
{
|
||||
m_Stream.Write( buffer, 0, size );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
Fill( size - buffer.Length );
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills the stream from the current position up to (capacity) with 0x00's
|
||||
/// </summary>
|
||||
public void Fill()
|
||||
{
|
||||
Fill( (int) (m_Capacity - m_Stream.Length) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a number of 0x00 byte values to the underlying stream.
|
||||
/// </summary>
|
||||
public void Fill( int length )
|
||||
{
|
||||
if ( m_Stream.Position == m_Stream.Length )
|
||||
{
|
||||
m_Stream.SetLength( m_Stream.Length + length );
|
||||
m_Stream.Seek( 0, SeekOrigin.End );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Stream.Write( new byte[length], 0, length );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total stream length.
|
||||
/// </summary>
|
||||
public long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Stream.Length;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current stream position.
|
||||
/// </summary>
|
||||
public long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Stream.Position;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Stream.Position = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The internal stream used by this PacketWriter instance.
|
||||
/// </summary>
|
||||
public MemoryStream UnderlyingStream
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Stream;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Offsets the current position from an origin.
|
||||
/// </summary>
|
||||
public long Seek( long offset, SeekOrigin origin )
|
||||
{
|
||||
return m_Stream.Seek( offset, origin );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entire stream content as a byte array.
|
||||
/// </summary>
|
||||
public byte[] ToArray()
|
||||
{
|
||||
return m_Stream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
4284
Source/Network/Packets.cs
Normal file
4284
Source/Network/Packets.cs
Normal file
File diff suppressed because it is too large
Load diff
237
Source/Network/SendQueue.cs
Normal file
237
Source/Network/SendQueue.cs
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
/***************************************************************************
|
||||
* SendQueue.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Network {
|
||||
public class SendQueue {
|
||||
public class Gram {
|
||||
private static Stack<Gram> _pool = new Stack<Gram>();
|
||||
|
||||
public static Gram Acquire() {
|
||||
lock ( _pool ) {
|
||||
Gram gram;
|
||||
|
||||
if ( _pool.Count > 0 ) {
|
||||
gram = _pool.Pop();
|
||||
} else {
|
||||
gram = new Gram();
|
||||
}
|
||||
|
||||
gram._buffer = AcquireBuffer();
|
||||
gram._length = 0;
|
||||
|
||||
return gram;
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] _buffer;
|
||||
private int _length;
|
||||
|
||||
public byte[] Buffer {
|
||||
get {
|
||||
return _buffer;
|
||||
}
|
||||
}
|
||||
|
||||
public int Length {
|
||||
get {
|
||||
return _length;
|
||||
}
|
||||
}
|
||||
|
||||
public int Available {
|
||||
get {
|
||||
return ( _buffer.Length - _length );
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFull {
|
||||
get {
|
||||
return ( _length == _buffer.Length );
|
||||
}
|
||||
}
|
||||
|
||||
private Gram() {
|
||||
}
|
||||
|
||||
public int Write( byte[] buffer, int offset, int length ) {
|
||||
int write = Math.Min( length, this.Available );
|
||||
|
||||
System.Buffer.BlockCopy( buffer, offset, _buffer, _length, write );
|
||||
|
||||
_length += write;
|
||||
|
||||
return write;
|
||||
}
|
||||
|
||||
public void Release() {
|
||||
lock ( _pool ) {
|
||||
_pool.Push( this );
|
||||
ReleaseBuffer( _buffer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int m_CoalesceBufferSize = 512;
|
||||
private static BufferPool m_UnusedBuffers = new BufferPool( "Coalesced", 2048, m_CoalesceBufferSize );
|
||||
|
||||
public static int CoalesceBufferSize {
|
||||
get {
|
||||
return m_CoalesceBufferSize;
|
||||
}
|
||||
set {
|
||||
if ( m_CoalesceBufferSize == value )
|
||||
return;
|
||||
|
||||
if ( m_UnusedBuffers != null )
|
||||
m_UnusedBuffers.Free();
|
||||
|
||||
m_CoalesceBufferSize = value;
|
||||
m_UnusedBuffers = new BufferPool( "Coalesced", 2048, m_CoalesceBufferSize );
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] AcquireBuffer() {
|
||||
return m_UnusedBuffers.AcquireBuffer();
|
||||
}
|
||||
|
||||
public static void ReleaseBuffer( byte[] buffer ) {
|
||||
if ( buffer != null && buffer.Length == m_CoalesceBufferSize ) {
|
||||
m_UnusedBuffers.ReleaseBuffer( buffer );
|
||||
}
|
||||
}
|
||||
|
||||
private Queue<Gram> _pending;
|
||||
|
||||
private Gram _buffered;
|
||||
|
||||
public bool IsFlushReady {
|
||||
get {
|
||||
return ( _pending.Count == 0 && _buffered != null );
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEmpty {
|
||||
get {
|
||||
return ( _pending.Count == 0 && _buffered == null );
|
||||
}
|
||||
}
|
||||
|
||||
public SendQueue() {
|
||||
_pending = new Queue<Gram>();
|
||||
}
|
||||
|
||||
public Gram CheckFlushReady() {
|
||||
Gram gram = null;
|
||||
|
||||
if ( _pending.Count == 0 && _buffered != null ) {
|
||||
gram = _buffered;
|
||||
|
||||
_pending.Enqueue( _buffered );
|
||||
_buffered = null;
|
||||
}
|
||||
|
||||
return gram;
|
||||
}
|
||||
|
||||
public Gram Dequeue() {
|
||||
Gram gram = null;
|
||||
|
||||
if ( _pending.Count > 0 ) {
|
||||
_pending.Dequeue().Release();
|
||||
|
||||
if ( _pending.Count > 0 ) {
|
||||
gram = _pending.Peek();
|
||||
}
|
||||
}
|
||||
|
||||
return gram;
|
||||
}
|
||||
|
||||
private const int PendingCap = 96 * 1024;
|
||||
|
||||
public Gram Enqueue( byte[] buffer, int length ) {
|
||||
return Enqueue( buffer, 0, length );
|
||||
}
|
||||
|
||||
public Gram Enqueue( byte[] buffer, int offset, int length ) {
|
||||
if ( buffer == null ) {
|
||||
throw new ArgumentNullException( "buffer" );
|
||||
} else if ( !(offset >= 0 && offset < buffer.Length) ) {
|
||||
throw new ArgumentOutOfRangeException( "offset", offset, "Offset must be greater than or equal to zero and less than the size of the buffer." );
|
||||
} else if ( length < 0 || length > buffer.Length ) {
|
||||
throw new ArgumentOutOfRangeException( "length", length, "Length cannot be less than zero or greater than the size of the buffer." );
|
||||
} else if ( ( buffer.Length - offset ) < length ) {
|
||||
throw new ArgumentException( "Offset and length do not point to a valid segment within the buffer." );
|
||||
}
|
||||
|
||||
int existingBytes = ( _pending.Count * m_CoalesceBufferSize ) + ( _buffered == null ? 0 : _buffered.Length );
|
||||
|
||||
if ( ( existingBytes + length ) > PendingCap ) {
|
||||
throw new CapacityExceededException();
|
||||
}
|
||||
|
||||
Gram gram = null;
|
||||
|
||||
while ( length > 0 ) {
|
||||
if ( _buffered == null ) { // nothing yet buffered
|
||||
_buffered = Gram.Acquire();
|
||||
}
|
||||
|
||||
int bytesWritten = _buffered.Write( buffer, offset, length );
|
||||
|
||||
offset += bytesWritten;
|
||||
length -= bytesWritten;
|
||||
|
||||
if ( _buffered.IsFull ) {
|
||||
if ( _pending.Count == 0 ) {
|
||||
gram = _buffered;
|
||||
}
|
||||
|
||||
_pending.Enqueue( _buffered );
|
||||
_buffered = null;
|
||||
}
|
||||
}
|
||||
|
||||
return gram;
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
if ( _buffered != null ) {
|
||||
_buffered.Release();
|
||||
_buffered = null;
|
||||
}
|
||||
|
||||
while ( _pending.Count > 0 ) {
|
||||
_pending.Dequeue().Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CapacityExceededException : Exception {
|
||||
public CapacityExceededException()
|
||||
: base( "Too much data pending." ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
80
Source/Notoriety.cs
Normal file
80
Source/Notoriety.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/***************************************************************************
|
||||
* Notoriety.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Server;
|
||||
using Server.Guilds;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public delegate int NotorietyHandler( Mobile source, Mobile target );
|
||||
|
||||
public static class Notoriety
|
||||
{
|
||||
public const int Innocent = 1;
|
||||
public const int Ally = 2;
|
||||
public const int CanBeAttacked = 3;
|
||||
public const int Criminal = 4;
|
||||
public const int Enemy = 5;
|
||||
public const int Murderer = 6;
|
||||
public const int Invulnerable = 7;
|
||||
|
||||
private static NotorietyHandler m_Handler;
|
||||
|
||||
public static NotorietyHandler Handler
|
||||
{
|
||||
get{ return m_Handler; }
|
||||
set{ m_Handler = value; }
|
||||
}
|
||||
|
||||
private static int[] m_Hues = new int[]
|
||||
{
|
||||
0x000,
|
||||
0x059,
|
||||
0x03F,
|
||||
0x3B2,
|
||||
0x3B2,
|
||||
0x090,
|
||||
0x022,
|
||||
0x035
|
||||
};
|
||||
|
||||
public static int[] Hues
|
||||
{
|
||||
get{ return m_Hues; }
|
||||
set{ m_Hues = value; }
|
||||
}
|
||||
|
||||
public static int GetHue( int noto )
|
||||
{
|
||||
if ( noto < 0 || noto >= m_Hues.Length )
|
||||
return 0;
|
||||
|
||||
return m_Hues[noto];
|
||||
}
|
||||
|
||||
public static int Compute( Mobile source, Mobile target )
|
||||
{
|
||||
return m_Handler == null ? CanBeAttacked : m_Handler( source, target );
|
||||
}
|
||||
}
|
||||
}
|
||||
198
Source/ObjectPropertyList.cs
Normal file
198
Source/ObjectPropertyList.cs
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
/***************************************************************************
|
||||
* ObjectPropertyList.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using Server;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public sealed class ObjectPropertyList : Packet
|
||||
{
|
||||
private IEntity m_Entity;
|
||||
private int m_Hash;
|
||||
private int m_Header;
|
||||
private int m_Strings;
|
||||
private string m_HeaderArgs;
|
||||
|
||||
public IEntity Entity{ get{ return m_Entity; } }
|
||||
public int Hash{ get{ return 0x40000000 + m_Hash; } }
|
||||
|
||||
public int Header{ get{ return m_Header; } set{ m_Header = value; } }
|
||||
public string HeaderArgs{ get{ return m_HeaderArgs; } set{ m_HeaderArgs = value; } }
|
||||
|
||||
private static bool m_Enabled = false;
|
||||
|
||||
public static bool Enabled{ get{ return m_Enabled; } set{ m_Enabled = value; } }
|
||||
|
||||
public ObjectPropertyList( IEntity e ) : base( 0xD6 )
|
||||
{
|
||||
EnsureCapacity( 128 );
|
||||
|
||||
m_Entity = e;
|
||||
|
||||
m_Stream.Write( (short) 1 );
|
||||
m_Stream.Write( (int) e.Serial );
|
||||
m_Stream.Write( (byte) 0 );
|
||||
m_Stream.Write( (byte) 0 );
|
||||
m_Stream.Write( (int) e.Serial );
|
||||
}
|
||||
|
||||
public void Add( int number )
|
||||
{
|
||||
if ( number == 0 )
|
||||
return;
|
||||
|
||||
AddHash( number );
|
||||
|
||||
if ( m_Header == 0 )
|
||||
{
|
||||
m_Header = number;
|
||||
m_HeaderArgs = "";
|
||||
}
|
||||
|
||||
m_Stream.Write( number );
|
||||
m_Stream.Write( (short) 0 );
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
m_Stream.Write( (int) 0 );
|
||||
|
||||
m_Stream.Seek( 11, System.IO.SeekOrigin.Begin );
|
||||
m_Stream.Write( (int) m_Hash );
|
||||
}
|
||||
|
||||
private static byte[] m_Buffer = new byte[1024];
|
||||
private static Encoding m_Encoding = Encoding.Unicode;
|
||||
|
||||
public void AddHash( int val )
|
||||
{
|
||||
m_Hash ^= (val & 0x3FFFFFF);
|
||||
m_Hash ^= (val >> 26) & 0x3F;
|
||||
}
|
||||
|
||||
public void Add( int number, string arguments )
|
||||
{
|
||||
if ( number == 0 )
|
||||
return;
|
||||
|
||||
if ( arguments == null )
|
||||
arguments = "";
|
||||
|
||||
if ( m_Header == 0 )
|
||||
{
|
||||
m_Header = number;
|
||||
m_HeaderArgs = arguments;
|
||||
}
|
||||
|
||||
AddHash( number );
|
||||
AddHash( arguments.GetHashCode() );
|
||||
|
||||
m_Stream.Write( number );
|
||||
|
||||
int byteCount = m_Encoding.GetByteCount( arguments );
|
||||
|
||||
if ( byteCount > m_Buffer.Length )
|
||||
m_Buffer = new byte[byteCount];
|
||||
|
||||
byteCount = m_Encoding.GetBytes( arguments, 0, arguments.Length, m_Buffer, 0 );
|
||||
|
||||
m_Stream.Write( (short) byteCount );
|
||||
m_Stream.Write( m_Buffer, 0, byteCount );
|
||||
}
|
||||
|
||||
public void Add( int number, string format, object arg0 )
|
||||
{
|
||||
Add( number, String.Format( format, arg0 ) );
|
||||
}
|
||||
|
||||
public void Add( int number, string format, object arg0, object arg1 )
|
||||
{
|
||||
Add( number, String.Format( format, arg0, arg1 ) );
|
||||
}
|
||||
|
||||
public void Add( int number, string format, object arg0, object arg1, object arg2 )
|
||||
{
|
||||
Add( number, String.Format( format, arg0, arg1, arg2 ) );
|
||||
}
|
||||
|
||||
public void Add( int number, string format, params object[] args )
|
||||
{
|
||||
Add( number, String.Format( format, args ) );
|
||||
}
|
||||
|
||||
// Each of these are localized to "~1_NOTHING~" which allows the string argument to be used
|
||||
private static int[] m_StringNumbers = new int[]
|
||||
{
|
||||
1042971,
|
||||
1070722
|
||||
};
|
||||
|
||||
private int GetStringNumber()
|
||||
{
|
||||
return m_StringNumbers[m_Strings++ % m_StringNumbers.Length];
|
||||
}
|
||||
|
||||
public void Add( string text )
|
||||
{
|
||||
Add( GetStringNumber(), text );
|
||||
}
|
||||
|
||||
public void Add( string format, string arg0 )
|
||||
{
|
||||
Add( GetStringNumber(), String.Format( format, arg0 ) );
|
||||
}
|
||||
|
||||
public void Add( string format, string arg0, string arg1 )
|
||||
{
|
||||
Add( GetStringNumber(), String.Format( format, arg0, arg1 ) );
|
||||
}
|
||||
|
||||
public void Add( string format, string arg0, string arg1, string arg2 )
|
||||
{
|
||||
Add( GetStringNumber(), String.Format( format, arg0, arg1, arg2 ) );
|
||||
}
|
||||
|
||||
public void Add( string format, params object[] args )
|
||||
{
|
||||
Add( GetStringNumber(), String.Format( format, args ) );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OPLInfo : Packet
|
||||
{
|
||||
/*public OPLInfo( ObjectPropertyList list ) : base( 0xBF )
|
||||
{
|
||||
EnsureCapacity( 13 );
|
||||
|
||||
m_Stream.Write( (short) 0x10 );
|
||||
m_Stream.Write( (int) list.Entity.Serial );
|
||||
m_Stream.Write( (int) list.Hash );
|
||||
}*/
|
||||
|
||||
public OPLInfo( ObjectPropertyList list ) : base( 0xDC, 9 )
|
||||
{
|
||||
m_Stream.Write( (int) list.Entity.Serial );
|
||||
m_Stream.Write( (int) list.Hash );
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Source/Party.cs
Normal file
39
Source/Party.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/***************************************************************************
|
||||
* Party.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public abstract class PartyCommands
|
||||
{
|
||||
private static PartyCommands m_Handler;
|
||||
|
||||
public static PartyCommands Handler{ get{ return m_Handler; } set{ m_Handler = value; } }
|
||||
|
||||
public abstract void OnAdd( Mobile from );
|
||||
public abstract void OnRemove( Mobile from, Mobile target );
|
||||
public abstract void OnPrivateMessage( Mobile from, Mobile target, string text );
|
||||
public abstract void OnPublicMessage( Mobile from, string text );
|
||||
public abstract void OnSetCanLoot( Mobile from, bool canLoot );
|
||||
public abstract void OnAccept( Mobile from, Mobile leader );
|
||||
public abstract void OnDecline( Mobile from, Mobile leader );
|
||||
}
|
||||
}
|
||||
86
Source/Persistence/BinaryMemoryWriter.cs
Normal file
86
Source/Persistence/BinaryMemoryWriter.cs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/***************************************************************************
|
||||
* BinaryMemoryWriter.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Server {
|
||||
public sealed class BinaryMemoryWriter : BinaryFileWriter {
|
||||
private MemoryStream stream;
|
||||
|
||||
protected override int BufferSize {
|
||||
get { return 512; }
|
||||
}
|
||||
|
||||
public BinaryMemoryWriter()
|
||||
: base( new MemoryStream( 512 ), true ) {
|
||||
this.stream = this.UnderlyingStream as MemoryStream;
|
||||
}
|
||||
|
||||
private static byte[] indexBuffer;
|
||||
|
||||
public int CommitTo( SequentialFileWriter dataFile, SequentialFileWriter indexFile, int typeCode, int serial ) {
|
||||
Flush();
|
||||
|
||||
byte[] buffer = stream.GetBuffer();
|
||||
int length = ( int ) stream.Length;
|
||||
|
||||
long position = dataFile.Position;
|
||||
|
||||
dataFile.Write( buffer, 0, length );
|
||||
|
||||
if ( indexBuffer == null ) {
|
||||
indexBuffer = new byte[20];
|
||||
}
|
||||
|
||||
indexBuffer[0] = ( byte ) ( typeCode );
|
||||
indexBuffer[1] = ( byte ) ( typeCode >> 8 );
|
||||
indexBuffer[2] = ( byte ) ( typeCode >> 16 );
|
||||
indexBuffer[3] = ( byte ) ( typeCode >> 24 );
|
||||
|
||||
indexBuffer[4] = ( byte ) ( serial );
|
||||
indexBuffer[5] = ( byte ) ( serial >> 8 );
|
||||
indexBuffer[6] = ( byte ) ( serial >> 16 );
|
||||
indexBuffer[7] = ( byte ) ( serial >> 24 );
|
||||
|
||||
indexBuffer[8] = ( byte ) ( position );
|
||||
indexBuffer[9] = ( byte ) ( position >> 8 );
|
||||
indexBuffer[10] = ( byte ) ( position >> 16 );
|
||||
indexBuffer[11] = ( byte ) ( position >> 24 );
|
||||
indexBuffer[12] = ( byte ) ( position >> 32 );
|
||||
indexBuffer[13] = ( byte ) ( position >> 40 );
|
||||
indexBuffer[14] = ( byte ) ( position >> 48 );
|
||||
indexBuffer[15] = ( byte ) ( position >> 56 );
|
||||
|
||||
indexBuffer[16] = ( byte ) ( length );
|
||||
indexBuffer[17] = ( byte ) ( length >> 8 );
|
||||
indexBuffer[18] = ( byte ) ( length >> 16 );
|
||||
indexBuffer[19] = ( byte ) ( length >> 24 );
|
||||
|
||||
indexFile.Write( indexBuffer, 0, indexBuffer.Length );
|
||||
|
||||
stream.SetLength( 0 );
|
||||
|
||||
return length;
|
||||
}
|
||||
}
|
||||
}
|
||||
60
Source/Persistence/DualSaveStrategy.cs
Normal file
60
Source/Persistence/DualSaveStrategy.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/***************************************************************************
|
||||
* DualSaveStrategy.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Server;
|
||||
using Server.Guilds;
|
||||
|
||||
namespace Server {
|
||||
public sealed class DualSaveStrategy : StandardSaveStrategy {
|
||||
public override string Name {
|
||||
get { return "Dual"; }
|
||||
}
|
||||
|
||||
public DualSaveStrategy() {
|
||||
}
|
||||
|
||||
public override void Save( SaveMetrics metrics, bool permitBackgroundWrite )
|
||||
{
|
||||
this.PermitBackgroundWrite = permitBackgroundWrite;
|
||||
|
||||
Thread saveThread = new Thread( delegate() {
|
||||
SaveItems(metrics);
|
||||
} );
|
||||
|
||||
saveThread.Name = "Item Save Subset";
|
||||
saveThread.Start();
|
||||
|
||||
SaveMobiles(metrics);
|
||||
SaveGuilds(metrics);
|
||||
|
||||
saveThread.Join();
|
||||
|
||||
if (permitBackgroundWrite && UseSequentialWriters) //If we're permitted to write in the background, but we don't anyways, then notify.
|
||||
World.NotifyDiskWriteComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
314
Source/Persistence/DynamicSaveStrategy.cs
Normal file
314
Source/Persistence/DynamicSaveStrategy.cs
Normal file
|
|
@ -0,0 +1,314 @@
|
|||
/***************************************************************************
|
||||
* DynamicSaveStrategy.cs
|
||||
* -------------------
|
||||
* begin : December 16, 2010
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#if Framework_4_0
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
using Server.Guilds;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public sealed class DynamicSaveStrategy : SaveStrategy
|
||||
{
|
||||
public override string Name { get { return "Dynamic"; } }
|
||||
|
||||
private SaveMetrics _metrics;
|
||||
|
||||
private SequentialFileWriter _itemData, _itemIndex;
|
||||
private SequentialFileWriter _mobileData, _mobileIndex;
|
||||
private SequentialFileWriter _guildData, _guildIndex;
|
||||
|
||||
private ConcurrentBag<Item> _decayBag;
|
||||
|
||||
private BlockingCollection<QueuedMemoryWriter> _itemThreadWriters;
|
||||
private BlockingCollection<QueuedMemoryWriter> _mobileThreadWriters;
|
||||
private BlockingCollection<QueuedMemoryWriter> _guildThreadWriters;
|
||||
|
||||
public DynamicSaveStrategy()
|
||||
{
|
||||
_decayBag = new ConcurrentBag<Item>();
|
||||
_itemThreadWriters = new BlockingCollection<QueuedMemoryWriter>();
|
||||
_mobileThreadWriters = new BlockingCollection<QueuedMemoryWriter>();
|
||||
_guildThreadWriters = new BlockingCollection<QueuedMemoryWriter>();
|
||||
}
|
||||
|
||||
public override void Save(SaveMetrics metrics, bool permitBackgroundWrite)
|
||||
{
|
||||
this._metrics = metrics;
|
||||
|
||||
OpenFiles();
|
||||
|
||||
Task[] saveTasks = new Task[3];
|
||||
|
||||
saveTasks[0] = SaveItems();
|
||||
saveTasks[1] = SaveMobiles();
|
||||
saveTasks[2] = SaveGuilds();
|
||||
|
||||
SaveTypeDatabases();
|
||||
|
||||
if (permitBackgroundWrite)
|
||||
{
|
||||
//This option makes it finish the writing to disk in the background, continuing even after Save() returns.
|
||||
Task.Factory.ContinueWhenAll(saveTasks, _ =>
|
||||
{
|
||||
CloseFiles();
|
||||
|
||||
World.NotifyDiskWriteComplete();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Task.WaitAll(saveTasks); //Waits for the completion of all of the tasks(committing to disk)
|
||||
CloseFiles();
|
||||
}
|
||||
}
|
||||
|
||||
private Task StartCommitTask(BlockingCollection<QueuedMemoryWriter> threadWriter, SequentialFileWriter data, SequentialFileWriter index)
|
||||
{
|
||||
Task commitTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
while (!(threadWriter.IsCompleted))
|
||||
{
|
||||
QueuedMemoryWriter writer;
|
||||
|
||||
try
|
||||
{
|
||||
writer = threadWriter.Take();
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
//Per MSDN, it's fine if we're here, successful completion of adding can rarely put us into this state.
|
||||
break;
|
||||
}
|
||||
|
||||
writer.CommitTo(data, index);
|
||||
}
|
||||
});
|
||||
|
||||
return commitTask;
|
||||
}
|
||||
|
||||
private Task SaveItems()
|
||||
{
|
||||
//Start the blocking consumer; this runs in background.
|
||||
Task commitTask = StartCommitTask(_itemThreadWriters, _itemData, _itemIndex);
|
||||
|
||||
IEnumerable<Item> items = World.Items.Values;
|
||||
|
||||
//Start the producer.
|
||||
Parallel.ForEach(items, () => new QueuedMemoryWriter(),
|
||||
(Item item, ParallelLoopState state, QueuedMemoryWriter writer) =>
|
||||
{
|
||||
long startPosition = writer.Position;
|
||||
|
||||
item.Serialize(writer);
|
||||
|
||||
int size = (int)(writer.Position - startPosition);
|
||||
|
||||
writer.QueueForIndex(item, size);
|
||||
|
||||
if (item.Decays && item.Parent == null && item.Map != Map.Internal && DateTime.Now > (item.LastMoved + item.DecayTime))
|
||||
{
|
||||
_decayBag.Add(item);
|
||||
}
|
||||
|
||||
if (_metrics != null)
|
||||
{
|
||||
_metrics.OnItemSaved(size);
|
||||
}
|
||||
|
||||
return writer;
|
||||
},
|
||||
(writer) =>
|
||||
{
|
||||
writer.Flush();
|
||||
|
||||
_itemThreadWriters.Add(writer);
|
||||
});
|
||||
|
||||
_itemThreadWriters.CompleteAdding(); //We only get here after the Parallel.ForEach completes. Lets our task
|
||||
|
||||
return commitTask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Task SaveMobiles()
|
||||
{
|
||||
//Start the blocking consumer; this runs in background.
|
||||
Task commitTask = StartCommitTask( _mobileThreadWriters, _mobileData, _mobileIndex );
|
||||
|
||||
IEnumerable<Mobile> mobiles = World.Mobiles.Values;
|
||||
|
||||
//Start the producer.
|
||||
Parallel.ForEach(mobiles, () => new QueuedMemoryWriter(),
|
||||
(Mobile mobile, ParallelLoopState state, QueuedMemoryWriter writer) =>
|
||||
{
|
||||
long startPosition = writer.Position;
|
||||
|
||||
mobile.Serialize(writer);
|
||||
|
||||
int size = (int)(writer.Position - startPosition);
|
||||
|
||||
writer.QueueForIndex(mobile, size);
|
||||
|
||||
if (_metrics != null)
|
||||
{
|
||||
_metrics.OnMobileSaved(size);
|
||||
}
|
||||
|
||||
return writer;
|
||||
},
|
||||
(writer) =>
|
||||
{
|
||||
writer.Flush();
|
||||
|
||||
_mobileThreadWriters.Add(writer);
|
||||
});
|
||||
|
||||
_mobileThreadWriters.CompleteAdding(); //We only get here after the Parallel.ForEach completes. Lets our task tell the consumer that we're done
|
||||
|
||||
return commitTask;
|
||||
}
|
||||
|
||||
private Task SaveGuilds()
|
||||
{
|
||||
//Start the blocking consumer; this runs in background.
|
||||
Task commitTask = StartCommitTask(_guildThreadWriters, _guildData, _guildIndex);
|
||||
|
||||
IEnumerable<BaseGuild> guilds = BaseGuild.List.Values;
|
||||
|
||||
//Start the producer.
|
||||
Parallel.ForEach(guilds, () => new QueuedMemoryWriter(),
|
||||
(BaseGuild guild, ParallelLoopState state, QueuedMemoryWriter writer) =>
|
||||
{
|
||||
long startPosition = writer.Position;
|
||||
|
||||
guild.Serialize(writer);
|
||||
|
||||
int size = (int)(writer.Position - startPosition );
|
||||
|
||||
writer.QueueForIndex(guild, size);
|
||||
|
||||
if (_metrics != null)
|
||||
{
|
||||
_metrics.OnGuildSaved(size);
|
||||
}
|
||||
|
||||
return writer;
|
||||
},
|
||||
(writer) =>
|
||||
{
|
||||
writer.Flush();
|
||||
|
||||
_guildThreadWriters.Add(writer);
|
||||
});
|
||||
|
||||
_guildThreadWriters.CompleteAdding(); //We only get here after the Parallel.ForEach completes. Lets our task
|
||||
|
||||
return commitTask;
|
||||
}
|
||||
|
||||
public override void ProcessDecay()
|
||||
{
|
||||
Item item;
|
||||
|
||||
while( _decayBag.TryTake( out item ) )
|
||||
{
|
||||
item.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenFiles()
|
||||
{
|
||||
_itemData = new SequentialFileWriter(World.ItemDataPath, _metrics);
|
||||
_itemIndex = new SequentialFileWriter(World.ItemIndexPath, _metrics);
|
||||
|
||||
_mobileData = new SequentialFileWriter(World.MobileDataPath, _metrics);
|
||||
_mobileIndex = new SequentialFileWriter(World.MobileIndexPath, _metrics);
|
||||
|
||||
_guildData = new SequentialFileWriter(World.GuildDataPath, _metrics);
|
||||
_guildIndex = new SequentialFileWriter(World.GuildIndexPath, _metrics);
|
||||
|
||||
WriteCount(_itemIndex, World.Items.Count);
|
||||
WriteCount(_mobileIndex, World.Mobiles.Count);
|
||||
WriteCount(_guildIndex, BaseGuild.List.Count);
|
||||
}
|
||||
|
||||
private void CloseFiles()
|
||||
{
|
||||
_itemData.Close();
|
||||
_itemIndex.Close();
|
||||
|
||||
_mobileData.Close();
|
||||
_mobileIndex.Close();
|
||||
|
||||
_guildData.Close();
|
||||
_guildIndex.Close();
|
||||
}
|
||||
|
||||
private void WriteCount(SequentialFileWriter indexFile, int count)
|
||||
{
|
||||
//Equiv to GenericWriter.Write( (int)count );
|
||||
byte[] buffer = new byte[4];
|
||||
|
||||
buffer[0] = (byte)(count);
|
||||
buffer[1] = (byte)(count >> 8);
|
||||
buffer[2] = (byte)(count >> 16);
|
||||
buffer[3] = (byte)(count >> 24);
|
||||
|
||||
indexFile.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
private void SaveTypeDatabases()
|
||||
{
|
||||
SaveTypeDatabase(World.ItemTypesPath, World.m_ItemTypes);
|
||||
SaveTypeDatabase(World.MobileTypesPath, World.m_MobileTypes);
|
||||
}
|
||||
|
||||
private void SaveTypeDatabase(string path, List<Type> types)
|
||||
{
|
||||
BinaryFileWriter bfw = new BinaryFileWriter(path, false);
|
||||
|
||||
bfw.Write(types.Count);
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
bfw.Write(type.FullName);
|
||||
}
|
||||
|
||||
bfw.Flush();
|
||||
|
||||
bfw.Close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
141
Source/Persistence/FileOperations.cs
Normal file
141
Source/Persistence/FileOperations.cs
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
/***************************************************************************
|
||||
* FileOperations.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
#if !MONO
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
#endif
|
||||
|
||||
namespace Server {
|
||||
public static class FileOperations {
|
||||
public const int KB = 1024;
|
||||
public const int MB = 1024 * KB;
|
||||
|
||||
#if !MONO
|
||||
private const FileOptions NoBuffering = ( FileOptions ) 0x20000000;
|
||||
|
||||
[DllImport( "Kernel32", CharSet = CharSet.Auto, SetLastError = true )]
|
||||
private static extern SafeFileHandle CreateFile( string lpFileName, int dwDesiredAccess, FileShare dwShareMode, IntPtr securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile );
|
||||
#endif
|
||||
|
||||
private static int bufferSize = 1 * MB;
|
||||
private static int concurrency = 1;
|
||||
|
||||
private static bool unbuffered = true;
|
||||
|
||||
public static int BufferSize {
|
||||
get {
|
||||
return bufferSize;
|
||||
}
|
||||
set {
|
||||
bufferSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static int Concurrency {
|
||||
get {
|
||||
return concurrency;
|
||||
}
|
||||
set {
|
||||
concurrency = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Unbuffered {
|
||||
get {
|
||||
return unbuffered;
|
||||
}
|
||||
set {
|
||||
unbuffered = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AreSynchronous {
|
||||
get {
|
||||
return ( concurrency < 1 );
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AreAsynchronous {
|
||||
get {
|
||||
return ( concurrency > 0 );
|
||||
}
|
||||
}
|
||||
|
||||
public static FileStream OpenSequentialStream( string path, FileMode mode, FileAccess access, FileShare share ) {
|
||||
FileOptions options = FileOptions.SequentialScan;
|
||||
|
||||
if ( concurrency > 0 ) {
|
||||
options |= FileOptions.Asynchronous;
|
||||
}
|
||||
|
||||
#if MONO
|
||||
return new FileStream( path, mode, access, share, bufferSize, options );
|
||||
#else
|
||||
if ( unbuffered ) {
|
||||
options |= NoBuffering;
|
||||
} else {
|
||||
return new FileStream( path, mode, access, share, bufferSize, options );
|
||||
}
|
||||
|
||||
SafeFileHandle fileHandle = CreateFile( path, (int) access, share, IntPtr.Zero, mode, (int) options, IntPtr.Zero );
|
||||
|
||||
if ( fileHandle.IsInvalid ) {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
return new UnbufferedFileStream( fileHandle, access, bufferSize, ( concurrency > 0 ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !MONO
|
||||
private class UnbufferedFileStream : FileStream {
|
||||
private SafeFileHandle fileHandle;
|
||||
|
||||
public UnbufferedFileStream( SafeFileHandle fileHandle, FileAccess access, int bufferSize, bool isAsync )
|
||||
: base( fileHandle, access, bufferSize, isAsync ) {
|
||||
this.fileHandle = fileHandle;
|
||||
}
|
||||
|
||||
public override void Write( byte[] array, int offset, int count ) {
|
||||
base.Write( array, offset, bufferSize );
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginWrite( byte[] array, int offset, int numBytes, AsyncCallback userCallback, object stateObject ) {
|
||||
return base.BeginWrite( array, offset, bufferSize, userCallback, stateObject );
|
||||
}
|
||||
|
||||
protected override void Dispose( bool disposing ) {
|
||||
if ( !fileHandle.IsClosed ) {
|
||||
fileHandle.Close();
|
||||
}
|
||||
|
||||
base.Dispose( disposing );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
251
Source/Persistence/FileQueue.cs
Normal file
251
Source/Persistence/FileQueue.cs
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
/***************************************************************************
|
||||
* FileQueue.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
using Server;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server {
|
||||
public delegate void FileCommitCallback( FileQueue.Chunk chunk );
|
||||
|
||||
public sealed class FileQueue : IDisposable {
|
||||
public sealed class Chunk {
|
||||
private FileQueue owner;
|
||||
private int slot;
|
||||
|
||||
private byte[] buffer;
|
||||
private int offset;
|
||||
private int size;
|
||||
|
||||
public byte[] Buffer {
|
||||
get {
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
public int Offset {
|
||||
get {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int Size {
|
||||
get {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
public Chunk( FileQueue owner, int slot, byte[] buffer, int offset, int size ) {
|
||||
this.owner = owner;
|
||||
this.slot = slot;
|
||||
|
||||
this.buffer = buffer;
|
||||
this.offset = offset;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void Commit() {
|
||||
owner.Commit( this, this.slot );
|
||||
}
|
||||
}
|
||||
|
||||
private struct Page {
|
||||
public byte[] buffer;
|
||||
public int length;
|
||||
}
|
||||
|
||||
private static int bufferSize;
|
||||
private static BufferPool bufferPool;
|
||||
|
||||
static FileQueue() {
|
||||
bufferSize = FileOperations.BufferSize;
|
||||
bufferPool = new BufferPool( "File Buffers", 64, bufferSize );
|
||||
}
|
||||
|
||||
private object syncRoot;
|
||||
|
||||
private Chunk[] active;
|
||||
private int activeCount;
|
||||
|
||||
private Queue<Page> pending;
|
||||
private Page buffered;
|
||||
|
||||
private FileCommitCallback callback;
|
||||
|
||||
private ManualResetEvent idle;
|
||||
|
||||
private long position;
|
||||
|
||||
public long Position {
|
||||
get {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
public FileQueue( int concurrentWrites, FileCommitCallback callback ) {
|
||||
if ( concurrentWrites < 1 ) {
|
||||
throw new ArgumentOutOfRangeException( "concurrentWrites" );
|
||||
} else if ( bufferSize < 1 ) {
|
||||
throw new ArgumentOutOfRangeException( "bufferSize" );
|
||||
} else if ( callback == null ) {
|
||||
throw new ArgumentNullException( "callback" );
|
||||
}
|
||||
|
||||
this.syncRoot = new object();
|
||||
|
||||
this.active = new Chunk[concurrentWrites];
|
||||
this.pending = new Queue<Page>();
|
||||
|
||||
this.callback = callback;
|
||||
|
||||
this.idle = new ManualResetEvent( true );
|
||||
}
|
||||
|
||||
private void Append( Page page ) {
|
||||
lock ( syncRoot ) {
|
||||
if ( activeCount == 0 ) {
|
||||
idle.Reset();
|
||||
}
|
||||
|
||||
++activeCount;
|
||||
|
||||
for ( int slot = 0; slot < active.Length; ++slot ) {
|
||||
if ( active[slot] == null ) {
|
||||
active[slot] = new Chunk( this, slot, page.buffer, 0, page.length );
|
||||
|
||||
callback( active[slot] );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pending.Enqueue( page );
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
if ( idle != null ) {
|
||||
idle.Close();
|
||||
idle = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Flush() {
|
||||
if ( buffered.buffer != null ) {
|
||||
Append( buffered );
|
||||
|
||||
buffered.buffer = null;
|
||||
buffered.length = 0;
|
||||
}
|
||||
|
||||
/*lock ( syncRoot ) {
|
||||
if ( pending.Count > 0 ) {
|
||||
idle.Reset();
|
||||
}
|
||||
|
||||
for ( int slot = 0; slot < active.Length && pending.Count > 0; ++slot ) {
|
||||
if ( active[slot] == null ) {
|
||||
Page page = pending.Dequeue();
|
||||
|
||||
active[slot] = new Chunk( this, slot, page.buffer, 0, page.length );
|
||||
|
||||
++activeCount;
|
||||
|
||||
callback( active[slot] );
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
idle.WaitOne();
|
||||
}
|
||||
|
||||
private void Commit( Chunk chunk, int slot ) {
|
||||
if ( slot < 0 || slot >= active.Length ) {
|
||||
throw new ArgumentOutOfRangeException( "slot" );
|
||||
}
|
||||
|
||||
lock ( syncRoot ) {
|
||||
if ( active[slot] != chunk ) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
bufferPool.ReleaseBuffer( chunk.Buffer );
|
||||
|
||||
if ( pending.Count > 0 ) {
|
||||
Page page = pending.Dequeue();
|
||||
|
||||
active[slot] = new Chunk( this, slot, page.buffer, 0, page.length );
|
||||
|
||||
callback( active[slot] );
|
||||
} else {
|
||||
active[slot] = null;
|
||||
}
|
||||
|
||||
--activeCount;
|
||||
|
||||
if ( activeCount == 0 ) {
|
||||
idle.Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Enqueue( byte[] buffer, int offset, int size ) {
|
||||
if ( buffer == null ) {
|
||||
throw new ArgumentNullException( "buffer" );
|
||||
} else if ( offset < 0 ) {
|
||||
throw new ArgumentOutOfRangeException( "offset" );
|
||||
} else if ( size < 0 ) {
|
||||
throw new ArgumentOutOfRangeException( "size" );
|
||||
} else if ( ( buffer.Length - offset ) < size ) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
position += size;
|
||||
|
||||
while ( size > 0 ) {
|
||||
if ( buffered.buffer == null ) { // nothing yet buffered
|
||||
buffered.buffer = bufferPool.AcquireBuffer();
|
||||
}
|
||||
|
||||
byte[] page = buffered.buffer; // buffer page
|
||||
int pageSpace = page.Length - buffered.length; // available bytes in page
|
||||
int byteCount = ( size > pageSpace ? pageSpace : size ); // how many bytes we can copy over
|
||||
|
||||
Buffer.BlockCopy( buffer, offset, page, buffered.length, byteCount );
|
||||
|
||||
buffered.length += byteCount;
|
||||
offset += byteCount;
|
||||
size -= byteCount;
|
||||
|
||||
if ( buffered.length == page.Length ) { // page full
|
||||
Append( buffered );
|
||||
|
||||
buffered.buffer = null;
|
||||
buffered.length = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
345
Source/Persistence/ParallelSaveStrategy.cs
Normal file
345
Source/Persistence/ParallelSaveStrategy.cs
Normal file
|
|
@ -0,0 +1,345 @@
|
|||
/***************************************************************************
|
||||
* ParallelSaveStrategy.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Server;
|
||||
using Server.Guilds;
|
||||
|
||||
namespace Server {
|
||||
public sealed class ParallelSaveStrategy : SaveStrategy {
|
||||
public override string Name {
|
||||
get { return "Parallel"; }
|
||||
}
|
||||
|
||||
private int processorCount;
|
||||
|
||||
public ParallelSaveStrategy( int processorCount ) {
|
||||
this.processorCount = processorCount;
|
||||
|
||||
_decayQueue = new Queue<Item>();
|
||||
}
|
||||
|
||||
private int GetThreadCount() {
|
||||
return processorCount - 1;
|
||||
}
|
||||
|
||||
private SaveMetrics metrics;
|
||||
|
||||
private SequentialFileWriter itemData, itemIndex;
|
||||
private SequentialFileWriter mobileData, mobileIndex;
|
||||
private SequentialFileWriter guildData, guildIndex;
|
||||
|
||||
private Queue<Item> _decayQueue;
|
||||
|
||||
private Consumer[] consumers;
|
||||
private int cycle;
|
||||
|
||||
private bool finished;
|
||||
|
||||
public override void Save(SaveMetrics metrics, bool permitBackgroundWrite)
|
||||
{
|
||||
this.metrics = metrics;
|
||||
|
||||
OpenFiles();
|
||||
|
||||
consumers = new Consumer[GetThreadCount()];
|
||||
|
||||
for ( int i = 0; i < consumers.Length; ++i ) {
|
||||
consumers[i] = new Consumer( this, 256 );
|
||||
}
|
||||
|
||||
IEnumerable<ISerializable> collection = new Producer();
|
||||
|
||||
foreach ( ISerializable value in collection ) {
|
||||
while ( !Enqueue( value ) ) {
|
||||
if ( !Commit() ) {
|
||||
Thread.Sleep( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
finished = true;
|
||||
|
||||
SaveTypeDatabases();
|
||||
|
||||
WaitHandle.WaitAll(
|
||||
Array.ConvertAll<Consumer, WaitHandle>(
|
||||
consumers,
|
||||
delegate( Consumer input ) {
|
||||
return input.completionEvent;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Commit();
|
||||
|
||||
CloseFiles();
|
||||
}
|
||||
|
||||
public override void ProcessDecay() {
|
||||
while ( _decayQueue.Count > 0 ) {
|
||||
Item item = _decayQueue.Dequeue();
|
||||
|
||||
if ( item.OnDecay() ) {
|
||||
item.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveTypeDatabases() {
|
||||
SaveTypeDatabase( World.ItemTypesPath, World.m_ItemTypes );
|
||||
SaveTypeDatabase( World.MobileTypesPath, World.m_MobileTypes );
|
||||
}
|
||||
|
||||
private void SaveTypeDatabase( string path, List<Type> types ) {
|
||||
BinaryFileWriter bfw = new BinaryFileWriter( path, false );
|
||||
|
||||
bfw.Write( types.Count );
|
||||
|
||||
foreach ( Type type in types ) {
|
||||
bfw.Write( type.FullName );
|
||||
}
|
||||
|
||||
bfw.Flush();
|
||||
|
||||
bfw.Close();
|
||||
}
|
||||
|
||||
private void OpenFiles() {
|
||||
itemData = new SequentialFileWriter( World.ItemDataPath, metrics );
|
||||
itemIndex = new SequentialFileWriter( World.ItemIndexPath, metrics );
|
||||
|
||||
mobileData = new SequentialFileWriter( World.MobileDataPath, metrics );
|
||||
mobileIndex = new SequentialFileWriter( World.MobileIndexPath, metrics );
|
||||
|
||||
guildData = new SequentialFileWriter( World.GuildDataPath, metrics );
|
||||
guildIndex = new SequentialFileWriter( World.GuildIndexPath, metrics );
|
||||
|
||||
WriteCount( itemIndex, World.Items.Count );
|
||||
WriteCount( mobileIndex, World.Mobiles.Count );
|
||||
WriteCount( guildIndex, BaseGuild.List.Count );
|
||||
}
|
||||
|
||||
private void WriteCount( SequentialFileWriter indexFile, int count ) {
|
||||
byte[] buffer = new byte[4];
|
||||
|
||||
buffer[0] = ( byte ) ( count );
|
||||
buffer[1] = ( byte ) ( count >> 8 );
|
||||
buffer[2] = ( byte ) ( count >> 16 );
|
||||
buffer[3] = ( byte ) ( count >> 24 );
|
||||
|
||||
indexFile.Write( buffer, 0, buffer.Length );
|
||||
}
|
||||
|
||||
private void CloseFiles() {
|
||||
itemData.Close();
|
||||
itemIndex.Close();
|
||||
|
||||
mobileData.Close();
|
||||
mobileIndex.Close();
|
||||
|
||||
guildData.Close();
|
||||
guildIndex.Close();
|
||||
|
||||
World.NotifyDiskWriteComplete();
|
||||
}
|
||||
|
||||
private void OnSerialized( ConsumableEntry entry ) {
|
||||
ISerializable value = entry.value;
|
||||
BinaryMemoryWriter writer = entry.writer;
|
||||
|
||||
Item item = value as Item;
|
||||
|
||||
if ( item != null ) {
|
||||
Save( item, writer );
|
||||
} else {
|
||||
Mobile mob = value as Mobile;
|
||||
|
||||
if ( mob != null ) {
|
||||
Save( mob, writer );
|
||||
} else {
|
||||
BaseGuild guild = value as BaseGuild;
|
||||
|
||||
if ( guild != null ) {
|
||||
Save( guild, writer );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Save( Item item, BinaryMemoryWriter writer ) {
|
||||
int length = writer.CommitTo( itemData, itemIndex, item.m_TypeRef, item.Serial );
|
||||
|
||||
if ( metrics != null ) {
|
||||
metrics.OnItemSaved( length );
|
||||
}
|
||||
|
||||
if ( item.Decays && item.Parent == null && item.Map != Map.Internal && DateTime.Now > ( item.LastMoved + item.DecayTime ) ) {
|
||||
_decayQueue.Enqueue( item );
|
||||
}
|
||||
}
|
||||
|
||||
private void Save( Mobile mob, BinaryMemoryWriter writer ) {
|
||||
int length = writer.CommitTo( mobileData, mobileIndex, mob.m_TypeRef, mob.Serial );
|
||||
|
||||
if ( metrics != null ) {
|
||||
metrics.OnMobileSaved( length );
|
||||
}
|
||||
}
|
||||
|
||||
private void Save( BaseGuild guild, BinaryMemoryWriter writer ) {
|
||||
int length = writer.CommitTo( guildData, guildIndex, 0, guild.Id );
|
||||
|
||||
if ( metrics != null ) {
|
||||
metrics.OnGuildSaved( length );
|
||||
}
|
||||
}
|
||||
|
||||
private bool Enqueue( ISerializable value ) {
|
||||
for ( int i = 0; i < consumers.Length; ++i ) {
|
||||
Consumer consumer = consumers[cycle++ % consumers.Length];
|
||||
|
||||
if ( ( consumer.tail - consumer.head ) < consumer.buffer.Length ) {
|
||||
consumer.buffer[consumer.tail % consumer.buffer.Length].value = value;
|
||||
consumer.tail++;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool Commit() {
|
||||
bool committed = false;
|
||||
|
||||
for ( int i = 0; i < consumers.Length; ++i ) {
|
||||
Consumer consumer = consumers[i];
|
||||
|
||||
while ( consumer.head < consumer.done ) {
|
||||
OnSerialized( consumer.buffer[consumer.head % consumer.buffer.Length] );
|
||||
consumer.head++;
|
||||
|
||||
committed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return committed;
|
||||
}
|
||||
|
||||
private sealed class Producer : IEnumerable<ISerializable> {
|
||||
private IEnumerable<Item> items;
|
||||
private IEnumerable<Mobile> mobiles;
|
||||
private IEnumerable<BaseGuild> guilds;
|
||||
|
||||
public Producer() {
|
||||
items = World.Items.Values;
|
||||
mobiles = World.Mobiles.Values;
|
||||
guilds = BaseGuild.List.Values;
|
||||
}
|
||||
|
||||
public IEnumerator<ISerializable> GetEnumerator() {
|
||||
foreach ( Item item in items ) {
|
||||
yield return item;
|
||||
}
|
||||
|
||||
foreach ( Mobile mob in mobiles ) {
|
||||
yield return mob;
|
||||
}
|
||||
|
||||
foreach ( BaseGuild guild in guilds ) {
|
||||
yield return guild;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
private struct ConsumableEntry {
|
||||
public ISerializable value;
|
||||
public BinaryMemoryWriter writer;
|
||||
}
|
||||
|
||||
private sealed class Consumer {
|
||||
private ParallelSaveStrategy owner;
|
||||
|
||||
public ManualResetEvent completionEvent;
|
||||
|
||||
public ConsumableEntry[] buffer;
|
||||
public int head, done, tail;
|
||||
|
||||
private Thread thread;
|
||||
|
||||
public Consumer( ParallelSaveStrategy owner, int bufferSize ) {
|
||||
this.owner = owner;
|
||||
|
||||
this.buffer = new ConsumableEntry[bufferSize];
|
||||
|
||||
for ( int i = 0; i < this.buffer.Length; ++i ) {
|
||||
this.buffer[i].writer = new BinaryMemoryWriter();
|
||||
}
|
||||
|
||||
this.completionEvent = new ManualResetEvent( false );
|
||||
|
||||
thread = new Thread( Processor );
|
||||
|
||||
thread.Name = "Parallel Serialization Thread";
|
||||
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
private void Processor() {
|
||||
try {
|
||||
while ( !owner.finished ) {
|
||||
Process();
|
||||
Thread.Sleep( 0 );
|
||||
}
|
||||
|
||||
Process();
|
||||
|
||||
completionEvent.Set();
|
||||
} catch ( Exception ex ) {
|
||||
Console.WriteLine( ex );
|
||||
}
|
||||
}
|
||||
|
||||
private void Process() {
|
||||
ConsumableEntry entry;
|
||||
|
||||
while ( done < tail ) {
|
||||
entry = buffer[done % buffer.Length];
|
||||
|
||||
entry.value.Serialize( entry.writer );
|
||||
|
||||
++done;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
126
Source/Persistence/QueuedMemoryWriter.cs
Normal file
126
Source/Persistence/QueuedMemoryWriter.cs
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
/***************************************************************************
|
||||
* QueuedMemoryWriter.cs
|
||||
* -------------------
|
||||
* begin : December 16, 2010
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public sealed class QueuedMemoryWriter : BinaryFileWriter
|
||||
{
|
||||
private struct IndexInfo
|
||||
{
|
||||
public int size;
|
||||
public int typeCode;
|
||||
public int serial;
|
||||
}
|
||||
|
||||
private MemoryStream _memStream;
|
||||
private List<IndexInfo> _orderedIndexInfo = new List<IndexInfo>();
|
||||
|
||||
protected override int BufferSize
|
||||
{
|
||||
get { return 512; }
|
||||
}
|
||||
|
||||
public QueuedMemoryWriter()
|
||||
: base(new MemoryStream(1024 * 1024), true)
|
||||
{
|
||||
this._memStream = this.UnderlyingStream as MemoryStream;
|
||||
}
|
||||
|
||||
public void QueueForIndex(ISerializable serializable, int size)
|
||||
{
|
||||
IndexInfo info;
|
||||
|
||||
info.size = size;
|
||||
|
||||
info.typeCode = serializable.TypeReference; //For guilds, this will automagically be zero.
|
||||
info.serial = serializable.SerialIdentity;
|
||||
|
||||
_orderedIndexInfo.Add(info);
|
||||
}
|
||||
|
||||
public void CommitTo(SequentialFileWriter dataFile, SequentialFileWriter indexFile)
|
||||
{
|
||||
this.Flush();
|
||||
|
||||
int memLength = (int)_memStream.Position;
|
||||
|
||||
if (memLength > 0)
|
||||
{
|
||||
byte[] memBuffer = _memStream.GetBuffer();
|
||||
|
||||
long actualPosition = dataFile.Position;
|
||||
|
||||
dataFile.Write(memBuffer, 0, memLength); //The buffer contains the data from many items.
|
||||
|
||||
//Console.WriteLine("Writing {0} bytes starting at {1}, with {2} things", memLength, actualPosition, _orderedIndexInfo.Count);
|
||||
|
||||
byte[] indexBuffer = new byte[20];
|
||||
|
||||
//int indexWritten = _orderedIndexInfo.Count * indexBuffer.Length;
|
||||
//int totalWritten = memLength + indexWritten
|
||||
|
||||
for (int i = 0; i < _orderedIndexInfo.Count; i++)
|
||||
{
|
||||
IndexInfo info = _orderedIndexInfo[i];
|
||||
|
||||
int typeCode = info.typeCode;
|
||||
int serial = info.serial;
|
||||
int length = info.size;
|
||||
|
||||
|
||||
indexBuffer[0] = (byte)(info.typeCode);
|
||||
indexBuffer[1] = (byte)(info.typeCode >> 8);
|
||||
indexBuffer[2] = (byte)(info.typeCode >> 16);
|
||||
indexBuffer[3] = (byte)(info.typeCode >> 24);
|
||||
|
||||
indexBuffer[4] = (byte)(info.serial);
|
||||
indexBuffer[5] = (byte)(info.serial >> 8);
|
||||
indexBuffer[6] = (byte)(info.serial >> 16);
|
||||
indexBuffer[7] = (byte)(info.serial >> 24);
|
||||
|
||||
indexBuffer[8] = (byte)(actualPosition);
|
||||
indexBuffer[9] = (byte)(actualPosition >> 8);
|
||||
indexBuffer[10] = (byte)(actualPosition >> 16);
|
||||
indexBuffer[11] = (byte)(actualPosition >> 24);
|
||||
indexBuffer[12] = (byte)(actualPosition >> 32);
|
||||
indexBuffer[13] = (byte)(actualPosition >> 40);
|
||||
indexBuffer[14] = (byte)(actualPosition >> 48);
|
||||
indexBuffer[15] = (byte)(actualPosition >> 56);
|
||||
|
||||
indexBuffer[16] = (byte)(info.size);
|
||||
indexBuffer[17] = (byte)(info.size >> 8);
|
||||
indexBuffer[18] = (byte)(info.size >> 16);
|
||||
indexBuffer[19] = (byte)(info.size >> 24);
|
||||
|
||||
indexFile.Write(indexBuffer, 0, indexBuffer.Length);
|
||||
|
||||
actualPosition += info.size;
|
||||
}
|
||||
}
|
||||
|
||||
this.Close(); //We're done with this writer.
|
||||
}
|
||||
}
|
||||
}
|
||||
131
Source/Persistence/SaveMetrics.cs
Normal file
131
Source/Persistence/SaveMetrics.cs
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/***************************************************************************
|
||||
* SaveMetrics.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace Server {
|
||||
public sealed class SaveMetrics : IDisposable {
|
||||
private const string PerformanceCategoryName = "Ultima";
|
||||
private const string PerformanceCategoryDesc = "Performance counters for Ultima.";
|
||||
|
||||
private PerformanceCounter numberOfWorldSaves;
|
||||
|
||||
private PerformanceCounter itemsPerSecond;
|
||||
private PerformanceCounter mobilesPerSecond;
|
||||
|
||||
private PerformanceCounter serializedBytesPerSecond;
|
||||
private PerformanceCounter writtenBytesPerSecond;
|
||||
|
||||
public SaveMetrics() {
|
||||
if ( !PerformanceCounterCategory.Exists( PerformanceCategoryName ) ) {
|
||||
CounterCreationDataCollection counters = new CounterCreationDataCollection();
|
||||
|
||||
counters.Add( new CounterCreationData(
|
||||
"Save - Count",
|
||||
"Number of world saves.",
|
||||
PerformanceCounterType.NumberOfItems32
|
||||
)
|
||||
);
|
||||
|
||||
counters.Add( new CounterCreationData(
|
||||
"Save - Items/sec",
|
||||
"Number of items saved per second.",
|
||||
PerformanceCounterType.RateOfCountsPerSecond32
|
||||
)
|
||||
);
|
||||
|
||||
counters.Add( new CounterCreationData(
|
||||
"Save - Mobiles/sec",
|
||||
"Number of mobiles saved per second.",
|
||||
PerformanceCounterType.RateOfCountsPerSecond32
|
||||
)
|
||||
);
|
||||
|
||||
counters.Add( new CounterCreationData(
|
||||
"Save - Serialized bytes/sec",
|
||||
"Amount of world-save bytes serialized per second.",
|
||||
PerformanceCounterType.RateOfCountsPerSecond32
|
||||
)
|
||||
);
|
||||
|
||||
counters.Add( new CounterCreationData(
|
||||
"Save - Written bytes/sec",
|
||||
"Amount of world-save bytes written to disk per second.",
|
||||
PerformanceCounterType.RateOfCountsPerSecond32
|
||||
)
|
||||
);
|
||||
|
||||
#if !MONO
|
||||
PerformanceCounterCategory.Create( PerformanceCategoryName, PerformanceCategoryDesc, PerformanceCounterCategoryType.SingleInstance, counters );
|
||||
#endif
|
||||
}
|
||||
|
||||
numberOfWorldSaves = new PerformanceCounter( PerformanceCategoryName, "Save - Count", false );
|
||||
|
||||
itemsPerSecond = new PerformanceCounter( PerformanceCategoryName, "Save - Items/sec", false );
|
||||
mobilesPerSecond = new PerformanceCounter( PerformanceCategoryName, "Save - Mobiles/sec", false );
|
||||
|
||||
serializedBytesPerSecond = new PerformanceCounter( PerformanceCategoryName, "Save - Serialized bytes/sec", false );
|
||||
writtenBytesPerSecond = new PerformanceCounter( PerformanceCategoryName, "Save - Written bytes/sec", false );
|
||||
|
||||
// increment number of world saves
|
||||
numberOfWorldSaves.Increment();
|
||||
}
|
||||
|
||||
public void OnItemSaved( int numberOfBytes ) {
|
||||
itemsPerSecond.Increment();
|
||||
|
||||
serializedBytesPerSecond.IncrementBy( numberOfBytes );
|
||||
}
|
||||
|
||||
public void OnMobileSaved( int numberOfBytes ) {
|
||||
mobilesPerSecond.Increment();
|
||||
|
||||
serializedBytesPerSecond.IncrementBy( numberOfBytes );
|
||||
}
|
||||
|
||||
public void OnGuildSaved( int numberOfBytes ) {
|
||||
serializedBytesPerSecond.IncrementBy( numberOfBytes );
|
||||
}
|
||||
|
||||
public void OnFileWritten( int numberOfBytes ) {
|
||||
writtenBytesPerSecond.IncrementBy( numberOfBytes );
|
||||
}
|
||||
|
||||
private bool isDisposed;
|
||||
|
||||
public void Dispose() {
|
||||
if ( !isDisposed ) {
|
||||
isDisposed = true;
|
||||
|
||||
numberOfWorldSaves.Dispose();
|
||||
|
||||
itemsPerSecond.Dispose();
|
||||
mobilesPerSecond.Dispose();
|
||||
|
||||
serializedBytesPerSecond.Dispose();
|
||||
writtenBytesPerSecond.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
58
Source/Persistence/SaveStrategy.cs
Normal file
58
Source/Persistence/SaveStrategy.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/***************************************************************************
|
||||
* SaveStrategy.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public abstract class SaveStrategy
|
||||
{
|
||||
public static SaveStrategy Acquire()
|
||||
{
|
||||
if (Core.MultiProcessor)
|
||||
{
|
||||
int processorCount = Core.ProcessorCount;
|
||||
|
||||
if (processorCount > 16)
|
||||
{
|
||||
#if Framework_4_0
|
||||
return new DynamicSaveStrategy();
|
||||
#else
|
||||
return new ParallelSaveStrategy(processorCount);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DualSaveStrategy();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new StandardSaveStrategy();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract string Name { get; }
|
||||
public abstract void Save(SaveMetrics metrics, bool permitBackgroundWrite);
|
||||
|
||||
public abstract void ProcessDecay();
|
||||
}
|
||||
}
|
||||
141
Source/Persistence/SequentialFileWriter.cs
Normal file
141
Source/Persistence/SequentialFileWriter.cs
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
/***************************************************************************
|
||||
* SequentialFileWriter.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace Server {
|
||||
public sealed class SequentialFileWriter : Stream {
|
||||
private FileStream fileStream;
|
||||
private FileQueue fileQueue;
|
||||
|
||||
private AsyncCallback writeCallback;
|
||||
|
||||
private SaveMetrics metrics;
|
||||
|
||||
public SequentialFileWriter( string path, SaveMetrics metrics ) {
|
||||
if ( path == null ) {
|
||||
throw new ArgumentNullException( "path" );
|
||||
}
|
||||
|
||||
this.metrics = metrics;
|
||||
|
||||
this.fileStream = FileOperations.OpenSequentialStream( path, FileMode.Create, FileAccess.Write, FileShare.None );
|
||||
|
||||
fileQueue = new FileQueue(
|
||||
Math.Max( 1, FileOperations.Concurrency ),
|
||||
FileCallback
|
||||
);
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
return fileQueue.Position;
|
||||
}
|
||||
set {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private void FileCallback( FileQueue.Chunk chunk ) {
|
||||
if ( FileOperations.AreSynchronous ) {
|
||||
fileStream.Write( chunk.Buffer, chunk.Offset, chunk.Size );
|
||||
|
||||
if ( metrics != null ) {
|
||||
metrics.OnFileWritten( chunk.Size );
|
||||
}
|
||||
|
||||
chunk.Commit();
|
||||
} else {
|
||||
if ( writeCallback == null ) {
|
||||
writeCallback = this.OnWrite;
|
||||
}
|
||||
|
||||
fileStream.BeginWrite( chunk.Buffer, chunk.Offset, chunk.Size, writeCallback, chunk );
|
||||
}
|
||||
}
|
||||
|
||||
private void OnWrite( IAsyncResult asyncResult ) {
|
||||
FileQueue.Chunk chunk = asyncResult.AsyncState as FileQueue.Chunk;
|
||||
|
||||
fileStream.EndWrite( asyncResult );
|
||||
|
||||
if ( metrics != null ) {
|
||||
metrics.OnFileWritten( chunk.Size );
|
||||
}
|
||||
|
||||
chunk.Commit();
|
||||
}
|
||||
|
||||
public override void Write( byte[] buffer, int offset, int size ) {
|
||||
fileQueue.Enqueue( buffer, offset, size );
|
||||
}
|
||||
|
||||
public override void Flush() {
|
||||
fileQueue.Flush();
|
||||
fileStream.Flush();
|
||||
}
|
||||
|
||||
protected override void Dispose( bool disposing ) {
|
||||
if ( fileStream != null ) {
|
||||
Flush();
|
||||
|
||||
fileQueue.Dispose();
|
||||
fileQueue = null;
|
||||
|
||||
fileStream.Close();
|
||||
fileStream = null;
|
||||
}
|
||||
|
||||
base.Dispose( disposing );
|
||||
}
|
||||
|
||||
public override bool CanRead {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get { return this.Position; }
|
||||
}
|
||||
|
||||
public override int Read( byte[] buffer, int offset, int count ) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
public override long Seek( long offset, SeekOrigin origin ) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
public override void SetLength( long value ) {
|
||||
fileStream.SetLength( value );
|
||||
}
|
||||
}
|
||||
}
|
||||
204
Source/Persistence/StandardSaveStrategy.cs
Normal file
204
Source/Persistence/StandardSaveStrategy.cs
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
/***************************************************************************
|
||||
* StandardSaveStrategy.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Server;
|
||||
using Server.Guilds;
|
||||
|
||||
namespace Server {
|
||||
public class StandardSaveStrategy : SaveStrategy {
|
||||
public override string Name {
|
||||
get { return "Standard"; }
|
||||
}
|
||||
|
||||
private Queue<Item> _decayQueue;
|
||||
private bool _permitBackgroundWrite;
|
||||
|
||||
public StandardSaveStrategy() {
|
||||
_decayQueue = new Queue<Item>();
|
||||
}
|
||||
|
||||
protected bool PermitBackgroundWrite { get { return _permitBackgroundWrite; } set { _permitBackgroundWrite = value; } }
|
||||
|
||||
protected bool UseSequentialWriters { get { return (World.SaveType == World.SaveOption.Normal || !_permitBackgroundWrite); } }
|
||||
|
||||
public override void Save(SaveMetrics metrics, bool permitBackgroundWrite)
|
||||
{
|
||||
_permitBackgroundWrite = permitBackgroundWrite;
|
||||
|
||||
SaveMobiles(metrics);
|
||||
SaveItems(metrics);
|
||||
SaveGuilds(metrics);
|
||||
|
||||
if (permitBackgroundWrite && UseSequentialWriters) //If we're permitted to write in the background, but we don't anyways, then notify.
|
||||
World.NotifyDiskWriteComplete();
|
||||
}
|
||||
|
||||
protected void SaveMobiles(SaveMetrics metrics)
|
||||
{
|
||||
Dictionary<Serial, Mobile> mobiles = World.Mobiles;
|
||||
|
||||
GenericWriter idx;
|
||||
GenericWriter tdb;
|
||||
GenericWriter bin;
|
||||
|
||||
if (UseSequentialWriters)
|
||||
{
|
||||
idx = new BinaryFileWriter( World.MobileIndexPath, false );
|
||||
tdb = new BinaryFileWriter( World.MobileTypesPath, false );
|
||||
bin = new BinaryFileWriter( World.MobileDataPath, true );
|
||||
} else {
|
||||
idx = new AsyncWriter( World.MobileIndexPath, false );
|
||||
tdb = new AsyncWriter( World.MobileTypesPath, false );
|
||||
bin = new AsyncWriter( World.MobileDataPath, true );
|
||||
}
|
||||
|
||||
idx.Write( ( int ) mobiles.Count );
|
||||
foreach ( Mobile m in mobiles.Values ) {
|
||||
long start = bin.Position;
|
||||
|
||||
idx.Write( ( int ) m.m_TypeRef );
|
||||
idx.Write( ( int ) m.Serial );
|
||||
idx.Write( ( long ) start );
|
||||
|
||||
m.Serialize( bin );
|
||||
|
||||
if ( metrics != null ) {
|
||||
metrics.OnMobileSaved( ( int ) ( bin.Position - start ) );
|
||||
}
|
||||
|
||||
idx.Write( ( int ) ( bin.Position - start ) );
|
||||
|
||||
m.FreeCache();
|
||||
}
|
||||
|
||||
tdb.Write( ( int ) World.m_MobileTypes.Count );
|
||||
|
||||
for ( int i = 0; i < World.m_MobileTypes.Count; ++i )
|
||||
tdb.Write( World.m_MobileTypes[i].FullName );
|
||||
|
||||
idx.Close();
|
||||
tdb.Close();
|
||||
bin.Close();
|
||||
}
|
||||
|
||||
protected void SaveItems(SaveMetrics metrics)
|
||||
{
|
||||
Dictionary<Serial, Item> items = World.Items;
|
||||
|
||||
GenericWriter idx;
|
||||
GenericWriter tdb;
|
||||
GenericWriter bin;
|
||||
|
||||
if (UseSequentialWriters)
|
||||
{
|
||||
idx = new BinaryFileWriter( World.ItemIndexPath, false );
|
||||
tdb = new BinaryFileWriter( World.ItemTypesPath, false );
|
||||
bin = new BinaryFileWriter( World.ItemDataPath, true );
|
||||
} else {
|
||||
idx = new AsyncWriter( World.ItemIndexPath, false );
|
||||
tdb = new AsyncWriter( World.ItemTypesPath, false );
|
||||
bin = new AsyncWriter( World.ItemDataPath, true );
|
||||
}
|
||||
|
||||
idx.Write( ( int ) items.Count );
|
||||
foreach ( Item item in items.Values ) {
|
||||
if ( item.Decays && item.Parent == null && item.Map != Map.Internal && ( item.LastMoved + item.DecayTime ) <= DateTime.Now ) {
|
||||
_decayQueue.Enqueue( item );
|
||||
}
|
||||
|
||||
long start = bin.Position;
|
||||
|
||||
idx.Write( ( int ) item.m_TypeRef );
|
||||
idx.Write( ( int ) item.Serial );
|
||||
idx.Write( ( long ) start );
|
||||
|
||||
item.Serialize( bin );
|
||||
|
||||
if ( metrics != null ) {
|
||||
metrics.OnItemSaved( ( int ) ( bin.Position - start ) );
|
||||
}
|
||||
|
||||
idx.Write( ( int ) ( bin.Position - start ) );
|
||||
|
||||
item.FreeCache();
|
||||
}
|
||||
|
||||
tdb.Write( ( int ) World.m_ItemTypes.Count );
|
||||
for ( int i = 0; i < World.m_ItemTypes.Count; ++i )
|
||||
tdb.Write( World.m_ItemTypes[i].FullName );
|
||||
|
||||
idx.Close();
|
||||
tdb.Close();
|
||||
bin.Close();
|
||||
}
|
||||
|
||||
protected void SaveGuilds(SaveMetrics metrics)
|
||||
{
|
||||
GenericWriter idx;
|
||||
GenericWriter bin;
|
||||
|
||||
if (UseSequentialWriters)
|
||||
{
|
||||
idx = new BinaryFileWriter( World.GuildIndexPath, false );
|
||||
bin = new BinaryFileWriter( World.GuildDataPath, true );
|
||||
} else {
|
||||
idx = new AsyncWriter( World.GuildIndexPath, false );
|
||||
bin = new AsyncWriter( World.GuildDataPath, true );
|
||||
}
|
||||
|
||||
idx.Write( ( int ) BaseGuild.List.Count );
|
||||
foreach ( BaseGuild guild in BaseGuild.List.Values ) {
|
||||
long start = bin.Position;
|
||||
|
||||
idx.Write( ( int ) 0 );//guilds have no typeid
|
||||
idx.Write( ( int ) guild.Id );
|
||||
idx.Write( ( long ) start );
|
||||
|
||||
guild.Serialize( bin );
|
||||
|
||||
if ( metrics != null ) {
|
||||
metrics.OnGuildSaved( ( int ) ( bin.Position - start ) );
|
||||
}
|
||||
|
||||
idx.Write( ( int ) ( bin.Position - start ) );
|
||||
}
|
||||
|
||||
idx.Close();
|
||||
bin.Close();
|
||||
}
|
||||
|
||||
public override void ProcessDecay() {
|
||||
while ( _decayQueue.Count > 0 ) {
|
||||
Item item = _decayQueue.Dequeue();
|
||||
|
||||
if ( item.OnDecay() ) {
|
||||
item.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
113
Source/Point3DList.cs
Normal file
113
Source/Point3DList.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/***************************************************************************
|
||||
* Point3DList.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public class Point3DList
|
||||
{
|
||||
private Point3D[] m_List;
|
||||
private int m_Count;
|
||||
|
||||
public Point3DList()
|
||||
{
|
||||
m_List = new Point3D[8];
|
||||
m_Count = 0;
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Count;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_Count = 0;
|
||||
}
|
||||
|
||||
public Point3D Last
|
||||
{
|
||||
get{ return m_List[m_Count - 1]; }
|
||||
}
|
||||
|
||||
public Point3D this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_List[index];
|
||||
}
|
||||
}
|
||||
|
||||
public void Add( int x, int y, int z )
|
||||
{
|
||||
if ( (m_Count + 1) > m_List.Length )
|
||||
{
|
||||
Point3D[] old = m_List;
|
||||
m_List = new Point3D[old.Length * 2];
|
||||
|
||||
for ( int i = 0; i < old.Length; ++i )
|
||||
m_List[i] = old[i];
|
||||
}
|
||||
|
||||
m_List[m_Count].m_X = x;
|
||||
m_List[m_Count].m_Y = y;
|
||||
m_List[m_Count].m_Z = z;
|
||||
++m_Count;
|
||||
}
|
||||
|
||||
public void Add( Point3D p )
|
||||
{
|
||||
if ( (m_Count + 1) > m_List.Length )
|
||||
{
|
||||
Point3D[] old = m_List;
|
||||
m_List = new Point3D[old.Length * 2];
|
||||
|
||||
for ( int i = 0; i < old.Length; ++i )
|
||||
m_List[i] = old[i];
|
||||
}
|
||||
|
||||
m_List[m_Count].m_X = p.m_X;
|
||||
m_List[m_Count].m_Y = p.m_Y;
|
||||
m_List[m_Count].m_Z = p.m_Z;
|
||||
++m_Count;
|
||||
}
|
||||
|
||||
private static Point3D[] m_EmptyList = new Point3D[0];
|
||||
|
||||
public Point3D[] ToArray()
|
||||
{
|
||||
if ( m_Count == 0 )
|
||||
return m_EmptyList;
|
||||
|
||||
Point3D[] list = new Point3D[m_Count];
|
||||
|
||||
for ( int i = 0; i < m_Count; ++i )
|
||||
list[i] = m_List[i];
|
||||
|
||||
m_Count = 0;
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
144
Source/Poison.cs
Normal file
144
Source/Poison.cs
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
/***************************************************************************
|
||||
* Poison.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
[Parsable]
|
||||
public abstract class Poison
|
||||
{
|
||||
/*public abstract TimeSpan Interval{ get; }
|
||||
public abstract TimeSpan Duration{ get; }*/
|
||||
public abstract string Name { get; }
|
||||
public abstract int Level { get; }
|
||||
public abstract Timer ConstructTimer( Mobile m );
|
||||
/*public abstract void OnDamage( Mobile m, ref object state );*/
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name;
|
||||
}
|
||||
|
||||
|
||||
private static List<Poison> m_Poisons = new List<Poison>();
|
||||
|
||||
public static void Register( Poison reg )
|
||||
{
|
||||
string regName = reg.Name.ToLower();
|
||||
|
||||
for ( int i = 0; i < m_Poisons.Count; i++ )
|
||||
{
|
||||
if ( reg.Level == m_Poisons[i].Level )
|
||||
throw new Exception( "A poison with that level already exists." );
|
||||
else if ( regName == m_Poisons[i].Name.ToLower() )
|
||||
throw new Exception( "A poison with that name already exists." );
|
||||
}
|
||||
|
||||
m_Poisons.Add( reg );
|
||||
}
|
||||
|
||||
public static Poison Lesser { get { return GetPoison( "Lesser" ); } }
|
||||
public static Poison Regular { get { return GetPoison( "Regular" ); } }
|
||||
public static Poison Greater { get { return GetPoison( "Greater" ); } }
|
||||
public static Poison Deadly { get { return GetPoison( "Deadly" ); } }
|
||||
public static Poison Lethal { get { return GetPoison( "Lethal" ); } }
|
||||
|
||||
public static List<Poison> Poisons
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Poisons;
|
||||
}
|
||||
}
|
||||
|
||||
public static Poison Parse( string value )
|
||||
{
|
||||
Poison p = null;
|
||||
|
||||
int plevel;
|
||||
|
||||
if ( int.TryParse( value, out plevel ) )
|
||||
p = GetPoison( plevel );
|
||||
|
||||
if ( p == null )
|
||||
p = GetPoison( value );
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public static Poison GetPoison( int level )
|
||||
{
|
||||
for ( int i = 0; i < m_Poisons.Count; ++i )
|
||||
{
|
||||
Poison p = m_Poisons[i];
|
||||
|
||||
if ( p.Level == level )
|
||||
return p;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Poison GetPoison( string name )
|
||||
{
|
||||
for ( int i = 0; i < m_Poisons.Count; ++i )
|
||||
{
|
||||
Poison p = m_Poisons[i];
|
||||
|
||||
if ( Utility.InsensitiveCompare( p.Name, name ) == 0 )
|
||||
return p;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Serialize( Poison p, GenericWriter writer )
|
||||
{
|
||||
if ( p == null )
|
||||
{
|
||||
writer.Write( (byte)0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write( (byte)1 );
|
||||
writer.Write( (byte)p.Level );
|
||||
}
|
||||
}
|
||||
|
||||
public static Poison Deserialize( GenericReader reader )
|
||||
{
|
||||
switch ( reader.ReadByte() )
|
||||
{
|
||||
case 1: return GetPoison( reader.ReadByte() );
|
||||
case 2:
|
||||
//no longer used, safe to remove?
|
||||
reader.ReadInt();
|
||||
reader.ReadDouble();
|
||||
reader.ReadInt();
|
||||
reader.ReadTimeSpan();
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Source/Prompt.cs
Normal file
55
Source/Prompt.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/***************************************************************************
|
||||
* Prompt.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Prompts
|
||||
{
|
||||
public abstract class Prompt
|
||||
{
|
||||
private int m_Serial;
|
||||
private static int m_Serials;
|
||||
|
||||
public int Serial
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Serial;
|
||||
}
|
||||
}
|
||||
|
||||
protected Prompt()
|
||||
{
|
||||
do
|
||||
{
|
||||
m_Serial = ++m_Serials;
|
||||
} while ( m_Serial == 0 );
|
||||
}
|
||||
|
||||
public virtual void OnCancel( Mobile from )
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnResponse( Mobile from, string text )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
123
Source/QuestArrow.cs
Normal file
123
Source/QuestArrow.cs
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/***************************************************************************
|
||||
* QuestArrow.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public class QuestArrow
|
||||
{
|
||||
private Mobile m_Mobile;
|
||||
private Mobile m_Target;
|
||||
private bool m_Running;
|
||||
|
||||
public Mobile Mobile
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Mobile;
|
||||
}
|
||||
}
|
||||
|
||||
public Mobile Target
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Target;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Running
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Running;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Update( m_Target.X, m_Target.Y );
|
||||
}
|
||||
|
||||
public void Update( int x, int y )
|
||||
{
|
||||
if ( !m_Running )
|
||||
return;
|
||||
|
||||
NetState ns = m_Mobile.NetState;
|
||||
|
||||
if ( ns == null )
|
||||
return;
|
||||
|
||||
if ( ns.HighSeas )
|
||||
ns.Send( new SetArrowHS( x, y, m_Target.Serial ) );
|
||||
else
|
||||
ns.Send( new SetArrow( x, y ) );
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
Stop( m_Target.X, m_Target.Y );
|
||||
}
|
||||
|
||||
public void Stop( int x, int y )
|
||||
{
|
||||
if ( !m_Running )
|
||||
return;
|
||||
|
||||
m_Mobile.ClearQuestArrow();
|
||||
|
||||
NetState ns = m_Mobile.NetState;
|
||||
|
||||
if ( ns != null ) {
|
||||
if ( ns.HighSeas )
|
||||
ns.Send( new CancelArrowHS( x, y, m_Target.Serial ) );
|
||||
else
|
||||
ns.Send( new CancelArrow() );
|
||||
}
|
||||
|
||||
m_Running = false;
|
||||
OnStop();
|
||||
}
|
||||
|
||||
public virtual void OnStop()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnClick( bool rightClick )
|
||||
{
|
||||
}
|
||||
|
||||
public QuestArrow( Mobile m, Mobile t )
|
||||
{
|
||||
m_Running = true;
|
||||
m_Mobile = m;
|
||||
m_Target = t;
|
||||
}
|
||||
|
||||
public QuestArrow( Mobile m, Mobile t, int x, int y ) : this( m, t )
|
||||
{
|
||||
Update( x, y );
|
||||
}
|
||||
}
|
||||
}
|
||||
211
Source/Race.cs
Normal file
211
Source/Race.cs
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
/***************************************************************************
|
||||
* Race.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
[Parsable]
|
||||
public abstract class Race
|
||||
{
|
||||
public static Race DefaultRace { get { return m_Races[0]; } }
|
||||
|
||||
private static Race[] m_Races = new Race[0x100];
|
||||
|
||||
public static Race[] Races { get { return m_Races; } }
|
||||
|
||||
public static Race Human { get { return m_Races[0]; } }
|
||||
public static Race Orc { get { return m_Races[1]; } }
|
||||
|
||||
private static List<Race> m_AllRaces = new List<Race>();
|
||||
|
||||
public static List<Race> AllRaces { get { return m_AllRaces; } }
|
||||
|
||||
private int m_RaceID, m_RaceIndex;
|
||||
|
||||
private string m_Name, m_PluralName;
|
||||
|
||||
private static string[] m_RaceNames;
|
||||
private static Race[] m_RaceValues;
|
||||
|
||||
public static string[] GetRaceNames()
|
||||
{
|
||||
CheckNamesAndValues();
|
||||
return m_RaceNames;
|
||||
}
|
||||
|
||||
public static Race[] GetRaceValues()
|
||||
{
|
||||
CheckNamesAndValues();
|
||||
return m_RaceValues;
|
||||
}
|
||||
|
||||
public static Race Parse( string value )
|
||||
{
|
||||
CheckNamesAndValues();
|
||||
|
||||
for( int i = 0; i < m_RaceNames.Length; ++i )
|
||||
{
|
||||
if( Insensitive.Equals( m_RaceNames[i], value ) )
|
||||
return m_RaceValues[i];
|
||||
}
|
||||
|
||||
int index;
|
||||
if( int.TryParse( value, out index ) )
|
||||
{
|
||||
if( index >= 0 && index < m_Races.Length && m_Races[index] != null )
|
||||
return m_Races[index];
|
||||
}
|
||||
|
||||
throw new ArgumentException( "Invalid race name" );
|
||||
}
|
||||
|
||||
private static void CheckNamesAndValues()
|
||||
{
|
||||
if( m_RaceNames != null && m_RaceNames.Length == m_AllRaces.Count )
|
||||
return;
|
||||
|
||||
m_RaceNames = new string[m_AllRaces.Count];
|
||||
m_RaceValues = new Race[m_AllRaces.Count];
|
||||
|
||||
for( int i = 0; i < m_AllRaces.Count; ++i )
|
||||
{
|
||||
Race race = m_AllRaces[i];
|
||||
|
||||
m_RaceNames[i] = race.Name;
|
||||
m_RaceValues[i] = race;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
|
||||
private int m_MaleBody, m_FemaleBody, m_MaleGhostBody, m_FemaleGhostBody;
|
||||
|
||||
private Expansion m_RequiredExpansion;
|
||||
|
||||
public Expansion RequiredExpansion { get { return m_RequiredExpansion; } }
|
||||
|
||||
public int MaleBody { get { return m_MaleBody; } }
|
||||
public int MaleGhostBody { get { return m_MaleGhostBody; } }
|
||||
|
||||
public int FemaleBody { get { return m_FemaleBody; } }
|
||||
public int FemaleGhostBody { get { return m_FemaleGhostBody; } }
|
||||
|
||||
protected Race( int raceID, int raceIndex, string name, string pluralName, int maleBody, int femaleBody, int maleGhostBody, int femaleGhostBody, Expansion requiredExpansion )
|
||||
{
|
||||
m_RaceID = raceID;
|
||||
m_RaceIndex = raceIndex;
|
||||
|
||||
m_Name = name;
|
||||
|
||||
m_MaleBody = maleBody;
|
||||
m_FemaleBody = femaleBody;
|
||||
m_MaleGhostBody = maleGhostBody;
|
||||
m_FemaleGhostBody = femaleGhostBody;
|
||||
|
||||
m_RequiredExpansion = requiredExpansion;
|
||||
m_PluralName = pluralName;
|
||||
}
|
||||
|
||||
public virtual bool ValidateHair( Mobile m, int itemID ) { return ValidateHair( m.Female, itemID ); }
|
||||
public abstract bool ValidateHair( bool female, int itemID );
|
||||
|
||||
public virtual int RandomHair( Mobile m ) { return RandomHair( m.Female ); }
|
||||
public abstract int RandomHair( bool female );
|
||||
|
||||
public virtual bool ValidateFacialHair( Mobile m, int itemID ) { return ValidateFacialHair( m.Female, itemID ); }
|
||||
public abstract bool ValidateFacialHair( bool female, int itemID );
|
||||
|
||||
public virtual int RandomFacialHair( Mobile m ) { return RandomFacialHair( m.Female ); }
|
||||
public abstract int RandomFacialHair( bool female ); //For the *ahem* bearded ladies
|
||||
|
||||
public abstract int ClipSkinHue( int hue );
|
||||
public abstract int RandomSkinHue();
|
||||
|
||||
public abstract int ClipHairHue( int hue );
|
||||
public abstract int RandomHairHue();
|
||||
|
||||
public virtual int Body( Mobile m )
|
||||
{
|
||||
if( m.Alive )
|
||||
return AliveBody( m.Female );
|
||||
|
||||
return GhostBody( m.Female );
|
||||
}
|
||||
|
||||
public virtual int AliveBody( Mobile m ) { return AliveBody( m.Female ); }
|
||||
public virtual int AliveBody( bool female )
|
||||
{
|
||||
return (female ? m_FemaleBody : m_MaleBody);
|
||||
}
|
||||
|
||||
public virtual int GhostBody( Mobile m ) { return GhostBody( m.Female ); }
|
||||
public virtual int GhostBody( bool female )
|
||||
{
|
||||
return (female ? m_FemaleGhostBody : m_MaleGhostBody);
|
||||
}
|
||||
|
||||
public int RaceID
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_RaceID;
|
||||
}
|
||||
}
|
||||
|
||||
public int RaceIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_RaceIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Name = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string PluralName
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_PluralName;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_PluralName = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1277
Source/Region.cs
Normal file
1277
Source/Region.cs
Normal file
File diff suppressed because it is too large
Load diff
649
Source/ScriptCompiler.cs
Normal file
649
Source/ScriptCompiler.cs
Normal file
|
|
@ -0,0 +1,649 @@
|
|||
/***************************************************************************
|
||||
* ScriptCompiler.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using Microsoft.CSharp;
|
||||
using Microsoft.VisualBasic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public static class ScriptCompiler
|
||||
{
|
||||
private static Assembly[] m_Assemblies;
|
||||
|
||||
public static Assembly[] Assemblies
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Assemblies;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Assemblies = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<string> m_AdditionalReferences = new List<string>();
|
||||
|
||||
public static string[] GetReferenceAssemblies()
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
|
||||
string path = Path.Combine( Core.BaseDirectory, "Data/Config/Assemblies.cfg" );
|
||||
|
||||
if( File.Exists( path ) )
|
||||
{
|
||||
using( StreamReader ip = new StreamReader( path ) )
|
||||
{
|
||||
string line;
|
||||
|
||||
while( (line = ip.ReadLine()) != null )
|
||||
{
|
||||
if( line.Length > 0 && !line.StartsWith( "#" ) )
|
||||
list.Add( line );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
list.Add( Core.ExePath );
|
||||
|
||||
list.AddRange( m_AdditionalReferences );
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static string GetDefines()
|
||||
{
|
||||
StringBuilder sb = null;
|
||||
|
||||
#if MONO
|
||||
AppendDefine( ref sb, "/d:MONO" );
|
||||
#endif
|
||||
|
||||
//These two defines are legacy, ie, depreciated.
|
||||
if( Core.Is64Bit )
|
||||
AppendDefine( ref sb, "/d:x64" );
|
||||
|
||||
AppendDefine( ref sb, "/d:Framework_2_0" );
|
||||
|
||||
#if Framework_4_0
|
||||
AppendDefine( ref sb, "/d:Framework_4_0" );
|
||||
#endif
|
||||
|
||||
return (sb == null ? null : sb.ToString());
|
||||
}
|
||||
|
||||
public static void AppendDefine( ref StringBuilder sb, string define )
|
||||
{
|
||||
if( sb == null )
|
||||
sb = new StringBuilder();
|
||||
else
|
||||
sb.Append( ' ' );
|
||||
|
||||
sb.Append( define );
|
||||
}
|
||||
|
||||
private static byte[] GetHashCode( string compiledFile, string[] scriptFiles, bool debug )
|
||||
{
|
||||
using( MemoryStream ms = new MemoryStream() )
|
||||
{
|
||||
using( BinaryWriter bin = new BinaryWriter( ms ) )
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo( compiledFile );
|
||||
|
||||
bin.Write( fileInfo.LastWriteTimeUtc.Ticks );
|
||||
|
||||
foreach( string scriptFile in scriptFiles )
|
||||
{
|
||||
fileInfo = new FileInfo( scriptFile );
|
||||
|
||||
bin.Write( fileInfo.LastWriteTimeUtc.Ticks );
|
||||
}
|
||||
|
||||
bin.Write( debug );
|
||||
bin.Write( Core.Version.ToString() );
|
||||
|
||||
ms.Position = 0;
|
||||
|
||||
using( SHA1 sha1 = SHA1.Create() )
|
||||
{
|
||||
return sha1.ComputeHash( ms );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CompileCSScripts( out Assembly assembly )
|
||||
{
|
||||
return CompileCSScripts( false, true, out assembly );
|
||||
}
|
||||
|
||||
public static bool CompileCSScripts( bool debug, out Assembly assembly )
|
||||
{
|
||||
return CompileCSScripts( debug, true, out assembly );
|
||||
}
|
||||
|
||||
public static bool CompileCSScripts( bool debug, bool cache, out Assembly assembly )
|
||||
{
|
||||
Console.Write( "Scripts: Compiling C# scripts..." );
|
||||
string[] files = GetScripts( "*.cs" );
|
||||
|
||||
if( files.Length == 0 )
|
||||
{
|
||||
Console.WriteLine( "no files found." );
|
||||
assembly = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
if( File.Exists( "Scripts/Output/Scripts.CS.dll" ) )
|
||||
{
|
||||
if( cache && File.Exists( "Scripts/Output/Scripts.CS.hash" ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] hashCode = GetHashCode( "Scripts/Output/Scripts.CS.dll", files, debug );
|
||||
|
||||
using( FileStream fs = new FileStream( "Scripts/Output/Scripts.CS.hash", FileMode.Open, FileAccess.Read, FileShare.Read ) )
|
||||
{
|
||||
using( BinaryReader bin = new BinaryReader( fs ) )
|
||||
{
|
||||
byte[] bytes = bin.ReadBytes( hashCode.Length );
|
||||
|
||||
if( bytes.Length == hashCode.Length )
|
||||
{
|
||||
bool valid = true;
|
||||
|
||||
for( int i = 0; i < bytes.Length; ++i )
|
||||
{
|
||||
if( bytes[i] != hashCode[i] )
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( valid )
|
||||
{
|
||||
assembly = Assembly.LoadFrom( "Scripts/Output/Scripts.CS.dll" );
|
||||
|
||||
if( !m_AdditionalReferences.Contains( assembly.Location ) )
|
||||
{
|
||||
m_AdditionalReferences.Add( assembly.Location );
|
||||
}
|
||||
|
||||
Console.WriteLine( "done (cached)" );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DeleteFiles( "Scripts.CS*.dll" );
|
||||
|
||||
using ( CSharpCodeProvider provider = new CSharpCodeProvider() )
|
||||
{
|
||||
string path = GetUnusedPath( "Scripts.CS" );
|
||||
|
||||
CompilerParameters parms = new CompilerParameters( GetReferenceAssemblies(), path, debug );
|
||||
|
||||
string defines = GetDefines();
|
||||
|
||||
if( defines != null )
|
||||
parms.CompilerOptions = defines;
|
||||
|
||||
if( Core.HaltOnWarning )
|
||||
parms.WarningLevel = 4;
|
||||
|
||||
#if !MONO
|
||||
CompilerResults results = provider.CompileAssemblyFromFile( parms, files );
|
||||
#else
|
||||
parms.CompilerOptions = String.Format( "{0} /nowarn:169,219,414 /recurse:Scripts/*.cs", parms.CompilerOptions );
|
||||
CompilerResults results = provider.CompileAssemblyFromFile( parms, files );
|
||||
#endif
|
||||
m_AdditionalReferences.Add( path );
|
||||
|
||||
Display( results );
|
||||
|
||||
#if !MONO
|
||||
if( results.Errors.Count > 0 )
|
||||
{
|
||||
assembly = null;
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
if( results.Errors.Count > 0 ) {
|
||||
foreach( CompilerError err in results.Errors ) {
|
||||
if ( !err.IsWarning ) {
|
||||
assembly = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if( cache && Path.GetFileName( path ) == "Scripts.CS.dll" )
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] hashCode = GetHashCode( path, files, debug );
|
||||
|
||||
using( FileStream fs = new FileStream( "Scripts/Output/Scripts.CS.hash", FileMode.Create, FileAccess.Write, FileShare.None ) )
|
||||
{
|
||||
using( BinaryWriter bin = new BinaryWriter( fs ) )
|
||||
{
|
||||
bin.Write( hashCode, 0, hashCode.Length );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
assembly = results.CompiledAssembly;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Display( CompilerResults results )
|
||||
{
|
||||
if( results.Errors.Count > 0 )
|
||||
{
|
||||
Dictionary<string, List<CompilerError>> errors = new Dictionary<string, List<CompilerError>>( results.Errors.Count, StringComparer.OrdinalIgnoreCase );
|
||||
Dictionary<string, List<CompilerError>> warnings = new Dictionary<string, List<CompilerError>>( results.Errors.Count, StringComparer.OrdinalIgnoreCase );
|
||||
|
||||
foreach( CompilerError e in results.Errors )
|
||||
{
|
||||
string file = e.FileName;
|
||||
|
||||
// Ridiculous. FileName is null if the warning/error is internally generated in csc.
|
||||
if ( string.IsNullOrEmpty( file ) ) {
|
||||
Console.WriteLine( "ScriptCompiler: {0}: {1}", e.ErrorNumber, e.ErrorText );
|
||||
continue;
|
||||
}
|
||||
|
||||
Dictionary<string, List<CompilerError>> table = (e.IsWarning ? warnings : errors);
|
||||
|
||||
List<CompilerError> list = null;
|
||||
table.TryGetValue( file, out list );
|
||||
|
||||
if( list == null )
|
||||
table[file] = list = new List<CompilerError>();
|
||||
|
||||
list.Add( e );
|
||||
}
|
||||
|
||||
if( errors.Count > 0 )
|
||||
Console.WriteLine( "failed ({0} errors, {1} warnings)", errors.Count, warnings.Count );
|
||||
else
|
||||
Console.WriteLine( "done ({0} errors, {1} warnings)", errors.Count, warnings.Count );
|
||||
|
||||
string scriptRoot = Path.GetFullPath( Path.Combine( Core.BaseDirectory, "Scripts" + Path.DirectorySeparatorChar ) );
|
||||
Uri scriptRootUri = new Uri( scriptRoot );
|
||||
|
||||
Utility.PushColor( ConsoleColor.Yellow );
|
||||
|
||||
if( warnings.Count > 0 )
|
||||
Console.WriteLine( "Warnings:" );
|
||||
|
||||
foreach( KeyValuePair<string, List<CompilerError>> kvp in warnings )
|
||||
{
|
||||
string fileName = kvp.Key;
|
||||
List<CompilerError> list = kvp.Value;
|
||||
|
||||
string fullPath = Path.GetFullPath( fileName );
|
||||
string usedPath = Uri.UnescapeDataString( scriptRootUri.MakeRelativeUri( new Uri( fullPath ) ).OriginalString );
|
||||
|
||||
Console.WriteLine( " + {0}:", usedPath );
|
||||
|
||||
Utility.PushColor( ConsoleColor.DarkYellow );
|
||||
|
||||
foreach( CompilerError e in list )
|
||||
Console.WriteLine( " {0}: Line {1}: {3}", e.ErrorNumber, e.Line, e.Column, e.ErrorText );
|
||||
|
||||
Utility.PopColor();
|
||||
}
|
||||
|
||||
Utility.PopColor();
|
||||
|
||||
Utility.PushColor( ConsoleColor.Red );
|
||||
|
||||
if( errors.Count > 0 )
|
||||
Console.WriteLine( "Errors:" );
|
||||
|
||||
foreach( KeyValuePair<string, List<CompilerError>> kvp in errors )
|
||||
{
|
||||
string fileName = kvp.Key;
|
||||
List<CompilerError> list = kvp.Value;
|
||||
|
||||
string fullPath = Path.GetFullPath( fileName );
|
||||
string usedPath = Uri.UnescapeDataString( scriptRootUri.MakeRelativeUri( new Uri( fullPath ) ).OriginalString );
|
||||
|
||||
Console.WriteLine( " + {0}:", usedPath );
|
||||
|
||||
Utility.PushColor( ConsoleColor.DarkRed );
|
||||
|
||||
foreach( CompilerError e in list )
|
||||
Console.WriteLine( " {0}: Line {1}: {3}", e.ErrorNumber, e.Line, e.Column, e.ErrorText );
|
||||
|
||||
Utility.PopColor();
|
||||
}
|
||||
|
||||
Utility.PopColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine( "done (0 errors, 0 warnings)" );
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetUnusedPath( string name )
|
||||
{
|
||||
string path = Path.Combine( Core.BaseDirectory, String.Format( "Scripts/Output/{0}.dll", name ) );
|
||||
|
||||
for( int i = 2; File.Exists( path ) && i <= 1000; ++i )
|
||||
path = Path.Combine( Core.BaseDirectory, String.Format( "Scripts/Output/{0}.{1}.dll", name, i ) );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static void DeleteFiles( string mask )
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] files = Directory.GetFiles( Path.Combine( Core.BaseDirectory, "Scripts/Output" ), mask );
|
||||
|
||||
foreach( string file in files )
|
||||
{
|
||||
try { File.Delete( file ); }
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private delegate CompilerResults Compiler( bool debug );
|
||||
|
||||
public static bool Compile()
|
||||
{
|
||||
return Compile( false );
|
||||
}
|
||||
|
||||
public static bool Compile( bool debug )
|
||||
{
|
||||
return Compile( debug, true );
|
||||
}
|
||||
|
||||
public static bool Compile( bool debug, bool cache )
|
||||
{
|
||||
EnsureDirectory( "Scripts/" );
|
||||
EnsureDirectory( "Scripts/Output/" );
|
||||
|
||||
if( m_AdditionalReferences.Count > 0 )
|
||||
m_AdditionalReferences.Clear();
|
||||
|
||||
List<Assembly> assemblies = new List<Assembly>();
|
||||
|
||||
Assembly assembly;
|
||||
|
||||
if( CompileCSScripts( debug, cache, out assembly ) )
|
||||
{
|
||||
if( assembly != null )
|
||||
{
|
||||
assemblies.Add( assembly );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( assemblies.Count == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Assemblies = assemblies.ToArray();
|
||||
|
||||
Console.Write( "Scripts: Verifying..." );
|
||||
|
||||
Stopwatch watch = Stopwatch.StartNew();
|
||||
|
||||
Core.VerifySerialization();
|
||||
|
||||
watch.Stop();
|
||||
|
||||
Console.WriteLine("done ({0} items, {1} mobiles) ({2:F2} seconds)", Core.ScriptItems, Core.ScriptMobiles, watch.Elapsed.TotalSeconds);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Invoke( string method )
|
||||
{
|
||||
List<MethodInfo> invoke = new List<MethodInfo>();
|
||||
|
||||
for( int a = 0; a < m_Assemblies.Length; ++a )
|
||||
{
|
||||
Type[] types = m_Assemblies[a].GetTypes();
|
||||
|
||||
for( int i = 0; i < types.Length; ++i )
|
||||
{
|
||||
MethodInfo m = types[i].GetMethod( method, BindingFlags.Static | BindingFlags.Public );
|
||||
|
||||
if( m != null )
|
||||
invoke.Add( m );
|
||||
}
|
||||
}
|
||||
|
||||
invoke.Sort( new CallPriorityComparer() );
|
||||
|
||||
for( int i = 0; i < invoke.Count; ++i )
|
||||
invoke[i].Invoke( null, null );
|
||||
}
|
||||
|
||||
private static Dictionary<Assembly, TypeCache> m_TypeCaches = new Dictionary<Assembly, TypeCache>();
|
||||
private static TypeCache m_NullCache;
|
||||
|
||||
public static TypeCache GetTypeCache( Assembly asm )
|
||||
{
|
||||
if( asm == null )
|
||||
{
|
||||
if( m_NullCache == null )
|
||||
m_NullCache = new TypeCache( null );
|
||||
|
||||
return m_NullCache;
|
||||
}
|
||||
|
||||
TypeCache c = null;
|
||||
m_TypeCaches.TryGetValue( asm, out c );
|
||||
|
||||
if( c == null )
|
||||
m_TypeCaches[asm] = c = new TypeCache( asm );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Type FindTypeByFullName( string fullName )
|
||||
{
|
||||
return FindTypeByFullName( fullName, true );
|
||||
}
|
||||
|
||||
public static Type FindTypeByFullName( string fullName, bool ignoreCase )
|
||||
{
|
||||
Type type = null;
|
||||
|
||||
for( int i = 0; type == null && i < m_Assemblies.Length; ++i )
|
||||
type = GetTypeCache( m_Assemblies[i] ).GetTypeByFullName( fullName, ignoreCase );
|
||||
|
||||
if( type == null )
|
||||
type = GetTypeCache( Core.Assembly ).GetTypeByFullName( fullName, ignoreCase );
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public static Type FindTypeByName( string name )
|
||||
{
|
||||
return FindTypeByName( name, true );
|
||||
}
|
||||
|
||||
public static Type FindTypeByName( string name, bool ignoreCase )
|
||||
{
|
||||
Type type = null;
|
||||
|
||||
for( int i = 0; type == null && i < m_Assemblies.Length; ++i )
|
||||
type = GetTypeCache( m_Assemblies[i] ).GetTypeByName( name, ignoreCase );
|
||||
|
||||
if( type == null )
|
||||
type = GetTypeCache( Core.Assembly ).GetTypeByName( name, ignoreCase );
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public static void EnsureDirectory( string dir )
|
||||
{
|
||||
string path = Path.Combine( Core.BaseDirectory, dir );
|
||||
|
||||
if( !Directory.Exists( path ) )
|
||||
Directory.CreateDirectory( path );
|
||||
}
|
||||
|
||||
public static string[] GetScripts( string filter )
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
|
||||
GetScripts( list, Path.Combine( Core.BaseDirectory, "Scripts" ), filter );
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static void GetScripts( List<string> list, string path, string filter )
|
||||
{
|
||||
foreach( string dir in Directory.GetDirectories( path ) )
|
||||
GetScripts( list, dir, filter );
|
||||
|
||||
list.AddRange( Directory.GetFiles( path, filter ) );
|
||||
}
|
||||
}
|
||||
|
||||
public class TypeCache
|
||||
{
|
||||
private Type[] m_Types;
|
||||
private TypeTable m_Names, m_FullNames;
|
||||
|
||||
public Type[] Types { get { return m_Types; } }
|
||||
public TypeTable Names { get { return m_Names; } }
|
||||
public TypeTable FullNames { get { return m_FullNames; } }
|
||||
|
||||
public Type GetTypeByName( string name, bool ignoreCase )
|
||||
{
|
||||
return m_Names.Get( name, ignoreCase );
|
||||
}
|
||||
|
||||
public Type GetTypeByFullName( string fullName, bool ignoreCase )
|
||||
{
|
||||
return m_FullNames.Get( fullName, ignoreCase );
|
||||
}
|
||||
|
||||
public TypeCache( Assembly asm )
|
||||
{
|
||||
if( asm == null )
|
||||
m_Types = Type.EmptyTypes;
|
||||
else
|
||||
m_Types = asm.GetTypes();
|
||||
|
||||
m_Names = new TypeTable( m_Types.Length );
|
||||
m_FullNames = new TypeTable( m_Types.Length );
|
||||
|
||||
Type typeofTypeAliasAttribute = typeof( TypeAliasAttribute );
|
||||
|
||||
for( int i = 0; i < m_Types.Length; ++i )
|
||||
{
|
||||
Type type = m_Types[i];
|
||||
|
||||
m_Names.Add( type.Name, type );
|
||||
m_FullNames.Add( type.FullName, type );
|
||||
|
||||
if( type.IsDefined( typeofTypeAliasAttribute, false ) )
|
||||
{
|
||||
object[] attrs = type.GetCustomAttributes( typeofTypeAliasAttribute, false );
|
||||
|
||||
if( attrs != null && attrs.Length > 0 )
|
||||
{
|
||||
TypeAliasAttribute attr = attrs[0] as TypeAliasAttribute;
|
||||
|
||||
if( attr != null )
|
||||
{
|
||||
for( int j = 0; j < attr.Aliases.Length; ++j )
|
||||
m_FullNames.Add( attr.Aliases[j], type );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TypeTable
|
||||
{
|
||||
private Dictionary<string, Type> m_Sensitive, m_Insensitive;
|
||||
|
||||
public void Add( string key, Type type )
|
||||
{
|
||||
m_Sensitive[key] = type;
|
||||
m_Insensitive[key] = type;
|
||||
}
|
||||
|
||||
public Type Get( string key, bool ignoreCase )
|
||||
{
|
||||
Type t = null;
|
||||
|
||||
if( ignoreCase )
|
||||
m_Insensitive.TryGetValue( key, out t );
|
||||
else
|
||||
m_Sensitive.TryGetValue( key, out t );
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public TypeTable( int capacity )
|
||||
{
|
||||
m_Sensitive = new Dictionary<string, Type>( capacity );
|
||||
m_Insensitive = new Dictionary<string, Type>( capacity, StringComparer.OrdinalIgnoreCase );
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue