public void GameStateChanged(GameServer server, GameServer.ServiceState originalState, GameServer.ServiceState newState) { GameServer.ServerEventType eventType = GameServer.ServerEventType.UnknownEvent; switch (originalState) { case GameServer.ServiceState.Starting: { if (newState == GameServer.ServiceState.Running) { //游戏正常启动 server.AppendMessage("Start", GameServer.MessageInfo.Type.Success); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} Start", server.ToString()); ; context.Server = server; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStart, context); eventType = GameServer.ServerEventType.GameStart; } else if (newState == GameServer.ServiceState.ErrorStopped) { //游戏启动失败 server.AppendMessage("StartFail", GameServer.MessageInfo.Type.Failure); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} StartFail", server.ToString()); ; context.Server = server; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.StartGameFail, context); eventType = GameServer.ServerEventType.GameStartFail; } } break; case GameServer.ServiceState.Stopping: { if (newState == GameServer.ServiceState.OKStopped || newState == GameServer.ServiceState.ErrorStopped) { //停止,指web主动关闭服务器程序 //游戏正常关闭 server.AppendMessage("Stop", GameServer.MessageInfo.Type.Alert); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} Stop", server.ToString()); ; context.Server = server; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStop, context); eventType = GameServer.ServerEventType.GameStop; } } break; case GameServer.ServiceState.ErrorStopped: case GameServer.ServiceState.OKStopped : { if (newState == GameServer.ServiceState.Running) { //游戏意外启动 server.AppendMessage("StartByAccident", GameServer.MessageInfo.Type.Failure); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} StartByAccident", server.ToString()); ; context.Server = server; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStartByAccident, context); eventType = GameServer.ServerEventType.GameStartByAccident; } } break; case GameServer.ServiceState.Running: { if (newState == GameServer.ServiceState.ErrorStopped) { //游戏崩溃 server.AppendMessage("StopByAccident", GameServer.MessageInfo.Type.Failure); AutomationContext context = new AutomationContext(); context.Message = string.Format("{0} StopByAccident", server.ToString()); ; context.Server = server; AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStopByAccident, context); eventType = GameServer.ServerEventType.GameStopByAccident; } } break; } if (eventType != GameServer.ServerEventType.UnknownEvent) { DateTime eventTime = DateTime.Now; using (IBlazeDatabase db = DbFactory.GetDatabase()) { IBlazeTable table = db.GetTable(TableString.ServerEventTableName); string[] fieldNames = { TableString.ServerEventFieldServerId, TableString.ServerEventFieldEventTime, TableString.ServerEventFieldEventType }; object[] fieldValues = { server.Id, eventTime, (Int16)eventType }; table.Add(fieldNames, fieldValues); } } }
void SendConfigPackage(GameServer server) { string fileContentString = null; using (MemoryStream configStream = new MemoryStream()) { server.LordConfig.WriteGuardConfig(configStream); fileContentString = SystemConfig.Current.DefaultEncoding.GetString(configStream.ToArray()); //Encoding.ASCII.GetString(configStream.ToArray()); } int x = s_random.Next(1000); int y = Util.CaculateY(x); string encryptFileContent = fileContentString; //string encryptFileContent = string.Empty; //util.DBEncrypt(fileContentString, ref encryptFileContent); string md5 = UtilDllWrap.MD5(y.ToString(), SystemConfig.Current.DefaultEncoding); e2g_ConfigInfo configInfo = new e2g_ConfigInfo(); configInfo.X = x; configInfo.Y = md5; configInfo.ConfigFileDataLength = (ushort)encryptFileContent.Length; configInfo.ConfigFileData = encryptFileContent; //configProtocol.X = x; //configProtocol.Y = md5; //configProtocol.ConfigFileDataLength = (ushort)encryptFileContent.Length; //configProtocol.ConfigFileData = encryptFileContent; server.CommunicationKey = UtilDllWrap.CreateRandomKey(8); byte[] encryptedKey = server.CommunicationKey;//romandou UtilDllWrap.RSAEncrypt(server.CommunicationKey); byte[] encryptedConfigInfo = configInfo.ToBytes();//romandou UtilDllWrap.RC4Encrypt(configInfo.ToBytes(), server.CommunicationKey); e2g_config configProtocol = new e2g_config(); Array.Copy(encryptedKey, configProtocol.Key.Data, encryptedKey.Length); Array.Copy(encryptedConfigInfo, configProtocol.ConfigInfo, encryptedConfigInfo.Length); IPEndPoint target = new IPEndPoint(IPAddress.Parse(server.IpAddress), SystemConfig.Current.ConfigGuardPort); if (AdminServer.TheInstance.ConnectionManager.SendTo(target, configProtocol.ToBytes())) server.AppendMessage(StringDef.AttemptToConfigGuard, GameServer.MessageInfo.Type.Normal); }
protected override void OnCommandComplete(GameServer server, bool success, string output) { if (success && (output == null || output.Length == 0)) { server.GameServiceState = GameServer.ServiceState.Stopping; } else { server.AppendMessage(StringDef.StopGameFailed + ":" + output, GameServer.MessageInfo.Type.Failure); } }