Skip to content

Commit

Permalink
- NEW FEATURE: Localization (Translations for Auth server will be pos…
Browse files Browse the repository at this point in the history
…sible soon)

-- You can add/change Localizations in the Content/Lang/ folder
-- move hardcoded strings to English.xml and add it to the LangKey enum
-- See LocalizerCommand for examples
- added World.Pause()
- fixed World.Paused
- more
  • Loading branch information
Domiii committed May 29, 2010
1 parent 3c5c0a9 commit 33875e7
Show file tree
Hide file tree
Showing 82 changed files with 1,279 additions and 469 deletions.
4 changes: 2 additions & 2 deletions Addons/WCell.DefaultAddon/Commands/AddonDevCommands.cs
Expand Up @@ -30,7 +30,7 @@ public class SampleNPCCommand : SubCommand
protected override void Initialize() protected override void Initialize()
{ {
Init("NPC"); Init("NPC");
ParamInfo = "[-f]"; EnglishParamInfo = "[-f]";
EnglishDescription = "Adds a sample NPC. -f makes it friendly."; EnglishDescription = "Adds a sample NPC. -f makes it friendly.";
} }


Expand Down Expand Up @@ -63,7 +63,7 @@ public class SampleBowCommand : SubCommand
protected override void Initialize() protected override void Initialize()
{ {
Init("Bow"); Init("Bow");
ParamInfo = "[-ea] [<amount>]"; EnglishParamInfo = "[-ea] [<amount>]";
EnglishDescription = "Adds a sample Bow." + EnglishDescription = "Adds a sample Bow." +
"-a switch auto-equips, -e switch only adds if not already present."; "-a switch auto-equips, -e switch only adds if not already present.";
} }
Expand Down
4 changes: 3 additions & 1 deletion Applications/WCell.RealmServerConsole/Program.cs
Expand Up @@ -19,6 +19,8 @@
using NLog; using NLog;
using System.Runtime; using System.Runtime;
using System.Threading; using System.Threading;
using WCell.RealmServer.Lang;
using WCell.Util.Lang;
using WCell.Util.NLog; using WCell.Util.NLog;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;


Expand All @@ -29,7 +31,7 @@ internal class Program
private static readonly Logger log = LogManager.GetCurrentClassLogger(); private static readonly Logger log = LogManager.GetCurrentClassLogger();


private static void Main(string[] args) private static void Main(string[] args)
{ {
if (GCSettings.IsServerGC) if (GCSettings.IsServerGC)
{ {
GCSettings.LatencyMode = GCLatencyMode.Batch; GCSettings.LatencyMode = GCLatencyMode.Batch;
Expand Down
Expand Up @@ -155,6 +155,7 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
Expand All @@ -168,27 +169,27 @@
<ProjectReference Include="..\..\Core\Cell.Core\Cell.Core.csproj"> <ProjectReference Include="..\..\Core\Cell.Core\Cell.Core.csproj">
<Project>{71AB07AD-4D94-4693-8560-47862E5B6E61}</Project> <Project>{71AB07AD-4D94-4693-8560-47862E5B6E61}</Project>
<Name>Cell.Core</Name> <Name>Cell.Core</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\Core\WCell.Core\WCell.Core.csproj"> <ProjectReference Include="..\..\Core\WCell.Core\WCell.Core.csproj">
<Project>{EEA9DEB6-8EA6-46F1-B1B7-AB38D8BBCA6C}</Project> <Project>{EEA9DEB6-8EA6-46F1-B1B7-AB38D8BBCA6C}</Project>
<Name>WCell.Core</Name> <Name>WCell.Core</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\Core\WCell.Intercommunication\WCell.Intercommunication.csproj"> <ProjectReference Include="..\..\Core\WCell.Intercommunication\WCell.Intercommunication.csproj">
<Project>{5997613F-D2A5-4B86-BEE2-C823BC07D5AF}</Project> <Project>{5997613F-D2A5-4B86-BEE2-C823BC07D5AF}</Project>
<Name>WCell.Intercommunication</Name> <Name>WCell.Intercommunication</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\Services\WCell.RealmServer\WCell.RealmServer.csproj"> <ProjectReference Include="..\..\Services\WCell.RealmServer\WCell.RealmServer.csproj">
<Project>{A38FAA6D-86B5-4429-85D0-BC93EB5E2C56}</Project> <Project>{A38FAA6D-86B5-4429-85D0-BC93EB5E2C56}</Project>
<Name>WCell.RealmServer</Name> <Name>WCell.RealmServer</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\Utilities\WCell.Util\WCell.Util.csproj"> <ProjectReference Include="..\..\Utilities\WCell.Util\WCell.Util.csproj">
<Project>{F753AF28-A251-4C12-9335-07E8236184F2}</Project> <Project>{F753AF28-A251-4C12-9335-07E8236184F2}</Project>
<Name>WCell.Util</Name> <Name>WCell.Util</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
Expand Down
31 changes: 22 additions & 9 deletions Applications/WCell.RealmServerConsole/app.config
@@ -1,27 +1,40 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<configuration> <configuration>
<configSections> <configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/> <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections> </configSections>
<runtime> <runtime>
<gcServer enabled="true"/> <gcServer enabled="true" />
</runtime> </runtime>
<appSettings> <appSettings>
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings> </appSettings>
<nlog autoReload="true"> <nlog autoReload="true">
<variable name="logDirectory" value="${basedir}\logs"/> <variable name="logDirectory" value="${basedir}\logs" />
<variable name="normalRealmServerLog" value="realmServer-${level}.wcelllog"/> <variable name="normalRealmServerLog" value="realmServer-${level}.wcelllog" />
<variable name="archiveRealmServerLog" value="realmServer-${level}-{#####}.wcelllog"/> <variable name="archiveRealmServerLog" value="realmServer-${level}-{#####}.wcelllog" />
<targets> <targets>
<target name="console" type="AsyncWrapper"> <target name="console" type="AsyncWrapper">
<target type="ColoredConsole" layout="(${processtime}) [${level}] ${message} ${exception:format=tostring}"/> <target type="ColoredConsole" layout="(${processtime}) [${level}] ${message} ${exception:format=tostring}" />
</target> </target>
<target name="file" type="AsyncWrapper"> <target name="file" type="AsyncWrapper">
<target type="File" fileName="${logDirectory}\${normalRealmServerLog}" encoding="utf-8" archiveEvery="ArchiveEveryMode.Day" archiveFileName="${logDirectory}\${archiveRealmServerLog}" archiveNumbering="ArchiveNumberingMode.Rolling" maxArchiveFiles="10000" layout="(${longdate}) [${level}] ${message} ${exception:format=tostring}"/> <target type="File" fileName="${logDirectory}\${normalRealmServerLog}" encoding="utf-8" archiveEvery="ArchiveEveryMode.Day" archiveFileName="${logDirectory}\${archiveRealmServerLog}" archiveNumbering="ArchiveNumberingMode.Rolling" maxArchiveFiles="10000" layout="(${longdate}) [${level}] ${message} ${exception:format=tostring}" />
</target> </target>
</targets> </targets>
<rules> <rules>
<logger name="*" minlevel="Debug" writeTo="console,file"/> <logger name="*" minlevel="Debug" writeTo="console,file" />
</rules> </rules>
</nlog> </nlog>
</configuration> <system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
4 changes: 2 additions & 2 deletions Core/WCell.Constants/Spells/Constants.Spells.cs
Expand Up @@ -614,9 +614,9 @@ public enum SpellAttributesExC : uint
AttrExC_25_0x2000000 = 0x2000000,//25 AttrExC_25_0x2000000 = 0x2000000,//25


/// <summary> /// <summary>
/// Not in the old land or instances /// Not in the old land or instances (probably labeled incorrectly)
/// </summary> /// </summary>
OnlyInOutlands = 0x4000000, OldOnlyInOutlands = 0x4000000,


AttrExC_27_0x8000000 = 0x8000000,//27 AttrExC_27_0x8000000 = 0x8000000,//27
AttrExC_28_0x10000000 = 0x10000000,//28 AttrExC_28_0x10000000 = 0x10000000,//28
Expand Down
8 changes: 7 additions & 1 deletion Core/WCell.Core/Initialization/InitializationException.cs
Expand Up @@ -15,7 +15,13 @@ public InitializationException(string msg) : base(msg)
{ {
} }


public InitializationException(string msg, params object[] args) : base(string.Format(msg, args)) public InitializationException(string msg, params object[] args)
: base(string.Format(msg, args))
{
}

public InitializationException(Exception e, string msg, params object[] args)
: base(string.Format(msg, args), e)
{ {
} }
} }
Expand Down
128 changes: 120 additions & 8 deletions Core/WCell.Core/ServerApp.cs
Expand Up @@ -51,7 +51,7 @@ static ServerApp()
protected List<IUpdatable> m_updatables; protected List<IUpdatable> m_updatables;
protected LockfreeQueue<IMessage> m_messageQueue; protected LockfreeQueue<IMessage> m_messageQueue;


protected Task _updateTask; protected Task _updateTask;
protected int _currentUpdateThreadId; protected int _currentUpdateThreadId;
protected Stopwatch m_queueTimer; protected Stopwatch m_queueTimer;
protected long m_updateFrequency, m_lastUpdate; protected long m_updateFrequency, m_lastUpdate;
Expand Down Expand Up @@ -96,10 +96,10 @@ public static InitMgr InitMgr
} }
} }


/// <summary> /// <summary>
/// Modify this to the Location of the file whose App-config you want to load. /// Modify this to the Location of the file whose App-config you want to load.
/// This is needed specifically for tests, since they don't have an EntryAssembly /// This is needed specifically for tests, since they don't have an EntryAssembly
/// </summary> /// </summary>
[NotVariable] [NotVariable]
public static string EntryLocation public static string EntryLocation
{ {
Expand Down Expand Up @@ -155,7 +155,7 @@ public override bool IsRunning
if (value) if (value)
{ {
// start message loop // start message loop
_updateTask = Task.Factory.StartNewDelayed((int) m_updateFrequency, QueueUpdateCallback, this); _updateTask = Task.Factory.StartNewDelayed((int)m_updateFrequency, QueueUpdateCallback, this);
} }
} }
} }
Expand Down Expand Up @@ -243,6 +243,22 @@ public void UnregisterUpdatable(IUpdatable updatable)
AddMessage(() => m_updatables.Remove(updatable)); AddMessage(() => m_updatables.Remove(updatable));
} }



/// <summary>
/// Registers the given Updatable during the next Region Tick
/// </summary>
public void RegisterUpdatableLater(IUpdatable updatable)
{
m_messageQueue.Enqueue(new Message(() => RegisterUpdatable(updatable)));
}

/// <summary>
/// Unregisters the given Updatable during the next Region Update
/// </summary>
public void UnregisterUpdatableLater(IUpdatable updatable)
{
m_messageQueue.Enqueue(new Message(() => UnregisterUpdatable(updatable)));
}
#endregion #endregion


#region Task Pool #region Task Pool
Expand Down Expand Up @@ -305,7 +321,7 @@ protected void QueueUpdateCallback(object state)
{ {
// get the time at the start of our task processing // get the time at the start of our task processing
var timerStart = m_queueTimer.ElapsedMilliseconds; var timerStart = m_queueTimer.ElapsedMilliseconds;
var updateDt = (timerStart - m_lastUpdate)/1000.0f; var updateDt = (timerStart - m_lastUpdate) / 1000.0f;


// run timers! // run timers!
foreach (var updatable in m_updatables) foreach (var updatable in m_updatables)
Expand Down Expand Up @@ -351,11 +367,102 @@ protected void QueueUpdateCallback(object state)
if (_running) if (_running)
{ {
// re-register the Update-callback // re-register the Update-callback
_updateTask = Task.Factory.StartNewDelayed((int) callbackTimeout, QueueUpdateCallback, this); _updateTask = Task.Factory.StartNewDelayed((int)callbackTimeout, QueueUpdateCallback, this);
} }
} }
} }


#region Waiting
/// <summary>
/// Ensures execution outside the Region-context.
/// </summary>
/// <exception cref="InvalidOperationException">thrown if the calling thread is the region thread</exception>
public void EnsureNoContext()
{
if (Thread.CurrentThread.ManagedThreadId == _currentUpdateThreadId)
{
throw new InvalidOperationException(string.Format("Application Queue context prohibited."));
}
}

