Cleanup/Housekeeping (#242)
This commit is contained in:
parent
90ede0659f
commit
741e8d8300
228 changed files with 6292 additions and 2690 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: BufferedFileWriter.cs *
|
||||
* *
|
||||
|
|
@ -59,14 +59,18 @@ namespace Server
|
|||
while (v >= 0x80)
|
||||
{
|
||||
if (m_Index + 1 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index++] = (byte)(v | 0x80);
|
||||
v >>= 7;
|
||||
}
|
||||
|
||||
if (m_Index + 1 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index++] = (byte)v;
|
||||
}
|
||||
|
|
@ -78,14 +82,18 @@ namespace Server
|
|||
if (value == null)
|
||||
{
|
||||
if (m_Index + 1 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index++] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Index + 1 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index++] = 1;
|
||||
|
||||
|
|
@ -143,13 +151,17 @@ namespace Server
|
|||
var bits = decimal.GetBits(value);
|
||||
|
||||
for (var i = 0; i < bits.Length; ++i)
|
||||
{
|
||||
Write(bits[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(long value)
|
||||
{
|
||||
if (m_Index + 8 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index] = (byte)value;
|
||||
Data[m_Index + 1] = (byte)(value >> 8);
|
||||
|
|
@ -165,7 +177,9 @@ namespace Server
|
|||
public void Write(ulong value)
|
||||
{
|
||||
if (m_Index + 8 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index] = (byte)value;
|
||||
Data[m_Index + 1] = (byte)(value >> 8);
|
||||
|
|
@ -181,7 +195,9 @@ namespace Server
|
|||
public void Write(int value)
|
||||
{
|
||||
if (m_Index + 4 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index] = (byte)value;
|
||||
Data[m_Index + 1] = (byte)(value >> 8);
|
||||
|
|
@ -193,7 +209,9 @@ namespace Server
|
|||
public void Write(uint value)
|
||||
{
|
||||
if (m_Index + 4 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index] = (byte)value;
|
||||
Data[m_Index + 1] = (byte)(value >> 8);
|
||||
|
|
@ -205,7 +223,9 @@ namespace Server
|
|||
public void Write(short value)
|
||||
{
|
||||
if (m_Index + 2 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index] = (byte)value;
|
||||
Data[m_Index + 1] = (byte)(value >> 8);
|
||||
|
|
@ -215,7 +235,9 @@ namespace Server
|
|||
public void Write(ushort value)
|
||||
{
|
||||
if (m_Index + 2 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index] = (byte)value;
|
||||
Data[m_Index + 1] = (byte)(value >> 8);
|
||||
|
|
@ -225,7 +247,9 @@ namespace Server
|
|||
public unsafe void Write(double value)
|
||||
{
|
||||
if (m_Index + 8 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
fixed (byte* pBuffer = Data)
|
||||
{
|
||||
|
|
@ -238,7 +262,9 @@ namespace Server
|
|||
public unsafe void Write(float value)
|
||||
{
|
||||
if (m_Index + 4 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
fixed (byte* pBuffer = Data)
|
||||
{
|
||||
|
|
@ -251,7 +277,9 @@ namespace Server
|
|||
public void Write(char value)
|
||||
{
|
||||
if (m_Index + 8 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
m_SingleCharBuffer[0] = value;
|
||||
|
||||
|
|
@ -262,7 +290,9 @@ namespace Server
|
|||
public void Write(byte value)
|
||||
{
|
||||
if (m_Index + 1 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index++] = value;
|
||||
}
|
||||
|
|
@ -275,7 +305,9 @@ namespace Server
|
|||
public void Write(byte[] value, int length)
|
||||
{
|
||||
while (m_Index + length > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Buffer.BlockCopy(value, 0, Data, m_Index, length);
|
||||
m_Index += length;
|
||||
|
|
@ -284,7 +316,9 @@ namespace Server
|
|||
public void Write(sbyte value)
|
||||
{
|
||||
if (m_Index + 1 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index++] = (byte)value;
|
||||
}
|
||||
|
|
@ -292,7 +326,9 @@ namespace Server
|
|||
public void Write(bool value)
|
||||
{
|
||||
if (m_Index + 1 > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Data[m_Index++] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
|
@ -325,17 +361,25 @@ namespace Server
|
|||
public void Write(Map value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
Write((byte)value.MapIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
Write((byte)0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(Race value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
Write((byte)value.RaceIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
Write((byte)0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteEntity(IEntity value)
|
||||
|
|
@ -356,9 +400,13 @@ namespace Server
|
|||
public void Write(BaseGuild value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
Write(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Write(value.Serial);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteItem<T>(T value) where T : Item
|
||||
|
|
@ -394,16 +442,26 @@ namespace Server
|
|||
public void WriteItemList<T>(List<T> list, bool tidy) where T : Item
|
||||
{
|
||||
if (tidy)
|
||||
{
|
||||
for (var i = 0; i < list.Count;)
|
||||
{
|
||||
if (list[i].Deleted)
|
||||
{
|
||||
list.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write(list.Count);
|
||||
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
{
|
||||
Write(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(HashSet<Item> set)
|
||||
|
|
@ -413,11 +471,17 @@ namespace Server
|
|||
|
||||
public void Write(HashSet<Item> set, bool tidy)
|
||||
{
|
||||
if (tidy) set.RemoveWhere(item => item.Deleted);
|
||||
if (tidy)
|
||||
{
|
||||
set.RemoveWhere(item => item.Deleted);
|
||||
}
|
||||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (var item in set) Write(item);
|
||||
foreach (var item in set)
|
||||
{
|
||||
Write(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteItemSet<T>(HashSet<T> set) where T : Item
|
||||
|
|
@ -427,11 +491,17 @@ namespace Server
|
|||
|
||||
public void WriteItemSet<T>(HashSet<T> set, bool tidy) where T : Item
|
||||
{
|
||||
if (tidy) set.RemoveWhere(item => item.Deleted);
|
||||
if (tidy)
|
||||
{
|
||||
set.RemoveWhere(item => item.Deleted);
|
||||
}
|
||||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (var item in set) Write(item);
|
||||
foreach (var item in set)
|
||||
{
|
||||
Write(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(List<Mobile> list)
|
||||
|
|
@ -442,16 +512,26 @@ namespace Server
|
|||
public void Write(List<Mobile> list, bool tidy)
|
||||
{
|
||||
if (tidy)
|
||||
{
|
||||
for (var i = 0; i < list.Count;)
|
||||
{
|
||||
if (list[i].Deleted)
|
||||
{
|
||||
list.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write(list.Count);
|
||||
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
{
|
||||
Write(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteMobileList<T>(List<T> list) where T : Mobile
|
||||
|
|
@ -462,16 +542,26 @@ namespace Server
|
|||
public void WriteMobileList<T>(List<T> list, bool tidy) where T : Mobile
|
||||
{
|
||||
if (tidy)
|
||||
{
|
||||
for (var i = 0; i < list.Count;)
|
||||
{
|
||||
if (list[i].Deleted)
|
||||
{
|
||||
list.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write(list.Count);
|
||||
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
{
|
||||
Write(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(HashSet<Mobile> set)
|
||||
|
|
@ -481,11 +571,17 @@ namespace Server
|
|||
|
||||
public void Write(HashSet<Mobile> set, bool tidy)
|
||||
{
|
||||
if (tidy) set.RemoveWhere(mobile => mobile.Deleted);
|
||||
if (tidy)
|
||||
{
|
||||
set.RemoveWhere(mobile => mobile.Deleted);
|
||||
}
|
||||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (var mob in set) Write(mob);
|
||||
foreach (var mob in set)
|
||||
{
|
||||
Write(mob);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteMobileSet<T>(HashSet<T> set) where T : Mobile
|
||||
|
|
@ -495,11 +591,17 @@ namespace Server
|
|||
|
||||
public void WriteMobileSet<T>(HashSet<T> set, bool tidy) where T : Mobile
|
||||
{
|
||||
if (tidy) set.RemoveWhere(mob => mob.Deleted);
|
||||
if (tidy)
|
||||
{
|
||||
set.RemoveWhere(mob => mob.Deleted);
|
||||
}
|
||||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (var mob in set) Write(mob);
|
||||
foreach (var mob in set)
|
||||
{
|
||||
Write(mob);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(List<BaseGuild> list)
|
||||
|
|
@ -510,16 +612,26 @@ namespace Server
|
|||
public void Write(List<BaseGuild> list, bool tidy)
|
||||
{
|
||||
if (tidy)
|
||||
{
|
||||
for (var i = 0; i < list.Count;)
|
||||
{
|
||||
if (list[i].Disbanded)
|
||||
{
|
||||
list.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write(list.Count);
|
||||
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
{
|
||||
Write(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteGuildList<T>(List<T> list) where T : BaseGuild
|
||||
|
|
@ -530,16 +642,26 @@ namespace Server
|
|||
public void WriteGuildList<T>(List<T> list, bool tidy) where T : BaseGuild
|
||||
{
|
||||
if (tidy)
|
||||
{
|
||||
for (var i = 0; i < list.Count;)
|
||||
{
|
||||
if (list[i].Disbanded)
|
||||
{
|
||||
list.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write(list.Count);
|
||||
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
{
|
||||
Write(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(HashSet<BaseGuild> set)
|
||||
|
|
@ -549,11 +671,17 @@ namespace Server
|
|||
|
||||
public void Write(HashSet<BaseGuild> set, bool tidy)
|
||||
{
|
||||
if (tidy) set.RemoveWhere(guild => guild.Disbanded);
|
||||
if (tidy)
|
||||
{
|
||||
set.RemoveWhere(guild => guild.Disbanded);
|
||||
}
|
||||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (var guild in set) Write(guild);
|
||||
foreach (var guild in set)
|
||||
{
|
||||
Write(guild);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteGuildSet<T>(HashSet<T> set) where T : BaseGuild
|
||||
|
|
@ -563,11 +691,17 @@ namespace Server
|
|||
|
||||
public void WriteGuildSet<T>(HashSet<T> set, bool tidy) where T : BaseGuild
|
||||
{
|
||||
if (tidy) set.RemoveWhere(guild => guild.Disbanded);
|
||||
if (tidy)
|
||||
{
|
||||
set.RemoveWhere(guild => guild.Disbanded);
|
||||
}
|
||||
|
||||
Write(set.Count);
|
||||
|
||||
foreach (var guild in set) Write(guild);
|
||||
foreach (var guild in set)
|
||||
{
|
||||
Write(guild);
|
||||
}
|
||||
}
|
||||
|
||||
public void Flush()
|
||||
|
|
@ -605,7 +739,9 @@ namespace Server
|
|||
var byteLength = m_Encoding.GetBytes(value, current, charCount, m_CharacterBuffer, 0);
|
||||
|
||||
if (m_Index + byteLength > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Buffer.BlockCopy(m_CharacterBuffer, 0, Data, m_Index, byteLength);
|
||||
m_Index += byteLength;
|
||||
|
|
@ -619,7 +755,9 @@ namespace Server
|
|||
var byteLength = m_Encoding.GetBytes(value, 0, value.Length, m_CharacterBuffer, 0);
|
||||
|
||||
if (m_Index + byteLength > Data.Length)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
Buffer.BlockCopy(m_CharacterBuffer, 0, Data, m_Index, byteLength);
|
||||
m_Index += byteLength;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue