initial commit
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 147 KiB |
@@ -0,0 +1,36 @@
|
||||
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("WorldServer")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("WorldServer")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("d3649609-e86d-4411-96a3-a6695b15f765")]
|
||||
|
||||
// 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 Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Configuration;
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.Runtime;
|
||||
using Game;
|
||||
using Game.Chat;
|
||||
using Game.Network;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace WorldServer
|
||||
{
|
||||
public class Server
|
||||
{
|
||||
const uint WorldSleep = 50;
|
||||
|
||||
static void Main()
|
||||
{
|
||||
ApplicationSignal.SetConsoleCtrlHandler(AbortHandler, true);
|
||||
ApplicationSignal.RemoveConsoleQuickEditMode();
|
||||
|
||||
if (!ConfigMgr.Load(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".conf"))
|
||||
ExitNow();
|
||||
|
||||
var WorldSocketMgr = new WorldSocketManager();
|
||||
//AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; // Watch for any unhandled exceptions.
|
||||
|
||||
if (!StartDB())
|
||||
ExitNow();
|
||||
|
||||
Testing();
|
||||
|
||||
// set server offline (not connectable)
|
||||
DB.Login.Execute("UPDATE realmlist SET flag = (flag & ~{0}) | {1} WHERE id = '{2}'", (uint)RealmFlags.VersionMismatch, (uint)RealmFlags.Offline, Global.WorldMgr.GetRealm().Id.Realm);
|
||||
|
||||
Global.RealmMgr.Initialize(ConfigMgr.GetDefaultValue("RealmsStateUpdateDelay", 10));
|
||||
|
||||
Global.WorldMgr.SetInitialWorldSettings();
|
||||
|
||||
// Launch the worldserver listener socket
|
||||
int worldPort = WorldConfig.GetIntValue(WorldCfg.PortWorld);
|
||||
string worldListener = ConfigMgr.GetDefaultValue("BindIP", "0.0.0.0");
|
||||
|
||||
int networkThreads = ConfigMgr.GetDefaultValue("Network.Threads", 1);
|
||||
if (networkThreads <= 0)
|
||||
{
|
||||
Log.outError(LogFilter.Server, "Network.Threads must be greater than 0");
|
||||
ExitNow();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!WorldSocketMgr.StartNetwork(worldListener, worldPort, networkThreads))
|
||||
{
|
||||
Log.outError(LogFilter.Network, "Failed to start Realm Network");
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
// set server online (allow connecting now)
|
||||
DB.Login.Execute("UPDATE realmlist SET flag = flag & ~{0}, population = 0 WHERE id = '{1}'", (uint)RealmFlags.Offline, Global.WorldMgr.GetRealm().Id.Realm);
|
||||
Global.WorldMgr.GetRealm().PopulationLevel = 0.0f;
|
||||
Global.WorldMgr.GetRealm().Flags = Global.WorldMgr.GetRealm().Flags & ~RealmFlags.VersionMismatch;
|
||||
|
||||
//- Launch CliRunnable thread
|
||||
if (ConfigMgr.GetDefaultValue("Console.Enable", true))
|
||||
{
|
||||
Thread commandThread = new Thread(CommandManager.InitConsole);
|
||||
commandThread.Start();
|
||||
}
|
||||
|
||||
WorldUpdateLoop();
|
||||
|
||||
try
|
||||
{
|
||||
// Shutdown starts here
|
||||
Global.WorldMgr.KickAll(); // save and kick all players
|
||||
Global.WorldMgr.UpdateSessions(1); // real players unload required UpdateSessions call
|
||||
|
||||
// unload Battlegroundtemplates before different singletons destroyed
|
||||
Global.BattlegroundMgr.DeleteAllBattlegrounds();
|
||||
|
||||
WorldSocketMgr.StopNetwork();
|
||||
|
||||
Global.MapMgr.UnloadAll(); // unload all grids (including locked in memory)
|
||||
Global.ScriptMgr.Unload();
|
||||
|
||||
// set server offline
|
||||
DB.Login.Execute("UPDATE realmlist SET flag = flag | {0} WHERE id = '{1}'", (uint)RealmFlags.Offline, Global.WorldMgr.GetRealm().Id.Realm);
|
||||
Global.RealmMgr.Close();
|
||||
|
||||
ClearOnlineAccounts();
|
||||
|
||||
ExitNow();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.outException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static bool StartDB()
|
||||
{
|
||||
// Load databases
|
||||
DatabaseLoader loader = new DatabaseLoader(DatabaseTypeFlags.All);
|
||||
loader.AddDatabase(DB.Login, "Login");
|
||||
loader.AddDatabase(DB.Characters, "Character");
|
||||
loader.AddDatabase(DB.World, "World");
|
||||
loader.AddDatabase(DB.Hotfix, "Hotfix");
|
||||
|
||||
if (!loader.Load())
|
||||
return false;
|
||||
|
||||
// Get the realm Id from the configuration file
|
||||
Global.WorldMgr.GetRealm().Id.Realm = ConfigMgr.GetDefaultValue("RealmID", 0u);
|
||||
if (Global.WorldMgr.GetRealm().Id.Realm == 0)
|
||||
{
|
||||
Log.outError(LogFilter.Server, "Realm ID not defined in configuration file");
|
||||
return false;
|
||||
}
|
||||
Log.outInfo(LogFilter.ServerLoading, "Realm running as realm ID {0} ", Global.WorldMgr.GetRealm().Id.Realm);
|
||||
|
||||
// Clean the database before starting
|
||||
ClearOnlineAccounts();
|
||||
|
||||
Log.outInfo(LogFilter.Server, "Using World DB: {0}", Global.WorldMgr.LoadDBVersion());
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ClearOnlineAccounts()
|
||||
{
|
||||
// Reset online status for all accounts with characters on the current realm
|
||||
DB.Login.Execute("UPDATE account SET online = 0 WHERE online > 0 AND id IN (SELECT acctid FROM realmcharacters WHERE realmid = {0})", Global.WorldMgr.GetRealm().Id.Realm);
|
||||
|
||||
// Reset online status for all characters
|
||||
DB.Characters.Execute("UPDATE characters SET online = 0 WHERE online <> 0");
|
||||
|
||||
// Battlegroundinstance ids reset at server restart
|
||||
DB.Characters.Execute("UPDATE character_Battleground_data SET instanceId = 0");
|
||||
}
|
||||
|
||||
static void WorldUpdateLoop()
|
||||
{
|
||||
uint realPrevTime = Time.GetMSTime();
|
||||
uint prevSleepTime = 0; // used for balanced full tick time length near WORLD_SLEEP_CONST
|
||||
|
||||
while (!Global.WorldMgr.IsStopped)
|
||||
{
|
||||
var realCurrTime = Time.GetMSTime();
|
||||
|
||||
uint diff = Time.GetMSTimeDiff(realPrevTime, realCurrTime);
|
||||
Global.WorldMgr.Update(diff);
|
||||
realPrevTime = realCurrTime;
|
||||
|
||||
if (diff <= (WorldSleep + prevSleepTime))
|
||||
{
|
||||
prevSleepTime = WorldSleep + prevSleepTime - diff;
|
||||
Thread.Sleep((int)prevSleepTime);
|
||||
}
|
||||
else
|
||||
prevSleepTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
var ex = e.ExceptionObject as Exception;
|
||||
Log.outException(ex);
|
||||
}
|
||||
|
||||
static void ExitNow()
|
||||
{
|
||||
Log.outInfo(LogFilter.Server, "Halting process...");
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
|
||||
static bool AbortHandler(CtrlType sig)
|
||||
{
|
||||
Global.WorldMgr.StopNow(ShutdownExitCode.Shutdown);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void Testing()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,136 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{D157534F-86F1-4E8E-80B0-ECAD321ECAA6}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WorldServer</RootNamespace>
|
||||
<AssemblyName>WorldServer</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\Build\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>..\Build\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\Build\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>WorldServer.Server</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>Blue.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Server.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Framework\Framework.csproj">
|
||||
<Project>{82d442a9-18c0-4c59-8ec6-0dfe3e34d334}</Project>
|
||||
<Name>Framework</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Game\Game.csproj">
|
||||
<Project>{83ef8d5c-afa1-4546-bcdd-6422d55b1515}</Project>
|
||||
<Name>Game</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Blue.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="WorldServer.conf">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Reference in New Issue
Block a user