/// <summary>
/// Adds the given message to the region's message queue and does not return
/// until the message is processed.
/// </summary>
/// <remarks>Make sure that the region is running before calling this method.</remarks>
/// <remarks>Must not be called from the region context.</remarks>
public void AddMessageAndWait(bool allowInstantExecution, Action action)
{
AddMessageAndWait(allowInstantExecution, new Message(action));
}

/// <summary>
/// Adds the given message to the region's message queue and does not return
/// until the message is processed.
/// </summary>
/// <remarks>Make sure that the region is running before calling this method.</remarks>
/// <remarks>Must not be called from the region context.</remarks>
public void AddMessageAndWait(bool allowInstantExecution, IMessage msg)
{
if (allowInstantExecution && IsInContext)
{
msg.Execute();
}
else
{
EnsureNoContext();

// to ensure that we are not exiting in the current message-loop, add an updatable
// which again registers the message
var updatable = new SimpleUpdatable();
updatable.Callback = () => AddMessage(new Message(() =>
{
msg.Execute();
lock (msg)
{
Monitor.PulseAll(msg);
}
UnregisterUpdatable(updatable);
}));

lock (msg)
{
RegisterUpdatableLater(updatable);
// int delay = this.GetWaitDelay();
Monitor.Wait(msg);
// Assert.IsTrue(added, string.Format(debugMsg, args));
}
}
}

/// <summary>
/// Waits for one region tick before returning.
/// </summary>
/// <remarks>Must not be called from the region context.</remarks>
public void WaitOneTick()
{
AddMessageAndWait(false, new Message(() =>
{
// do nothing
}));
}

/// <summary>
/// Waits for the given amount of ticks.
/// One tick might take 0 until Region.UpdateSpeed milliseconds.
/// </summary>
/// <remarks>Make sure that the region is running before calling this method.</remarks>
/// <remarks>Must not be called from the region context.</remarks>
public void WaitTicks(int ticks)
{
EnsureNoContext();

for (int i = 0; i < ticks; i++)
{
WaitOneTick();
}
}
#endregion
#endregion #endregion


#region Start #region Start
Expand All @@ -365,6 +472,11 @@ protected void QueueUpdateCallback(object state)
/// </summary> /// </summary>
public virtual void Start() public virtual void Start()
{ {
if (_running)
{
return;
}

if (InitMgr.PerformInitialization()) if (InitMgr.PerformInitialization())
{ {
var address = Utility.ParseOrResolve(Host); var address = Utility.ParseOrResolve(Host);
Expand Down
1 change: 1 addition & 0 deletions README.txt
@@ -0,0 +1 @@
Welcome to WCell
37 changes: 37 additions & 0 deletions Run/Content/Lang/English.xml
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Translation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Items>
<Item Key="Done">
<Value>Done.</Value>
</Item>
<Item Key="Addon">
<Value>Addon</Value>
</Item>
<Item Key="Library">
<Value>Library</Value>
</Item>

<Item Key="SubCommandNotFound">
<Value>SubCommand not found: {0}</Value>
</Item>
<Item Key="MustNotUseCommand">
<Value>You are not allowed to use the {0}-Command!</Value>
</Item>

<Item Key="CmdLocalizerDescription">
<Value>Provides commands to manage the localizer</Value>
</Item>
<Item Key="CmdLocalizerReloadDescription">
<Value>Reloads the language files.</Value>
</Item>
<Item Key="CmdLocalizerSetLocaleDescription">
<Value>Allows you to set your own Locale (use "Cfg Set DefaultLocale" to set the server's locale)</Value>
</Item>
<Item Key="CmdLocalizerSetLocaleParamInfo">
<Value>&lt;locale&gt;</Value>
</Item>
<Item Key="UnableToSetUserLocale">
<Value>Could not change the current user's locale.</Value>
</Item>
</Items>
</Translation>
8 changes: 8 additions & 0 deletions Run/Content/Sample.xml
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Translation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Items>
<TranslatedItemOfLangKey Key="Addon">
<Value>Addon</Value>
</TranslatedItemOfLangKey>
</Items>
</Translation>

1 comment on commit 33875e7

@Skizot
Copy link

@Skizot Skizot commented on 33875e7 May 30, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wave @ Domiii

:D

Please sign in to comment.