本文整理汇总了C#中MessageHandler.Start方法的典型用法代码示例。如果您正苦于以下问题:C# MessageHandler.Start方法的具体用法?C# MessageHandler.Start怎么用?C# MessageHandler.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageHandler
的用法示例。
在下文中一共展示了MessageHandler.Start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public bool Start()
{
try
{
context = new ServerContext();
context.ServerConfig = serverConfig;
// Database connection check
Logger.Output(this, "Checking database connection..");
context.Css = Config.DatabaseConnectionString;
using (MySqlConnection conn = new MySqlConnection(Config.DatabaseConnectionString))
{
conn.Open();
if (conn.State == ConnectionState.Open)
{
Logger.Output(this, "Database connection verified..");
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM settings";
MySqlDataReader dr = cmd.ExecuteReader();
// Load all world settings from the database.
while (dr.Read())
{
string name, value;
name = DatabaseHelper.GetString(dr, "name");
value = DatabaseHelper.GetString(dr, "value");
Logger.Record(this, "Config param: {0}\t= '{1}'", name, value);
serverConfig.Add(name, value);
}
dr.Close();
}
else
{
Logger.Output(this, "Database connection can't be opened!");
throw new InvalidOperationException("Database connection can't be opened.");
}
}
Logger.Output(this, "Creating server components..");
Timer = new Stopwatch();
Timer.Start();
Logger.Output(this, "Hi res timer available: {0}, frequency: {1}.", Stopwatch.IsHighResolution, Stopwatch.Frequency);
int result;
int.TryParse(serverConfig["turn_duration"], out result);
context.TurnDuration = result;
int.TryParse(serverConfig["users_allowed"], out result);
context.Mpt = new MasterPlayerTable(result, context);
// Queues
QueueManager qMngr = QueueManager.Singletone;
qMngr.CreateQueues(result);
// Load all WorldData.xml and Entities.xml data
DataManager dMngr = DataManager.Singletone;
// Create the zone manager.
Logger.Output(this, "Creating zone manager..");
context.ZoneManager = new ZoneManager(context);
// Now load all static predefined entities.
//Logger.Output(this, "Loading static entities..");
//dMngr.LoadStaticEntities(context.ZoneManager);
// Create the game processor for handling messages.
Logger.Output(this, "Creating game processor..");
context.GameProcessor = new GameProcessor(context);
// Create the chat processor for handling chat and remote commands.
Logger.Output(this, "Creating chat processor..");
context.ChatProcessor = new ChatProcessor(context);
// Network server
Logger.Output(this, "Creating network server..");
NetPeerConfiguration cfg = new NetPeerConfiguration("Asteria");
int.TryParse(context.ServerConfig["client_port"], out result);
cfg.Port = result;
int.TryParse(context.ServerConfig["users_allowed"], out result);
cfg.MaximumConnections = result;
int.TryParse(context.ServerConfig["max_transmissionunit"], out result);
cfg.MaximumTransmissionUnit = result;
int.TryParse(context.ServerConfig["client_timeout_seconds"], out result);
cfg.ConnectionTimeout = result;
cfg.ReceiveBufferSize = 4095;
cfg.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
#if DEBUG
cfg.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
#endif
IPAddress clientAddress;
//.........这里部分代码省略.........