You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
288 lines
7.9 KiB
288 lines
7.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sog
|
|
{
|
|
public enum AppRunMode
|
|
{
|
|
/// <summary>
|
|
/// 初始,错误
|
|
/// </summary>
|
|
None = 0,
|
|
|
|
/// <summary>
|
|
/// 非代理模式
|
|
/// 启动
|
|
/// </summary>
|
|
Run = 1,
|
|
|
|
|
|
/// <summary>
|
|
/// 代理模式
|
|
/// 启动
|
|
/// </summary>
|
|
Start = 2,
|
|
|
|
/// <summary>
|
|
/// 代理模式
|
|
/// 停服,注意保存数据
|
|
/// </summary>
|
|
Stop = 3,
|
|
|
|
/// <summary>
|
|
/// 代理模式
|
|
/// 重新加载逻辑模块(XXXServer.dll)
|
|
/// </summary>
|
|
Hotfix = 4,
|
|
|
|
/// <summary>
|
|
/// 代理模式
|
|
/// 重新加载配置
|
|
/// </summary>
|
|
ReloadConfig = 5,
|
|
|
|
/// <summary>
|
|
/// 代理模式
|
|
/// 死亡测试,正式环境别用
|
|
/// </summary>
|
|
//DeadTest = 6,
|
|
|
|
/// <summary>
|
|
/// 重新加载cluster.json配置文件
|
|
/// </summary>
|
|
ReloadCluster = 7,
|
|
|
|
/// <summary>
|
|
/// 代理模式
|
|
/// Gm指令,主要是GameServer使用
|
|
/// </summary>
|
|
GmCommand = 10,
|
|
|
|
/// <summary>
|
|
/// 工具模式
|
|
/// hotfix检查, 检查协议是否有修改,有修改则不能hotfix,免得引起运营事故
|
|
/// </summary>
|
|
HotfixCheck = 12,
|
|
}
|
|
|
|
public class AppParam
|
|
{
|
|
public uint ServerID { get; private set; } //服务器inst 拼合id,
|
|
public string ConfigFileName { get; set; }
|
|
public string ClusterFileName { get; private set; } //args 里面的配置文件名
|
|
public SogServerConfig ServerConfig { get; private set; }
|
|
public AppRunMode RunMode { get; private set; }
|
|
public bool forceHotfix { get; private set; }
|
|
public string CommandAllText { get; private set; }
|
|
public string[] Args { get; private set; }
|
|
public string hotfixcheckDllFileFullName { get; private set; }
|
|
public AppParam(string[] args)
|
|
{
|
|
Args = args;
|
|
|
|
//缺省
|
|
//在SogLoader里需要判断
|
|
RunMode = AppRunMode.None;
|
|
|
|
Parse(args);
|
|
|
|
Check();
|
|
}
|
|
|
|
/*
|
|
* 不进行校验,特殊服务器使用,比如ServerManager
|
|
*/
|
|
public AppParam(string[] args, bool noCheck)
|
|
{
|
|
Args = args;
|
|
|
|
//缺省
|
|
//在SogLoader里需要判断
|
|
RunMode = AppRunMode.None;
|
|
|
|
Parse(args);
|
|
}
|
|
|
|
public void Parse(string[] args)
|
|
{
|
|
int count = args.Length;
|
|
|
|
for(int i=0; i<count; i++)
|
|
{
|
|
ParseOne(args[i]);
|
|
|
|
if(RunMode == AppRunMode.GmCommand)
|
|
{
|
|
ProcessGmCmd(args, i);
|
|
|
|
return;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ParseOne(string arg)
|
|
{
|
|
string command = arg.Trim();
|
|
|
|
// 服务器启动模式
|
|
if (command.Contains("=") == false)
|
|
{
|
|
if(RunMode == AppRunMode.ReloadConfig)
|
|
{
|
|
CommandAllText += " " + command;
|
|
return;
|
|
}
|
|
|
|
if ("run" == command)
|
|
{
|
|
RunMode = AppRunMode.Run;
|
|
CommandAllText = command;
|
|
}
|
|
if ("start" == command)
|
|
{
|
|
RunMode = AppRunMode.Start;
|
|
CommandAllText = command;
|
|
}
|
|
else if ("stop" == command)
|
|
{
|
|
RunMode = AppRunMode.Stop;
|
|
CommandAllText = command;
|
|
}
|
|
else if ("hotfix" == command)
|
|
{
|
|
RunMode = AppRunMode.Hotfix;
|
|
CommandAllText = command;
|
|
}
|
|
else if ("reloadconfig" == command)
|
|
{
|
|
RunMode = AppRunMode.ReloadConfig;
|
|
CommandAllText = command;
|
|
}
|
|
else if("gmcmd" == command)
|
|
{
|
|
RunMode = AppRunMode.GmCommand;
|
|
CommandAllText = command;
|
|
}
|
|
else if("reloadcluster" == command)
|
|
{
|
|
RunMode = AppRunMode.ReloadCluster;
|
|
CommandAllText = command;
|
|
}
|
|
else if ("force" == command)
|
|
{
|
|
//强制hotfix,防止某些时候不小心搞得没法hotfix,但是可以人工确定是安全的
|
|
forceHotfix = true;
|
|
RunMode = AppRunMode.Hotfix;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
// 服务器启动参数 比如 --id=1.1.1
|
|
// xx=xxx
|
|
|
|
string[] pair = command.Split('=');
|
|
string key = pair[0].Trim();
|
|
string value = pair[1].Trim();
|
|
|
|
if(String.IsNullOrEmpty(key) || String.IsNullOrEmpty(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
key = key.Trim();
|
|
value = value.Trim();
|
|
if (String.IsNullOrEmpty(key) || String.IsNullOrEmpty(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if("--id" == key || "id" == key)
|
|
{
|
|
ServerID = ServerIDUtils.IDToNumber(value);
|
|
}
|
|
else if ("--cluster" == key || "cluster" == key)
|
|
{
|
|
ClusterFileName = value;
|
|
}
|
|
else if ("QuestMethod.Nonetfixcheck" == key || "hotfixcheck" == key)
|
|
{
|
|
hotfixcheckDllFileFullName = value;
|
|
RunMode = AppRunMode.HotfixCheck;
|
|
CommandAllText = command;
|
|
}
|
|
}
|
|
|
|
private void Check()
|
|
{
|
|
if(ServerID == 0)
|
|
{
|
|
// no log here
|
|
string message = "invalid appid,please use id=x.x.x when start server";
|
|
Console.WriteLine(message);
|
|
throw new Exception(message);
|
|
}
|
|
}
|
|
|
|
private void ProcessGmCmd(string[] args, int index)
|
|
{
|
|
if (args.Length < index + 2)
|
|
{
|
|
string message = "invalid gmcmd,no cmd, use SogLoader --id=1.1.1 --config=xxx.json --cluster=xxx.json gmcmd cmd cmdparam1 cmdparam2";
|
|
Console.WriteLine(message);
|
|
throw new Exception(message);
|
|
}
|
|
|
|
if (args[index] != "gmcmd")
|
|
{
|
|
string message = "invalid gmcmd,must be first param,use SogLoader --id=1.1.1 --config=xxx.json --cluster=xxx.json gmcmd cmdparam1 cmdparam2";
|
|
Console.WriteLine(message);
|
|
throw new Exception(message);
|
|
}
|
|
|
|
index++;
|
|
string cmd = args[index];
|
|
|
|
//string[] gmcmd_params = new string[args.Length - 2];
|
|
|
|
CommandAllText = "gmcmd " + cmd;
|
|
|
|
index++;
|
|
for (; index < args.Length; index++)
|
|
{
|
|
CommandAllText += " ";
|
|
CommandAllText += args[index];
|
|
}
|
|
}
|
|
|
|
public void Reload()
|
|
{
|
|
LoadServerConfig();
|
|
}
|
|
|
|
public void LoadServerConfig()
|
|
{
|
|
//读取文件
|
|
SogServerConfig config = null;
|
|
|
|
//这里有可能出错,先保存到临时变量
|
|
config = JsonConfig.parseFile<SogServerConfig>(ConfigFileName);
|
|
|
|
if(config == null)
|
|
{
|
|
Console.WriteLine("SogServerConfig ConfigFileName {0} read failed", ConfigFileName);
|
|
|
|
}
|
|
else
|
|
{
|
|
ServerConfig = config;
|
|
//转化格式
|
|
ServerConfig.ReplaceFormatString(ServerID);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|